/* Dacci Dentro! · dashboard web
   Gli stessi colori dell'app (Theme.swift): chiaro caldo di giorno, fondo scuro con dettagli accesi di notte.
   I colori dei grafici sono passati dal validatore della palette, su #FFFFFF in chiaro e #1E1A18 in scuro. */

:root {
  color-scheme: light;
  --bg: #FAF6F0;
  --card: #FFFFFF;
  --inset: #F6F0E8;
  --ink: #1F1B18;
  --ink-2: #6B625B;
  --ink-3: #8C8178;
  --hairline: #EDE6DD;
  --baseline: #DCD2C7;
  --accent: #D85A30;
  --accent-text: #B8481F;
  --accent-soft: #FAECE7;
  --button: #C2502A;
  --button-ink: #FFFFFF;
  --danger: #D92D20;
  --danger-soft: #FCE9E7;
  --ok: #1D9E75;
  --warn: #B86E00;
  --star: #F2C200;
  --shadow: 0 1px 2px rgb(31 27 24 / 0.04), 0 8px 24px rgb(31 27 24 / 0.06);
  --shadow-lift: 0 2px 6px rgb(31 27 24 / 0.06), 0 18px 48px rgb(31 27 24 / 0.14);
  --card-border: transparent;
  --scrim: rgb(31 27 24 / 0.32);

  /* Grafici */
  --c-steps: #1D9E75;
  --c-steps-soft: #72C5A3;
  --c-weight: #7F77DD;
  --c-fat: #E06A2E;
  /* Pressione (massima e minima, due passi dello stesso blu) e battito: validati su #FFFFFF. */
  --c-bp-sys: #1D50A6;
  --c-bp-dia: #3F82DD;
  --c-heart: #E24B4A;
  /* Ossigeno nel sangue e HRV: validati su #FFFFFF con gli altri colori del Corpo (nessuna coppia vicina si confonde,
     neanche per chi non distingue rosso e verde). */
  --c-oxygen: #0A8CA6;
  --c-hrv: #B8790F;
  /* Sonno: il viola dell'app (Marco, 29/10/2026) e le fasi alle opacità 1, 0,72, 0,5 e 0,3, già fuse col fondo delle
     card (vedi colors.js: un test controlla che coincidano). Il sonno senza fasi è grigio: non si sa quale fase. */
  --c-sleep: #7F77DD;
  --c-sleep-deep: #7F77DD;
  --c-sleep-light: #A39DE7;
  --c-sleep-rem: #BFBBEE;
  --c-sleep-awake: #D9D6F5;
  --c-sleep-unknown: #ADA49C;
  --heat-0: #F1EBE3;
  --heat-1: #F2A48B;
  --heat-2: #E77D5A;
  --heat-3: #CF5429;
  --heat-4: #A13A12;
  --chart-grid: #EFE8DF;
  --chart-axis: #DCD2C7;

  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  --r-card: 22px;
  --r-control: 12px;
  --gutter: 24px;
  --page-max: 1140px;
  --tabbar-h: 0px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121010;
  --card: #1E1A18;
  --inset: #2A2523;
  --ink: #F6F1EB;
  --ink-2: #B7ABA1;
  --ink-3: #998D84;
  --hairline: #332C28;
  --baseline: #463D38;
  --accent: #FF7A4A;
  --accent-text: #FF8A5E;
  --accent-soft: #3B241B;
  --button: #FF7A4A;
  --button-ink: #1A1512;
  --danger: #FF6257;
  --danger-soft: #3A1D1B;
  --ok: #35D69C;
  --warn: #FFBC4D;
  --star: #FFD83D;
  --shadow: none;
  --shadow-lift: 0 18px 48px rgb(0 0 0 / 0.5);
  --card-border: #2A2421;
  --scrim: rgb(0 0 0 / 0.55);

  --c-steps: #07AA79;
  --c-steps-soft: #2A614B;
  --c-weight: #8C82E0;
  --c-fat: #D87031;
  /* Validati su #1E1A18. La minima resta sotto 3:1 (2,8): la aiutano la legenda, il valore accanto
     all'ultimo punto, il tooltip e l'elenco delle misure. */
  --c-bp-sys: #6393E2;
  --c-bp-dia: #2F5EB5;
  --c-heart: #EC5B5A;
  --c-oxygen: #1F9DB5;
  --c-hrv: #C08420;
  --c-sleep: #A79EFF;
  --c-sleep-deep: #A79EFF;
  --c-sleep-light: #8179BE;
  --c-sleep-rem: #635C8C;
  --c-sleep-awake: #47425D;
  --c-sleep-unknown: #766D66;
  --heat-0: #2A2523;
  --heat-1: #7F422E;
  --heat-2: #AD5436;
  --heat-3: #DC6841;
  --heat-4: #FF8B63;
  --chart-grid: #2C2622;
  --chart-axis: #463D38;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121010;
    --card: #1E1A18;
    --inset: #2A2523;
    --ink: #F6F1EB;
    --ink-2: #B7ABA1;
    --ink-3: #998D84;
    --hairline: #332C28;
    --baseline: #463D38;
    --accent: #FF7A4A;
    --accent-text: #FF8A5E;
    --accent-soft: #3B241B;
    --button: #FF7A4A;
    --button-ink: #1A1512;
    --danger: #FF6257;
    --danger-soft: #3A1D1B;
    --ok: #35D69C;
    --warn: #FFBC4D;
    --star: #FFD83D;
    --shadow: none;
    --shadow-lift: 0 18px 48px rgb(0 0 0 / 0.5);
    --card-border: #2A2421;
    --scrim: rgb(0 0 0 / 0.55);

    --c-steps: #07AA79;
    --c-steps-soft: #2A614B;
    --c-weight: #8C82E0;
    --c-fat: #D87031;
    --c-bp-sys: #6393E2;
    --c-bp-dia: #2F5EB5;
    --c-heart: #EC5B5A;
    --c-oxygen: #1F9DB5;
    --c-hrv: #C08420;
    --c-sleep: #A79EFF;
    --c-sleep-deep: #A79EFF;
    --c-sleep-light: #8179BE;
    --c-sleep-rem: #635C8C;
    --c-sleep-awake: #47425D;
    --c-sleep-unknown: #766D66;
    --heat-0: #2A2523;
    --heat-1: #7F422E;
    --heat-2: #AD5436;
    --heat-3: #DC6841;
    --heat-4: #FF8B63;
    --chart-grid: #2C2622;
    --chart-axis: #463D38;
  }
}

/* MARK: Base */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3 { font-family: var(--font-round); margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; }
[hidden] { display: none !important; }

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

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* MARK: Pagine di accesso */

body.auth {
  display: grid;
  grid-template-columns: min(400px, 100%);
  place-content: center;
  padding: 48px 16px;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 70%),
    var(--bg);
}

.brand { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 24px; }
.brand h1 { font-size: 28px; font-weight: 800; }
.brand-icon { width: 64px; height: 64px; border-radius: 15px; box-shadow: var(--shadow); }

.auth-card {
  width: min(400px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
}
.auth-card h2 { font-size: 20px; }
.auth-lead { color: var(--ink-2); }
.form-error {
  padding: 10px 12px;
  border-radius: var(--r-control);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 600;
}

/* MARK: Controlli */

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-control);
  background: var(--inset);
  transition: border-color 0.15s, background-color 0.15s;
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--card);
}
.field-hint { font-size: 13px; color: var(--ink-2); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.check { display: flex; gap: 10px; align-items: center; color: var(--ink-2); }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  font-weight: 650;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.12s, background-color 0.15s, box-shadow 0.15s, opacity 0.15s;
}
.button:hover { text-decoration: none; }
.button:active { transform: scale(0.98); }
.button:disabled { opacity: 0.55; cursor: default; transform: none; }
.button svg { width: 18px; height: 18px; flex: none; }
.button.primary { background: var(--button); color: var(--button-ink); box-shadow: 0 6px 16px rgb(194 80 42 / 0.22); }
.button.primary:hover { filter: brightness(1.05); }
.button.secondary { background: var(--accent-soft); color: var(--accent-text); }
.button.ghost { background: transparent; color: var(--ink-2); }
.button.ghost:hover { background: var(--inset); color: var(--ink); }
.button.danger { background: var(--danger-soft); color: var(--danger); }
.button.small { min-height: 34px; padding: 0 12px; font-size: 13px; }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.icon-button:hover { background: var(--inset); color: var(--ink); }
.icon-button.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-button svg { width: 18px; height: 18px; }

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  flex: none;
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

.select-pill {
  min-height: 40px;
  padding: 0 34px 0 14px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%238C8178' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 14px center;
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  appearance: none;
  cursor: pointer;
}

/* MARK: Struttura della dashboard */

body.dashboard { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

.loading { padding: 80px 16px; text-align: center; color: var(--ink-2); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.6) blur(16px);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
.topbar.scrolled { border-bottom-color: var(--hairline); }
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 12px var(--gutter);
}
.topbar .home-link { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.topbar .home-link img { width: 34px; height: 34px; border-radius: 9px; }
.topbar .home-link span { font-family: var(--font-round); font-size: 19px; font-weight: 800; letter-spacing: -0.01em; white-space: nowrap; }

.tabs { display: flex; gap: 2px; margin-left: 8px; }
.tab {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--ink-2);
  font-weight: 600;
  font-size: 14.5px;
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
}
.tab:hover { color: var(--ink); background: var(--inset); text-decoration: none; }
.tab svg { width: 18px; height: 18px; flex: none; }
.tab[aria-current="page"] { color: var(--accent-text); background: var(--accent-soft); }

.sync-pill {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--hairline);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.sync-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.sync-pill.stale .dot { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 22%, transparent); }
.sync-pill.never .dot { background: var(--ink-3); box-shadow: none; }
/* Le Impostazioni, dietro l'ingranaggio in alto a destra (29/10/2026). */
.topbar .gear { flex: none; margin-left: 4px; }
.topbar .gear[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); }

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 20px var(--gutter) 56px;
  transition: opacity 0.2s;
}
.page.refreshing { opacity: 0.6; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 8px 0 20px;
}
.eyebrow { font-size: 13px; font-weight: 650; color: var(--ink-2); text-transform: none; margin-bottom: 4px; }
.page-head h1 { font-size: 34px; font-weight: 800; line-height: 1.1; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 20px; }

.stack { display: grid; gap: 20px; }
.grid-2 { display: grid; gap: 20px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: 1 / -1; }

/* MARK: Card */

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 20px 22px 22px;
  min-width: 0;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { font-size: 18px; font-weight: 750; }
.card-sub { margin-top: 3px; font-size: 13.5px; color: var(--ink-2); }
.card-tools { display: flex; gap: 4px; flex: none; }
/* La card dei dati (29/10/2026): le icone in alto a destra si vedono come comandi; quella della tabella resta accesa
   mentre si guarda la tabella, che sta nello stesso box del grafico. */
.data-card .card-tools .icon-button { border: 1px solid var(--hairline); background: var(--card); }
.data-card .card-tools .icon-button:hover { background: var(--inset); }
.data-card .card-tools .icon-button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.data-card .table-host .table-wrap { max-height: 480px; }
.data-card .table-host > div > .card-sub { margin-bottom: 4px; }
.data-card .table-host td.actions { white-space: nowrap; }

.empty {
  display: grid;
  gap: 10px;
  justify-items: start;
  padding: 28px 22px;
  background: var(--card);
  border: 1px dashed var(--baseline);
  border-radius: var(--r-card);
  color: var(--ink-2);
}
.empty h2 { color: var(--ink); font-size: 18px; }

/* MARK: Tessere dei numeri */

.tiles { display: grid; gap: 16px; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 20px; }
.tiles.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
/* La Panoramica: i passi grandi a sinistra, su due righe, e accanto sei tessere, tre per riga: settimana, peso,
   pressione, sonno, HRV e ossigeno, come l'Oggi dell'app (29/10/2026). */
.tiles.seven { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.tiles.seven .tile.hero { grid-column: span 2; grid-row: span 2; }
.tiles.seven .tile:not(.hero) .tile-value { font-size: 26px; }
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 20px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  min-width: 0;
}
.tile-label { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 650; color: var(--ink-2); }
.tile-label .key { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.tile-value { font-family: var(--font-round); font-size: 30px; font-weight: 750; line-height: 1.1; letter-spacing: -0.02em; }
.tile-value small { font-size: 0.55em; font-weight: 650; color: var(--ink-2); letter-spacing: 0; margin-left: 3px; }
.tile-foot { margin-top: auto; font-size: 13px; color: var(--ink-2); }
.tile .delta { font-weight: 650; }
.tile .star { color: var(--star); }

.tile.hero { grid-column: span 2; padding: 22px 24px; background:
  radial-gradient(420px 200px at 100% 0%, color-mix(in srgb, var(--c-steps) 13%, transparent), transparent 70%), var(--card); }
.tile.hero .tile-value { font-size: 56px; letter-spacing: -0.03em; }

.meter { position: relative; height: 8px; border-radius: 999px; background: color-mix(in srgb, var(--meter, var(--accent)) 16%, var(--card)); overflow: hidden; margin: 6px 0 2px; }
.meter > span { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 999px; background: var(--meter, var(--accent)); transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); }
.meter.steps { --meter: var(--c-steps); }
.meter.workouts { --meter: var(--accent); }

.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--inset);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}
.badge svg { width: 12px; height: 12px; }

/* MARK: Grafici */

.chart { position: relative; width: 100%; outline: none; touch-action: pan-y; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart:focus-visible { box-shadow: 0 0 0 2px var(--accent); border-radius: 10px; }
.chart .grid line { stroke: var(--chart-grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .baseline { stroke: var(--chart-axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick { fill: var(--ink-2); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .tick.y { text-anchor: end; }
.chart .tick.x { text-anchor: middle; }
.chart .ref { stroke-width: 1.5; shape-rendering: crispEdges; }
.chart .ref.star { stroke: var(--star); }
.chart .ref.goal { stroke: var(--ink-3); stroke-width: 1; }
.chart .ref-label { fill: var(--ink-2); font-size: 11px; font-weight: 650; }
/* Le etichette sopra i dati hanno un alone del colore della card: restano leggibili sopra barre e linee. */
.chart .ref-label, .chart .end-label { paint-order: stroke fill; stroke: var(--card); stroke-width: 4px; stroke-linejoin: round; }
.chart .ref-star { fill: var(--star); }
.chart .bar { transition: opacity 0.15s; }
.chart .bar.full { fill: var(--c-steps); }
.chart .bar.soft { fill: var(--c-steps-soft); }
.chart.dimmed .bar { opacity: 0.45; }
.chart.dimmed .bar.active { opacity: 1; }
.chart .series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-area { stroke: none; opacity: 0.1; }
.chart .series-band { stroke: none; opacity: 0.12; }
/* L'anello del colore della card solo sull'ultimo punto: sui punti della linea la taglierebbe a tratti. */
.chart .dot { stroke: none; }
.chart .end-dot { stroke: var(--card); stroke-width: 2; }
.chart .raw-dot { opacity: 0.32; }
.chart .series-line.trend { stroke-width: 2.25; }
.chart .weight .series-line, .chart .weight .series-area, .chart .weight .series-band, .chart .weight .dot, .chart .weight .raw-dot { --c: var(--c-weight); }
.chart .fat .series-line, .chart .fat .series-area, .chart .fat .series-band, .chart .fat .dot, .chart .fat .raw-dot { --c: var(--c-fat); }
.chart .bp-sys .series-line, .chart .bp-sys .dot { --c: var(--c-bp-sys); }
.chart .bp-dia .series-line, .chart .bp-dia .dot { --c: var(--c-bp-dia); }
.chart .heart .series-line, .chart .heart .dot { --c: var(--c-heart); }
.chart .oxygen .series-line, .chart .oxygen .dot { --c: var(--c-oxygen); }
.chart .hrv .series-line, .chart .hrv .dot { --c: var(--c-hrv); }
.chart .series-line { stroke: var(--c); }
.chart .series-area, .chart .series-band, .chart .dot, .chart .raw-dot { fill: var(--c); }
.chart .end-label { fill: var(--ink); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart .crosshair { stroke: var(--ink-3); stroke-width: 1; shape-rendering: crispEdges; pointer-events: none; }
.chart .hover-dot { stroke: var(--card); stroke-width: 2; pointer-events: none; }
.chart .hit { fill: transparent; cursor: default; }
/* Il sonno: barre a strati (le fasi), barre degli orari e le fasi di una notte. Ogni barra è un gruppo: scelta col
   dito o col mouse resta piena e le altre si attenuano. La linea della media è d'inchiostro, non del colore dei dati. */
.chart .seg.stage-d { fill: var(--c-sleep-deep); }
.chart .seg.stage-l { fill: var(--c-sleep-light); }
.chart .seg.stage-r { fill: var(--c-sleep-rem); }
.chart .seg.stage-s { fill: var(--c-sleep-unknown); }
.chart .seg.stage-w { fill: var(--c-sleep-awake); }
.chart .seg.sleep-span { fill: var(--c-sleep); }
/* Lo storico dei passi a tutto schermo: barre verdi come nella pagina dei passi. */
.chart .seg.steps-bar { fill: var(--c-steps); }
.chart .bar-group, .chart .stage-block { transition: opacity 0.15s; }
.chart.dimmed .bar-group, .chart.dimmed .stage-block { opacity: 0.45; }
.chart.dimmed .bar-group.active, .chart.dimmed .stage-block.active { opacity: 1; }
.chart .ref.mean { stroke: var(--ink-2); stroke-width: 1.5; }
.chart .lane-label { fill: var(--ink-2); font-size: 12px; font-weight: 600; text-anchor: end; }
.chart .stage-link { stroke: var(--chart-axis); stroke-width: 1; shape-rendering: crispEdges; }
.stages-chart { margin-top: 4px; }

.chart .cell { rx: 3px; ry: 3px; transition: opacity 0.15s; }
.chart .cell.l0 { fill: var(--heat-0); }
.chart .cell.l1 { fill: var(--heat-1); }
.chart .cell.l2 { fill: var(--heat-2); }
.chart .cell.l3 { fill: var(--heat-3); }
.chart .cell.l4 { fill: var(--heat-4); }
.chart .cell.future { fill: transparent; }
.chart .cell.today { stroke: var(--ink); stroke-width: 1.5; }
.chart .cell.active { stroke: var(--ink); stroke-width: 2; }
.chart .month-label { fill: var(--ink-2); font-size: 11.5px; font-weight: 600; }
.chart .weekday-label { fill: var(--ink-3); font-size: 10.5px; }

.tooltip {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  min-width: 150px;
  max-width: 260px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-lift);
  pointer-events: none;
  font-size: 13px;
  line-height: 1.35;
}
.tooltip-title { font-size: 12px; font-weight: 650; color: var(--ink-2); margin-bottom: 6px; }
.tooltip-row { display: grid; grid-template-columns: 12px auto minmax(0, 1fr); align-items: baseline; column-gap: 8px; }
.tooltip-row .tooltip-key { align-self: center; }
.tooltip-key.dot { width: 8px; height: 8px; border-radius: 50%; justify-self: center; }
.tooltip-row + .tooltip-row { margin-top: 4px; }
.tooltip-key { width: 12px; height: 3px; border-radius: 2px; flex: none; }
.tooltip-value { font-weight: 750; font-size: 15px; font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }
.tooltip-name { color: var(--ink-2); }
.tooltip-note { margin-top: 6px; color: var(--ink-2); font-size: 12px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.legend-line { width: 16px; height: 2px; border-radius: 2px; flex: none; }
.legend-scale { display: inline-flex; gap: 3px; align-items: center; }
.legend-scale span { width: 12px; height: 12px; border-radius: 3px; }
.swatch-full { background: var(--c-steps); }
.swatch-soft { background: var(--c-steps-soft); }
.swatch-star { background: var(--star); }
.swatch-goal { background: var(--ink-3); }
.swatch-weight { background: var(--c-weight); }
.swatch-fat { background: var(--c-fat); }
.swatch-bp-sys { background: var(--c-bp-sys); }
.swatch-bp-dia { background: var(--c-bp-dia); }
.swatch-heart { background: var(--c-heart); }
.swatch-oxygen { background: var(--c-oxygen); }
.swatch-hrv { background: var(--c-hrv); }
.swatch-sleep { background: var(--c-sleep); }
.swatch-stage-d { background: var(--c-sleep-deep); }
.swatch-stage-l { background: var(--c-sleep-light); }
.swatch-stage-r { background: var(--c-sleep-rem); }
.swatch-stage-s { background: var(--c-sleep-unknown); }
.swatch-stage-w { background: var(--c-sleep-awake); }
.swatch-mean { background: var(--ink-2); }
.legend-hint { color: var(--ink-3); }
.swatch-h0 { background: var(--heat-0); }
.swatch-h1 { background: var(--heat-1); }
.swatch-h2 { background: var(--heat-2); }
.swatch-h3 { background: var(--heat-3); }
.swatch-h4 { background: var(--heat-4); }

/* MARK: Tabelle */

.table-wrap { margin-top: 14px; max-height: 420px; overflow: auto; border: 1px solid var(--hairline); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--hairline); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--card); color: var(--ink-2); font-size: 12.5px; font-weight: 650; z-index: 1; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--inset); }
td .muted { color: var(--ink-2); }
td.actions { text-align: right; padding-top: 4px; padding-bottom: 4px; }
/* Righe che si aprono (le notti): tutta la riga si tocca, e il giorno è un pulsante per la tastiera. */
tr.row-open { cursor: pointer; }
.link-button { padding: 0; border: 0; background: none; color: var(--accent-text); font-weight: 650; cursor: pointer; white-space: nowrap; }
.link-button:hover { text-decoration: underline; }
.stage-key { display: inline-flex; align-items: center; gap: 7px; }
.stage-key .legend-swatch { width: 10px; height: 10px; }

/* MARK: Elenchi */

.list { list-style: none; margin: 0; padding: 0; }
.month-group + .month-group { margin-top: 24px; }
.month-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 4px 10px; }
.month-title h3 { font-size: 17px; font-weight: 750; }
.month-title p { font-size: 13px; color: var(--ink-2); }

.workout {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 16px;
  transition: background-color 0.15s;
}
.workout + .workout { border-top: 1px solid var(--hairline); }
.workout:hover { background: var(--inset); }
.disc-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--disc, var(--accent)) 16%, var(--card));
  color: var(--disc, var(--accent));
}
.disc-icon svg { width: 20px; height: 20px; }
.disc-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--disc, var(--accent)); flex: none; }
.workout-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 700; }
.workout-meta { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.workout-notes { font-size: 13.5px; color: var(--ink-2); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workout-figures { display: flex; gap: 14px; text-align: right; }
.fig { display: grid; font-variant-numeric: tabular-nums; }
.fig strong { font-family: var(--font-round); font-size: 16px; font-weight: 750; }
.fig span { font-size: 11.5px; color: var(--ink-2); }
.row-actions { display: flex; gap: 2px; opacity: 0.85; }
.feeling { display: inline-flex; gap: 2px; align-items: center; }
.feeling i { width: 6px; height: 6px; border-radius: 50%; background: var(--hairline); }
.feeling i.on { background: var(--accent); }

.more { display: flex; justify-content: center; margin-top: 14px; }

/* MARK: Impostazioni */

.settings-grid { display: grid; gap: 20px; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.device { display: flex; align-items: center; gap: 14px; padding: 12px 0; }
.device + .device { border-top: 1px solid var(--hairline); }
.device-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--inset); color: var(--ink-2); }
.device-icon svg { width: 22px; height: 22px; }
.device-main { flex: 1; min-width: 0; }
.device-name { font-weight: 700; }
.device-meta { font-size: 13px; color: var(--ink-2); }
.pair-code {
  display: flex;
  gap: 8px;
  margin: 6px 0 4px;
  font-family: var(--font-round);
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
.pair-code span { display: grid; place-items: center; width: 1.25em; height: 1.5em; border-radius: 12px; background: var(--inset); }
.steps-list { margin: 8px 0 0; padding-left: 20px; color: var(--ink-2); display: grid; gap: 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-weight: 600; text-align: right; }
.form-stack { display: grid; gap: 14px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.message { font-size: 14px; font-weight: 600; }
.message.ok { color: var(--ok); }
.message.error { color: var(--danger); }

/* MARK: Finestre */

dialog.sheet {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--card-border);
  border-radius: 26px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow-lift);
  overflow: auto;
}
dialog.sheet::backdrop { background: var(--scrim); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
dialog.sheet[open] { animation: sheet-in 0.22s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes sheet-in { from { transform: translateY(12px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 22px 0; }
.sheet-head h2 { font-size: 21px; font-weight: 800; }
.sheet-body { display: grid; gap: 14px; padding: 18px 22px 22px; }
.sheet-note { padding: 10px 12px; border-radius: var(--r-control); background: var(--inset); color: var(--ink-2); font-size: 13.5px; }
dialog.sheet.wide { width: min(780px, calc(100vw - 24px)); }
.sheet-head .card-sub { margin-top: 4px; }
.night-stages td:first-child { width: 45%; }

.feeling-picker { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.feeling-picker button {
  min-height: 40px;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--inset);
  font-size: 13px;
  font-weight: 650;
  color: var(--ink-2);
  cursor: pointer;
}
.feeling-picker button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.duration-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.input-suffix { position: relative; }
.input-suffix input { padding-right: 44px; }
.input-suffix em { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; font-size: 13px; color: var(--ink-2); pointer-events: none; }

/* MARK: Avvisi */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--tabbar-h) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  display: grid;
  gap: 8px;
  justify-items: center;
  pointer-events: none;
}
.toast {
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 650;
  font-size: 14px;
  box-shadow: var(--shadow-lift);
  animation: toast-in 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* MARK: Schermi stretti */

@media (max-width: 1020px) {
  .tiles, .tiles.seven { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tiles.seven .tile.hero { grid-column: 1 / -1; grid-row: auto; }
  .tiles.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tab span { display: none; }
  .tab { padding: 0 11px; }
}

@media (max-width: 760px) {
  :root { --gutter: 16px; --tabbar-h: 62px; }
  /* Un backdrop-filter sulla barra in alto farebbe da contenitore alla barra delle schede «fixed»,
     che finirebbe in cima invece che in fondo allo schermo: qui la barra in alto ha un fondo pieno. */
  .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); }
  .topbar-inner { padding: 10px var(--gutter); gap: 12px; }
  .topbar .gear { margin-left: 0; }
  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    margin: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    gap: 0;
    justify-content: space-around;
    background: color-mix(in srgb, var(--card) 88%, transparent);
    backdrop-filter: saturate(1.6) blur(18px);
    -webkit-backdrop-filter: saturate(1.6) blur(18px);
    border-top: 1px solid var(--hairline);
  }
  .tab { flex: 1; flex-direction: column; gap: 2px; min-height: 50px; padding: 4px 0; border-radius: 14px; font-size: 10.5px; justify-content: center; }
  .tab span { display: block; }
  .tab svg { width: 22px; height: 22px; }
  .tab[aria-current="page"] { background: transparent; }
  .page { padding-top: 12px; }
  .page-head h1 { font-size: 28px; }
  .grid-2, .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .tiles, .tiles.three, .tiles.seven { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .tile { padding: 14px 16px; }
  .tile-value, .tiles.seven .tile:not(.hero) .tile-value { font-size: 24px; }
  .tile.hero { grid-column: 1 / -1; }
  .tile.hero .tile-value { font-size: 48px; }
  .card { padding: 16px 16px 18px; }
  .workout { grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; padding: 12px 6px; }
  .workout .row-actions { grid-column: 2 / -1; justify-content: flex-end; margin-top: -6px; }
  .workout-figures { gap: 10px; }
  .field-row { grid-template-columns: minmax(0, 1fr); }
  .pair-code { font-size: 32px; }
}

@media (max-width: 420px) {
  .sync-pill .label-long { display: none; }
}

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

@media (forced-colors: active) {
  .chart .bar, .chart .cell, .chart .dot { forced-color-adjust: none; }
}

@media print {
  .topbar, .tabs, .page-actions, .filters, .row-actions, .card-tools, .toasts { display: none !important; }
  body { background: #fff; }
  .card, .tile { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
}

/* MARK: Ritocchi */

.spacer { flex: 1; }
.form-actions .spacer { min-width: 0; }
.heat-year { margin: 14px 0 6px; font-weight: 700; color: var(--ink); }
.heat-year:first-child { margin-top: 0; }
.heat-segment + .heat-year { margin-top: 18px; }

/* MARK: Grafico a tutto schermo */

dialog.zoom {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: 100vw;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--card);
  color: var(--ink);
  overflow: hidden;
}
dialog.zoom[open] { display: flex; flex-direction: column; }
dialog.zoom::backdrop { background: var(--scrim); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
@media (min-width: 761px) {
  dialog.zoom {
    width: calc(100vw - 40px);
    height: calc(100dvh - 40px);
    margin: auto;
    border: 1px solid var(--card-border);
    border-radius: 24px;
    box-shadow: var(--shadow-lift);
  }
}
.zoom-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  padding: max(16px, env(safe-area-inset-top)) 20px 8px;
}
.zoom-title h2 { font-size: 22px; font-weight: 800; }
.zoom-controls { grid-column: 1 / -1; min-width: 0; }
.zoom-body { flex: 1; min-height: 0; display: flex; padding: 6px 12px 4px 4px; }
.zoom-foot { display: grid; gap: 4px; padding: 6px 20px max(14px, env(safe-area-inset-bottom)); }
.zoom-legend { margin-top: 0; }
.zoom-hint { font-size: 12.5px; color: var(--ink-2); }

.chart.zoom-chart { display: flex; flex: 1; min-width: 0; min-height: 0; touch-action: auto; }
.chart.zoom-chart svg { width: auto; }
.zoom-axis { flex: none; display: block; }
.zoom-scroller {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  outline: none;
  touch-action: pan-x;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  border-radius: 10px;
}
.zoom-scroller:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.zoom-track { position: relative; height: 100%; }
/* Il grafico che scorre dentro una card (pressione e battito): alto quanto gli dice il codice, e il dito che
   va su e giù fa scorrere la pagina. */
.chart.zoom-chart.inline { flex: none; }
.chart.zoom-chart.inline .zoom-scroller { touch-action: pan-x pan-y; }
.section-head { margin-top: 12px; }
.section-head h2 { font-size: 21px; font-weight: 800; }
.zoom-track > svg { position: absolute; top: 0; display: block; overflow: visible; }
.chart .year-line { stroke: var(--chart-axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .year-label { fill: var(--ink); font-family: var(--font-round); font-size: 13px; font-weight: 750; }
.chart .month-mark { stroke: var(--chart-axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick.month { text-anchor: start; }
.chart .tick.unit { font-weight: 650; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.legend-dot.faint { opacity: 0.45; }
@media (max-width: 420px) {
  .zoom-controls .segmented button { padding: 0 9px; font-size: 13.5px; }
}
