/* AI Trainer: stile unico. Mobile-first, una mano in palestra, tema chiaro e scuro. */
:root {
  --bg: #f3f4f5; --surface: #ffffff; --surface-2: #e9ebed; --ink: #121416; --muted: #5f656c; --line: #dadde1;
  --accent: #d9480f; --accent-ink: #ffffff; --accent-soft: #fce4d9; --accent-text: #c2410c;
  --danger: #b4123a; --danger-soft: #f9e1e6; --warn: #6b6400; --warn-soft: #f0eed0;
  --radius: 14px; --radius-s: 10px; --tap: 48px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --shadow: 0 1px 2px rgba(20, 22, 26, .06), 0 8px 24px rgba(20, 22, 26, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0d0f; --surface: #16181b; --surface-2: #1f2226; --ink: #f1f2f3; --muted: #999fa6; --line: #2a2d32;
    --accent: #ff7a33; --accent-ink: #170a02; --accent-soft: #36200f; --accent-text: #ff8d4f;
    --danger: #ff7a95; --danger-soft: #3b1720; --warn: #d9d066; --warn-soft: #2f2c12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c0d0f; --surface: #16181b; --surface-2: #1f2226; --ink: #f1f2f3; --muted: #999fa6; --line: #2a2d32;
  --accent: #ff7a33; --accent-ink: #170a02; --accent-soft: #36200f; --accent-text: #ff8d4f;
  --danger: #ff7a95; --danger-soft: #3b1720; --warn: #d9d066; --warn-soft: #2f2c12;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.6rem; line-height: 1.15; letter-spacing: -.02em; font-weight: 750; }
h2 { font-size: 1.05rem; letter-spacing: -.01em; font-weight: 700; }
h3 { font-size: .95rem; font-weight: 650; }
a { color: var(--accent-text); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; opacity: 0; }
.num, .tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 12px; }
.stack-s { display: grid; gap: 6px; }
.right { margin-left: auto; }
.center { text-align: center; }

/* ---------- Guscio ---------- */
#app { min-height: 100dvh; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.top h1 { font-size: 1.25rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 6px 16px calc(96px + env(safe-area-inset-bottom)); display: grid; gap: 22px; align-content: start; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.tab {
  display: grid; justify-items: center; gap: 2px; padding: 6px 2px; min-height: var(--tap); border: 0; background: none;
  color: var(--muted); font-size: .7rem; font-weight: 600; text-decoration: none; border-radius: 10px;
}
.tab[aria-current="page"] { color: var(--ink); }
.tab[aria-current="page"] svg { color: var(--accent); }
.side-brand { display: none; }
/* PC: barra laterale larga con le scritte (icona e scritta affiancate, voci una sotto l'altra) e colonna centrale. */
@media (min-width: 900px) {
  .tabbar { top: 0; bottom: 0; right: auto; width: 220px; grid-template-columns: 1fr; align-content: start; gap: 4px; border-top: 0; border-right: 1px solid var(--line); padding: 22px 12px; }
  .side-brand { display: block; padding: 4px 14px 20px; font-size: 1.25rem; font-weight: 750; letter-spacing: -.02em; }
  .tab { grid-auto-flow: column; justify-content: start; align-items: center; gap: 12px; padding: 8px 14px; font-size: .95rem; }
  #app.has-tabs { padding-left: 220px; }
  .top { width: 100%; max-width: 760px; margin: 0 auto; }
  .view { padding-bottom: 40px; }
  .timer { left: 232px; }
  #toasts { left: 232px; bottom: 24px; }
  body:has(.timer) #toasts { bottom: 96px; }
  /* Ingresso: colonna centrata di al massimo 560 px, sfondo a tutta pagina, contenuto centrato anche in verticale (soluzione provvisoria, vedi docs/decisioni.md). */
  .ingresso { align-items: center; }
  .in-blocco { flex: none; width: 100%; max-width: 560px; min-height: 0; }
  .in-allenamento { margin-top: auto; }
  .in-alimentazione { margin-top: 12px; margin-bottom: auto; border-radius: 28px; padding-bottom: 24px; }
}

/* ---------- Sezioni e righe ---------- */
.sec { display: grid; gap: 10px; }
.sec-title { font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 12px; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 10px 14px; border: 0; background: none; text-align: left;
  border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; cursor: pointer;
}
.item:last-child { border-bottom: 0; }
.item:active { background: var(--surface-2); }
div.item { cursor: default; }
.item-main { flex: 1; min-width: 0; display: grid; gap: 1px; }
.item-title { font-weight: 620; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { color: var(--muted); font-size: .85rem; }
.item-val { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chev { color: var(--muted); }
.empty { text-align: center; padding: 26px 16px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); display: grid; gap: 12px; justify-items: center; }
.hero { display: grid; gap: 4px; }
.hero .kicker { font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.big { font-size: 2.2rem; font-weight: 780; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 600px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px 12px; display: grid; gap: 2px; }
.stat b { font-size: 1.3rem; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat span { font-size: .75rem; color: var(--muted); }
.note { background: var(--accent-soft); border-radius: var(--radius-s); padding: 10px 12px; font-size: .9rem; }
.note-warn { background: var(--warn-soft); color: var(--ink); }
.note-danger { background: var(--danger-soft); }

/* ---------- Pulsanti ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 0 18px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-weight: 650; cursor: pointer; text-decoration: none; color: var(--ink);
  transition: transform .08s ease, background .15s ease; text-align: center; line-height: 1.25;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn-ghost { border-color: transparent; background: none; color: var(--accent-text); padding: 0 10px; }
.btn-block { width: 100%; }
.btn-s { min-height: var(--tap); padding: 0 12px; font-size: .88rem; }
.btn-xl { min-height: 58px; font-size: 1.05rem; }
.icon-btn { display: inline-grid; place-items: center; width: var(--tap); height: var(--tap); border: 0; border-radius: 50%; background: none; color: var(--ink); cursor: pointer; flex: none; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn.sm { width: 36px; height: 36px; color: var(--muted); }
.icon-btn.danger { color: var(--danger); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); font-size: .75rem; font-weight: 650; white-space: nowrap; }
.chip-accent { background: var(--accent-soft); color: var(--accent-text); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; max-width: 100%; overflow-x: auto; }
.seg button { border: 0; background: none; min-height: 38px; padding: 0 14px; border-radius: 999px; font-weight: 650; font-size: .88rem; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }

/* ---------- Campi ---------- */
.field { display: grid; gap: 5px; }
.field label, .lbl { font-size: .82rem; font-weight: 650; color: var(--muted); }
.hint { font-size: .82rem; color: var(--muted); }
input[type="text"], input[type="password"], input[type="date"], input[type="number"], input[type="url"], input[type="search"], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface);
  font-size: 16px; /* evita lo zoom di iOS */
}
textarea { min-height: 96px; resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input.num { text-align: center; font-variant-numeric: tabular-nums; font-weight: 650; padding: 10px 4px; }
.check { display: flex; gap: 10px; align-items: flex-start; min-height: var(--tap); padding: 8px 0; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.err { color: var(--danger); font-size: .9rem; font-weight: 600; min-height: 1.3em; }
pre.preview { margin: 0; white-space: pre-wrap; word-break: break-word; font: .82rem/1.45 ui-monospace, Menlo, Consolas, monospace; background: var(--surface-2); border-radius: var(--radius-s); padding: 12px; max-height: 46vh; overflow: auto; }
.answer { white-space: pre-wrap; word-break: break-word; line-height: 1.5; }

/* ---------- Finestre e avvisi ---------- */
dialog.dlg {
  border: 0; border-radius: 20px 20px 0 0; background: var(--surface); color: var(--ink); padding: 0; width: 100%; max-width: 560px;
  margin: auto auto 0; max-height: 92dvh; box-shadow: var(--shadow);
}
dialog.dlg[open] { display: flex; flex-direction: column; }
dialog.dlg::backdrop { background: rgba(8, 9, 10, .55); }
@media (min-width: 620px) { dialog.dlg { margin: auto; border-radius: 20px; } dialog.dlg-wide { max-width: 720px; } }
.dlg-head { display: flex; align-items: center; gap: 8px; padding: 14px 10px 6px 18px; }
.dlg-head h2 { flex: 1; font-size: 1.15rem; }
.dlg-body { padding: 8px 18px 16px; overflow: auto; display: grid; gap: 14px; align-content: start; }
.dlg-foot { display: flex; gap: 10px; padding: 12px 18px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.dlg-foot .btn { flex: 1; }
#toasts { position: fixed; left: 12px; right: 12px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 50; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
/* Con il timer di recupero in vista, l'avviso sta sopra il timer e non lo copre. */
body:has(.timer) #toasts { bottom: calc(150px + env(safe-area-inset-bottom)); }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 999px; font-weight: 600; font-size: .9rem; box-shadow: var(--shadow); max-width: 100%; animation: rise .18s ease; }
.toast-err { background: var(--danger); color: #fff; }
.toast-action { border: 0; background: none; color: inherit; font-weight: 800; text-decoration: underline; cursor: pointer; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- Blocco ---------- */
.lock { min-height: 100dvh; display: grid; align-content: center; gap: 20px; max-width: 460px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 28px) 22px calc(env(safe-area-inset-bottom) + 28px); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.02em; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.bullets { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.bullets li { padding-left: 18px; position: relative; color: var(--muted); }
.bullets li::before { content: ""; position: absolute; left: 0; top: .6em; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.code { font: 700 1.15rem/1.6 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .06em; text-align: center; padding: 16px 10px; background: var(--surface-2); border-radius: var(--radius); word-break: break-word; user-select: all; -webkit-user-select: all; }

/* ---------- Allenamento ---------- */
.ex { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.ex-head { display: flex; align-items: center; gap: 8px; padding: 12px 8px 8px 14px; }
.ex-head h3 { flex: 1; min-width: 0; font-size: 1.02rem; }
.ex-meta { padding: 0 14px 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.ex-body { padding: 4px 10px 12px; display: grid; gap: 6px; }
.set { display: grid; grid-template-columns: 34px 1fr 1fr 58px 46px; gap: 6px; align-items: center; }
.set-ed { display: grid; grid-template-columns: 1.5fr 1fr 1fr 1fr 36px; gap: 6px; align-items: center; }
.set-head { font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); text-align: center; }
.set-n { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 750; font-size: .8rem; background: var(--surface-2); color: var(--muted); border: 0; }
.set-n[data-type="warmup"] { background: var(--warn-soft); color: var(--warn); }
.set-n[data-type="failure"], .set-n[data-type="drop"], .set-n[data-type="myo"], .set-n[data-type="partial"] { background: var(--danger-soft); color: var(--danger); }
.set.done input { background: var(--accent-soft); border-color: transparent; }
.set-done { width: 46px; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; color: var(--muted); cursor: pointer; }
.set.done .set-done { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.set-hint { grid-column: 2 / -1; font-size: .78rem; color: var(--muted); margin: -2px 0 4px; }
.timer {
  position: fixed; left: 12px; right: 12px; bottom: calc(78px + env(safe-area-inset-bottom)); z-index: 7; max-width: 520px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px; background: var(--ink); color: var(--bg); border-radius: 18px; padding: 10px 10px 10px 18px; box-shadow: var(--shadow);
}
.timer b { font-size: 1.6rem; font-variant-numeric: tabular-nums; letter-spacing: -.02em; min-width: 68px; }
.timer .btn { background: transparent; color: inherit; border-color: color-mix(in srgb, var(--bg) 35%, transparent); min-height: 40px; padding: 0 12px; }
.timer.over { background: var(--accent); color: var(--accent-ink); }
.rule { display: grid; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.rule:last-child { border-bottom: 0; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-h { font-size: .68rem; text-align: center; color: var(--muted); font-weight: 700; }
.cal-d { aspect-ratio: 1; border-radius: 9px; display: grid; place-items: center; font-size: .8rem; font-variant-numeric: tabular-nums; background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.cal-d.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 750; }
.cal-d.act { background: var(--accent-soft); border-color: transparent; color: var(--ink); font-weight: 650; }
.cal-d.out { visibility: hidden; }
.cal-d.now { outline: 2px solid var(--ink); outline-offset: 1px; }

/* ---------- Alimentazione, progressi ---------- */
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.over i { background: var(--warn); }
.macro { display: grid; gap: 4px; }
.macro .row { justify-content: space-between; font-size: .85rem; }
.chart { width: 100%; height: auto; display: block; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--accent); }
.chart-txt { font-size: 9px; fill: var(--muted); font-family: var(--font); }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo { position: relative; aspect-ratio: 3 / 4; border-radius: var(--radius-s); overflow: hidden; background: var(--surface-2); border: 0; padding: 0; cursor: pointer; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo span { position: absolute; left: 6px; bottom: 6px; background: rgba(0, 0, 0, .6); color: #fff; font-size: .68rem; font-weight: 650; padding: 2px 7px; border-radius: 99px; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.compare img { width: 100%; border-radius: var(--radius-s); display: block; }
.bubble { padding: 10px 13px; border-radius: 16px; max-width: 92%; white-space: pre-wrap; word-break: break-word; }
.bubble.me { background: var(--accent); color: var(--accent-ink); justify-self: end; border-bottom-right-radius: 5px; }
.bubble.ai { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.tbl th, table.tbl td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.tbl th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ---------- Scelte a schede, primo avvio, configurazione AI ---------- */
.choices { display: grid; gap: 8px; }
.choice {
  display: grid; gap: 2px; width: 100%; text-align: left; padding: 12px 14px; min-height: var(--tap); cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s); color: var(--ink); transition: border-color .12s ease, background .12s ease;
}
.choice-title { font-weight: 680; }
.choice-sub { font-size: .84rem; color: var(--muted); }
.choice[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.seg-fill { display: flex; width: 100%; }
.seg-fill button { flex: 1; padding: 0 8px; }
.steps-head { display: grid; gap: 8px; }
.steps-head .kicker { font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.steps-head .bar { height: 4px; }
.step-title { font-size: 1.45rem; letter-spacing: -.02em; }
.onboarding { gap: 18px; }
.item-tight { min-height: 44px; padding: 8px 14px; }
.item-sub-ink { font-size: .92rem; }
.panel-accent { background: var(--accent-soft); border-color: transparent; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.dot-on { background: var(--accent); }
a.list { display: block; text-decoration: none; color: inherit; }
.steps-list { margin: 0; padding-left: 22px; display: grid; gap: 8px; }
.steps-list li::marker { font-weight: 750; color: var(--accent-text); }
details.adv { border-top: 1px solid var(--line); padding-top: 10px; }
details.adv summary { cursor: pointer; font-weight: 650; color: var(--muted); min-height: 32px; }
details.adv[open] summary { margin-bottom: 8px; }

/* ---------- Stampa (report PDF) ---------- */
[hidden] { display: none !important; }
a.note { color: inherit; text-decoration: none; }
.btn > .grow { text-align: left; }

/* Assistente AI */
.preview { max-height: 42vh; overflow: auto; margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font: inherit; font-size: .82rem; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.msg { max-width: 92%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.msg .answer { margin: 0; }
.msg-user { align-self: flex-end; background: var(--surface-2, var(--bg)); }
.msg-ai { align-self: flex-start; }
.msg-who { display: block; margin-bottom: 2px; font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
button.item { width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left; font: inherit; color: inherit; cursor: pointer; }

/* Alimentazione */
.flip svg { transform: scaleX(-1); }
.pick { max-height: 34vh; overflow-y: auto; }
.item[aria-pressed="true"] { background: var(--accent-soft); }
.plan-meal { display: grid; gap: 4px; padding-top: 10px; border-top: 1px solid var(--line); }
ul.plain { margin: 0; padding-left: 18px; font-size: .9rem; color: var(--muted); }
.stat .bar { margin-top: 4px; height: 5px; }

/* Progressi */
.big-num { font-size: 1.9rem; font-weight: 750; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.photo-empty { cursor: default; border: 1px dashed var(--line); background: none; }
.photo-empty span { background: none; color: var(--muted); }
.photo-full img { width: 100%; max-height: 62vh; object-fit: contain; border-radius: var(--radius-s); display: block; background: var(--surface-2); }
.compare figure { margin: 0; display: grid; gap: 4px; }
.compare figcaption { font-size: .78rem; color: var(--muted); text-align: center; }
.compare img { aspect-ratio: 3 / 4; object-fit: cover; background: var(--surface-2); }
.report-title { font-size: 1.35rem; letter-spacing: -.02em; }
.report table.tbl td:not(:first-child), .report table.tbl th:not(:first-child) { text-align: right; }
.report table.tbl td:first-child { overflow-wrap: anywhere; }
@media (max-width: 380px) {
  .report table.tbl { font-size: .8rem; }
  .report table.tbl th, .report table.tbl td { padding: 6px 4px; }
  .report table.tbl th { font-size: .62rem; letter-spacing: 0; }
}

@media print {
  .report-photos { break-inside: avoid; }
  .report .compare { max-width: 120mm; }
  :root { --bg: #fff; --surface: #fff; --surface-2: #f2f2f2; --ink: #000; --muted: #444; --line: #ccc; --accent: #c2410c; --accent-ink: #fff; --accent-soft: #fbe5d8; --accent-text: #c2410c; }
  .top, .tabbar, #toasts, .no-print, .timer { display: none !important; }
  #app.has-tabs { padding-left: 0; }
  .view { max-width: none; padding: 0; }
  .panel, .list, .stat { break-inside: avoid; }
  body { font-size: 11pt; }
}

/* Elenco esercizi con ricerca (scheda su misura). */
.pick-list { max-height: 280px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overscroll-behavior: contain; }
.pick-group { position: sticky; top: 0; z-index: 1; padding: 8px 12px; background: var(--surface-2); font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.pick { display: flex; align-items: center; width: 100%; min-height: 44px; padding: 8px 12px; border: 0; border-top: 1px solid var(--line); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.pick-group + .pick { border-top: 0; }
.pick::after { content: ''; margin-left: auto; flex: none; width: 18px; height: 18px; border-radius: 6px; border: 1.5px solid var(--muted); }
.pick[aria-checked="true"] { background: var(--accent-soft); }
.pick[aria-checked="true"]::after { border-color: var(--accent); background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.5l2.5 2.5L12 5.5' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/14px no-repeat; }
.pick:hover { background: var(--surface-2); }
.pick-empty { padding: 12px; }
.chip-btn { min-height: 36px; padding: 6px 12px; border: 0; font: inherit; font-size: .8rem; font-weight: 650; cursor: pointer; }
.chip-tag { margin-left: 8px; padding: 1px 7px; font-size: .68rem; vertical-align: 1px; }
.choices-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.choices-grid .choice { min-height: 44px; padding-block: 8px; }
.tags { gap: 4px; margin-top: 4px; }
.tags .chip-tag { margin-left: 0; }

/* ---------- Ingresso: scelta tra Allenamento e Alimentazione ---------- */
.ingresso {
  --in-top: var(--surface); --in-sheet: var(--surface-2); --in-track-sheet: var(--surface); --in-cell: var(--surface);
  position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain;
  background: var(--in-top); color: var(--ink); animation: in-fade .18s ease;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ingresso { --in-top: var(--bg); --in-sheet: var(--surface); --in-track-sheet: var(--line); --in-cell: var(--surface-2); }
}
:root[data-theme="dark"] .ingresso { --in-top: var(--bg); --in-sheet: var(--surface); --in-track-sheet: var(--line); --in-cell: var(--surface-2); }
@keyframes in-fade { from { opacity: 0; } }

.in-blocco { flex: var(--peso, 1) 1 0px; min-height: min-content; display: flex; flex-direction: column; gap: 14px; padding: 0 20px 24px; }
.in-allenamento { padding-top: calc(env(safe-area-inset-top) + 12px); background: var(--in-top); }
.in-alimentazione { padding: 22px 20px calc(env(safe-area-inset-bottom) + 24px); background: var(--in-sheet); border-radius: 28px 28px 0 0; }
.in-corpo { flex: 1; display: flex; flex-direction: column; gap: 16px; }

.in-barra-alta { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
.in-barra-alta .brand-mark { width: 32px; height: 32px; border-radius: 9px; flex: none; }
.in-data { flex: 1; min-width: 0; font-size: .94rem; font-weight: 650; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.in-link { display: inline-flex; align-items: center; gap: 2px; min-height: var(--tap); padding: 0 2px; border: 0; background: none; color: var(--accent-text); font-size: .94rem; font-weight: 650; text-decoration: none; white-space: nowrap; cursor: pointer; }
.in-link-ink { color: var(--ink); }
.in-testa { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 24px; }
.in-testa .in-link { margin: -12px 0; }
.in-testa h2 { font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }

.in-riga { display: flex; align-items: center; gap: 16px; }
.in-testo { flex: 1; min-width: 0; display: grid; gap: 4px; }
.in-titolo { font-size: 2.25rem; line-height: 1.05; font-weight: 780; letter-spacing: -.03em; }
.in-titolo-m { font-size: 1.75rem; line-height: 1.12; font-weight: 780; letter-spacing: -.025em; }
.in-titolo-s { font-size: 1.25rem; line-height: 1.2; font-weight: 750; letter-spacing: -.02em; }
.in-sub { font-size: .94rem; color: var(--muted); }
.in-stato { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: .88rem; font-weight: 700; color: var(--accent-text); }
.in-stato::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }

.in-anello { position: relative; flex: none; }
.in-anello svg { display: block; transform: rotate(-90deg); }
.in-anello-txt { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; line-height: 1.1; }
.in-anello-txt b { font-variant-numeric: tabular-nums; }
.in-anello-txt span { font-size: .7rem; color: var(--muted); }

.in-settimana { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.in-giorno { height: 40px; border-radius: 9px; display: grid; place-items: center; font-size: .8rem; font-weight: 700; background: var(--surface); color: var(--muted); border: 1px solid var(--line); }
.in-giorno.fatto { background: var(--accent-text); border-color: var(--accent-text); color: var(--accent-ink); }
.in-giorno.oggi { background: var(--in-top); color: var(--ink); border: 2px solid var(--ink); }

.in-cta { margin-top: auto; font-size: 1.15rem; font-weight: 750; }
.in-cta-2 { margin-top: auto; background: var(--in-cell); }
.in-progresso { display: grid; gap: 8px; }
.in-progresso-riga { display: flex; justify-content: space-between; font-size: .88rem; color: var(--muted); }
.in-progresso-riga b { color: var(--ink); }

.in-spunta { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent-text); }

.in-kcal { display: flex; align-items: center; gap: 18px; }
.in-kcal .in-anello-txt b { font-size: 1.6rem; font-weight: 780; letter-spacing: -.02em; }
.in-macro { flex: 1; min-width: 0; display: grid; gap: 10px; }
.in-macro-riga { display: flex; align-items: center; gap: 10px; }
.in-macro-riga svg { flex: none; display: block; transform: rotate(-90deg); }
.in-macro-txt { min-width: 0; line-height: 1.25; }
.in-macro-txt small { display: block; font-size: .75rem; color: var(--muted); }
.in-macro-txt b { font-size: .94rem; font-variant-numeric: tabular-nums; }
.in-macro-txt b span { font-weight: 500; color: var(--muted); }

.in-pasti { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--in-cell); border-radius: var(--radius); overflow: hidden; }
.in-pasto { min-height: 58px; padding: 6px 2px; border: 0; border-left: 1px solid var(--in-sheet); background: var(--in-cell); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; cursor: pointer; }
.in-pasto:first-child { border-left: 0; }
.in-pasto small { font-size: .75rem; color: var(--muted); }
.in-pasto b { font-size: .94rem; font-variant-numeric: tabular-nums; }
.in-agg { display: inline-flex; align-items: center; gap: 2px; font-size: .8rem; font-weight: 700; color: var(--accent-text); }

.in-lista { display: grid; border-top: 1px solid var(--line); }
.in-lista-riga { display: flex; align-items: center; gap: 12px; min-height: var(--tap); border-bottom: 1px solid var(--line); }
.in-lista-riga span { flex: 1; font-weight: 620; }
.in-lista-riga b { font-variant-numeric: tabular-nums; }

.in-extra { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; font-size: .8rem; color: var(--muted); }
.in-extra b { color: var(--ink); font-variant-numeric: tabular-nums; }
.in-extra > span { display: inline-flex; align-items: center; gap: 6px; }
.in-seg { display: inline-flex; gap: 3px; }
.in-seg i { width: 10px; height: 4px; border-radius: 2px; background: var(--in-track-sheet); }
.in-seg i.on { background: var(--accent); }

/* Ingresso: adattamenti a schermi stretti (non sono nel riferimento).
   «Alimentazione» è più lunga di «Cibo»: sotto i 380 px si riduce solo il carattere dell'etichetta, i tab restano alti uguale.
   «+ Aggiungi» nei pasti vuoti a 320 px non deve venire tagliato. */
@media (max-width: 380px) {
  .tab { font-size: .62rem; padding-inline: 3px; }
  .in-agg { font-size: .7rem; }
  .in-agg svg { width: 12px; height: 12px; }
}

/* Aggiungere un alimento: ricerca unica a gruppi. */
.food-results { display: grid; gap: 14px; }
.food-group .lbl { margin: 0 0 6px; }
.food-group .list { max-height: none; }
.food-group .note, .food-group .small { margin: 6px 0 0; }
.pick-create { display: flex; }
.pick-head { align-items: flex-start; }
.pick-head .item-title { display: block; font-weight: 600; }
