/* Desktop site + admin. One stylesheet; colours are tokens so dark mode is one block. */

/* Light is the default. Dark comes from data-theme="dark" (set in <head> from
   the toggle or the system), or from the system alone if that script didn't run. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --sidebar: #ffffff;
  --hover: #eef0f3;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e3e6eb;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #c62828;
  --error-bg: #fdecec;
  --ok-bg: #e8f3ec;
  --ok-text: #1e6b3a;
  --gold: #a86b00;
  --gold-bg: #fdf1d8;
  --scrim: rgb(15 18 24 / .45);
  --shadow: 0 8px 24px rgb(15 18 24 / .12);
  --radius: 8px;
  --sidebar-width: 260px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --bg: #0e1013;
    --surface: #16191e;
    --sidebar: #181b21;
    --hover: #232730;
    --text: #e8eaee;
    --muted: #9097a3;
    --line: #2a2f38;
    --accent: #4f8cff;
    --danger: #ff6b6b;
    --error-bg: #3a1d1f;
    --ok-bg: #18301f;
    --ok-text: #8fd5a6;
    --gold: #f2b84b;
    --gold-bg: #3a2c10;
    --scrim: rgb(0 0 0 / .6);
    --shadow: 0 8px 24px rgb(0 0 0 / .5);
    color-scheme: dark;
  }
}
:root[data-theme=dark] {
  --bg: #0e1013;
  --surface: #16191e;
  --sidebar: #181b21;
  --hover: #232730;
  --text: #e8eaee;
  --muted: #9097a3;
  --line: #2a2f38;
  --accent: #4f8cff;
  --danger: #ff6b6b;
  --error-bg: #3a1d1f;
  --ok-bg: #18301f;
  --ok-text: #8fd5a6;
  --gold: #f2b84b;
  --gold-bg: #3a2c10;
  --scrim: rgb(0 0 0 / .6);
  --shadow: 0 8px 24px rgb(0 0 0 / .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* A class that sets display (grid, flex) would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }

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

main { width: 100%; max-width: 1100px; margin: 0 auto; padding: 32px 40px 64px; }
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 24px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
h2 { font-size: 18px; margin: 0 0 8px; }
.muted { color: var(--muted); }

/* ---- shell: side menu on the left, content on the right ---- */

body.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}
.shell main { grid-column: 2; }

.icon { width: 20px; height: 20px; display: block; }
.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px; padding: 0;
  background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: var(--radius);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* The theme button shows where you'd go: a moon in light mode, a sun in dark. */
.theme-toggle .icon-sun,
[data-theme=dark] .theme-toggle .icon-moon { display: none; }
[data-theme=dark] .theme-toggle .icon-sun { display: block; }

.brand {
  display: flex; align-items: center; gap: 12px;
  color: var(--text); text-decoration: none;
  font-size: 22px; font-weight: 700; letter-spacing: -.01em;
}
.logo {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent); color: var(--accent-text);
}
.logo .icon { width: 22px; height: 22px; }

.sidebar {
  grid-column: 1; grid-row: 1;
  position: sticky; top: 0;
  height: 100vh;
  display: flex; flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 24px 16px 16px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 20px; }
#nav-close { display: none; }

.nav-group { display: flex; flex-direction: column; gap: 2px; padding: 12px 0; }
.nav-group + .nav-group { border-top: 1px solid var(--line); }
.nav-heading {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 4px 16px 6px;
}
.nav-group a {
  color: var(--muted); text-decoration: none;
  padding: 8px 16px; border-radius: var(--radius);
}
.nav-group a:hover { background: var(--hover); color: var(--text); }
.nav-group a[aria-current] { background: var(--hover); color: var(--text); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.nav-group a:focus-visible, .icon-btn:focus-visible, .user-menu summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.sidebar-foot { margin-top: auto; padding-top: 16px; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.sidebar-foot .theme-toggle { border-color: var(--line); }
.sidebar-foot .user-menu { width: 100%; }

/* ---- account menu: avatar button + a small popup ---- */

.user-menu { position: relative; }
.user-menu summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  border-radius: var(--radius);
}
.user-menu summary::-webkit-details-marker { display: none; }
.sidebar-foot summary { padding: 8px 10px; background: var(--hover); }
.sidebar-foot summary:hover { box-shadow: inset 0 0 0 1px var(--line); }
.user-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  flex: none; display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  font-size: 13px; font-weight: 700; letter-spacing: .02em;
}
.menu {
  position: absolute; z-index: 30; min-width: 220px;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px;
}
.sidebar-foot .menu { bottom: calc(100% + 6px); left: 0; right: 0; }
.topbar .menu { top: calc(100% + 8px); right: 0; }
.menu-email { font-size: 13px; color: var(--muted); padding: 6px 10px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; }
.menu a, .menu button {
  font: inherit; text-align: left; color: var(--text); text-decoration: none;
  background: none; border: 0; border-radius: 6px; padding: 8px 10px;
}
.menu a:hover, .menu button:hover { background: var(--hover); }

/* ---- ≤1024px: a top bar with a hamburger; the side menu becomes a drawer ---- */

.topbar, .scrim { display: none; }

@media (max-width: 1024px) {
  body.shell { display: block; }

  .topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: 8px;
    height: 56px; padding: 0 12px;
    background: var(--sidebar);
    border-bottom: 1px solid var(--line);
  }
  .topbar .brand { margin-left: 4px; }
  .topbar .logo { width: 32px; height: 32px; border-radius: 9px; }
  .topbar .spacer { flex: 1; }
  .topbar summary { padding: 3px; border-radius: 50%; }

  .sidebar {
    position: fixed; z-index: 40; top: 0; left: 0; bottom: 0;
    width: min(320px, 85vw); height: auto;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform .2s ease, visibility 0s .2s;
  }
  .nav-open .sidebar { transform: none; visibility: visible; transition: transform .2s ease; }
  .sidebar-foot { display: none; }
  #nav-close { display: grid; }

  .scrim {
    display: block; position: fixed; inset: 0; z-index: 35;
    background: var(--scrim);
    backdrop-filter: blur(3px);
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
  }
  .nav-open .scrim { opacity: 1; pointer-events: auto; }
  .nav-open { overflow: hidden; }

  main { padding: 24px 24px 64px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .scrim { transition: none !important; }
}

/* ---- forms ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.row { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin-bottom: 16px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; font-size: 15px; color: var(--text); padding-bottom: 8px; }

input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input[type=date], input[type=datetime-local], select, textarea {
  font: inherit; color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  min-width: 220px;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit; cursor: pointer;
  background: var(--accent); color: var(--accent-text);
  border: 0; border-radius: 6px;
  padding: 8px 14px;
}
button:disabled { opacity: .6; cursor: default; }
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.link { background: none; color: var(--accent); padding: 0; }
button.link.danger { color: var(--danger); }

textarea { min-width: 0; width: 100%; resize: vertical; line-height: 1.45; }
select { min-width: 160px; }

form.inline { display: flex; gap: 8px; }

.title-row { display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin: 0 0 24px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.title-row h1 { margin: 0; padding: 0; border: 0; }
form.inline input { min-width: 0; flex: 1; }

.flash { padding: 10px 14px; border-radius: 6px; background: var(--ok-bg); color: var(--ok-text); margin: 0 0 16px; }
.flash.error { background: var(--error-bg); color: var(--danger); }

/* ---- tables ---- */

/* The wrapper scrolls sideways on a narrow screen instead of the whole page. */
.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
td.actions button + button { margin-left: 16px; }
tr.retired td:nth-child(2) { color: var(--muted); }
td.thumb { width: 56px; padding-right: 0; }
td.thumb img { display: block; width: 44px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--line); }
td .badge { margin-left: 8px; }

.badge {
  display: inline-block; font-size: 12px; font-weight: 600; white-space: nowrap;
  padding: 1px 8px; border-radius: 99px;
  background: var(--accent); color: var(--accent-text);
}
.badge.muted { background: var(--line); color: var(--muted); }

/* ---- dialog ---- */

dialog {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  padding: 20px; width: min(420px, 90vw);
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog label { margin: 12px 0 16px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; }
dialog.wide { width: min(640px, 94vw); }

/* the exercise editor */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid .span { grid-column: 1 / -1; }
.grid label { margin: 0 0 14px; }
.grid select, .grid input[type=text] { min-width: 0; width: 100%; }
fieldset { border: 1px solid var(--line); border-radius: 6px; margin: 0 0 14px; padding: 8px 12px 4px; }
legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.checks label.check { padding: 2px 0 4px; font-size: 14px; }
.checks label:has(input:disabled) { opacity: .45; }
.photo-field { display: flex; gap: 16px; align-items: start; }
.photo-field img { width: 120px; height: 120px; object-fit: cover; border-radius: 6px; background: var(--line); }
.photo-field label { margin-bottom: 8px; }

/* ---- login ---- */

body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
body.login form { width: min(340px, 100%); display: flex; flex-direction: column; gap: 14px; }
body.login h1 { margin: 0 0 4px; padding: 0; border: 0; }
body.login input { min-width: 0; width: 100%; }
body.login .flash { margin: 0; }

@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  main { padding: 20px 16px 64px; }
  h1 { font-size: 24px; }
  td.actions { white-space: normal; }
}

/* ---- a link or file-picker label that looks like a button ---- */

a.button, label.button {
  display: inline-flex; align-items: center; flex-direction: row;
  font: inherit; font-size: 15px; cursor: pointer; text-decoration: none; white-space: nowrap;
  background: var(--accent); color: var(--accent-text);
  border: 1px solid transparent; border-radius: 6px; padding: 7px 14px;
}
a.button.secondary, label.button.secondary { background: transparent; color: var(--text); border-color: var(--line); }
a.button.secondary:hover, label.button.secondary:hover, button.secondary:hover { background: var(--hover); }
label.button:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
img.avatar { object-fit: cover; }
.avatar-lg { width: 64px; height: 64px; font-size: 22px; }

/* ---- settings: one row per setting, label left, control right ---- */

.settings { display: flex; flex-direction: column; gap: 20px; max-width: 720px; }
.settings .card { padding: 4px 20px; }
.settings h2 { margin: 16px 0 4px; }
.setting {
  display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 60px; padding: 10px 0; margin: 0;
  border-top: 1px solid var(--line);
  font-size: 15px; color: var(--text);
}
.settings h2 + .setting { border-top: 0; }
.setting > span:first-child { display: flex; flex-direction: column; }
.setting small { font-size: 13px; }
.setting input[type=text], .setting input[type=date], .setting select { min-width: 0; width: min(260px, 100%); }
.status { font-size: 13px; color: var(--ok-text); }
.status.error { color: var(--danger); }
.unit-inputs { display: flex; align-items: center; gap: 8px; }
.unit-inputs input { width: 84px; min-width: 0; }
.photo-setting { justify-content: flex-start; }
.photo-actions { display: flex; align-items: center; gap: 16px; }

/* radio buttons drawn as one pill with the choice highlighted */
.segmented {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
.segmented label { flex-direction: row; margin: 0; font-size: 14px; color: var(--text); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; white-space: nowrap; min-width: 48px; text-align: center; padding: 5px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- dashboard ---- */

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-head h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

.week-card { padding: 20px; margin-bottom: 20px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stat {
  display: flex; flex-direction: column; align-items: flex-start;
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--bg); border: 1px solid var(--line);
  font: inherit; text-align: left; color: var(--text);
}
button.stat { cursor: pointer; }
button.stat:hover { border-color: var(--gold); }
.stat-value { font-size: 30px; font-weight: 700; line-height: 1.15; white-space: nowrap; }
.stat-value small { font-size: 15px; font-weight: 600; color: var(--muted); }
.stat-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.delta { font-size: 12px; color: var(--muted); margin-top: 8px; }
.delta.up { color: var(--ok-text); font-weight: 600; }
.stat.gold .stat-value { color: var(--gold); }
.stat.hot .stat-value { color: var(--accent); }

.badge.pr-badge { background: var(--gold-bg); color: var(--gold); }
.pr-list { display: grid; gap: 2px; margin-top: 16px; padding-top: 8px; border-top: 1px solid var(--line); }
.pr { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 14px; }
.pr-value { margin-left: auto; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }

.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.day-card { padding: 20px; }
.workout-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.workout-head h3 { margin: 0; font-size: 20px; }
.eyebrow { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }
.empty { padding: 32px 0; text-align: center; margin: 0; }

.exercises { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 20px; }
.exercises:last-child { margin-bottom: 0; }
.exercise { padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.exercise header { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.exercise header img, .thumb-blank { flex: none; width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--line); }
.exercise h3 { margin: 0 0 4px; font-size: 15px; line-height: 1.3; }
.exercise .badge { margin: 0 4px 4px 0; font-size: 11px; }
.sets { list-style: none; margin: 0; padding: 0; font-variant-numeric: tabular-nums; }
.sets li { display: flex; gap: 12px; padding: 5px 0; border-top: 1px solid var(--line); font-size: 14px; }
.sets li:first-child { border-top: 0; }
.set-n { width: 1.5em; color: var(--muted); }
.sets .logged { margin-left: auto; font-size: 12px; color: var(--muted); }

.plan { list-style: none; margin: 0; padding: 0; }
.plan li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }

.calendar-card { padding: 14px 16px 12px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-head h2 { margin: 0; font-size: 16px; }
.cal-head, .cal-grid { max-width: 360px; margin-left: auto; margin-right: auto; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal-dow { padding: 4px 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.cal-day {
  position: relative; display: grid; place-items: center;
  aspect-ratio: 1; padding: 0; border-radius: 50%;
  background: none; color: var(--text); font-size: 14px; font-variant-numeric: tabular-nums;
}
.cal-day:hover { background: var(--hover); }
.cal-day.has-workout { font-weight: 600; }
.cal-day.has-workout::after {
  content: ''; position: absolute; bottom: 12%;
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent);
}
.cal-day.today { box-shadow: inset 0 0 0 1.5px var(--accent); }
.cal-day.selected { background: var(--accent); color: var(--accent-text); }
.cal-day.selected::after { background: var(--accent-text); }
#cal-today { display: block; margin: 8px auto 0; font-size: 14px; }

/* ---- exercises list (everyone's) ---- */

.filters input[type=search] { min-width: 0; width: 220px; }
.filters select { min-width: 0; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
td .badge { margin-left: 8px; }
.badge.muted + .badge, .badge + .badge.muted { margin-left: 4px; }
table.clickable tbody tr { cursor: pointer; }
table.clickable tbody tr:hover td { background: var(--hover); }
.row-link { color: var(--text); text-decoration: none; font-weight: 600; }
.row-link:hover, .row-link:focus-visible { text-decoration: underline; }
td.thumb .thumb-blank { display: block; width: 44px; height: 44px; border-radius: 6px; background: var(--line); }

/* ---- one exercise ---- */

.back { display: inline-block; margin-bottom: 8px; color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--text); }
.title-row h1 .badge { vertical-align: middle; font-size: 13px; }
.title-actions { display: flex; gap: 8px; }
button.secondary.danger { color: var(--danger); }
.exercise-page { display: flex; flex-direction: column; gap: 20px; }
.exercise-page .week-card { margin: 0; }

.ex-about { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; padding: 20px; align-items: start; }
.ex-about.no-photo { grid-template-columns: minmax(0, 1fr); }
.ex-about img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); background: var(--line); }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 20px; margin: 0 0 16px; }
.facts dt { color: var(--muted); font-size: 14px; }
.facts dd { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; padding: 1px 10px; border-radius: 99px; background: var(--hover); border: 1px solid var(--line); }
.instructions { white-space: pre-line; margin: 0; max-width: 68ch; line-height: 1.6; }

.chart-card { padding: 20px; }
.chart-card .card-head { flex-wrap: wrap; align-items: center; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .area { fill: var(--accent); opacity: .1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; }
.chart-tip {
  position: absolute; z-index: 5; transform: translate(-50%, calc(-100% - 14px)); pointer-events: none;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 8px 12px; font-size: 13px;
}
.chart-tip strong { font-size: 15px; }
.chart-tip span { color: var(--muted); }
.chart-tip .badge { margin-top: 4px; }

.history-card { padding: 20px; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { padding: 12px 0; border-top: 1px solid var(--line); }
.history li:first-child { border-top: 0; padding-top: 0; }
.history-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-bottom: 8px; }
.history-head a { color: var(--text); font-weight: 600; text-decoration: none; }
.history-head a:hover { text-decoration: underline; }
.history-sets { display: flex; flex-wrap: wrap; gap: 6px; }
.set-chip {
  font-size: 14px; font-variant-numeric: tabular-nums; padding: 3px 10px;
  border-radius: 6px; background: var(--bg); border: 1px solid var(--line);
}
#more { margin-top: 12px; }

@media (max-width: 640px) {
  .ex-about { grid-template-columns: minmax(0, 1fr); }
  .ex-about img { max-width: 280px; }
  .filters input[type=search] { width: 100%; }
}

/* ---- routines list ---- */

.routine-group { margin-bottom: 28px; }
.routine-group > h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 12px; }
.routine-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.routine-card {
  display: flex; flex-direction: column; gap: 12px; padding: 16px 18px;
  color: var(--text); text-decoration: none; transition: border-color .15s;
}
.routine-card:hover, .routine-card:focus-visible { border-color: var(--accent); }
.routine-card-head { display: flex; flex-direction: column; gap: 2px; }
.routine-card h3 { margin: 0; font-size: 18px; }
.routine-card-head .muted { font-size: 14px; }
.routine-preview { list-style: none; margin: 0; padding: 0; font-size: 14px; flex: 1; }
.routine-preview li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-top: 1px solid var(--line); }
.routine-preview li:first-child { border-top: 0; }
.routine-card p { margin: 0; flex: 1; }
.routine-card-foot { font-size: 13px; }
.empty-state { padding: 32px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.empty-state h2 { margin: 0; }
.empty-state .button { margin-top: 12px; }

/* ---- routine editor ---- */

.routine-editor { display: flex; flex-direction: column; gap: 20px; padding-bottom: 72px; }
.routine-editor > .card { padding: 20px; }
.routine-meta { display: flex; flex-wrap: wrap; align-items: end; gap: 16px; }
.routine-meta label { flex: 1 1 240px; }
.routine-meta input:not([type=checkbox]), .routine-meta select { min-width: 0; width: 100%; }
.routine-meta p { flex-basis: 100%; margin: 0; font-size: 14px; }

.rx-list { list-style: none; margin: 0 0 12px; padding: 0; }
.rx { position: relative; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.rx.dragging { opacity: .4; }
.rx.drop { border-color: var(--accent); }
.rx-main { display: grid; grid-template-columns: auto 44px minmax(140px, 1fr) auto auto; align-items: center; gap: 12px; }
.rx-main img, .rx-main .thumb-blank { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--line); }
.rx-name { overflow: hidden; }
.rx-name strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drag {
  cursor: grab; padding: 4px 6px; background: none; color: var(--muted);
  font-size: 16px; letter-spacing: -3px; line-height: 1; border-radius: 4px;
}
.drag:hover { background: var(--hover); color: var(--text); }
.rx-targets { display: flex; align-items: end; gap: 10px; }
.rx-targets label { font-size: 12px; gap: 2px; }
.rx-targets input[type=number] { width: 56px; min-width: 0; padding: 5px 6px; text-align: center; }
.rx-targets select { min-width: 0; padding: 5px 6px; }
.rx-targets .times { color: var(--muted); padding-bottom: 7px; }
.range { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.rx-actions { display: flex; align-items: center; gap: 2px; }
.rx-actions .link { font-size: 13px; margin-right: 6px; white-space: nowrap; }
button.icon-text {
  width: 30px; height: 30px; padding: 0; border-radius: 6px;
  background: none; color: var(--muted); font-size: 15px;
}
button.icon-text:hover:not(:disabled) { background: var(--hover); color: var(--text); }
button.icon-text.danger:hover { color: var(--danger); }
button.icon-text:disabled { opacity: .3; }
.rx-notes { margin-top: 10px; font-size: 14px; }

/* Supersets: linked rows share an accent edge and sit closer together. */
.rx.in-superset { border-left: 3px solid var(--accent); }
.rx.linked { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.rx-link + .rx.in-superset:not(:has(.superset-label)) { border-top-left-radius: 0; border-top-right-radius: 0; }
.superset-label {
  position: absolute; top: -9px; left: 12px; padding: 0 6px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--accent); background: var(--surface);
}
.rx-link { display: flex; justify-content: center; height: 28px; align-items: center; }
.rx-link.on { height: 22px; border-left: 3px solid var(--accent); margin: 0; background: var(--bg); border-right: 1px solid var(--line); }
.link-toggle {
  background: none; color: var(--muted); font-size: 12px; padding: 2px 10px; border-radius: 99px;
  opacity: 0; transition: opacity .15s;
}
.rx-list:hover .link-toggle, .link-toggle:focus-visible, .rx-link.on .link-toggle { opacity: 1; }
.link-toggle:hover { background: var(--hover); color: var(--text); }
.rx-link.on .link-toggle { color: var(--accent); }

.save-bar {
  position: sticky; bottom: 16px; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  margin-left: auto; padding: 10px 12px 10px 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.save-bar span { margin-right: 8px; font-weight: 600; }

/* the exercise picker */
.picker-list { list-style: none; margin: 0 0 12px; padding: 0; max-height: min(52vh, 480px); overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.picker-list li { border-top: 1px solid var(--line); }
.picker-list li:first-child { border-top: 0; }
.picker-list li.muted { padding: 16px; }
label.pick {
  display: flex; flex-direction: row; align-items: center; gap: 12px; margin: 0;
  padding: 8px 12px; cursor: pointer; font-size: 15px; color: var(--text);
}
label.pick:hover { background: var(--hover); }
label.pick img, label.pick .thumb-blank { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--line); flex: none; }
label.pick > span:not(.badge, .thumb-blank) { display: flex; flex-direction: column; flex: 1; min-width: 0; }
label.pick small { font-size: 13px; }
#picker .row { margin: 12px 0; }
#picker .row input[type=search] { flex: 1; }
#picker .actions { align-items: center; }
#picker .actions .muted { margin-right: auto; }

@media (max-width: 900px) {
  .rx-main { grid-template-columns: auto 44px minmax(0, 1fr) auto; }
  .rx-targets { grid-column: 2 / -1; grid-row: 2; flex-wrap: wrap; }
}
/* Phone width: name on its own line, the numbers under it, the buttons last. */
@media (max-width: 640px) {
  .rx-main { grid-template-columns: auto 44px minmax(0, 1fr); gap: 10px; }
  .rx-name strong { white-space: normal; }
  .rx-targets { grid-column: 1 / -1; grid-row: 2; }
  .rx-actions { grid-column: 1 / -1; grid-row: 3; justify-content: flex-end; }
}

/* ---- programs ---- */

button.small, .button.small { font-size: 14px; padding: 5px 12px; }
.program-card { padding: 18px 20px; margin-bottom: 16px; }
.program-card.active { border-color: var(--accent); }
.program-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 12px; }
.program-head h2 { margin: 0; font-size: 20px; }
.program-actions { display: flex; align-items: center; gap: 8px; }
.program-actions .badge { font-size: 13px; padding: 3px 10px; }
.small-note { font-size: 13px; margin: -4px 0 12px; }
.program-days { list-style: none; margin: 0; padding: 0; }
.program-days li {
  display: grid; grid-template-columns: 56px minmax(120px, max-content) minmax(0, 1fr) auto;
  align-items: center; gap: 12px; padding: 8px 10px; border-radius: 6px;
}
.program-days li + li { border-top: 1px solid var(--line); }
.program-days li.next { background: var(--hover); border-top-color: transparent; }
.program-days li.next + li { border-top-color: transparent; }
.program-days a { color: var(--text); font-weight: 600; text-decoration: none; }
.program-days a:hover { text-decoration: underline; }
.program-days .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.day-n { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.next .day-n { color: var(--accent); }
.badge.next-badge { background: var(--accent); }

/* the program editor */
label.switch { flex-direction: row; align-items: flex-start; gap: 10px; flex: 1 1 280px; padding: 0; color: var(--text); font-size: 15px; }
label.switch input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--accent); }
label.switch > span { display: flex; flex-direction: column; }
label.switch small { font-size: 13px; }
.px-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.px {
  display: grid; grid-template-columns: auto 56px minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
}
.px.dragging { opacity: .4; }
.px.drop { border-color: var(--accent); }
.px-name { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; min-width: 0; }
.px-name a { color: var(--text); font-weight: 600; text-decoration: none; }
.px-name a:hover { text-decoration: underline; }
.px-name small { font-size: 13px; }
.row-buttons { display: flex; align-items: center; gap: 16px; }
.link-button { color: var(--accent); text-decoration: none; font-size: 15px; }
.link-button:hover { text-decoration: underline; }

@media (max-width: 640px) {
  .program-head { flex-direction: column; }
  .program-days li { grid-template-columns: 52px minmax(0, 1fr) auto; }
  .program-days li > .muted { display: none; }
}

/* ---- workouts ---- */

.workouts-table .month-row th {
  background: var(--bg); color: var(--text); font-size: 13px; letter-spacing: .04em;
  padding-top: 14px; padding-bottom: 8px; cursor: default;
}
.workouts-table .month-row th .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
table.clickable tbody tr.month-row:hover th { background: var(--bg); }
.date-cell { white-space: nowrap; }
.date-cell strong, .date-cell span { display: block; line-height: 1.3; }
.date-cell span { font-size: 13px; }
td.ellipsis { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.load-more { display: block; margin: 16px auto 0; }
.workout-head h3 a { color: inherit; text-decoration: none; }
.workout-head h3 a:hover { text-decoration: underline; }

/* the workout editor */
.title-date { display: block; font-size: 15px; font-weight: 400; color: var(--muted); margin-top: 4px; }
.pr-row { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px; }
.pr-row:empty { display: none; }
.workout-blocks { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.workout-blocks:empty { display: none; }
.workout-block { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.workout-block header { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 12px; align-items: start; }
.workout-block header img, .workout-block header .thumb-blank { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--line); }
.workout-block h2 { margin: 0 0 4px; font-size: 16px; }
.workout-block h2 a { color: var(--text); text-decoration: none; }
.workout-block h2 a:hover { text-decoration: underline; }
.workout-block header .badge { margin: 0 4px 4px 0; font-size: 11px; }
.workout-block .link { align-self: flex-start; font-size: 14px; }
.sets-table { border: 0; background: none; border-radius: 0; }
.sets-table th { padding: 4px 6px; font-size: 11px; }
.sets-table td { padding: 4px 6px; border-bottom: 0; }
.sets-table td.set-n { width: 2em; color: var(--muted); font-variant-numeric: tabular-nums; }
.sets-table input[type=number] { min-width: 0; width: 68px; padding: 5px 6px; text-align: right; font-variant-numeric: tabular-nums; }
.weight-in { display: inline-flex; gap: 4px; }
.weight-in input[type=number] { width: 76px; }
.weight-in select { min-width: 0; padding: 5px 4px; }

@media (max-width: 640px) {
  .workouts-table th:nth-child(3), .workouts-table td:nth-child(3),
  .workouts-table th:nth-child(5), .workouts-table td:nth-child(5) { display: none; }
  .workout-blocks { grid-template-columns: minmax(0, 1fr); }
  .workout-block { padding: 12px; overflow-x: auto; }
  .sets-table th, .sets-table td { padding: 3px 2px; }
  .sets-table input[type=number] { width: 48px; padding: 5px 4px; }
  .weight-in input[type=number] { width: 58px; }
}

/* The calendar drops below the day card once there's no room beside it. */
@media (max-width: 1280px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 12px; }
  .stat-value { font-size: 22px; white-space: normal; }
  .week-card, .day-card { padding: 16px; }
  .setting { flex-wrap: wrap; }
}
