/* The Long Road - a private tracker.
   Colour tokens come from the validated data-viz reference palette; the chart
   marks were run through the palette validator (blue vs orange: CVD dE 24.7
   light / 26.8 dark, both well clear of the 8.0 target). */

:root {
    color-scheme: light;

    --plane:          #f9f9f7;
    --surface:        #fcfcfb;
    --surface-sunken: #f2f1ed;
    --ink:            #0b0b0b;
    --ink-2:          #52514e;
    --muted:          #898781;
    --grid:           #e1e0d9;
    --rule:           #c3c2b7;
    --border:         rgba(11, 11, 11, 0.10);

    --accent:         #2a78d6;
    --accent-soft:    #e8f0fc;
    --goal:           #eb6834;
    --raw:            #898781;

    --good:           #0ca30c;
    --warning:        #fab219;
    --critical:       #d03b3b;
    --good-text:      #006300;

    --radius:   12px;
    --radius-s: 8px;
    --gap:      1rem;
    --shadow:   0 1px 2px rgba(11, 11, 11, 0.05);
    --font:     system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --plane:          #0d0d0d;
        --surface:        #1a1a19;
        --surface-sunken: #232322;
        --ink:            #ffffff;
        --ink-2:          #c3c2b7;
        --muted:          #898781;
        --grid:           #2c2c2a;
        --rule:           #383835;
        --border:         rgba(255, 255, 255, 0.10);
        --accent:         #3987e5;
        --accent-soft:    #16243a;
        --goal:           #d95926;
        --raw:            #898781;
        --good-text:      #0ca30c;
        --shadow:         none;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --plane:          #0d0d0d;
    --surface:        #1a1a19;
    --surface-sunken: #232322;
    --ink:            #ffffff;
    --ink-2:          #c3c2b7;
    --muted:          #898781;
    --grid:           #2c2c2a;
    --rule:           #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --accent:         #3987e5;
    --accent-soft:    #16243a;
    --goal:           #d95926;
    --raw:            #898781;
    --good-text:      #0ca30c;
    --shadow:         none;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--plane);
    color: var(--ink);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }

/* --- Layout ------------------------------------------------------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top, 0);
}

.topbar-inner {
    max-width: 960px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.7rem 1rem;
}

.wordmark {
    font-weight: 700;
    letter-spacing: -0.01em;
    text-decoration: none;
    color: var(--ink);
    font-size: 1.05rem;
    white-space: nowrap;
}

.nav {
    display: flex;
    gap: 0.15rem;
    overflow-x: auto;
    scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }

.nav a {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-s);
    color: var(--ink-2);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
    white-space: nowrap;
}
.nav a:hover { background: var(--surface-sunken); }
.nav a.is-current { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.25rem 1rem 4rem;
}

h1 { font-size: 1.5rem; margin: 0 0 0.2rem; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }
h3 { font-size: 0.95rem; margin: 0 0 0.5rem; }
.page-sub { color: var(--ink-2); margin: 0 0 1.5rem; font-size: 0.95rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem;
    margin-bottom: var(--gap);
    box-shadow: var(--shadow);
}

.card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.9rem;
}
.card-head h2, .card-head h1 { margin: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }

@media (max-width: 720px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* --- Figures ------------------------------------------------------------ */

.stat-label {
    font-size: 0.8rem;
    color: var(--ink-2);
    text-transform: none;
    margin-bottom: 0.15rem;
}

/* Proportional figures on purpose: tabular-nums makes 121 look loose at
   display sizes. Tabular is reserved for the tables and the axis ticks. */
.hero {
    font-size: 2.75rem;
    font-weight: 600;
    line-height: 1.05;
    letter-spacing: -0.02em;
}
.hero .unit { font-size: 1.1rem; font-weight: 500; color: var(--ink-2); }

.stat-value { font-size: 1.6rem; font-weight: 600; line-height: 1.15; }
.stat-value .unit { font-size: 0.85rem; font-weight: 500; color: var(--ink-2); }

.delta { font-size: 0.9rem; font-weight: 600; }
.delta.down { color: var(--good-text); }
.delta.up   { color: var(--critical); }
.delta.flat { color: var(--ink-2); }

.meter {
    height: 8px;
    background: var(--surface-sunken);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 0.5rem;
}
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.meter.over span { background: var(--warning); }

/* --- Chart -------------------------------------------------------------- */

.chart-wrap { position: relative; }
.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }

.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--rule); stroke-width: 1; }
.chart .tick-text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

.chart .trend-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}
/* Dashing is legitimate here: it means "projected", not "gridline". */
.chart .projection-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
    stroke-dasharray: 5 5;
    opacity: 0.75;
    stroke-linecap: round;
}
.chart .goal-line { stroke: var(--goal); stroke-width: 2; }
.chart .goal-label { fill: var(--ink-2); font-size: 11px; font-weight: 600; }

/* Raw readings recede: they are the same measurement as the trend, just noisy.
   Muted grey clears 3:1 on both surfaces (3.50 light / 4.85 dark). */
.chart .raw-dot { fill: var(--raw); stroke: var(--surface); stroke-width: 2; }
.chart .end-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .end-label { fill: var(--ink); font-size: 12px; font-weight: 600; }

.chart .hit { fill: transparent; }
.chart .crosshair { stroke: var(--rule); stroke-width: 1; opacity: 0; }
.chart .focus-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; opacity: 0; }

.chart-tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-s);
    box-shadow: 0 4px 14px rgba(11, 11, 11, 0.12);
    padding: 0.5rem 0.65rem;
    font-size: 0.82rem;
    line-height: 1.4;
    opacity: 0;
    transition: opacity 0.1s;
    white-space: nowrap;
    z-index: 5;
}
.chart-tooltip .tt-date { color: var(--ink-2); margin-bottom: 0.2rem; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 0.4rem; }
.chart-tooltip b { font-variant-numeric: tabular-nums; }

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.1rem;
    margin-top: 0.6rem;
    font-size: 0.85rem;
    color: var(--ink-2);
}
.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.key { width: 14px; height: 3px; border-radius: 2px; flex-shrink: 0; }
.key.dot { width: 9px; height: 9px; border-radius: 50%; }
.key.dash {
    background: repeating-linear-gradient(90deg,
        var(--accent) 0 5px, transparent 5px 9px);
}

/* --- Range filter row (above the chart, never inside the card body) ------ */

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1rem;
    align-items: center;
}
.chip {
    padding: 0.4rem 0.8rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink-2);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
}
.chip.is-current { background: var(--accent); border-color: var(--accent); color: #fff; }

/* --- Forms -------------------------------------------------------------- */

.field { margin-bottom: 0.85rem; }
.field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink-2);
    margin-bottom: 0.3rem;
}
.field .help { font-size: 0.78rem; color: var(--muted); margin-top: 0.25rem; }
.field .error { font-size: 0.82rem; color: var(--critical); margin-top: 0.25rem; }

input[type="text"], input[type="number"], input[type="date"],
input[type="password"], select, textarea {
    width: 100%;
    padding: 0.6rem 0.7rem;
    font-size: 1rem;
    font-family: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius-s);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.form-row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: flex-end; }
.form-row .field { flex: 1 1 8rem; margin-bottom: 0; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.62rem 1.1rem;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: var(--radius-s);
    border: 1px solid transparent;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    cursor: pointer;
    min-height: 2.6rem;
}
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--rule); }
.btn.ghost { background: transparent; color: var(--ink-2); border-color: transparent; padding: 0.4rem 0.6rem; }
.btn.danger { background: var(--critical); }
.btn.small { padding: 0.35rem 0.7rem; font-size: 0.85rem; min-height: 2.1rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* --- Tables ------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--grid); }
th { font-size: 0.78rem; color: var(--ink-2); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }
tfoot td { font-weight: 600; border-top: 1px solid var(--rule); border-bottom: none; }

details.table-view { margin-top: 0.9rem; }
details.table-view summary {
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--ink-2);
    padding: 0.35rem 0;
}

/* --- Lists & misc ------------------------------------------------------- */

.item-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--grid);
}
.item-row:last-child { border-bottom: none; }
.item-row .grow { flex: 1; min-width: 0; }
.item-row .title { font-weight: 600; }
.item-row .sub { font-size: 0.83rem; color: var(--ink-2); }
.item-row.done .title { text-decoration: line-through; color: var(--muted); }

.tick {
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 50%;
    border: 2px solid var(--rule);
    background: var(--surface);
    cursor: pointer;
    flex-shrink: 0;
    font-size: 1rem;
    line-height: 1;
    color: transparent;
    padding: 0;
}
.tick.is-done { background: var(--good); border-color: var(--good); color: #fff; }

.pill {
    display: inline-block;
    padding: 0.12rem 0.5rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    background: var(--surface-sunken);
    color: var(--ink-2);
}
.pill.stretch  { background: #e8f0fc; color: #1c5cab; }
.pill.strength { background: #fdece4; color: #a83c12; }
.pill.cardio   { background: #e6f6ef; color: #0d6b4c; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .pill.stretch  { background: #16243a; color: #86b6ef; }
    :root:not([data-theme="light"]) .pill.strength { background: #33190e; color: #eb6834; }
    :root:not([data-theme="light"]) .pill.cardio   { background: #0e2a20; color: #1baf7a; }
}

.day-nav { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 1rem; }
.day-nav .day-name { font-weight: 600; font-size: 1.05rem; }
.day-nav .day-sub { font-size: 0.8rem; color: var(--ink-2); }

.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li {
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-s);
    border-left: 3px solid var(--accent);
    background: var(--accent-soft);
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
}
.messages li.success { border-left-color: var(--good); }

.empty { color: var(--ink-2); font-size: 0.92rem; padding: 0.8rem 0; }

.bar-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.3rem 0; }
.bar-row .bar-label { width: 5.5rem; font-size: 0.82rem; color: var(--ink-2); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.bar-row .bar-track { flex: 1; height: 18px; position: relative; background: var(--surface-sunken); border-radius: 4px; overflow: hidden; }
/* 4px rounded data-end, square at the baseline. */
.bar-row .bar-fill { height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.bar-row .bar-fill.over { background: var(--warning); }
.bar-row .bar-value { width: 4.5rem; text-align: right; font-size: 0.85rem; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.target-marker { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--goal); }

.login-shell { max-width: 380px; margin: 12vh auto; padding: 0 1rem; }
.login-shell .wordmark { font-size: 1.4rem; display: block; margin-bottom: 0.3rem; }
.login-shell .tagline { color: var(--ink-2); margin: 0 0 1.5rem; font-size: 0.92rem; }

.step-list { padding-left: 1.3rem; margin: 0; }
.step-list li { margin-bottom: 0.5rem; }

.formset-row {
    border: 1px solid var(--border);
    border-radius: var(--radius-s);
    padding: 0.75rem;
    margin-bottom: 0.6rem;
    background: var(--surface-sunken);
}
.formset-row .delete-box { font-size: 0.82rem; color: var(--ink-2); }
.formset-row input[type="checkbox"] { width: auto; margin-right: 0.3rem; }
