:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --ink: #1a1a2e;
  --ink-2: #4a4a5c;
  --muted: #8a8a9e;
  --border: #e4e4ea;
  --brand: #76092d;
  --brand-dark: #5a071f;
  --brand-soft: #fbf2f4;
  --ok: #2ba26a;
  --ok-soft: #e7f6ee;
  --err: #e53e3e;
  --err-soft: #fdecec;
  --warn: #e89000;
  --warn-soft: #fdf4e3;
  --info: #2c6ecb;
  --info-soft: #e8eff9;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--ink); margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--err); font-size: 13px; margin-top: 6px; }

/* ======== Topbar ======== */
.topbar {
  background: var(--brand);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 18px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-link { display: inline-flex; align-items: center; }
.brand img { height: 48px; width: auto; filter: brightness(0) invert(1); }
.brand .subtitle {
  color: rgba(255,255,255,.85);
  font-size: 12px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-weight: 600;
}
.topnav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.topnav-link {
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  transition: background .15s;
}
.topnav-link:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.topnav-link--btn {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.25);
  cursor: pointer;
  font-family: inherit;
}
.topnav-link--btn:hover { background: rgba(255,255,255,.22); }
.topnav-user { color: rgba(255,255,255,.8); font-size: 13px; }
.topnav-logout { margin: 0; }

/* ======== Container ======== */
.container {
  width: 100%;
  max-width: 1100px;
  margin: 24px auto 32px;
  padding: 0 20px;
}
.container--wide { max-width: 1500px; }

.page-head { margin: 8px 0 20px; }
.page-head h1 { font-size: 22px; margin: 0 0 4px; }

/* ======== Month nav ======== */
.month-bar {
  display: flex;
  align-items: center;
  gap: 12px;
}
.month-title { margin: 0; font-size: 22px; min-width: 220px; text-align: center; }
.month-today { margin-left: auto; }

/* ======== Cards ======== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  margin: 16px 0;
  box-shadow: var(--shadow);
}
.card--table { padding: 0; overflow: hidden; }
.card h2 { font-size: 17px; margin: 0 0 14px; }
.card h3.cat-heading {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--brand);
  margin: 18px 0 8px;
}

/* ======== Forms ======== */
.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.form-row label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.form-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
}
.form-inline .form-row { margin-bottom: 0; }
.form-inline .form-row--narrow { flex: 0 0 180px; }
.form-inline .form-row--grow { flex: 1 1 320px; }

.input,
input[type="text"], input[type="number"], input[type="password"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--ink);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(118,9,45,.12);
}

/* ======== Buttons ======== */
.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background .15s, border-color .15s, transform .05s;
  line-height: 1.2;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.is-disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn-sm { padding: 6px 12px; font-size: 13px; font-weight: 600; }
.btn-block { display: block; width: 100%; }

.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); text-decoration: none; }

.btn-secondary { background: #fff; color: var(--brand); border-color: var(--brand); }
.btn-secondary:hover { background: var(--brand-soft); text-decoration: none; }

.btn-danger { background: var(--err); color: #fff; border-color: var(--err); }
.btn-danger:hover { background: #c92929; border-color: #c92929; text-decoration: none; }

.inline-form { display: inline-block; margin: 0; }

/* ======== Icon buttons (32×32 chip-style) ======== */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
  vertical-align: middle;
}
.icon-btn:hover { text-decoration: none; }
.icon-btn:active { transform: translateY(1px); }
.icon-btn:disabled { opacity: .45; cursor: not-allowed; }

.icon-btn--primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.icon-btn--primary:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

.icon-btn--secondary {
  background: var(--brand-soft);
  color: var(--brand);
  border-color: var(--brand);
}
.icon-btn--secondary:hover {
  background: var(--brand);
  color: #fff;
}

.icon-btn--danger {
  background: var(--err-soft);
  color: var(--err);
  border-color: var(--err);
  font-size: 14px;
}
.icon-btn--danger:hover {
  background: var(--err);
  color: #fff;
}

.col-actions-inline { white-space: nowrap; text-align: right; }
.col-actions-inline .icon-btn + .inline-form { margin-left: 4px; }
.col-actions-inline .inline-form + .icon-btn { margin-left: 4px; }

/* "A pari" status (importo da incassare = 0) */
.status--neutral { background: #eef0f4; color: #4a4a5c; }

/* ======== Auth card ======== */
.auth-card {
  max-width: 380px;
  margin: 60px auto;
  padding: 32px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.auth-title { font-size: 22px; margin: 0 0 6px; }

/* ======== Data table ======== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.data-table thead th {
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid #f0f0f4;
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table .col-num { text-align: right; white-space: nowrap; }
.data-table .col-total { background: var(--brand-soft); }
.data-table .col-total strong { color: var(--brand); font-size: 15px; }
.data-table .col-status { white-space: nowrap; }
.data-table .col-actions { white-space: nowrap; text-align: right; }
.data-table .col-actions .btn-sm + .inline-form { margin-left: 6px; }
.data-table .col-name a { font-weight: 600; color: var(--ink); }
.data-table .col-name a:hover { color: var(--brand); }

.data-table tr.is-collected td { opacity: .85; }
.data-table tr.is-collected .col-total { background: var(--ok-soft); }
.data-table tr.is-collected .col-total strong { color: #166c43; }

.muted-num { color: var(--ink-2); }
.badge-count {
  display: inline-block;
  font-size: 11px;
  color: var(--muted);
  margin-left: 4px;
}

/* ======== Status pills ======== */
.status {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.status--ok { background: var(--ok-soft); color: #166c43; }
.status--pending { background: var(--warn-soft); color: #8a5a07; }

/* ======== Summary card (pt_detail) ======== */
.summary-card { padding: 18px 22px; }
.summary-row {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  align-items: center;
}
.summary-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 130px;
}
.summary-cell--total {
  padding: 10px 16px;
  background: var(--brand-soft);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--brand);
}
.summary-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}
.summary-val { font-size: 20px; }
.summary-cell--total .summary-val strong { color: var(--brand); font-size: 24px; }

/* ======== Flash messages ======== */
.flashes { margin: 0 0 16px; display: flex; flex-direction: column; gap: 8px; }
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  border: 1px solid transparent;
}
.flash--success { background: var(--ok-soft); color: #166c43; border-color: #c4e9d4; }
.flash--info { background: var(--info-soft); color: #234d8a; border-color: #c4d8f3; }
.flash--warning { background: var(--warn-soft); color: #8a5a07; border-color: #f4d9a3; }
.flash--danger { background: var(--err-soft); color: #962525; border-color: #f4caca; }
.flash--message { background: var(--info-soft); color: #234d8a; border-color: #c4d8f3; }

.link-muted { font-size: 13px; color: var(--muted); }
.link-muted:hover { color: var(--brand); }

/* ======== Footer ======== */
.footer {
  text-align: center;
  padding: 22px 16px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.4px;
  display: flex;
  justify-content: center;
  gap: 14px;
}
