:root {
  --bg: #f5f4f0; --surface: #ffffff; --ink: #1b2432; --muted: #687385; --line: #e3e1da; --soft: #efede7;
  --brand: #16335b; --accent: #1f5fbf; --gold: #e2a33b; --red: #c0392b; --green: #23804a;
  --radius: 10px; --shadow: 0 10px 30px rgba(20, 30, 50, .16);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12161d; --surface: #1b212b; --ink: #e8ebf0; --muted: #98a2b3; --line: #2c3440; --soft: #232a35; --accent: #6ea4f0; --red: #f0766a; --green: #5fc48a; --shadow: 0 10px 30px rgba(0, 0, 0, .5); }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; display: flex; flex-direction: column; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.top { background: var(--brand); color: #fff; display: flex; align-items: center; gap: 14px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand strong { display: block; font-size: 15px; letter-spacing: .2px; }
.brand small { display: block; opacity: .75; font-size: 12px; text-transform: capitalize; }
.logo { background: #fff; color: var(--brand); font-weight: 800; border-radius: 8px; width: 34px; height: 34px; display: grid; place-items: center; font-size: 14px; border-bottom: 3px solid var(--gold); }
.logo.big { width: 56px; height: 56px; font-size: 22px; background: var(--brand); color: #fff; margin: 0 auto; }
#q { flex: 1; min-width: 0; max-width: 460px; margin-left: auto; border: 0; border-radius: 8px; padding: 8px 12px; background: rgba(255, 255, 255, .14); color: #fff; outline: none; }
#q::placeholder { color: rgba(255, 255, 255, .65); }
#q:focus { background: rgba(255, 255, 255, .24); }
.status { border: 0; border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 600; white-space: nowrap; background: rgba(255, 255, 255, .14); color: #fff; }
.status::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; background: #6fdc9a; }
.status.sync::before { background: var(--gold); }
.status.off::before { background: #b9c1cf; }
.status.err { background: #fff; color: var(--red); } .status.err::before { display: none; }

main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; padding: 14px; max-width: 1500px; width: 100%; margin: 0 auto; }
.col { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.colhead { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.colhead h2 { margin: 0; font-size: 16px; }
.count { color: var(--muted); font-weight: 500; font-size: 13px; margin-left: 2px; }
.chips, .inline { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.colhead .chips { flex: 1; }
.fchip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 4px 10px; font-size: 12.5px; color: var(--muted); }
.fchip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.quick { display: flex; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.quick input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 9px 11px; outline: none; }
.quick input:focus { border-color: var(--accent); }
.quick button { border: 0; background: var(--accent); color: #fff; border-radius: 8px; width: 40px; font-size: 18px; }
.list { overflow-y: auto; flex: 1; padding: 4px 0 20px; -webkit-overflow-scrolling: touch; }
.group { font-size: 11.5px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); padding: 12px 14px 4px; }
.row { display: flex; gap: 11px; padding: 10px 14px; border-bottom: 1px solid var(--soft); cursor: pointer; align-items: flex-start; }
.row:hover { background: var(--soft); }
.row.sel { background: color-mix(in srgb, var(--accent) 12%, transparent); box-shadow: inset 3px 0 0 var(--accent); }
.body { min-width: 0; flex: 1; }
.title { font-weight: 600; overflow-wrap: anywhere; }
.sub { color: var(--muted); font-size: 13.5px; margin-top: 1px; }
.meta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; align-items: center; }
.meta:empty { display: none; }
.chip { font-size: 12px; background: var(--soft); border-radius: 6px; padding: 2px 7px; color: var(--muted); white-space: nowrap; }
.chip.date { font-weight: 600; } .chip.late { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); } .chip.now { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.chip.link { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.chip.who::before { content: "→ "; } .chip.pend { background: color-mix(in srgb, var(--gold) 25%, transparent); color: inherit; }
.chip.rm { font-size: 13px; padding: 4px 4px 4px 9px; color: var(--ink); display: inline-flex; gap: 4px; align-items: center; white-space: normal; }
.chip.rm button { border: 0; background: transparent; color: var(--muted); padding: 0 4px; }
.stars, .star { color: var(--gold); letter-spacing: 1px; font-size: 12px; }
.check { flex: none; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #aab2c0; background: transparent; margin-top: 1px; color: #fff; font-size: 13px; line-height: 1; padding: 0; }
.check:hover { border-color: var(--green); }
.todo.done .check { background: var(--green); border-color: var(--green); }
.todo.done .title { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.fase { font-size: 11.5px; font-weight: 600; border-radius: 999px; padding: 2px 9px; margin-left: 8px; white-space: nowrap; border: 1px solid transparent; vertical-align: 1px; }
.f-q { background: #e7e8ec; color: #454d5b; } .f-c { background: #d7e6fb; color: #164a94; } .f-a { background: #fbeec2; color: #7a5a00; } .f-z { background: #fde0c8; color: #8a4706; } .f-v { background: #d4efdd; color: #17613a; } .f-p { background: #f8d7d3; color: #96261b; }
.fase.pick { margin: 0; padding: 5px 11px; font-size: 12.5px; opacity: .55; } .fase.pick.on { opacity: 1; border-color: currentColor; box-shadow: 0 0 0 1px currentColor; }
.empty { color: var(--muted); padding: 26px 16px; text-align: center; margin: 0; } .empty.small { padding: 8px 0; text-align: left; font-size: 13.5px; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 9px 14px; font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary, .quick button { color: #0e141c; } }
.btn.small { padding: 6px 11px; font-size: 13px; } .btn.ghost { border-color: transparent; color: var(--accent); padding-left: 0; }
.mini { border: 1px solid var(--line); background: transparent; border-radius: 6px; padding: 5px 8px; font-size: 12.5px; color: var(--muted); }

.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(470px, 100vw); background: var(--surface); box-shadow: var(--shadow); border-left: 1px solid var(--line); display: flex; flex-direction: column; z-index: 20; padding-top: env(safe-area-inset-top); }
.dhead { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.dhead h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); } .dhead small { margin-left: 8px; font-weight: 500; letter-spacing: 0; }
.x { border: 0; background: var(--soft); border-radius: 50%; width: 32px; height: 32px; }
.dbody { overflow-y: auto; padding: 14px 16px calc(40px + env(safe-area-inset-bottom)); flex: 1; -webkit-overflow-scrolling: touch; }
.field { margin-bottom: 16px; } .field > label, .dbody h4 { display: block; font-size: 11.5px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
.in, .field textarea, input[type=date] { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 9px 11px; outline: none; }
.in, .field textarea { width: 100%; } .field textarea { resize: vertical; display: block; }
.in:focus, .field textarea:focus, input[type=date]:focus { border-color: var(--accent); }
.in.big { resize: none; font-size: 18px; font-weight: 650; background: transparent; border-color: transparent; padding-left: 0; } .in.big:focus { background: var(--bg); padding-left: 11px; }
.in.pick { width: 170px; flex: 1; } .in.bad { border-color: var(--red); }
.star { border: 0; background: transparent; font-size: 24px; color: var(--line); padding: 0 2px; } .star.on { color: var(--gold); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 18px; }
#note + .btn { margin-top: 8px; }
.storico { border-left: 2px solid var(--line); padding-left: 12px; } .note { margin-bottom: 12px; white-space: pre-wrap; overflow-wrap: anywhere; } .note time { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.sublist { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 8px; } .sublist .row:last-child { border-bottom: 0; } .sublist .empty { padding: 10px 12px; }
.field .quick { padding: 0; border: 0; }
ul.plain { padding-left: 18px; margin: 8px 0 14px; } ul.plain li { margin-bottom: 6px; } .err { color: var(--red); font-size: 13.5px; }

.tabs { display: none; }
.login { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 50; padding: 24px; }
.login form { width: min(340px, 100%); display: grid; gap: 12px; text-align: center; } .login h1 { font-size: 20px; margin: 4px 0 8px; }
.login input { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 12px; text-align: center; }

/* Mac: con la scheda aperta le due colonne restano visibili */
@media (min-width: 1180px) { body.has-drawer main { padding-right: 484px; max-width: none; } }
/* iPhone: una colonna alla volta, schede in basso */
@media (max-width: 820px) {
  .top { gap: 10px; padding-left: 12px; padding-right: 12px; flex-wrap: wrap; } .brand small { display: none; } #q { order: 3; flex-basis: 100%; max-width: none; margin: 0; } .status { margin-left: auto; }
  main { grid-template-columns: 1fr; padding: 0; gap: 0; } .col { border: 0; border-radius: 0; }
  body[data-tab=todo] #col-tratt, body[data-tab=tratt] #col-todo { display: none; }
  .tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabs button { border: 0; background: transparent; padding: 13px; font-weight: 700; color: var(--muted); border-top: 3px solid transparent; }
  body[data-tab=todo] .tabs [data-tab=todo], body[data-tab=tratt] .tabs [data-tab=tratt] { color: var(--accent); border-top-color: var(--accent); }
  .drawer { width: 100vw; border: 0; } .row { padding: 12px; } .check { width: 28px; height: 28px; }
  input, textarea, select { font-size: 16px; } /* evita lo zoom automatico di iOS */
}
