:root {
  --bg: #0E1116;
  --surface: #171B22;
  --surface-2: #12161C;
  --line: #222832;
  --line-2: #262C36;
  --ring: #3A4250;
  --text: #E8ECF2;
  --text-2: #C9D0DA;
  --muted: #9AA3B2;
  --muted-2: #7D8695;
  --accent: #5CC8E0;
  --accent-ink: #0E1116;
  --warn: #F0B44C;
  --warn-bg: #1E1A14;
  --warn-line: #3A2F1C;
  --ok: #7BD389;
  --pink: #F28DB2;
  --violet: #B39DFA;
  --blue: #6EA8FE;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#app { max-width: 560px; margin: 0 auto; padding: calc(14px + var(--safe-t)) 20px calc(110px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px; }

/* testate */
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.head h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.sub { font-size: 13px; color: var(--muted); font-weight: 600; }
.back { display: inline-flex; align-items: center; gap: 4px; height: 44px; margin-left: -6px; text-decoration: none; font-weight: 700; font-size: 14px; background: none; border: 0; color: var(--accent); padding: 0 6px; }
.icon-btn { width: 44px; height: 44px; flex: none; border-radius: 14px; border: 0; background: var(--surface); color: var(--text); display: inline-flex; align-items: center; justify-content: center; position: relative; text-decoration: none; }
.badge { position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--warn); color: #1A1406; font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center; border: 2px solid var(--bg); }
.btn { height: 44px; padding: 0 16px; border-radius: 12px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.ghost { background: transparent; border: 1px solid #2E3541; color: var(--text-2); font-weight: 700; }
.btn.warn { background: var(--warn); color: #1A1406; }
.btn.small { height: 36px; font-size: 13px; padding: 0 12px; }
.btn.block { width: 100%; }
.btn.dashed { background: transparent; border: 1px dashed var(--ring); color: var(--text-2); font-weight: 700; width: 100%; height: 48px; }

/* cattura */
.capture { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 16px; padding: 6px 6px 6px 16px; }
.capture input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; color: var(--text); font-size: 16px; height: 40px; }
.capture input::placeholder { color: var(--muted-2); }
.capture .go { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--accent); color: var(--accent-ink); display: flex; align-items: center; justify-content: center; flex: none; }

/* contatori */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--surface); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--text); min-height: 44px; }
.stat b { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; font-weight: 600; color: var(--muted); }
.stat.warn { background: #2A2112; color: var(--warn); }
.stat.warn span { color: #E8C98A; }

/* card e righe */
.card { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; }
.card.tight { padding: 0 14px; }
.card.warn { background: var(--warn-bg); border: 1px solid var(--warn-line); }
.card.pink { background: #1C1720; border: 1px solid #33283A; }
.card.blue { background: #151A24; border: 1px solid #243042; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 2px; }
.card-head h2, .section-title { margin: 0; font-size: 16px; font-weight: 700; }
.card-head a, .link { font-size: 13px; font-weight: 700; text-decoration: none; padding: 8px 0; background: none; border: 0; color: var(--accent); }
.group-title { margin: 4px 0 -6px; font-size: 13px; font-weight: 800; letter-spacing: 0.02em; color: var(--text-2); }
.kicker { font-size: 12px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }

.row { display: flex; align-items: center; gap: 10px; min-height: 52px; border-top: 1px solid var(--line); }
.card.tight .row:first-child, .card .row.first { border-top: 0; }
.card:not(.tight) .card-head + .row { border-top: 1px solid var(--line); }
.row .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; padding: 7px 0; }
.row .title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.done .title { color: var(--muted-2); text-decoration: line-through; }
.row .meta { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.row .when { font-size: 12px; font-weight: 800; color: var(--accent); white-space: nowrap; }
.row .more { width: 36px; height: 44px; border: 0; background: transparent; color: var(--muted-2); display: flex; align-items: center; justify-content: center; margin-right: -8px; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }

.check { width: 44px; height: 44px; flex: none; margin-left: -10px; border: 0; background: transparent; padding: 0; display: flex; align-items: center; justify-content: center; }
.check span { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--ring); display: flex; align-items: center; justify-content: center; color: transparent; }
.check.square span { border-radius: 7px; width: 22px; height: 22px; }
.check[aria-pressed="true"] span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check.square[aria-pressed="true"] span { background: var(--ok); border-color: var(--ok); }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -20px; padding: 0 20px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 38px; padding: 0 14px; border-radius: 19px; border: 1px solid var(--line-2); background: var(--surface); color: var(--text-2); font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; gap: 7px; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; background: var(--surface); border-radius: 14px; padding: 4px; }
.seg button { height: 40px; border-radius: 11px; border: 0; background: transparent; color: var(--muted); font-weight: 800; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); }

.pill { flex: none; padding: 6px 10px; border-radius: 10px; font-size: 12px; font-weight: 800; }
.pill.warn { background: var(--warn-line); color: var(--warn); }
.pill.pink { background: #3A2840; color: var(--pink); }
.pill.btn-pill { height: 32px; min-width: 96px; border-radius: 16px; border: 1px solid #4A3A52; background: transparent; color: #D9B8C8; }
.pill.btn-pill.s1 { background: #3A2840; border-color: #3A2840; color: var(--pink); }
.pill.btn-pill.s2 { background: var(--ok); border-color: var(--ok); color: var(--bg); }

.datebox { width: 44px; height: 44px; flex: none; border-radius: 12px; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.datebox b { font-size: 16px; font-weight: 800; }
.datebox span { font-size: 11px; font-weight: 700; color: var(--muted); margin-top: 2px; }
.avatar { width: 40px; height: 40px; flex: none; border-radius: 50%; background: var(--bg); color: var(--text-2); display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 800; }
.avatar.big { width: 48px; height: 48px; font-size: 20px; background: #3A2840; color: var(--pink); }

.empty { background: var(--surface); border-radius: 16px; padding: 24px 20px; text-align: center; color: var(--muted); font-size: 14px; font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); }
.agenda-time { width: 48px; font-size: 14px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }

/* moduli */
.form { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; font-weight: 700; color: var(--muted); }
.field input, .field select, .field textarea { height: 44px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--bg); color: var(--text); padding: 0 12px; font-size: 16px; }
.field textarea { height: 80px; padding: 10px 12px; resize: vertical; }
.inline-add { display: flex; gap: 8px; }
.inline-add input { flex: 1; min-width: 0; height: 44px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--bg); padding: 0 12px; font-size: 16px; }

/* barra in basso */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface-2); border-top: 1px solid #1F242D; padding: 8px 8px calc(8px + var(--safe-b)); z-index: 10; }
.tabbar-inner { max-width: 560px; margin: 0 auto; display: flex; justify-content: space-around; align-items: flex-start; }
.tab { width: 64px; min-height: 48px; display: flex; flex-direction: column; align-items: center; gap: 4px; text-decoration: none; color: var(--muted-2); font-size: 11px; font-weight: 700; }
.tab[aria-current="page"] { color: var(--accent); }
.fab { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); margin-top: -26px; display: flex; align-items: center; justify-content: center; box-shadow: 0 0 0 6px var(--bg); }

/* foglio a comparsa e avvisi */
.sheet-wrap { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; background: var(--surface); border-radius: 22px 22px 0 0; padding: 18px 20px calc(20px + var(--safe-b)); display: flex; flex-direction: column; gap: 12px; max-height: 88dvh; overflow-y: auto; }
.sheet h2 { margin: 0; font-size: 18px; font-weight: 800; }
.sheet .actions { display: flex; flex-direction: column; gap: 8px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(100px + var(--safe-b)); width: calc(100% - 32px); max-width: 520px; background: #E8ECF2; color: #0E1116; border-radius: 14px; padding: 12px 14px; font-size: 14px; font-weight: 700; z-index: 30; display: flex; gap: 12px; align-items: center; white-space: pre-line; }
.toast button { margin-left: auto; flex: none; height: 36px; border-radius: 10px; border: 0; background: #0E1116; color: #E8ECF2; font-weight: 800; padding: 0 12px; }
.loading { color: var(--muted); font-size: 14px; padding: 20px 0; text-align: center; }

@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: up .18s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}
