/* Allenamenti: stile condiviso da accesso e app */

:root {
  color-scheme: light dark;
  --bg: #f1f2f5;
  --surface: #ffffff;
  --surface-sunk: #f6f7f9;
  --ink: #14171c;
  --ink-2: #47505d;
  --ink-3: #636c7a;
  --line: #e3e6eb;
  --line-strong: #cfd5dd;
  --accent: #1f5fd6;
  --accent-hover: #194fb5;
  --accent-ink: #ffffff;
  --accent-soft: #e7eefc;
  --reps: #d0600e;
  --reps-ink: #a84c0a;
  --up: #1d7f47;
  --up-soft: #e2f3e9;
  --stuck: #8f5200;
  --stuck-soft: #fbefd9;
  --down: #4f5866;
  --down-soft: #eceef2;
  --danger: #b8261f;
  --danger-soft: #fdeaea;
  --shadow: 0 1px 2px rgba(20, 23, 28, 0.06), 0 4px 14px rgba(20, 23, 28, 0.06);
  --shadow-pop: 0 6px 24px rgba(20, 23, 28, 0.16), 0 2px 6px rgba(20, 23, 28, 0.08);
  --radius: 14px;
  --radius-s: 10px;
  --gutter: 16px;
  --tabbar: 64px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f13;
    --surface: #171a20;
    --surface-sunk: #1d2128;
    --ink: #f2f4f7;
    --ink-2: #b9c0cb;
    --ink-3: #939cab;
    --line: #272c35;
    --line-strong: #363c47;
    --accent: #5b98ff;
    --accent-hover: #7eaeff;
    --accent-ink: #0b1220;
    --accent-soft: #1b2a45;
    --reps: #ff8a3d;
    --reps-ink: #ffa366;
    --up: #4cc98a;
    --up-soft: #15301f;
    --stuck: #f0b34a;
    --stuck-soft: #33270f;
    --down: #aab3c0;
    --down-soft: #232831;
    --danger: #ff6b63;
    --danger-soft: #3a1714;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.28);
    --shadow-pop: 0 10px 30px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  caret-color: var(--accent);
  scrollbar-color: var(--line-strong) transparent;
}
::selection { background: var(--accent-soft); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
a { color: var(--accent); text-underline-offset: 3px; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------------------------------------------------------------- pulsanti */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border-radius: 12px; border: 1px solid transparent;
  font-weight: 600; font-size: 1rem; cursor: pointer;
  transition: background-color 160ms ease-out, color 160ms ease-out, box-shadow 160ms ease-out;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn-primario { background: var(--accent); color: var(--accent-ink); }
.btn-primario:hover { background: var(--accent-hover); }
.btn-secondario { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondario:hover { background: var(--surface-sunk); }
.btn-testo { background: transparent; color: var(--accent); padding: 0 8px; min-height: 40px; }
.btn-testo:hover { background: var(--accent-soft); }
.btn:disabled, .btn[aria-busy="true"] { opacity: 0.55; cursor: default; }
.btn-largo { width: 100%; }

.icona-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: transparent; border: 0; color: var(--accent); cursor: pointer;
  transition: background-color 160ms ease-out;
}
.icona-btn:hover { background: var(--accent-soft); }
.icona-btn svg { width: 22px; height: 22px; }
.icona-btn[aria-busy="true"] svg { animation: gira 900ms linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 0.9375rem;
  display: inline-grid; place-items: center; border: 0; cursor: pointer;
}

/* ---------------------------------------------------------------- struttura app */

.app {
  max-width: 760px; margin: 0 auto;
  padding: 0 var(--gutter) calc(var(--tabbar) + 32px + env(safe-area-inset-bottom));
}

.barra {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  margin: 0 calc(-1 * var(--gutter));
  padding: calc(env(safe-area-inset-top) + 6px) var(--gutter) 6px;
  display: flex; align-items: center; gap: 8px; min-height: 52px;
  transition: box-shadow 160ms ease-out;
}
.barra.staccata { box-shadow: 0 1px 0 var(--line); }
.barra-titolo {
  flex: 1; min-width: 0; text-align: center; font-weight: 600; font-size: 1.0625rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transition: opacity 160ms ease-out;
}
.barra.staccata .barra-titolo { opacity: 1; }
.barra-sinistra, .barra-destra { display: flex; align-items: center; gap: 4px; min-width: 88px; }
.barra-destra { justify-content: flex-end; }

.indietro {
  display: inline-flex; align-items: center; gap: 2px;
  color: var(--accent); background: none; border: 0; cursor: pointer;
  font-size: 1.0625rem; min-height: 40px; padding: 0 6px 0 0; text-decoration: none;
}
.indietro svg { width: 22px; height: 22px; }

.intestazione { padding: 4px 0 14px; }
.intestazione h1 {
  margin: 0; font-size: 2rem; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em;
  text-wrap: balance;
}
.sottotitolo { margin: 6px 0 0; color: var(--ink-2); font-size: 0.9375rem; }

/* schede (tab) */
.schede {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center; gap: 0;
  background: var(--surface);
  box-shadow: 0 -1px 0 var(--line);
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
}
.scheda {
  flex: 1; max-width: 200px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; border-radius: 10px;
  color: var(--ink-3); text-decoration: none; font-size: 0.75rem; font-weight: 600;
}
.scheda svg { width: 26px; height: 26px; }
.scheda[aria-current="page"] { color: var(--accent); }

@media (min-width: 820px) {
  .app { padding-bottom: 48px; }
  .barra-sinistra { order: 0; min-width: 0; }
  /* su schermo largo le schede in alto riportano già indietro */
  .indietro { display: none; }
  .schede {
    position: static; background: transparent; box-shadow: none; padding: 0;
    order: 1; gap: 4px; flex: none;
  }
  .barra-titolo { order: 2; }
  .barra-destra { order: 3; }
  .scheda {
    flex-direction: row; gap: 8px; font-size: 0.9375rem; padding: 8px 14px; max-width: none;
  }
  .scheda svg { width: 20px; height: 20px; }
  .scheda[aria-current="page"] { background: var(--accent-soft); }
}

/* ---------------------------------------------------------------- liste e sezioni */

.sezione { margin: 0 0 28px; }
.sezione > h2 {
  font-size: 1.25rem; font-weight: 700; margin: 0 0 10px; letter-spacing: -0.01em;
}
.sezione > h2 .conteggio { color: var(--ink-3); font-weight: 500; font-size: 1rem; margin-left: 6px; }

.foglio {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
.foglio + .foglio { margin-top: 12px; }

/* seduta */
.seduta-testa {
  display: flex; align-items: baseline; gap: 10px; padding: 14px 16px 10px;
}
.seduta-testa h3 { margin: 0; font-size: 1.0625rem; font-weight: 700; }
.seduta-testa .tipo { color: var(--ink-2); font-size: 0.9375rem; flex: 1; min-width: 0; }
.seduta-testa .luogo { color: var(--ink-3); font-size: 0.875rem; white-space: nowrap; }

.righe { list-style: none; margin: 0; padding: 0; }
.riga {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px 12px;
  padding: 9px 16px; min-height: 52px;
  border-top: 1px solid var(--line);
  color: inherit; text-decoration: none;
  transition: background-color 120ms ease-out;
}
a.riga { position: relative; padding-right: 40px; }
a.riga:hover { background: var(--surface-sunk); }
a.riga:active { background: var(--line); }
.freccia {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  display: grid; color: var(--ink-3);
}
.freccia svg { width: 18px; height: 18px; }
/* con la nota aperta la freccia resta accanto al nome, non a metà del testo */
a.riga.con-nota .freccia { top: 21px; }
.riga-nome { font-weight: 500; overflow-wrap: anywhere; }
.insieme { white-space: nowrap; }
.riga-dati {
  display: flex; align-items: center; gap: 8px; justify-content: flex-end;
  color: var(--ink); font-size: 0.9375rem; white-space: nowrap;
}
.riga-dati .round { color: var(--ink-2); }
.riga-nota {
  grid-column: 1 / -1; color: var(--ink-2); font-size: 0.875rem; line-height: 1.45;
  white-space: pre-line;
}
.riga.saltata .riga-nome { color: var(--ink-3); }
.riga-sotto { grid-column: 1 / -1; font-size: 0.9375rem; color: var(--ink); margin-top: -2px; overflow-wrap: anywhere; }
.riga-sotto .round { color: var(--ink-2); }
.riga-sotto .sep { color: var(--ink-3); }
.salito {
  display: inline-grid; place-items: center; width: 18px; height: 18px; margin-left: 6px;
  border-radius: 5px; background: var(--up-soft); color: var(--up); vertical-align: -3px;
}
.salito svg { width: 12px; height: 12px; stroke-width: 2.4; }
.riga.nota-sola { grid-template-columns: auto minmax(0, 1fr); align-items: start; }
.riga.nota-sola svg { width: 18px; height: 18px; color: var(--ink-3); margin-top: 2px; }

.chip {
  display: inline-flex; align-items: center; height: 24px; padding: 0 8px;
  border-radius: 999px; font-size: 0.8125rem; font-weight: 600; white-space: nowrap;
  background: var(--surface-sunk); color: var(--ink-2); border: 1px solid var(--line);
}
.chip-rir { min-width: 58px; justify-content: center; }
.chip-saltato { background: transparent; color: var(--ink-3); }

.seduta-piede {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; min-height: 48px;
  border-top: 1px solid var(--line); padding: 4px 8px;
}
.legenda-salito {
  display: inline-flex; align-items: center; gap: 6px; margin-left: auto; padding: 0 8px;
  color: var(--ink-3); font-size: 0.8125rem;
}
.legenda-salito .salito { margin-left: 0; }
.seduta-piede .btn-testo { font-size: 0.9375rem; font-weight: 600; }

.altre { display: flex; justify-content: center; padding: 8px 0 0; }

/* ---------------------------------------------------------------- esercizi */

.strumenti { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0 0 16px; }
.cerca {
  flex: 1 1 220px; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border-radius: 12px; padding: 0 12px; min-height: 44px;
  box-shadow: inset 0 0 0 1px var(--line);
}
.cerca:focus-within { box-shadow: inset 0 0 0 2px var(--accent); }
.cerca svg { width: 18px; height: 18px; color: var(--ink-3); flex: none; }
.cerca input {
  flex: 1; min-width: 0; border: 0; background: transparent; font: inherit; color: var(--ink);
  min-height: 42px; outline: none;
}
.cerca input::placeholder { color: var(--ink-3); }

.segmenti {
  display: inline-flex; background: var(--line); border-radius: 10px; padding: 2px; gap: 2px;
}
.segmenti button {
  border: 0; background: transparent; border-radius: 8px; padding: 0 12px; min-height: 36px;
  font-size: 0.875rem; font-weight: 600; color: var(--ink-2); cursor: pointer;
  transition: background-color 160ms ease-out, color 160ms ease-out;
}
.segmenti button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.12); }

.esercizio-riga { grid-template-columns: minmax(0, 1fr) auto; }
.esercizio-riga .riga-nome { font-weight: 600; }
.esercizio-dettagli { grid-column: 1 / -1; color: var(--ink-3); font-size: 0.8125rem; margin-top: -2px; }
.esercizio-ultimo { text-align: right; font-size: 0.9375rem; }
.andamento {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 6px;
  font-size: 0.875rem; color: var(--ink-2);
}
.andamento .segno {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 6px; flex: none;
}
.andamento .segno svg { width: 14px; height: 14px; }
.stato-sale .segno { background: var(--up-soft); color: var(--up); }
.stato-fermo .segno { background: var(--stuck-soft); color: var(--stuck); }
.stato-fermo { color: var(--stuck); }
.stato-scende .segno, .stato-uguale .segno, .stato-nuovo .segno { background: var(--down-soft); color: var(--down); }

.vuoto {
  padding: 28px 20px; text-align: center; color: var(--ink-2);
}
.vuoto strong { display: block; color: var(--ink); margin-bottom: 4px; }

/* ---------------------------------------------------------------- dettaglio esercizio */

.fatti {
  display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 10px 0 0; color: var(--ink-2); font-size: 0.9375rem;
}
.fatti b { color: var(--ink); font-weight: 600; }

.grafico-foglio { padding: 14px 16px 12px; }
.grafico-testa { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.legenda { display: flex; flex-wrap: wrap; gap: 6px; }
.voce-legenda {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 10px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  font-size: 0.8125rem; font-weight: 600; color: var(--ink-2); cursor: pointer;
}
.voce-legenda[aria-pressed="false"] { opacity: 0.45; }
.campione { width: 18px; height: 10px; flex: none; }

.grafico { position: relative; margin-top: 10px; touch-action: pan-y; }
.grafico svg { display: block; width: 100%; height: auto; overflow: visible; border-radius: 8px; }
.grafico svg:focus { outline: none; }
.grafico svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.grafico .asse text { font-size: 13px; fill: var(--ink-3); }
.grafico .asse-reps text { fill: var(--reps-ink); }
.grafico .griglia line { stroke: var(--line); stroke-dasharray: 3 4; }
.grafico .guida { stroke: var(--line-strong); stroke-width: 1; }
.linea { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.linea-peso { stroke: var(--accent); stroke-width: 2.5; }
.linea-reps { stroke: var(--reps); stroke-width: 2.25; }
/* area sotto la linea, come nei grafici di Notion: il colore della serie che svanisce verso il basso */
.sfumatura-peso .sf-alto { stop-color: var(--accent); stop-opacity: 0.2; }
.sfumatura-peso .sf-basso { stop-color: var(--accent); stop-opacity: 0; }
.sfumatura-reps .sf-alto { stop-color: var(--reps); stop-opacity: 0.16; }
.sfumatura-reps .sf-basso { stop-color: var(--reps); stop-opacity: 0; }
@media (prefers-color-scheme: dark) {
  .sfumatura-peso .sf-alto { stop-opacity: 0.16; }
}
.linea.tratteggio { stroke-dasharray: 6 5; }
.linea.tratteggio-corto { stroke-dasharray: 4 3; }
.punto-peso { fill: var(--accent); }
.punto-reps { fill: var(--reps); }
.punto.cavo { fill: var(--surface); stroke: var(--accent); stroke-width: 1.8; }
.alone { fill: var(--surface); stroke-width: 2.5; }
.alone-peso { stroke: var(--accent); }
.alone-reps { stroke: var(--reps); }
.sezione-grafico { margin-top: 18px; }
#contenuto:focus { outline: none; }
.suggerimento {
  position: absolute; top: 0; left: 0; z-index: 5; pointer-events: none;
  background: var(--surface); border-radius: 10px; box-shadow: var(--shadow-pop);
  padding: 8px 10px; font-size: 0.8125rem; line-height: 1.4; min-width: 150px; max-width: 230px;
  opacity: 0; transform: translateY(4px);
  transition: opacity 140ms ease-out, transform 140ms ease-out;
}
.suggerimento.visibile { opacity: 1; transform: none; }
.suggerimento b { font-size: 0.875rem; }
.suggerimento .r { color: var(--ink-2); }
.nota-grafico { color: var(--ink-3); font-size: 0.8125rem; margin: 6px 0 0; }

.storico .riga { grid-template-columns: 88px minmax(0, 1fr) auto; }
.storico .data { font-weight: 600; font-size: 0.9375rem; }
.storico .dati-centrali { font-size: 0.9375rem; }
.storico .dati-centrali .luogo { color: var(--ink-3); font-size: 0.8125rem; display: block; }

details.come {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 0 16px;
}
details.come summary {
  min-height: 48px; display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; cursor: pointer; list-style: none;
}
details.come summary::-webkit-details-marker { display: none; }
details.come summary svg { width: 18px; height: 18px; color: var(--ink-3); transition: transform 160ms ease-out; }
details.come[open] summary svg { transform: rotate(90deg); }
details.come p { margin: 0 0 14px; color: var(--ink-2); max-width: 68ch; }

/* ---------------------------------------------------------------- menu account */

.menu {
  position: fixed; z-index: 40; right: max(var(--gutter), calc((100vw - 760px) / 2 + var(--gutter)));
  top: calc(env(safe-area-inset-top) + 56px);
  width: min(320px, calc(100vw - 2 * var(--gutter)));
  margin: 0; padding: 6px; border: 0;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-pop);
  color: var(--ink);
}
.menu-testa { padding: 10px 12px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-testa b { display: block; }
.menu-testa span { color: var(--ink-3); font-size: 0.8125rem; }
.menu button.voce {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 0 12px;
  border: 0; border-radius: 10px; background: transparent; cursor: pointer; text-align: left; font-size: 0.9375rem;
}
.menu button.voce:hover { background: var(--surface-sunk); }
.menu button.voce svg { width: 20px; height: 20px; color: var(--ink-3); flex: none; }
.menu .pannello-link { padding: 8px 12px 10px; font-size: 0.875rem; color: var(--ink-2); }
.menu .pannello-link input {
  width: 100%; font: inherit; font-size: 0.8125rem; padding: 8px 10px; margin: 6px 0;
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface-sunk); color: var(--ink);
}

.avviso {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + 20px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 8px); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 0.9375rem; font-weight: 500; box-shadow: var(--shadow-pop); max-width: calc(100vw - 32px);
  transition: opacity 180ms ease-out, transform 180ms ease-out; pointer-events: none;
}
.avviso.visibile { opacity: 1; transform: translate(-50%, 0); }

/* scheletri di caricamento */
.scheletro { padding: 16px; }
.scheletro i {
  display: block; height: 14px; border-radius: 7px; background: var(--surface-sunk); margin: 10px 0;
  animation: pulsa 1.2s ease-in-out infinite;
}
.scheletro i:nth-child(2) { width: 70%; }
.scheletro i:nth-child(3) { width: 85%; }
@keyframes pulsa { 50% { opacity: 0.45; } }

.errore-pagina { padding: 40px 0; text-align: center; color: var(--ink-2); }
.errore-pagina strong { display: block; color: var(--ink); font-size: 1.125rem; margin-bottom: 6px; }

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

/* ---------------------------------------------------------------- pagina di accesso */

.accesso {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center; padding: 24px var(--gutter);
}
.accesso-colonna { width: 100%; max-width: 380px; text-align: center; }
.marchio {
  width: 72px; height: 72px; border-radius: 18px; margin: 0 auto 18px;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  box-shadow: var(--shadow);
}
.marchio svg { width: 40px; height: 40px; }
.accesso h1 { margin: 0 0 8px; font-size: 1.75rem; letter-spacing: -0.02em; }
.accesso p.spiega { margin: 0 0 24px; color: var(--ink-2); }
.accesso .campo { text-align: left; margin: 0 0 14px; }
.accesso label { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 6px; color: var(--ink-2); }
.accesso input[type="text"] {
  width: 100%; min-height: 44px; padding: 0 12px; font: inherit; color: var(--ink);
  border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface);
}
.messaggio { margin: 14px 0 0; min-height: 1.45em; font-size: 0.9375rem; }
.messaggio.errore { color: var(--danger); }
.messaggio.ok { color: var(--up); }
.piccolo { margin-top: 28px; color: var(--ink-3); font-size: 0.8125rem; }
