/* Famiglia — stile
   Nebbia + inchiostro blu notte; cobalto per le azioni, zafferano solo per "oggi" e "fatto". */
:root {
  --bg: #eef1ef;
  --surface: #ffffff;
  --surface-2: #e6ebe8;
  --ink: #16222b;
  --ink-2: #4b5b66;
  --line: #d3dad6;
  --brand: #2c3ea8;
  --brand-ink: #ffffff;
  --brand-text: #2c3ea8;
  --saffron: #ffc93c;
  --saffron-ink: #3a2a00;
  --danger: #b3261e;
  --ok: #1f6f43;
  --shadow: 0 1px 2px rgba(22, 34, 43, .08), 0 6px 20px rgba(22, 34, 43, .06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --nav-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10151c;
    --surface: #1a222c;
    --surface-2: #232d39;
    --ink: #e9eef2;
    --ink-2: #a3b1bb;
    --line: #2c3743;
    --brand: #5b6ee0;
    --brand-text: #9fadff;
    --danger: #ff8a80;
    --ok: #6fd39b;
    --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%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -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; }
[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: 760px;
  margin: 0 auto;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 8px;
}
.brand { font-family: var(--serif); font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.sync { font-size: 13px; color: var(--ink-2); min-height: 20px; }
.sync.off { color: var(--danger); font-weight: 600; }

main.view { padding: 4px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 96px); }

.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-rows: auto auto 1fr; }
  .nav { position: static; border: 0; background: none; padding: 0 16px; order: 2; }
  .nav-inner { max-width: none; grid-template-columns: repeat(4, auto); justify-content: start; gap: 4px; }
  .tab { flex-direction: row; gap: 8px; height: 44px; padding: 0 16px; border-radius: 999px; font-size: 15px; }
  .tab[aria-current="page"] { background: var(--surface); box-shadow: var(--shadow); }
  main.view { order: 3; padding-bottom: 96px; }
  .fab { right: max(24px, calc(50vw - 380px + 16px)); bottom: 28px !important; }
}

/* ---------- 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: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);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

.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(--serif); font-size: 26px; font-weight: 700; letter-spacing: -.01em; line-height: 1.15; }
.h2 { font-size: 15px; font-weight: 700; color: var(--ink-2); margin: 22px 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); }

.empty { text-align: center; padding: 36px 16px; color: var(--ink-2); }
.empty strong { display: block; color: var(--ink); font-family: var(--serif); font-size: 20px; 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: 38px; }
.login .lead { color: var(--ink-2); margin-top: 6px; }
.login .mark { width: 64px; height: 64px; border-radius: 18px; }

/* ---------- calendario ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 10px; }
.cal-title { font-family: var(--serif); font-size: 28px; font-weight: 700; text-transform: capitalize; letter-spacing: -.01em; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.cal-dow { text-align: center; font-size: 13px; font-weight: 700; 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%; }
.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); }

.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; }
.ev-title { font-weight: 700; }
.ev-note { font-size: 14px; color: var(--ink-2); margin-top: 2px; white-space: pre-line; }

/* ---------- spese ---------- */
.balance { padding: 18px; }
.balance .sentence { font-family: var(--serif); font-size: 24px; line-height: 1.25; font-weight: 700; letter-spacing: -.01em; }
.balance .sentence .amt { white-space: nowrap; }
.balance.even .sentence { color: var(--ok); }
.exp-day { font-size: 14px; font-weight: 700; color: var(--ink-2); margin: 18px 2px 6px; }
.exp-day::first-letter, .cap::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(--serif); font-weight: 700; font-size: 18px; white-space: nowrap; }
.money { font-variant-numeric: tabular-nums; }
.month-total { font-size: 14px; color: var(--ink-2); }
.month-total b { font-family: var(--serif); color: var(--ink); font-size: 18px; }

/* ---------- lista della spesa ---------- */
.add-row { display: flex; gap: 8px; position: sticky; top: 0; z-index: 5; padding: 8px 0; background: var(--bg); }
.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, .5); }
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-family: var(--serif); font-size: 22px; }
.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; }
}
