/* Fitness Planner styles.
   WCAG 2.2 AA contrast in both themes, focus ring >= 2px at >= 3:1 (except buttons, feature 030), targets >= 44 x 44 CSS px,
   one column below 768px, two columns from 768px, no horizontal scroll at 320px.
   Feature 004: refreshed style (research R11), dark theme from the device setting (R10), and a
   bottom tab bar below 768px (R9). Every color is a token; each holds its light and dark value in light-dark() (feature 006). */

:root {
    /* Feature 012 (research R7): calmer dark values. Softer text, one desaturated blue accent, muted
       status colors; every pair below still meets WCAG 2.2 AA (checked by ThemeTokensTests). Light
       values are unchanged. */
    --bg: light-dark(#f6f7f9, #121417);
    --surface: light-dark(#ffffff, #1a1d22);
    --text: light-dark(#1a1d23, #dcdfe4); /* light: 16.1:1 on white; dark: 12.7:1 on surface, 13.8:1 on bg */
    --text-muted: light-dark(#4b5563, #a3abb5); /* light: 7.6:1 on white; dark: 7.3:1 on surface */
    --border: light-dark(#8a94a3, #737b87); /* light: 3.2:1 on white, for control borders; dark: 3.9:1 on surface, control borders */
    --border-soft: light-dark(#d7dce3, #2a2f36);
    --primary: light-dark(#1d4ed8, #9db8e8); /* light: 6.7:1 on white; dark: 8.4:1 on surface, 6.9:1 on primary-soft */
    --primary-text: light-dark(#ffffff, #121417); /* light: decorative; dark: 9.2:1 on primary */
    --primary-soft: light-dark(#e6edfd, #232d3e); /* light: decorative; dark: text on it 10.4:1 */
    --primary-strong: light-dark(#1e40af, #b8cbef); /* light: hover on primary, 8.7:1 with white; dark: decorative */
    --done: light-dark(#166534, #7cc49a); /* light: 7.1:1 on white; dark: 8.2:1 on surface */
    --logo-main: light-dark(#1d4ed8, #9db8e8); /* light: 6.7:1 on white; dark: 8.4:1 on surface (feature 026) */
    --logo-accent: light-dark(#166534, #7cc49a); /* light: 7.1:1 on white; dark: 8.2:1 on surface (feature 026) */
    --done-soft: light-dark(#e7f5ec, #1b2e23); /* light: decorative; dark: text on it 10.8:1 */
    --danger: light-dark(#b91c1c, #e8988f); /* light: 6.5:1 on white; dark: 7.5:1 on surface */
    --warning-bg: light-dark(#fff4d6, #332b1a);
    --warning-text: light-dark(#6b4500, #e6c98a); /* light: decorative; dark: 8.7:1 on warning-bg */
    --focus: light-dark(#b45309, #e0a85a); /* light: 4.9:1 on white and on primary-soft; dark: 8.0:1 on surface; 6.5:1 on primary-soft */
    /* Results chart (feature 003 FR-025): each >= 3:1 against white; patterns also tell them apart. */
    --cat-upper: light-dark(#1d4ed8, #9db8e8); /* light: 6.7:1; dark: 8.4:1 */
    --cat-lower: light-dark(#166534, #7cc49a); /* light: 7.1:1; dark: 8.2:1; 6.3:1 on its soft fill */
    --cat-lower-soft: light-dark(#c9ead4, #1f3628);
    --cat-stretch: light-dark(#9a3412, #e0a37f); /* light: 7.0:1; dark: 7.8:1; 6.6:1 on its soft fill */
    --cat-stretch-soft: light-dark(#fde0cc, #38271d);
    --gym: light-dark(#9a3412, #e0a37f); /* feature 023 gym-day icon: light 7.3:1 on white (surface), 6.8:1 on bg; dark 7.8:1 on surface, 8.5:1 on bg */
    --chart-axis: light-dark(#4b5563, #a3abb5); /* light: 7.6:1; dark: 7.3:1 */
    --chart-grid: light-dark(#d7dce3, #323842);
    --chart-outline: light-dark(#4b5563, #a3abb5); /* light: 7.6:1, pool outline; dark: decorative, 7.3:1 */
    --primary-strong-text: light-dark(#ffffff, #121417); /* light: decorative; dark: 11.3:1 */
    --danger-strong: light-dark(#991b1b, #f0b4ad); /* light: hover on danger, 8.3:1 with white; dark: decorative */
    --on-danger: light-dark(#ffffff, #121417); /* light: 6.5:1 on danger; dark: 8.2:1 on danger */
    --done-border: light-dark(#9ccfb0, #4d8d67); /* light: decorative edge of done rows; dark: 4.3:1 on surface */
    --overlay: light-dark(rgba(17, 24, 39, 0.55), rgba(0, 0, 0, 0.7));
    --card-border: light-dark(#e3e7ed, #2a2f36); /* light: decorative; cards are also set apart by their shadow; dark: shadows hardly show on dark backgrounds */
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
    --nav-bg: light-dark(#ffffff, #16191d); /* light: decorative; dark: nav text 13.2:1, active 6.9:1 on primary-soft */
    /* Feature 014 FR-012 (research R8): translucent nav. 86 % of --nav-bg over the worst page content
       (pure black in light, pure white in dark): light --text 12.2:1, --primary 4.9:1; dark --text 8.7:1,
       --primary 5.8:1. The active link keeps its opaque --primary-soft background. */
    --nav-glass: light-dark(rgb(255 255 255 / 0.86), rgb(22 25 29 / 0.86)); /* worst case: light text 12.2:1, primary 4.9:1; dark text 8.7:1, primary 5.8:1 */
    --nav-glass-border: light-dark(rgb(0 0 0 / 0.08), rgb(255 255 255 / 0.10)); /* decorative */
    /* Muscle map (features 005, 009): outlines and fills each meet 3:1; states also differ by dash, width, and hatch. */
    --body-fill: light-dark(#eef1f5, #23272e);
    --body-outline: light-dark(#8a94a3, #4a515c); /* light: 2.7:1 on body fill, decorative; dark: 1.9:1, decorative */
    --muscle-fill: light-dark(#5f83ec, #5a78b0); /* light: 3.1:1 on body fill, 3.5:1 on surface; dark: 3.4:1 on body fill, 3.8:1 on surface (feature 009 FR-010) */
    --muscle-stroke: light-dark(#1d4ed8, #9db8e8); /* light: 5.9:1 on body fill; dark: 7.5:1 on body fill */
    --muscle-selected-fill: light-dark(#1d4ed8, #9db8e8); /* light: 5.9:1 on body fill, 6.7:1 on white; dark: 7.5:1 on body fill; hatch in --surface on it: 6.7:1 / 8.4:1 */
    --muscle-selected-stroke: light-dark(#1a1d23, #dcdfe4);
    --muscle-empty-stroke: light-dark(#6b7480, #8a94a3); /* light: 4.2:1 on body fill, dashed; dark: 4.9:1 on body fill, dashed */
    --radius: 12px;
    --radius-card: 16px;
    --target: 44px;
    --nav-height: 64px;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    color-scheme: light dark;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 100%;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

/* Feature 006 (research R6): the owner's saved theme choice sets data-theme on <html>; without it
   the device setting decides. Colors above use light-dark(), which follows color-scheme. */
:root[data-theme="light"] {
    color-scheme: light;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.5); /* not a color, so light-dark() cannot hold it */
    }
}

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

/* Feature 015 FR-015 (research R1): "clip", not "hidden". In WebKit (iPhone Safari) overflow-x: hidden on
   html and body made the sticky top bar scroll away with the page (it vanished on Notes after an action).
   "clip" still prevents sideways scrolling but does not create a scroll container. */
html, body {
    margin: 0;
    overflow-x: hidden;
    overflow-x: clip;
}

body {
    min-width: 0;
}

h1, h2, h3 {
    line-height: 1.25;
    margin: 0 0 var(--space-3);
    letter-spacing: -0.01em;
}

h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.3rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; margin-top: 1.25rem; }

body {
    background: var(--bg);
    color: var(--text);
}

p { margin: 0 0 0.75rem; }

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

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

/* Text and date fields always show focus; Chromium puts date-field focus on inner parts, where
   :focus-visible does not reach the input itself. */
input:focus,
input:focus-within,
.date-jump-field:focus-within input {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

[tabindex="-1"]:focus {
    outline: none;
}

[tabindex="-1"]:focus-visible {
    outline: 3px solid var(--focus);
}

/* Feature 014 FR-011 (research R5): headings are focus targets for page and day changes, not controls.
   Chromium matches :focus-visible on the programmatic focus at first load, which drew an orange ring
   around the planner title. Controls keep the ring above. */
:is(h1, h2, h3)[tabindex="-1"]:focus,
:is(h1, h2, h3)[tabindex="-1"]:focus-visible {
    outline: none;
}

/* Feature 030 FR-021 (research R12, Constitution VII exemption): buttons show no focus outline, after a
   tap, a click, or keyboard focus. Fields, checkboxes, switches, dropdowns, links, the muscle map, and
   chart points keep theirs. The [tabindex] form also covers roving-focus buttons such as calendar days. */
button:focus,
button:focus-visible,
button[tabindex]:focus,
button[tabindex]:focus-visible {
    outline: none;
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: 1rem;
    top: -4rem;
    background: var(--surface);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    z-index: 100;
}

.skip-link:focus {
    top: 0.5rem;
}

/* Layout */

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-1) var(--space-4);
    padding: var(--space-1) var(--space-4);
    background: var(--nav-bg);
    border-bottom: 1px solid var(--card-border);
}

.brand {
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    min-height: var(--target);
    display: inline-flex;
    align-items: center;
    gap: var(--space-2); /* feature 026: the logo symbol sits before the name */
}

/* Feature 026 FR-014: the logo symbol in the top bar; decorative, follows the theme. */
.app-logo {
    width: 1.5rem;
    height: 1.5rem;
    flex: none;
}

@media (forced-colors: active) {
    .app-logo rect {
        fill: CanvasText;
    }
}

/* Feature 006: the nav sits at the right of the top bar (feature 020: the theme toggle moved to Settings). */
.main-nav {
    margin-left: auto;
}

.nav-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-links a {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--target);
    padding: 0 var(--space-3);
    border-radius: 999px;
    color: var(--text);
    text-decoration: none;
    transition: background-color 150ms, color 150ms;
}

.nav-links a:hover {
    background: var(--primary-soft);
}

/* Feature 010 "More" disclosure (research R12). Same look as a nav link. */
.nav-more {
    position: relative;
}

.nav-more-button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--target);
    min-width: var(--target);
    padding: 0 var(--space-3);
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.nav-more-button:hover,
.nav-more-button[aria-expanded="true"] {
    background: var(--primary-soft);
}

.nav-more-button.active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 700;
}

.nav-more-button.active .nav-label {
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

.nav-more-backdrop {
    position: fixed;
    inset: 0;
    z-index: 35;
}

.nav-more-list {
    position: absolute;
    right: 0;
    top: calc(100% + var(--space-2));
    z-index: 36;
    display: grid;
    gap: 2px;
    min-width: 12rem;
    margin: 0;
    padding: var(--space-2);
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.nav-more-list[hidden] {
    display: none;
}

.nav-more-list a {
    display: flex;
    width: 100%;
    border-radius: var(--radius);
}

/* Current page: tinted pill, bold, and underlined label, so it is not shown by color alone. */
.nav-links a.active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 700;
}

.nav-links a.active .nav-label {
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

.nav-icon {
    flex: none;
}

/* Below 768px the same navigation becomes a tab bar fixed to the bottom (FR-038, FR-039). */
@media (max-width: 767px) {
    .main-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 30;
        background: var(--nav-bg);
        border-top: 1px solid var(--card-border);
        box-shadow: var(--shadow);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .main-nav .nav-links {
        display: grid;
        /* Feature 010: primary links plus More (research R12). Feature 021: five items (Results merged
           into Body Map), 64 px each at 320 px, so every target stays at least 44 px wide. */
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 0;
    }

    .main-nav .nav-links li {
        display: flex;
        min-width: 0;
    }

    .main-nav .nav-links a,
    .main-nav .nav-more-button {
        flex: 1 1 auto;
        min-width: var(--target);
        flex-direction: column;
        justify-content: center;
        gap: 2px;
        min-height: var(--nav-height);
        padding: var(--space-1) 2px;
        border-radius: 0;
        font-size: 0.75rem;
        line-height: 1.15;
        text-align: center;
        overflow-wrap: anywhere;
    }

    .main-nav .nav-links a.active,
    .main-nav .nav-more-button.active {
        box-shadow: inset 0 3px 0 var(--primary);
    }

    .main-nav .nav-more {
        display: flex;
        flex: 1 1 auto;
    }

    .main-nav .nav-more-button {
        width: 100%;
    }

    /* The More list opens upwards from the bottom tab bar. */
    .nav-more-list {
        top: auto;
        bottom: calc(100% + var(--space-2));
    }

    .main-nav .nav-more-list a {
        flex-direction: row;
        justify-content: flex-start;
        min-height: var(--target);
        padding: 0 var(--space-3);
        font-size: 1rem;
        text-align: left;
    }

    main {
        padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + var(--space-4)) !important;
    }

    .saving {
        bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + var(--space-3)) !important;
    }

    #blazor-error-ui {
        bottom: calc(var(--nav-height) + env(safe-area-inset-bottom)) !important;
    }
}

main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1rem;
}

.planner-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
}

.planner-side, .planner-main {
    display: grid;
    gap: 1rem;
    align-content: start;
    min-width: 0;
}

@media (min-width: 768px) {
    .planner-layout {
        grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    }

}

.card {
    background: var(--surface);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow);
    padding: var(--space-4);
    min-width: 0;
}

@media (min-width: 768px) {
    .card {
        padding: var(--space-5);
    }
}

.section-head, .day-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.section-head h2, .day-head h2 {
    margin: 0;
}

.section-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.day-picker[hidden] {
    display: none;
}

/* Controls */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: var(--target);
    min-width: var(--target);
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}

.btn {
    transition: background-color 150ms, border-color 150ms, color 150ms;
    font-weight: 600;
}

.btn:hover {
    background: var(--primary-soft);
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-text);
}

.btn-primary:hover {
    background: var(--primary-strong);
    border-color: var(--primary-strong);
    color: var(--primary-strong-text);
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: var(--on-danger);
}

.btn-danger:hover {
    background: var(--danger-strong);
    border-color: var(--danger-strong);
}

.btn-small {
    padding: 0.25rem 0.75rem;
}

.field {
    display: grid;
    gap: 0.25rem;
    min-width: 0;
}

label {
    font-weight: 600;
}

input[type="text"], input[type="date"], input[type="password"], input[type="time"] {
    min-height: var(--target);
    width: 100%;
    max-width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    background: var(--surface);
    color: var(--text);
}

/* Feature 007: shared search field (contracts/ui-contract.md SearchBox). */
input[type="search"] {
    min-height: var(--target);
    width: 100%;
    max-width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    background: var(--surface);
    color: var(--text);
}

/* The native cancel button is smaller than 44 px; the app's own "Clear search" button is used. */
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
}

.search-box {
    margin: 0 0 0.75rem;
}

.search-box label {
    display: block;
    margin-bottom: 0.25rem;
}

.search-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: stretch;
}

.search-row input[type="search"] {
    flex: 1 1 12rem;
    min-width: 0;
}

.search-clear {
    min-height: var(--target);
    flex: 0 0 auto;
}

.search-shown {
    margin: 0 0 0.5rem;
    font-size: 0.9rem;
}

/* Feature 007: Planner view switch, same look as the section switch. */
/* Feature 025 FR-011: one filter row (All exercises, Remaining, Done); replaces .view-switch and .section-switch. */
.planner-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.5rem 0 1rem;
}

.planner-filter .section-button {
    min-height: var(--target);
}

/* Feature 007/008: note above the All exercises rows (rows reuse .rows). */
.all-note {
    margin: 0 0 0.75rem;
}

input[aria-invalid="true"] {
    border: 2px solid var(--danger);
}

.field-error {
    color: var(--danger);
    font-weight: 600;
    margin: 0.25rem 0 0;
    grid-column: 1 / -1;
}

.add-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.75rem;
    align-items: end;
}

@media (min-width: 480px) {
    .add-form {
        grid-template-columns: minmax(0, 1fr) auto;
    }
}

.date-jump {
    display: grid;
    gap: 0.5rem;
    margin-top: 1rem;
}

.date-jump-field {
    display: grid;
    gap: 0.25rem;
    font-weight: 600;
}

/* Feature 014 FR-009 (research R7): iOS Safari ignores max-width on a native date input, which pushed
   the right border past the card. A block box with border-box sizing keeps all four sides inside. */
.date-jump-field input {
    display: block;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: var(--target);
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    -webkit-appearance: none;
    appearance: none;
}

.date-jump-field:focus-within input {
    outline-offset: 0;
}

.date-jump-steps {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.progress {
    display: grid;
    gap: 0.25rem;
    margin: 0;
    font-weight: 600;
}

.progress progress {
    width: 12rem;
    max-width: 100%;
    height: 0.6rem;
    accent-color: var(--done);
}

/* Calendar */

.calendar-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.calendar-month {
    font-weight: 700;
}

.calendar-grid {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.calendar-grid th {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0.25rem 0;
}

.calendar-grid td {
    padding: 1px;
    text-align: center;
}

.cell {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-width: var(--target);
    min-height: 3.25rem;
    padding: 0.15rem 0;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

@media (max-width: 400px) {
    main { padding-left: 0.5rem; padding-right: 0.5rem; }
    .card { padding: 0.75rem; }
    .calendar-grid td { padding: 0; }
    .cell { min-width: 0; min-height: var(--target); border-radius: 4px; }
}

.cell.is-open {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-text);
    font-weight: 700;
}

.cell.is-today {
    border: 2px solid var(--text);
    /* Feature 028 FR-014: today is bold as well as outlined. */
    font-weight: 800;
}

/* Set dot and mark count are drawn with CSS so the visible text of a cell stays its day
   number, which is part of its accessible name (WCAG 2.5.3). The name states both. */
.cell[data-sets]::before {
    content: "●";
    position: absolute;
    top: 1px;
    left: 4px;
    font-size: 0.7rem;
}

.cell[data-count]::after {
    content: attr(data-count);
    position: absolute;
    top: 1px;
    right: 3px;
    font-size: 0.7rem;
    font-weight: 700;
}

.calendar-legend {
    margin: 0.5rem 0 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Feature 023 (research R5, contracts/ui-contract.md): gym days. The dumbbell is an icon, not color only;
   each cell's name says "gym day". Feature 028 (research R7): Plan gym days mode was removed; a double-click
   or G toggles a gym day. touch-action stops iOS from zooming on a double-tap, so both taps arrive. */
.cell-icons {
    display: flex;
    gap: 2px;
    line-height: 0;
    margin-top: 1px;
}

.cell.is-gym .cell-gym {
    color: var(--gym);
}

.cell.is-open .cell-gym {
    color: currentColor;
}

.calendar-grid .cell {
    touch-action: manipulation;
}

/* Feature 028 FR-020 (research R8): the first-open note. Text on --primary-soft: 14.4:1 (light), 10.4:1 (dark). */
.calendar-note {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    background: var(--primary-soft);
}

.calendar-note p {
    flex: 1 1 14rem;
    margin: 0;
}

.calendar-note .btn {
    min-height: var(--target);
    min-width: var(--target);
}

.plain-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.radio input[type="radio"] {
    width: 1.5rem;
    height: 1.5rem;
    margin: 0;
    flex: none;
    accent-color: var(--primary);
}

.radio label {
    font-weight: 400;
    flex: 1;
    min-height: var(--target);
    display: flex;
    align-items: center;
}

.plain-list {
    list-style: disc;
    padding-left: 1.5rem;
    margin-bottom: 0.75rem;
}

.btn-day {
    width: 100%;
    justify-content: space-between;
    text-align: left;
}

.btn-day.is-open {
    border: 2px solid var(--primary);
    background: var(--primary-soft);
    font-weight: 700;
}

.day-count {
    font-size: 0.85rem;
    color: var(--done);
    font-weight: 700;
}

/* Day view */

/* Section switch (feature 004 FR-006): pill toggle buttons; the selected one is filled, bold, and
   shows a check mark, so the state is not shown by color alone. */
.section-button {
    border-radius: 999px;
    flex: 1 1 auto;
    /* The pressed state changes at once; a fading color would be unreadable for a moment. */
    transition: none;
}

.section-button[aria-pressed="true"] {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-text);
    font-weight: 700;
}

.section-button[aria-pressed="true"]:hover {
    background: var(--primary-strong);
    border-color: var(--primary-strong);
    color: var(--primary-strong-text);
}

.section-check:empty {
    display: none;
}

.tag {
    display: inline-block;
    margin-left: 0.5rem;
    padding: 0.1rem 0.5rem;
    border: 1px solid var(--text);
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    vertical-align: middle;
}

.rows {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.4rem;
}

.row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    background: var(--surface);
    min-width: 0;
}

.row {
    flex-wrap: wrap;
}

.row-details {
    flex: 1 0 100%;
    min-width: 0;
    display: grid;
    gap: 0.4rem;
    padding: 0 0 0.25rem;
}

.sets-summary {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-muted);
    overflow-wrap: anywhere;
}

/* Set lines (feature 004 FR-014, FR-016): the best set has a tinted background, a border, and a
   "Best" badge, so it is not marked by color alone. */
.set-lines {
    list-style: none;
    margin: 0.25rem 0 0;
    padding: 0;
    display: grid;
    gap: 0.2rem;
    font-variant-numeric: tabular-nums;
}

.set-lines li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.5rem;
    padding: 0.15rem 0.5rem;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text);
}

.set-lines li.is-best {
    background: var(--done-soft);
    border-color: var(--done);
    font-weight: 600;
}

.badge-best {
    display: inline-flex;
    align-items: center;
    padding: 0 0.5rem;
    border-radius: 999px;
    background: var(--done);
    color: var(--surface);
    font-size: 0.8rem;
    font-weight: 700;
}

.best-so-far {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--done);
    overflow-wrap: anywhere;
}

.tag-history {
    margin: 0 0.4rem 0 0;
}

/* Feature 014 FR-008: Add note and Edit sets on one row after the exercise name; they wrap when narrow. */
.details-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1);
}

.category-heading {
    margin: 1rem 0 0.4rem;
    font-size: 0.95rem;
    text-transform: none;
    color: var(--text);
}

/* Feature 028 FR-022 to FR-025 (research R9): category sections. The header is a 44 px disclosure button with
   the name, the count (--text-muted, 7.6:1 light, 7.3:1 dark on --surface), and a chevron that turns when open. */
.category-section-heading {
    margin: var(--space-2) 0 0;
    border-bottom: 1px solid var(--border-soft);
}

.category-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    min-height: var(--target);
    padding: var(--space-1) 0;
    border: 0;
    background: none;
    color: var(--text);
    font: inherit;
    font-weight: 700;
    text-align: start;
    cursor: pointer;
}

.category-count {
    color: var(--text-muted);
    font-weight: 400;
}

.category-toggle .chevron {
    width: 0.55rem;
    height: 0.55rem;
    margin-left: auto;
    margin-right: var(--space-1);
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.15s ease;
}

.category-toggle[aria-expanded="true"] .chevron {
    transform: rotate(-135deg);
}

@media (prefers-reduced-motion: reduce) {
    .category-toggle .chevron {
        transition: none;
    }
}

.category-body {
    padding-top: var(--space-2);
}

.category-done {
    margin: 0 0 0.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.category-select, .add-form select {
    min-height: var(--target);
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    max-width: 100%;
}

.round-complete {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    border: 2px solid var(--done);
    border-radius: var(--radius);
    background: var(--done-soft);
}

.round-complete p {
    margin: 0;
    font-weight: 700;
}

.round-note {
    padding: 0.5rem 0.75rem;
    border-left: 4px solid var(--border);
    background: var(--bg);
}

.set-panel {
    display: grid;
    gap: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    background: var(--bg);
    min-width: 0;
}

.set-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 0.5rem;
}

.set-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    min-width: 0;
}

.set-line {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.set-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.set-fields {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.4rem;
    align-items: end;
    width: 100%;
}

.set-note-field {
    display: grid;
    gap: 0.25rem;
    grid-column: 1 / -1;
}

.set-note {
    flex-basis: 100%;
    color: var(--text-muted);
    font-style: italic;
    overflow-wrap: anywhere;
}

/* In the editable set list the note sits below the set line and its buttons. */
.set-item .set-note {
    order: 1;
}

.set-fields input {
    min-height: var(--target);
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    width: 100%;
    min-width: 0;
}

@media (min-width: 480px) {
    .set-fields {
        grid-template-columns: auto minmax(4rem, 6rem) auto minmax(4rem, 7rem) auto;
        align-items: center;
    }
}

.row-done {
    background: var(--done-soft);
    border-color: var(--done-border);
}

.row-readonly {
    min-height: var(--target);
}

.row-text {
    display: flex;
    flex-wrap: wrap;
    gap: 0 0.5rem;
    min-width: 0;
    overflow-wrap: anywhere;
}

.row-name {
    font-weight: 600;
}

.row-note {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.row-action {
    flex: none;
}

.row-action .check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid currentColor;
    border-radius: 4px;
    font-size: 0.85rem;
}

.row-action.is-pressed {
    color: var(--text);
    border-color: var(--border);
}

.empty-state {
    padding: 1rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--bg);
}

.empty-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Exercises page */

.intro {
    color: var(--text-muted);
    max-width: 60ch;
}

.exercise-list {
    margin: 0 0 1rem;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 0.4rem;
}

.exercise-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.4rem 0.4rem 0.4rem 0.75rem;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
}

.exercise-name {
    font-weight: 600;
    min-width: 0;
    overflow-wrap: anywhere;
}

.row-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.rename-form {
    display: grid;
    gap: 0.4rem;
    width: 100%;
}

/* Dialogs, banners */

.dialog {
    width: min(32rem, calc(100vw - 2rem));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    color: var(--text);
    background: var(--surface);
}

.dialog::backdrop {
    background: var(--overlay);
}

.dialog-list {
    padding-left: 1.25rem;
}

.dialog-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.scope-options {
    border: 0;
    margin: 0;
    padding: 0;
}

.radio {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.radio input:disabled + label {
    color: var(--text-muted);
}

.hint {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.reset-preview {
    font-weight: 600;
    margin-top: 0.75rem;
}

main {
    padding-bottom: 4rem;
}

.banner {
    padding: 0.75rem 1rem;
    font-weight: 600;
}

.banner-warning {
    background: var(--warning-bg);
    color: var(--warning-text);
}

.banner-info {
    background: var(--primary-soft);
    color: var(--text);
}

.loading {
    padding: 2rem 1rem;
    text-align: center;
}

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.75rem 1rem;
    background: var(--warning-bg);
    color: var(--warning-text);
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    float: right;
    min-width: var(--target);
    min-height: var(--target);
    border: 0;
    background: none;
    font-size: 1.25rem;
    cursor: pointer;
}

/* Server state (feature 003) */

.server-error {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border: 2px solid var(--danger);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--danger);
    font-weight: 600;
}

.server-error p {
    margin: 0;
    flex: 1 1 12rem;
}

.saving {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    margin: 0;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    background: var(--text);
    color: var(--surface);
    z-index: 40;
}

.saving.is-hidden {
    display: none;
}

/* Feature 025 FR-030, FR-034: a circular indicator while saving and a check mark after; both take the
   indicator's text color, so contrast matches the text in both themes. No spin with reduced motion. */
.saving-ring {
    display: inline-block;
    width: 1em;
    height: 1em;
    margin-right: 0.4em;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    vertical-align: -0.15em;
    animation: saving-spin 0.8s linear infinite;
}

@keyframes saving-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .saving-ring {
        animation: none;
    }
}

.saving-check {
    margin-right: 0.25em;
    font-weight: 700;
}

.sign-in form {
    display: grid;
    gap: 0.5rem;
    max-width: 22rem;
}

.load-failed {
    display: grid;
    gap: 0.75rem;
    justify-items: start;
}

.restore-round {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    margin-top: 0.75rem;
    padding: 0.75rem;
    border-radius: var(--radius);
    background: var(--primary-soft);
}

.restore-round p {
    margin: 0;
    flex: 1 1 12rem;
}

.about-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Results page (feature 004 contracts/ui-contract.md "Results page") */

.results-summary {
    font-weight: 600;
    font-size: 1.05rem;
}

.results-figure {
    margin: 0 0 1rem;
}

.results-caption {
    font-weight: 700;
    margin-bottom: 0.75rem;
}

/* Category fills for chart bars and columns: patterns as well as colors (feature 004 FR-029). */
.wc-cat-0 {
    background: var(--cat-upper);
    border-color: var(--cat-upper);
}

.wc-cat-1 {
    border-color: var(--cat-lower);
    background: repeating-linear-gradient(45deg, var(--cat-lower) 0 3px, var(--cat-lower-soft) 3px 6px);
}

.wc-cat-2 {
    border-color: var(--cat-stretch);
    background-color: var(--cat-stretch-soft);
    background-image: radial-gradient(circle, var(--cat-stretch) 1.6px, transparent 1.8px);
    background-size: 6px 6px;
}

.table-scroll {
    max-width: 100%;
    overflow-x: auto;
}

.done-without-weight {
    color: var(--text-muted);
}

.results-category {
    margin-top: 0; /* feature 015: inside a collapsible card */    display: grid;
    gap: 0.75rem;
}

.results-category h2 {
    margin: 0;
}

.exercise-result {
    border-top: 1px solid var(--border-soft);
    padding-top: 0.75rem;
}

.exercise-result h3 {
    margin: 0 0 0.25rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.result-best {
    margin: 0;
    font-weight: 700;
    color: var(--done);
}

.result-best.is-none {
    color: var(--text-muted);
    font-weight: 600;
}

.result-days {
    margin: 0 0 0.25rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.result-date {
    font-size: 0.9rem;
    margin: 0.5rem 0 0;
    color: var(--text-muted);
}

.tag {
    border-radius: 999px;
}

/* Feature 005: column chart (research R8). The axis stays outside the scroll region; each column is
   72 px wide with its value above the bar and the full name below. */
.column-chart {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: var(--space-2);
    --cc-height: 12rem;
}

.cc-axis {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: var(--space-1);
    height: var(--cc-height);
    margin-top: 3rem;
}

.cc-axis-title {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--chart-axis);
    text-align: center;
    align-self: center;
}

.cc-ticks {
    position: relative;
    display: block;
    width: 2.5rem;
    height: 100%;
}

.cc-tick {
    position: absolute;
    right: 0;
    transform: translateY(50%);
    font-size: 0.8rem;
    color: var(--chart-axis);
    font-variant-numeric: tabular-nums;
}

.cc-scroll {
    overflow-x: auto;
    min-width: 0;
    padding-bottom: var(--space-1);
}

.cc-plot {
    display: inline-grid;
    min-width: 100%;
}

.cc-bars {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    height: var(--cc-height);
    margin-top: 3rem;
    border-bottom: 1px solid var(--chart-axis);
    padding: 0 var(--space-2);
}

.cc-grid {
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--chart-grid);
}

.cc-column {
    position: relative;
    flex: 0 0 72px;
    height: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.cc-bar {
    display: block;
    width: 40px;
    min-height: 2px;
    border: 1.5px solid;
    border-radius: 6px 6px 0 0;
}

.cc-value {
    position: absolute;
    left: 50%;
    transform: translate(-50%, -0.25rem);
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 0.85rem;
    font-weight: 700;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.cc-column.is-max .cc-bar {
    outline: 3px solid var(--text);
    outline-offset: 2px;
}

.cc-names {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-2) 0;
}

.cc-name {
    flex: 0 0 72px;
    font-size: 0.8rem;
    text-align: center;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Results table, always visible (feature 005 FR-005). */
[data-testid="results-table"] {
    width: 100%;
    border-collapse: collapse;
    margin-top: var(--space-4);
    font-variant-numeric: tabular-nums;
}

[data-testid="results-table"] caption {
    text-align: left;
    font-weight: 700;
    padding-bottom: var(--space-2);
}

[data-testid="results-table"] th,
[data-testid="results-table"] td {
    padding: var(--space-2);
    border-bottom: 1px solid var(--border-soft);
    text-align: left;
    vertical-align: top;
}

[data-testid="results-table"] .badge-best {
    margin-left: var(--space-2);
}

[data-testid="results-table"] tr.is-max {
    background: var(--done-soft);
}

/* Muscle map (feature 005 FR-007 to FR-011). Front and back side by side from 480 px. */
.muscle-map {
    display: grid;
    gap: var(--space-4);
}

@media (min-width: 768px) {
    .muscle-map {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        align-items: start;
    }
}

.body-map {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-4);
}

.body-view {
    margin: 0;
    text-align: center;
}

.body-view figcaption {
    font-weight: 600;
    color: var(--text-muted);
}

.body-svg {
    width: 9rem;
    height: auto;
    display: block;
}

/* Feature 009 (research R5, R9): the anatomical figure. Visible strokes keep their CSS px width at
   any size (non-scaling-stroke); the hit layer's stroke is in viewBox units on purpose. */
.body-svg path {
    vector-effect: non-scaling-stroke;
}

.body-outline {
    fill: none;
    stroke: var(--body-outline);
    stroke-width: 1.5;
    pointer-events: none;
}

.body-decor path:not(.body-outline) {
    fill: var(--body-fill);
    stroke: var(--body-outline);
    stroke-width: 1;
    cursor: default;
}

.muscle-hit path {
    fill: none;
    stroke: transparent;
    vector-effect: none;
    pointer-events: stroke;
    stroke-linejoin: round;
    cursor: pointer;
}

.muscle-area {
    cursor: pointer;
    stroke-width: 2;
    transition: fill 150ms;
}

.muscle-area:focus {
    outline: none;
}

/* Available: solid fill, solid outline. */
.muscle-area.is-selectable {
    fill: var(--muscle-fill);
    stroke: var(--muscle-stroke);
}

.muscle-area.is-selectable:hover {
    stroke-width: 3;
}

/* Unavailable: body fill, dashed outline, no pointer (feature 009 FR-009). */
.muscle-area.is-empty {
    fill: var(--body-fill);
    stroke: var(--muscle-empty-stroke);
    stroke-dasharray: 4 3;
    cursor: default;
}

/* Selected: strong fill, thick outline, and a hatch overlay, so it is not color alone (FR-010). */
.muscle-area.is-selected {
    fill: var(--muscle-selected-fill);
    stroke: var(--muscle-selected-stroke);
    stroke-width: 3.5;
    stroke-dasharray: none;
}

/* Feature 021 (research R4): the fill is set per diagram on the element (url(#{prefix}-hatch)). */
.muscle-area .muscle-hatch {
    stroke: none;
    pointer-events: none;
}

.muscle-hatch-line {
    stroke: var(--surface); /* 6.7:1 (light) and 8.3:1 (dark) on --muscle-selected-fill */
    stroke-width: 5;
}

/* Focus: its own color and width, used by no other state. */
.muscle-area:focus-visible {
    stroke: var(--focus);
    stroke-width: 4;
    stroke-dasharray: none;
}

.muscle-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-content: start;
}

.muscle-button {
    border-radius: 999px;
    transition: none;
}

.muscle-button.is-empty {
    border-style: dashed;
    color: var(--text-muted);
}

/* Feature 009 FR-009: unavailable chips stay focusable (aria-disabled, not disabled) but do nothing. */
.muscle-button[aria-disabled="true"],
.muscle-button[aria-disabled="true"]:hover {
    cursor: default;
    background: transparent;
}

.muscle-button[aria-pressed="true"] {
    background: var(--primary);
    border-color: var(--primary);
    border-style: solid;
    color: var(--primary-text);
    font-weight: 700;
}

.muscle-max {
    margin-top: var(--space-4);
    padding: var(--space-3) var(--space-4);
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    background: var(--primary-soft);
    display: grid;
    gap: var(--space-2);
    justify-items: start;
}

.muscle-max-text {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
}

.muscle-max-note {
    margin: 0;
    color: var(--text-muted);
}

/* Exercises page (feature 005 US5). */
.muscle-summary {
    display: block;
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text-muted);
}

.muscle-checks {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: var(--space-2) var(--space-3);
    margin: var(--space-3) 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
    gap: 0 var(--space-3);
}

.check-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--target);
}

.check-row input {
    width: 1.25rem;
    height: 1.25rem;
}

.check-row label {
    font-weight: 400;
}

@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

/* ===== Feature 010: planner filters, stretching, priorities, notes (contracts/ui-contract.md) ===== */

.past-day-hint {
    margin: 0;
}

/* Day set total (feature 011), in the progress area since feature 028. The number is the accessible value; the bar is decorative. */
.day-reps {
    display: grid;
    gap: 0.25rem;
    margin: 0;
    font-weight: 600;
}

.calendar-date-text.is-today {
    font-weight: 800;
}

/* Feature 028 FR-009 to FR-012 (research R5): the highlighted progress area. Feature 029 (research R2): it sits
   in the day card below the date and the filters; the styles are unchanged.
   On --primary-soft: --text 14.4:1 (light) and 10.4:1 (dark); the --done bars 6.1:1 and 6.7:1. The 2 px
   --primary border is 5.7:1 (light) and 6.9:1 (dark) against it, so the area is set apart without relying
   on fill color alone. */
.progress-panel {
    display: grid;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    padding: var(--space-4);
    border: 2px solid var(--primary);
    border-radius: var(--radius-card);
    background: var(--primary-soft);
    min-width: 0;
}

@media (min-width: 768px) {
    .progress-panel {
        grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
        align-items: end;
    }
}

/* Inside the panel the texts are centered and the bars fill the whole width. */
.progress-panel .day-reps,
.progress-panel .progress {
    justify-items: stretch;
    text-align: center;
}

.progress-panel .day-reps progress,
.progress-panel .progress progress {
    width: 100%;
}

.day-reps progress {
    width: 12rem;
    max-width: 100%;
    height: 0.6rem;
    accent-color: var(--done);
}

.done-later,
.stretching {
    display: grid;
    gap: var(--space-2);
    margin-top: var(--space-4);
}

.done-later h3,
.stretching h3 {
    margin: 0;
    font-size: 1rem;
}

.stretching .hint {
    margin: 0;
}

/* "Want today": a pressed toggle; the pressed state also shows the word "Wanted". */
.btn-want {
    flex: none;
}

.btn-want.is-pressed {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 700;
}

.tag-wanted {
    border-color: var(--primary);
    color: var(--primary);
}

.next-note {
    display: grid;
    gap: 0.4rem;
    justify-items: start;
}

.row-next-note {
    margin: 0;
    padding: 0.15rem 0.5rem;
    border-left: 3px solid var(--primary);
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.note-editor {
    display: grid;
    gap: 0.4rem;
    width: 100%;
}

.note-editor[hidden] {
    display: none;
}

.note-editor textarea {
    width: 100%;
    min-height: var(--target);
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.note-editor .hint {
    margin: 0;
}

.note-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.weight-prefill-hint {
    flex: 1 0 100%;
    margin: 0;
}

/* ===== Feature 010: Body map page (research R13). States differ by fill, outline style, and the
   written state in each region's name and the legend, never by color alone. ===== */

/* Work remaining: blue fill (3.1:1 on body fill), solid outline (5.9:1 light, 7.1:1 dark). */
.muscle-area.map-remaining {
    fill: var(--muscle-fill);
    stroke: var(--muscle-stroke);
    stroke-dasharray: none;
}

/* Done: green fill (--done: 6.3:1 light, 7.9:1 dark on body fill), dotted outline in text color. */
.muscle-area.map-done {
    fill: var(--done);
    stroke: var(--text);
    stroke-dasharray: 1 4;
    stroke-linecap: round;
}

/* No work done (past days): no fill, solid outline (5.9:1 light, 7.1:1 dark on body fill). */
.muscle-area.map-not-done {
    fill: var(--body-fill);
    stroke: var(--muscle-stroke);
    stroke-dasharray: none;
}

.body-legend {
    display: grid;
    gap: var(--space-2);
    align-content: start;
    margin: 0;
    padding: 0;
    list-style: none;
}

.body-legend li {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.legend-swatch {
    flex: none;
    background: var(--body-fill);
    border-radius: 6px;
}

.legend-swatch .muscle-area {
    cursor: default;
}

.body-group {
    display: grid;
    gap: var(--space-2);
    margin-top: var(--space-4);
}

.body-group h2,
.body-group h3 {
    margin: 0;
}

.body-group h3 {
    font-size: 1rem;
}

.body-group-list {
    margin: 0;
    padding-left: 1.25rem;
}

.body-group-list a {
    display: inline-flex;
    align-items: center;
    min-height: var(--target);
    min-width: var(--target); /* short names such as "Dips" still give a 44 x 44 px target */
}

/* ===== Feature 010: Results trends and heaviest lifts (FR-021 to FR-023) ===== */

/* Feature 013: the trend select styles now serve the Progress control bar (TrendChart was removed). */
.progress-controls select {
    min-height: var(--target);
    padding: 0 var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.trend-panel {
    margin: var(--space-3) 0 0;
}

.trend-title {
    font-weight: 600;
    margin-bottom: var(--space-2);
}

.insights-section summary {
    display: inline-flex;
    align-items: center;
    min-height: var(--target);
    cursor: pointer;
}

.cc-date {
    display: block;
    font-weight: 400;
    color: var(--text-muted);
}

.lifts-list {
    margin: var(--space-3) 0 0;
    padding-left: 1.25rem;
}

/* ===== Feature 010: Insights page (labeled guidance, constitution V) ===== */

.insights-lead {
    margin: 0 0 var(--space-4);
    font-weight: 600;
}

.insights-section {
    display: grid;
    gap: var(--space-3);
}

.insights-section h2 {
    margin: 0;
}

.insights-list {
    margin: 0;
    padding-left: 1.25rem;
    display: grid;
    gap: var(--space-2);
}

/* ===== Feature 010: Notes page (FR-024) ===== */

.notes-form {
    display: grid;
    gap: var(--space-2);
}

.notes-form textarea,
.tracker-item textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

/* Feature 014: Notes toolbar (contracts/ui-contract.md "Notes"). The type fieldset was removed. */
.notes-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    margin-block: var(--space-2);
}

.notes-toolbar .btn {
    min-height: var(--target);
}

.tracker-list {
    display: grid;
    gap: var(--space-3);
    margin: 0;
    padding: 0;
    list-style: none;
}

.tracker-item {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-3);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
}

.tracker-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
}

.tracker-text {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* ===== Feature 012: Progress, Insights polish, page titles, navigation ===== */

/* Shared page title (FR-024, research R8): one h1 style on every page; card headings stay below it. */
.page-title {
    margin-block: var(--space-4) var(--space-4);
}

.page-title h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.page-title .lead {
    margin: var(--space-1) 0 0;
    color: var(--text-muted);
    font-weight: 400;
    max-width: 65ch;
}

.card h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

@media (min-width: 768px) {
    .page-title {
        margin-block: 1.5rem var(--space-4);
    }

    .page-title h1 {
        font-size: 1.75rem;
    }
}

/* Navigation (FR-023, research R8): the current page keeps its tinted pill and underlined label and
   gains an indicator bar, so it is shown by shape as well as color. */
@media (min-width: 768px) {
    .topbar {
        min-height: 56px;
        box-shadow: none;
        border-bottom-color: var(--border-soft);
    }

    .nav-links a.active,
    .nav-more-button.active {
        box-shadow: inset 0 -3px 0 var(--primary);
    }
}

/* Progress page (FR-003) */
.progress-summary {
    margin: 0;
    font-weight: 600;
}

/* Insights alignment (FR-012, FR-013; research R5) */
.insights-section > h2,
.session-heading,
.jump-name {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-1) var(--space-2);
}

.insights-section > h2 .tag,
.session-heading .tag,
.jump-name .tag {
    margin-left: 0;
}

.insights-section table th,
.insights-section table td {
    padding: 0.5rem 0.75rem;
    text-align: start;
    vertical-align: top;
    overflow-wrap: anywhere;
}

.num,
.insights-section table .num {
    text-align: end;
    font-variant-numeric: tabular-nums;
    overflow-wrap: normal;
}

.cell-note {
    display: block;
    color: var(--text-muted);
    font-size: 0.875rem;
}

@media (min-width: 768px) {
    .insights-section [data-testid="calories-table"] {
        table-layout: fixed;
        width: 100%;
    }

    .insights-section [data-testid="calories-table"] th:nth-child(1) { width: 34%; }
    .insights-section [data-testid="calories-table"] th:nth-child(2) { width: 30%; }
    .insights-section [data-testid="calories-table"] th:nth-child(3),
    .insights-section [data-testid="calories-table"] th:nth-child(4) { width: 18%; }
}

/* Session estimate (FR-008 to FR-011) */
.session-estimate {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-3);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
}

.session-heading {
    margin: 0;
    font-size: 1rem;
}

.session-value {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-2);
    margin: 0;
}

.session-value output {
    font-size: 1.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.session-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-2);
}

.session-controls .btn {
    min-height: var(--target);
    min-width: var(--target);
}

.session-field {
    display: grid;
    gap: var(--space-1);
    margin: 0;
}

.session-field input {
    width: 7rem;
    min-height: var(--target);
    padding: 0 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.session-field input[aria-invalid="true"] {
    border-color: var(--danger);
    border-width: 2px;
}

.session-estimate .field-error {
    margin: 0;
    color: var(--danger);
    font-weight: 600;
}

/* Jump guidance (FR-015 to FR-019) */
.jump-relevant {
    display: grid;
    gap: var(--space-3);
    margin: 0;
    padding: 0;
    list-style: none;
}

.jump-item {
    display: grid;
    gap: var(--space-1);
    padding: var(--space-3);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
}

.jump-name {
    margin: 0;
    font-size: 1rem;
}

.jump-reason,
.jump-recent {
    margin: 0;
}

.jump-recent {
    color: var(--text-muted);
}

.jump-steps {
    margin: var(--space-1) 0 0;
    padding-left: 1.25rem;
    display: grid;
    gap: var(--space-1);
}

.jump-disclaimer {
    font-style: italic;
}

/* ===== Feature 013: Progress page design (FR-013 to FR-016; research R6, R9) ===== */

/* Control bar: labels above controls; one row from 768 px, one column below. */
.progress-controls {
    display: grid;
    gap: var(--space-3);
    align-items: end;
}

.progress-controls .field {
    gap: var(--space-1);
}

.progress-controls select {
    width: 100%;
}

.field-label {
    font-weight: 600;
}

.metric-switch {
    display: flex;
    gap: var(--space-2);
}

.metric-switch .section-button {
    flex: 1 1 0;
    min-width: 5.5rem;
}

@media (min-width: 768px) {
    .progress-controls {
        grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto;
    }
}

.progress-summary {
    margin: var(--space-1) 0 var(--space-3);
    font-weight: 600;
}

.progress-chart-card {
    display: grid;
    gap: var(--space-3);
}

.progress-chart-card > h2 {
    margin: 0;
    overflow-wrap: anywhere;
}

.progress-chart-card .hint {
    margin: 0;
}

.progress-figure {
    margin: 0;
}

/* ===== Feature 014: collapsible cards (Insights categories; feature 015: also Results and Progress) (contracts/ui-contract.md "Insights", research R9) ===== */

.insights-search {
    margin-bottom: var(--space-3);
}

.collapsible {
    display: grid;
    gap: var(--space-2);
}

.collapsible-heading {
    margin: 0;
    font-size: inherit;
}

.collapsible-toggle {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-2);
    width: 100%;
    min-height: var(--target);
    padding: var(--space-1) 0;
    border: 0;
    background: none;
    color: var(--text);
    font: inherit;
    font-size: 1.2rem;
    font-weight: 700;
    text-align: start;
    cursor: pointer;
}

.collapsible-toggle .tag {
    margin-left: 0;
}

/* Chevron drawn with borders in the text color, so it follows both themes; rotated when open. */
.collapsible-toggle .chevron {
    width: 0.6rem;
    height: 0.6rem;
    margin-left: auto;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.15s ease;
}

.collapsible-toggle[aria-expanded="true"] .chevron {
    transform: rotate(-135deg);
}

@media (prefers-reduced-motion: reduce) {
    .collapsible-toggle .chevron {
        transition: none;
    }
}

.collapsible-hint {
    margin: 0;
}

.collapsible-body {
    display: grid;
    gap: var(--space-3);
}

.collapsible-body[hidden] {
    display: none;
}

.collapsible .insights-section {
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-soft);
}

.insights-section > h3 {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-1) var(--space-2);
    margin: 0;
}

.insights-section > h3 .tag {
    margin-left: 0;
}

.insights-areas {
    display: grid;
    gap: var(--space-3);
}

.insights-area h3 {
    margin: 0 0 var(--space-1);
}

/* Each exercise is its own section with a separator line, so Dips and Pull-ups never run together. */

/* ===== Feature 014: Glass navigation bar (FR-012, research R8) ===== */

/* The blur sits on a ::before layer, not on the bar itself: backdrop-filter on the bar would make it
   the containing block of the fixed "More" backdrop and menu, which then no longer cover the page. */
.topbar {
    background: transparent;
    border-bottom-color: var(--nav-glass-border);
}

.topbar::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--nav-glass);
    -webkit-backdrop-filter: blur(14px) saturate(1.5);
    backdrop-filter: blur(14px) saturate(1.5);
    pointer-events: none;
}

@media (max-width: 767px) {
    .main-nav {
        background: transparent;
        border-top-color: var(--nav-glass-border);
    }

    .main-nav::before {
        content: "";
        position: absolute;
        inset: 0;
        z-index: -1;
        background: var(--nav-glass);
        -webkit-backdrop-filter: blur(14px) saturate(1.5);
        backdrop-filter: blur(14px) saturate(1.5);
        pointer-events: none;
    }
}

/* Without blur, or when the system asks for less transparency, the bar stays opaque. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .topbar::before,
    .main-nav::before {
        background: var(--nav-bg);
    }
}

@media (prefers-reduced-transparency: reduce) {
    .topbar::before,
    .main-nav::before {
        background: var(--nav-bg);
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
}

/* ===== Feature 015: row button group and one-line names (FR-012, FR-013, research R6, R7) ===== */

/* Name column takes the free space and may shrink; the name itself is one line with an ellipsis. */
.row-text {
    flex: 1 1 12rem;
    min-width: 0;
    overflow-wrap: normal;
}

.row-name {
    display: block;
    flex: 1 0 100%;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* One bordered rectangle; buttons inside share 1 px separators instead of their own borders. */
.row-actions {
    display: flex;
    flex: 0 1 auto;
    flex-wrap: wrap;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
}

.row-actions:empty {
    display: none;
}

.row-actions > .btn {
    flex: 1 0 auto;
    min-height: var(--target);
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: -1px 0 0 var(--border);
}

/* Feature 019 FR-004 to FR-007: the group stays on the name's line at every width (was: under the name
   below 600 px); see the feature 019 block at the end. */

/* Feature 015 (research R6 risk): anything scrolled into view (by focus, by the browser, by a tap) stays
   clear of the sticky top bar and, on phones, of the fixed tab bar. Without this, a control could land
   under the tab bar and the next tap scrolled the page by a whole screen. */
html {
    scroll-padding-top: 4rem;
}

@media (max-width: 767px) {
    html {
        scroll-padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + var(--space-2));
    }
}

/* ---------------------------------------------------------------------------------------------
   Feature 017 (specs/017-workout-app-improvements/contracts/ui-contract.md)
   --------------------------------------------------------------------------------------------- */

/* Rest timer (US1): written time, never color alone; the countdown is aria-hidden, the start and end
   are announced. --primary on --primary-soft: light 6.0:1, dark 6.9:1; --done on --done-soft: light
   6.4:1, dark 7.4:1. */
.rest-timer {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.rest-ready {
    background: var(--done-soft);
    color: var(--done);
}

.set-new .rest-timer {
    align-self: center;
}

.btn:disabled[data-testid="add-set"] {
    cursor: not-allowed;
}

/* Settings page (US1) */
.settings .field {
    max-width: 20rem;
}

.settings select {
    min-height: var(--target);
    width: 100%;
}

/* Repeat entries (US2): the tag is written text; --text-muted border on surface, decorative. */
.tag-repeat {
    border-color: var(--text-muted);
    color: var(--text);
}

/* Progress line chart (US4): scales to the card width; text sizes are in the 360-unit view box. Line and
   points use --primary (6.7:1 light, 8.4:1 dark on surface); grid --chart-grid is decorative; tick text
   --chart-axis (7.6:1 / 7.3:1). Points are circles with written values, never color alone. */
.line-chart {
    margin: var(--space-3) 0 0;
}

.line-chart-title {
    font-weight: 600;
    margin-bottom: var(--space-2);
}

.line-chart-svg {
    display: block;
    width: 100%;
    max-width: 44rem;
    height: auto;
    overflow: visible;
}

.line-grid {
    stroke: var(--chart-grid);
    stroke-width: 1;
}

.line-axis {
    stroke: var(--chart-axis);
    stroke-width: 1.5;
}

.line-tick,
.line-axis-title {
    fill: var(--chart-axis);
    font-size: 11px;
}

.line-axis-title {
    font-weight: 600;
}

.line-path {
    fill: none;
    stroke: var(--primary);
    stroke-width: 2.5;
    stroke-linejoin: round;
}

.line-point circle {
    fill: var(--surface);
    stroke: var(--primary);
    stroke-width: 2.5;
}

.line-value {
    fill: var(--text);
    font-size: 11px;
    font-weight: 600;
    visibility: hidden;
}

.line-value.is-shown,
.line-point:hover .line-value,
.line-point:focus .line-value {
    visibility: visible;
}

.line-point:focus {
    outline: none;
}

.line-point:focus circle,
.line-point:focus-visible circle {
    stroke: var(--focus);
    stroke-width: 4;
}

/* Heaviest-weight bar list (US5, FR-024): one row per exercise, name on its own wrapping line, bar
   and written value below it. Percentage widths, so it fits 320 px with no sideways scroll. Bar fills
   reuse the category patterns (.wc-cat-*), so meaning never depends on color alone. */
.bar-list {
    min-width: 0;
}

.bar-rows {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: var(--space-3);
}

.bar-row {
    display: grid;
    gap: var(--space-1);
    min-width: 0;
}

.bar-name {
    overflow-wrap: anywhere;
    font-weight: 600;
}

.bar-area {
    color: var(--text-muted);
    font-weight: 600;
}

.bar-date {
    margin-left: var(--space-2);
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.9em;
}

.bar-track {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

/* The heaviest bar is 75 % of the track (set inline), so the value always fits after it. */
.bar-fill {
    flex: 0 0 auto;
    min-width: 2px;
    height: 1.25rem;
    border: 1px solid;
    border-radius: 4px;
}

.bar-value {
    flex: 0 0 auto;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.bar-row.is-max .bar-name {
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

/* Nested cards inside Body (US6): a lighter frame, so the Body card stays one group. */
.collapsible-nested {
    box-shadow: none;
    border: 1px solid var(--card-border);
    padding: var(--space-3);
}

.collapsible-nested .collapsible-toggle {
    font-size: 1.05rem;
}

/* Shared section header icon (US8, FR-026). */
.collapsible-toggle .nav-icon {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    color: var(--text-muted);
}

/* Feature 017 E2E fixes: 44 px targets for the inline muscle picker and the History exercise toggles;
   bar rows may shrink below their content width (long names wrap instead of widening the row). */
.muscle-suggestion-hint {
    min-height: 1.5em;
    margin: 0;
}

.muscle-picker .check-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--target);
}

.muscle-picker .check-row input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
}

.muscle-picker .check-row label {
    flex: 1;
    min-height: var(--target);
    display: flex;
    align-items: center;
}

.bar-rows,
.bar-row {
    grid-template-columns: minmax(0, 1fr);
}

.bar-list,
.collapsible-body > .results {
    min-width: 0;
    max-width: 100%;
}

/* Trends, formerly Progress over time (US4): the exercise select is a 44 px target like the control bar's. */
#progress-line-exercise,
#progress-line-range {
    min-height: var(--target);
    width: 100%;
    max-width: 24rem;
}

/* ---------------------------------------------------------------------------------------------
   Feature 018 (specs/018-workout-ui-history/contracts/ui-contract.md)
   --------------------------------------------------------------------------------------------- */

/* Past day (US1): the selected date is the most prominent text; the tag uses --text-muted
   (7.6:1 light, 7.3:1 dark on surface). */
.day-heading-past {
    font-size: 1.5rem;
    font-weight: 700;
}

.tag-past {
    border-color: var(--text-muted);
    color: var(--text-muted);
}

@media (max-width: 400px) {
    .day-heading-past .tag-past {
        display: table;
        margin: var(--space-1) 0 0;
    }
}

.past-day-view {
    display: grid;
    gap: var(--space-3);
    margin-top: var(--space-3);
}

/* Add New Exercise form (US3, FR-008 to FR-010): one column; Category and Main muscle group share a row
   when the form is at least 480 px wide; the Also works items flow in columns and wrap. */
.add-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3);
    container-type: inline-size;
    justify-items: stretch;
    align-items: start;
}

.add-form > .btn-primary {
    justify-self: start;
}

.add-form-selects {
    display: grid;
    gap: var(--space-3);
    grid-template-columns: minmax(0, 1fr);
}

@container (min-width: 480px) {
    .add-form-selects {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.add-form-selects select {
    width: 100%;
    min-height: var(--target);
}

.muscle-checks .check-grid {
    /* The fieldset is itself a grid (feature 005); the wrapper spans it so the items get the columns. */
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
    gap: 0 var(--space-3);
}

.muscle-checks .check-grid .check-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--target);
}

.muscle-checks .check-grid .check-row input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    flex: 0 0 auto;
}

.muscle-checks .check-grid .check-row label {
    flex: 1;
    min-height: var(--target);
    display: flex;
    align-items: center;
}

/* Insights summaries (US4, FR-011 to FR-014): metric cards wrap to one or two columns on phones. The
   value uses --text (16.1:1 / 12.7:1), the label --text-muted (7.6:1 / 7.3:1); the card edge
   --card-border is decorative (the label names the group). */
.metric-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    gap: var(--space-2);
    margin: var(--space-2) 0 var(--space-3);
}

.metric-card {
    display: grid;
    gap: var(--space-1);
    min-width: 0;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    background: var(--bg);
}

.metric-label {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
}

.metric-label .nav-icon {
    width: 18px;
    height: 18px;
}

.metric-value {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.tag-bar {
    margin-left: var(--space-1);
    font-weight: 600;
}

/* Modern line chart (US5, FR-015 to FR-017): dashed light grid, soft area, distinct points, latest value
   highlighted. --primary line on surface 6.7:1 light / 8.4:1 dark; the area is decorative. */
.line-grid {
    stroke-dasharray: 3 4;
}

.line-axis {
    stroke: var(--chart-grid);
}

.line-path {
    stroke-width: 3;
    stroke-linecap: round;
}

.line-area-top {
    stop-color: var(--primary);
    stop-opacity: 0.22;
}

.line-area-bottom {
    stop-color: var(--primary);
    stop-opacity: 0;
}

.line-area {
    stroke: none;
}

.line-point circle {
    stroke-width: 2.5;
}

.line-point.is-latest circle {
    fill: var(--primary);
    stroke: var(--surface);
    stroke-width: 3;
}

.line-value.is-latest {
    font-size: 12px;
    font-weight: 700;
    fill: var(--primary);
}

.line-date {
    font-size: 10.5px;
}

/* Past day count: --text-muted (7.6:1 light, 7.3:1 dark on surface). */
.past-day-count {
    margin: 0;
    color: var(--text-muted);
    font-weight: 600;
}

/* ---------------------------------------------------------------------------------------------
   Feature 019 (specs/019-progress-row-actions/contracts/ui-contract.md)
   --------------------------------------------------------------------------------------------- */

/* Row first line (US2, R2): the name shrinks (one line, "…"), the four buttons never wrap off it;
   details and panels keep their own full line below. */
li.row {
    flex-wrap: wrap;
    align-items: center;
    /* The icon-only switch below follows the row's own width (rows sit in narrow columns on desktop). */
    container-type: inline-size;
}

li.row > .row-text {
    flex: 1 1 0;
    min-width: 3.5rem;
}

li.row > .row-actions {
    flex: 0 0 auto;
    flex-wrap: nowrap;
}

li.row > .row-details {
    flex: 1 0 100%;
}

.row-actions > .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    white-space: nowrap;
}

.row-actions > .btn .row-icon {
    width: 18px;
    height: 18px;
}

/* Rows narrower than 640 px (R3): icon-only 44 x 44 buttons; the text stays in the accessible name and
   the title. Labeled buttons need about 460 px, so below that width they would push the name away. */
@media (max-width: 479px) {
    li.row {
        gap: var(--space-2);
        padding-left: var(--space-3);
    }
}

@container (max-width: 639px) {
    .row-actions > .btn {
        width: var(--target);
        min-width: var(--target);
        padding: 0;
    }

    .row-actions > .btn .btn-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .row-actions > .btn .row-icon {
        width: 20px;
        height: 20px;
    }
}

/* Row button icons (R3) are CSS masks in currentColor, so they follow the button's text color in both
   themes and cost no extra component per row (long lists stay fast). Decorative: aria-hidden. */
.row-icon {
    display: inline-block;
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    background-color: currentColor;
    -webkit-mask: var(--icon) center / contain no-repeat;
    mask: var(--icon) center / contain no-repeat;
}

.icon-want {
    --icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 3.5l2.6 5.3 5.9.9-4.25 4.1 1 5.8L12 16.9l-5.25 2.7 1-5.8L3.5 9.7l5.9-.9z' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'/></svg>");
}

.icon-want-on {
    --icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 3.5l2.6 5.3 5.9.9-4.25 4.1 1 5.8L12 16.9l-5.25 2.7 1-5.8L3.5 9.7l5.9-.9z' fill='black' stroke='black' stroke-width='2' stroke-linejoin='round'/></svg>");
}

.icon-note {
    --icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M4 20h4L19 9l-4-4L4 16z M13.5 6.5l4 4' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round' stroke-linecap='round'/></svg>");
}

.icon-sets {
    --icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M9 6h11M9 12h11M9 18h11' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'/><path d='M4 6h1M4 12h1M4 18h1' fill='none' stroke='black' stroke-width='3' stroke-linecap='round'/></svg>");
}

.icon-done {
    --icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M5 12.5l4.5 4.5L19 7.5' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}

.icon-undo {
    --icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M9 7L4 12l5 5M4 12h10a5 5 0 0 1 0 10h-3' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}

.icon-move {
    --icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M4 12h12M12 7l5 5-5 5M20 4v16' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}

/* ---------------------------------------------------------------------------------------------
   Feature 020 (specs/020-insights-navigation-polish/contracts/ui-contract.md)
   --------------------------------------------------------------------------------------------- */

/* Shared select (research R3): native select with one look. Border --border is 3.2:1 (light) and
   3.9:1 (dark) on --surface; text --text 16.1:1 / 12.7:1; the chevron is a currentColor mask. Focus
   uses the global :focus-visible outline. */
select.control-select {
    appearance: none;
    -webkit-appearance: none;
    min-height: var(--target);
    width: 100%;
    max-width: 100%;
    padding: 0.5rem 2.5rem 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--surface);
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: calc(100% - 1.25rem) 50%, calc(100% - 0.9rem) 50%;
    background-size: 0.35rem 0.35rem, 0.35rem 0.35rem;
    background-repeat: no-repeat;
    color: var(--text);
    font: inherit;
    text-overflow: ellipsis;
    cursor: pointer;
}

select.control-select:hover {
    border-color: var(--text-muted);
}

select.control-select option,
select.control-select optgroup {
    background: var(--surface);
    color: var(--text);
}

/* Trends controls (FR-005): one column on phones, two from 480 px; same height and spacing. */
.chart-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.chart-controls .field {
    min-width: 0;
    margin: 0;
}

@media (min-width: 480px) {
    .chart-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

#progress-line-exercise.control-select,
#progress-line-range.control-select {
    max-width: 100%;
}

/* Rest time (FR-021, FR-022): value and options centered; padding balanced so the chevron does not
   push the centered text off center. */
select.rest-select {
    padding-left: 2.5rem;
    text-align: center;
    text-align-last: center;
}

select.rest-select option {
    text-align: center;
}

/* Calendar arrows (FR-020, research R8): 44 x 44 buttons. Glyph --text on --surface (16.1:1 / 12.7:1),
   border --border (3.2:1 / 3.9:1); hover --primary-soft (text 10.4:1 dark); pressed adds an inset ring.
   Focus uses the global outline. */
.btn.calendar-arrow {
    inline-size: var(--target);
    block-size: var(--target);
    min-width: var(--target);
    padding: 0;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text);
}

.btn.calendar-arrow:active {
    background: var(--primary-soft);
    box-shadow: inset 0 0 0 2px var(--primary);
}

/* Planner date (FR-018): the heading text is the calendar button. Calendar icon and chevron show it
   opens something; the open state rotates the chevron (shape, not color only). */
.calendar-date {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--target);
    margin: 0;
    padding: 0.25rem 0.5rem;
    margin-left: -0.5rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.calendar-date:hover {
    background: var(--primary-soft);
    border-color: var(--border);
}

.calendar-date-text {
    /* Feature 028 FR-014 (research R6): another day reads in a lighter weight, so today's bold stands out. */
    font-weight: 500;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
}

.calendar-date-chevron {
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translate(-2px, -2px);
    transition: transform 0.15s ease;
}

.calendar-date[aria-expanded="true"] .calendar-date-chevron {
    transform: rotate(-135deg) translate(-2px, -2px);
}

.calendar-date[aria-expanded="true"] {
    background: var(--primary-soft);
}

/* Theme choice (FR-012): radios in a fieldset; each label is a 44 px target. The checked state is the
   radio dot, plus a --primary border (6.7:1 / 8.4:1) on the chosen label. */
.choice-group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    border: 0;
}

.choice-group legend {
    padding: 0;
    margin-bottom: var(--space-2);
    font-weight: 600;
}

.choice {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--target);
    min-width: 7rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.choice:hover {
    background: var(--primary-soft);
}

.choice:has(input:checked) {
    border-color: var(--primary);
    box-shadow: inset 0 0 0 1px var(--primary);
    font-weight: 600;
}

.choice input {
    width: 1.25rem;
    height: 1.25rem;
    margin: 0;
    accent-color: var(--primary);
}

.choice input:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

/* On/off slide switch (Settings, phone notifications): grey track when off, green when on. */
.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    min-height: var(--target);
    cursor: pointer;
}

.switch {
    appearance: none;
    -webkit-appearance: none;
    position: relative;
    flex: none;
    width: 3.25rem;
    height: 2rem;
    margin: 0;
    border-radius: 999px;
    background: var(--border);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.switch::before {
    content: "";
    position: absolute;
    top: 0.1875rem;
    left: 0.1875rem;
    width: 1.625rem;
    height: 1.625rem;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease;
}

.switch:checked {
    background: var(--done);
}

.switch:checked::before {
    transform: translateX(1.25rem);
}

.switch:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .calendar-date-chevron,
    .switch,
    .switch::before {
        transition: none;
    }
}

/* Phone and wide navigation (FR-015, research R6). Below 768 px the wrapper makes no box: the header is
   sticky on its own and the nav is fixed to the viewport with no sticky ancestor. From 768 px the
   wrapper is the sticky top row; the header inside it is static, so its glass ::before layer covers
   the whole row (the bar itself still has no backdrop-filter, see "Glass navigation bar"). */
.app-bar {
    display: contents;
}

@media (min-width: 768px) {
    .app-bar {
        position: sticky;
        top: 0;
        z-index: 30;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-1) var(--space-4);
        min-height: 56px;
        padding: var(--space-1) var(--space-4);
        border-bottom: 1px solid var(--border-soft);
    }

    .app-bar > .topbar {
        position: static;
        z-index: auto;
        min-height: 0;
        padding: 0;
        border-bottom: 0;
        flex: 0 1 auto;
    }

    .app-bar > .main-nav {
        position: relative;
        margin-left: auto;
    }
}

/* Feature 024: clear the iPhone status bar in the iOS app and in standalone mode. The inset is 0 in a
   normal browser tab, so the existing top padding stays the same there. */
@media (max-width: 767px) {
    .topbar {
        padding-top: calc(var(--space-1) + env(safe-area-inset-top));
    }
}

@media (min-width: 768px) {
    .app-bar {
        padding-top: calc(var(--space-1) + env(safe-area-inset-top));
    }
}

/* Feature 025 FR-002: also clear the notch side in landscape, and the static loading text before the app
   starts. Each inset is 0 in a normal browser tab, so every box keeps its size and place there (FR-003). */
@media (max-width: 767px) {
    .topbar {
        padding-left: calc(var(--space-4) + env(safe-area-inset-left));
        padding-right: calc(var(--space-4) + env(safe-area-inset-right));
    }

    .main-nav {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

@media (min-width: 768px) {
    .app-bar {
        padding-left: calc(var(--space-4) + env(safe-area-inset-left));
        padding-right: calc(var(--space-4) + env(safe-area-inset-right));
    }
}

main {
    padding-left: calc(1rem + env(safe-area-inset-left));
    padding-right: calc(1rem + env(safe-area-inset-right));
}

@media (max-width: 400px) {
    main {
        padding-left: calc(0.5rem + env(safe-area-inset-left));
        padding-right: calc(0.5rem + env(safe-area-inset-right));
    }
}

#app > .loading {
    padding-top: env(safe-area-inset-top);
}

@media (max-width: 767px) {
    /* Focused controls scroll clear of the tab bar. */
    html {
        scroll-padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + var(--space-4));
    }
}

/* ---------------------------------------------------------------------------------------------
   Feature 021 (specs/021-body-map-merge/contracts/ui-contract.md)
   --------------------------------------------------------------------------------------------- */

/* Large Body Map sections (FR-011, research R6): a 56 px header across the card, heading-size title. */
.collapsible-large > .collapsible-heading .collapsible-toggle {
    min-height: 56px;
    width: 100%;
}

.collapsible-large > .collapsible-heading .collapsible-title {
    font-size: 1.25rem;
}

/* Owner requests after feature 021. The day's date in the day view opens the Planner calendar: it reads as
   the heading, with an underline and pointer to show it can be activated; 44 px target; global focus ring. */
.day-date-button {
    display: inline-flex;
    align-items: center;
    min-height: var(--target);
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
    cursor: pointer;
}

.day-date-button:hover {
    text-decoration-thickness: 2px;
}

/* "How this is worked out" is always shown (no fold): a small heading and its text. */
.insights-method {
    margin-top: var(--space-3);
}

.insights-method h4 {
    margin: 0 0 var(--space-1);
    font-size: 0.95rem;
}

.insights-method p {
    margin: 0;
}

/* ---------------------------------------------------------------------------------------------
   Feature 027 (specs/027-workout-reminder-fixes/contracts/ui-contract.md)
   --------------------------------------------------------------------------------------------- */

/* Startup (FR-002): the Blazor loading state continues the index.html loading view. */
.startup-app {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    min-height: 60vh;
}

.startup-app .app-logo {
    width: 96px;
    height: 96px;
}

.startup-app .loading {
    padding: 0;
}

/* index.html sets its own centred view; no extra top padding for its text. */
#app > .startup > .loading {
    padding-top: 0;
}

/* Feature 028 FR-027 (research R10): the manual rest timer control (Start, Pause, Resume, Reset) was removed. */

/* Feature 028 (research R1): the gym reminder clock picker and its Save were replaced by a rest-time dropdown. */

/* Body Map heaviest section without a toggle (FR-010): the same 56 px header look as the large toggles. */
.collapsible-static-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-2);
    min-height: 56px;
    padding: var(--space-1) 0;
    font-size: 1.2rem;
    font-weight: 700;
}

.collapsible-static-title .nav-icon {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
}

.collapsible-large > .collapsible-heading .collapsible-static-title .collapsible-title {
    font-size: 1.25rem;
}

/* Feature 030 (research R4, contracts/ui-contract.md "Celebration toast"): a short milestone celebration.
   It never catches taps (pointer-events: none) and holds nothing focusable. Existing tokens only. */
.celebration {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 4.5rem);
    left: 50%;
    z-index: 950;
    width: max-content;
    max-width: min(90vw, 26rem);
    padding: var(--space-3) var(--space-5);
    background: var(--surface);
    color: var(--text);
    border: 2px solid var(--done);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    pointer-events: none;
    transform: translateX(-50%);
    animation: celebration-in 200ms ease-out, celebration-out 300ms ease-in 2700ms forwards;
}

.celebration-emoji {
    display: block;
    font-size: 2.5rem;
    line-height: 1.2;
}

.celebration-text {
    margin: var(--space-1) 0 0;
    font-weight: 600;
}

@keyframes celebration-in {
    from { opacity: 0; transform: translateX(-50%) scale(0.8); }
    to { opacity: 1; transform: translateX(-50%) scale(1); }
}

@keyframes celebration-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .celebration { animation: none; }
}

/* Feature 030 (contracts/ui-contract.md "Gym bag page"): the gym equipment checklist. */
.gym-packed-count {
    font-weight: 600;
}

.gym-add {
    margin-bottom: var(--space-4);
}

.gym-add-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.gym-add-row input {
    flex: 1 1 12rem;
    min-width: 0;
}

.gym-items {
    list-style: none;
    margin: 0 0 var(--space-4);
    padding: 0;
}

.gym-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    min-height: var(--target);
    padding: var(--space-1) 0;
    border-bottom: 1px solid var(--border-soft);
}

.gym-check {
    display: flex;
    flex: 1 1 10rem;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--target);
    min-width: 0;
    cursor: pointer;
}

.gym-check input {
    width: 1.375rem;
    height: 1.375rem;
    flex: none;
}

.gym-name {
    overflow-wrap: anywhere;
}

.gym-item.is-packed .gym-name {
    color: var(--text-muted);
    text-decoration: line-through;
}

.gym-actions {
    display: flex;
    gap: var(--space-2);
}

.gym-edit {
    flex: 1 1 12rem;
    min-width: 0;
}

/* Feature 031 (contracts/ui-contract.md "Gym session card", "Rest timer reset"): existing tokens only. */
.gym-session {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0.75rem 0;
}

.gym-session-line {
    margin: 0;
}

.gym-session-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.gym-session-actions .btn {
    min-height: var(--target);
    min-width: var(--target);
}

.gym-session-running {
    display: inline-flex;
    gap: 0.5rem;
    align-items: baseline;
    margin: 0;
    font-weight: 600;
}

.gym-session-elapsed {
    font-variant-numeric: tabular-nums;
}

.rest-reset {
    min-height: var(--target);
    min-width: var(--target);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
