/* style.css — Workout Tracker (Hevy-style) */

:root {
    --bg: #08080a;
    --surface: #161618;
    --surface-2: #202023;
    --surface-hover: #2a2a2e;
    --row-alt: #141416;
    --border: #242428;
    --border-light: #34343a;

    --text: #f2f2f3;
    --text-2: #95959d;
    --text-3: #5f5f67;

    --blue: #2f7be0;
    --blue-press: #2666c2;
    --green: #43a047;
    --done-bg: #294b27;
    --done-bg-alt: #25461f;
    --red: #e0443c;
    --yellow: #ffc933;
    --gold: #f5b819;

    --radius: 12px;
    --radius-sm: 8px;
    --gap: 12px;
    --nav-h: 60px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textbox; appearance: textbox; }

html { overscroll-behavior-y: none; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.4;
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    overscroll-behavior-y: none;
}

/* Re-enable selection only where the user actually types. */
input, textarea { -webkit-user-select: text; user-select: text; }

.app {
    max-width: 640px;
    margin: 0 auto;
    min-height: 100vh;
    padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 32px);
}

/* ── Views ──────────────────────────────────────────────── */
.view { display: none; padding: 14px 14px 0; }
.view.active { display: block; }

.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding-top: env(safe-area-inset-top);
}
.view-header h1 { font-size: 27px; font-weight: 800; letter-spacing: -0.02em; }

.section-label {
    font-size: 17px; color: var(--text); font-weight: 800; letter-spacing: -0.01em;
    margin: 22px 2px 12px; display: flex; align-items: center; justify-content: space-between;
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
    background: var(--surface-2); border: none; color: var(--text);
    padding: 13px 16px; border-radius: var(--radius); font-size: 15px; font-weight: 700;
    cursor: pointer; font-family: inherit; transition: background .12s, transform .06s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:active { background: var(--blue-press); }
.btn-secondary { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-finish { background: var(--blue); color: #fff; font-weight: 700; padding: 9px 20px; border-radius: 20px; }
.btn-sm { padding: 8px 14px; font-size: 14px; }
.w-full { width: 100%; }
.big-btn { width: 100%; padding: 15px; font-size: 16px; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; gap: 8px; }

/* ── Stat strip ─────────────────────────────────────────── */
.stat-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.stat {
    background: var(--surface); border-radius: var(--radius);
    padding: 14px 8px; text-align: center;
}
.stat-val { display: block; font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-label { display: block; font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }

/* ── Cards / lists ──────────────────────────────────────── */
.card-list { display: flex; flex-direction: column; gap: 12px; }

.workout-card, .routine-card, .ex-card {
    background: var(--surface); border-radius: var(--radius);
    padding: 15px; cursor: pointer; transition: background .1s;
}
.workout-card:active, .ex-card:active { background: var(--surface-hover); }

.wc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.wc-title { font-size: 17px; font-weight: 800; letter-spacing: -0.01em; }
.wc-date { font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.wc-stats { display: flex; gap: 16px; margin: 8px 0 10px; font-size: 13px; color: var(--text-2); }
.wc-stats b { color: var(--text); font-weight: 700; }
.wc-ex-line { font-size: 14px; color: var(--text-2); display: flex; justify-content: space-between; padding: 4px 0; }
.wc-ex-line .best { color: var(--text-3); font-variant-numeric: tabular-nums; }
.wc-ex-list { margin-top: 2px; }
.wc-more { font-size: 13px; color: var(--text-3); margin-top: 4px; }

/* ── Routine card (Hevy-style) ──────────────────────────── */
.routine-card { padding: 16px; }
.routine-card .rc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.rc-title { font-size: 17px; font-weight: 800; letter-spacing: -0.01em; }
.rc-sub { font-size: 14px; color: var(--text-2); margin: 6px 0 14px; line-height: 1.5;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rc-start { width: 100%; }
.rc-menu { background: none; border: none; color: var(--text-2); cursor: pointer; font-size: 22px;
    line-height: 1; padding: 0 4px; flex-shrink: 0; }

/* ── Exercise catalog card ──────────────────────────────── */
.ex-card { display: flex; align-items: center; gap: 14px; padding: 10px 12px; }

/* Muscle-group identity tile — color-tinted square + minimal glyph, keyed off e.BodyPart. */
.grp-tile {
    flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 11px;
    color: var(--grp); background: color-mix(in srgb, var(--grp) 16%, transparent);
}
.grp-tile svg { width: 64%; height: 64%; }
.grp-tile.lg { width: 50px; height: 50px; border-radius: 14px; }
.grp-tile.sm { width: 34px; height: 34px; border-radius: 10px; }
.ex-info { min-width: 0; flex: 1; }
.ex-name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex-meta { font-size: 13px; color: var(--text-2); margin-top: 1px; }
.chip {
    display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 20px;
    background: var(--surface-2); color: var(--text-2);
}

/* ── Active workout ─────────────────────────────────────── */
.active-header {
    position: sticky; top: 0; z-index: 6; background: var(--bg); border-bottom: 1px solid var(--border);
    padding: calc(env(safe-area-inset-top) + 10px) 0 11px; margin: 0 0 14px;
    display: flex; align-items: center; gap: 12px;
}
.active-title { flex: 1; min-width: 0; background: transparent; border: none; color: var(--text); font-size: 20px; font-weight: 800; letter-spacing: -0.02em; padding: 2px 0; text-overflow: ellipsis; }
.active-title:focus { outline: none; }
.active-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 0 0 14px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }
.active-stat .l { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 1px; }
.active-stat .v { display: block; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.active-stat .v.timer { color: var(--blue); }

.ex-block { padding: 4px 0 8px; margin-bottom: 8px; }
.ex-block-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.ex-block-title { font-size: 17px; font-weight: 700; color: var(--blue); flex: 1; min-width: 0; cursor: pointer;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex-block-title:active { opacity: 0.6; }
.ex-block-del { color: var(--text-3); background: none; border: none; font-size: 22px; cursor: pointer; padding: 0 4px; }
.ex-block-title.plain { color: var(--blue); cursor: default; }

.set-grid { display: flex; flex-direction: column; gap: 2px; }
.set-grid.no-check .set-head, .set-grid.no-check .set-cells { grid-template-columns: 34px 98px 1fr 1fr; }
.set-head { display: grid; grid-template-columns: 34px 98px 1fr 1fr 42px; gap: 4px; align-items: center; padding: 2px 0 8px; }
.set-head > div { font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; text-align: center; }
.set-row { position: relative; border-radius: 8px; overflow: hidden; touch-action: pan-y; }
.set-del-reveal { position: absolute; inset: 0; background: var(--red); border-radius: 8px; display: flex; align-items: center; justify-content: flex-end; padding-right: 16px; font-size: 17px; z-index: 0; opacity: 0; }
.set-row.swiping .set-del-reveal { opacity: 1; }
.set-cells { position: relative; z-index: 1; background: var(--bg); display: grid; grid-template-columns: 34px 98px 1fr 1fr 42px; gap: 4px; align-items: center; padding: 4px 0; will-change: transform; }
.set-cells > div { text-align: center; }
.set-row.done .set-cells, .set-row.will-del .set-cells { background: var(--done-bg); }
.set-num { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; font-size: 15px; }
.set-num.warmup { color: var(--yellow); }
.set-medal { font-size: 17px; }
.prev-val { font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.set-row.done .prev-val { color: rgba(255,255,255,0.55); }
.set-input {
    width: 100%; background: var(--surface-2); border: none; border-radius: var(--radius-sm);
    color: var(--text); text-align: center; padding: 9px 2px; font-size: 16px; font-family: inherit;
    font-variant-numeric: tabular-nums; font-weight: 600;
    /* let horizontal gestures reach the swipe-to-delete handler instead of selecting text */
    touch-action: pan-y;
}
.set-input:focus { outline: 1.5px solid var(--blue); }
.set-row.done .set-input { background: rgba(0,0,0,0.18); }
/* Barbell plate breakdown (per side, 45 lb bar) under each set */
.plate-hint { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center;
    gap: 4px; padding: 0 2px; min-height: 0; }
.plate-hint:empty { display: none; }
.plate-label { font-size: 10px; font-weight: 700; letter-spacing: .04em;
    text-transform: uppercase; color: var(--text-3); margin-right: 1px; }
.plate-chip { font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
    color: var(--text-2); background: var(--surface-2); border-radius: 999px;
    padding: 1px 7px; line-height: 1.5; }
.plate-note { font-size: 11px; font-weight: 600; color: var(--text-3); }
.set-row.done .plate-chip { background: rgba(0,0,0,0.18); color: rgba(255,255,255,0.6); }
.set-check {
    width: 30px; height: 30px; border-radius: var(--radius-sm); border: none;
    background: var(--surface-2); color: var(--text-3); cursor: pointer; display: inline-flex;
    align-items: center; justify-content: center;
}
.set-check.done { background: var(--green); color: #fff; }
.set-check svg { width: 17px; height: 17px; }
.add-set-btn { width: 100%; margin-top: 10px; background: var(--surface-2); border: none; color: var(--text); padding: 10px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 700; cursor: pointer; }
.add-set-btn:active { background: var(--surface-hover); }
.add-ex-btn { margin-top: 6px; padding: 14px; background: var(--surface-2); color: var(--blue); }
.discard-btn { margin-top: 12px; padding: 14px; background: transparent; color: var(--red); }
.discard-btn:active { background: rgba(241,69,61,0.1); }

/* ── Exercise notes (active logger + detail) ────────────── */
.ex-note {
    background: transparent; border: none;
    color: var(--text); font-family: inherit; font-size: 15px; padding: 2px 2px; margin: 0 0 2px;
    width: 100%; resize: none; overflow: hidden; line-height: 1.5; display: block; min-height: 26px;
}
.ex-note::placeholder { color: var(--text-3); }
.ex-note:focus { outline: none; }
.ex-note.dim, .ex-note.dim::placeholder { color: var(--text-3); }
.ex-note.dim:focus { color: var(--text); }
.detail-note { margin: 4px 0 2px; width: 100%; font-size: 15px; }

/* ── Search ─────────────────────────────────────────────── */
.search-input {
    width: 100%; background: var(--surface); border: none; color: var(--text);
    padding: 13px 16px; border-radius: var(--radius); font-size: 15px; font-family: inherit; margin-bottom: 14px;
}
.search-input:focus { outline: 1.5px solid var(--blue); }

/* ── Bottom Nav ─────────────────────────────────────────── */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(16,16,18,0.94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border); display: flex; z-index: 50;
}
.nav-btn {
    flex: 1; background: none; border: none; color: var(--text-3); cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font-size: 11px; font-weight: 600; font-family: inherit;
}
.nav-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-btn.active { color: var(--blue); }

/* ── Full-screen sub-pages (exercise detail, routine editor) ── */
.fs-screen {
    position: fixed; inset: 0; background: var(--bg); z-index: 95; display: flex; flex-direction: column;
    transform: translateX(100%); transition: transform .24s cubic-bezier(.3,.7,.3,1); visibility: hidden;
}
.fs-screen.open { transform: translateX(0); visibility: visible; }
.fs-appbar {
    display: flex; align-items: center; gap: 6px; flex-shrink: 0; width: 100%; max-width: 640px; margin: 0 auto;
    padding: calc(env(safe-area-inset-top) + 12px) 12px 12px; border-bottom: 1px solid var(--border);
}
.fs-appbar h2 { flex: 1; min-width: 0; text-align: center; font-size: 17px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fs-spacer { width: 30px; flex-shrink: 0; }
.fs-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    width: 100%; max-width: 640px; margin: 0 auto;
    padding: 0 16px calc(40px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
.fs-body > :first-child { margin-top: 14px; }
/* This is a scrolling flex column: children must keep their natural size, never get
   compressed. Without this, an auto-grown note textarea is shrunk to its min-height. */
.fs-body > * { flex-shrink: 0; }
.btn-text { background: none; border: none; color: var(--text); font-family: inherit; font-size: 16px; font-weight: 600; cursor: pointer; padding: 4px 6px; }
.btn-text.accent { color: var(--blue); font-weight: 800; }
.routine-name-input {
    width: 100%; background: transparent; border: none; color: var(--text);
    font-family: inherit; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; padding: 4px 2px;
}
.routine-name-input:focus { outline: none; }

/* ── Modals (bottom sheets) ─────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop.hidden { display: none; }
.modal.sheet {
    background: var(--bg); border-top-left-radius: 18px; border-top-right-radius: 18px;
    width: 100%; max-width: 640px; max-height: 92vh; padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
    overflow-y: auto; animation: slideUp .24s cubic-bezier(.2,.8,.2,1); display: flex; flex-direction: column;
    -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-grabber { width: 38px; height: 4px; border-radius: 2px; background: var(--border-light); margin: 6px auto 8px; flex-shrink: 0; }
.modal-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 14px; position: sticky; top: 0; background: var(--bg); padding: 4px 0 6px; z-index: 2; }
.modal-header h2 { font-size: 18px; font-weight: 800; flex: 1; min-width: 0; }
.modal-header.centered h2 { text-align: center; }
.btn-close { background: none; border: none; color: var(--text); font-size: 26px; line-height: 1; cursor: pointer; padding: 0 6px; }
.btn-back { background: none; border: none; color: var(--text); cursor: pointer; padding: 2px 6px 2px 0; display: flex; }
.btn-back svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.modal-actions { margin-top: 16px; }

.picker-list { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }

/* ── Exercise detail ────────────────────────────────────── */
.detail-body { display: flex; flex-direction: column; gap: 14px; }
.detail-head { display: flex; align-items: center; gap: 13px; }
.detail-head-text { min-width: 0; }
.detail-title { font-size: 21px; font-weight: 800; letter-spacing: -0.01em; }
.detail-muscles { font-size: 14px; color: var(--text-2); margin-top: 2px; }
.detail-muscles b { color: var(--text); font-weight: 600; }
.yt-btn {
    display: flex; align-items: center; justify-content: center; gap: 9px; width: 100%;
    padding: 11px; background: var(--surface-2); color: var(--text); border: none;
    border-radius: var(--radius); font-size: 15px; font-weight: 700; cursor: pointer;
}
.yt-btn:active { opacity: 0.6; }
.yt-btn svg { width: 22px; height: 22px; }
#detail-prs { display: flex; flex-direction: column; gap: 12px; }
.detail-prs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.detail-prs.three { grid-template-columns: 1fr 1fr 1fr; }
.detail-note { margin: 2px 0 4px; }
.pr-box { background: var(--surface); border-radius: var(--radius); padding: 13px; text-align: center; }
.pr-val { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pr-label { font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; margin-top: 3px; }
.pr-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.detail-section-label { font-size: 13px; font-weight: 800; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; }
.pr-header { display: flex; align-items: center; gap: 7px; font-size: 16px; font-weight: 800; }

/* progress chart */
.chart-head { display: flex; align-items: baseline; justify-content: space-between; }
.chart-metric { font-size: 14px; color: var(--text-2); font-weight: 600; }
.chart-latest { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.chart-latest small { font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.chart-wrap { background: var(--surface); border-radius: var(--radius); padding: 10px 10px 6px; margin-top: 8px; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-wrap .grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-wrap .ylab { fill: var(--text-3); font-size: 9px; font-family: inherit; text-anchor: end; dominant-baseline: middle; }
.chart-wrap .xlab { fill: var(--text-3); font-size: 9px; font-family: inherit; }
.chart-wrap .xlab.end { text-anchor: end; }
.chart-empty { color: var(--text-3); font-size: 14px; text-align: center; padding: 30px 0; }

/* ── Underline tab bar ──────────────────────────────────── */
.tab-bar { display: flex; gap: 22px; border-bottom: 1px solid var(--border); margin-bottom: 2px; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.tab-btn {
    background: none; border: none; color: var(--text-2); font-family: inherit; font-size: 15px;
    font-weight: 700; padding: 10px 0; cursor: pointer; position: relative; border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab-panel { display: flex; flex-direction: column; gap: 14px; padding-top: 14px; }
.tab-panel.hidden { display: none; }
.pr-val .u { font-size: 13px; }

/* ── Routine editor ─────────────────────────────────────── */
.routine-edit-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.re-ex { background: var(--surface); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.re-ex-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.re-ex-name { font-size: 16px; font-weight: 700; color: var(--blue); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.re-sets { display: flex; flex-direction: column; gap: 6px; }
.re-set { display: flex; align-items: center; gap: 10px; }
.re-setn { width: 22px; text-align: center; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.re-rep { width: 64px; background: var(--surface-2); border: none; border-radius: var(--radius-sm); color: var(--text); text-align: center; padding: 8px 4px; font-size: 15px; font-family: inherit; font-weight: 600; }
.re-rep:focus { outline: 1.5px solid var(--blue); }
.re-rep-label { font-size: 13px; color: var(--text-2); }
.re-set-del { margin-left: auto; background: none; border: none; color: var(--text-3); font-size: 20px; cursor: pointer; padding: 0 6px; }

/* ── Reorder / tool buttons ─────────────────────────────── */
.ex-block-tools { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.ex-move {
    background: none; border: none; color: var(--text-3); cursor: pointer; font-size: 12px;
    padding: 5px 6px; line-height: 1; border-radius: 4px;
}
.ex-move:active { background: var(--surface-2); color: var(--text); }
/* Per-exercise rest length; tapping opens the rest-length picker sheet. */
.rest-chip {
    background: var(--surface-2); border: none; color: var(--text-2); font-family: inherit;
    font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
    height: 32px; padding: 0 10px; margin-right: 4px; border-radius: 999px; cursor: pointer;
    white-space: nowrap; flex-shrink: 0;
}
.rest-chip:active { background: var(--surface-hover); color: var(--text); }

/* ── Rest length picker sheet ─────────────────────────── */
.rest-pick-row { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 4px 0 14px; }
.rest-pick-current { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 96px; text-align: center; }
.rest-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.rest-presets button {
    background: var(--surface-2); border: 1px solid transparent; color: var(--text); font-family: inherit;
    font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; height: 42px; border-radius: 10px; cursor: pointer;
}
.rest-presets button.on { border-color: var(--blue); color: var(--blue); }
#rest-custom { margin-bottom: 12px; }

/* ── Rest timer bar (fixed just above the bottom nav) ───── */
.rest-bar {
    position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
    z-index: 55; background: var(--surface); border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px; padding: 8px 14px;
}
.rest-bar.hidden { display: none; }
.rest-track { position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--surface-2); overflow: hidden; }
.rest-fill { display: block; height: 100%; width: 100%; background: var(--blue);
    transform-origin: left center; transform: scaleX(1); }
.rest-text { flex: 1; min-width: 0; }
.rest-label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .05em; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rest-time { display: block; font-size: 24px; font-weight: 800; line-height: 1.15;
    letter-spacing: -0.02em; color: var(--blue); font-variant-numeric: tabular-nums; }
.rest-actions { display: flex; gap: 6px; flex-shrink: 0; }
.rest-btn {
    background: var(--surface-2); border: none; color: var(--text); font-family: inherit;
    font-size: 13px; font-weight: 700; min-width: 46px; height: 40px; padding: 0 10px;
    border-radius: var(--radius); cursor: pointer; font-variant-numeric: tabular-nums;
}
.rest-btn:active { background: var(--surface-hover); }
.rest-btn.skip { color: var(--text-2); }
.rest-bar.go { background: var(--done-bg); border-color: var(--green); }
.rest-bar.go .rest-time { color: #fff; }
.rest-bar.go .rest-label { color: rgba(255,255,255,0.7); }
.rest-bar.go .rest-fill { background: var(--green); }
/* Keep the last button clear of the bar while it's up. */
.app.rest-open { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 92px); }

/* ── Danger buttons ─────────────────────────────────────── */
.danger-btn { background: transparent; color: var(--red); margin-top: 8px; }
.danger-btn:active { background: rgba(241,69,61,0.12); }

/* ── Labeled facts ──────────────────────────────────────── */

/* ── Per-session history ────────────────────────────────── */
.hist-session { border-top: 1px solid var(--border); padding-top: 14px; }
.hist-session:first-child { border-top: none; padding-top: 0; }
.hist-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.hist-date { font-weight: 800; font-size: 15px; }
.hist-workout { font-size: 13px; color: var(--text-3); }

/* ── Workout detail modal ───────────────────────────────── */
.ws-ex { border-top: 1px solid var(--border); padding: 14px 0; }
.ws-ex:first-child { border-top: none; }
.ws-ex-head { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--blue); font-size: 16px; margin-bottom: 8px; cursor: pointer; }
.ws-ex-head:active { opacity: 0.6; }
.ws-note { font-size: 13px; color: var(--text-2); background: var(--surface); border-radius: var(--radius-sm); padding: 8px 10px; margin-bottom: 8px; line-height: 1.5; }
.ws-sets { display: flex; flex-direction: column; gap: 3px; }
.ws-set { display: flex; align-items: center; gap: 12px; font-size: 14px; padding: 3px 0; }
.ws-setn { width: 24px; text-align: center; font-weight: 700; color: var(--text-3); font-variant-numeric: tabular-nums; }
.ws-val { color: var(--text); font-variant-numeric: tabular-nums; }
.ws-rpe { color: var(--text-3); font-size: 12px; }
.set-type-tag { display: inline-block; width: 20px; height: 20px; line-height: 20px; border-radius: 5px; font-size: 11px; font-weight: 700; text-align: center; }
.set-type-tag.warmup { background: rgba(255,201,51,0.2); color: var(--yellow); }
.set-type-tag.dropset { background: rgba(176,126,216,0.2); color: #b07ed8; }
.set-type-tag.failure { background: rgba(241,69,61,0.2); color: var(--red); }

/* ── Misc ───────────────────────────────────────────────── */
.empty { text-align: center; color: var(--text-3); padding: 40px 20px; font-size: 15px; }
.error-msg { color: var(--red); font-size: 14px; margin-top: 8px; text-align: center; }
.skeleton-card { height: 100px; background: var(--surface); border-radius: var(--radius); opacity: .5; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .35; } 50% { opacity: .6; } }

.toast {
    position: fixed; bottom: calc(var(--nav-h) + 24px); left: 50%; transform: translateX(-50%) translateY(20px);
    background: #fff; color: #111;
    padding: 11px 20px; border-radius: 24px; font-size: 14px; font-weight: 700; z-index: 200;
    opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; white-space: nowrap;
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Shown while the backend is cold-starting or after it failed to answer. */
.boot-status { text-align: center; color: var(--text-3); font-size: 13px; padding: 6px 0 10px; }
.boot-status.retry { color: var(--blue); cursor: pointer; }

/* ── Login ──────────────────────────────────────────────── */
.login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-box { text-align: center; width: 300px; }
.login-box img { margin-bottom: 14px; }
.login-box h1 { font-size: 24px; font-weight: 800; margin-bottom: 4px; }
.login-box p { font-size: 15px; color: var(--text-3); margin-bottom: 18px; }
.login-box form { display: flex; gap: 8px; }
.login-box input { flex: 1; background: var(--surface); border: none; color: var(--text); padding: 12px 14px; border-radius: var(--radius); font-family: inherit; font-size: 15px; }
.login-box input:focus { outline: 1.5px solid var(--blue); }

@media (min-width: 660px) {
    .modal.sheet { margin-bottom: 0; align-self: center; border-radius: 18px; max-height: 88vh; }
    .modal-backdrop { align-items: center; }
    .bottom-nav { max-width: 640px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
    .rest-bar { max-width: 640px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

/* ── Log Run form ─────────────────────────────────────────── */
.run-form { display: flex; flex-direction: column; gap: 4px; padding-bottom: 8px; }
.run-form label { display: block; font-size: 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; }
.run-form label .search-input { margin: 6px 0 10px; }
.run-form textarea.search-input { resize: none; }
.run-form select.search-input { appearance: none; -webkit-appearance: none; }
.run-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.run-pace { font-size: 14px; color: var(--text-2); margin: 2px 0 12px; font-variant-numeric: tabular-nums; }
.run-pace b { color: var(--text); }
.wc-title .run-badge { font-size: 12px; margin-left: 6px; }
