/* Denise — console personale di Alex.
   Identità: metà "familiare da tavolo" (dado D20, ciondolo in ottone),
   metà AI (tatuaggio a circuiti). Da qui i due accenti: ottone + circuito. */

:root {
    --ink: #eef2f1;
    --surface-1: #ffffff;
    --surface-2: #e5eae8;
    --line: #d6ddda;
    --text: #1b1f1e;
    --text-dim: #5c6663;

    --brass: #a5761f;
    --circuit: #158f80;
    --good: #3f7a3d;
    --warn: #a85526;
    --bad: #9c3a34;
    --good-bg: #e4f1e2;
    --warn-bg: #f7e6d8;
    --bad-bg: #f6e0de;
    --info-bg: #dcf1ee;

    /* la sidebar resta sempre scura (lo "chassis" della console),
       indipendentemente dal tema del contenuto */
    --rail-bg: #15130f;
    --rail-surface: #1e1b16;
    --rail-line: #34302a;
    --rail-text: #ece6da;
    --rail-text-dim: #a89e8c;

    --font-display: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    --font-body: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

    --radius: 8px;
    --shadow: 0 1px 2px rgba(20, 20, 15, 0.06), 0 4px 14px rgba(20, 20, 15, 0.05);
}

@media (prefers-color-scheme: dark) {
    :root {
        --ink: #15130f;
        --surface-1: #1e1b16;
        --surface-2: #262219;
        --line: #353025;
        --text: #ece6da;
        --text-dim: #a89e8c;

        --brass: #d1a34e;
        --circuit: #6fd3c7;
        --good: #7cbb77;
        --warn: #dd9257;
        --bad: #d9736b;
        --good-bg: #1f2e1c;
        --warn-bg: #332417;
        --bad-bg: #34201c;
        --info-bg: #17302e;

        --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 4px 16px rgba(0, 0, 0, 0.3);
    }
}

:root[data-theme="dark"] {
    --ink: #15130f;
    --surface-1: #1e1b16;
    --surface-2: #262219;
    --line: #353025;
    --text: #ece6da;
    --text-dim: #a89e8c;
    --brass: #d1a34e;
    --circuit: #6fd3c7;
    --good: #7cbb77;
    --warn: #dd9257;
    --bad: #d9736b;
    --good-bg: #1f2e1c;
    --warn-bg: #332417;
    --bad-bg: #34201c;
    --info-bg: #17302e;
}

:root[data-theme="light"] {
    --ink: #eef2f1;
    --surface-1: #ffffff;
    --surface-2: #e5eae8;
    --line: #d6ddda;
    --text: #1b1f1e;
    --text-dim: #5c6663;
    --brass: #a5761f;
    --circuit: #158f80;
    --good: #3f7a3d;
    --warn: #a85526;
    --bad: #9c3a34;
    --good-bg: #e4f1e2;
    --warn-bg: #f7e6d8;
    --bad-bg: #f6e0de;
    --info-bg: #dcf1ee;
}

* { box-sizing: border-box; }
::selection { background: var(--circuit); color: #0a0f0e; }

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

body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--ink);
    color: var(--text);
    line-height: 1.55;
    font-size: 15px;
}

a { color: var(--circuit); }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--circuit); outline-offset: 2px; }

code, .mono { font-family: var(--font-display); }
.tnum { font-variant-numeric: tabular-nums; }

h1, h2, h3 {
    font-family: var(--font-display);
    font-weight: 600;
    line-height: 1.25;
    margin: 0;
    text-wrap: balance;
}
h1 { font-size: 1.35rem; letter-spacing: -0.01em; }
h2 { font-size: 1rem; }

.eyebrow {
    font-family: var(--font-display);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-dim);
}

.subtitle { color: var(--text-dim); margin: 0.35rem 0 0; font-size: 0.9rem; max-width: 62ch; }

/* ---------- shell: sidebar sempre scura + contenuto a tema ---------- */

.shell { display: flex; min-height: 100vh; }

.rail {
    flex: 0 0 232px;
    background: var(--rail-bg);
    color: var(--rail-text);
    border-right: 1px solid var(--rail-line);
    display: flex;
    flex-direction: column;
    padding: 1.25rem 1rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.rail-brand { display: flex; align-items: center; gap: 0.7rem; text-decoration: none; color: var(--rail-text); padding-bottom: 1.1rem; margin-bottom: 1.1rem; border-bottom: 1px solid var(--rail-line); }
.rail-brand img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; border: 2px solid var(--brass); }
.rail-brand .name { font-family: var(--font-display); font-weight: 600; font-size: 1rem; display: block; }
.rail-brand .role { font-size: 0.72rem; color: var(--rail-text-dim); display: block; margin-top: 0.1rem; }

.rail-nav { display: flex; flex-direction: column; gap: 0.15rem; flex: 1; }
.rail-nav a {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius);
    color: var(--rail-text-dim);
    text-decoration: none;
    font-size: 0.87rem;
    border-left: 2px solid transparent;
}
.rail-nav a svg { width: 17px; height: 17px; flex: none; opacity: 0.85; }
.rail-nav a:hover { background: var(--rail-surface); color: var(--rail-text); }
.rail-nav a.active { background: var(--rail-surface); color: var(--brass); border-left-color: var(--brass); }
.rail-nav a.active svg { opacity: 1; }

.rail-group summary {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius);
    color: var(--rail-text-dim);
    font-size: 0.87rem;
    cursor: pointer;
    border-left: 2px solid transparent;
    list-style: none;
    user-select: none;
}
.rail-group summary::-webkit-details-marker { display: none; }
.rail-group summary svg:first-child { width: 17px; height: 17px; flex: none; opacity: 0.85; }
.rail-group summary:hover { background: var(--rail-surface); color: var(--rail-text); }
.rail-group summary .chevron { width: 14px; height: 14px; flex: none; margin-left: auto; opacity: 0.6; transition: transform 150ms ease; }
.rail-group[open] > summary .chevron { transform: rotate(90deg); }
.rail-group[open] > summary { color: var(--rail-text); }
.rail-group:has(.rail-subnav a.active) > summary { color: var(--brass); border-left-color: var(--brass); }
.rail-group:has(.rail-subnav a.active) > summary svg:first-child { opacity: 1; }

.rail-subnav { display: flex; flex-direction: column; gap: 0.1rem; padding-left: 1.35rem; margin-top: 0.1rem; }
.rail-subnav a { font-size: 0.83rem; padding: 0.42rem 0.6rem; }

.rail-foot { padding-top: 0.9rem; margin-top: 0.6rem; border-top: 1px solid var(--rail-line); display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.rail-foot a { color: var(--rail-text-dim); font-size: 0.8rem; text-decoration: none; }
.rail-foot a:hover { color: var(--rail-text); }

.theme-toggle {
    background: var(--rail-surface);
    border: 1px solid var(--rail-line);
    color: var(--rail-text-dim);
    border-radius: 999px;
    width: 30px; height: 30px;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
}
.theme-toggle:hover { color: var(--brass); }
.theme-toggle svg { width: 15px; height: 15px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

.main { flex: 1; min-width: 0; }
.topbar-mobile { display: none; }

.page { max-width: 1100px; margin: 0 auto; padding: 2rem 2rem 4rem; }
.page-narrow { max-width: 420px; }

.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }

/* ---------- stat tiles (dashboard) ---------- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.9rem; margin-bottom: 1.75rem; }
.stat-tile { background: var(--surface-1); border: 1px solid var(--line); border-top: 2px solid var(--brass); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; }
.stat-tile.good-tile { border-top-color: var(--good); }
.stat-tile.good-tile .stat-value { color: var(--good); }
.stat-tile.warn-tile { border-top-color: var(--warn); }
.stat-tile.warn-tile .stat-value { color: var(--warn); }
.stat-tile.bad-tile { border-top-color: var(--bad); }
.stat-tile.bad-tile .stat-value { color: var(--bad); }
.stat-tile .stat-value { font-family: var(--font-display); font-size: 1.85rem; font-weight: 600; line-height: 1; }
.stat-tile .stat-label { color: var(--text-dim); font-size: 0.78rem; margin-top: 0.4rem; }

/* ---------- cards & tables ---------- */

.card { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 1.5rem; }
.card .card-body { padding: 1.25rem 1.4rem; }
.card-scroll { overflow-x: auto; }

/* ---------- modal (generico, riusabile: vedi public/garmin-activities.php) ---------- */

.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(15, 15, 12, 0.55);
    z-index: 1000; align-items: flex-start; justify-content: center;
    padding: 4vh 1rem; overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); max-width: 560px; width: 100%; padding: 1.4rem 1.5rem;
    position: relative;
}
.modal-close {
    position: absolute; top: 0.9rem; right: 1rem; background: none; border: none;
    color: var(--text-dim); font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 0.2rem 0.4rem;
}
.modal-close:hover { color: var(--text); }
.modal-box h2 { margin: 0 0 0.2rem; }
.modal-box .modal-subtitle { color: var(--text-dim); font-size: 0.85rem; margin: 0 0 1.1rem; }
.modal-section { margin-bottom: 1.1rem; }
.modal-section:last-child { margin-bottom: 0; }
.modal-section h3 { font-family: var(--font-display); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); margin: 0 0 0.5rem; }
.modal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 0.7rem 1rem; }
.modal-stat .modal-stat-value { font-variant-numeric: tabular-nums; font-weight: 600; }
.modal-stat .modal-stat-label { color: var(--text-dim); font-size: 0.75rem; margin-top: 0.1rem; }
.modal-hrzones { display: flex; flex-direction: column; gap: 0.3rem; }
.modal-hrzone-row { display: grid; grid-template-columns: 60px 1fr 50px; align-items: center; gap: 0.5rem; font-size: 0.78rem; }
.modal-hrzone-bar { background: var(--surface-2); border-radius: 4px; height: 8px; overflow: hidden; }
.modal-hrzone-fill { height: 100%; background: var(--brass); }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { background: var(--surface-2); font-family: var(--font-display); font-weight: 600; color: var(--text-dim); text-transform: uppercase; font-size: 0.66rem; letter-spacing: 0.06em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tr.disabled-row { opacity: 0.5; }
/* white-space qui era pre-wrap: nessun contenuto reale in queste celle ha
   mai newline intenzionali (sono valori singoli o link/form separati da "·"),
   ma il markup PHP sì (indentazione multi-riga del sorgente) — pre-wrap la
   rendeva visibile a schermo (es. "modifica" e "elimina" su righe separate
   invece che affiancati). normal lascia comunque il wrap del testo lungo via
   overflow-wrap, senza mostrare gli a-capo del sorgente. */
td.wrap, td.detail { max-width: 320px; overflow-wrap: anywhere; white-space: normal; }
td.empty-row { padding: 2.5rem 1rem; text-align: center; color: var(--text-dim); }
td, th { font-variant-numeric: tabular-nums; }

/* ---------- controls ---------- */

.btn {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    background: var(--brass);
    color: #1b1508 !important;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    font-family: var(--font-body);
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--circuit) !important; border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--surface-2); }

.link-action { background: none; border: none; color: var(--circuit); cursor: pointer; padding: 0; font-size: 0.82rem; text-decoration: underline; font-family: inherit; }
.link-action.danger { color: var(--bad); }

.chip { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.18rem 0.6rem; border-radius: 999px; font-size: 0.72rem; font-weight: 600; font-family: var(--font-display); white-space: nowrap; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip-muted { background: var(--surface-2); color: var(--text-dim); }
.chip-info { background: var(--info-bg); color: var(--circuit); }
.chip-warn { background: var(--warn-bg); color: var(--warn); }
.chip-good { background: var(--good-bg); color: var(--good); }
.chip-bad { background: var(--bad-bg); color: var(--bad); }
.chip-brass { background: var(--warn-bg); background: color-mix(in srgb, var(--brass) 18%, transparent); color: var(--brass); }

.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1.25rem; font-size: 0.88rem; border: 1px solid transparent; }
.alert-error { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.alert-success { background: var(--good-bg); color: var(--good); border-color: var(--good); }

label { display: block; margin-bottom: 0.9rem; font-size: 0.87rem; color: var(--text-dim); }
input[type="text"], input[type="password"], input[type="number"], input[type="datetime-local"], select, textarea {
    display: block; width: 100%; margin-top: 0.35rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: 0.92rem;
    font-family: var(--font-body);
    background: var(--ink);
    color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--circuit); outline-offset: 1px; }

.checkbox-label { display: flex; align-items: center; gap: 0.5rem; }
.checkbox-label input[type="checkbox"] { width: auto; margin: 0; }

.code-display { font-family: var(--font-display); font-size: 1.9rem; letter-spacing: 0.25rem; font-weight: 600; text-align: center; margin: 1.5rem 0; color: var(--brass); }

/* Sotto 860px la sidebar diventa un cassetto (drawer) fuori schermo invece
   di una barra orizzontale a soli icone: la versione precedente comprimeva
   il gruppo "Nurse" (9 voci) in un dropdown assoluto dentro un contenitore
   con overflow-x:auto, che lo tagliava/rendeva inutilizzabile su telefono —
   qui invece il cassetto riusa esattamente il markup/stile verticale del
   desktop (stesso <details> per i gruppi, niente JS per i sottomenu), solo
   spostato fuori schermo e fatto scorrere dentro con un pulsante hamburger,
   stesso pattern classList.add/remove('open') + overlay del modal generico
   (vedi public/garmin-activities.php). */
@media (max-width: 860px) {
    .topbar-mobile {
        display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
        background: var(--rail-bg); border-bottom: 1px solid var(--rail-line);
        padding: 0.65rem 1rem; position: sticky; top: 0; z-index: 20;
    }
    .topbar-brand { display: flex; align-items: center; gap: 0.6rem; text-decoration: none; color: var(--rail-text); min-width: 0; }
    .topbar-brand img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; border: 2px solid var(--brass); flex: none; }
    .topbar-brand .name { font-family: var(--font-display); font-weight: 600; font-size: 0.95rem; color: var(--rail-text); }

    .rail-toggle {
        background: var(--rail-surface); border: 1px solid var(--rail-line); color: var(--rail-text);
        width: 38px; height: 38px; border-radius: var(--radius); flex: none;
        display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
    }
    .rail-toggle:hover { color: var(--brass); }
    .rail-toggle svg { width: 20px; height: 20px; }

    .rail-overlay { display: none; position: fixed; inset: 0; background: rgba(15, 15, 12, 0.55); z-index: 29; }
    .rail-overlay.open { display: block; }

    .shell { flex-direction: column; }
    .rail {
        position: fixed; top: 0; left: 0; height: 100vh; width: 268px; max-width: 82vw;
        transform: translateX(-100%);
        transition: transform 200ms ease;
        z-index: 30;
        box-shadow: var(--shadow);
    }
    .rail.open { transform: translateX(0); }

    .page { padding: 1.25rem 1.1rem 3rem; }
}

@media (prefers-reduced-motion: no-preference) {
    .btn, .rail-nav a, a { transition: background-color 120ms ease, color 120ms ease, filter 120ms ease; }
}
