:root {
  color-scheme: light dark;
  --bg: #f2f5fa;
  --surface: #ffffff;
  --ink: #14213d;
  --muted: #59647f;
  --line: #dde3ee;
  --accent: #2f5bea;
  --on-accent: #ffffff;
  --danger: #c62f3d;
  --shadow: 0 1px 2px rgba(20, 33, 61, .06);
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1322;
    --surface: #172038;
    --ink: #eef1f8;
    --muted: #9fa9c4;
    --line: #27314f;
    --accent: #7b97ff;
    --on-accent: #0e1322;
    --danger: #ff7a86;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.4 var(--font);
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
svg { width: 1.5rem; height: 1.5rem; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 1rem calc(7rem + env(safe-area-inset-bottom));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}

/* ---------- intestazione ---------- */
.top {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: calc(1rem + env(safe-area-inset-top)) 0 .6rem;
}
.titles { flex: 1; min-width: 0; }
h1 { margin: 0; font-size: 1.7rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.15; }
.top.has-nav h1 { font-size: 1.4rem; white-space: nowrap; }
.nav { display: flex; align-items: center; }
.nav .ghost { min-width: 40px; }
.nav .ghost.txt { padding: 0 .4rem; }
.ghost {
  min-width: 44px; height: 44px;
  display: inline-grid; place-items: center;
  border: 0; border-radius: 22px;
  background: transparent;
  color: var(--ink);
}
.ghost.txt { padding: 0 .7rem; font-weight: 650; }
.ghost:active { background: var(--line); }
.avatar {
  width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  font-weight: 750; font-size: 1.1rem;
}

/* ---------- barra vista + filtri ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: .3rem 0 .7rem;
  display: grid; gap: .6rem;
}
.seg {
  display: grid; grid-template-columns: 1fr 1fr;
  padding: 4px; gap: 4px;
  background: var(--line);
  border-radius: 14px;
}
.seg button {
  min-height: 42px;
  border: 0; border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip {
  display: inline-flex; align-items: center; gap: .45rem;
  min-height: 38px; padding: 0 .85rem 0 .65rem;
  border: 1.5px solid var(--line);
  border-radius: 19px;
  background: var(--surface);
  font-weight: 600; font-size: .92rem;
}
.chip i { width: .8rem; height: .8rem; border-radius: 50%; background: var(--c); }
.chip[aria-pressed="false"] { background: transparent; color: var(--muted); }
.chip[aria-pressed="false"] i { background: transparent; box-shadow: inset 0 0 0 2px var(--c); }

/* ---------- agenda ---------- */
.mhead { margin: 1.4rem 0 .2rem; font-size: 1rem; font-weight: 700; color: var(--muted); }
.mhead:first-child { margin-top: .4rem; }
.day { display: grid; grid-template-columns: 3.6rem 1fr; gap: .4rem .7rem; padding: .7rem 0; }
.dnum { display: grid; justify-items: center; align-content: start; gap: .15rem; }
.dnum .n {
  display: grid; place-items: center;
  width: 3.1rem; height: 3.1rem;
  border-radius: 50%;
  font-size: 1.85rem; font-weight: 750; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
}
.dnum .w { font-size: .85rem; font-weight: 600; color: var(--muted); }
.is-today .n { background: var(--ink); color: var(--bg); }
.is-today .w { color: var(--ink); }
.evs { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; align-content: start; }
.none { color: var(--muted); padding: .85rem 0; }

.ev {
  display: grid; grid-template-columns: 4.2rem 1fr auto;
  gap: .6rem; align-items: center;
  width: 100%; min-height: 58px;
  padding: .75rem .9rem;
  text-align: left;
  background: var(--surface);
  border: 0; border-left: 6px solid var(--c);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.ev:active { transform: scale(.99); }
.ev .t { font-size: .85rem; line-height: 1.2; color: var(--muted); font-variant-numeric: tabular-nums; }
.ev .ti { font-weight: 650; font-size: 1.05rem; overflow-wrap: anywhere; }
.ev .who { font-size: .8rem; color: var(--muted); text-align: right; }
.ev .rep { margin-right: .3rem; font-weight: 700; }

.empty { margin: 2.5rem 0; color: var(--muted); text-align: center; }
.more {
  display: block; width: 100%; margin: .8rem 0;
  min-height: 48px; border: 1.5px dashed var(--line); border-radius: 14px;
  background: transparent; color: var(--muted); font-weight: 650;
}

/* ---------- mese ---------- */
.mgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.wd { text-align: center; font-size: .8rem; font-weight: 600; color: var(--muted); padding: .2rem 0 .3rem; }
.cell {
  display: grid; justify-items: center; align-content: start; gap: .25rem;
  min-height: 56px; padding: .4rem 0 .3rem;
  border: 2px solid transparent; border-radius: 12px;
  background: var(--surface);
}
.cell .num { font-weight: 650; font-variant-numeric: tabular-nums; }
.cell.out { background: transparent; color: var(--muted); opacity: .6; }
.cell.today .num { background: var(--ink); color: var(--bg); border-radius: 50%; width: 1.8rem; height: 1.8rem; display: grid; place-items: center; margin: -.2rem 0; }
.cell.sel { border-color: var(--accent); }
.dots { display: flex; gap: 3px; align-items: center; height: .55rem; }
.dots i { width: .5rem; height: .5rem; border-radius: 50%; background: var(--c); }
.dots b { font-size: .7rem; line-height: 1; color: var(--muted); }
.sel-day { margin-top: 1.1rem; }
.sel-day h2 { margin: 0 0 .6rem; font-size: 1.15rem; }

/* ---------- pulsante + ---------- */
.fab {
  position: fixed; z-index: 6;
  right: max(1.2rem, env(safe-area-inset-right));
  bottom: calc(1.2rem + env(safe-area-inset-bottom));
  width: 62px; height: 62px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 6px 18px rgba(20, 33, 61, .28);
}
.fab svg { width: 1.9rem; height: 1.9rem; stroke-width: 2.6; }
.fab:active { transform: scale(.95); }

/* ---------- finestre (scheda dal basso) ---------- */
dialog {
  width: 100%; max-width: 520px;
  margin: auto auto 0; padding: 0;
  border: 0; border-radius: 24px 24px 0 0;
  background: var(--surface); color: var(--ink);
  max-height: 92dvh;
}
dialog::backdrop { background: rgba(10, 16, 32, .5); }
@media (min-width: 600px) { dialog { margin: auto; border-radius: 24px; } }
@media (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: rise .18s ease-out; }
  @keyframes rise { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}
.sheet-in { display: grid; gap: .9rem; padding: 1.3rem 1.2rem calc(1.2rem + env(safe-area-inset-bottom)); }
.sheet-in h2 { margin: 0; font-size: 1.35rem; }
.fld { display: grid; gap: .3rem; }
.fld > span { font-size: .9rem; font-weight: 650; color: var(--muted); }
input[type="text"], input[type="password"], input[type="date"], input[type="time"], select {
  width: 100%; min-height: 50px; padding: 0 .85rem;
  background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 12px;
  font-size: 1rem;
}
input:focus-visible, select:focus-visible { outline-offset: 0; border-color: var(--accent); }
.check { display: flex; align-items: center; gap: .7rem; min-height: 44px; font-weight: 600; }
.check input { width: 1.4rem; height: 1.4rem; accent-color: var(--accent); }
.who-line, .hint { margin: 0; color: var(--muted); font-size: .92rem; }
.who-line:empty { display: none; }
.err { margin: 0; padding: .7rem .85rem; border-radius: 12px; color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); font-weight: 600; }
.actions { display: grid; gap: .6rem; margin-top: .3rem; }
.primary, .secondary, .danger {
  min-height: 52px; border-radius: 14px; font-weight: 700; border: 1.5px solid transparent;
}
.primary { background: var(--accent); color: var(--on-accent); }
.primary:disabled { opacity: .6; }
.secondary { background: transparent; border-color: var(--line); }
.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.danger.armed { background: var(--danger); color: var(--bg); }

/* ---------- avviso ---------- */
#toast {
  position: fixed; z-index: 20; left: 50%;
  bottom: calc(6.2rem + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  max-width: min(92vw, 420px);
  padding: .75rem 1.1rem; border-radius: 14px;
  background: var(--ink); color: var(--bg);
  font-weight: 650; text-align: center;
  opacity: 0; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: no-preference) { #toast { transition: opacity .2s, transform .2s; } }

/* ---------- login ---------- */
.login-page { min-height: 100dvh; display: grid; align-items: center; }
.login {
  width: 100%; max-width: 400px; margin: 0 auto;
  padding: 2rem 1.4rem calc(2rem + env(safe-area-inset-bottom));
  display: grid; gap: .9rem;
}
.login-icon { border-radius: 18px; }
.login h1 { font-size: 1.9rem; }
.login-form { display: grid; gap: .9rem; margin-top: .4rem; }
