/* Famiglia — stile
   Nebbia + inchiostro blu notte; cobalto per le azioni, zafferano solo per "oggi" e "fatto".
   Titoli: Bricolage Grotesque. Testo: Figtree. Entrambi serviti dal sito stesso (cartella /fonts). */

@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/fonts/BricolageGrotesque-Variable.woff2") format("woff2");
  font-weight: 200 800; font-stretch: 75% 100%; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Figtree";
  src: url("/fonts/Figtree-Variable.woff2") format("woff2");
  font-weight: 300 900; font-style: normal; font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #eef1ef;
  --surface: #ffffff;
  --surface-2: #e5eae7;
  --ink: #14202a;
  --ink-2: #46555f;
  --line: #d5dcd8;
  --brand: #2c3ea8;
  --brand-ink: #ffffff;
  --brand-text: #2c3ea8;
  --saffron: #ffc93c;
  --saffron-ink: #3a2a00;
  --danger: #b3261e;
  --ok: #1f6f43;
  --s1: #2a78d6;
  --s2: #eb6834;
  --shadow: 0 1px 2px rgba(20, 32, 42, .07), 0 6px 20px rgba(20, 32, 42, .06);
  --display: "Bricolage Grotesque", "Figtree", system-ui, sans-serif;
  --sans: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --nav-h: 64px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f141b;
  --surface: #18202a;
  --surface-2: #222c38;
  --ink: #e8eef2;
  --ink-2: #a2b0ba;
  --line: #2b3642;
  --brand: #4d60d8;
  --brand-text: #a3b0ff;
  --danger: #ff8a80;
  --ok: #6fd39b;
  --s1: #3987e5;
  --s2: #d95926;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .25);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f141b;
    --surface: #18202a;
    --surface-2: #222c38;
    --ink: #e8eef2;
    --ink-2: #a2b0ba;
    --line: #2b3642;
    --brand: #4d60d8;
    --brand-text: #a3b0ff;
    --danger: #ff8a80;
    --ok: #6fd39b;
    --s1: #3987e5;
    --s2: #d95926;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: -.015em; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--brand-text); outline-offset: 2px; border-radius: 6px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- struttura ---------- */
.shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-width: 1120px;
  margin: 0 auto;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 6px;
}
.brand { font-family: var(--display); font-size: 24px; font-weight: 800; letter-spacing: -.03em; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.sync { font-size: 13px; color: var(--ink-2); }
.sync.off { color: var(--danger); font-weight: 600; }
.sync:empty { display: none; }

main.view { padding: 4px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 96px); width: 100%; min-width: 0; }
main.view[data-page="shopping"], main.view[data-page="account"] { max-width: 720px; margin-inline: auto; }
main.view[data-page="expenses"] { max-width: 1000px; margin-inline: auto; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-inner { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; max-width: 760px; }
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--nav-h); border: 0; background: none; color: var(--ink-2);
  font-size: 12px; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--brand-text); }
.tab[aria-current="page"] svg { stroke-width: 2.4; }

@media (min-width: 900px) {
  .shell {
    grid-template-columns: auto 1fr auto; grid-template-rows: auto 1fr;
    padding-inline: 24px; column-gap: 16px; align-items: center;
  }
  .topbar { display: contents; }
  .brand { grid-column: 1; grid-row: 1; padding-top: 10px; }
  .top-actions { grid-column: 3; grid-row: 1; padding-top: 10px; }
  .nav { grid-column: 2; grid-row: 1; position: static; border: 0; background: none; padding: 10px 0 0; justify-content: center; }
  .nav-inner { display: flex; width: auto; max-width: none; gap: 4px; padding: 4px; border-radius: 999px; background: var(--surface-2); }
  .tab { flex-direction: row; gap: 8px; height: 40px; padding: 0 18px; border-radius: 999px; font-size: 15px; }
  .tab svg { width: 20px; height: 20px; }
  .tab[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
  main.view { grid-column: 1 / -1; grid-row: 2; align-self: start; padding: 20px 0 96px; }
  .fab { right: max(24px, calc(50vw - 560px + 24px)); bottom: 28px !important; }
  .toast { bottom: 28px; }
}

/* ---------- elementi comuni ---------- */
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-grid; place-items: center; flex: none;
  color: #fff; font-weight: 700; font-size: 15px;
}
.avatar.sm { width: 24px; height: 24px; font-size: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--surface); font-weight: 600;
}
.btn:hover { border-color: color-mix(in srgb, var(--ink-2) 50%, var(--line)); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.btn.ghost { border-color: transparent; background: none; color: var(--brand-text); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn[disabled] { opacity: .55; cursor: default; }
.btn svg { width: 20px; height: 20px; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: none;
  display: grid; place-items: center; color: var(--ink); flex: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.sm { width: 38px; height: 38px; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 15;
  height: 56px; padding: 0 22px 0 18px; border-radius: 28px; border: 0;
  background: var(--brand); color: var(--brand-ink); font-weight: 700;
  display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 6px 18px rgba(44, 62, 168, .4);
}
.fab svg { width: 22px; height: 22px; }

.card { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); padding: 16px; }
.stack { display: grid; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }
.title { font-family: var(--display); font-size: 28px; font-weight: 700; letter-spacing: -.025em; line-height: 1.1; }
.h2 { font-family: var(--sans); font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); margin: 26px 2px 8px; }

.field { display: grid; gap: 6px; }
.field > span, legend { font-size: 14px; font-weight: 600; color: var(--ink-2); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
input[type="text"], input[type="password"], input[type="date"], input[type="time"], input[type="search"], input[type="number"], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface);
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid color-mix(in srgb, var(--brand-text) 35%, transparent); border-color: var(--brand-text); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; font-weight: 600; }
.switch input { width: 48px; height: 28px; appearance: none; border-radius: 14px; background: var(--line); position: relative; cursor: pointer; flex: none; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { transform: translateX(20px); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px;
  border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); font-size: 15px; font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

/* controllo a segmenti (vista calendario, tema) */
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 12px; background: var(--surface-2); }
.seg button {
  flex: 1; min-height: 36px; padding: 0 14px; border: 0; border-radius: 9px; background: none;
  font-size: 14px; font-weight: 600; color: var(--ink-2); white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
.seg.wide { display: flex; }

.empty { text-align: center; padding: 36px 16px; color: var(--ink-2); }
.empty strong { display: block; color: var(--ink); font-family: var(--display); font-size: 21px; letter-spacing: -.015em; margin-bottom: 4px; }

.error { color: var(--danger); font-weight: 600; font-size: 15px; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }

/* ---------- accesso ---------- */
.login { max-width: 420px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 56px) 20px 32px; display: grid; gap: 22px; }
.login .title { font-size: 40px; font-weight: 800; letter-spacing: -.035em; }
.login .lead { color: var(--ink-2); margin-top: 8px; }
.login .mark { width: 64px; height: 64px; border-radius: 18px; }

/* ---------- calendario: barra comandi ---------- */
.cal-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 2px 0 12px; }
.cal-top { display: flex; align-items: center; gap: 2px; flex: 1 1 320px; min-width: 0; }
.cal-title {
  flex: 1; min-width: 0; margin: 0 6px; font-size: clamp(20px, 5.4vw, 30px); font-weight: 700; letter-spacing: -.025em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-toolbar .seg { flex: 0 0 auto; }
@media (max-width: 639px) { .cal-toolbar .seg { width: 100%; } .cal-toolbar .seg button { padding: 0 6px; } }

.cal-layout { display: grid; gap: 18px; }
.cal-side-h { font-size: 20px; margin-bottom: 10px; }
.cal-side-h::first-letter, .cap::first-letter { text-transform: uppercase; }
@media (min-width: 1000px) {
  .cal-layout.has-side { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
  .cal-side { position: sticky; top: 16px; }
}

/* ---------- calendario: mese ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.cal-dow { text-align: center; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2); padding: 4px 0 6px; }
.cal-day {
  position: relative; min-width: 0; height: clamp(50px, 14vw, 60px);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 3px;
  padding-top: 6px; border: 0; border-radius: 14px; background: transparent; font-size: 16px; font-weight: 600;
}
.cal-day.out { color: var(--ink-2); opacity: .5; }
.cal-day .num { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; font-variant-numeric: tabular-nums; }
.cal-day.today .num { background: var(--saffron); color: var(--saffron-ink); font-weight: 800; }
.cal-day.sel { background: var(--surface); box-shadow: inset 0 0 0 2px var(--brand-text); }
.dots { display: flex; gap: 3px; height: 7px; }
.dot { width: 7px; height: 7px; border-radius: 50%; }
.dot.more { background: var(--ink-2); }
.mev, .mev-more { display: none; }

@media (min-width: 900px) {
  .cal-grid { gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
  .cal-dow { background: var(--surface); padding: 10px 0; }
  .cal-day {
    height: auto; min-height: 116px; align-items: stretch; gap: 4px; padding: 6px 6px 8px;
    border-radius: 0; background: var(--surface); text-align: left; font-size: 14px;
  }
  .cal-day .num { width: 28px; height: 28px; font-size: 14px; }
  .cal-day.out { opacity: 1; background: color-mix(in srgb, var(--surface) 55%, var(--bg)); color: var(--ink-2); }
  .cal-day.sel { box-shadow: inset 0 0 0 2px var(--brand-text); }
  .dots { display: none; }
  .mev {
    display: block; width: 100%; padding: 2px 6px; border-radius: 6px; font-size: 12.5px; font-weight: 600; line-height: 1.35;
    border-left: 3px solid var(--c); background: color-mix(in srgb, var(--c) 18%, var(--surface));
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink);
  }
  .mev i { font-style: normal; font-weight: 500; color: var(--ink-2); margin-right: 4px; font-variant-numeric: tabular-nums; }
  .mev-more { display: block; font-size: 12px; font-weight: 700; color: var(--ink-2); padding-left: 4px; }
}

/* elenco eventi del giorno (pannello laterale / sotto il mese) */
.ev { display: flex; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); width: 100%; text-align: left; border: 0; }
.ev + .ev { margin-top: 8px; }
.ev .bar { width: 5px; border-radius: 3px; flex: none; }
.ev-time { font-size: 14px; color: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.ev-title { font-weight: 700; }
.ev-note { font-size: 14px; color: var(--ink-2); margin-top: 2px; white-space: pre-line; }

/* ---------- calendario: griglia oraria (settimana, 3 giorni) ---------- */
.tg-scroll {
  --hh: 56px; --gut: 38px;
  position: relative; overflow: auto; overscroll-behavior: contain;
  max-height: clamp(340px, calc(100dvh - 330px), 820px);
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
}
@media (min-width: 900px) { .tg-scroll { --hh: 60px; --gut: 56px; max-height: clamp(420px, calc(100dvh - 230px), 860px); } }
.tg-top { position: sticky; top: 0; z-index: 4; background: var(--surface); border-bottom: 1px solid var(--line); }
.tg-row { display: grid; grid-template-columns: var(--gut) repeat(var(--n), minmax(0, 1fr)); }
.tg-dh { text-align: center; padding: 8px 2px 6px; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2); border-left: 1px solid var(--line); }
.tg-dh .dn {
  display: grid; place-items: center; width: 34px; height: 34px; margin: 3px auto 0; border-radius: 50%;
  font-family: var(--display); font-size: 19px; font-weight: 700; letter-spacing: 0; text-transform: none; color: var(--ink);
}
.tg-dh.today .dn { background: var(--saffron); color: var(--saffron-ink); }
.tg-dh.today { color: var(--ink); }
.tg-ad { min-height: 30px; padding: 3px 2px; border-left: 1px solid var(--line); display: grid; gap: 2px; align-content: start; min-width: 0; }
.tg-adl { font-size: 10px; font-weight: 700; color: var(--ink-2); display: grid; place-items: center; padding: 0 2px; text-align: center; line-height: 1.1; }
.tg-pill {
  display: block; width: 100%; padding: 1px 5px; border: 0; border-radius: 5px; text-align: left; font-size: 11.5px; font-weight: 600; line-height: 1.4;
  background: color-mix(in srgb, var(--c) 24%, var(--surface)); border-left: 3px solid var(--c); color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tg-more { font-size: 11px; font-weight: 700; color: var(--ink-2); padding-left: 4px; }
.tg-body { display: grid; grid-template-columns: var(--gut) repeat(var(--n), minmax(0, 1fr)); }
.tg-gutter { position: relative; height: calc(24 * var(--hh)); }
.tg-hr { position: absolute; right: 6px; top: calc(var(--h) * var(--hh)); transform: translateY(-50%); font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.tg-col {
  position: relative; height: calc(24 * var(--hh)); border-left: 1px solid var(--line); cursor: pointer; min-width: 0;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hh) - 1px), var(--line) calc(var(--hh) - 1px), var(--line) var(--hh));
}
.tg-col.today { background-color: color-mix(in srgb, var(--saffron) 7%, transparent); }
.tg-ev {
  position: absolute; z-index: 1; overflow: hidden; padding: 2px 5px; border: 0; border-radius: 8px; text-align: left;
  top: calc(var(--top) * var(--hh) / 60);
  height: calc(var(--len) * var(--hh) / 60 - 2px);
  left: calc(var(--col) * 100% / var(--k) + 1px);
  width: calc(100% / var(--k) - 3px);
  background: color-mix(in srgb, var(--c) 24%, var(--surface)); border-left: 4px solid var(--c); color: var(--ink);
  font-size: 12px; line-height: 1.25; display: flex; flex-direction: column; align-items: stretch;
}
.tg-ev b { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.tg-ev span { color: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tg-ev.short { flex-direction: row; gap: 6px; align-items: baseline; padding-top: 1px; }
.tg-ev.short b { white-space: nowrap; }
.tg-ev:hover { z-index: 3; filter: brightness(.97); }
.tg-now { position: absolute; left: 0; right: 0; z-index: 2; height: 2px; top: calc(var(--top) * var(--hh) / 60); background: #e0a100; pointer-events: none; }
.tg-now::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: #e0a100; }
@media (min-width: 900px) { .tg-ev { font-size: 13px; padding: 3px 8px; } }

/* ---------- calendario: agenda ---------- */
.ag { display: grid; gap: 6px; max-width: 760px; }
.ag-day { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 4px 14px; padding: 10px 0; border-top: 1px solid var(--line); }
.ag-day:first-child { border-top: 0; }
.ag-h { display: flex; flex-direction: column; align-items: center; align-self: start; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2); line-height: 1.2; position: sticky; top: 8px; }
.ag-n { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; font-family: var(--display); font-size: 24px; letter-spacing: -.02em; color: var(--ink); text-transform: none; }
.ag-day.today .ag-n { background: var(--saffron); color: var(--saffron-ink); }
.ag-list { display: grid; gap: 8px; min-width: 0; }
.ag-row { display: flex; gap: 12px; align-items: stretch; width: 100%; padding: 10px 12px; border: 0; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); text-align: left; }
.ag-row .bar { width: 5px; border-radius: 3px; flex: none; }
.ag-time { width: 84px; flex: none; font-size: 14px; font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.ag-title { font-weight: 700; }
.ag-note { font-size: 14px; color: var(--ink-2); white-space: pre-line; overflow-wrap: anywhere; }
.ag-none { padding: 12px 2px; color: var(--ink-2); }
.ag-more { justify-self: center; margin-top: 10px; }
@media (max-width: 479px) { .ag-row { flex-wrap: wrap; } .ag-time { width: auto; } .ag-day { grid-template-columns: 52px minmax(0, 1fr); gap: 4px 10px; } .ag-n { width: 40px; height: 40px; font-size: 22px; } }

/* ---------- spese ---------- */
.split { display: grid; gap: 4px; }
@media (min-width: 900px) {
  .split { grid-template-columns: 320px minmax(0, 1fr); gap: 32px; align-items: start; }
  .split-side { position: sticky; top: 16px; }
  .split-main .cal-head { margin-top: 0 !important; }
}
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 10px; }
.balance { padding: 18px; }
.balance .sentence { font-family: var(--display); font-size: 26px; line-height: 1.15; font-weight: 700; letter-spacing: -.025em; }
.balance .sentence .amt { white-space: nowrap; font-variant-numeric: tabular-nums; }
.balance.even .sentence { color: var(--ok); }
.exp-day { font-family: var(--sans); font-size: 13px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2); margin: 20px 2px 6px; }
.exp-day::first-letter { text-transform: uppercase; }
.exp { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0; padding: 12px 14px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); }
.exp + .exp { margin-top: 8px; }
.exp .cat { width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; font-size: 20px; flex: none; }
.exp-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exp-meta { font-size: 14px; color: var(--ink-2); }
.exp-amt { font-family: var(--display); font-weight: 700; font-size: 19px; letter-spacing: -.01em; white-space: nowrap; }
.money { font-variant-numeric: tabular-nums; }
.month-total { font-size: 14px; color: var(--ink-2); }
.month-total b { font-family: var(--display); color: var(--ink); font-size: 18px; }

/* ---------- lista della spesa ---------- */
.shop-top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 6px 0 4px; display: grid; gap: 8px; }
.add-row { display: flex; gap: 8px; }
.add-row input[name="name"] { flex: 1; min-width: 0; }
.add-row input[name="qty"] { width: 84px; flex: none; }
.item { display: flex; align-items: center; gap: 4px; min-height: 56px; padding: 0 6px 0 4px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); }
.item + .item { margin-top: 8px; }
.item .tick { width: 52px; height: 52px; flex: none; display: grid; place-items: center; border: 0; background: none; border-radius: 50%; }
.item .box { width: 28px; height: 28px; border-radius: 9px; border: 2px solid var(--ink-2); display: grid; place-items: center; transition: background .12s, border-color .12s; }
.item .box svg { width: 18px; height: 18px; opacity: 0; stroke: var(--saffron-ink); stroke-width: 3.2; }
.item.done .box { background: var(--saffron); border-color: var(--saffron); }
.item.done .box svg { opacity: 1; }
.item.done .name { text-decoration: line-through; color: var(--ink-2); }
.item .name { font-weight: 600; overflow-wrap: anywhere; }
.item .qty { color: var(--brand-text); font-weight: 700; margin-left: 6px; }
.item .by { font-size: 13px; color: var(--ink-2); }

/* ---------- account ---------- */
.member { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.member + .member { border-top: 1px solid var(--line); }
.member.off { opacity: .55; }
.pw-box {
  display: block; width: 100%; padding: 14px; border-radius: 12px; background: var(--surface-2);
  font: 600 20px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .04em; text-align: center; user-select: all; word-break: break-all;
}
.msg-box { white-space: pre-line; font-size: 15px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); user-select: all; }

/* ---------- finestre ---------- */
dialog.sheet {
  border: 0; padding: 0; color: var(--ink); background: var(--surface);
  width: 100%; max-width: 560px; max-height: 92dvh; margin: auto auto 0; border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .25); overflow: hidden;
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: sheet-in .22s ease-out; }
dialog.sheet::backdrop { background: rgba(10, 16, 22, .55); }
dialog.sheet > form { display: flex; flex-direction: column; min-height: 0; max-height: 92dvh; }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 8px 6px 20px; }
.sheet-head h2 { font-size: 23px; letter-spacing: -.02em; }
.sheet-body { padding: 8px 20px 12px; overflow: auto; display: grid; gap: 14px; }
.sheet-foot { display: flex; gap: 10px; padding: 12px 20px calc(env(safe-area-inset-bottom) + 14px); border-top: 1px solid var(--line); }
.sheet-foot .btn.primary { flex: 1; }
@media (min-width: 640px) {
  dialog.sheet { margin: auto; border-radius: 22px; }
}

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 84px);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; max-width: calc(100vw - 32px);
  box-shadow: var(--shadow);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* settimana su schermi stretti: sette colonne piccole, quindi solo il titolo, a capo ovunque serva */
@media (max-width: 639px) {
  .tg-scroll.n7 .tg-ev { padding: 1px 3px; border-left-width: 3px; font-size: 10.5px; line-height: 1.2; }
  .tg-scroll.n7 .tg-ev b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tg-scroll.n7 .tg-ev span { display: none; }
  .tg-scroll.n7 .tg-ev.short { flex-direction: column; }
  .tg-scroll.n7 .tg-pill { font-size: 10px; padding: 1px 3px; }
}
.exp-head { text-align: center; }
@media (min-width: 900px) {
  .split-main .cal-head { justify-content: flex-start; gap: 16px; }
  .split-main .cal-head > .icon-btn:last-child { order: 3; }
  .split-main .exp-head { text-align: left; min-width: 220px; }
}

/* ---------- calendario: anteprima del trascinamento ---------- */
.tg-scroll, .tg-col { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.tg-ghost {
  position: absolute; z-index: 3; left: 2px; right: 2px; pointer-events: none; overflow: hidden;
  top: calc(var(--top) * var(--hh) / 60); height: calc(var(--len) * var(--hh) / 60);
  padding: 3px 7px; border-radius: 8px; font-size: 12px; line-height: 1.25;
  background: color-mix(in srgb, var(--brand) 28%, transparent); border: 2px dashed var(--brand-text); color: var(--ink);
  display: flex; flex-direction: column; backdrop-filter: blur(1px);
}
.tg-ghost b { font-weight: 700; }
.tg-ghost span { font-variant-numeric: tabular-nums; font-weight: 600; }
body.is-dragging { cursor: row-resize; }
body.is-dragging .tg-scroll { overscroll-behavior: contain; }

/* ---------- lista della spesa: suggerimenti, prodotti ---------- */
.sugg { display: flex; align-items: center; gap: 8px; min-height: 44px; overflow-x: auto; scrollbar-width: none; padding: 0 2px 2px; margin: 0 -2px; -webkit-overflow-scrolling: touch; }
.sugg::-webkit-scrollbar { display: none; }
.sugg .chip { flex: none; min-height: 38px; }
.chip small { color: inherit; opacity: .7; font-weight: 600; }
.sugg-label { flex: none; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.prod-head { display: grid; gap: 10px; margin: 8px 0 6px; }
.prod-head .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -2px; padding: 0 2px; }
.prod-head .chip { flex: none; min-height: 38px; }
.prod-head select { width: auto; min-height: 38px; padding: 4px 10px; }
.prod { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); }
.prod + .prod { margin-top: 8px; }
.prod-main { flex: 1; min-width: 0; display: grid; text-align: left; border: 0; background: none; padding: 8px 8px; min-height: 52px; align-content: center; }
.prod-main .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prod-meta { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; flex: none; }
.st-todo { background: color-mix(in srgb, var(--brand) 16%, var(--surface)); color: var(--brand-text); }
.st-cart { background: var(--saffron); color: var(--saffron-ink); }
.st-archive { background: var(--surface-2); color: var(--ink-2); }

/* ---------- spese: barra vista + statistiche ---------- */
.exp-modebar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 2px 0 12px; }
.stats { display: grid; gap: 14px; }
.stats .wide, .stats .kpis { grid-column: 1 / -1; }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 14px 16px; display: grid; gap: 2px; align-content: start; min-width: 0; }
.kpi-l { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.kpi-v { font-family: var(--display); font-size: clamp(22px, 6vw, 30px); letter-spacing: -.02em; line-height: 1.15; }
.kpi-sub { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.stat-card h3 { font-size: 18px; margin-bottom: 4px; }
.stat-card > p { margin-bottom: 8px; }
.stat-card summary { cursor: pointer; font-weight: 700; min-height: 28px; }
.chart { position: relative; min-height: 210px; }
.chart svg { display: block; max-width: 100%; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .grid.base { stroke: color-mix(in srgb, var(--ink-2) 45%, var(--line)); }
.chart .ax { fill: var(--ink-2); font: 11px var(--sans); }
.chart .pk { fill: var(--ink); font: 700 11.5px var(--sans); }
.chart .bar { fill: var(--s1); transition: opacity .12s; }
.chart.has-hl .bar:not(.hl) { opacity: .45; }
.chart .hit { fill: transparent; cursor: default; }
.viz-tip { position: absolute; z-index: 3; pointer-events: none; background: var(--ink); color: var(--bg); border-radius: 10px; padding: 6px 10px; font-size: 12.5px; line-height: 1.35; white-space: nowrap; box-shadow: var(--shadow); }
.bars { display: grid; gap: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; align-items: baseline; }
.bar-row.sub { gap: 2px 10px; }
.bar-label { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row.sub .bar-label { font-weight: 500; font-size: 13px; color: var(--ink-2); }
.bar-val { font-weight: 700; font-size: 14px; }
.bar-val small { color: var(--ink-2); font-weight: 600; margin-left: 2px; }
.bar-track { grid-column: 1 / -1; height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 0 5px 5px 0; }
.bar-fill.s1 { background: var(--s1); } .bar-fill.s2 { background: var(--s2); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.s1 { background: var(--s1); } .sw.s2 { background: var(--s2); }
.person-stat { display: grid; gap: 6px; }
.person-stat + .person-stat { padding-top: 12px; border-top: 1px solid var(--line); }
.top-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.top-row + .top-row { border-top: 1px solid var(--line); }
.top-row .cat { width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-size: 18px; flex: none; }
.tbl-wrap { overflow-x: auto; margin-top: 10px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.tbl th:last-child, .tbl td:last-child { text-align: right; }
.tbl tfoot td { font-weight: 800; border-bottom: 0; }
.export-link { display: flex; justify-content: flex-start; gap: 14px; min-height: 60px; text-align: left; text-decoration: none; color: var(--ink); }
.export-link span { display: grid; }
.export-link small { color: var(--ink-2); font-weight: 500; }
@media (min-width: 900px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
}
