/* Casa & Conti — stile: pulito, leggibile, rassicurante. */
:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --border: #e2e5ea; --border-strong: #cfd4dc;
  --text: #17202b; --text-2: #4b5563; --muted: #6b7280;
  --primary: #1f4e79; --primary-2: #163a5c; --primary-soft: #e6eef6;
  --green: #15803d; --green-soft: #e8f5ec; --red: #b91c1c; --red-soft: #fdecec; --orange: #c2410c; --orange-soft: #fff1e6;
  --blue-soft: #eaf2fb;
  --radius: 12px; --radius-s: 8px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 64px; --side-w: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a; --surface: #161d25; --surface-2: #1d2630; --border: #29333f; --border-strong: #38444f;
    --text: #e8edf2; --text-2: #b8c1cc; --muted: #8a95a3;
    --primary: #6ea8dc; --primary-2: #8bbbe6; --primary-soft: #1a2a3a;
    --green: #4ade80; --green-soft: #12291b; --red: #f87171; --red-soft: #2d1515; --orange: #fb923c; --orange-soft: #2e1d10; --blue-soft: #15222f;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.45; color: var(--text); background: var(--bg); overflow-x: hidden; }
body.modal-open { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; margin: 1rem 0 .5rem; color: var(--text-2); }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { max-width: 100%; }
.icon { flex: none; vertical-align: middle; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; top: 0; background: var(--primary); color: #fff; padding: .5rem 1rem; z-index: 100; }
.skip:focus { left: 1rem; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ───── Layout ───── */
#app { min-height: 100vh; }
.sidebar { display: none; }
.content { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top)); background: var(--surface); border-bottom: 1px solid var(--border); }
main { padding: 1rem; padding-bottom: calc(var(--nav-h) + 2.5rem + env(safe-area-inset-bottom)); outline: none; max-width: 1400px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); text-decoration: none !important; min-width: 0; }
.brand span { display: flex; flex-direction: column; min-width: 0; }
.brand strong { font-size: 1.05rem; }
.brand small { color: var(--muted); font-size: .75rem; }
.bottom-nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(5, 1fr); }
.bottom-nav a, .bottom-nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .7rem; color: var(--muted); background: none; border: 0; text-decoration: none; min-width: 0; padding: 0; cursor: pointer; }
.bottom-nav .on { color: var(--primary); font-weight: 600; }
.fab { position: fixed; z-index: 31; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 18px); width: 60px; height: 60px; border-radius: 50%; border: 4px solid var(--bg); background: var(--primary); color: #fff; display: grid; place-items: center; box-shadow: 0 6px 16px rgba(31, 78, 121, .35); cursor: pointer; }
.fab:active { transform: translateX(-50%) scale(.96); }
.demo-banner { background: var(--orange-soft); color: var(--orange); font-size: .85rem; padding: .45rem 1rem; display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.demo-banner a { color: inherit; text-decoration: underline; }

@media (min-width: 1024px) {
  #app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .sidebar { display: flex; flex-direction: column; gap: .6rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 1rem .8rem; background: var(--surface); border-right: 1px solid var(--border); }
  .sidebar .brand { padding: .25rem .4rem .8rem; }
  .side-nav { display: flex; flex-direction: column; gap: 2px; margin-top: .5rem; }
  .side-nav a { display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: var(--radius-s); color: var(--text-2); text-decoration: none; font-weight: 500; }
  .side-nav a:hover { background: var(--surface-2); }
  .side-nav a.on { background: var(--primary-soft); color: var(--primary); font-weight: 650; }
  .sidebar .logout { margin-top: auto; }
  .topbar, .bottom-nav, .fab { display: none; }
  main { padding: 1.5rem 2rem 3rem; }
}

/* ───── Pagina ───── */
.page { display: flex; flex-direction: column; gap: 1rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; }
.toolbar-right { display: flex; flex-wrap: wrap; gap: .5rem; margin-left: auto; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--border); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { white-space: nowrap; padding: .55rem .8rem; color: var(--text-2); border-bottom: 2px solid transparent; text-decoration: none; font-weight: 500; }
.tabs a.on { color: var(--primary); border-color: var(--primary); font-weight: 650; }
.split { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); align-items: start; }
.col { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
@media (min-width: 900px) { .split { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); min-width: 0; }
.card-title { margin-bottom: .75rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; flex-wrap: wrap; }
.card-head .card-title { margin: 0; }
.card-actions { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; margin-bottom: .5rem; }
.card-head .card-actions { margin: 0; }
.section-title { margin: .5rem 0 0; }
.note { font-size: .85rem; color: var(--muted); margin: 0; display: flex; gap: .35rem; align-items: flex-start; flex-wrap: wrap; }
.warn-text { color: var(--orange); font-size: .9rem; }
.stack { display: flex; flex-direction: column; gap: .5rem; align-items: stretch; }
.stack-row { display: flex; gap: .5rem; flex-wrap: wrap; }
hr { border: 0; border-top: 1px solid var(--border); margin: .5rem 0; width: 100%; }

/* ───── KPI ───── */
.kpis { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem .9rem; min-width: 0; }
.card .kpi { background: var(--surface-2); border-color: transparent; }
.kpi-label { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.kpi-value { font-size: 1.35rem; font-weight: 700; margin-top: .15rem; overflow-wrap: anywhere; }
.kpi-value.small { font-size: 1.05rem; }
.kpi-sub { font-size: .8rem; color: var(--muted); margin-top: .2rem; }
.kpi-bad { border-color: var(--red); background: var(--red-soft); }
.kpi-good .kpi-value { color: inherit; }

/* ───── Importi e badge ───── */
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money.strong { font-weight: 700; }
.money.pos { color: var(--green); }
.money.neg { color: var(--red); }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .1rem .45rem; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge-eseguito { background: var(--green-soft); color: var(--green); }
.badge-confermato { background: var(--blue-soft); color: var(--primary); }
.badge-previsto { background: var(--surface-2); color: var(--muted); border: 1px dashed var(--border-strong); }
.badge-annullato { text-decoration: line-through; }
.badge-red { background: var(--red-soft); color: var(--red); }

/* ───── Avvisi ───── */
.alert { display: flex; gap: .6rem; align-items: flex-start; padding: .75rem 1rem; border-radius: var(--radius); border: 1px solid; font-size: .95rem; }
.alert-red { background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 40%, transparent); color: var(--red); }
.alert-orange { background: var(--orange-soft); border-color: color-mix(in srgb, var(--orange) 40%, transparent); color: var(--orange); }
.alert-info { background: var(--blue-soft); border-color: color-mix(in srgb, var(--primary) 30%, transparent); color: var(--primary); }
.alert a { color: inherit; text-decoration: underline; }

/* ───── Bottoni ───── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-height: 40px; padding: .45rem .9rem; border-radius: var(--radius-s); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-weight: 550; cursor: pointer; text-decoration: none !important; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger-ghost { color: var(--red); border-color: color-mix(in srgb, var(--red) 45%, transparent); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-small { min-height: 32px; padding: .25rem .6rem; font-size: .85rem; }
.btn-block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: var(--radius-s); border: 0; background: transparent; color: var(--text-2); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger { color: var(--red); }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; text-align: left; }
.file-btn { position: relative; }
.chips-row { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .75rem; }
.chip { display: inline-flex; align-items: center; gap: .2rem; border: 1px solid var(--border-strong); background: var(--surface); padding: .35rem .7rem; border-radius: 999px; font-size: .85rem; cursor: pointer; }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip-in:hover { border-color: var(--green); color: var(--green); }
.quick-links { display: flex; flex-direction: column; gap: .5rem; }
.quick-links .btn { justify-content: flex-start; }

/* ───── Filtri, controlli ───── */
.segmented { display: inline-flex; flex-wrap: wrap; background: var(--surface-2); border-radius: var(--radius-s); padding: 3px; gap: 2px; max-width: 100%; }
.seg { border: 0; background: transparent; padding: .4rem .75rem; border-radius: 6px; cursor: pointer; color: var(--text-2); font-weight: 550; min-height: 34px; }
.seg.on { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chips .seg { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; min-height: 40px; }
.chips .seg.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.month-picker { display: inline-flex; align-items: center; gap: .15rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-s); padding: 2px; }
.month-picker input[type=month] { width: 0; height: 0; opacity: 0; position: absolute; pointer-events: none; }
.month-label { min-width: 8.5rem; text-align: center; font-weight: 600; text-transform: capitalize; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.filter { display: flex; flex-direction: column; gap: .2rem; font-size: .8rem; color: var(--muted); min-width: 0; flex: 1 1 150px; max-width: 260px; }
.filter.grow { flex: 2 1 220px; max-width: none; }
.filter-check { flex-direction: row; align-items: center; gap: .4rem; font-size: .9rem; color: var(--text); flex: 0 0 auto; min-height: 40px; }
.more-filters summary { cursor: pointer; color: var(--primary); font-weight: 550; padding: .25rem 0; }
.more-filters .filters { margin-top: .5rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=month], input[type=search], select, textarea {
  width: 100%; min-height: 42px; padding: .45rem .65rem; border: 1px solid var(--border-strong); border-radius: var(--radius-s); background: var(--surface); font-size: 16px; min-width: 0;
}
textarea { resize: vertical; }
input[type=color] { width: 56px; height: 42px; padding: 2px; border: 1px solid var(--border-strong); border-radius: var(--radius-s); background: var(--surface); }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--primary); flex: none; }
.money-input { font-size: 1.15rem !important; font-variant-numeric: tabular-nums; }

/* ───── Moduli ───── */
.form { display: flex; flex-direction: column; gap: .9rem; }
.form-grid { display: grid; gap: .75rem 1rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field.full, .form-section { grid-column: 1 / -1; }
.field > label { font-weight: 600; font-size: .88rem; color: var(--text-2); }
.field .check { display: flex; align-items: center; gap: .55rem; font-weight: 500; color: var(--text); cursor: pointer; min-height: 40px; }
.req { color: var(--red); }
.hint { color: var(--muted); font-size: .78rem; min-height: 0; }
.hint:empty { display: none; }
.form-section { font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-top: 1px solid var(--border); padding-top: .8rem; margin-top: .2rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; }
.form-errors { background: var(--red-soft); color: var(--red); border-radius: var(--radius-s); padding: .6rem .8rem; margin: 0; }
.form-errors ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: .25rem; }
.error-list { color: var(--red); }

/* ───── Modali ───── */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(15, 20, 26, .45); display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 0 1rem calc(1rem + env(safe-area-inset-bottom)); box-shadow: 0 10px 40px rgba(0, 0, 0, .2); overscroll-behavior: contain; }
.modal-head { position: sticky; top: 0; background: var(--surface); display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .9rem 0 .6rem; z-index: 1; }
.modal-body { display: flex; flex-direction: column; gap: .8rem; }
@media (min-width: 700px) {
  .overlay { align-items: center; padding: 1.5rem; }
  .modal { max-width: 520px; border-radius: 16px; max-height: 88vh; padding-bottom: 1.25rem; }
  .modal-wide { max-width: 760px; }
}
.confirm-msg { margin: 0; white-space: pre-line; }
.choice-list { display: flex; flex-direction: column; gap: .5rem; }
.choice { text-align: left; border: 1px solid var(--border-strong); border-radius: var(--radius-s); background: var(--surface); padding: .7rem .9rem; cursor: pointer; display: flex; flex-direction: column; gap: .15rem; }
.choice:hover { border-color: var(--primary); background: var(--primary-soft); }
.choice span { color: var(--muted); font-size: .85rem; }
.sheet-overlay { position: fixed; inset: 0; z-index: 40; background: rgba(15, 20, 26, .4); display: flex; align-items: flex-end; }
.sheet { background: var(--surface); width: 100%; border-radius: 16px 16px 0 0; padding: 1rem 1rem calc(var(--nav-h) + 1rem + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: .75rem; }
.sheet-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; }
.sheet-grid a { display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: .8rem .3rem; border-radius: var(--radius-s); background: var(--surface-2); color: var(--text); text-align: center; font-size: .82rem; text-decoration: none; }

/* ───── Elenchi movimenti ───── */
.entries { list-style: none; margin: 0; padding: 0; }
.entry { display: grid; grid-template-columns: 46px minmax(0, 1fr) auto 40px; align-items: center; gap: .5rem; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.entry:last-child { border-bottom: 0; }
.entry.cancelled { opacity: .55; }
.entry.cancelled .entry-title { text-decoration: line-through; }
.entry.overdue .entry-date { background: var(--red-soft); color: var(--red); }
.entry.soon .entry-date { background: var(--orange-soft); color: var(--orange); }
.entry.done { opacity: .7; }
.entry-date { display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--surface-2); border-radius: var(--radius-s); padding: .25rem 0; line-height: 1.05; }
.entry-date .d { font-weight: 700; font-size: 1.05rem; }
.entry-date .m { font-size: .62rem; color: inherit; opacity: .75; white-space: nowrap; }
.entry-main { display: flex; flex-direction: column; min-width: 0; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; }
.entry-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: .25rem; }
.entry-meta { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-right { display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; }
.exec { color: var(--green); border: 1px solid color-mix(in srgb, var(--green) 35%, transparent); }
.exec:hover { background: var(--green-soft); color: var(--green); }
.exec-placeholder { width: 40px; }
.group-head { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .9rem 0 .3rem; border-bottom: 1px solid var(--border); }
.entries .group-head:first-child { padding-top: 0; }
.totals-line { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; font-size: .9rem; color: var(--text-2); margin-bottom: .5rem; }
.empty { text-align: center; padding: 1.5rem .5rem; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: .75rem; }
.empty p { margin: 0; }
.empty-inline { margin: .25rem 0; }
.mini-list { list-style: none; margin: .5rem 0; padding: 0; }
.mini-list li { display: flex; justify-content: space-between; gap: .75rem; padding: .35rem 0; border-bottom: 1px dashed var(--border); font-size: .9rem; }
.mini-list li > span:first-child { min-width: 0; overflow-wrap: anywhere; }

.acc-list, .agenda-mini { list-style: none; margin: 0; padding: 0; }
.acc-list li { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .55rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.acc-list li:last-child, .agenda-mini li:last-child { border-bottom: 0; }
.acc-list li > div:first-child, .link-block { display: flex; flex-direction: column; min-width: 0; flex: 1 1 140px; }
.link-block { background: none; border: 0; text-align: left; padding: 0; cursor: pointer; color: inherit; }
.acc-list small, .link-block small { color: var(--muted); font-size: .8rem; }
.acc-list .right { display: flex; flex-direction: column; align-items: flex-end; }
.acc-list .archived, .archived { opacity: .55; }
.acc-list .budget { flex-wrap: wrap; }
.meter { flex: 1 0 100%; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter-fill { display: block; height: 100%; background: var(--green); }
.meter-fill.warn { background: var(--orange); }
.meter-fill.bad { background: var(--red); }
.agenda-mini li { display: grid; grid-template-columns: 5.6rem minmax(0, 1fr) auto; align-items: center; gap: .5rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.agenda-mini .date { font-variant-numeric: tabular-nums; font-size: .88rem; color: var(--text-2); }
.agenda-mini .title { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.agenda-mini .title small { color: var(--muted); font-size: .78rem; }
.agenda-mini .soon .date { color: var(--orange); font-weight: 700; }
.agenda-mini .late .date { color: var(--red); font-weight: 700; }

.grid-cards { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); }
.tile { display: flex; flex-direction: column; gap: .3rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; color: inherit; text-decoration: none !important; box-shadow: var(--shadow); min-width: 0; }
.tile:hover { border-color: var(--primary); }
.tile-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.tile-sub { font-size: .82rem; color: var(--muted); }
.tile-value { font-size: 1.3rem; margin: .2rem 0; }
.tile-value small { font-size: .8rem; color: var(--muted); }

.pill-list, .cat-tree, .cat-tree ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.cat-tree { flex-direction: column; gap: .6rem; }
.cat-tree ul { margin: .35rem 0 0 1rem; }
.pill { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: .3rem .7rem; cursor: pointer; font-size: .88rem; }
.pill:hover { border-color: var(--primary); }
.pill-sub { font-size: .82rem; background: var(--surface-2); border-color: transparent; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: middle; }

/* ───── Tabelle ───── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 650; padding: .5rem; border-bottom: 1px solid var(--border-strong); white-space: nowrap; }
.table td { padding: .55rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table.compact td, .table.compact th { padding: .35rem .5rem; }
.table .num { text-align: right; white-space: nowrap; }
.table .sub { font-size: .78rem; color: var(--muted); }
.table .actions { white-space: nowrap; text-align: right; }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--border-strong); }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.row-neg td { background: var(--red-soft); }
.muted-row { opacity: .55; }

/* ───── Grafici ───── */
.chart { margin: 0 0 .75rem; }
.chart svg { width: 100%; height: 220px; display: block; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .zero { stroke: var(--red); stroke-dasharray: 4 4; stroke-width: 1.2; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line-all { fill: none; stroke: var(--primary); stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.chart .line-confirmed { fill: none; stroke: var(--green); stroke-width: 2; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
.chart .dot { fill: var(--primary); }
.chart .dot-neg { fill: var(--red); }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .8rem; color: var(--muted); margin-top: .35rem; }
.lg::before { content: ""; display: inline-block; width: 14px; height: 4px; border-radius: 2px; margin-right: .35rem; vertical-align: middle; }
.lg-all::before { background: var(--primary); }
.lg-confirmed::before { background: repeating-linear-gradient(90deg, var(--green) 0 5px, transparent 5px 8px); }
.lg-neg::before { background: var(--red); width: 8px; height: 8px; border-radius: 50%; }
.lg-cur::before { background: var(--primary); }
.lg-prev::before { background: var(--border-strong); }
.lg-inc::before { background: var(--green); }
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) 9.5rem; align-items: center; gap: .6rem; width: 100%; padding: .3rem .2rem; border-radius: 6px; }
.bar-row.link { background: none; border: 0; cursor: pointer; text-align: left; }
.bar-row.link:hover { background: var(--surface-2); }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.bar-value { font-variant-numeric: tabular-nums; font-size: .88rem; white-space: nowrap; text-align: right; }
.bar-value small { color: var(--muted); }
.month-bars { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; height: 160px; align-items: end; }
.mb-col { display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.mb-bars { flex: 1; display: flex; align-items: flex-end; gap: 1px; width: 100%; justify-content: center; }
.mb { width: 30%; max-width: 10px; border-radius: 2px 2px 0 0; min-height: 1px; }
.mb.cur { background: var(--primary); }
.mb.prev { background: var(--border-strong); }
.mb.inc { background: var(--green); }
.mb-label { font-size: .65rem; color: var(--muted); margin-top: 3px; }

/* ───── Calendario ───── */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.cal-wd { font-size: .7rem; text-transform: uppercase; color: var(--muted); text-align: center; padding: .2rem 0; }
.cal-cell { min-height: 74px; background: var(--surface-2); border-radius: 6px; padding: 3px; display: flex; flex-direction: column; gap: 2px; min-width: 0; overflow: hidden; }
.cal-cell.empty { background: transparent; }
.cal-cell.today { outline: 2px solid var(--primary); }
.cal-cell.has-overdue .cal-day { color: var(--red); }
.cal-day { font-size: .75rem; font-weight: 700; color: var(--text-2); }
.cal-item { font-size: .66rem; line-height: 1.2; text-align: left; border: 0; border-radius: 3px; padding: 1px 3px; background: var(--surface); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; border-left: 3px solid var(--border-strong); }
.cal-item.in { border-left-color: var(--green); }
.cal-item.out { border-left-color: var(--primary); }
.cal-item.plain { border-left-color: var(--orange); }
.cal-item.overdue { background: var(--red-soft); color: var(--red); }
.cal-item.done { opacity: .55; }
.cal-more { font-size: .65rem; color: var(--muted); }
@media (max-width: 560px) { .cal-cell { min-height: 54px; } .cal-item { font-size: 0; height: 6px; padding: 0; border-left-width: 0; } .cal-item.in { background: var(--green); } .cal-item.out { background: var(--primary); } .cal-item.plain { background: var(--orange); } .cal-item.overdue { background: var(--red); } }

/* ───── Accesso e caricamento ───── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 1.5rem; display: flex; flex-direction: column; gap: .6rem; box-shadow: var(--shadow); }
.login-card h1 { margin-top: .3rem; }
.login-card label { font-weight: 600; font-size: .9rem; margin-top: .3rem; }
.login-card .btn { margin-top: .6rem; }
.loading { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }

/* ───── Notifiche ───── */
#toasts { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 1.5rem + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: .4rem; width: min(92vw, 420px); pointer-events: none; }
@media (min-width: 1024px) { #toasts { bottom: 1.5rem; } }
.toast { background: var(--text); color: var(--surface); padding: .65rem 1rem; border-radius: var(--radius-s); box-shadow: 0 6px 20px rgba(0, 0, 0, .2); transition: opacity .4s; font-size: .92rem; }
.toast-error { background: var(--red); color: #fff; }
.toast.out { opacity: 0; }

@media (max-width: 420px) {
  .bar-row { grid-template-columns: minmax(0, 1fr) 8.5rem; }
  .bar-track { grid-column: 1 / -1; grid-row: 2; }
  main { padding-left: .75rem; padding-right: .75rem; }
  .entry { grid-template-columns: 42px minmax(0, 1fr) auto 36px; gap: .4rem; }
  .icon-btn.exec { width: 36px; height: 36px; }
  .exec-placeholder { width: 36px; }
  .kpi-value { font-size: 1.15rem; }
  .month-label { min-width: 7rem; font-size: .9rem; }
  .page-head h1 { width: 100%; }
}
@media print { .sidebar, .bottom-nav, .fab, .topbar, .demo-banner, .page-actions button { display: none !important; } #app { display: block; } body { background: #fff; } }

/* ═════ Tema colorato (v1.1) ═════ */
:root { --bg: #f4f6fb; --primary: #4f46e5; --primary-2: #4338ca; --primary-soft: #eef0ff; }
@media (prefers-color-scheme: dark) { :root { --primary: #a5b4fc; --primary-2: #c7d2fe; --primary-soft: #23264a; } }
.c-green { --c: #10b981; } .c-coral { --c: #f43f5e; } .c-red { --c: #dc2626; } .c-orange { --c: #f97316; }
.c-violet { --c: #8b5cf6; } .c-amber { --c: #f59e0b; } .c-sky { --c: #0ea5e9; } .c-blue { --c: #3b82f6; }
.page-sub { margin: .2rem 0 0; }
.hero { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); padding: 1.25rem 1.4rem; border-radius: 20px; color: #fff;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #db2777 100%); box-shadow: 0 10px 30px rgba(79, 70, 229, .25); }
.hero-bad { background: linear-gradient(135deg, #b91c1c, #ea580c); }
.hero-block { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.hero-q { font-size: .95rem; opacity: .9; font-weight: 500; }
.hero-amount { font-size: clamp(2rem, 7vw, 2.8rem); font-weight: 800; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hero-amount.small { font-size: clamp(1.5rem, 5vw, 2rem); }
.hero-sub { font-size: .85rem; opacity: .85; }
.hero-right { padding-top: .9rem; border-top: 1px solid rgba(255, 255, 255, .25); }
@media (min-width: 700px) { .hero { grid-template-columns: 3fr 2fr; align-items: end; } .hero-right { border-top: 0; padding-top: 0; padding-left: 1.2rem; border-left: 1px solid rgba(255, 255, 255, .25); } }
.answers { display: grid; gap: .75rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 1100px) { .answers { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.answer { display: flex; flex-direction: column; gap: .2rem; padding: .9rem 1rem; border-radius: 16px; background: var(--surface); color: var(--text); text-decoration: none !important;
  border: 1px solid var(--border); border-top: 4px solid var(--c); box-shadow: var(--shadow); min-width: 0; transition: transform .12s; }
.answer:hover { transform: translateY(-2px); }
.answer-ico { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); margin-bottom: .2rem; }
.answer-q { font-size: .85rem; color: var(--text-2); font-weight: 600; }
.answer-v { font-size: 1.3rem; color: var(--c); overflow-wrap: anywhere; }
.answer-v .money { color: inherit; }
.answer-sub { font-size: .78rem; color: var(--muted); overflow-wrap: anywhere; }
.quick-actions { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .5rem; }
.qa { display: flex; flex-direction: column; align-items: center; gap: .35rem; padding: .7rem .2rem; border-radius: 16px; border: 0; cursor: pointer;
  background: color-mix(in srgb, var(--c) 12%, var(--surface)); color: color-mix(in srgb, var(--c) 75%, var(--text)); font-weight: 650; font-size: .82rem; min-width: 0; }
.qa:hover { background: color-mix(in srgb, var(--c) 20%, var(--surface)); }
.qa-ico { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--c); color: #fff; box-shadow: 0 4px 10px color-mix(in srgb, var(--c) 40%, transparent); }
@media (min-width: 900px) { .quick-actions { grid-template-columns: repeat(5, minmax(0, 160px)); } }
.kpi { border-top: 3px solid var(--border); }
.kpis .kpi:nth-child(1) { border-top-color: #4f46e5; } .kpis .kpi:nth-child(2) { border-top-color: #8b5cf6; } .kpis .kpi:nth-child(3) { border-top-color: #10b981; }
.kpis .kpi:nth-child(4) { border-top-color: #f43f5e; } .kpis .kpi:nth-child(5) { border-top-color: #0ea5e9; } .kpis .kpi:nth-child(6) { border-top-color: #f59e0b; }
.kpi-bad { border-top-color: var(--red) !important; }
.card { border-radius: 16px; }
.nav-ico { width: 32px; height: 32px; border-radius: 10px; display: inline-grid; place-items: center; color: var(--c, var(--primary)); background: color-mix(in srgb, var(--c, var(--primary)) 13%, transparent); flex: none; }
.nav-ico.big { width: 48px; height: 48px; border-radius: 14px; }
.side-nav a.on { background: color-mix(in srgb, var(--c) 10%, transparent); color: var(--text); }
.side-nav a.on .nav-ico { background: var(--c); color: #fff; }
.sidebar .btn-primary, .btn-primary { background: linear-gradient(135deg, #4f46e5, #7c3aed); border-color: transparent; }
.fab { background: linear-gradient(135deg, #4f46e5, #db2777); box-shadow: 0 8px 20px rgba(124, 58, 237, .4); }
.bottom-nav .on { color: #7c3aed; }
.entry-date { background: color-mix(in srgb, var(--c, #94a3b8) 14%, transparent); color: color-mix(in srgb, var(--c, #64748b) 80%, var(--text)); }
.entry { border-left: 3px solid var(--c, transparent); padding-left: .5rem; }
.bar-fill { background: var(--c, var(--primary)); }
.tile { border-top: 4px solid #8b5cf6; }
.grid-cards .tile:nth-child(3n+2) { border-top-color: #0ea5e9; } .grid-cards .tile:nth-child(3n+3) { border-top-color: #f97316; }
.tabs a.on { color: #7c3aed; border-color: #7c3aed; }
.seg.on { color: #4f46e5; }
.chips .seg.on { background: #7c3aed; border-color: #7c3aed; color: #fff; }
.demo-banner { background: linear-gradient(90deg, #fff7ed, #fdf2f8); }
@media (prefers-color-scheme: dark) { .demo-banner { background: var(--orange-soft); } }
@media (max-width: 420px) { .qa { font-size: .72rem; } .qa-ico { width: 40px; height: 40px; } .answer-v { font-size: 1.1rem; } .answer { padding: .75rem; } }
