@import url('https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,700&family=DM+Mono:wght@500&display=swap');

/* Theme tokens, ported from prototypes/theme.css. Every colour in the rules below comes from here. */
:root {
    /* surfaces */
    --bg: #f4f4f0;
    --surface: #ffffff;
    --surface-sunk: #ebebe6;
    --line: #000000;

    /* text */
    --fg: #000000;
    --muted: #4d4d4d;
    --faint: #8a8a85;
    --on-dark: #ffffff;

    /* accent */
    --accent: #ff90e8;
    --accent-ink: #000000;

    /* style tags */
    --tag-hiit: #ff90e8;
    --tag-bodybuilding: #ffc900;
    --tag-hybrid: #23a094;
    --tag-hybrid-ink: #ffffff;
    --tag-custom: #ffffff;

    /* states */
    --danger: #dc341e;
    --today: #fff3b0;
    --focus: var(--accent);
    --scrim: rgba(0, 0, 0, 0.35);

    /* borders and lift */
    --border: 1px solid var(--line);
    --radius: 4px;
    --lift: 4px 4px 0 var(--line);
    --lift-move: translate(-4px, -4px);

    /* type */
    --font-sans: 'DM Sans', system-ui, sans-serif;
    --font-mono: 'DM Mono', ui-monospace, monospace;
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-md: 1rem;
    --text-lg: 1.25rem;
    --text-xl: 1.75rem;
    --text-xxl: 3rem;

    /* spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 1rem;
    --space-4: 1.5rem;
    --space-5: 2.5rem;
    --space-6: 4rem;
}

/* ---- base ---- */
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font-sans); font-size: var(--text-md); line-height: 1.5; }
h1, h2, h3 { margin: 0; line-height: 1.1; font-weight: 700; }
h1 { font-size: var(--text-xxl); letter-spacing: -0.02em; }
h2 { font-size: var(--text-xl); letter-spacing: -0.01em; }
h3 { font-size: var(--text-lg); }
h1:focus { outline: none; }
p { margin: 0; }
a { color: var(--fg); }
.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); }
.small { font-size: var(--text-sm); }
.stack > * + * { margin-top: var(--space-3); }
.row { display: flex; align-items: center; gap: var(--space-2); }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ---- app shell ---- */
.topbar { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-3) var(--space-4); background: var(--surface); border-bottom: var(--border); }
/* A long name shortens here, so Sign out never leaves the screen. */
.topbar-user { min-width: 0; max-width: 100%; }
.topbar-user > :not(.topbar-name) { flex: none; }
.topbar-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { font-weight: 700; font-size: var(--text-lg); text-decoration: none; display: flex; align-items: center; gap: var(--space-2); }
.brand-mark { width: 32px; height: 32px; flex: none; }
.nav { display: flex; gap: var(--space-1); }
.nav a { text-decoration: none; padding: var(--space-2) var(--space-3); border-radius: var(--radius); border: 1px solid transparent; font-weight: 500; }
.nav a.active { border: var(--border); background: var(--bg); }
.nav a:hover { border: var(--border); }
.avatar { width: 36px; height: 36px; border: var(--border); border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--tag-bodybuilding); font-size: var(--text-sm); }
.page { max-width: 76rem; margin: 0 auto; padding: var(--space-5) var(--space-4); }
.page-head { display: flex; align-items: flex-end; gap: var(--space-3); margin-bottom: var(--space-4); }

/* ---- login layout ---- */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: var(--space-3); }
.login-card { width: min(26rem, 100%); }
.login-card .brand { margin-bottom: var(--space-2); }
.login-slogan { margin: 0 0 var(--space-4); }
.form-error { color: var(--danger); font-weight: 500; font-size: var(--text-sm); }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; gap: var(--space-2); font: inherit; font-weight: 700; padding: 0.7rem 1.1rem; border: var(--border); border-radius: var(--radius); background: var(--surface); color: var(--fg); cursor: pointer; text-decoration: none; transition: transform 0.12s, box-shadow 0.12s; }
.btn:hover, .btn:focus-visible { box-shadow: var(--lift); transform: var(--lift-move); outline: none; }
.btn:disabled { cursor: progress; box-shadow: none; transform: none; opacity: 0.7; }
.btn.primary { background: var(--fg); color: var(--on-dark); }
.btn.accent { background: var(--accent); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { border: var(--border); box-shadow: none; transform: none; }
.btn.sm { padding: 0.35rem 0.7rem; font-size: var(--text-sm); }
.btn.block { width: 100%; justify-content: center; }
.btn.danger { color: var(--danger); }
.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border: var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; font: inherit; font-weight: 700; }

/* ---- cards ---- */
.card { background: var(--surface); border: var(--border); border-radius: var(--radius); padding: var(--space-4); }
.card.link { display: block; text-decoration: none; transition: transform 0.12s, box-shadow 0.12s; }
.card.link:hover { box-shadow: var(--lift); transform: var(--lift-move); }
.grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); }

/* ---- workouts ---- */
.wcard { position: relative; display: flex; flex-direction: column; gap: var(--space-3); min-height: 11rem; transition: transform 0.12s, box-shadow 0.12s; }
.wcard:hover, .wcard:focus-within { box-shadow: var(--lift); transform: var(--lift-move); }
.wcard h3 { overflow-wrap: anywhere; }
.wcard h3 a { color: inherit; text-decoration: none; outline: none; }
/* The title link covers the whole card; the action buttons sit above it. */
.wcard h3 a::after { content: ""; position: absolute; inset: 0; }
.wcard .actions { position: relative; z-index: 1; display: flex; gap: var(--space-2); }
.wcard p { overflow-wrap: anywhere; }
.search-field { width: 100%; max-width: 16rem; }
.new-workout-bar { align-items: flex-end; gap: var(--space-3); }
.new-workout-bar .field { flex: 1; min-width: min(16rem, 100%); }
.workout-title { overflow-wrap: anywhere; }
.wcard .meta { display: flex; gap: var(--space-2); align-items: center; margin-top: auto; }
.styles { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); }
.style-card { min-height: 12rem; display: flex; flex-direction: column; gap: var(--space-3); text-align: left; font: inherit; color: var(--fg); cursor: pointer; transition: transform 0.12s, box-shadow 0.12s; }
.style-card:hover, .style-card:focus-visible, .style-card.picked { box-shadow: var(--lift); transform: var(--lift-move); outline: none; }
.style-card.picked { border-width: 2px; }
.style-card .swatch-bar { height: 4.5rem; border: var(--border); border-radius: var(--radius); }
.swatch-bar.hiit { background: var(--tag-hiit); }
.swatch-bar.bodybuilding { background: var(--tag-bodybuilding); }
.swatch-bar.hybrid { background: var(--tag-hybrid); }
.swatch-bar.plain { background: var(--surface-sunk); }

/* ---- tags ---- */
.tag { display: inline-block; padding: 0.1rem 0.55rem; border: var(--border); border-radius: 999px; font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; background: var(--tag-custom); }
.tag.hiit { background: var(--tag-hiit); }
.tag.bodybuilding { background: var(--tag-bodybuilding); }
.tag.hybrid { background: var(--tag-hybrid); color: var(--tag-hybrid-ink); }
.tag.plain { background: var(--surface-sunk); }
.tag.coach { background: var(--accent); }
.inline-tag { margin-left: var(--space-2); }
.tag.inactive { background: transparent; color: var(--muted); border-style: dashed; }

/* ---- forms ---- */
label.field { display: block; }
label.field > span { display: block; font-weight: 700; font-size: var(--text-sm); margin-bottom: var(--space-1); }
.input, select.input, textarea.input { width: 100%; font: inherit; padding: 0.6rem 0.75rem; border: var(--border); border-radius: var(--radius); background: var(--surface); color: var(--fg); }
.input:focus, .input.is-focus { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.input.sm { padding: 0.35rem 0.5rem; font-size: var(--text-sm); }
.validation-message { color: var(--danger); font-size: var(--text-sm); margin-top: var(--space-1); }

/* ---- tabs ---- */
.tabs { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.tab { font: inherit; font-weight: 500; padding: var(--space-2) var(--space-3); border: var(--border); border-radius: 999px; background: var(--surface); color: var(--fg); cursor: pointer; }
.tab.active { background: var(--fg); color: var(--on-dark); }
.tab:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }

/* ---- table ---- */
.table-wrap { overflow-x: auto; position: relative; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: var(--border); border-radius: var(--radius); }
.table th, .table td { border: var(--border); padding: var(--space-2); text-align: left; vertical-align: top; }
.table th { font-size: var(--text-sm); background: var(--bg); }
.table td.actions { white-space: nowrap; }

/* ---- dialog ---- */
.scrim { position: fixed; inset: 0; background: var(--scrim); display: grid; place-items: center; padding: var(--space-3); z-index: 100; }
.dialog { width: min(34rem, 100%); max-height: calc(100vh - 2 * var(--space-3)); overflow-y: auto; background: var(--surface); border: var(--border); border-radius: var(--radius); box-shadow: 8px 8px 0 var(--line); padding: var(--space-4); }
.form-success { color: var(--fg); font-weight: 500; font-size: var(--text-sm); }

/* ---- whiteboard pieces (shared with the 4d read view) ---- */
.board-letter { font-family: var(--font-mono); font-weight: 500; background: var(--fg); color: var(--on-dark); border-radius: var(--radius); padding: 0 0.4rem; font-size: var(--text-sm); }
.board-format { font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; font-size: var(--text-sm); }
.board { background: var(--surface); border: var(--border); border-radius: var(--radius); overflow-wrap: anywhere; }
.board-head { padding: var(--space-4); border-bottom: var(--border); }
.board-block { padding: var(--space-3) var(--space-4); border-bottom: var(--border); }
.board-block:last-child { border-bottom: none; }
.board-label { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-2); margin-bottom: var(--space-2); }
.board-text { white-space: pre-line; }
.board ul { list-style: none; margin: 0; padding: 0; }
.board li { display: flex; gap: var(--space-2); padding: 0.2rem 0; }
/* A 20-character reps value wraps here rather than squeezing the exercise name into a thin column. */
.board li .qty { font-family: var(--font-mono); min-width: 5.5rem; max-width: 50%; }
.board li .ss { font-family: var(--font-mono); font-size: var(--text-xs); border: var(--border); border-radius: 3px; padding: 0 0.3rem; height: fit-content; }
.board li .board-row { flex: 1; min-width: 0; }

/* ---- builder with live preview ---- */
.workout-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); align-items: start; }
.preview-head { margin-bottom: var(--space-2); }
@media (min-width: 1101px) {
    .workout-layout { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
    /* Scrolls on its own, and stops short of the screen bottom so a two-line save bar never covers its last row. */
    .preview { position: sticky; top: var(--space-3); max-height: calc(100vh - 8rem); overflow-y: auto; }
}

/* ---- builder (ported from prototypes/builder.html) ---- */
/* clip, not hidden: wide tables never scroll the page, and the sticky save bar outside still works. */
.builder { overflow-x: clip; }
.block { background: var(--surface); border: var(--border); border-radius: var(--radius); }
.block + .block { margin-top: var(--space-3); }
.block-head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); padding: var(--space-2) var(--space-3); border-bottom: var(--border); background: var(--bg); border-radius: var(--radius) var(--radius) 0 0; }
.block-head .block-title { width: auto; flex: 1 1 8rem; max-width: 16rem; }
.block-body { padding: var(--space-3); }
/* relative so the absolutely positioned sr-only header stays inside the scroll area and cannot widen the page. */
.items-wrap { position: relative; overflow-x: auto; }
/* An open dropdown must not be cut off by the scrolling wrapper. */
.items-wrap:has(.dropdown) { overflow: visible; }
.items { width: 100%; border-collapse: collapse; }
.items th { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); text-align: left; padding: 0 var(--space-1) var(--space-1); white-space: nowrap; }
.items td { padding: var(--space-1); vertical-align: middle; }
.items td.ex { width: 40%; min-width: 10rem; }
.items .row-errors td { padding-top: 0; }
.items .row-actions { white-space: nowrap; }
.items .load { display: flex; gap: var(--space-1); }
.items .w-sets { width: 3.6rem; }
.items .w-reps { width: 4.5rem; }
.items .w-load { width: 4.4rem; }
.items .w-unit { width: 4.8rem; }
.items .w-rest { width: 4rem; }
.items .w-amount { width: 4.8rem; }
.items .w-measure { width: 4.6rem; }
.items .w-note { width: 9rem; }
/* Labels stay on one line and inputs share a bottom edge, so the fields in a row line up. */
.params { display: flex; align-items: flex-end; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-3); }
.params label.field { width: 9.5rem; }
.params label.field > span { white-space: nowrap; }
.params-error { margin-bottom: var(--space-2); }
.ss-pick { width: 2.4rem; text-align: center; text-transform: uppercase; }
.add-item { margin-top: var(--space-2); }
.icon-btn:disabled { cursor: default; opacity: 0.35; }
.picker { position: relative; }
.dropdown { position: absolute; left: 0; top: calc(100% + 2px); min-width: min(18rem, calc(100vw - 4rem)); background: var(--surface); border: var(--border); border-radius: var(--radius); box-shadow: var(--lift); z-index: 5; }
.dropdown [role="option"] { padding: var(--space-2) var(--space-3); display: flex; gap: var(--space-2); align-items: center; font-size: var(--text-sm); cursor: pointer; }
.dropdown [role="option"].hi, .dropdown [role="option"]:hover { background: var(--accent); }
.dropdown .add { color: var(--muted); }
.add-block { border: 1px dashed var(--line); border-radius: var(--radius); padding: var(--space-3); margin-top: var(--space-3); background: var(--surface); }
.formats { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: var(--space-2); margin-top: var(--space-3); }
.format { font: inherit; color: var(--fg); text-align: left; border: var(--border); border-radius: var(--radius); padding: var(--space-2) var(--space-3); background: var(--surface); cursor: pointer; transition: transform 0.12s, box-shadow 0.12s; }
.format:hover, .format:focus-visible { box-shadow: var(--lift); transform: var(--lift-move); outline: none; }
.format b { display: block; }
.format span { font-size: var(--text-xs); color: var(--muted); }
.savebar { position: sticky; bottom: 0; z-index: 10; display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2) var(--space-3); padding: var(--space-3); background: var(--tag-bodybuilding); border: var(--border); border-radius: var(--radius); }

/* ---- schedule (ported from prototypes/schedule.html) ---- */
.week-head { flex-wrap: wrap; }
.week { table-layout: fixed; min-width: 60rem; }
.week th:first-child, .week td:first-child { width: 11rem; }
.week td { height: 5.5rem; }
.week th.today, .week td.today { background: var(--today); }
.week[aria-busy="true"] { opacity: 0.6; }
.person { display: flex; align-items: center; gap: var(--space-2); font-weight: 700; overflow-wrap: anywhere; }
.person .avatar { flex: none; }
.chip { display: block; width: 100%; border: var(--border); border-radius: var(--radius); padding: 0.15rem 0.4rem; font: inherit; font-size: var(--text-xs); font-weight: 700; color: var(--fg); text-align: left; margin-bottom: var(--space-1); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: transform 0.12s, box-shadow 0.12s; }
.chip:hover, .chip:focus-visible { box-shadow: var(--lift); transform: var(--lift-move); outline: none; }
.chip.hiit { background: var(--tag-hiit); }
.chip.bodybuilding { background: var(--tag-bodybuilding); }
.chip.hybrid { background: var(--tag-hybrid); color: var(--tag-hybrid-ink); }
.chip.plain { background: var(--surface-sunk); }
.schedule-status:not(:empty) { margin-bottom: var(--space-3); }
.schedule-hint { margin-top: var(--space-2); }
.picker-group { border: none; margin-inline: 0; margin-bottom: 0; padding: 0; min-width: 0; }
.picker-group legend { padding: 0; font-weight: 700; font-size: var(--text-sm); margin-bottom: var(--space-1); }
.people { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
.check { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border: var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; }
.check.on { background: var(--accent); }
.check:focus-within { box-shadow: 0 0 0 3px var(--focus); }
.check-name { min-width: 0; overflow-wrap: anywhere; }
.box { flex: none; width: 18px; height: 18px; border: var(--border); border-radius: 3px; background: var(--surface); display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--space-1); }
.day { font: inherit; color: var(--fg); border: var(--border); border-radius: var(--radius); padding: var(--space-1) 0; text-align: center; font-size: var(--text-sm); background: var(--surface); cursor: pointer; }
.day b { display: block; }
.day.on { background: var(--accent); }
.day.today { box-shadow: inset 0 -3px 0 var(--fg); }
.day:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.assignment-who, .assignment-note { overflow-wrap: anywhere; }

/* ---- athlete home and workout ---- */
.my-home { max-width: 40rem; margin: 0 auto; overflow-wrap: anywhere; }
.my-section { margin-top: var(--space-3); }
.my-section-label { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: var(--space-4) 0 var(--space-2); }
.my-today { background: var(--accent); }
.my-today + .my-today { margin-top: var(--space-2); }
.card.link.my-item { display: flex; align-items: center; gap: var(--space-3); }
.my-item + .my-item, .my-more { margin-top: var(--space-2); }
.my-item-text { min-width: 0; }
.my-item-text h3 { margin-top: var(--space-1); }
.my-date { border: var(--border); border-radius: var(--radius); width: 3.2rem; text-align: center; background: var(--surface); flex: none; }
.my-date span { display: block; font-size: var(--text-xs); text-transform: uppercase; }
.my-date b { display: block; font-size: var(--text-lg); line-height: 1.1; }
.my-past { opacity: 0.6; }
.my-note { border: var(--border); border-radius: var(--radius); background: var(--tag-bodybuilding); padding: var(--space-2) var(--space-3); font-size: var(--text-sm); white-space: pre-line; overflow-wrap: anywhere; }
.my-detail-bar { margin-bottom: var(--space-3); }
.my-detail-bar .btn { min-height: 2.75rem; }

/* ---- empty state ---- */
.empty { border: 1px dashed var(--line); border-radius: var(--radius); padding: var(--space-6) var(--space-4); text-align: center; background: var(--surface); }

@media (max-width: 640px) {
    h1 { font-size: var(--text-xl); }
    .topbar { gap: var(--space-2); padding: var(--space-2) var(--space-3); flex-wrap: wrap; }
    .topbar .nav { order: 3; width: 100%; flex-wrap: wrap; }
    .nav a { padding: var(--space-2); }
    .page { padding: var(--space-4) var(--space-3); }
    .board li .qty { min-width: 4.5rem; }
    /* separate, not collapse: collapsed borders scroll away from a sticky cell and let the columns show past its edge. */
    .week { min-width: 52rem; border: none; border-collapse: separate; border-spacing: 0; }
    .week th, .week td { border-width: 0 1px 1px 0; }
    .week thead th { border-top-width: 1px; }
    .week th:first-child, .week td:first-child { width: 7.5rem; position: sticky; left: 0; z-index: 1; background: var(--surface); border-left-width: 1px; }
    .week th:first-child { background: var(--bg); }
    .person .avatar { display: none; }
}

/* ---- Blazor loading and error UI ---- */
.loading-progress { position: absolute; display: block; width: 8rem; height: 8rem; inset: 20vh 0 auto 0; margin: 0 auto; }
.loading-progress circle { fill: none; stroke: var(--surface-sunk); stroke-width: 0.6rem; transform-origin: 50% 50%; transform: rotate(-90deg); }
.loading-progress circle:last-child { stroke: var(--accent); stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%; transition: stroke-dasharray 0.05s ease-in-out; }
.loading-progress-text { position: absolute; text-align: center; font-weight: 700; inset: calc(20vh + 3.25rem) 0 auto 0.2rem; }
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Loading"); }

#blazor-error-ui { background: var(--accent); border-top: var(--border); bottom: 0; display: none; left: 0; padding: var(--space-2) var(--space-4); position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
