/* Gestionale Finanze — stile dell'interfaccia.
   Token di colore in :root, tema scuro automatico (o forzato con data-theme). */

:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f4f6fa;
  --surface-3: #e9edf3;
  --border: #e2e6ee;
  --border-strong: #ccd3de;
  --text: #0f1729;
  --text-muted: #556070;
  --text-faint: #8a93a3;
  --primary: #2350e0;
  --primary-hover: #1b40ba;
  --primary-soft: #e9efff;
  --primary-contrast: #ffffff;
  --pos: #0f7a3d;
  --pos-soft: #e3f5ea;
  --neg: #c62828;
  --neg-soft: #fdecec;
  --warn: #9a5b00;
  --warn-soft: #fff4dc;
  --focus: #2563eb;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.04);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.07);
  --shadow-lg: 0 18px 48px rgba(16, 24, 40, 0.2);
  --radius: 14px;
  --radius-sm: 10px;
  --brand-gradient: linear-gradient(135deg, #2350e0 0%, #0e9384 100%);
  --sidebar-w: 248px;
  --topbar-h: 56px;
  --tabbar-h: 64px;
  --font: 'Inter', 'Segoe UI Variable Text', 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', monospace;
  /* palette categoriale per grafici: ordine fisso, validata (daltonismo + contrasto) su superficie chiara e scura */
  --c1: #2a78d6;
  --c2: #eb6834;
  --c3: #1baf7a;
  --c4: #eda100;
  --c5: #e87ba4;
  --c6: #008300;
  --c7: #4a3aa7;
  --c8: #e34948;
  --c-other: #9aa1ad;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0b0e14;
    --surface: #141922;
    --surface-2: #1a202b;
    --surface-3: #232a36;
    --border: #262e3b;
    --border-strong: #37404f;
    --text: #e8ebf1;
    --text-muted: #a3acbb;
    --text-faint: #7c8595;
    --primary: #6b9cff;
    --primary-hover: #8fb3ff;
    --primary-soft: #1d2a45;
    --primary-contrast: #0b1020;
    --pos: #4ade80;
    --pos-soft: #12301f;
    --neg: #f87171;
    --neg-soft: #3a1717;
    --warn: #fbbf24;
    --warn-soft: #33270d;
    --focus: #8fb3ff;
    --shadow-sm: none;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.55);
    --c1: #3987e5;
    --c2: #d95926;
    --c3: #199e70;
    --c4: #c98500;
    --c5: #d55181;
    --c6: #008300;
    --c7: #9085e9;
    --c8: #e66767;
    --c-other: #6b7280;
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #0b0e14;
  --surface: #141922;
  --surface-2: #1a202b;
  --surface-3: #232a36;
  --border: #262e3b;
  --border-strong: #37404f;
  --text: #e8ebf1;
  --text-muted: #a3acbb;
  --text-faint: #7c8595;
  --primary: #6b9cff;
  --primary-hover: #8fb3ff;
  --primary-soft: #1d2a45;
  --primary-contrast: #0b1020;
  --pos: #4ade80;
  --pos-soft: #12301f;
  --neg: #f87171;
  --neg-soft: #3a1717;
  --warn: #fbbf24;
  --warn-soft: #33270d;
  --focus: #8fb3ff;
  --shadow-sm: none;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.55);
  --c1: #3987e5;
  --c2: #d95926;
  --c3: #199e70;
  --c4: #c98500;
  --c5: #d55181;
  --c6: #008300;
  --c7: #9085e9;
  --c8: #e66767;
  --c-other: #6b7280;
  color-scheme: dark;
}

/* ---------- base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.01em;
}
h1 {
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}
h2 {
  font-size: 1.1rem;
}
h3 {
  font-size: 0.98rem;
}
p {
  margin: 0 0 0.6em;
}
a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.num,
.amount,
table.data td.r,
.kpi-value,
.tx-amount,
.picker-value {
  font-variant-numeric: tabular-nums;
}
.muted {
  color: var(--text-muted);
}
.faint {
  color: var(--text-faint);
}
.small {
  font-size: 0.85rem;
}
.pos {
  color: var(--pos);
}
.neg {
  color: var(--neg);
}
.warn-text {
  color: var(--warn);
}
.nowrap {
  white-space: nowrap;
}
.right {
  text-align: right;
}
.center {
  text-align: center;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.boot {
  display: grid;
  place-items: center;
  min-height: 100vh;
  color: var(--text-muted);
}

/* ---------- layout ---------- */
.shell {
  min-height: 100vh;
}
.sidebar {
  display: none;
}
.main {
  padding: 12px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  max-width: 1320px;
  margin: 0 auto;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--topbar-h);
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 {
  flex: 1;
  font-size: 1.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .brand-mini {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 8px 0 18px;
}
.page-head h1 {
  font-size: 1.6rem;
  font-weight: 700;
}
.page-head .grow {
  flex: 1;
  min-width: 160px;
}
.page-head .subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 2px;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.tabbar a,
.tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  cursor: pointer;
  text-decoration: none;
}
.tabbar .active {
  color: var(--primary);
  font-weight: 600;
}
.tabbar .fab {
  width: 52px;
  height: 52px;
  margin: -18px auto 0;
  border-radius: 50%;
  background: var(--brand-gradient);
  color: #fff;
  box-shadow: 0 8px 20px color-mix(in srgb, var(--primary) 40%, transparent);
  justify-self: center;
}
.tabbar .fab svg {
  width: 26px;
  height: 26px;
}

@media (max-width: 959px) {
  /* su telefono il titolo è già nella barra in alto */
  .page-head .grow h1 {
    display: none;
  }
  .hide-mobile {
    display: none !important;
  }
}

@media (min-width: 960px) {
  .shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
  }
  .sidebar {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 14px 10px;
  }
  .tabbar {
    display: none;
  }
  .topbar {
    display: none;
  }
  .main {
    padding: 20px 28px 40px;
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 14px;
  font-weight: 750;
  font-size: 1.02rem;
}
.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--brand-gradient);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 30%, transparent);
  display: grid;
  place-items: center;
  color: #fff;
  flex: none;
}
.nav-group {
  margin-top: 10px;
}
.nav-group-title {
  padding: 6px 12px;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 12px;
  margin: 1px 0;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.93rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.nav-link svg {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  flex: none;
}
.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.nav-link.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--primary);
}
.nav-link.active svg {
  color: var(--primary);
}
.nav-badge {
  margin-left: auto;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
}
.sidebar-foot {
  margin-top: auto;
  padding: 12px 6px 4px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}

/* ---------- griglie ---------- */
.grid {
  display: grid;
  gap: 14px;
}
.grid-2,
.grid-3,
.grid-4,
.kpis {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}
.kpis {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 700px) {
  .grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-4,
  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (min-width: 1100px) {
  .grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .grid-4,
  .kpis {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .span-2 {
    grid-column: span 2;
  }
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.row.between {
  justify-content: space-between;
}
.spacer {
  flex: 1;
}

/* ---------- card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 18px 0;
}
.card-head h2,
.card-head h3 {
  flex: 1;
  font-size: 1rem;
  font-weight: 650;
}
/* collegamenti nell'intestazione di una scheda ("Tutti", "Dettaglio"...) */
.card-head a.btn.ghost {
  color: var(--primary);
  font-weight: 600;
}
.card-head a.btn.ghost::after {
  content: '→';
  margin-left: 2px;
}
.card-body {
  padding: 14px 18px 18px;
}
.card-body.flush {
  padding: 8px 0 4px;
}
.card-foot {
  padding: 11px 18px;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
}

.kpi {
  display: flex;
  flex-direction: column;
  padding: 16px 18px;
}
.kpi-label {
  font-size: 0.82rem;
  font-weight: 560;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 9px;
}
.kpi-icon {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  flex: none;
  background: var(--primary-soft);
  color: var(--primary);
}
.kpi-icon svg {
  width: 16px;
  height: 16px;
}
.kpi-value {
  margin-top: 12px;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-sub {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
/* avviso breve sotto il numero (es. conti senza prezzo): il dettaglio è nel suggerimento */
.kpi-flag {
  margin-top: auto;
  padding-top: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 560;
  color: var(--warn);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-flag svg {
  flex: none;
}
/* variazione con segno, in una pillola colorata */
.delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.delta.pos {
  background: var(--pos-soft);
  color: var(--pos);
}
.delta.neg {
  background: var(--neg-soft);
  color: var(--neg);
}
@media (max-width: 700px) {
  .kpi {
    padding: 14px;
  }
  .kpi-label {
    font-size: 0.78rem;
    gap: 7px;
    align-items: flex-start;
  }
  .kpi-icon {
    width: 24px;
    height: 24px;
    border-radius: 8px;
  }
  .kpi-value {
    margin-top: 10px;
    font-size: 1.3rem;
  }
}
@media (max-width: 380px) {
  .kpi-value {
    font-size: 1.12rem;
  }
}

/* ---------- pulsanti ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn svg {
  width: 17px;
  height: 17px;
}
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-contrast);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--primary) 35%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.btn.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.btn.danger {
  color: var(--neg);
  border-color: color-mix(in srgb, var(--neg) 45%, var(--border));
}
.btn.danger.solid {
  background: var(--neg);
  border-color: var(--neg);
  color: #fff;
}
.btn.ghost {
  border-color: transparent;
  background: transparent;
}
.btn.ghost:hover {
  background: var(--surface-2);
}
.btn.sm {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.84rem;
}
.btn.icon {
  padding: 0;
  width: 38px;
}
.btn.icon.sm {
  width: 30px;
}
.btn.block {
  width: 100%;
}

/* ---------- form ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.field > label,
.field-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}
.field .hint {
  font-size: 0.78rem;
  color: var(--text-faint);
}
.field .error {
  font-size: 0.8rem;
  color: var(--neg);
}
.input,
select.input,
textarea.input {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 16px; /* evita lo zoom automatico su iOS */
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input:hover {
  border-color: color-mix(in srgb, var(--border-strong) 60%, var(--text-muted));
}
@media (min-width: 960px) {
  .input,
  select.input,
  textarea.input {
    font-size: 0.93rem;
  }
}
.input:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent);
}
.input.amount-input {
  min-height: 58px;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.input.invalid {
  border-color: var(--neg);
}
/* campo numerico: errore o valore interpretato sotto il campo */
.num-field {
  display: block;
  min-width: 0;
}
.row > .num-field {
  flex: 1 1 auto;
}
.num-msg {
  display: block;
  margin-top: 3px;
  font-size: 0.78rem;
  line-height: 1.3;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.num-msg.error {
  color: var(--neg);
}
.input.amount-input + .num-msg {
  text-align: right;
}
textarea.input {
  min-height: 70px;
  resize: vertical;
}
.form-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 600px) {
  .form-grid.cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .form-grid.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .form-grid .full {
    grid-column: 1 / -1;
  }
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.92rem;
}
.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 12px;
  background: var(--surface-3);
  border: 1px solid var(--border);
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 9px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.segmented.big {
  display: flex;
  width: 100%;
}
.segmented.big button {
  flex: 1;
  padding: 10px 18px;
  font-size: 0.98rem;
}
.segmented .on-out.active {
  color: var(--neg);
}
.segmented .on-in.active {
  color: var(--pos);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, border-color 0.12s;
}
.chip:hover {
  background: var(--surface-2);
}
/* una sola riga scorrevole (es. descrizioni suggerite): non diventa un blocco di pulsanti */
.chips.scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  margin: -4px -2px 0;
  padding: 2px 2px 6px;
  scrollbar-width: thin;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
}
.chips.scroll .chip {
  flex: none;
}
.chip.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 650;
  background: var(--surface-3);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge.pos {
  background: var(--pos-soft);
  color: var(--pos);
}
.badge.neg {
  background: var(--neg-soft);
  color: var(--neg);
}
.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.badge.info {
  background: var(--primary-soft);
  color: var(--primary);
}

/* ---------- tabelle ---------- */
.table-wrap {
  /* contiene anche gli elementi posizionati (es. testo per screen reader) */
  position: relative;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
table.data th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  text-align: left;
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tr:last-child td {
  border-bottom: 0;
}
table.data th.r,
table.data td.r {
  text-align: right;
  white-space: nowrap;
}
table.data tbody tr.clickable {
  cursor: pointer;
}
table.data tbody tr.clickable:hover td {
  background: var(--surface-2);
}
table.data tr.future td {
  color: var(--text-faint);
  font-style: italic;
}
table.data tfoot td {
  font-weight: 700;
  border-top: 2px solid var(--border-strong);
  border-bottom: 0;
}
table.matrix {
  font-size: 0.82rem;
}
table.matrix td,
table.matrix th {
  padding: 6px 8px;
}
table.matrix th:first-child,
table.matrix td:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
}
table.matrix tr.total td {
  font-weight: 700;
  background: var(--surface-2);
}
table.matrix td.zero {
  color: var(--text-faint);
}
/* origine di un valore (es. R = registro, M = misto) */
.src-tag {
  margin-left: 2px;
  font-size: 0.68em;
  font-weight: 650;
  color: var(--text-muted);
}
.chip.chip-new {
  border-style: dashed;
}

/* lista movimenti (mobile) */
.tx-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.tx-day {
  padding: 14px 18px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  display: flex;
  justify-content: space-between;
  text-transform: uppercase;
}
.tx-day .num {
  letter-spacing: 0;
}
.tx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  cursor: pointer;
  transition: background 0.1s;
}
.tx-item:hover {
  background: var(--surface-2);
}
.tx-item.future {
  opacity: 0.6;
}
.tx-icon {
  --tx-c: var(--c-other);
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  flex: none;
  background: color-mix(in srgb, var(--tx-c) 15%, var(--surface));
  color: var(--tx-c);
}
.tx-icon svg {
  width: 18px;
  height: 18px;
}
.tx-main {
  flex: 1;
  min-width: 0;
}
.tx-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tx-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tx-amount {
  font-weight: 650;
  white-space: nowrap;
}
.tx-amount.pos {
  color: var(--pos);
}

/* ---------- modale / pannello ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 14, 22, 0.48);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.15s ease-out;
}
.modal {
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow-lg);
  padding-bottom: env(safe-area-inset-bottom);
  animation: slide-up 0.18s ease-out;
}
.modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.modal-head h2 {
  flex: 1;
  font-size: 1.05rem;
}
.modal-body {
  padding: 18px;
}
.modal-foot {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
@media (min-width: 700px) {
  .overlay {
    align-items: center;
    padding: 24px;
  }
  .modal {
    max-width: 560px;
    border-radius: 18px;
  }
  .modal.wide {
    max-width: 860px;
  }
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
@keyframes slide-up {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}

.toasts {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
}
@media (min-width: 960px) {
  .toasts {
    bottom: 24px;
  }
}
.toast {
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  animation: slide-up 0.18s ease-out;
}
.toast.error {
  background: var(--neg);
  color: #fff;
}
.toast.warn {
  background: var(--warn);
  color: var(--bg);
}

/* ---------- vari ---------- */
.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
}
.empty svg {
  width: 34px;
  height: 34px;
  color: var(--text-faint);
  margin-bottom: 6px;
}
.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.9rem;
}
.alert.warn {
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 30%, transparent);
  color: var(--text);
}
.alert.error {
  background: var(--neg-soft);
  border-color: color-mix(in srgb, var(--neg) 30%, transparent);
}
.alert.info {
  background: var(--primary-soft);
  border-color: color-mix(in srgb, var(--primary) 30%, transparent);
}
.divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}
.list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child {
  border-bottom: 0;
}
.list-item.clickable {
  cursor: pointer;
}
/* righe con pulsanti: su schermi stretti i pulsanti vanno a capo invece di allargare la pagina */
.list-item.wrap {
  flex-wrap: wrap;
}
.list-item.wrap .spacer {
  flex: 1 1 140px;
  min-width: 0;
}
.item-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}
.list-item > svg {
  flex: none;
  color: var(--text-muted);
}
.list-item.clickable:hover {
  background: var(--surface-2);
}
.progress {
  height: 8px;
  border-radius: 99px;
  background: var(--surface-3);
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: var(--primary);
}
.progress.over > span {
  background: var(--neg);
}
.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--surface-3);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.loading {
  display: grid;
  place-items: center;
  padding: 40px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  overflow-x: auto;
}
.tabs button {
  border: 0;
  background: none;
  padding: 9px 12px;
  font-weight: 560;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.tabs button.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  font-size: 0.9rem;
}
.kv dt {
  color: var(--text-muted);
}
.kv dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.suggestions {
  position: absolute;
  z-index: 50;
  left: 0;
  right: 0;
  top: 100%;
  margin-top: 4px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}
.suggestions button {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
  padding: 9px 12px;
  cursor: pointer;
}
.suggestions button:hover,
.suggestions button.hl {
  background: var(--surface-2);
}
.rel {
  position: relative;
}
code,
.mono {
  font-family: var(--mono);
  font-size: 0.86em;
}

/* ---------- grafici ---------- */
.chart {
  width: 100%;
  display: block;
  overflow: visible;
}
.chart text {
  fill: var(--text-muted);
  font-size: 11px;
  font-family: var(--font);
}
.chart .grid-line {
  stroke: var(--border);
  stroke-width: 1;
}
.chart .axis-line {
  stroke: var(--border-strong);
}
.chart .zero-line {
  stroke: var(--text-faint);
  stroke-width: 1;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
}
.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chart-tip {
  position: absolute;
  pointer-events: none;
  z-index: 10;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-size: 0.8rem;
  white-space: nowrap;
}
.chart-tip b {
  font-variant-numeric: tabular-nums;
}
/* la larghezza non dipende dallo spazio a destra: ogni nome resta sulla riga del suo valore */
.chart-tip {
  width: max-content;
  max-width: none;
}
.chart-tip .row {
  flex-wrap: nowrap;
}
.donut-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.donut-legend {
  flex: 1;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.86rem;
}
.donut-legend .item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.donut-legend .item .lbl {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- login ---------- */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: radial-gradient(circle at 20% 0%, var(--primary-soft), transparent 55%), var(--bg);
}
.auth-card {
  width: min(100%, 400px);
  padding: 28px 24px;
}
.auth-card .brand {
  justify-content: center;
  padding-bottom: 6px;
  font-size: 1.15rem;
}
.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 16px;
}

@media print {
  .sidebar,
  .tabbar,
  .topbar,
  .no-print {
    display: none !important;
  }
  .shell {
    display: block;
  }
  .card {
    break-inside: avoid;
    box-shadow: none;
  }
}

/* ---------- selettore della categoria (menu a tendina con ricerca) ---------- */
.cat-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}
.picker {
  position: relative;
  min-width: 0;
}
.picker-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  cursor: pointer;
}
.picker-trigger > svg {
  margin-left: auto;
  flex: none;
  color: var(--text-muted);
  transition: transform 0.15s;
}
.picker-trigger.open {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent);
}
.picker-trigger.open > svg {
  transform: rotate(180deg);
}
.picker-value {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.picker-placeholder {
  color: var(--text-faint);
}
.picker-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.picker-panel.pop {
  position: fixed;
  z-index: 150;
  border-radius: var(--radius);
  animation: fade 0.12s ease-out;
}
.picker-overlay {
  z-index: 150;
}
.picker-panel.sheet {
  width: 100%;
  max-height: 78vh;
  border-radius: 20px 20px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: slide-up 0.18s ease-out;
}
.picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 10px 4px 18px;
  font-size: 1rem;
}
.picker-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 10px 4px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
}
.picker-search:focus-within {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent);
}
.picker-search input {
  flex: 1;
  min-width: 0;
  height: 40px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
}
@media (min-width: 960px) {
  .picker-search input {
    font-size: 0.93rem;
  }
}
.picker-list {
  overflow-y: auto;
  padding: 4px 6px 8px;
  overscroll-behavior: contain;
}
.picker-group {
  padding: 10px 10px 4px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 0.93rem;
  cursor: pointer;
}
.picker-item.hl {
  background: var(--surface-2);
}
.picker-item.sel {
  font-weight: 650;
}
.picker-item.sel > svg {
  margin-left: auto;
  color: var(--primary);
}
.picker-name {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.picker-new {
  margin-top: 4px;
  color: var(--primary);
  font-weight: 600;
  border-top: 1px solid var(--border);
  border-radius: 0 0 9px 9px;
}
.picker-new b {
  font-weight: 700;
}
.picker-empty {
  padding: 14px 10px 6px;
  color: var(--text-muted);
  font-size: 0.88rem;
}
@media (max-width: 640px) {
  .picker-item {
    min-height: 46px;
    font-size: 1rem;
  }
}

/* data con le scelte rapide (Oggi, Ieri...) sulla stessa riga */
.input.date-quick {
  flex: 1 1 140px;
  width: auto;
  max-width: 170px;
}
@media (max-width: 640px) {
  .row:has(> .date-quick) {
    gap: 6px;
    flex-wrap: nowrap;
  }
  .row:has(> .date-quick) .chip {
    padding: 6px 10px;
    flex: none;
  }
  .input.date-quick {
    min-width: 0;
    padding: 9px 8px;
  }
}

/* calcolatori della previdenza: campi compatti dentro le tabelle */
.calc-table td {
  vertical-align: middle;
}
.calc-table .num-field,
.calc-table .input.calc-input {
  min-width: 90px;
}
.calc-table .input.calc-input {
  min-height: 34px;
  padding: 4px 8px;
}
.calc-table td.r .input.calc-input {
  text-align: right;
}
