:root {
  color-scheme: light;
  --good: #2e8b3e; --warn: #c98500; --bad: #e34948;
  --surface-0: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #efeeeb;
  --border: #dedcd6;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77766f;
  --grid: #e6e5e0;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  /* categorical slots, fixed order: bike, run, swim, strength, other */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  /* sequential blue for zones */
  --seq-1: #86b6ef; --seq-2: #5598e7; --seq-3: #2a78d6; --seq-4: #1c5cab; --seq-5: #184f95; --seq-6: #104281; --seq-7: #0d366b;
  --warning-bg: #fff4d6;
  --warning-ink: #6b4a00;
  --critical: #c0392b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #242422;
    --border: #34332f;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #96958c;
    --grid: #2b2b28;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --seq-1: #184f95; --seq-2: #1c5cab; --seq-3: #256abf; --seq-4: #2a78d6; --seq-5: #3987e5; --seq-6: #6da7ec; --seq-7: #9ec5f4;
    --warning-bg: #3a2f10;
    --warning-ink: #f3d68a;
    --critical: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #242422;
  --border: #34332f;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #96958c;
  --grid: #2b2b28;
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --seq-1: #184f95; --seq-2: #1c5cab; --seq-3: #256abf; --seq-4: #2a78d6; --seq-5: #3987e5; --seq-6: #6da7ec; --seq-7: #9ec5f4;
  --warning-bg: #3a2f10;
  --warning-ink: #f3d68a;
  --critical: #e66767;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--surface-0);
  color: var(--text-primary);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.small { font-size: 0.85rem; }
.num { font-variant-numeric: tabular-nums; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text-primary); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand svg { width: 24px; height: 24px; fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav[hidden] { display: none; }
nav a { color: var(--text-secondary); padding: 6px 12px; border-radius: 8px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
nav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav a:hover { background: var(--surface-2); text-decoration: none; }
nav a.active { color: var(--text-primary); background: var(--surface-2); }
#sync-status { margin-left: auto; }

main { margin: 0 auto; padding: 24px 32px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }

.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-bottom: 16px; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.tile { padding: 14px 16px; }
.tile .label { color: var(--text-secondary); font-size: 0.8rem; font-weight: 500; }
.tile .value { font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 2px; }
.tile .value small { font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); margin-left: 2px; }
.tile .sub { color: var(--text-muted); font-size: 0.8rem; margin-top: 2px; }

.chart { position: relative; height: 260px; }
.chart.short { height: 170px; }
.chart.tiny { height: 120px; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.8rem; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend i.line { height: 3px; border-radius: 2px; width: 14px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; color: var(--text-secondary); padding: 4px 10px; border-radius: 6px; font: inherit; font-size: 0.8rem; cursor: pointer; }
.seg button.on { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); }

button.primary, button.ghost, select, input {
  font: inherit; border-radius: 8px; padding: 7px 12px;
}
button.primary { background: var(--accent); color: var(--accent-ink); border: 0; font-weight: 600; cursor: pointer; }
button.primary:disabled { opacity: 0.6; cursor: progress; }
button.ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); cursor: pointer; }
button.ghost:hover { color: var(--text-primary); }
select, input { background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th { text-align: left; color: var(--text-muted); font-weight: 500; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; padding: 6px 8px; border-bottom: 1px solid var(--border); }
td { padding: 8px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

.sport { display: inline-flex; align-items: center; gap: 6px; }
.sport i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.banner { background: var(--warning-bg); color: var(--warning-ink); border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-size: 0.9rem; }
.banner a { color: inherit; text-decoration: underline; }
.error { color: var(--critical); }

.prose { line-height: 1.6; }
.prose h1, .prose h2, .prose h3 { font-size: 1rem; margin: 18px 0 6px; }
.prose p { margin: 6px 0; }
.prose ul { margin: 6px 0; padding-left: 22px; }
.prose > :first-child { margin-top: 0; }

.chat { display: flex; flex-direction: column; gap: 10px; max-height: 520px; overflow-y: auto; margin-bottom: 12px; }
.msg { padding: 10px 14px; border-radius: 12px; max-width: 88%; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.msg.model { align-self: flex-start; background: var(--surface-2); }
.ask-row { display: flex; gap: 8px; }
.ask-row textarea { flex: 1; font: inherit; border-radius: 8px; padding: 8px 12px; background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); resize: vertical; min-height: 42px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chips button { border: 1px solid var(--border); background: var(--surface-1); color: var(--text-secondary); border-radius: 999px; padding: 4px 12px; font: inherit; font-size: 0.8rem; cursor: pointer; }
.chips button:hover { color: var(--text-primary); }

details.report { border-top: 1px solid var(--grid); padding: 10px 0; }
details.report summary { cursor: pointer; font-weight: 600; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--text-secondary); }
.form-grid .hint { font-size: 0.75rem; color: var(--text-muted); }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.login { max-width: 380px; margin: 12vh auto; text-align: center; padding: 32px; }
.login #g-button { display: flex; justify-content: center; margin: 20px 0 8px; min-height: 44px; color-scheme: light; }
/* Google renders the button in a light-scheme iframe; matching it avoids an opaque white backdrop on dark pages */
.workout { display: grid; grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
.workout-side, .workout-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 10px; }
.stat .label { color: var(--text-muted); font-size: 0.75rem; }
.stat .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .v small { font-weight: 400; color: var(--text-secondary); margin-left: 2px; font-size: 0.75rem; }
table.perf td, table.perf th { padding: 6px 4px; }
.form-row { display: flex; justify-content: space-between; margin-top: 10px; font-size: 1.05rem; }
/* Leaflet uses z-index up to 1000; isolate it so the sticky header and bottom tab bar stay on top. */
.map-card { padding: 0; overflow: hidden; position: relative; z-index: 0; isolation: isolate; }
#map { height: 320px; background: var(--surface-2); }
.readout { display: flex; flex-wrap: wrap; gap: 6px 16px; min-height: 24px; margin-bottom: 8px; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.readout span { display: inline-flex; align-items: center; gap: 6px; }
.readout i { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }
.stream-label { margin-top: 4px; }
.chart.stream { height: 120px; }
.chart.zones { height: 240px; }
.empty { text-align: center; padding: 48px 16px; color: var(--text-secondary); }
.empty code { background: var(--surface-2); padding: 2px 6px; border-radius: 4px; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile { filter: brightness(0.6) invert(1) contrast(3) hue-rotate(200deg) saturate(0.3) brightness(0.7); }
}
:root[data-theme="dark"] .leaflet-tile { filter: brightness(0.6) invert(1) contrast(3) hue-rotate(200deg) saturate(0.3) brightness(0.7); }

@media (max-width: 860px) {
  .cols-2, .cols-3 { grid-template-columns: minmax(0, 1fr); }
  .workout { grid-template-columns: minmax(0, 1fr); }
  main { padding: 16px; }
  .topbar { padding: 10px 16px; gap: 10px; }
  #sync-status { margin-left: 0; width: 100%; }
}

/* ---------- phone ---------- */
@media (max-width: 640px) {
  body { font-size: 14px; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .topbar { padding: calc(8px + env(safe-area-inset-top)) 14px 8px; gap: 8px; flex-wrap: nowrap; }
  .brand { font-size: 1rem; }
  .brand svg { width: 20px; height: 20px; }
  #sync-status { margin-left: auto; width: auto; font-size: 0.72rem; text-align: right; line-height: 1.3; }
  nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 0;
    background: var(--surface-1); border-top: 1px solid var(--border);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  nav[hidden] { display: none; }
  nav a { flex-direction: column; gap: 2px; padding: 6px 2px; font-size: 0.68rem; border-radius: 10px; }
  nav a.active { background: transparent; color: var(--accent); }
  nav svg { width: 22px; height: 22px; }
  main { padding: 12px; }
  h1 { font-size: 1.25rem; }
  .page-head { margin-bottom: 12px; }
  .grid { gap: 12px; }
  .card { padding: 12px 14px; border-radius: 10px; }
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
  .tile { padding: 10px; }
  .tile .label { font-size: 0.7rem; }
  .tile .value { font-size: 1.2rem; }
  .tile .value small { font-size: 0.7rem; }
  .tile .sub { font-size: 0.68rem; line-height: 1.25; }
  .chart { height: 200px; }
  .chart.short { height: 140px; }
  .chart.tiny { height: 100px; }
  .chart.stream { height: 100px; }
  .chart.zones { height: 220px; }
  #map { height: 240px; }
  .stats { gap: 10px 8px; }
  .seg button { padding: 4px 8px; }
  .legend { gap: 10px; font-size: 0.75rem; }
  table { font-size: 0.82rem; }
  td, th { padding: 7px 5px; }
  .hide-sm { display: none; }
  .msg { max-width: 94%; }
  .chat { max-height: 60vh; }
  .login { margin: 8vh auto; padding: 24px; }
}
.show-sm { display: none !important; }
@media (max-width: 640px) { .show-sm { display: inline-block !important; } }

/* ---------- status colours (plan compliance) ---------- */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --good: #3fb950; --warn: #d9a022; --bad: #e66767; } }
:root[data-theme="dark"] { --good: #3fb950; --warn: #d9a022; --bad: #e66767; }

.nav-more { display: none !important; }

/* ---------- calendar ---------- */
.cal-nav { display: flex; gap: 6px; }
.cal-nav button { min-width: 40px; }
.calendar { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface-1); }
.cal-header, .cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)) minmax(170px, 0.9fr); }
.cal-header div { padding: 8px 10px; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); }
.cal-week { border-bottom: 1px solid var(--border); }
.cal-week:last-child { border-bottom: 0; }
.cal-day { padding: 6px; border-right: 1px solid var(--grid); min-height: 120px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cal-day.past { background: color-mix(in srgb, var(--surface-2) 35%, transparent); }
.cal-day.today { background: color-mix(in srgb, var(--accent) 9%, transparent); }
.cal-date { font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); }
.cal-today { background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 1px 6px; font-size: 0.7rem; margin-left: 4px; }
.cal-metrics { font-size: 0.7rem; color: var(--text-muted); }
.wk { border: 1px solid var(--border); border-left: 4px solid var(--border); border-radius: 8px; padding: 6px 8px; background: var(--surface-1); font-size: 0.78rem; line-height: 1.35; }
.wk[data-href] { cursor: pointer; }
.wk[data-href]:hover { border-color: var(--text-muted); }
.wk-head { display: flex; align-items: center; gap: 4px; min-width: 0; }
.wk-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wk-main { font-variant-numeric: tabular-nums; }
.wk-plan { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.wk-status { font-size: 0.7rem; color: var(--text-secondary); margin-top: 2px; }
.wk-icon { font-weight: 700; margin-right: 3px; }
.wk-good { border-left-color: var(--good); } .wk-good .wk-icon { color: var(--good); }
.wk-warn { border-left-color: var(--warn); } .wk-warn .wk-icon { color: var(--warn); }
.wk-bad { border-left-color: var(--bad); } .wk-bad .wk-icon { color: var(--bad); }
.wk-missed { border-left-color: var(--bad); border-style: dashed; border-left-style: solid; opacity: 0.85; } .wk-missed .wk-icon { color: var(--bad); }
.wk-planned { border-style: dashed; border-left: 4px solid var(--text-muted); background: transparent; }
.wk-unplanned, .wk-done { border-left-color: var(--text-muted); }
.wk-desc { margin-top: 4px; font-size: 0.72rem; color: var(--text-secondary); }
.wk-desc summary { cursor: pointer; color: var(--accent); }
.wk-desc div { margin-top: 4px; white-space: normal; max-height: 160px; overflow: auto; }
.cal-summary { padding: 8px 10px; font-size: 0.78rem; display: flex; flex-direction: column; gap: 4px; background: var(--surface-2); }
.cal-form { display: flex; justify-content: space-between; margin-bottom: 4px; }
.cal-form span { display: flex; flex-direction: column; align-items: center; }
.cal-form small { color: var(--text-muted); font-size: 0.68rem; }
.cal-form b { font-size: 1.05rem; }
.cal-row { display: flex; flex-wrap: wrap; gap: 0 6px; align-items: baseline; }
.cal-row > span:first-child { flex: 1; color: var(--text-secondary); }
.cal-legend { margin-top: 12px; }
.cl { width: 12px !important; height: 12px !important; border-radius: 3px; border: 2px solid; background: transparent !important; }
.cl.good { border-color: var(--good); } .cl.warn { border-color: var(--warn); } .cl.bad, .cl.missed { border-color: var(--bad); }
.cl.missed { border-style: dashed; } .cl.planned { border-color: var(--text-muted); border-style: dashed; }

textarea.script { width: 100%; font: 0.75rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border); border-radius: 8px; padding: 10px; resize: vertical; }
.more-list { display: flex; flex-direction: column; }
.more-list a { padding: 14px 4px; border-bottom: 1px solid var(--grid); color: var(--text-primary); }
.more-list a:last-child { border-bottom: 0; }

@media (max-width: 1100px) and (min-width: 641px) {
  .cal-header, .cal-week { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .cal-header div:last-child { display: none; }
  .cal-summary { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; gap: 4px 18px; align-items: center; }
  .cal-form { gap: 14px; margin: 0; }
}
@media (max-width: 640px) {
  .nav-secondary { display: none !important; }
  .nav-more { display: flex !important; }
  nav { grid-template-columns: repeat(6, 1fr); }
  .calendar { border: 0; background: transparent; }
  .cal-week { display: flex; flex-direction: column; gap: 8px; border: 0; margin-bottom: 18px; }
  .cal-day { border: 1px solid var(--border); border-radius: 10px; min-height: 0; background: var(--surface-1); }
  .cal-day.past { background: var(--surface-1); }
  .cal-day:not(:has(.wk)):not(.today) { display: none; }
  .cal-summary { border-radius: 10px; }
  .cal-legend { font-size: 0.7rem; }
}

/* ---------- AI coach chat ---------- */
a.btn { display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; padding: 7px 12px; font-weight: 600; text-decoration: none; }
a.btn.primary { background: var(--accent); color: var(--accent-ink); }
.ask-coach { width: 100%; margin-top: 12px; }
.coach { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; height: calc(100vh - 120px); min-height: 480px; }
.coach-side { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.coach-side-actions { display: flex; flex-direction: column; gap: 8px; }
.chat-list { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.chat-item { display: flex; flex-direction: column; padding: 8px 10px; border-radius: 8px; color: var(--text-primary); }
.chat-item:hover { background: var(--surface-2); text-decoration: none; }
.chat-item.on { background: var(--surface-2); }
.chat-title { font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-meta { font-size: 0.72rem; color: var(--text-muted); }
.coach-main { display: flex; flex-direction: column; min-height: 0; background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.coach-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.coach-head h2 { margin: 0; flex: 1; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.coach-head-actions { display: flex; gap: 6px; }
.coach-head input.rename { flex: 1; font-size: 1rem; }
.ref-bar { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 16px; border-bottom: 1px solid var(--grid); }
.ref-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border-radius: 999px; padding: 3px 10px; font-size: 0.78rem; max-width: 100%; }
.ref-chip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.ref-chip a { color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.ref-chip button { border: 0; background: none; color: var(--text-muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 2px; }
.coach-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.coach-messages .msg { max-width: min(760px, 92%); }
.coach-messages .msg.model { background: transparent; padding: 0; }
.coach-messages .msg.user { padding: 10px 14px; }
.msg-refs { font-size: 0.75rem; opacity: 0.85; margin-top: 4px; }
.msg-meta { font-size: 0.7rem; color: var(--text-muted); margin-top: 4px; }
.chat-empty { margin: auto; text-align: center; max-width: 520px; }
.chat-empty .chips { justify-content: center; margin-top: 16px; }
.composer { border-top: 1px solid var(--border); padding: 10px 12px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; font: inherit; border-radius: 10px; padding: 9px 12px; background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border); resize: none; max-height: 200px; }
.composer .attach { font-size: 1.05rem; padding: 7px 10px; }
.composer-hint { margin-top: 4px; }
.pending-refs { display: flex; gap: 6px; flex-wrap: wrap; }
.pending-refs:not(:empty) { margin-bottom: 8px; }
.picker-overlay { position: fixed; inset: 0; background: rgb(0 0 0 / 0.5); z-index: 70; display: flex; align-items: flex-start; justify-content: center; padding: calc(8vh + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); }
.picker { width: min(560px, 100%); max-height: 80vh; display: flex; flex-direction: column; }
.picker-search { width: 100%; margin-bottom: 8px; }
.picker-list { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.picker-item { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; gap: 8px; align-items: center; text-align: left; border: 0; background: transparent; color: var(--text-primary); padding: 8px 6px; border-radius: 8px; cursor: pointer; font: inherit; }
.picker-item:hover { background: var(--surface-2); }
.picker-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.show-sm-flex { display: none !important; }
.drawer-close { display: none !important; }
@media (max-width: 860px) {
  .coach { grid-template-columns: minmax(0, 1fr); height: calc(100vh - 150px); }
  .coach-side { display: none; }
  /* Drawer clears the iPhone status bar and home indicator, and sits above the tab bar. */
  .coach-side.open {
    display: flex; position: fixed; top: 0; bottom: 0; left: 0; width: min(320px, 85vw); z-index: 60;
    background: var(--surface-1); border-right: 1px solid var(--border); box-shadow: 0 0 40px rgb(0 0 0 / 0.4);
    padding: calc(14px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  }
  .coach-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 0.5); z-index: 55; }
  .drawer-close { display: flex !important; align-self: flex-end; }
  .show-sm-flex { display: inline-flex !important; }
}
@media (max-width: 640px) {
  .coach { height: calc(100dvh - 140px - env(safe-area-inset-bottom)); }
  .coach-messages { padding: 14px; }
  .composer-hint { display: none; }
  .coach-head-actions .small { padding: 4px 8px; }
}

.picker-tabs { margin-bottom: 10px; align-self: flex-start; }
.ref-chip.planned { border: 1px dashed var(--text-muted); background: transparent; }
.wk-steps { font: 0.7rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; margin: 4px 0; color: var(--text-secondary); }
.wk-ask { margin-top: 6px; width: 100%; }

.plan-sources { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-top: 12px; }
.plan-sources label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* ---------- planned workout card buttons + window ---------- */
.wk-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.wk-btn { flex: 1 1 auto; min-width: 0; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-secondary); border-radius: 6px; padding: 3px 4px; font: inherit; font-size: 0.7rem; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wk-btn:hover { color: var(--text-primary); border-color: var(--text-muted); }
.wk-btn.wk-ask { color: var(--accent); }
body.modal-open { overflow: hidden; }
.modal-overlay { position: fixed; inset: 0; z-index: 80; background: rgb(0 0 0 / 0.55); display: flex; align-items: center; justify-content: center; padding: 24px; animation: fade 0.15s ease-out; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(760px, 100%); max-height: min(88vh, 900px); display: flex; flex-direction: column; padding: 0; overflow: hidden; box-shadow: 0 20px 60px rgb(0 0 0 / 0.45); }
.modal-head { display: flex; justify-content: space-between; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--grid); }
.modal-head h2 { margin: 4px 0 0; font-size: 1.25rem; }
.modal-x { font-size: 1.4rem; line-height: 1; padding: 2px 10px; align-self: flex-start; }
.modal-body { overflow-y: auto; padding: 16px 20px; }
.modal-body h3 { font-size: 0.9rem; margin: 18px 0 8px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--grid); background: var(--surface-1); }
.plan-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.plan-profile-wrap { background: var(--surface-2); border-radius: 10px; padding: 12px 12px 8px; }
.plan-profile { width: 100%; height: 170px; display: block; }
.plan-profile .ftp-line { stroke: var(--text-muted); stroke-dasharray: 6 5; stroke-width: 1; vector-effect: non-scaling-stroke; }
.plan-profile .axis text { fill: var(--text-muted); font-size: 22px; }
.plan-profile rect:hover { filter: brightness(1.25); }
.plan-steps { display: flex; flex-direction: column; gap: 6px; }
.plan-step { display: grid; grid-template-columns: 6px 96px 92px minmax(0, 1fr); gap: 10px; align-items: center; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.plan-swatch { width: 6px; height: 22px; border-radius: 3px; }
.plan-kind { font-weight: 600; }
.plan-note { grid-column: 2 / -1; color: var(--text-muted); font-size: 0.78rem; white-space: pre-line; }
.plan-repeat { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 8px; align-items: stretch; }
.plan-repeat-label { display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--accent); border: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-right: 0; border-radius: 10px 0 0 10px; }
.plan-repeat-steps { display: flex; flex-direction: column; gap: 6px; }
.plan-desc { font-size: 0.88rem; line-height: 1.55; color: var(--text-secondary); background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
@media (max-width: 640px) {
  .modal-overlay { padding: 0; align-items: stretch; }
  .modal { width: 100%; max-height: none; height: 100%; border-radius: 0; border: 0; }
  .modal-head { padding-top: calc(14px + env(safe-area-inset-top)); }
  .modal-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot .primary { flex: 1; }
  .plan-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plan-step { grid-template-columns: 6px 78px minmax(0, 1fr); }
  .plan-target { grid-column: 2 / -1; }
  .plan-profile { height: 130px; }
}

.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.9rem; }
/* Full-width pages: let long-form text keep a readable line length */
.prose { max-width: 900px; }
.page-head > div:first-child { min-width: 0; }

.wa-connect { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 16px; align-items: start; margin-top: 12px; }
.wa-qr { background: #fff; border-radius: 10px; padding: 6px; width: 150px; height: 150px; }
.wa-qr svg { width: 100%; height: 100%; display: block; }
@media (max-width: 640px) { .wa-connect { grid-template-columns: minmax(0, 1fr); } .wa-qr { display: none; } }

.memory-list { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.memory-row { display: grid; grid-template-columns: 130px minmax(0, 1fr) 140px auto auto; gap: 6px; align-items: center; }
.memory-row input, .memory-row select { min-width: 0; padding: 6px 8px; font-size: 0.85rem; }
.memory-new { margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--grid); }
a.btn.ghost { border: 1px solid var(--border); color: var(--text-secondary); }
.memory-link { font-size: 0.82rem; }
@media (max-width: 640px) { .memory-row { grid-template-columns: 1fr 1fr; } .memory-row input[name="text"] { grid-column: 1 / -1; } }

.wa-health { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; margin: 6px 0 10px; line-height: 1.5; }
