/* ToDo – un'unica colonna da telefono: data grande, carico del giorno, argomenti con le attività
   sotto, barra di dettatura in basso. I colori delle aree (lavoro, casa, altro) sono l'unico
   tocco forte; tutto il resto resta neutro. */
:root {
  --bg: #eef0f4;
  --surface: #ffffff;
  --ink: #141822;
  --muted: #6b7384;
  --line: #dfe3ea;
  --soft: #f5f6f9;

  --lavoro: #2f62e0;
  --lavoro-soft: #e6edff;
  --casa: #e46f2c;
  --casa-soft: #fdeee4;
  --altro: #8a55e6;
  --altro-soft: #f1eafe;

  --good: #1f9d63;
  --bad: #d4383d;

  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --r: 18px;
  --shadow: 0 1px 2px rgba(20, 24, 34, .05), 0 6px 20px -10px rgba(20, 24, 34, .18);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --surface: #181c25; --ink: #eef1f6; --muted: #949cad; --line: #2a303c; --soft: #1e232d;
    --lavoro: #6b93ff; --lavoro-soft: #1d2a4d; --casa: #ff9658; --casa-soft: #3d2618; --altro: #b28cff; --altro-soft: #2c2247;
    --good: #3ccf8a; --bad: #ff6b6f;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 24px -12px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1218; --surface: #181c25; --ink: #eef1f6; --muted: #949cad; --line: #2a303c; --soft: #1e232d;
  --lavoro: #6b93ff; --lavoro-soft: #1d2a4d; --casa: #ff9658; --casa-soft: #3d2618; --altro: #b28cff; --altro-soft: #2c2247;
  --good: #3ccf8a; --bad: #ff6b6f;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 24px -12px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 400 16px/1.45 var(--f-body); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2.5px solid var(--lavoro); outline-offset: 2px; border-radius: 8px; }
.hidden { display: none !important; }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; font-weight: 500; letter-spacing: -.02em; }
.hint { color: var(--muted); font-size: .86rem; margin: 0; }
.error { color: var(--bad); font-size: .9rem; min-height: 1.2em; margin: 8px 0 0; }

/* Aree: ogni elemento con .area-x prende il suo colore in --a */
.area-lavoro { --a: var(--lavoro); --a-soft: var(--lavoro-soft); }
.area-casa   { --a: var(--casa);   --a-soft: var(--casa-soft); }
.area-altro  { --a: var(--altro);  --a-soft: var(--altro-soft); }

/* ------------------------------------------------------------------ guscio */
.app { position: relative; height: 100%; max-width: 640px; margin: 0 auto; overflow: hidden; display: flex; flex-direction: column; }
.main { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: calc(env(safe-area-inset-top) + 14px) 16px 0; scroll-behavior: smooth; }
.scroll-pad { height: 24px; }

/* ------------------------------------------------------------------ intestazione */
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 6px 2px 14px; }
.date { display: flex; flex-direction: column; line-height: 1; }
.d-weekday { font: 600 .82rem var(--f-body); text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin-bottom: 6px; }
.d-row { display: flex; align-items: baseline; gap: 10px; }
.d-day { font: 800 clamp(3.4rem, 15vw, 4.4rem)/.82 var(--f-display); letter-spacing: -.04em; font-variation-settings: "opsz" 96; }
.d-month { font: 500 1.45rem var(--f-display); letter-spacing: -.02em; color: var(--muted); }
.icon-btn { border: 0; background: var(--surface); width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; box-shadow: var(--shadow); transition: transform .2s var(--ease); }
.icon-btn:active { transform: scale(.92); }

/* ------------------------------------------------------------------ carico del giorno */
.gauge { background: var(--surface); border-radius: var(--r); padding: 14px 16px 12px; box-shadow: var(--shadow); }
.gauge-text { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; font-size: .92rem; color: var(--muted); }
.gauge-text b { color: var(--ink); font-size: 1.05rem; }
.g-note { font-size: .82rem; font-weight: 600; }
.g-note.over { color: var(--bad); }
.g-note.ok { color: var(--good); }
.gauge-bar { position: relative; display: flex; gap: 3px; height: 12px; margin: 10px 0 10px; border-radius: 7px; background: var(--soft); overflow: hidden; }
.seg { display: block; height: 100%; width: 0; border-radius: 7px; transition: width .9s var(--ease); }
.seg-lavoro { background: var(--lavoro); }
.seg-casa { background: var(--casa); }
.seg-altro { background: var(--altro); }
.cap-mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); opacity: 0; transition: left .9s var(--ease), opacity .3s; }
.gauge-bar.over .cap-mark { opacity: .55; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .8rem; color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg i { width: 8px; height: 8px; border-radius: 3px; }
.lg-lavoro i { background: var(--lavoro); } .lg-casa i { background: var(--casa); } .lg-altro i { background: var(--altro); }
.lg b { color: var(--ink); font-size: .78rem; }

/* ------------------------------------------------------------------ filtri */
.filters { display: flex; flex-direction: column; gap: 10px; margin: 16px 0 6px; }
.seg-ctl { position: relative; display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border-radius: 14px; padding: 4px; box-shadow: var(--shadow); }
.seg-ctl button { position: relative; z-index: 1; border: 0; background: transparent; padding: 9px 0; font-weight: 600; color: var(--muted); border-radius: 10px; transition: color .25s; }
.seg-ctl button.active { color: var(--bg); }
.seg-pill { position: absolute; top: 4px; bottom: 4px; left: 4px; width: calc((100% - 8px) / 3); border-radius: 10px; background: var(--ink); transition: transform .45s var(--spring); }
.area-chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.area-chips button { flex-shrink: 0; display: inline-flex; align-items: center; gap: 7px; border: 1.5px solid var(--line); background: transparent; padding: 6px 13px; border-radius: 999px; font-size: .88rem; font-weight: 500; color: var(--muted); transition: all .25s var(--ease); }
.area-chips button i { width: 9px; height: 9px; border-radius: 50%; }
.chip-lavoro i { background: var(--lavoro); } .chip-casa i { background: var(--casa); } .chip-altro i { background: var(--altro); }
.area-chips button.active { color: var(--ink); border-color: var(--ink); background: var(--surface); }
.area-chips .chip-lavoro.active { border-color: var(--lavoro); background: var(--lavoro-soft); }
.area-chips .chip-casa.active { border-color: var(--casa); background: var(--casa-soft); }
.area-chips .chip-altro.active { border-color: var(--altro); background: var(--altro-soft); }

/* ------------------------------------------------------------------ argomenti */
.groups { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.group { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; position: relative; }
.group::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--a); }
.g-head { display: flex; align-items: center; gap: 12px; padding: 14px 12px 12px 20px; cursor: pointer; user-select: none; }
.g-titles { flex: 1; min-width: 0; }
.g-area { display: inline-block; font-size: .68rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--a); margin-bottom: 1px; }
.g-titles h3 { margin: 0; font: 700 1.22rem/1.15 var(--f-display); letter-spacing: -.02em; overflow-wrap: anywhere; text-wrap: balance; }
.g-meta { margin: 3px 0 0; font-size: .8rem; color: var(--muted); }
.g-meta .late { color: var(--bad); font-weight: 600; }
.ring { flex-shrink: 0; width: 38px; height: 38px; position: relative; }
.ring svg { transform: rotate(-90deg); display: block; }
.ring .bg { stroke: var(--a-soft); }
.ring .fg { stroke: var(--a); stroke-linecap: round; transition: stroke-dashoffset .8s var(--ease); }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font: 500 .68rem var(--f-mono); color: var(--muted); }
.ring.full span { color: var(--a); font-size: .95rem; }
.g-more { border: 0; background: transparent; width: 34px; height: 34px; border-radius: 10px; color: var(--muted); display: grid; place-items: center; flex-shrink: 0; }
.g-more:hover { background: var(--soft); }
.g-chev { transition: transform .35s var(--ease); color: var(--muted); flex-shrink: 0; }
.group.collapsed .g-chev { transform: rotate(-90deg); }
.g-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .4s var(--ease); }
.group.collapsed .g-body { grid-template-rows: 0fr; }
.g-body > ul { min-height: 0; overflow: hidden; list-style: none; margin: 0; padding: 0 10px 8px 14px; }

/* attività (sotto-argomenti) con la linea ad albero dell'area */
.task { position: relative; margin-left: 6px; }
.task::before { content: ""; position: absolute; left: 4px; top: 0; bottom: 0; width: 2px; background: var(--a-soft); }
.task:last-child::before { bottom: 50%; }
.task::after { content: ""; position: absolute; left: 4px; top: 50%; width: 12px; height: 2px; background: var(--a-soft); }
.task-inner { position: relative; z-index: 1; display: flex; gap: 10px; align-items: flex-start; margin-left: 18px; padding: 10px 8px; border-radius: 12px; background: var(--surface); touch-action: pan-y; transition: transform .35s var(--ease), background .2s; }
.task-inner.dragging { transition: none; }
.task-inner:hover { background: var(--soft); }
.swipe-bg { position: absolute; inset: 2px 0 2px 24px; border-radius: 12px; display: flex; justify-content: space-between; align-items: center; padding: 0 16px; font-size: .82rem; font-weight: 600; color: #fff; opacity: 0; }
.swipe-bg.right { opacity: 1; background: var(--good); }
.swipe-bg.left { opacity: 1; background: var(--bad); }
.swipe-bg.right .sw-del, .swipe-bg.left .sw-done { visibility: hidden; }

.check { flex-shrink: 0; width: 26px; height: 26px; border: 0; padding: 0; background: transparent; margin-top: 1px; color: var(--a); }
.check svg { display: block; }
.check .c-ring { stroke: currentColor; opacity: .55; transition: opacity .2s, fill .3s; fill: transparent; }
.check:hover .c-ring { opacity: 1; }
.check .c-tick { stroke: #fff; stroke-dasharray: 16; stroke-dashoffset: 16; transition: stroke-dashoffset .35s var(--ease) .05s; }
.task.done .check .c-ring, .task.completing .check .c-ring { fill: currentColor; opacity: 1; }
.task.done .check .c-tick, .task.completing .check .c-tick { stroke-dashoffset: 0; }
.t-body { flex: 1; min-width: 0; cursor: pointer; }
.t-title { font-weight: 500; overflow-wrap: anywhere; position: relative; display: inline; background: linear-gradient(currentColor, currentColor) 0 55% / 0 1.5px no-repeat; transition: background-size .4s var(--ease), color .3s; }
.task.done .t-title, .task.completing .t-title { background-size: 100% 1.5px; color: var(--muted); }
.t-notes { font-size: .84rem; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.t-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 5px; font-size: .78rem; color: var(--muted); }
.t-meta .mono { font-size: .76rem; }
.t-meta .late { color: var(--bad); font-weight: 600; }
.t-meta .over { color: var(--bad); }
.t-meta svg { vertical-align: -2px; margin-right: 3px; }
.task.nofit .t-title { color: var(--muted); }

/* priorità: tre tacche come un indicatore di segnale */
.pb { display: inline-flex; align-items: flex-end; gap: 2px; height: 11px; vertical-align: -1px; }
.pb b { width: 3px; border-radius: 1px; background: var(--line); }
.pb b:nth-child(1) { height: 5px; } .pb b:nth-child(2) { height: 8px; } .pb b:nth-child(3) { height: 11px; }
.pb.p3 b:nth-child(1) { background: var(--muted); }
.pb.p2 b:nth-child(-n+2) { background: var(--ink); }
.pb.p1 b { background: var(--bad); }

/* ------------------------------------------------------------------ animazioni */
.app.intro .group { animation: rise .6s var(--ease) both; animation-delay: calc(var(--i, 0) * 70ms + 120ms); }
.app.intro .gauge, .app.intro .top, .app.intro .filters { animation: rise .6s var(--ease) both; }
.app.intro .gauge { animation-delay: 60ms; }
.app.intro .filters { animation-delay: 100ms; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.task.just-added .task-inner { animation: landed 1.6s var(--ease); }
@keyframes landed {
  0% { transform: scale(.94); box-shadow: 0 0 0 0 var(--a); background: var(--a-soft); }
  25% { transform: scale(1.02); box-shadow: 0 0 0 6px color-mix(in srgb, var(--a) 25%, transparent); background: var(--a-soft); }
  100% { transform: none; box-shadow: 0 0 0 0 transparent; }
}
.group.just-added { animation: pop .7s var(--spring); }
@keyframes pop { from { transform: scale(.96); opacity: .4; } }
.burst { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: var(--a); pointer-events: none; z-index: 5; animation: burst .7s var(--ease) forwards; }
@keyframes burst { to { transform: translate(var(--dx), var(--dy)) scale(.2); opacity: 0; } }
.ghost-chip { position: absolute; z-index: 30; pointer-events: none; padding: 9px 14px; border-radius: 14px; background: var(--surface); box-shadow: 0 10px 30px -8px rgba(0,0,0,.35); font-weight: 500; border-left: 5px solid var(--a); white-space: nowrap; max-width: 80%; overflow: hidden; text-overflow: ellipsis; }

/* ------------------------------------------------------------------ dock di inserimento */
.dock { position: relative; z-index: 6; display: flex; align-items: flex-end; gap: 10px; padding: 10px 14px calc(env(safe-area-inset-bottom) + 12px); background: linear-gradient(to top, var(--bg) 70%, transparent); }
.dock-field { flex: 1; min-width: 0; display: flex; align-items: flex-end; background: var(--surface); border-radius: 24px; box-shadow: var(--shadow); padding: 4px 4px 4px 16px; border: 1.5px solid transparent; transition: border-color .2s; }
.dock-field:focus-within { border-color: var(--ink); }
.dock textarea { flex: 1; min-width: 0; width: 100%; border: 0; background: transparent; resize: none; padding: 10px 0; max-height: 140px; line-height: 1.35; outline: none; }
.send { flex-shrink: 0; width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--ink); color: var(--bg); display: grid; place-items: center; transform: scale(0); transition: transform .3s var(--spring); }
.dock.has-text .send { transform: scale(1); }
.send.busy { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.mic { position: relative; flex-shrink: 0; width: 58px; height: 58px; border-radius: 50%; border: 0; color: #fff; display: grid; place-items: center;
  background: conic-gradient(from 200deg, var(--lavoro), var(--altro), var(--casa), var(--lavoro));
  box-shadow: 0 10px 24px -8px color-mix(in srgb, var(--altro) 70%, transparent); transition: transform .25s var(--spring); }
.mic::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: var(--ink); z-index: 0; }
.mic svg { position: relative; z-index: 1; color: var(--bg); }
.mic:active { transform: scale(.9); }

/* ------------------------------------------------------------------ ascolto */
.listen { position: absolute; inset: 0; z-index: 20; display: flex; align-items: flex-end; background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); animation: fade .25s; }
@keyframes fade { from { opacity: 0; } }
.listen-card { width: 100%; background: var(--surface); border-radius: 28px 28px 0 0; padding: 28px 22px calc(env(safe-area-inset-bottom) + 22px); text-align: center; box-shadow: 0 -10px 40px -20px rgba(0,0,0,.4); animation: sheet-in .45s var(--ease); }
.orb { position: relative; width: 96px; height: 96px; margin: 4px auto 14px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  background: conic-gradient(from 0deg, var(--lavoro), var(--altro), var(--casa), var(--lavoro)); animation: rotate 6s linear infinite; }
.orb svg { position: relative; z-index: 2; animation: rotate 6s linear infinite reverse; }
.orb span { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--altro); opacity: 0; animation: ripple 2.4s var(--ease) infinite; }
.orb span:nth-child(2) { animation-delay: .8s; border-color: var(--lavoro); }
.orb span:nth-child(3) { animation-delay: 1.6s; border-color: var(--casa); }
@keyframes rotate { to { transform: rotate(360deg); } }
@keyframes ripple { 0% { transform: scale(1); opacity: .7; } 100% { transform: scale(1.9); opacity: 0; } }
.listen.thinking .orb { animation-duration: 1.4s; }
.listen.thinking .orb span { animation: none; }
.listen-state { font: 700 1.3rem var(--f-display); margin: 0 0 6px; }
.listen.thinking .listen-state { background: linear-gradient(90deg, var(--muted), var(--ink), var(--muted)); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.listen-text { min-height: 2.8em; margin: 0 auto 10px; max-width: 30em; font-size: 1.05rem; color: var(--ink); }
.listen-text .cursor { display: inline-block; width: 2px; height: 1.1em; background: var(--altro); vertical-align: -2px; margin-left: 2px; animation: blink .8s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.wave { display: flex; justify-content: center; align-items: center; gap: 4px; height: 34px; margin-bottom: 12px; }
.wave i { width: 4px; border-radius: 2px; background: var(--ink); opacity: .75; height: 6px; transition: height .12s; }
.listen.thinking .wave { opacity: .25; }

/* ------------------------------------------------------------------ toast */
.toast { position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 92px); z-index: 25; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; width: max-content; max-width: calc(100% - 28px); min-width: min(320px, calc(100% - 28px));
  padding: 12px 14px 12px 16px; border-radius: 16px; background: var(--ink); color: var(--bg); font-size: .9rem; box-shadow: 0 14px 30px -12px rgba(0,0,0,.5); animation: toast-in .45s var(--spring); white-space: pre-line; }
.toast > span { flex: 1; }
.toast button { flex-shrink: 0; border: 0; background: transparent; color: color-mix(in srgb, var(--lavoro) 55%, #fff); font-weight: 700; padding: 4px 6px; }
@keyframes toast-in { from { transform: translate(-50%, 20px) scale(.95); opacity: 0; } }

/* ------------------------------------------------------------------ vuoto */
.empty { text-align: center; color: var(--muted); padding: 34px 0 10px; animation: rise .5s var(--ease); }
.empty p { margin: 8px 0 0; }

/* ------------------------------------------------------------------ fogli */
.sheet-wrap { position: absolute; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.scrim { position: absolute; inset: 0; background: rgba(10, 12, 18, .42); animation: fade .25s; }
.sheet { position: relative; width: 100%; max-height: 92%; overflow-y: auto; background: var(--surface); border-radius: 26px 26px 0 0; padding: 10px 18px calc(env(safe-area-inset-bottom) + 18px); animation: sheet-in .42s var(--ease); }
.sheet.small { margin: 0 12px 12px; border-radius: 22px; padding-top: 18px; }
.sheet-wrap.closing .sheet { animation: sheet-out .25s var(--ease) forwards; }
.sheet-wrap.closing .scrim { animation: fade .25s reverse forwards; }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet h2 { margin: 0 0 12px; font: 700 1.4rem var(--f-display); letter-spacing: -.02em; }
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: .8rem; font-weight: 500; color: var(--muted); }
.field input, .field textarea, .est input { width: 100%; border: 1.5px solid var(--line); background: var(--soft); border-radius: 12px; padding: 10px 12px; font-size: 1rem; color: var(--ink); transition: border-color .2s, background .2s; }
.field input:focus, .field textarea:focus, .est input:focus { outline: none; border-color: var(--ink); background: var(--surface); }
.field small { font-weight: 400; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
fieldset { border: 0; border-top: 1px solid var(--line); margin: 4px 0 0; padding: 12px 0 0; display: flex; flex-direction: column; gap: 10px; }
legend { font: 700 .95rem var(--f-display); padding-right: 8px; color: var(--ink); }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.spacer { flex: 1; }
.btn { border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 600; background: var(--soft); transition: transform .15s, background .2s; }
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: var(--soft); }
.btn.danger { background: transparent; color: var(--bad); }
.btn.danger-fill { background: var(--bad); color: #fff; }
.btn.wide { width: 100%; padding: 13px; }

.area-pick, .prio-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.area-pick button, .prio-pick button { border: 1.5px solid var(--line); background: var(--surface); border-radius: 11px; padding: 9px 4px; font-size: .86rem; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: all .2s var(--ease); }
.area-pick.big button { padding: 13px 4px; }
.area-pick .ap-lavoro.on { border-color: var(--lavoro); background: var(--lavoro-soft); color: var(--lavoro); }
.area-pick .ap-casa.on { border-color: var(--casa); background: var(--casa-soft); color: var(--casa); }
.area-pick .ap-altro.on { border-color: var(--altro); background: var(--altro-soft); color: var(--altro); }
.prio-pick button.on { border-color: var(--ink); color: var(--ink); background: var(--soft); }
.est { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.est input { width: 90px; }
.est .unit { color: var(--muted); font-size: .9rem; margin-right: 4px; }
.est-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.est-chips button { border: 1.5px solid var(--line); background: transparent; border-radius: 999px; padding: 5px 11px; font: 500 .8rem var(--f-mono); color: var(--muted); }
.est-chips button.on { border-color: var(--ink); color: var(--ink); }

.switch { display: flex; align-items: center; gap: 12px; font-size: .95rem; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch span { position: relative; flex-shrink: 0; width: 44px; height: 26px; border-radius: 13px; background: var(--line); transition: background .25s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .3s var(--spring); }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2.5px solid var(--lavoro); outline-offset: 2px; }

.prop-list { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 14px; }
.prop { border-radius: 14px; border: 1.5px solid var(--line); padding: 10px 12px 12px; position: relative; overflow: hidden; animation: rise .4s var(--ease) both; }
.prop::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--a); }
.prop .p-top { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; margin-bottom: 8px; padding-left: 4px; }
.prop .p-top select { width: auto; }
.prop .p-top input { min-width: 0; width: 100%; border: 0; border-bottom: 1.5px dashed var(--line); background: transparent; font: 700 1rem var(--f-display); padding: 3px 0; color: var(--a); }
.prop .p-title { width: 100%; border: 1.5px solid var(--line); background: var(--soft); border-radius: 10px; padding: 8px 10px; }
.prop .p-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 6px; }
.prop select, .prop .p-grid input { width: 100%; border: 1.5px solid var(--line); background: var(--soft); border-radius: 10px; padding: 7px 8px; font-size: .88rem; }
.prop .p-x { border: 0; background: transparent; color: var(--muted); font-size: 1.1rem; padding: 0 4px; }

/* ------------------------------------------------------------------ accesso */
.login { flex: 1; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: 24px; padding: 28px 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; animation: rise .6s var(--ease); }
.login-card h1 { margin: 0; font: 800 2.6rem/.9 var(--f-display); letter-spacing: -.04em; }
.login-card p { margin: 0; }
.login-mark { display: flex; gap: 5px; }
.login-mark span { width: 26px; height: 8px; border-radius: 4px; background: var(--lavoro); }
.login-mark span:nth-child(2) { background: var(--casa); width: 16px; }
.login-mark span:nth-child(3) { background: var(--altro); width: 10px; }

@media (min-width: 700px) {
  .app { padding: 0 8px; }
  .sheet { max-width: 560px; border-radius: 26px; margin-bottom: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* modalità auto: solo microfono grande */
.car-exit { display: none; }
body.car > *:not(.dock):not(#toast) { visibility: hidden; }
body.car .mic { position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%); width: 56vmin; height: 56vmin; z-index: 50; visibility: visible; }
body.car .mic svg { width: 40%; height: 40%; }
body.car .car-exit { display: block; position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 60; visibility: visible; background: transparent; color: var(--ink); border: 1px solid currentColor; border-radius: 20px; padding: 10px 18px; opacity: .7; }

.car-state, .car-text { display: none; }
body.car .car-state { display: block; position: fixed; left: 0; right: 0; top: calc(42% + 40vmin); text-align: center; font: 700 1.5rem var(--f-display, system-ui); z-index: 60; visibility: visible; padding: 0 16px; }
body.car .car-text { display: block; position: fixed; left: 0; right: 0; top: calc(42% + 40vmin + 3rem); text-align: center; font-size: 1.15rem; z-index: 60; visibility: visible; padding: 0 20px; opacity: .8; }
/* registrazione: microfono rosso con onde che pulsano */
body.car.rec .mic { background: #e5342b; animation: car-pulse 1.1s ease-in-out infinite; }
body.car.rec .mic::after { background: #e5342b; }
body.car.rec .mic svg { color: #fff; }
body.car.rec .mic::before { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 6px solid #e5342b; animation: car-ring 1.1s ease-out infinite; }
body.car.rec .car-state { color: #e5342b; }
body.car.thinking .mic { opacity: .5; animation: car-pulse 1.8s ease-in-out infinite; }
body.car.done .mic { background: #1f9d55; }
body.car.done .mic::after { background: #1f9d55; }
body.car.done .mic svg { color: #fff; }
body.car.done .car-state { color: #1f9d55; }
@keyframes car-pulse { 0%,100% { transform: translate(-50%,-50%) scale(1); } 50% { transform: translate(-50%,-50%) scale(1.08); } }
@keyframes car-ring { 0% { transform: scale(1); opacity: .8; } 100% { transform: scale(1.35); opacity: 0; } }

/* Impostazioni a tendina */
details.grp { border-top: 1px solid var(--line); }
details.grp > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; padding: 14px 2px; font: 700 1rem var(--f-display); color: var(--ink); min-height: 48px; }
details.grp > summary::-webkit-details-marker { display: none; }
details.grp > summary::after { content: "›"; font-size: 1.4rem; line-height: 1; color: var(--muted); transition: transform .15s; }
details.grp[open] > summary::after { transform: rotate(90deg); }
details.grp > .grp-body { display: flex; flex-direction: column; gap: 10px; padding: 0 0 14px; }
details.grp[hidden] { display: none; }

/* Utenti */
.users-list { display: flex; flex-direction: column; gap: 8px; }
.user-row { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.user-row .u-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.user-row .u-name { font-weight: 700; }
.user-row .u-meta { color: var(--muted); font-size: .8rem; }
.user-row .u-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.user-row .u-actions .btn { padding: 6px 10px; min-height: 36px; font-size: .85rem; }
.user-row .u-qr { display: none; justify-content: center; background: #fff; border-radius: 10px; padding: 8px; }
.user-row .u-qr.open { display: flex; }
.user-row .u-qr { flex-direction: column; align-items: center; gap: 6px; padding: 14px; }
.user-row .u-qr svg { width: min(300px, 78vw); height: min(300px, 78vw); }
.user-row .u-qr small { color: #444; font-size: 11px; word-break: break-all; text-align: center; max-width: 300px; }

.theme-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: var(--soft); border-radius: 14px; padding: 4px; }
.theme-pick button { border: 0; background: transparent; padding: 10px 0; font-weight: 600; color: var(--muted); border-radius: 10px; min-height: 44px; }
.theme-pick button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

/* Schermi larghi (PC, tablet orizzontale): non piu' una colonna da telefono ma due colonne.
   A sinistra data, carico del giorno e filtri; a destra le attivita' a schede affiancate. */
@media (min-width: 900px) {
  .app { max-width: 1280px; padding: 0 16px; }
  .scroll { display: grid; grid-template-columns: 330px minmax(0, 1fr); grid-template-rows: auto auto auto 1fr; column-gap: 28px; align-content: start; padding-left: 4px; padding-right: 4px; }
  .scroll > .top { grid-column: 1; grid-row: 1; }
  .scroll > .gauge { grid-column: 1; grid-row: 2; align-self: start; }
  .scroll > .filters { grid-column: 1; grid-row: 3; align-self: start; }
  .scroll > .groups { grid-column: 2; grid-row: 1 / -1; display: block; columns: 380px; column-gap: 14px; margin-top: 8px; }
  .scroll > .groups > .group { break-inside: avoid; margin-bottom: 14px; }
  .scroll > .empty { grid-column: 2; grid-row: 1; }
  .scroll > .scroll-pad { grid-column: 1 / -1; }
  .dock { max-width: 760px; width: 100%; margin: 0 auto; }
  .sheet-wrap { align-items: center; }
  .sheet { max-width: 620px; max-height: 88%; margin-bottom: 0; border-radius: 26px; }
}

/* sottoattività: stesse righe, rientrate; i pulsanti compaiono al passaggio del mouse (sempre visibili al tocco) */
.task[data-depth] { margin-left: calc(6px + var(--depth, 0) * 22px); }
.task[data-depth="0"] { margin-left: 6px; }
.t-fold, .t-sub { border: 0; background: transparent; color: var(--muted); width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; cursor: pointer; }
.t-fold:hover, .t-sub:hover { background: var(--soft); color: var(--ink); }
.t-fold svg { transition: transform .25s var(--ease); }
.t-fold.closed svg { transform: rotate(-90deg); }
.subprog { color: var(--muted); }
@media (hover: hover) { .t-sub { opacity: 0; } .task-inner:hover .t-sub, .t-sub:focus-visible { opacity: 1; } }
.parent-line { margin: -4px 0 8px; font-weight: 600; }
.e-subs { list-style: none; margin: 4px 0 8px; padding: 0; display: grid; gap: 4px; }
.e-subs li { padding: 7px 10px; background: var(--soft); border-radius: 10px; }
.e-subs li.done { text-decoration: line-through; color: var(--muted); }

/* PC: strumenti di ricerca, vista settimana, trascinamento, selezione da tastiera */
.desk-tools { display: none; }
.linkbtn { border: 0; background: transparent; color: var(--muted); font-size: .85rem; padding: 6px 2px; text-align: left; cursor: pointer; }
.linkbtn:hover { color: var(--ink); }
.t-grip { display: none; color: var(--muted); cursor: grab; user-select: none; font-size: .9rem; letter-spacing: -2px; align-self: center; padding: 6px 2px; }
.task.sel .task-inner { outline: 2px solid var(--ink); outline-offset: -2px; }
.task.dragging-src { opacity: .45; }
.task.drop-on .task-inner, .g-head.drop-on { outline: 2px dashed var(--a, var(--ink)); outline-offset: -2px; background: var(--soft); }
.seg-ctl.dim .seg-pill { opacity: .25; }
.week { display: grid; gap: 10px; margin-top: 8px; }
.wk-day { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 10px 14px 12px; border: 2px solid transparent; }
.wk-day.today { border-color: var(--lavoro); }
.wk-day.late h4 { color: var(--bad); }
.wk-day.drop-on { border-color: var(--ink); background: var(--soft); }
.wk-day header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.wk-day h4 { margin: 0; font: 700 1rem var(--f-display); } .wk-day h4 small { color: var(--muted); font-weight: 500; }
.wk-day .over { color: var(--bad); }
.wk-list { display: flex; flex-wrap: wrap; gap: 8px; }
.wk-empty { margin: 2px 0; color: var(--muted); font-size: .85rem; }
.wk-chip { display: flex; gap: 8px; align-items: flex-start; min-width: 200px; max-width: 320px; flex: 1 1 220px; background: var(--soft); border-left: 4px solid var(--a, var(--line)); border-radius: 10px; padding: 8px 10px; cursor: grab; }
.wk-chip.area-lavoro { --a: var(--lavoro); } .wk-chip.area-casa { --a: var(--casa); } .wk-chip.area-altro { --a: var(--altro); }
.wk-check { border: 0; background: transparent; font-size: 1.15rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 0; }
.wk-t { font-weight: 500; overflow-wrap: anywhere; } .wk-m { color: var(--muted); font-size: .8rem; }
.keys { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 8px 0 12px; }
.keys dt { font: 600 .85rem var(--f-mono); background: var(--soft); padding: 3px 8px; border-radius: 8px; justify-self: start; }
.keys dd { margin: 0; align-self: center; }
@media (min-width: 900px) {
  .desk-tools { display: grid; gap: 8px; margin-top: 6px; }
  .desk-tools input[type=search] { width: 100%; padding: 10px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); }
  .desk-tools select { width: 100%; padding: 9px 10px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); }
  .desk-tools .btn.on { background: var(--ink); color: var(--bg); }
  .t-grip { display: block; opacity: 0; } .task-inner:hover .t-grip { opacity: 1; }
  .scroll > .week { grid-column: 2; grid-row: 1 / -1; margin-top: 8px; }
}

.p-mail { display: grid; gap: 6px; margin-top: 8px; padding: 8px; background: var(--soft); border-radius: 12px; font-size: .88rem; }
.p-mail label { display: grid; gap: 2px; color: var(--muted); font-weight: 600; }
.p-mail input, .p-mail textarea { width: 100%; padding: 7px 9px; border-radius: 9px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; }
.p-mail small { color: var(--muted); }
