:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1d1c19;
  --muted: #6d6b64;
  --line: #e8e5dc;
  --accent: #262ced;
  --accent-ink: #ffffff;
  --accent-soft: #e1e2fc;
  --danger: #c0392b;
  --danger-soft: #fbe4e0;
  --warn-soft: #fdf0d2;
  --warn: #8a5a00;
  --p-low: #94a3b8;
  --p-normal: #d99a1d;
  --p-high: #dc3b2f;
  --u0: #262ced;
  --u1: #7c4dcc;
  --shadow: 0 1px 2px rgba(30, 28, 20, .06), 0 4px 14px rgba(30, 28, 20, .05);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111312;
    --surface: #1a1d1b;
    --surface-2: #151816;
    --ink: #ecebe5;
    --muted: #9b9a92;
    --line: #2a2e2b;
    --accent: #8f92ff;
    --accent-ink: #0a0b33;
    --accent-soft: #1f2152;
    --danger: #ff7a6b;
    --danger-soft: #3a1f1b;
    --warn-soft: #3a2f12;
    --warn: #f0c35c;
    --u0: #8f92ff;
    --u1: #b794f6;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
body:has(dialog[open]) { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 1.35rem; letter-spacing: -.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { display: inline-flex; align-items: center; justify-content: center; line-height: 1.2; text-align: center; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.ic { display: inline-flex; }
.ic svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- bottoni ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface);
  padding: 10px 16px; border-radius: 12px; font-weight: 600; min-height: 44px;
  transition: transform .1s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger.armed { background: var(--danger); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent;
  display: inline-grid; place-items: center; color: var(--muted);
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 24px; padding: 28px 24px; box-shadow: var(--shadow);
  display: grid; gap: 16px; text-align: center;
}
.login-card .field { text-align: left; }
.logo {
  width: 52px; height: 52px; border-radius: 16px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; margin: 0 auto;
}
.logo.sm { width: 30px; height: 30px; border-radius: 9px; margin: 0; }
.field { display: grid; gap: 6px; }
.label { font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
input[type=text], input[type=password], input[type=date], select, textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 13px; min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; line-height: 1.5; }
.error { color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: 10px; font-size: .92rem; text-align: left; }

.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0; background: transparent; padding: 9px 8px; border-radius: 9px; font-weight: 600; color: var(--muted); min-height: 40px;
}
.seg button[aria-checked=true], .seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 94%, transparent); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top, 0); }
.top-in { max-width: 1120px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.08rem; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.avatar {
  --c: var(--u0);
  width: 26px; height: 26px; border-radius: 50%; background: var(--c); color: #fff; flex: none;
  display: inline-grid; place-items: center; font-size: .72rem; font-weight: 700;
}
.avatar.u1 { --c: var(--u1); }
.avatar.lg { width: 36px; height: 36px; font-size: .9rem; }
@media (prefers-color-scheme: dark) { .avatar { color: #06201d; } }
.avatar-btn { border: 0; background: transparent; padding: 4px; border-radius: 50%; }

/* tab principali: in basso su mobile, in alto su desktop */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px 12px calc(6px + var(--safe-b));
}
.tabs button {
  flex: 1; border: 0; background: transparent; display: grid; justify-items: center; gap: 2px;
  padding: 6px; color: var(--muted); font-size: .72rem; font-weight: 600; border-radius: 12px; min-height: 48px;
}
.tabs button.on { color: var(--accent); }

.wrap { max-width: 1120px; margin: 0 auto; padding: 18px 16px calc(150px + var(--safe-b)); }

.summary { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.summary p { font-size: .92rem; margin-top: 2px; }
.chips { display: flex; gap: 6px; }
.chips button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: .9rem; color: var(--muted); min-height: 36px;
}
.chips button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-bottom: 16px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .5s cubic-bezier(.2, .8, .2, 1); }

/* ---------- board ---------- */
.status-tabs { display: flex; gap: 6px; margin-bottom: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px; }
.status-tabs button {
  flex: 1; border: 0; background: transparent; padding: 9px 4px; border-radius: 10px; font-weight: 600; color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; font-size: .92rem;
}
.status-tabs button.on { background: var(--accent-soft); color: var(--accent); }
.status-tabs .n { font-size: .75rem; background: var(--line); color: var(--muted); border-radius: 99px; padding: 1px 7px; }
.status-tabs button.on .n { background: var(--accent); color: var(--accent-ink); }

.board { display: block; }
.col { display: none; }
.board[data-active=todo] .col[data-s=todo],
.board[data-active=doing] .col[data-s=doing],
.board[data-active=done] .col[data-s=done] { display: block; }
.col-head { display: none; }
.stack { display: grid; gap: 10px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px;
  box-shadow: var(--shadow); display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%;
  transition: transform .12s, border-color .15s; animation: pop .25s ease both;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.card:active { transform: scale(.985); }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

.check {
  flex: none; width: 26px; height: 26px; margin-top: 1px; border-radius: 50%; border: 2px solid var(--line); background: transparent;
  display: grid; place-items: center; color: transparent; padding: 0; transition: .15s; position: relative;
}
.check::after { content: ""; position: absolute; inset: -9px; } /* area di tocco più grande */
.check:hover { border-color: var(--accent); }
.check[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }

.card-main { min-width: 0; flex: 1; display: grid; gap: 8px; cursor: pointer; }
.card-title { font-weight: 600; overflow-wrap: anywhere; line-height: 1.35; }
.is-done .card-title { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.card-snippet { color: var(--muted); font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: .8rem; color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); font-weight: 600; }
.badge.late { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.soon { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge .ic svg { width: 13px; height: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.low { background: var(--p-low); } .dot.normal { background: var(--p-normal); } .dot.high { background: var(--p-high); }
.spacer { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; }

.empty { text-align: center; color: var(--muted); padding: 34px 16px; border: 1.5px dashed var(--line); border-radius: var(--radius); font-size: .95rem; }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; }

.ideas { display: grid; gap: 10px; }
.idea { flex-direction: column; gap: 8px; }
.idea .card-main { width: 100%; }

/* FAB mobile */
.fab {
  position: fixed; right: 16px; bottom: calc(76px + var(--safe-b)); z-index: 25; width: 58px; height: 58px; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(38, 44, 237, .4); transition: transform .12s;
}
.fab:active { transform: scale(.92); }
.fab .ic svg { width: 26px; height: 26px; stroke-width: 2.6; }
.desk-only { display: none; }

/* ---------- sheet (dettaglio) ---------- */
dialog { color: var(--ink); padding: 0; border: 0; }
dialog::backdrop { background: rgba(15, 16, 14, .5); backdrop-filter: blur(2px); animation: fade .2s both; }
@keyframes fade { from { opacity: 0; } }

.sheet {
  background: var(--bg); width: 100%; max-width: none; height: 94dvh; max-height: none;
  margin: auto 0 0; border-radius: 22px 22px 0 0; overflow: hidden;
}
.sheet[open] { display: flex; flex-direction: column; animation: up .28s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.grab { width: 38px; height: 4px; background: var(--line); border-radius: 9px; margin: 8px auto 0; flex: none; }
.sheet-bar { display: flex; align-items: center; gap: 4px; padding: 6px 8px 0 16px; flex: none; }
.sheet-bar .kind { font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-right: auto; }
.sheet-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 4px 16px 20px; display: grid; gap: 16px; align-content: start; }
.title-in {
  font-size: 1.3rem; font-weight: 700; border: 0 !important; background: transparent !important; padding: 8px 0 !important;
  letter-spacing: -.01em; width: 100%; outline: none !important; resize: none; min-height: 2.2em !important; overflow: hidden; line-height: 1.3;
}
.meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.meta-grid .full { grid-column: 1 / -1; }
.thread-h { font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; display: flex; align-items: center; gap: 8px; }
.thread-h::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.thread { display: grid; gap: 10px; }
.msg { display: grid; gap: 3px; max-width: 86%; justify-items: start; animation: pop .25s ease both; }
.msg.me { justify-self: end; justify-items: end; }
.bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 16px 16px 16px 5px; padding: 9px 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me .bubble { background: var(--accent-soft); border-color: transparent; border-radius: 16px 16px 5px 16px; }
.msg small { font-size: .74rem; color: var(--muted); display: flex; gap: 8px; align-items: center; padding: 0 4px; }
.msg small button { border: 0; background: none; color: var(--muted); padding: 2px; text-decoration: underline; font-size: inherit; }
.no-comments { color: var(--muted); font-size: .92rem; text-align: center; padding: 6px 0; }

.composer {
  flex: none; display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px calc(10px + var(--safe-b));
  background: var(--surface); border-top: 1px solid var(--line);
}
.composer textarea { min-height: 46px; max-height: 140px; resize: none; border-radius: 22px; padding: 11px 16px; }
.send { flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.send[disabled] { opacity: .4; }
.sheet-foot { flex: none; padding: 12px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--surface); display: grid; }

.pop { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); width: min(300px, calc(100vw - 32px)); margin: 0; position: fixed; inset: auto; top: 60px; right: 16px; padding: 8px; }
.pop::backdrop { background: transparent; backdrop-filter: none; }
.pop .who { display: flex; align-items: center; gap: 10px; padding: 10px; }
.pop .btn { width: 100%; justify-content: flex-start; border: 0; background: transparent; }
.pop .btn:hover { background: var(--surface-2); }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-b)); transform: translateX(-50%); z-index: 100;
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 99px; font-weight: 600; font-size: .92rem;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px); animation: pop .2s both;
}
.toast.err { background: var(--danger); color: #fff; }

/* ---------- desktop ---------- */
@media (min-width: 900px) {
  .top { backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
  .mob-only { display: none !important; }
  .desk-only { display: inline-flex; }
  .tabs {
    position: static; border: 0; background: transparent; padding: 0; backdrop-filter: none; margin-left: 12px; gap: 4px;
  }
  .tabs button { flex: none; display: flex; flex-direction: row; gap: 8px; padding: 8px 14px; font-size: .95rem; min-height: 40px; }
  .tabs button.on { background: var(--accent-soft); }
  .wrap { padding-bottom: 60px; }
  .status-tabs { display: none; }
  .board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; align-items: start; }
  .col, .board[data-active] .col { display: block; background: var(--surface-2); border: 1px solid var(--line); border-radius: 20px; padding: 12px; min-height: 160px; }
  .col-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 12px; font-weight: 700; }
  .col-head .n { font-size: .8rem; color: var(--muted); background: var(--line); border-radius: 99px; padding: 1px 9px; }
  .toast { bottom: 28px; }

  .sheet {
    width: 540px; height: 100dvh; margin: 0 0 0 auto; border-radius: 0; border-left: 1px solid var(--line);
  }
  .sheet[open] { animation: slide .3s cubic-bezier(.2, .8, .2, 1) both; }
  @keyframes slide { from { transform: translateX(40px); opacity: 0; } }
  .grab { display: none; }
}

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

.fields { display: grid; gap: 16px; }
.thread-wrap { display: grid; gap: 12px; }
.del { justify-self: start; }
.small { font-size: .85rem; }
