:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #eef1f5;
    --text: #1d2330;
    --muted: #667085;
    --border: #dde2ea;
    --accent: #2563eb;
    --accent-text: #ffffff;
    --good: #16a34a;
    --warn: #d97706;
    --bad: #dc2626;
    --ctl: #2563eb;
    --atl: #db2777;
    --tsb: #d97706;
    --radius: 10px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f131a;
        --surface: #171c25;
        --surface-2: #1f2633;
        --text: #e6e9ef;
        --muted: #98a2b3;
        --border: #2b3343;
        --accent: #60a5fa;
        --accent-text: #0b1220;
        --ctl: #60a5fa;
        --atl: #f472b6;
        --tsb: #fbbf24;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    font-size: 15px;
}

a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h1:focus { outline: none; }
h2 { font-size: 1.2rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }

.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 210px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
    padding: 1rem .75rem; display: flex; flex-direction: column; gap: .15rem;
}
.sidebar .brand { font-weight: 700; font-size: 1.05rem; padding: .25rem .5rem 1rem; }
.sidebar a { color: var(--text); text-decoration: none; padding: .5rem .75rem; border-radius: 8px; }
.sidebar a:hover { background: var(--surface-2); }
.sidebar a.active { background: var(--accent); color: var(--accent-text); }
.content { flex: 1; padding: 1.5rem 2rem; max-width: 1300px; min-width: 0; }

@media (max-width: 760px) {
    .shell { flex-direction: column; }
    .sidebar { width: auto; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--border); }
    .sidebar .brand { width: 100%; padding-bottom: .25rem; }
    .content { padding: 1rem; }
}

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stats { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; }
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.stat .value { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: .8rem; }

.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.good { color: var(--good); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }

.btn {
    display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--border); background: var(--surface);
    color: var(--text); padding: .45rem .9rem; border-radius: 8px; cursor: pointer; text-decoration: none; font: inherit;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: .2rem .55rem; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: default; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

form .field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .75rem; }
form label, .field label { font-size: .85rem; color: var(--muted); }
input, select, textarea {
    font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; padding: .45rem .6rem;
}
textarea { min-height: 80px; }
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.checks { display: flex; gap: .75rem; flex-wrap: wrap; }
.checks label { display: flex; gap: .3rem; align-items: center; color: var(--text); }

.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid var(--border); background: var(--surface-2); }
.alert.ok { border-color: var(--good); }
.alert.err { border-color: var(--bad); }

.badge { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.Base { background: #dbeafe; color: #1e3a8a; border-color: transparent; }
.badge.Build { background: #fef3c7; color: #78350f; border-color: transparent; }
.badge.Peak { background: #fee2e2; color: #7f1d1d; border-color: transparent; }
.badge.Taper, .badge.Event { background: #ede9fe; color: #4c1d95; border-color: transparent; }
.badge.Recovery { background: #dcfce7; color: #14532d; border-color: transparent; }
.badge.Maintenance { background: #e0f2fe; color: #0c4a6e; border-color: transparent; }

/* Plan calendar */
.week { display: grid; grid-template-columns: 150px repeat(7, minmax(0, 1fr)); gap: .4rem; margin-bottom: .4rem; }
.week-head { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem; font-size: .85rem; }
.day { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .35rem; min-height: 80px; font-size: .8rem; display: flex; flex-direction: column; gap: .25rem; }
.day.past { opacity: .65; }
.day.today { outline: 2px solid var(--accent); }
.day .date { color: var(--muted); font-size: .75rem; }
.wo { display: block; border-radius: 6px; padding: .3rem .4rem; text-decoration: none; color: #111; border-left: 4px solid rgba(0,0,0,.25); }
.wo .t { font-weight: 600; display: block; }
.wo.done::after { content: " ✓"; font-weight: 700; color: #166534; }
.wo-Recovery, .wo-Mobility { background: #e5e7eb; }
.wo-Endurance, .wo-LongRide { background: #bfdbfe; }
.wo-Tempo, .wo-SweetSpot { background: #a7f3d0; }
.wo-Threshold { background: #fde68a; }
.wo-VO2Max, .wo-OverUnders { background: #fdba74; }
.wo-Anaerobic { background: #fca5a5; }
.wo-Openers { background: #ddd6fe; }
.wo-Strength { background: #f5d0fe; }
.wo-Event, .wo-FitnessAssessment { background: #c4b5fd; border-left-color: #5b21b6; }
.wo-Run { background: #fed7aa; }
.wo-Agility { background: #bbf7d0; border-left-color: #15803d; }
.wo-Swim { background: #a5f3fc; }
.wo-Other, .wo-Rest { background: #e5e7eb; }

.exercise-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.exercise { border: 1px solid var(--border); border-radius: 8px; padding: .6rem; display: flex; flex-direction: column; gap: .3rem; }
.exercise h3 { margin: .2rem 0 0; }
.exercise p { margin: 0; flex: 1; }
.exercise-images { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem; }
.exercise-images img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.exercise-noimage { aspect-ratio: 8 / 3; display: flex; align-items: center; justify-content: center; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: .8rem; }
.exercise-today { padding: .45rem .6rem; border-left: 3px solid var(--accent, #2e86de); background: var(--surface-2); border-radius: 4px; line-height: 1.4; }
.exercise details summary { cursor: pointer; color: var(--accent, #2e86de); }
.exercise details p { margin: .35rem 0; }
.follow-list { list-style: none; padding: 0; margin: 0; counter-reset: follow; }
.follow-list li { padding: .55rem .6rem; border-bottom: 1px solid var(--border, #e5e7eb); }
.follow-exercise { counter-increment: follow; }
.follow-exercise .follow-head b::before { content: counter(follow) ". "; }
.follow-exercise.done { opacity: .55; }
.follow-head { display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; justify-content: space-between; }
.follow-watch { font-family: ui-monospace, monospace; font-size: .8rem; background: var(--surface-2); padding: .1rem .4rem; border-radius: 4px; white-space: nowrap; }
.follow-other { display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; color: var(--muted); font-size: .85rem; }
.follow-round { font-weight: 600; background: var(--surface-2); }
.follow-warmup { border-left: 3px solid #f6b93b; }
.follow-part-next { border-top: 0; padding-top: 0; margin-top: -.2rem; }
.follow-ticks { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .35rem; }
.follow-tick { display: inline-flex; align-items: center; gap: .3rem; padding: .3rem .6rem; border: 1px solid var(--border, #d1d5db); border-radius: 999px; font-size: .85rem; cursor: pointer; min-height: 2rem; }
.follow-tick.on { background: var(--accent, #2e86de); border-color: var(--accent, #2e86de); color: #fff; }
.follow-tick input { margin: 0; }
.exercise-compact { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .3rem; }

.zone-bars { display: flex; flex-direction: column; gap: .3rem; }
.zone-row { display: grid; grid-template-columns: 9.5rem 1fr 6.5rem; gap: .5rem; align-items: center; font-size: .82rem; }
.zone-track { background: var(--surface-2); border-radius: 4px; height: .8rem; overflow: hidden; }
.zone-track > span { display: block; height: 100%; border-radius: 4px; }
.zone-value { text-align: right; font-variant-numeric: tabular-nums; }
.week-bars { display: flex; align-items: flex-end; gap: .35rem; height: 140px; padding-top: .5rem; }
.week-bar { flex: 1; display: flex; flex-direction: column-reverse; min-width: 0; height: 100%; }
.week-bar > span { display: block; width: 100%; }
.week-bar-label { font-size: .7rem; color: var(--muted); text-align: center; }

.badge.suggested { background: #fef9c3; color: #713f12; border-color: #facc15; }
.session { border-top: 1px solid var(--border); padding: .75rem 0; }
.session:first-of-type { border-top: 0; }
details summary { cursor: pointer; }

@media (max-width: 1000px) {
    .week { grid-template-columns: 1fr; }
    .day { min-height: 0; }
    .day:not(:has(.wo)) { display: none; }
}

.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); flex-wrap: wrap; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .35rem; background: var(--c); }

.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }
.progress.met > div { background: var(--good); }

.prewrap { white-space: pre-wrap; line-height: 1.5; }

.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid #e50000; }
.validation-message { color: #e50000; font-size: .85rem; }

.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; }
.blazor-error-boundary::after { content: "An error has occurred." }

#blazor-error-ui {
    background: #fef3c7; color: #111; bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); display: none;
    left: 0; padding: 0.6rem 1.25rem 0.7rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

/* Garmin actions: loader while the watch is busy, and result notifications */
.garmin-busy { display: flex; gap: .75rem; align-items: center; padding: .65rem .8rem; margin-bottom: .6rem; border: 1px solid var(--accent); border-radius: 8px; background: var(--surface-2); }
.spinner { width: 1.4rem; height: 1.4rem; flex: none; border: 3px solid var(--surface); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.5s; } }
.toast { position: fixed; right: 1rem; bottom: 1rem; z-index: 1000; display: flex; gap: .6rem; align-items: flex-start; max-width: min(26rem, calc(100vw - 2rem));
    padding: .75rem .9rem; border-radius: 10px; background: var(--surface); color: var(--text); border: 1px solid var(--surface-2); border-left: 4px solid var(--good);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .18); animation: toast-in .2s ease-out; }
.toast.err { border-left-color: var(--bad); }
.toast-icon { flex: none; width: 1.5rem; height: 1.5rem; border-radius: 50%; display: grid; place-items: center; color: #fff; background: var(--good); font-weight: 700; font-size: .85rem; }
.toast.err .toast-icon { background: var(--bad); }
.toast .small { color: var(--muted); margin-top: .15rem; overflow-wrap: anywhere; }
.toast-close { margin-left: auto; background: none; border: 0; color: var(--muted); font-size: 1.2rem; line-height: 1; cursor: pointer; padding: 0 .2rem; }
@keyframes toast-in { from { transform: translateY(.5rem); opacity: 0; } }
/* Sign-in / setup pages */
.account-shell { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 3rem 1rem; }
.account-box { width: 100%; max-width: 30rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; }
.account-box .brand { font-weight: 700; margin-bottom: 1rem; }
.account-box h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }
.account-box .field input { width: 100%; }
.qr svg { width: 180px; height: 180px; background: #fff; border-radius: 6px; }
code.secret { font-size: 1rem; letter-spacing: .05em; word-break: break-all; }
.recovery-codes { columns: 2; padding-left: 1.2rem; }
