:root {
    --bg: #0f1420;
    --surface: #182031;
    --surface-2: #202a3f;
    --border: #2c3750;
    --text: #e7ecf5;
    --muted: #93a1bd;
    --accent: #4f8cff;
    --accent-2: #35d0a5;
    --danger: #ff6b6b;
    --radius: 12px;
}

/* ---------- Themes ---------- */
/* 'dark' matches the :root defaults above; kept explicit so the attribute is always meaningful. */
body[data-theme="dark"] {
    --bg: #0f1420;
    --surface: #182031;
    --surface-2: #202a3f;
    --border: #2c3750;
    --text: #e7ecf5;
    --muted: #93a1bd;
}

body[data-theme="mid"] {
    --bg: #4a5568;
    --surface: #5a6578;
    --surface-2: #667088;
    --border: #79839c;
    --text: #f5f7fb;
    --muted: #d5dae5;
}

body[data-theme="light"] {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #eef1f8;
    --border: #d3dae6;
    --text: #171d2b;
    --muted: #5a6479;
}

body[data-text-size="small"] { font-size: .875rem; }
body[data-text-size="normal"] { font-size: 1rem; }
body[data-text-size="large"] { font-size: 1.15rem; }

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.hidden { display: none !important; }

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(6, 9, 16, .65);
    padding: 1rem;
}

.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    max-width: 420px;
    width: 100%;
}

.modal-card h3 { margin-top: 0; }
.modal-actions { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.modal-actions button { width: 100%; }
.checkout-modal-card { max-width: 760px; max-height: calc(100vh - 2rem); overflow-y: auto; }
.checkout-modal-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.checkout-modal-head p { margin: 0; }
.checkout-close { width: 2.5rem; height: 2.5rem; padding: 0; font-size: 1.4rem; flex: 0 0 auto; }
#embedded-checkout { min-height: 280px; margin-top: 1rem; }
.muted { color: var(--muted); }
.grow { flex: 1 1 auto; }

h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; }
h2 { font-size: 1.05rem; }
h3 { font-size: 1rem; }

/* ---------- Auth ---------- */
.auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.auth-card {
    width: min(420px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem;
}

/* ---------- Layout ---------- */
.topbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 5;
}

.brand { font-weight: 700; letter-spacing: .02em; display: flex; align-items: center; gap: .6rem; font-size: 1.1rem; }
.brand-logo { width: 2.5rem; height: 2.5rem; border-radius: 8px; }
.brand-logo-landscape { width: auto; height: 4.4rem; max-width: 20rem; object-fit: contain; }
.auth-card h1 { display: flex; align-items: center; justify-content: center; gap: .6rem; }
.auth-card h1 .brand-logo { width: 3rem; height: 3rem; border-radius: 10px; }

.onboarding-card { width: min(560px, 100%); }
.onboarding-question { border: none; padding: 0; margin: 0; }
.onboarding-question legend { font-weight: 600; margin-bottom: .5rem; padding: 0; }
.onboarding-option {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .6rem .8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: .5rem;
    cursor: pointer;
}
.onboarding-option:has(input:checked) { border-color: var(--accent, #4f8cff); }
.user { display: flex; align-items: center; gap: .75rem; color: var(--muted); }

.nav-toggle { display: none; }
.nav-toggle-logo { display: block; width: auto; height: 100%; object-fit: contain; }
.nav-panel { display: contents; }

main {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.25rem;
}

/* ---------- Habit tracker ---------- */
.habit-home,
.habit-detail {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}
.habit-section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}
.habit-section-head h1 { margin-bottom: .2rem; }
.habit-section-head p { margin: 0; }
.habit-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
    gap: 1px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--border);
}
.habit-metric {
    display: flex;
    flex-direction: column;
    min-height: 104px;
    padding: .85rem;
    background: var(--surface);
}
.habit-metric-value { font-size: 1.35rem; line-height: 1.2; }
.habit-metric-label {
    margin-top: .35rem;
    color: var(--muted);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.habit-metric-detail { margin-top: auto; color: var(--muted); font-size: .72rem; }
.habit-week {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: .45rem;
    margin-top: .75rem;
}
.habit-week-day {
    display: grid;
    justify-items: center;
    gap: .2rem;
    min-width: 0;
    color: var(--muted);
    font-size: .72rem;
}
.habit-day-marker {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--muted);
    font-size: .82rem;
    font-weight: 700;
}
.habit-week-day.active .habit-day-marker {
    border-color: var(--accent-2);
    background: var(--accent-2);
    color: #071b15;
}
.habit-week-day.today .habit-day-marker { outline: 2px solid var(--accent); outline-offset: 2px; }

.habit-calendar-head {
    display: grid;
    grid-template-columns: 2.5rem minmax(0, 1fr) 2.5rem auto;
    align-items: center;
    gap: .5rem;
    margin: 1.25rem 0 .75rem;
}
.habit-calendar-head h2 { margin: 0; text-align: center; }
.habit-calendar-nav { width: 2.5rem; height: 2.5rem; padding: 0; }
.habit-calendar-weekdays,
.habit-calendar {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: .35rem;
}
.habit-calendar-weekdays { margin-bottom: .35rem; }
.habit-calendar-weekdays span {
    overflow: hidden;
    color: var(--muted);
    font-size: .7rem;
    text-align: center;
    text-overflow: ellipsis;
}
.habit-calendar-cell {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
}
.habit-calendar-cell.blank { visibility: hidden; }
.habit-calendar-cell.future { opacity: .45; }
.habit-calendar-cell.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.habit-calendar-cell.active { background: color-mix(in srgb, var(--accent-2) 16%, var(--surface)); }
.habit-calendar-date { position: absolute; top: .25rem; left: .35rem; color: var(--muted); font-size: .7rem; }
.habit-calendar-marker {
    display: grid;
    place-items: center;
    width: 1.65rem;
    height: 1.65rem;
    border-radius: 50%;
    background: var(--accent-2);
    color: #071b15;
    font-size: .8rem;
    font-weight: 700;
}
.habit-calendar-count { margin-top: .2rem; color: var(--muted); font-size: .65rem; }
.habit-calendar-empty { margin: .75rem 0 0; text-align: center; }

.workout-catalog-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1.5rem;
    margin-bottom: 1.25rem;
}
.workout-catalog-head h2 { font-size: 1.6rem; }
.workout-catalog-head p { margin: 0; }
.workout-filters { display: flex; gap: .75rem; flex: 0 0 auto; }
.workout-filters label { min-width: 145px; }
.premade-workout-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}
.premade-workout-card {
    display: flex;
    flex-direction: column;
    min-height: 230px;
    position: relative;
    border-radius: 8px;
    border-top: 3px solid var(--accent);
    cursor: pointer;
}
.premade-workout-card h2 { font-size: 1.15rem; }
.premade-workout-card .primary { align-self: flex-start; margin-top: auto; }
.premade-workout-card.expanded {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 640px);
    max-height: 88vh;
    overflow-y: auto;
    z-index: 260;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
    cursor: pointer;
}
.premade-workout-card .workout-detail { margin-top: 1rem; }
.workout-facts { display: flex; flex-wrap: wrap; gap: .4rem; margin: .65rem 0; }
.workout-facts span {
    padding: .2rem .5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--muted);
    font-size: .78rem;
}
.premade-movements { color: var(--muted); font-size: .88rem; margin: 0 0 1rem; }
.difficulty-beginner { color: var(--accent-2); border-color: var(--accent-2); }
.difficulty-intermediate { color: #ffd166; border-color: #ffd166; }
.difficulty-advanced { color: var(--danger); border-color: var(--danger); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.stack { display: flex; flex-direction: column; gap: .75rem; }
.row-fields { display: flex; flex-wrap: wrap; gap: 1rem; }
.row-fields label { flex: 1 1 220px; }

.target-editor { border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin: 1rem 0; }
.target-editor legend { padding: 0 .4rem; color: var(--text); font-weight: 600; }
.target-editor > p { margin-top: 0; }
.target-row {
    display: grid;
    grid-template-columns: 1.1fr 1.6fr .8fr .8fr .8fr auto;
    align-items: end;
    gap: .5rem;
    padding: .75rem 0;
    border-top: 1px solid var(--border);
}
.target-row:first-child { border-top: 0; padding-top: 0; }
.target-row .target-remove { margin-bottom: 0; }
.target-add { align-self: flex-start; }

.theme-choices { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem 1rem; margin: 0 0 .75rem; display: flex; flex-wrap: wrap; gap: 1rem; }
.theme-choices legend { padding: 0 .4rem; color: var(--muted); font-size: .85rem; }
.theme-option { display: flex; align-items: center; gap: .5rem; width: auto; color: var(--text); font-size: .9rem; }
.theme-option input { width: auto; margin: 0; }
.theme-swatch { display: inline-block; width: 1.4rem; height: 1.4rem; border-radius: 50%; border: 1px solid var(--border); }
.theme-swatch-light { background: #f4f6fb; }
.theme-swatch-mid { background: #4a5568; }
.theme-swatch-dark { background: #0f1420; }
.checkbox-field { display: flex; align-items: center; gap: .5rem; width: auto; }
.checkbox-field input { width: auto; margin: 0; }
.public-template-controls { display: inline-flex; align-items: flex-end; gap: .75rem; flex-wrap: wrap; }
.public-template-controls label { min-width: 150px; }
.add-exercise { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.actions { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 2rem; }

.workout-builder-card > .row-fields { margin-bottom: .75rem; }
.workout-builder-card .add-exercise { padding-top: 1rem; border-top: 1px solid var(--border); }
.builder-actions { margin: 1rem 0 0; padding-top: 1rem; border-top: 1px solid var(--border); }
#entries .entry { padding: 1rem 0; border-top: 1px solid var(--border); }
#entries .entry:last-child { padding-bottom: 1rem; }
#admin-entries .entry {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

/* ---------- Controls ---------- */
label {
    display: block;
    font-size: .85rem;
    color: var(--muted);
}

input, select, textarea {
    width: 100%;
    margin-top: .3rem;
    padding: .55rem .7rem;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

button {
    font: inherit;
    border-radius: 8px;
    border: 1px solid transparent;
    padding: .55rem 1rem;
    cursor: pointer;
}

.primary { background: var(--accent); color: #fff; }
.primary:hover { filter: brightness(1.1); }
.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.secondary:hover { border-color: var(--accent); }
.ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.ghost:hover { color: var(--text); }
.ghost.danger:hover { color: var(--danger); border-color: var(--danger); }

.tabs { display: flex; gap: .25rem; flex-wrap: wrap; }

.tab {
    background: transparent;
    color: var(--muted);
    border: 1px solid transparent;
    padding: .45rem .9rem;
}

.tab.active {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border);
}

.error { color: var(--danger); min-height: 1.25rem; margin: .75rem 0 0; }
.message { color: var(--accent-2); font-size: .9rem; }

.link-button {
    background: none;
    border: none;
    color: var(--muted);
    padding: 0;
    text-decoration: underline;
    font-size: .85rem;
}
.link-button:hover { color: var(--text); }

.invite-box {
    margin: .5rem 0 1rem;
    padding: .75rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.invite-box input { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; }

.badge {
    display: inline-block;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: .1rem .4rem;
    border-radius: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
    margin-left: .4rem;
}
.badge.pending { color: var(--accent-2); border-color: var(--accent-2); }
.badge.admin { color: var(--accent); border-color: var(--accent); }
.badge.completed { color: var(--accent-2); border-color: var(--accent-2); }
.badge.member { color: gold; border-color: gold; }

.admin-user { flex-wrap: wrap; }
.admin-user .tabs { margin-top: .3rem; }

/* ---------- Sets table ---------- */
.entry-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }

.entry-drag-handle {
    cursor: grab;
    color: var(--muted);
    padding: 0 .3rem;
    user-select: none;
    touch-action: none;
    flex: 0 0 auto;
}
.entry.dragging { opacity: .4; }
.entry.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }

.entry-reorder { display: flex; gap: .3rem; }
.entry-reorder button {
    width: 2rem;
    padding: 0;
    line-height: 1;
}
.entry-reorder button:disabled { opacity: .3; cursor: not-allowed; }

/* ---------- Current-workout summary (browse view), as a pull-up bottom sheet ---------- */
.workout-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0 auto;
    width: min(480px, 100%);
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, .45);
    z-index: 50;
    overflow: hidden;
    transition: max-height .2s ease;
}
.workout-sheet:not(.expanded) { max-height: 3.1rem; }
.workout-sheet-handle {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    flex: 0 0 auto;
    padding: .7rem 1rem;
    background: none;
    border: none;
    color: var(--text);
    font-weight: 600;
    font-size: 1rem;
    text-align: left;
    cursor: pointer;
}
.workout-sheet-chevron {
    margin-left: auto;
    color: var(--muted);
    transition: transform .2s ease;
}
.workout-sheet.expanded .workout-sheet-chevron { transform: rotate(180deg); }
.workout-sheet-body {
    overflow-y: auto;
    padding: 0 1rem 1rem;
}

.workout-summary-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .4rem 0;
    border-bottom: 1px solid var(--border);
}
.workout-summary-row.dragging { opacity: .4; }
.workout-summary-row.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.workout-summary-drag {
    cursor: grab;
    color: var(--muted);
    padding: 0 .2rem;
    user-select: none;
    touch-action: none;
    flex: 0 0 auto;
}
.workout-summary-row:last-child { border-bottom: none; }
.workout-summary-name { flex: 1 1 auto; }
.workout-summary-actions { display: flex; gap: .3rem; flex: 0 0 auto; }
.workout-summary-actions button {
    width: 2rem;
    padding: 0;
    line-height: 1;
}
.workout-summary-actions button:disabled { opacity: .3; cursor: not-allowed; }

table.sets { width: 100%; border-collapse: collapse; margin: .5rem 0 .75rem; }
table.sets th {
    text-align: left;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    padding: .25rem .4rem;
    font-weight: 600;
}
table.sets td { padding: .2rem .4rem; }
table.sets td input { margin-top: 0; }
table.sets td:first-child { width: 4.5rem; color: var(--muted); }
table.sets td:last-child { width: 3rem; }

.set-remove {
    background: transparent;
    border: none;
    color: var(--muted);
    padding: .25rem .5rem;
}
.set-remove:hover { color: var(--danger); }

.entry-timed { white-space: nowrap; }
.entry:not(.timed-entry) .col-duration { display: none; }
.timed-entry .col-reps, .timed-entry .col-weight { display: none; }

/* ---------- Workout player ---------- */
.player {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.player-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.player-topbar h2 { margin: 0; font-size: 1rem; text-align: center; flex: 1 1 auto; }
.player-topbar-actions { display: flex; gap: .5rem; }

.player-hr { display: flex; align-items: center; }
.player-hr-live { display: flex; align-items: center; gap: .4rem; font-size: 1.1rem; font-weight: 600; }
.player-hr-dot {
    width: .6rem;
    height: .6rem;
    border-radius: 50%;
    background: #6a9e4a;
    animation: player-hr-pulse 1s ease-in-out infinite;
}
.player-hr-dot.zone-warmup { background: #6a9e4a; }
.player-hr-dot.zone-moderate { background: #d1a53a; }
.player-hr-dot.zone-hard { background: #d16a3a; }
.player-hr-dot.zone-max { background: #c23a3a; }

@keyframes player-hr-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .5; transform: scale(.8); }
}

.player-elapsed { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.player-elapsed-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
#player-elapsed { font-size: 1.1rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.player-body {
    flex: 1 1 auto;
    padding: 1.25rem;
    max-width: 560px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.player-neighbor {
    display: flex;
    justify-content: space-between;
    gap: .5rem;
    font-size: .9rem;
}
.player-neighbor-label {
    text-transform: uppercase;
    font-size: .7rem;
    letter-spacing: .04em;
    color: var(--muted);
}

.player-current-head { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.player-current-head h3 { margin: 0; }
.player-current-head img.entry-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }

.player-timer-panel, .player-set-panel { text-align: center; padding: .5rem 0; }
.player-timer-caption {
    text-transform: uppercase;
    font-size: .75rem;
    letter-spacing: .06em;
    color: var(--muted);
    margin: 0 0 .25rem;
}
.player-timer-display {
    font-size: 3rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin-bottom: .75rem;
}
.player-timer-panel .actions, .player-set-panel .actions { justify-content: center; margin-bottom: 0; }

.player-step-nav { justify-content: space-between; margin-top: .75rem; margin-bottom: 0; }

.player-jump-list { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.player-jump-chip {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
    border-radius: 999px;
    padding: .4rem .8rem;
    font-size: .85rem;
    cursor: pointer;
}
.player-jump-chip.active { border-color: var(--accent); color: var(--text); }

/* ---------- RPE slider ---------- */
.rpe-field { display: block; margin-top: .75rem; }
/* Clips the widened slider below so the thumb's travel reaches the true visual edges, not the browser's default inset. */
.rpe-track {
    overflow: hidden;
    border-radius: 999px;
    height: 22px;
    display: flex;
    align-items: center;
    margin: .5rem 0 .3rem;
}
.rpe-slider {
    -webkit-appearance: none;
    appearance: none;
    display: block;
    width: calc(100% + 22px);
    margin: 0 -11px;
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(90deg, #35d0a5, #ffd166, #ff6b6b);
    outline: none;
}
.rpe-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--text);
    border: 3px solid var(--surface);
    box-shadow: 0 0 0 1px var(--border);
    cursor: pointer;
}
.rpe-slider::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--text);
    border: 3px solid var(--surface);
    box-shadow: 0 0 0 1px var(--border);
    cursor: pointer;
}
.rpe-scale-labels {
    display: flex;
    justify-content: space-between;
    font-size: .75rem;
    color: var(--muted);
}

/* ---------- History ---------- */
.workout-item { cursor: pointer; }
.workout-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.workout-meta { color: var(--muted); font-size: .85rem; }
.workout-detail { margin-top: .75rem; border-top: 1px solid var(--border); padding-top: .75rem; }
.detail-exercise { margin-bottom: .6rem; }
.detail-sets { color: var(--muted); font-size: .9rem; }

/* ---------- Progress ---------- */.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.chart-header { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; align-items: flex-end; }
.chart-header label { flex: 1 1 200px; }
.progress-hr-toggle { flex: 0 0 auto; display: flex; align-items: center; gap: .4rem; white-space: nowrap; }

.hr-breakdown-list { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: .25rem; }
.hr-breakdown-list li { font-size: .9rem; color: var(--muted); }
.hr-breakdown-list li.hr-spike { color: inherit; font-weight: 600; }

.detail-hr { font-size: .85rem; color: var(--muted); }
.detail-hr.hr-spike { color: inherit; font-weight: 600; }

/* ---------- Admin ---------- */
.admin-tabs {
    display: flex;
    gap: .25rem;
    overflow-x: auto;
    margin-bottom: 1rem;
    padding-bottom: .25rem;
    border-bottom: 1px solid var(--border);
}
.admin-tabs .tab { white-space: nowrap; }
.profile-tabs {
    display: flex;
    gap: .25rem;
    overflow-x: auto;
    margin-bottom: 1rem;
    padding-bottom: .25rem;
    border-bottom: 1px solid var(--border);
}
.profile-tabs .tab { white-space: nowrap; }

.admin-user {
    display: flex;
    flex-direction: column;
    gap: .1rem;
    padding: .5rem 0;
    border-bottom: 1px solid var(--border);
}
.admin-user:last-child { border-bottom: none; }
.member-name-button {
    align-self: flex-start;
    background: transparent;
    color: var(--text);
    border: none;
    padding: 0;
    font-weight: 600;
    text-align: left;
}
.member-name-button:hover { color: var(--accent); }

.account-details {
    display: grid;
    grid-template-columns: minmax(8rem, auto) 1fr;
    gap: .5rem 1rem;
    margin: 1rem 0;
}
.account-details dt { color: var(--muted); }
.account-details dd { margin: 0; overflow-wrap: anywhere; }

.prescribed-item { border-left: 3px solid var(--accent-2); }
#prescribed .card { margin-bottom: .75rem; }
#prescribed .card:last-child { margin-bottom: 0; }
#templates .card { margin-bottom: .75rem; }
#templates .card:last-child { margin-bottom: 0; }

.archived { opacity: .6; }

.inline-check {
    display: flex;
    align-items: center;
    gap: .4rem;
    white-space: nowrap;
    padding-bottom: .6rem;
}
.inline-check input { width: auto; margin: 0; }

.library-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .5rem 0;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.library-item:last-child { border-bottom: none; }

.day-picker { display: flex; flex-wrap: wrap; gap: .75rem; margin: -.25rem 0 .75rem; }

.card.nested { background: var(--surface-2); margin-top: .75rem; box-shadow: none; }

.button-like {
    display: inline-block;
    text-decoration: none;
    font: inherit;
    border-radius: 8px;
    border: 1px solid transparent;
    padding: .55rem 1rem;
    cursor: pointer;
}

.schedule-item { border-left: 3px solid var(--accent); }

.autocomplete-list {
    position: fixed;
    z-index: 200;
    margin: 0;
    padding: .25rem;
    list-style: none;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 240px;
    overflow-y: auto;
    box-shadow: 0 12px 28px rgba(0, 0, 0, .3);
}
.autocomplete-list.hidden { display: none; }
.autocomplete-option {
    padding: .55rem .65rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: .95rem;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: .5rem;
}
.autocomplete-option:hover,
.autocomplete-option.active { background: var(--accent); color: #fff; }
.autocomplete-hint {
    font-size: .75rem;
    color: var(--muted);
    white-space: nowrap;
}
.autocomplete-option.active .autocomplete-hint { color: inherit; opacity: .8; }
.autocomplete-empty {
    padding: .55rem .65rem;
    color: var(--muted);
    font-size: .85rem;
}

@media (max-width: 700px) {
    .habit-section-head { align-items: stretch; flex-direction: column; }
    .habit-section-head button { align-self: flex-start; }
    .habit-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    #habit-detail-metrics .habit-metric:last-child { grid-column: 1 / -1; }
    .habit-metric { min-height: 96px; }
    .habit-week { gap: .2rem; }
    .habit-day-marker { width: 1.8rem; height: 1.8rem; }
    .habit-calendar-head { grid-template-columns: 2.5rem minmax(0, 1fr) 2.5rem; }
    .habit-calendar-head #habit-calendar-today { grid-column: 1 / -1; justify-self: center; }
    .habit-calendar-weekdays, .habit-calendar { gap: .2rem; }
    .habit-calendar-cell { border-radius: 4px; }
    .habit-calendar-marker { width: 1.4rem; height: 1.4rem; }
    .habit-calendar-count { display: none; }
    .workout-catalog-head { align-items: stretch; flex-direction: column; gap: 1rem; }
    .workout-filters { flex-wrap: wrap; }
    .workout-filters label { flex: 1 1 130px; min-width: 0; }
    .premade-workout-grid { grid-template-columns: 1fr; }
    .target-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .target-row label:nth-child(2) { grid-column: 1 / -1; }
    .target-row .target-remove { justify-self: start; }
}



.library-thumb {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    flex: 0 0 auto;
}
.library-thumb.placeholder { visibility: hidden; }

.entry-title { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.entry-thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
}
.entry-video { color: var(--accent); font-size: .8rem; }

#library-search { margin-bottom: .5rem; }

/* ---------- Exercise library management (admin) ---------- */
.library-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    padding: .6rem 0;
    border-bottom: 1px solid var(--border);
}
.library-row:last-child { border-bottom: none; }
.library-row-thumb {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
}
.library-row-info { flex: 1 1 220px; min-width: 0; }
.library-row-info strong { display: block; }
.library-row-actions { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.library-row-actions .file-button { position: relative; overflow: hidden; }
.library-row-actions .file-button input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.csv-column-order {
    padding: .75rem;
    overflow-wrap: anywhere;
    border-left: 3px solid var(--accent);
    background: var(--surface-2);
}
.csv-column-order code,
.csv-example pre { font-family: ui-monospace, Consolas, monospace; }
.csv-example { margin-bottom: 1rem; }
.csv-example summary,
.csv-import-report summary { cursor: pointer; color: var(--text); }
.csv-example pre {
    max-width: 100%;
    margin: .6rem 0 0;
    padding: .75rem;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: .78rem;
    white-space: pre;
}
.csv-upload-row { align-items: flex-end; }
.csv-upload-row button { margin-bottom: 0; }
.csv-import-report:empty { display: none; }
.csv-import-report { margin-top: .75rem; }
.csv-import-report p { margin: 0 0 .5rem; }
.csv-import-report details { margin-top: .35rem; }
.csv-import-report ul {
    max-height: 12rem;
    margin: .4rem 0 0;
    padding-left: 1.4rem;
    overflow-y: auto;
    color: var(--muted);
    font-size: .85rem;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 480px);
    z-index: 260;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}

/* ---------- Browse exercises ---------- */
.browse-filter-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .75rem;
    margin-top: .75rem;
}

.exercise-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
}
.exercise-card { display: flex; flex-direction: column; gap: .5rem; position: relative; cursor: pointer; }
.exercise-card-thumb {
    width: 100%;
    height: 140px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.exercise-card-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: .05em;
}
.exercise-card-tags .badge:first-child { margin-left: 0; }
.exercise-card .actions { margin-bottom: 0; cursor: auto; }
.exercise-card .actions button,
.exercise-card .actions a { cursor: pointer; }

.exercise-card-favorite {
    position: absolute;
    top: .6rem;
    right: .6rem;
    width: 2.1rem;
    height: 2.1rem;
    padding: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, .45);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .3);
    font-size: 1.1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}
.exercise-card-favorite.active { color: gold; border-color: gold; }
.exercise-card-favorite:hover { filter: brightness(1.2); }

.browse-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .65);
    z-index: 250;
}
.browse-backdrop.hidden { display: none; }

.exercise-card.expanded {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 640px);
    max-height: 88vh;
    overflow-y: auto;
    z-index: 260;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
    cursor: default;
}
.exercise-card.expanded .exercise-card-thumb { height: 260px; }

@media (max-width: 640px) {
    .topbar { flex-wrap: nowrap; justify-content: space-between; }
    .brand { min-width: 0; }
    .brand-logo-landscape { height: 3.2rem; max-width: calc(100vw - 6.8rem); }
    main { padding: .75rem; }
    .browse-filter-row { grid-template-columns: repeat(2, 1fr); }

    .nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 3.2rem;
        height: 3.2rem;
        padding: .2rem;
        flex: 0 0 auto;
    }
    .nav-panel {
        display: block;
        position: fixed;
        top: 3.5rem;
        right: .75rem;
        left: .75rem;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: .75rem;
        box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
        z-index: 30;
        max-height: calc(100vh - 4.5rem);
        overflow-y: auto;
        transform-origin: top right;
        transform: scale(.95);
        opacity: 0;
        pointer-events: none;
        transition: opacity .15s ease, transform .15s ease;
    }
    .nav-panel.open {
        opacity: 1;
        transform: scale(1);
        pointer-events: auto;
    }
    .nav-panel .tabs { flex-direction: column; align-items: stretch; }
    .nav-panel .user {
        margin-top: .75rem;
        padding-top: .75rem;
        border-top: 1px solid var(--border);
        justify-content: space-between;
    }
}
/* ---------- Direct target setup ---------- */
.saved-target-section { margin: 1rem 0 1.5rem; }
.saved-target-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius); }
.saved-target-row > div { min-width: 0; overflow-wrap: anywhere; }
.saved-target-row h4, .saved-target-row p { margin: 0; }
.saved-target-row p { font-size: .85rem; margin-top: .25rem; }
.saved-target-row button { flex-shrink: 0; }
.goal-target-card + .goal-target-card { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.direct-target-invite, .direct-target-section { padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); margin-bottom: 1rem; }
.direct-target-invite p { margin: 0 0 .65rem; }
.direct-target-section > .muted { margin-top: 0; }
.direct-target-form .row-fields > label { flex: 1 1 140px; min-width: 0; }
.direct-target-hint, .direct-target-message { margin: 0; font-size: .85rem; }
.direct-target-message:empty { display: none; }

/* ---------- Goal celebration ---------- */
.goal-summary { position: relative; overflow: hidden; background: radial-gradient(ellipse at 100% 0, #4f8cff20, transparent 65%), var(--surface); }
.goal-summary .habit-section-head { position: relative; gap: 1rem; }
.goal-summary #goal-summary-focus { margin-bottom: 0; }
.goal-visual { display: flex; align-items: center; gap: 2rem; padding: 1.25rem 0 .5rem; }
.goal-dial { position: relative; width: 176px; height: 176px; flex: 0 0 176px; }
.goal-dial svg { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.goal-dial circle { fill: none; stroke-width: 10; }
.goal-ring-track { stroke: var(--border); }
.goal-ring-fill { stroke: var(--accent-2); stroke-linecap: round; filter: drop-shadow(0 0 5px #35d0a540); animation: goal-ring-enter 900ms ease-out both; }
.goal-dial-caption { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.goal-dial-caption strong { font-size: 2.5rem; line-height: 1.2; letter-spacing: -.04em; }
.goal-dial-caption span { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.goal-detail { flex: 1; min-width: 0; }
.goal-eyebrow { font-size: .7rem; font-weight: 800; letter-spacing: .13em; color: var(--text); }
.goal-detail .goal-cheer { font-size: clamp(1.2rem, 3vw, 1.65rem); margin: .25rem 0; }
.goal-name { margin: 0 0 1rem; overflow-wrap: anywhere; }
.goal-milestones { display: flex; gap: .4rem; margin: .75rem 0 1rem; }
.goal-milestones span { flex: 1; border-top: 4px solid var(--border); padding-top: .3rem; font-size: .7rem; color: var(--muted); }
.goal-milestones .is-reached { border-color: var(--accent-2); color: var(--text); }
.goal-numbers { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .6rem; margin: 0; }
.goal-numbers > div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: .65rem .8rem; }
.goal-numbers dt { color: var(--muted); font-size: .75rem; }
.goal-numbers dd { margin: .15rem 0 0; font-size: 1.05rem; font-weight: 700; overflow-wrap: anywhere; }
.goal-source { font-size: .75rem; margin: .75rem 0 0; }
.goal-achieved .goal-dial { background: radial-gradient(circle, #f6c85b22, transparent 70%); }
.goal-achieved .goal-ring-fill { stroke: #f6c85b; filter: drop-shadow(0 0 7px #f6c85b55); }
.goal-achieved .goal-dial-caption strong { color: #f6c85b; font-size: 3.5rem; }
body[data-theme="light"] .goal-achieved .goal-dial-caption strong { color: #946400; }
@keyframes goal-ring-enter { from { stroke-dasharray: 0 100; } }
@media (prefers-reduced-motion: reduce) { .goal-ring-fill { animation: none; } }
@media (max-width: 560px) {
    .goal-visual { flex-direction: column; gap: .75rem; align-items: stretch; }
    .goal-dial { align-self: center; width: 152px; height: 152px; flex-basis: 152px; }
    .goal-detail .goal-eyebrow, .goal-detail .goal-cheer, .goal-name { display: block; text-align: center; }
    .goal-numbers { gap: .35rem; }
    .goal-numbers > div { padding: .5rem; }
    .goal-numbers dd { font-size: .9rem; }
}
