/* style.css — Ghisa. Mobile-first, tema scuro, alto contrasto.
   Pensato per mani sudate: tasti grandi (>=48px), testo leggibile.
   Nessun framework, scritto a mano. */

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

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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
    font-size: 18px;
    line-height: 1.4;
    color: #f5f5f5;
    background: #111;
    /* Rispetta notch e barre di sistema. */
    padding: env(safe-area-inset-top) env(safe-area-inset-right)
             env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* [hidden] deve sempre vincere sui display impostati sotto. */
[hidden] { display: none !important; }

h1, h2 { margin: 0 0 0.6em; font-weight: 700; }
h2 { font-size: 1.25rem; }

.error { color: #ff6b6b; font-weight: 600; }

/* --- Colori accento ------------------------------------------------------- */
:root {
    --accent: #ff6b35;      /* arancio ghisa arroventata */
    --accent-press: #e2551f;
    --surface: #1c1c1e;
    --surface-2: #262629;
    --muted: #9a9a9f;
    --tap: 56px;            /* altezza minima area di tap */
}

/* --- Visibilità login <-> app -------------------------------------------- */
.view { display: none; }
body[data-logged-in="0"] #login-view { display: block; }
body[data-logged-in="1"] #app-view   { display: block; }

/* --- Contenitori ---------------------------------------------------------- */
#login-view, .screen {
    max-width: 560px;
    margin: 0 auto;
    padding: 20px 16px 40px;
}

/* --- Login ---------------------------------------------------------------- */
#login-view {
    min-height: 80vh;
    display: none;                 /* sovrascritto da data-logged-in="0" */
    flex-direction: column;
    justify-content: center;
}
body[data-logged-in="0"] #login-view { display: flex; }

.brand {
    font-size: 2.4rem;
    text-align: center;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent);
}

#login-form { display: flex; flex-direction: column; gap: 16px; }

/* --- Campi ---------------------------------------------------------------- */
label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.95rem;
    color: var(--muted);
}

input[type="text"],
input[type="number"],
input[type="url"] {
    width: 100%;
    min-height: var(--tap);
    padding: 12px 14px;
    font-size: 1.2rem;
    color: #fff;
    background: var(--surface);
    border: 2px solid #3a3a3d;
    border-radius: 12px;
    -webkit-appearance: none;
    appearance: none;
}
input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Toglie le frecce spin ai number su desktop (mobile non le mostra). */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* --- Bottoni -------------------------------------------------------------- */
button {
    font-family: inherit;
    cursor: pointer;
}

.big, button[type="submit"], .primary {
    display: block;
    width: 100%;
    min-height: var(--tap);
    padding: 16px;
    margin: 10px 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
    background: var(--surface-2);
    border: 2px solid #3a3a3d;
    border-radius: 14px;
    text-align: center;
}
.big:active { background: #303034; }

.primary, button[type="submit"] {
    background: var(--accent);
    border-color: var(--accent);
    color: #1a1a1a;
}
.primary:active, button[type="submit"]:active { background: var(--accent-press); }

/* Link testuale (torna indietro, esci, salta, storico). */
.link {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 1rem;
    padding: 12px;
    min-height: 48px;
    text-decoration: underline;
}
.link.danger { color: #ff6b6b; }

/* Scheda in home: nome + "giorni fa" su due righe. */
.wk { display: flex; flex-direction: column; gap: 4px; }
.wk-name { font-size: 1.15rem; font-weight: 700; }
.wk-sub { font-size: 0.8rem; font-weight: 400; color: var(--muted); }

/* --- Topbar --------------------------------------------------------------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid #2a2a2d;
    position: sticky;
    top: 0;
    background: #111;
    z-index: 5;
}
.brand-small {
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--accent);
}
.topbar .link { margin-left: auto; padding: 8px 4px; min-height: 40px; }

/* Indicatore coda offline: discreto ma leggibile. */
.queue {
    font-size: 0.8rem;
    color: #1a1a1a;
    background: var(--accent);
    padding: 3px 10px;
    border-radius: 999px;
    font-weight: 700;
}

/* --- Player --------------------------------------------------------------- */
.player { text-align: center; }
.p-progress { color: var(--muted); font-size: 0.9rem; margin-bottom: 6px; }
.p-exercise { font-size: 1.6rem; margin: 0 0 4px; }
.p-target { color: var(--muted); margin-bottom: 2px; }
.p-set { font-size: 1.1rem; margin-bottom: 18px; font-weight: 600; }

.p-field { text-align: left; margin-bottom: 14px; }

/* Riferimento "l'ultima volta" sotto il nome dell'esercizio. */
.p-last {
    margin: 6px 0 16px;
    padding: 8px 12px;
    font-size: 0.95rem;
    color: #cfcfcf;
    background: var(--surface);
    border-radius: 10px;
    font-variant-numeric: tabular-nums;
}

/* Link esplicativo dell'esercizio. */
.p-url {
    display: inline-block;
    margin: 2px 0 10px;
    color: var(--accent);
    text-decoration: underline;
    font-size: 0.95rem;
    min-height: 32px;
}

/* Controlli "+ Serie" / "Salta esercizio" / "Alternativa" sotto Avanti. */
.p-extra {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin: 2px 0 6px;
}
.p-extra .link { min-height: 44px; }

/* Etichetta "Al posto di …" nella schermata alternativa. */
.alt-for { color: var(--muted); margin: -6px 0 14px; }

/* Riga sostituzione nella schermata di fine. */
.sub-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    text-align: left;
    padding: 12px;
    background: var(--surface);
    border-radius: 10px;
    margin-bottom: 8px;
    color: #e6e6e6;
}
.sub-check {
    width: 24px;
    height: 24px;
    margin-top: 1px;
    flex: 0 0 auto;
    accent-color: var(--accent);
}

/* Textarea (nota di fine allenamento). */
textarea {
    width: 100%;
    min-height: 90px;
    padding: 12px 14px;
    font-family: inherit;
    font-size: 1.05rem;
    color: #fff;
    background: var(--surface);
    border: 2px solid #3a3a3d;
    border-radius: 12px;
    resize: vertical;
    -webkit-appearance: none;
    appearance: none;
}
textarea:focus { outline: none; border-color: var(--accent); }

/* Timer di recupero: molto visibile. */
.p-rest {
    margin: 16px 0;
    padding: 14px;
    font-size: 1.3rem;
    font-weight: 700;
    background: var(--surface);
    border: 2px solid var(--accent);
    border-radius: 14px;
}
.p-rest .link { display: inline; margin-left: 10px; }

/* Lista esercizi della scheda in fondo al player. */
.exlist-wrap {
    margin-top: 28px;
    padding-top: 16px;
    border-top: 1px solid #2a2a2d;
    text-align: left;
}
.exlist-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin: 0 0 8px;
}
.exlist {
    list-style: decimal;
    margin: 0;
    padding-left: 1.6em;
    color: var(--muted);
}
.exlist-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    margin: 3px 0;
    border-radius: 8px;
}
.exlist-item.current {
    background: var(--surface);
    color: #fff;
    font-weight: 700;
    outline: 2px solid var(--accent);
}
.exlist-item.done { opacity: 0.55; }
.exlist-item.done .exlist-name { text-decoration: line-through; }
.exlist-target { font-variant-numeric: tabular-nums; }
.exlist-item.current .exlist-target { color: var(--accent); }

/* --- Storico -------------------------------------------------------------- */
.session {
    background: var(--surface);
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 14px;
}
.session-head { font-weight: 700; margin-bottom: 8px; }
.set-row {
    color: #e6e6e6;
    padding: 3px 0;
    border-top: 1px solid #2a2a2d;
    font-variant-numeric: tabular-nums;
}
.set-row:first-of-type { border-top: none; }
.session-notes {
    margin-top: 8px;
    color: var(--muted);
    font-style: italic;
}

/* --- Riepilogo ------------------------------------------------------------ */
.summary {
    white-space: pre-wrap;
    background: var(--surface);
    border-radius: 14px;
    padding: 16px;
    font-size: 1.05rem;
    line-height: 1.6;
    font-family: inherit;
}

/* --- Toast ---------------------------------------------------------------- */
#toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translateX(-50%) translateY(20px);
    background: #f5f5f5;
    color: #111;
    padding: 12px 18px;
    border-radius: 12px;
    font-weight: 600;
    max-width: 90%;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
