/* Stile dell'app per telefono, ispirato alle linee guida Apple: font di sistema, superfici traslucide («vetro»),
   angoli morbidi, ombre leggere e animazioni brevi. Tutti i colori sono variabili: chiaro e scuro. */
:root {
  color-scheme: light;
  --bg: #f2f2f7;
  --surface: #ffffff;                       /* superficie piena (campi in primo piano, contorno dei numeri nei grafici) */
  --card: rgba(255, 255, 255, .78);         /* riquadri */
  --glass: rgba(250, 250, 252, .72);        /* vetro: testata, menu, finestre */
  --glass-line: rgba(0, 0, 0, .08);
  --fill: rgba(120, 120, 128, .12);         /* fondo di pulsanti e campi */
  --fill-2: rgba(120, 120, 128, .2);
  --ink: #1d1d1f;
  --ink-2: #424245;
  --muted: #6e6e73;
  --line: rgba(60, 60, 67, .13);
  --axis: rgba(60, 60, 67, .3);
  --accent: #0071e3;
  --accent-ink: #0066cc;
  --accent-soft: rgba(0, 113, 227, .12);
  --accent-glow: rgba(0, 113, 227, .3);
  --brand: var(--accent-ink);
  --s1: #2a78d6;
  --s1-soft: #9ec5f4;
  --s2: #eb6834;
  --good: #2fb350;
  --good-soft: rgba(52, 199, 89, .16);
  --good-ink: #1b7334;
  --warn-bg: rgba(255, 204, 0, .2);
  --warn-ink: #6b4a00;
  --bad: #e0352b;
  --bad-soft: rgba(255, 59, 48, .12);
  --bad-ink: #b3261e;
  --shadow: 0 1px .125rem rgba(0, 0, 0, .04), 0 .5rem 1.5rem rgba(0, 0, 0, .05);
  --shadow-lift: 0 .125rem .25rem rgba(0, 0, 0, .05), 0 .875rem 2.125rem rgba(0, 0, 0, .09);
  --shadow-float: 0 1.5rem 4.375rem rgba(0, 0, 0, .22);
  --blur: saturate(180%) blur(1.25rem);
  --ease: cubic-bezier(.25, 1, .5, 1);
  --spring: cubic-bezier(.34, 1.4, .64, 1);
  --r-card: 1.25rem;
  --r-ctl: .6875rem;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #000000;
    --surface: #1c1c1e;
    --card: rgba(28, 28, 30, .78);
    --glass: rgba(30, 30, 32, .7);
    --glass-line: rgba(255, 255, 255, .1);
    --fill: rgba(120, 120, 128, .24);
    --fill-2: rgba(120, 120, 128, .36);
    --ink: #f5f5f7;
    --ink-2: #c7c7cc;
    --muted: #98989d;
    --line: rgba(255, 255, 255, .1);
    --axis: rgba(255, 255, 255, .24);
    --accent: #0a78ec;
    --accent-ink: #4aa3ff;
    --accent-soft: rgba(10, 132, 255, .22);
    --accent-glow: rgba(10, 132, 255, .4);
    --brand: var(--accent-ink);
    --s1: #3987e5;
    --s1-soft: #184f95;
    --s2: #d95926;
    --good: #30d158;
    --good-soft: rgba(48, 209, 88, .18);
    --good-ink: #5fe07f;
    --warn-bg: rgba(255, 214, 10, .16);
    --warn-ink: #f3d27a;
    --bad: #ff453a;
    --bad-soft: rgba(255, 69, 58, .18);
    --bad-ink: #ff8a80;
    --shadow: 0 0 0 .5px rgba(255, 255, 255, .04);
    --shadow-lift: 0 .875rem 2.125rem rgba(0, 0, 0, .5);
    --shadow-float: 0 1.5rem 4.375rem rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: .875rem/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
/* Sfondo: due aloni di colore appena visibili, che danno profondità alle superfici di vetro. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(56.25rem 32.5rem at 88% -8%, rgba(0, 113, 227, .13), transparent 62%),
    radial-gradient(47.5rem 35rem at -8% 34%, rgba(175, 82, 222, .09), transparent 62%),
    radial-gradient(43.75rem 31.25rem at 70% 108%, rgba(48, 176, 199, .08), transparent 62%);
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: .125rem solid var(--accent-ink); outline-offset: .125rem; }
h1, h2, h3, p { margin: 0; }

/* ---------- Layout ---------- */
/* Una colonna larga quanto il telefono; su schermi più grandi resta stretta e centrata. */
.app { min-height: 100%; max-width: 30rem; margin: 0 auto; }
.main {
  min-width: 0;
  padding: calc(.5rem + env(safe-area-inset-top, 0px)) .75rem calc(6.5rem + env(safe-area-inset-bottom, 0px));
}
.wrap { max-width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: .875rem; }
.wrap .wrap { margin: 0; width: 100%; min-width: 0; }

/* Barra di navigazione: una «pillola» di vetro in basso al centro, con le voci in orizzontale */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(.75rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  gap: .25rem;
  max-width: calc(100vw - 1.5rem);
  padding: .375rem;
  border: 1px solid var(--glass-line);
  border-radius: 1.875rem;
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  box-shadow: var(--shadow-lift);
}
.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .125rem;
  min-width: 4.5rem;
  padding: .4375rem .5rem .375rem;
  border-radius: 1.5rem;
  color: var(--muted);
  font-size: .6875rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition: background .25s var(--ease), color .25s var(--ease), transform .25s var(--ease);
}
.tabbar a:active { transform: scale(.94); }
.tabbar svg { width: 1.5rem; height: 1.5rem; }
.tabbar a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); }

/* Testata: una barra di vetro che resta in alto mentre la pagina scorre */
.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .625rem;
  position: sticky;
  top: .75rem;
  z-index: 15;
  padding: .75rem .875rem .75rem 1.25rem;
  border: 1px solid var(--glass-line);
  border-radius: var(--r-card);
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.025em; line-height: 1.15; }
.topbar .sub { color: var(--muted); font-size: .8125rem; margin-top: 1px; }
.topbar .spacer { flex: 1; }
/* Pulsanti di una sola schermata: stanno nella testata come se fossero suoi figli diretti. */
.top-actions { display: contents; }

/* ---------- Pulsanti e campi ---------- */
.icon-btn, .btn-primary, .btn-danger, .btn-ghost {
  transition: background .25s var(--ease), color .25s var(--ease), transform .25s var(--ease), box-shadow .25s var(--ease), opacity .25s var(--ease);
}
.icon-btn:active, .btn-primary:active, .btn-danger:active, .btn-ghost:active, .ex-edit:active, .cal-day:active { transform: scale(.96); }
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  height: 2.25rem;
  padding: 0 .875rem;
  border: 0;
  border-radius: var(--r-ctl);
  background: var(--fill);
  font-weight: 500;
  white-space: nowrap;
}
.icon-btn:hover { background: var(--fill-2); }
.icon-btn svg { width: 1rem; height: 1rem; }
.icon-btn.square { width: 2.25rem; padding: 0; justify-content: center; }
.icon-btn:disabled { opacity: .4; cursor: default; }
.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.input, .select {
  height: 2.25rem;
  min-width: 0;
  padding: 0 .6875rem;
  border: 1px solid transparent;
  border-radius: var(--r-ctl);
  background: var(--fill);
  transition: background .25s var(--ease), border-color .25s var(--ease), box-shadow .25s var(--ease);
}
.select { max-width: 100%; }
.input:hover, .select:hover { background: var(--fill-2); }
.input:focus, .select:focus { outline: none; border-color: var(--accent-ink); background: var(--surface); box-shadow: 0 0 0 .25rem var(--accent-soft); }
.input::placeholder { color: var(--muted); }
.btn-primary {
  height: 2.25rem;
  padding: 0 1.125rem;
  border: 0;
  border-radius: var(--r-ctl);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 .25rem .875rem var(--accent-glow);
}
.btn-primary:hover { filter: brightness(1.08); box-shadow: 0 .375rem 1.25rem var(--accent-glow); }
.btn-primary.small { height: 1.875rem; padding: 0 .8125rem; border-radius: .5625rem; }
a.btn-primary { display: inline-flex; align-items: center; text-decoration: none; }
.btn-ghost {
  height: 1.875rem;
  padding: 0 .6875rem;
  border: 0;
  border-radius: .5625rem;
  background: none;
  color: var(--accent-ink);
  font-weight: 500;
  white-space: nowrap;
}
.btn-ghost:hover { background: var(--accent-soft); }
/* azioni che eliminano qualcosa */
#exDelete, .btn-ghost[data-act="remove"] { color: var(--bad-ink); }
#exDelete:hover, .btn-ghost[data-act="remove"]:hover { background: var(--bad-soft); }
.btn-ghost[data-armed] { background: var(--bad-soft); color: var(--bad-ink); font-weight: 600; }
.btn-danger {
  height: 2.25rem;
  padding: 0 1.125rem;
  border: 0;
  border-radius: var(--r-ctl);
  background: var(--bad);
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
}
.btn-danger:hover { filter: brightness(1.08); }
button:disabled, select:disabled { opacity: .5; cursor: default; }
a.icon-btn { text-decoration: none; color: inherit; }
.link { padding: 0; border: 0; background: none; color: var(--accent-ink); font-weight: 600; }
.link:hover { text-decoration: underline; }

/* ---------- Riquadri ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--glass-line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  min-width: 0;
}
.card-head { display: flex; align-items: flex-start; gap: .75rem; margin-bottom: .75rem; flex-wrap: wrap; }
.card-head h2 { font-size: 1.0625rem; font-weight: 600; letter-spacing: -.015em; }
.card-head p { font-size: .8125rem; color: var(--muted); }
.card-head .spacer { flex: 1; }

/* Le schermate compaiono con una dissolvenza breve quando si cambia voce di menu */
.view:not([hidden]) { animation: viewIn .34s var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(.625rem); } }
.state:not([hidden]) { animation: fadeIn .3s var(--ease); }
@keyframes fadeIn { from { opacity: 0; } }

/* ---------- Rank (Dashboard) ---------- */
.rank {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 10.5rem minmax(0, 1fr);
  gap: .5rem 1.75rem;
  align-items: center;
  padding: 1.625rem 1.75rem;
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}
/* alone del colore del rank dietro lo stemma */
.rank::before {
  content: "";
  position: absolute;
  left: -5.625rem;
  top: 50%;
  width: 27.5rem;
  height: 27.5rem;
  transform: translateY(-50%);
  background: radial-gradient(closest-side, var(--rank, #8e8e93), transparent);
  opacity: .24;
  pointer-events: none;
}
.rank > * { position: relative; }
.rank-crest { width: 10.5rem; height: 10.5rem; animation: crestIn .6s var(--spring); }
.rank-crest svg { display: block; width: 100%; height: 100%; filter: drop-shadow(0 .625rem 1.125rem rgba(0, 0, 0, .28)); }
.rank-crest.high svg { animation: crestFloat 5s ease-in-out infinite; }
@keyframes crestIn { from { opacity: 0; transform: scale(.7) rotate(-8deg); } }
@keyframes crestFloat { 50% { transform: translateY(-.3125rem); } }
.rank-label { font-size: .8125rem; font-weight: 600; color: var(--muted); }
.rank-name { font-size: 2.5rem; font-weight: 700; letter-spacing: -.035em; line-height: 1.1; }
.rank-points { margin-top: .125rem; font-size: .9375rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.rank-points b { font-weight: 650; color: var(--ink); }
.rank-bar { height: .5rem; margin-top: .875rem; border-radius: .25rem; background: var(--fill); overflow: hidden; }
.rank-bar i { display: block; height: 100%; border-radius: .25rem; background: var(--rank, var(--accent)); animation: grow .8s var(--ease); transform-origin: left; }
@keyframes grow { from { transform: scaleX(0); } }
.rank-next { margin-top: .4375rem; font-size: .8125rem; color: var(--ink-2); }
.rank-formula { margin-top: .25rem; font-size: .75rem; color: var(--muted); }
.rank-ladder { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .375rem; list-style: none; margin: .875rem 0 0; padding: .875rem 0 0; border-top: 1px solid var(--line); }
.rank-ladder li { display: flex; flex-direction: column; align-items: center; gap: .125rem; padding: .5rem .125rem .4375rem; border-radius: .875rem; font-size: .7188rem; color: var(--muted); text-align: center; transition: background .25s var(--ease), transform .25s var(--ease); }
.rank-ladder li:hover { transform: translateY(-.125rem); }
.rank-ladder svg { width: 2.875rem; height: 2.875rem; }
.rank-ladder b { font-size: .7813rem; font-weight: 600; color: var(--ink-2); }
.rank-ladder .locked svg { opacity: .32; filter: grayscale(.85); }
.rank-ladder .current { background: var(--fill); }
.rank-ladder .current b { color: var(--ink); }
.rank-ladder span { font-variant-numeric: tabular-nums; }

/* ---------- Calendario della scheda (settimana o mese) ---------- */
.cal { padding: 1rem; }
.cal-bar { display: flex; align-items: center; gap: .5rem; margin-bottom: .875rem; flex-wrap: wrap; }
.cal-bar h2 { font-size: 1.0625rem; font-weight: 600; letter-spacing: -.015em; margin-left: .375rem; }
.cal-bar .spacer { flex: 1; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .375rem; }
.cal-head { margin-bottom: .375rem; font-size: .7188rem; font-weight: 600; color: var(--muted); text-align: center; }
.cal-day {
  position: relative;
  min-height: 3.75rem;
  padding: .5rem .25rem .625rem;
  border: 1px solid transparent;
  border-radius: .875rem;
  background: var(--fill);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .125rem;
  overflow: hidden;
  transition: background .25s var(--ease), border-color .25s var(--ease), transform .25s var(--ease), box-shadow .25s var(--ease);
}
.cal-day:hover { background: var(--fill-2); }
.cal-num { font-size: 1rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; }
.cal-info { font-size: .7188rem; color: var(--ink-2); min-height: 1rem; white-space: nowrap; }
.cal-day:not(.has) .cal-num { color: var(--muted); font-weight: 500; }
.cal-day.out { opacity: .45; }
.cal-day.today { border-color: var(--accent-ink); }
.cal-day.today .cal-num { color: var(--accent-ink); }
.cal-day i { position: absolute; left: 0; bottom: 0; height: .1875rem; background: var(--good); }
.cal-day.sel { background: var(--accent); border-color: transparent; opacity: 1; box-shadow: 0 .375rem 1rem var(--accent-glow); }
.cal-day.sel .cal-num, .cal-day.sel .cal-info { color: #fff; }
.cal-day.sel i { background: #fff; opacity: .85; }
.cal-expand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .375rem;
  width: 100%;
  margin-top: .625rem;
  padding: .3125rem;
  border: 0;
  border-radius: .5625rem;
  background: none;
  color: var(--accent-ink);
  font-size: .8125rem;
  font-weight: 500;
  transition: background .25s var(--ease);
}
.cal-expand:hover { background: var(--accent-soft); }
.cal-expand svg { width: 1rem; height: 1rem; transition: transform .3s var(--spring); }
.cal-expand[aria-expanded="true"] svg { transform: rotate(180deg); }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.125rem; }
.kpi-label { font-size: .8125rem; font-weight: 500; color: var(--muted); }
.kpi-value { font-size: 1.875rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.2; margin-top: .25rem; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: .9375rem; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.kpi-foot { font-size: .7813rem; color: var(--ink-2); margin-top: .25rem; }
.bar { height: .375rem; border-radius: .1875rem; background: var(--fill); margin-top: .625rem; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: .1875rem; background: var(--good); animation: grow .7s var(--ease); transform-origin: left; }

/* ---------- Giorni ---------- */
.days { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.125rem; align-items: start; }
.day-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .25rem; }
.day-head h3 { font-size: 1.0625rem; font-weight: 600; letter-spacing: -.015em; }
.day-tag {
  min-width: 1.375rem;
  height: 1.375rem;
  padding: 0 .5625rem;
  border-radius: 62.4375rem;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: .75rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.day-count { margin-left: auto; font-size: .7813rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.ex-list { list-style: none; margin: 0; padding: 0; }
.ex { display: grid; grid-template-columns: 1.25rem minmax(0, 1fr) auto; gap: .6875rem; padding: .6875rem 0; border-top: 1px solid var(--line); }
.ex:first-child { border-top: 0; }
.tick {
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 1px;
  border: 1.5px solid var(--axis);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .25s var(--ease), border-color .25s var(--ease), transform .3s var(--spring);
}
.ex.done .tick { background: var(--good); border-color: var(--good); }
.tick svg { width: .75rem; height: .75rem; color: #fff; display: none; }
.ex.done .tick svg { display: block; }
.ex.done .ex-name { color: var(--ink-2); }
.ex-name { font-weight: 600; letter-spacing: -.005em; overflow-wrap: anywhere; }
.ex-meta { font-size: .7813rem; color: var(--muted); overflow-wrap: anywhere; }
.ex-note { font-size: .7813rem; color: var(--ink-2); margin-top: .25rem; overflow-wrap: anywhere; }
.ex-dose { text-align: right; max-width: 8.125rem; }
.ex-dose b { display: block; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ex-dose span { font-size: .7813rem; color: var(--ink-2); overflow-wrap: anywhere; }
.ex-dose .err { color: var(--warn-ink); background: var(--warn-bg); border-radius: .375rem; padding: 0 .375rem; white-space: nowrap; }

.notice {
  display: flex;
  gap: .625rem;
  align-items: flex-start;
  padding: .75rem 1rem;
  border-radius: .875rem;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: .8125rem;
}
.notice:not([hidden]) { animation: fadeIn .3s var(--ease); }
.notice svg { width: 1rem; height: 1rem; flex: none; margin-top: .125rem; }
.notice.info { background: var(--card); color: var(--ink-2); border: 1px solid var(--glass-line); }

/* ---------- Grafici ---------- */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.125rem; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font-size: .6875rem; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .val { font-size: .75rem; font-weight: 650; fill: var(--ink); paint-order: stroke; stroke: var(--surface); stroke-width: .25rem; stroke-linejoin: round; }
.chart .hit.click { cursor: pointer; }
.chart-empty { padding: 2.5rem .625rem; text-align: center; color: var(--ink-2); }
.legend { display: flex; gap: .875rem; font-size: .7813rem; color: var(--ink-2); margin-top: .375rem; }
.legend span { display: inline-flex; align-items: center; gap: .375rem; }
.legend i { width: .875rem; height: .1875rem; border-radius: .125rem; }
.tip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  padding: .5625rem .75rem;
  border: 1px solid var(--glass-line);
  border-radius: .75rem;
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  color: var(--ink);
  font-size: .7813rem;
  line-height: 1.4;
  box-shadow: var(--shadow-lift);
  max-width: 15rem;
}
.tip b { font-weight: 650; }
.tip .row { display: flex; align-items: center; gap: .375rem; }
.tip .row i { width: .5rem; height: .5rem; border-radius: 50%; flex: none; }
.tip .row span { margin-left: auto; padding-left: .75rem; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- Stati ---------- */
.state { text-align: center; padding: 3.75rem 1.25rem; color: var(--ink-2); }
.state h2 { font-size: 1.25rem; font-weight: 700; letter-spacing: -.02em; color: var(--ink); margin-bottom: .375rem; }
.state p { max-width: 28.75rem; margin: 0 auto 1rem; }
.state svg { width: 2.5rem; height: 2.5rem; color: var(--muted); margin-bottom: .625rem; }
[hidden] { display: none !important; }
.state-actions { display: flex; gap: .625rem; justify-content: center; flex-wrap: wrap; }

/* ---------- Scheda: modifica, finestre di dialogo ---------- */
.ex.editable { grid-template-columns: 1.25rem minmax(0, 1fr) auto 1.75rem; }
.ex-edit {
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 0;
  border-radius: .5rem;
  background: none;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .25s var(--ease), color .25s var(--ease), transform .25s var(--ease);
}
.ex-edit:hover { background: var(--fill); color: var(--ink); }
.ex-edit svg { width: .9375rem; height: .9375rem; }
.ex-edit[data-armed] { background: var(--bad-soft); color: var(--bad-ink); }
.ex-list.cols { column-width: 20rem; column-gap: 2.25rem; }
.ex-list.cols .ex { break-inside: avoid; border-top: 0; border-bottom: 1px solid var(--line); }

.dialog {
  width: min(35rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 1.5rem;
  border: 1px solid var(--glass-line);
  border-radius: 1.5rem;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(1.875rem);
  backdrop-filter: saturate(180%) blur(1.875rem);
  color: var(--ink);
  box-shadow: var(--shadow-float);
}
.dialog[open] { animation: sheetIn .34s var(--spring); }
.dialog::backdrop { background: rgba(0, 0, 0, .32); -webkit-backdrop-filter: blur(.375rem); backdrop-filter: blur(.375rem); animation: fadeIn .3s var(--ease); }
@keyframes sheetIn { from { opacity: 0; transform: translateY(1.125rem) scale(.95); } }
.dialog h2 { font-size: 1.25rem; font-weight: 700; letter-spacing: -.02em; margin-bottom: 1rem; }
.dialog p { margin-bottom: .625rem; }
.dialog-note { color: var(--ink-2); font-size: .8125rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .875rem; }
.field { display: flex; flex-direction: column; gap: .375rem; font-size: .7813rem; font-weight: 500; color: var(--ink-2); }
.field.wide { grid-column: 1 / -1; }
.field .input, .field .select { font-size: .875rem; font-weight: 400; color: var(--ink); width: 100%; height: 2.5rem; }
.dialog-msg { margin-top: .75rem; font-size: .8125rem; color: var(--ink-2); }
.dialog-msg.error { padding: .5625rem .75rem; border-radius: .625rem; background: var(--bad-soft); color: var(--bad-ink); }
.dialog-foot { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: 1.25rem; }
.dialog-foot .spacer { flex: 1; }
.dialog-foot .btn-ghost { height: 2.25rem; }

/* ---------- Allenamento ---------- */
a.day-count { text-decoration: none; transition: color .25s var(--ease); }
a.day-count:hover { color: var(--accent-ink); }
.datebar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .875rem 1rem; }
.datebar .spacer { flex: 1; }
.datebar-hint { font-size: .8125rem; color: var(--ink-2); }
.datebar label { display: flex; align-items: center; gap: .5rem; font-size: .8125rem; font-weight: 500; color: var(--ink-2); }
/* Dashboard: elenco degli allenamenti del periodo, con la durata stimata */
.sessions { max-height: 16.375rem; overflow-y: auto; padding-right: .375rem; }
.sessions .ex-name a { color: inherit; text-decoration: none; transition: color .25s var(--ease); }
.sessions .ex-name a:hover { color: var(--accent-ink); }
.save-status { font-size: .7813rem; color: var(--muted); }
.save-status.error { color: var(--bad-ink); }

.log-list { list-style: none; margin: 0; padding: 0; }
.log {
  display: grid;
  grid-template-columns: 1.75rem minmax(0, 1fr) 7.5rem 4.75rem;
  gap: .875rem;
  align-items: center;
  padding: .8125rem 0;
  border-top: 1px solid var(--line);
}
.log:first-child { border-top: 0; }
.log .tick { width: 1.75rem; height: 1.75rem; padding: 0; background: none; cursor: pointer; }
.log .tick:hover { border-color: var(--good); }
.log .tick:active { transform: scale(.85); }
.log .tick svg { width: .9375rem; height: .9375rem; }
.log.done .tick { background: var(--good); border-color: var(--good); animation: pop .36s var(--spring); }
@keyframes pop { from { transform: scale(.6); } }
.log.done .tick svg { display: block; }
.log.done .ex-name { color: var(--ink-2); }
.log .ex-meta b { color: var(--ink); font-weight: 650; }
.log .err { color: var(--warn-ink); }
.log-field { display: flex; flex-direction: column; gap: .25rem; font-size: .7188rem; font-weight: 500; color: var(--muted); }
.log-field .input { width: 100%; font-size: .875rem; font-weight: 400; color: var(--ink); }
.workout-foot { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.workout-foot a { display: inline-flex; align-items: center; text-decoration: none; height: 2.25rem; }

/* Scheda: riquadri dei giorni e tabella di modifica rapida */
.day-card { cursor: pointer; transition: transform .3s var(--ease), box-shadow .3s var(--ease), border-color .3s var(--ease); }
.day-card:hover { transform: translateY(-.125rem); box-shadow: var(--shadow-lift); }
.day-card.selected { border-color: var(--accent-ink); box-shadow: 0 0 0 .25rem var(--accent-soft), var(--shadow); }
.day-groups { font-size: .7813rem; color: var(--ink-2); margin-bottom: .125rem; }
.day-empty { color: var(--ink-2); margin: .5rem 0 .75rem; }
.day-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.day-actions a { display: inline-flex; align-items: center; height: 2.25rem; text-decoration: none; }
.check { display: inline-flex; align-items: center; gap: .4375rem; font-size: .8125rem; color: var(--ink-2); }
.check input { width: 1rem; height: 1rem; accent-color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.quick-wrap { position: relative; overflow-x: auto; margin: 0 -.25rem; padding: .25rem; }   /* relative: tiene dentro anche i testi .sr-only */
.quick { width: 100%; min-width: 58.75rem; border-collapse: collapse; }
.quick th { text-align: left; font-size: .75rem; font-weight: 600; color: var(--muted); padding: 0 .1875rem .375rem; white-space: nowrap; }
.quick td { padding: .1875rem; }
.quick tr.first td { padding-top: .75rem; border-top: 1px solid var(--line); }   /* stacco tra un giorno e il successivo */
.quick .input, .quick .select { width: 100%; height: 2.125rem; padding: 0 .5625rem; border-radius: .5625rem; }
.quick th:nth-child(1) { width: 8.75rem; }
.quick th:nth-child(2) { width: 7.75rem; }
.quick th:nth-child(3) { width: 24%; }
.quick th:nth-child(4) { width: 3.875rem; }
.quick th:nth-child(9) { width: 2.125rem; }
.quick tr.invalid [data-f="date"]:invalid, .quick tr.invalid [data-f="name"]:placeholder-shown { border-color: var(--bad-ink); }
.b-head, .b-row {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) 7.75rem 3.75rem minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.2fr) 1.75rem;
  gap: .5rem;
  align-items: center;
}
.b-head { font-size: .75rem; font-weight: 600; color: var(--muted); margin-bottom: .375rem; }
.b-row { margin-bottom: .5rem; }
.b-row .input, .b-row .select { width: 100%; }

/* ---------- Accesso ---------- */
.gate { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 1.5rem 1rem; }
.gate .card { width: min(30rem, 100%); border-radius: 1.75rem; box-shadow: var(--shadow-lift); animation: sheetIn .4s var(--spring); }
.state .gate-logo { width: 4rem; height: 4rem; margin-bottom: 1.125rem; border-radius: 1rem; box-shadow: 0 .625rem 1.5rem var(--accent-glow); }

/* ---------- Amministrazione ---------- */

.invite { display: flex; gap: .625rem; flex-wrap: wrap; }
.invite .input { flex: 1 1 15rem; }
.invite-done { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); animation: fadeIn .3s var(--ease); }
.invite-link { display: flex; gap: .625rem; flex-wrap: wrap; margin-top: .625rem; }
.invite-link .input { flex: 1 1 15rem; color: var(--ink-2); }

.users { display: flex; flex-direction: column; }
.user {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 5.75rem 10.25rem 11.875rem;
  gap: .75rem;
  align-items: center;
  padding: .8125rem 0;
  border-top: 1px solid var(--line);
}
.user:first-child { border-top: 0; }
.user-id { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.user-txt { min-width: 0; }
.avatar {
  width: 2.25rem;
  height: 2.25rem;
  flex: none;
  border-radius: 50%;
  background: linear-gradient(145deg, #5ac8fa, #0071e3);
  color: #fff;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.user-mail { font-weight: 600; overflow-wrap: anywhere; }
.you {
  margin-left: .25rem;
  padding: 1px .4375rem;
  border-radius: 62.4375rem;
  background: var(--fill);
  font-size: .6875rem;
  font-weight: 600;
  color: var(--ink-2);
}
.pill {
  justify-self: start;
  padding: .1875rem .625rem;
  border-radius: 62.4375rem;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--fill);
  color: var(--ink-2);
}
.pill-active { background: var(--good-soft); color: var(--good-ink); }
.pill-pending { background: var(--warn-bg); color: var(--warn-ink); }
.pill-blocked { background: var(--bad-soft); color: var(--bad-ink); }
.user .select { width: 100%; }
.user-actions { display: flex; gap: .375rem; justify-content: flex-end; align-items: center; }
.card > .notice { margin-bottom: .5rem; }

/* ---------- Disposizione su una colonna ---------- */
.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.days, .charts { grid-template-columns: minmax(0, 1fr); }

.wrap { gap: .875rem; }
.topbar h1 { font-size: 1.25rem; }
.topbar .sub, .topbar .icon-btn span { display: none; }
.topbar .icon-btn { width: 2.25rem; padding: 0; justify-content: center; }
.topbar .btn-primary { padding: 0 .8125rem; }
.cal { padding: .75rem; }
.cal-grid { gap: .25rem; }
.cal-day { min-height: 3.375rem; padding: .4375rem .125rem .5625rem; border-radius: .75rem; }
.cal-info { font-size: .6563rem; }
.log { grid-template-columns: 1.75rem minmax(0, 1fr) minmax(0, 1fr); }
.log-main { grid-column: 2 / -1; }
.log-field:first-of-type { grid-column: 2; }
.b-head { display: none; }
.b-row { grid-template-columns: repeat(2, minmax(0, 1fr)) 1.75rem; padding-bottom: .75rem; margin-bottom: .75rem; border-bottom: 1px solid var(--line); }
.b-row [data-f="name"] { grid-column: 1 / 3; }
.b-row [data-f="note"] { grid-column: 1 / 3; }
.b-row [data-remove] { grid-column: 3; grid-row: 1; }
.user { grid-template-columns: minmax(0, 1fr) auto; }
.user-id { grid-column: 1; grid-row: 1; }
.pill { grid-column: 2; grid-row: 1; justify-self: end; }
.user .select { grid-column: 1 / -1; }
.user-actions { grid-column: 1 / -1; justify-content: flex-start; }
.user-actions:empty { display: none; }
.rank-ladder { gap: .125rem; }
.rank-ladder svg { width: 2.125rem; height: 2.125rem; }
.rank-ladder span { display: none; }

.kpis { gap: .75rem; }
.kpi-value { font-size: 1.5rem; }
.card { padding: .9375rem; border-radius: 1.125rem; }
.form-grid { gap: .625rem; }

/* ================= Telefono ================= */
/* Tutte le misure sono in rem e 1rem segue la larghezza dello schermo (16px su un telefono largo 390px):
   icone, testi, riquadri e spazi restano in proporzione dal telefono più piccolo al più grande. */
html { font-size: clamp(13px, 4.1026vw, 20px); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overscroll-behavior-y: none; }

/* Testata: titolo a sinistra, pulsanti della schermata e profilo a destra */
.topbar { top: calc(.5rem + env(safe-area-inset-top, 0px)); flex-wrap: nowrap; gap: .375rem; padding: .5rem .5rem .5rem .875rem; border-radius: 1.375rem; }
.topbar .titles { flex: 1; min-width: 0; }
.topbar h1 { font-size: 1.375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .icon-btn, .topbar .btn-primary, .avatar-btn { flex: none; width: 2.375rem; height: 2.375rem; padding: 0; justify-content: center; border-radius: 50%; }
.topbar .icon-btn svg, .topbar .btn-primary svg { width: 1.125rem; height: 1.125rem; }
.topbar .btn-primary { display: inline-flex; align-items: center; }
.avatar-btn {
  display: inline-flex;
  align-items: center;
  border: 0;
  background: linear-gradient(145deg, #5ac8fa, #0071e3);
  color: #fff;
  font-size: .875rem;
  font-weight: 700;
  letter-spacing: .01em;
  box-shadow: 0 .25rem .75rem var(--accent-glow);
  transition: transform .25s var(--ease);
}
.avatar-btn:active { transform: scale(.92); }

/* Pulsanti e campi: abbastanza alti da toccarli con il dito */
.icon-btn, .btn-primary, .btn-danger, .input, .select { height: 2.625rem; }
.btn-primary.small, .btn-ghost { height: 2.25rem; }
.icon-btn, .btn-primary, .btn-danger, .btn-ghost { display: inline-flex; align-items: center; justify-content: center; }
.field .input, .field .select { height: 2.75rem; }
/* Su iPhone un campo con testo più piccolo di 16px fa ingrandire la pagina quando lo si tocca */
.input, .select, .field .input, .field .select, .log-field .input, .quick .input, .quick .select { font-size: max(16px, 1rem); }
input[type="date"].input { -webkit-appearance: none; appearance: none; display: inline-flex; align-items: center; text-align: left; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
.select { -webkit-appearance: none; appearance: none; padding-right: 1.875rem; text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .5rem center; background-size: 1rem; }

/* Rank: stemma grande al centro, in primo piano */
.rank { grid-template-columns: minmax(0, 1fr); justify-items: center; gap: .25rem; padding: 1.25rem 1rem 1rem; text-align: center; }
.rank::before { left: 50%; top: -3.5rem; width: 24rem; height: 24rem; transform: translateX(-50%); }
.rank-crest { width: 10.5rem; height: 10.5rem; }
.rank-text { width: 100%; }
.rank-name { font-size: 2.25rem; }
.rank-ladder { width: 100%; margin-top: .75rem; padding-top: .75rem; }
.rank-ladder li { padding: .375rem 0; border-radius: .75rem; }
.rank-ladder svg { width: 2.375rem; height: 2.375rem; }

/* Riquadri, indicatori e grafici */
.card-head { gap: .5rem .75rem; }
.card-head .select { flex: 1 1 100%; width: 100%; }
.card-head .spacer { display: none; }
.card-head > .check, .card-head > .save-status { flex: 1 1 100%; }
.kpi-label { font-size: .75rem; line-height: 1.3; }
.kpi-foot { font-size: .75rem; }
.chart { touch-action: pan-y; -webkit-user-select: none; user-select: none; }
.sessions { max-height: 19rem; -webkit-overflow-scrolling: touch; }
#next .btn-primary { flex: 1 1 100%; }
.ex-list.cols { column-width: auto; }
.state { padding: 2.5rem 1rem; }
.state-actions > * { flex: 1 1 auto; }

/* Scelta delle date */
.datebar { padding: .75rem; }
.datebar .spacer { display: none; }
.datebar > .input { flex: 1; }
.datebar label { flex: 1 1 9rem; min-width: 0; flex-direction: column; align-items: stretch; gap: .25rem; font-size: .75rem; }
.datebar label .input { width: 100%; }
.datebar #rangeAll { flex: 1 1 100%; }
.datebar-hint { flex: 1 1 100%; text-align: center; }

/* Scheda: ogni riga della modifica rapida diventa una scheda con i campi su due colonne */
.quick-wrap { overflow: visible; margin: 0; padding: 0; }
.quick, .quick tbody { display: block; min-width: 0; }
.quick thead { display: none; }
.quick tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) 2.25rem; gap: .375rem; align-items: center; padding: .75rem 0; border-top: 1px solid var(--line); }
.quick tr:first-child { border-top: 0; padding-top: 0; }
.quick td, .quick tr.first td { display: block; padding: 0; border: 0; }
.quick tr.first { border-top: .1875rem solid var(--fill-2); }
.quick td:nth-child(3), .quick td:nth-child(8) { grid-column: 1 / -1; }
.quick td:nth-child(5), .quick td:nth-child(7) { grid-column: 2 / -1; }
.quick td:nth-child(9) { grid-column: 3; grid-row: 1; }
.quick .input, .quick .select { height: 2.5rem; }
.ex-edit { width: 2.25rem; height: 2.25rem; }
.ex-edit svg { width: 1.0625rem; height: 1.0625rem; }
.ex.editable { grid-template-columns: 1.25rem minmax(0, 1fr) auto 2.25rem; }
.day-actions > *, .workout-foot > * { flex: 1 1 auto; justify-content: center; }
.cal-bar .icon-btn { height: 2.25rem; }
.cal-bar .icon-btn.square { width: 2.25rem; }

/* Allenamento */
.log .tick { width: 2rem; height: 2rem; }
.log { grid-template-columns: 2rem minmax(0, 1fr) minmax(0, 1fr); gap: .625rem .75rem; }
.b-row { grid-template-columns: repeat(2, minmax(0, 1fr)) 2.25rem; }
.b-row [data-f="group"] { grid-column: 1 / 3; }
.b-row [data-remove] { grid-row: 1 / span 5; align-self: start; }   /* tiene libera la terza colonna: lì sta solo la «x» */

/* Orari dell'allenamento */
.session { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .5rem; padding: .75rem; border-radius: 1rem; background: var(--fill); }
.session-info { flex: 1 1 8rem; min-width: 0; display: flex; flex-direction: column; }
.session-info b { font-size: 1.25rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.session-info span { font-size: .75rem; color: var(--ink-2); }
.session-info.live b { font-size: 1.75rem; color: var(--accent-ink); }
.session > button { flex: 1 1 auto; }
.session > .btn-ghost { flex: 0 0 auto; }
.session.busy { opacity: .6; pointer-events: none; }
input[type="time"].input { -webkit-appearance: none; appearance: none; display: inline-flex; align-items: center; text-align: left; }
input[type="time"]::-webkit-date-and-time-value { text-align: left; }
.time-check { margin-top: .875rem; font-size: .875rem; }
.time-check input { width: 1.25rem; height: 1.25rem; }
#timeClear { color: var(--bad-ink); }

/* Finestre: salgono dal basso come una tendina */
.dialog {
  width: 100%;
  max-width: 30rem;
  max-height: calc(100vh - 2.5rem);
  max-height: calc(100dvh - 2.5rem - env(safe-area-inset-top, 0px));
  margin: auto auto 0;
  padding: 1.75rem 1.125rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
  border-bottom: 0;
  border-radius: 1.75rem 1.75rem 0 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.dialog::before {            /* maniglia */
  content: "";
  position: absolute;
  top: .5rem;
  left: 50%;
  width: 2.25rem;
  height: .3125rem;
  margin-left: -1.125rem;
  border-radius: .1875rem;
  background: var(--fill-2);
}
.dialog[open] { animation: sheetUp .42s var(--ease); }
@keyframes sheetUp { from { transform: translateY(100%); } }
.dialog-foot .spacer { display: none; }
.dialog-foot > button { flex: 1 1 auto; height: 2.75rem; }
.dialog-foot .btn-ghost { height: 2.75rem; }

/* Profilo */
.profile-head { display: flex; align-items: center; gap: .875rem; margin-bottom: 1.125rem; }
.profile-head .avatar { width: 3.5rem; height: 3.5rem; font-size: 1.25rem; font-weight: 700; }
.profile-head h2 { margin: 0; overflow-wrap: anywhere; }
.profile-mail { font-size: .8125rem; color: var(--muted); overflow-wrap: anywhere; }
.profile-head .pill { margin-top: .25rem; display: inline-block; }
.field .unit { position: relative; display: block; }
.field .unit .input { padding-right: 2.5rem; }
.field .unit::after { content: attr(data-unit); position: absolute; right: .75rem; top: 50%; transform: translateY(-50%); font-size: .8125rem; color: var(--muted); pointer-events: none; }
.profile-logout { margin-top: .625rem; width: 100%; height: 2.75rem; color: var(--bad-ink); }
.profile-logout:hover { background: var(--bad-soft); }

/* Accesso */
#gateGoogle { display: flex; justify-content: center; min-height: 2.75rem; margin-bottom: .25rem; }
.gate { padding: calc(1.5rem + env(safe-area-inset-top, 0px)) 1rem calc(1.5rem + env(safe-area-inset-bottom, 0px)); }

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