:root {
  --bg: #f2f2f7; --card: #ffffff; --text: #000; --muted: #8e8e93; --sep: rgba(60,60,67,.16);
  --blue: #0a84ff; --green: #30d158; --red: #ff453a; --orange: #ff9f0a; --fill: rgba(120,120,128,.12);
  --bar: rgba(249,249,249,.84); --shadow: 0 10px 40px rgba(0,0,0,.18);
  --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --card: #1c1c1e; --text: #fff; --muted: #98989d; --sep: rgba(84,84,88,.55); --fill: rgba(120,120,128,.24); --bar: rgba(22,22,24,.84); --shadow: 0 10px 40px rgba(0,0,0,.6); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif; -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
.muted { color: var(--muted); } .small { font-size: 13px; } .err { color: var(--red); min-height: 1.4em; font-size: 15px; }

/* ---- accesso ---- */
#login { align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; text-align: center; display: flex; flex-direction: column; gap: 14px; }
.login-icon { width: 96px; height: 96px; border-radius: 22px; margin: 0 auto; box-shadow: var(--shadow); }
.login-card h1 { margin: 6px 0 0; font-size: 30px; letter-spacing: -.02em; }
.login-card input { height: 52px; border-radius: 14px; border: 0; background: var(--card); padding: 0 16px; font-size: 17px; text-align: center; outline: none; }

/* ---- intestazione ---- */
header { padding: calc(var(--sat) + 8px) 20px 6px; flex: none; background: linear-gradient(var(--bg) 70%, transparent); z-index: 5; }
.head-row { display: flex; justify-content: space-between; align-items: center; height: 36px; }
header h1 { margin: 0; font-size: 34px; line-height: 1.15; font-weight: 800; letter-spacing: -.025em; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); transition: background .3s; }
.dot.ok { background: var(--green); } .dot.busy { background: var(--orange); } .dot.bad { background: var(--red); }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--blue); color: #fff; font-size: 26px; line-height: 34px; font-weight: 400; box-shadow: 0 2px 8px rgba(10,132,255,.4); transition: transform .15s; }
.icon-btn:active { transform: scale(.88); }

/* ---- contenuto ---- */
main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 16px calc(96px + var(--sab)); }
.tab { animation: rise .35s cubic-bezier(.2,.8,.2,1); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.group { background: var(--card); border-radius: 14px; overflow: hidden; margin: 0 0 18px; padding: 0; list-style: none; }
h2.section { margin: 20px 16px 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 500; }
.empty { text-align: center; color: var(--muted); margin: 30px 0; font-size: 15px; }

.composer textarea { width: 100%; border: 0; outline: none; resize: none; background: transparent; padding: 14px 16px 4px; font-size: 17px; }
.composer-bar { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px 12px 16px; }
button.primary { background: var(--blue); color: #fff; height: 36px; padding: 0 20px; border-radius: 18px; font-weight: 600; transition: transform .12s, opacity .2s; }
button.primary.big { height: 52px; border-radius: 14px; font-size: 17px; }
button.primary:active { transform: scale(.95); opacity: .85; }
button.primary:disabled { opacity: .4; }

.list li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; position: relative; min-height: 52px; animation: rise .3s both; }
.list li + li::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: .5px; background: var(--sep); }
.list li:active { background: var(--fill); }
.check { flex: none; width: 24px; height: 24px; border-radius: 50%; border: 1.7px solid var(--muted); display: grid; place-items: center; transition: all .25s cubic-bezier(.3,1.4,.5,1); }
.check svg { width: 14px; height: 14px; stroke: #fff; stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 20; stroke-dashoffset: 20; transition: stroke-dashoffset .3s .05s; }
.check.on { background: var(--green); border-color: var(--green); transform: scale(1.06); } .check.on svg { stroke-dashoffset: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 17px; overflow-wrap: anywhere; } .row-sub { font-size: 13px; color: var(--muted); margin-top: 1px; }
li.done .row-title { color: var(--muted); text-decoration: line-through; }
.chip { flex: none; font-size: 13px; font-weight: 600; padding: 3px 9px; border-radius: 10px; background: color-mix(in srgb, var(--blue) 16%, transparent); color: var(--blue); }
.x { flex: none; width: 30px; height: 30px; border-radius: 50%; color: var(--muted); font-size: 22px; line-height: 28px; }

/* ---- agenda ---- */
.day { margin: 18px 4px 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.day.today { color: var(--blue); }
.time { flex: none; width: 54px; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--blue); }
.bar { flex: none; width: 4px; align-self: stretch; border-radius: 2px; background: var(--blue); margin: 2px 0; }

/* ---- bacheca ---- */
.seg { display: flex; gap: 2px; background: var(--fill); border-radius: 10px; padding: 2px; margin-bottom: 16px; }
.seg button { flex: 1; padding: 7px 2px; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); transition: all .25s; white-space: nowrap; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 2px 6px rgba(0,0,0,.18); }
.seg small { opacity: .7; font-weight: 500; }

/* ---- barra a schede ---- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; padding: 8px 12px calc(var(--sab) + 4px);
  background: var(--bar); backdrop-filter: saturate(180%) blur(22px); -webkit-backdrop-filter: saturate(180%) blur(22px); border-top: .5px solid var(--sep); z-index: 10; }
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 1; color: var(--muted); font-size: 10.5px; font-weight: 500; transition: color .2s, transform .2s; }
.tabbar button svg { width: 27px; height: 27px; stroke: currentColor; stroke-width: 1.7; fill: none; stroke-linecap: round; stroke-linejoin: round; transition: transform .35s cubic-bezier(.3,1.6,.5,1); }
.tabbar button.on { color: var(--blue); } .tabbar button.on svg { transform: scale(1.12); }

/* ---- sheet ---- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; animation: fade .25s; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--bg); border-radius: 22px 22px 0 0; max-height: 92%; overflow-y: auto; padding-bottom: calc(var(--sab) + 16px);
  box-shadow: var(--shadow); animation: up .42s cubic-bezier(.2,.9,.25,1); }
@keyframes up { from { transform: translateY(100%); } }
.sheet.closing { animation: down .26s ease-in forwards; } .scrim.closing { animation: fadeout .26s forwards; }
@keyframes down { to { transform: translateY(100%); } } @keyframes fadeout { to { opacity: 0; } }
.sheet-grab { width: 38px; height: 5px; border-radius: 3px; background: var(--sep); margin: 8px auto 0; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px 12px; }
.link { color: var(--blue); font-size: 17px; } .bold { font-weight: 600; }
.sheet-body { padding: 0 16px; }
.field { display: flex; align-items: center; gap: 12px; padding: 12px 16px; position: relative; }
.field + .field::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: .5px; background: var(--sep); }
.field label { flex: none; width: 84px; color: var(--muted); font-size: 15px; }
.field input, .field select, .field textarea { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font-size: 17px; text-align: right; padding: 0; }
.field textarea { text-align: left; resize: none; }
.field.block { align-items: flex-start; } .field.block textarea { height: 90px; }
button.danger { width: 100%; background: var(--card); color: var(--red); height: 52px; border-radius: 14px; font-size: 17px; margin-top: 4px; }

.toast { position: fixed; left: 50%; bottom: calc(86px + var(--sab)); transform: translateX(-50%); background: rgba(60,60,64,.95); color: #fff; padding: 10px 18px; border-radius: 22px; font-size: 15px; z-index: 30;
  animation: pop .45s cubic-bezier(.2,1.4,.4,1); box-shadow: var(--shadow); max-width: 90%; text-align: center; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 20px) scale(.9); } }
@media (min-width: 700px) { main, header { max-width: 640px; margin: 0 auto; width: 100%; } }
