:root {
  --bg: #f4f5f7; --card: #fff; --fg: #1d2127; --muted: #6b7280; --line: #d9dde3;
  --accent: #1f6feb; --ok: #1a7f37; --warn: #bf8700; --danger: #cf222e;
  color-scheme: light dark;
  --on-accent: #fff; /* testo sopra lo sfondo --accent */
}
@media (prefers-color-scheme: dark) {
  /* gli accenti scuri sono chiari (leggibili come testo sullo sfondo): sopra ci va testo scuro, 5,9–10:1 */
  :root { --on-accent: #0f1216; }
  :root { --bg: #0f1216; --card: #1a1f26; --fg: #e6e8eb; --muted: #9aa3ad; --line: #2e353f; --accent: #4c8dff; --ok: #3fb950; --warn: #d29922; --danger: #f85149; }
}
/* sezione integrazione: stesso tema, accento fucsia */
.theme-supp { --accent: #c026d3; }
@media (prefers-color-scheme: dark) { .theme-supp { --accent: #e060f0; } }
/* sezione corpo: accento verde acqua; colori delle origini validati con la skill dataviz (anche daltonismo) */
.theme-body { --accent: #0f766e; } /* bianco sopra: 5,5:1 */
.theme-blood { --accent: #6d28d9; } /* viola: il rosso è riservato alla fascia "fuori" */
:root { --z-green: #1a7f37; --z-yellow: #b58100; --z-red: #cf222e; }
@media (prefers-color-scheme: dark) { .theme-blood { --accent: #a78bfa; } :root { --z-green: #3fb950; --z-yellow: #d29922; --z-red: #f85149; } }
:root { --src-scale: #2a78d6; --src-tanita: #eb6834; --src-dexa: #1baf7a; }
@media (prefers-color-scheme: dark) { .theme-body { --accent: #2dd4bf; } :root { --src-scale: #3987e5; --src-tanita: #d95926; --src-dexa: #199e70; } }
[x-cloak] { display: none !important; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.4 system-ui, sans-serif; }
main { max-width: 720px; margin: 0 auto; padding: 12px 12px calc(88px + env(safe-area-inset-bottom)); } /* spazio per la barra in basso, barra dei gesti inclusa */

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 8px 10px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px;
}
textarea { resize: vertical; min-height: 44px; margin-top: 6px; }
input[type=checkbox] { width: 24px; min-height: 24px; height: 24px; accent-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select { margin-top: 2px; color: var(--fg); font-size: 16px; }
label.check { display: flex; gap: 8px; align-items: center; margin: 8px 0; font-size: 15px; color: var(--fg); }

button { min-height: 44px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.ghost { background: transparent; border-color: transparent; }
button.danger { color: var(--danger); }
button.small { min-height: 36px; padding: 4px 10px; font-size: 14px; }
button.wide { width: 100%; margin: 8px 0; }
button:disabled { opacity: .5; }

.login { max-width: 360px; padding-top: 20vh; }
.login form { display: grid; gap: 10px; }
.err { color: var(--danger); min-height: 1em; }

.bar { display: flex; align-items: center; gap: 8px; justify-content: space-between; margin-bottom: 8px; }
.bar.sticky { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 6px 0; }
.tabs { display: flex; gap: 4px; min-width: 0; }
.bar.top .tabs button { padding: 8px 10px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar-btn { flex: none; }
/* una pagina anche solo 1px più larga dello schermo fa scendere la barra in basso sotto il bordo (Chrome Android) */
html { overflow-x: clip; }
.tabs .on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.save { font-size: 14px; color: var(--muted); flex: 1; text-align: right; }
.save.saved { color: var(--ok); }
.save.error { color: #fff; background: var(--danger); padding: 4px 8px; border-radius: 6px; font-weight: 600; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; gap: 4px; margin-bottom: 6px; }
.list .row { flex: 1; display: grid; grid-template-columns: 1fr auto; text-align: left; background: var(--card); }
.list .date { font-size: 13px; color: var(--muted); }
.list .title { grid-column: 1; font-weight: 600; }
.list .badge { grid-row: 1 / 3; grid-column: 2; align-self: center; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--line); }
.badge.done { background: var(--ok); color: #fff; }
.badge.in_progress { background: var(--warn); color: #fff; }
.empty { color: var(--muted); justify-content: center; padding: 24px; text-align: center; }
.muted { color: var(--muted); font-size: 14px; }
.bar.top { max-width: 720px; margin: 0 auto; padding: 12px 12px 0; }
.bar.top + main { padding-top: 4px; }

nav.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center; gap: 4px;
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
nav.bottom button { flex: 1; max-width: 200px; display: flex; flex-direction: column; align-items: center; gap: 2px; border: 0; background: none;
  font-size: 12px; color: var(--muted); min-height: 52px; }
nav.bottom button span { font-size: 20px; filter: grayscale(1); opacity: .6; }
nav.bottom button.on { color: var(--accent); font-weight: 600; }
nav.bottom button.on span { filter: none; opacity: 1; }

.daynav { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; text-align: center; }
.daynav strong { display: block; }
.daynav strong::first-letter { text-transform: uppercase; }
.daynav button { font-size: 24px; }
.moment h3 { margin: 0 0 4px; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); }
label.intake { display: grid; grid-template-columns: 32px 1fr auto; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line);
  font-size: 16px; color: var(--fg); cursor: pointer; }
label.intake input { width: 28px; height: 28px; }
label.intake small { display: block; }
label.intake.taken > span { opacity: .6; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
label.chip { display: inline-flex; align-items: center; padding: 6px 12px; border: 1px solid var(--line); border-radius: 99px; font-size: 14px; color: var(--fg); cursor: pointer; }
label.chip input { display: none; }
label.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
h4.group { margin: 16px 4px 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.period { border-left: 4px solid var(--accent); }
.period.future { border-left-style: dashed; }
.period.ended { border-left-color: var(--line); opacity: .75; }
.period-head { display: flex; align-items: center; gap: 6px; }
.grid2 > .full { grid-column: span 2; }
button.link.danger { color: var(--danger); }
.card h3 { margin: 0; font-size: 16px; }
.hint { text-align: center; }

.blood-filter input[type=search] { margin-bottom: 4px; }
.markers .row { grid-template-columns: 1fr auto; }
.markers .title { grid-column: 1; font-weight: 600; }
.markers .val { grid-row: 1 / 3; grid-column: 2; align-self: center; text-align: right; font-variant-numeric: tabular-nums; }
.markers .date { grid-column: 1; }
.zchip { display: inline-block; width: 1.2em; text-align: center; font-size: 13px; }
.zchip.z-green, .zchip.z-normal { color: var(--z-green); } .zchip.z-yellow { color: var(--z-yellow); }
.zchip.z-red, .zchip.z-abnormal { color: var(--z-red); } .zchip.z-none { color: var(--muted); }
svg.chart .zone { stroke: none; }
svg.chart .zone.z-green, svg.chart .zone.z-normal { fill: color-mix(in srgb, var(--z-green) 16%, transparent); }
svg.chart .zone.z-yellow { fill: color-mix(in srgb, var(--z-yellow) 18%, transparent); }
svg.chart .zone.z-red, svg.chart .zone.z-abnormal { fill: color-mix(in srgb, var(--z-red) 13%, transparent); }
svg.chart g.z-green, svg.chart g.z-normal { fill: var(--z-green); } svg.chart g.z-yellow { fill: var(--z-yellow); }
svg.chart g.z-red, svg.chart g.z-abnormal { fill: var(--z-red); } svg.chart g.z-none { fill: var(--muted); }
svg.chart g[class^="z-"] > * { stroke: var(--card); stroke-width: 2; }
.zones-legend i { width: 14px; height: 10px; display: inline-block; }
.zones-legend i.z-green, .zones-legend i.z-normal { background: color-mix(in srgb, var(--z-green) 25%, transparent); }
.zones-legend i.z-yellow { background: color-mix(in srgb, var(--z-yellow) 28%, transparent); }
.zones-legend i.z-red, .zones-legend i.z-abnormal { background: color-mix(in srgb, var(--z-red) 22%, transparent); }
dl.ranges { margin: 8px 0 0; font-size: 14px; display: grid; gap: 2px; }
dl.ranges div { display: grid; grid-template-columns: 90px 1fr; }
dl.ranges dt { color: var(--muted); } dl.ranges dd { margin: 0; font-variant-numeric: tabular-nums; }
table.bhist { width: 100%; border-collapse: collapse; font-size: 14px; }
table.bhist tbody { border-top: 1px solid var(--line); }
table.bhist td { padding: 4px; } table.bhist td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.bhist tr.note td { font-size: 12px; color: var(--muted); padding-top: 0; }
p.desc { font-size: 14px; white-space: pre-wrap; margin: 0; }
.tvals { display: grid; gap: 2px; }
.tval { display: grid; grid-template-columns: 1fr 90px 22px; gap: 6px; align-items: center; border-top: 1px solid var(--line); padding: 2px 0; font-size: 14px; }
.tval input { min-height: 34px; padding: 4px 6px; text-align: right; }
.tval.filled .tname > span:first-child { font-weight: 600; }
code { font-size: 13px; }
svg.chart .line.cmp { stroke-dasharray: 4 3; stroke-width: 1.5; }
svg.chart circle.cmp { fill: var(--card); stroke: var(--muted); stroke-width: 2; }
.legend svg { width: 22px; }
.legend .lg-main { stroke: var(--muted); stroke-width: 2; }
.legend .lg-cmp { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 4 3; }
.legend .lg-cmp-dot { fill: var(--card); stroke: var(--muted); stroke-width: 1.5; }
small.calc { font-size: 11px; font-weight: normal; color: var(--accent); border: 1px solid var(--accent); border-radius: 99px; padding: 0 5px; }
.calc-val { text-align: right; padding-right: 6px; color: var(--muted); font-variant-numeric: tabular-nums; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; margin: 0; text-align: left; }
.tile.on { border-color: var(--accent); }
.tile strong { font-size: 22px; }
.tile small { font-size: 12px; }
.chart-card .chips { margin-bottom: 6px; }
.chips.small .chip { padding: 2px 10px; font-size: 13px; }
button.chip { min-height: 32px; padding: 4px 12px; border-radius: 99px; font-size: 14px; }
button.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
svg.chart { width: 100%; height: auto; aspect-ratio: 340 / 190; display: block; touch-action: manipulation; } /* = viewBox di chartGeom, scritto fisso in index.html: :viewBox di Alpine diventa "viewbox" e l'SVG lo ignora */
svg.chart .band { fill: color-mix(in srgb, var(--ok) 12%, transparent); }
svg.chart .grid { stroke: var(--line); stroke-width: 1; }
svg.chart .axis { fill: var(--muted); font-size: 10px; }
svg.chart .line { fill: none; stroke: var(--muted); stroke-width: 2; stroke-linejoin: round; }
svg.chart .cross { stroke: var(--fg); stroke-width: 1; stroke-dasharray: 3 3; }
svg.chart g circle, svg.chart g rect { stroke: var(--card); stroke-width: 2; }
svg.chart g.sel circle, svg.chart g.sel rect { stroke: var(--fg); }
.src-scale { fill: var(--src-scale); } .src-tanita { fill: var(--src-tanita); } .src-dexa { fill: var(--src-dexa); }
.sel-info { margin: 4px 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); }
.legend > span { display: inline-flex; align-items: center; gap: 4px; }
.legend svg { width: 12px; height: 12px; }
.legend .band-key i { width: 14px; height: 10px; background: color-mix(in srgb, var(--ok) 20%, transparent); display: inline-block; }
.src-tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 0 6px; border-radius: 99px; color: #fff; }
.src-tag.src-scale { background: var(--src-scale); } .src-tag.src-tanita { background: var(--src-tanita); } .src-tag.src-dexa { background: var(--src-dexa); }
.measures .row { grid-template-columns: 1fr; }
details.segs summary { cursor: pointer; font-size: 14px; color: var(--muted); padding: 6px 0; }
.seg-row { display: grid; grid-template-columns: 1fr 80px 80px; gap: 4px; align-items: center; font-size: 14px; margin-top: 4px; }

.top-title { margin: 0; font-size: 20px; flex: 1; }
.avatar-btn { width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 50%; overflow: hidden; display: grid; place-items: center;
  background: var(--line); font-size: 14px; font-weight: 700; margin-left: auto; }
.avatar-btn.on { outline: 2px solid var(--accent); outline-offset: 2px; }
.avatar-btn img, .avatar-big img { width: 100%; height: 100%; object-fit: cover; }
.profile-head { display: flex; gap: 14px; align-items: center; }
.avatar-big { position: relative; width: 84px; height: 84px; flex: none; border-radius: 50%; overflow: hidden; display: grid; place-items: center;
  background: var(--line); font-size: 28px; font-weight: 700; color: var(--fg); cursor: pointer; }
.avatar-big input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.zones { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.zones div { display: flex; flex-direction: column; align-items: center; padding: 6px 2px; border-radius: 8px; font-size: 13px; color: #fff; }
.zones .z1 { background: #6b7280; } .zones .z2 { background: #2563eb; } .zones .z3 { background: #16a34a; }
.zones .z4 { background: #d97706; } .zones .z5 { background: #dc2626; }
.adh { margin-top: 6px; font-size: 14px; }
.adh .bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-bottom: 2px; }
.adh .bar span { display: block; height: 100%; background: var(--ok); }
.adh.low .bar span { background: var(--warn); }
.adh small { display: block; }

.max .row { width: 100%; display: grid; grid-template-columns: 1fr auto; text-align: left; border: 0; padding: 4px 0; background: none; }
.max .title { font-weight: 600; }
.max .kg { grid-row: 1 / 3; grid-column: 2; align-self: center; font-size: 20px; font-weight: 700; }
.max .date { font-size: 13px; color: var(--muted); }
.pcts { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 4px; margin: 8px 0; }
.pcts div { display: flex; flex-direction: column; align-items: center; padding: 4px; border-radius: 8px; background: var(--bg); font-size: 13px; color: var(--muted); }
.pcts strong { font-size: 16px; color: var(--fg); }
.history { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.history th { font-size: 12px; font-weight: normal; color: var(--muted); text-align: right; padding: 4px; }
.history th:first-child, .history td:first-child { text-align: left; }
.history tbody { border-top: 1px solid var(--line); }
.history td { padding: 2px 4px; text-align: right; }
.history td:first-child { color: var(--muted); white-space: nowrap; }
.history button.cell { min-height: 32px; padding: 0 4px; border: 0; background: none; font-variant-numeric: tabular-nums; }
.history button.cell.best { color: var(--on-accent); background: var(--accent); border-radius: 6px; }
.history tr.note td { font-size: 12px; color: var(--muted); text-align: left; padding: 0 4px 4px; }
.small-note { font-size: 12px; margin: 6px 0 0; }

button.link.th { padding: 0; min-height: 0; font-size: 12px; color: var(--accent); }
dialog.picker { width: min(92vw, 420px); border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--fg); padding: 14px; }
dialog.picker::backdrop { background: rgb(0 0 0 / .5); }
dialog.picker h3 { margin: 0; }
.tabs.mode { margin-top: 10px; }
.tabs.mode button { flex: 1; }
dialog.picker label { margin-top: 8px; }
.preview { list-style: none; padding: 0; margin: 10px 0; }
.preview li { display: flex; justify-content: space-between; padding: 4px 0; border-top: 1px solid var(--line); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
.card > * + * { margin-top: 6px; }
.big { font-size: 20px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.block { border-left: 4px solid var(--accent); }
.block.done { border-left-color: var(--ok); background: color-mix(in srgb, var(--ok) 6%, var(--card)); }
.block.skipped { border-left-color: var(--danger); background: color-mix(in srgb, var(--danger) 6%, var(--card)); }
button.state { width: 28px; min-height: 28px; height: 28px; padding: 0; border: 2px solid var(--line); background: var(--bg); font-weight: 700; color: #fff; }
.done button.state { background: var(--ok); border-color: var(--ok); }
.skipped button.state { background: var(--danger); border-color: var(--danger); }
.block-head { display: grid; grid-template-columns: 28px 1fr 32px 32px 32px 32px; gap: 4px; align-items: center; }
button.icon { padding: 0; min-height: 36px; }
label.check.small { font-size: 14px; margin: 4px 0; }
.block.chained { margin-top: -10px; border-top: 2px dashed var(--accent); border-radius: 0 0 12px 12px; }
.params { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; align-items: end; }
.params .total { font-size: 14px; color: var(--muted); padding-bottom: 12px; }

.item { border-top: 1px dashed var(--line); padding-top: 6px; margin-top: 6px; }
.item > * + * { margin-top: 4px; }
.item-head { display: flex; gap: 4px; }
.item-head input { font-weight: 600; min-width: 0; }
.item-head .scheme { flex: 0 0 96px; font-weight: normal; font-size: 14px; }

.sets-wrap { overflow-x: auto; } /* complessi lunghi: la tabella scorre, non la pagina */
.sets { width: 100%; border-collapse: collapse; }
.sets th { font-size: 12px; color: var(--muted); font-weight: normal; text-align: left; }
.sets td { padding: 2px; }
.sets td:first-child { width: 24px; color: var(--muted); text-align: center; }
.sets td.unit { width: 44px; }
.sets td.chk { width: 30px; text-align: center; }
.sets input { min-height: 36px; padding: 4px 2px; min-width: 28px; text-align: center; }
.sets input[list]::-webkit-calendar-picker-indicator { display: none !important; } /* la freccia dei suggerimenti copriva "kg" */
.sets th { text-align: center; }
.sets tr.done input:not([type=checkbox]) { background: color-mix(in srgb, var(--ok) 15%, var(--bg)); }
.sets button { min-height: 36px; padding: 0 4px; }

.quick { display: grid; grid-template-columns: 1fr auto; gap: 4px; }
.quick input { min-height: 36px; font-size: 14px; }
.seg { border-top: 1px solid var(--line); padding: 4px 0; }
.seg.done { background: color-mix(in srgb, var(--ok) 8%, transparent); }
.seg-head { display: grid; grid-template-columns: 20px 1fr 30px 32px; gap: 4px; align-items: center; }
button.seg-sum { text-align: left; font-size: 15px; color: var(--fg); }
.seg-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 2px; }
.seg-grid label { font-size: 11px; }
.seg-grid input { min-height: 34px; padding: 4px 6px; margin-top: 0; font-size: 15px; }
.seg-grid .span2 { grid-column: span 2; }
.seg-cap { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-top: 4px; }
.seg-grid.act input { background: color-mix(in srgb, var(--accent) 8%, var(--bg)); }
.mod { display: grid; grid-template-columns: 1fr 1fr 36px; gap: 4px; }
.mod input { min-height: 32px; padding: 4px 8px; font-size: 14px; }
.mod button { padding: 0; min-height: 32px; }
.links { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
button.link { background: none; border: 0; padding: 4px 0; min-height: 32px; font-size: 13px; color: var(--muted); }
button.link.strong { font-size: 15px; color: var(--accent); }
textarea.minor { min-height: 32px; padding: 4px 8px; font-size: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.result { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 6px; }
.result > * + * { margin-top: 6px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
pre { white-space: pre-wrap; font-size: 14px; }
