/* HuronXC — mobile-first. Athletes log runs on a phone; everything else follows. */

/* Themes. Three states: no data-theme on <html> follows the device; the theme
   cookie sets data-theme="light" or "dark" to pin one. The dark tokens appear
   twice — once for "device is dark and nothing pinned", once for "pinned dark" —
   and tests.ThemeTokenTests fails if the two copies drift apart.

   Every text token clears WCAG AA (4.5:1) on bg, surface and surface-2, and the
   same test checks it. Never dim text with `opacity`: it multiplies with an
   already-dim colour and lands near 2:1, which is what made empty days and
   zero cells unreadable. Use --text-dim instead.

   --accent, --accent-soft and --accent-text are per school, so they're not
   here: base.html writes them from settings (see tracker/branding.py). */

:root {
  color-scheme: light;
  --bg: #f8f6f6;
  --surface: #ffffff;
  --surface-2: #f1eded;
  --border: #e0d9d9;
  --text: #1f1717;
  --text-dim: #6b5e5e;
  --warn: #a64d08;
  --warn-soft: #fdf3e3;
  --danger: #8a1c14;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(24 16 16 / 6%), 0 4px 14px rgb(24 16 16 / 5%);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141010;
    --surface: #1d1818;
    --surface-2: #272020;
    --border: #3a3131;
    --text: #ede8e8;
    --text-dim: #a89a9a;
    --warn: #e0a355;
    --warn-soft: #2a2116;
    --danger: #f35d5d;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 14px rgb(0 0 0 / 30%);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141010;
  --surface: #1d1818;
  --surface-2: #272020;
  --border: #3a3131;
  --text: #ede8e8;
  --text-dim: #a89a9a;
  --warn: #e0a355;
  --warn-soft: #2a2116;
  --danger: #f35d5d;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 14px rgb(0 0 0 / 30%);
}

* { box-sizing: border-box; }

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

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

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 64px;
}
.wrap--wide { max-width: 1180px; }

/* --- Header --------------------------------------------------------------- */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar__inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.topbar__brand {
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--text);
  margin-right: auto;
}
.topbar__brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 14px; align-items: center; }
.topbar nav a { font-size: 14px; text-decoration: none; color: var(--text-dim); }
.topbar nav a:hover { color: var(--text); }

/* Cycles device → light → dark. Each icon shows for its own state, keyed off
   the attribute the server already rendered, so nothing flickers on load. */
.theme-toggle {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--text-dim);
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.theme-toggle:hover { color: var(--text); }
.theme-toggle svg { display: none; width: 16px; height: 16px; }
:root:not([data-theme]) .theme-toggle [data-icon="auto"],
:root[data-theme="light"] .theme-toggle [data-icon="light"],
:root[data-theme="dark"] .theme-toggle [data-icon="dark"] { display: block; }

/* --- Cards ---------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-top: 18px;
}
.card__title {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

/* --- Today's workout ------------------------------------------------------ */

.plan {
  /* Accent edge marks this as coach-authored, not the athlete's own data. */
  border-left: 3px solid var(--accent);
  padding-top: 14px;
}
.plan--empty { border-left-color: var(--border); }
.plan__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.plan__eyebrow {
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  white-space: nowrap;
}
.plan__select {
  width: auto;
  max-width: 60%;
  padding: 8px 10px;
  border-radius: 8px;
  font-weight: 600;
}
.plan__title {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}
.plan__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.plan__meta:empty { display: none; }
.plan__loc {
  display: inline-block;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 650;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
}
.plan__desc {
  margin-top: 13px;
  padding-top: 13px;
  border-top: 1px solid var(--border);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-dim);
  /* Coaches type one interval per line; keep the breaks they typed. */
  white-space: pre-line;
}
.plan__none { font-size: 15px; color: var(--text-dim); }

/* --- Entry form ----------------------------------------------------------- */

.entry { padding-bottom: 20px; }
.entry__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.entry__grid .full { grid-column: 1 / -1; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: 5px;
}

.optional {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

input[type="text"],
input[type="date"],
input[type="number"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 12px;
  font-size: 16px; /* 16px prevents iOS zoom-on-focus. */
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}
textarea { resize: vertical; }

.miles-input input { font-size: 24px; font-weight: 650; padding: 14px 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 18px;
  min-height: 46px; /* Thumb-sized tap target. */
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.06); }
.btn--block { width: 100%; }
.btn--ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border);
}
.btn--link {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 4px 6px;
  min-height: 0;
  font-size: 13px;
  text-decoration: underline;
}
.btn--danger { color: var(--danger); }

.errors {
  background: var(--warn-soft);
  border: 1px solid var(--warn);
  color: var(--warn);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  margin-bottom: 12px;
}
.errors ul { margin: 0; padding-left: 18px; }

.field-error { color: var(--danger); font-size: 13px; margin-top: 4px; }

/* --- Week strip ----------------------------------------------------------- */

.weeknav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
}
.weeknav__label { font-weight: 650; font-size: 15px; }
.weeknav__total {
  font-size: 13px;
  color: var(--text-dim);
}
.weeknav__btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 40px;
  min-height: 40px;
  font-size: 18px;
  color: var(--text);
  cursor: pointer;
}
/* No surface fill marks it as inert; the arrow itself stays legible. */
.weeknav__btn[disabled] {
  background: transparent;
  border-style: dashed;
  color: var(--text-dim);
  cursor: default;
}
/* The coach week view navigates with links, not HTMX buttons. */
a.weeknav__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.total-banner {
  display: flex;
  padding: 15px 18px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 14px;
}
.stat { flex: 1; min-width: 0; }
.stat + .stat {
  border-left: 1px solid var(--border);
  padding-left: 18px;
  margin-left: 18px;
}
.stat__num {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
  line-height: 1.1;
}
.stat--muted .stat__num { color: var(--text-dim); }
.stat__label { font-size: 13px; color: var(--text-dim); }

.day {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.day:last-child { border-bottom: none; }
.day__date {
  width: 62px;
  flex: none;
  font-size: 13px;
  color: var(--text-dim);
}
.day__date b { display: block; font-size: 15px; color: var(--text); font-weight: 650; }
/* An empty day steps its weekday down to the dim colour; today's stays accent. */
.day--empty .day__date b { color: var(--text-dim); font-weight: 500; }
.day--today .day__date b { color: var(--accent); font-weight: 650; }
.day__runs { flex: 1; min-width: 0; }
.run {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  padding: 2px 0;
}
.run__miles { font-weight: 650; }
.run__meta { font-size: 13px; color: var(--text-dim); }
.run__notes { font-size: 13px; color: var(--text-dim); width: 100%; }
.run__actions { margin-left: auto; display: flex; gap: 2px; }

.tag {
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-dim);
}
.tag--race { background: var(--accent-soft); color: var(--accent); }
.tag--workout { background: var(--warn-soft); color: var(--warn); }
.tag--flag { background: var(--warn-soft); color: var(--warn); text-transform: none; }

.empty { color: var(--text-dim); font-size: 14px; padding: 8px 0; }

.toast {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}

/* --- Tables (coach) ------------------------------------------------------- */

/* Bleeds to the card's edge. The 18px inset lives on the end cells rather than
   on this box: padding here would sit outside the sticky column's pinned edge,
   leaving a strip the scrolled cells show through. */
.scroller { overflow-x: auto; margin: 0 -18px; }

table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td {
  padding: 9px 10px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  font-weight: 650;
}
th:last-child, td:last-child { padding-right: 28px; }
th:first-child, td:first-child {
  /* 28px = the card's 18px inset plus the usual 10px cell padding. */
  padding-left: 28px;
  text-align: left;
  position: sticky;
  left: 0;
  /* Keeps the pinned name above cells scrolling underneath it, so they can't
     paint over the column or swallow clicks on the link inside it. */
  z-index: 1;
  background: var(--surface);
}
tbody tr:hover td { background: var(--surface-2); }
tbody tr:hover td:first-child { background: var(--surface-2); }
td.zero { color: var(--text-dim); }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }
.col-total { font-weight: 700; }

.rowlink { color: var(--text); text-decoration: none; font-weight: 600; }
.rowlink:hover { color: var(--accent); }

/* Week headers drill into that week's day-by-day grid. */
.collink {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted var(--text-dim);
}
.collink:hover { color: var(--accent); border-bottom-color: var(--accent); }

.gridnote { color: var(--text-dim); font-size: 13px; margin: 18px 0 0; }

/* --- Weekly plan (coach) -------------------------------------------------- */

.plantools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}
.plantools .gridnote { margin: 0; }
.plantoast { margin: 14px 0 0; }

.btn--small { min-height: 36px; padding: 7px 14px; font-size: 14px; }

/* Desktop: the seven days share the card's width, so the week never scrolls
   sideways and needs no pinned column. Titles wrap; long ones clamp. */
.plangrid { table-layout: fixed; }
.plangrid__group { width: 84px; }
.plangrid__total { width: 64px; }
.plangrid th,
.plangrid td {
  position: static;
  padding: 8px 3px;
  text-align: left;
  vertical-align: top;
  white-space: normal;
  background: none;
}
.plangrid th:first-child, .plangrid td:first-child { padding-left: 0; }
.plangrid th:last-child, .plangrid td:last-child { padding-right: 0; text-align: right; }
.plangrid th { padding-left: 9px; }
.plangrid tbody tr:hover td,
.plangrid tbody tr:hover td:first-child { background: none; }
.plangrid tbody tr:last-child td { border-bottom: none; }
.plangrid .is-today { background: var(--accent-soft); }
.plangrid th.is-today { color: var(--accent); border-radius: 8px 8px 0 0; }
.plangrid .plangrid__name,
.plangrid .plangrid__sum { padding-top: 15px; font-weight: 650; }

.plancell__btn {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 76px;
  padding: 6px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}
.plancell__btn:hover,
.plancell__btn:focus-visible { background: var(--surface-2); border-color: var(--border); }
.plancell__btn--empty { display: flex; align-items: center; justify-content: center; }
.plancell__title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.3;
}
.plancell__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-dim);
}
.plancell__meta .tag { font-size: 10px; padding: 1px 6px; }
.plancell__loc {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plancell__add { font-size: 13px; color: var(--text-dim); }

/* Phones and narrow windows: a section per day instead of seven columns. */
.planlist { display: none; }
.plantotals {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-dim);
}
.plantotals b { color: var(--text); font-weight: 650; }
.planday { padding: 12px 0 6px; border-bottom: 1px solid var(--border); }
.planday:last-child { border-bottom: none; padding-bottom: 0; }
.planday__head {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
.planday--today .planday__head { color: var(--accent); }
.planday__row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: start;
  gap: 6px;
}
.planday__group { padding-top: 7px; font-size: 13px; font-weight: 650; }
.planday .plancell__btn { min-height: 0; padding: 6px 8px; }
.planday .plancell__btn--empty { justify-content: flex-start; }
.planday .plancell__title { -webkit-line-clamp: 2; font-size: 14px; }

@media (max-width: 879px) {
  .plangrid { display: none; }
  .planlist { display: block; }
}

/* The workout editor. A centred dialog on desktop, a bottom sheet on phones. */
.editor {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.editor::backdrop { background: rgb(0 0 0 / 45%); }
.editor__body { padding: 18px; }
.editor__eyebrow {
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}
.editor__title { margin: 2px 0 14px; font-size: 18px; font-weight: 700; }
.editor__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.editor__grid .full { grid-column: 1 / -1; }
.editor__check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
}
.editor__check input { width: 18px; height: 18px; accent-color: var(--accent); }
.editor__hint { margin: 12px 0 0; font-size: 13px; color: var(--text-dim); }
.editor__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

@media (max-width: 639px) {
  .editor {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: none;
  }
  .editor__body { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .editor__actions .btn { flex: 1; }
}

.alert {
  background: var(--warn-soft);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-top: 18px;
}
.alert__title { font-weight: 650; color: var(--warn); margin: 0 0 8px; font-size: 14px; }
.alert ul { margin: 0; padding-left: 18px; font-size: 14px; }
.alert li { margin-bottom: 3px; }

.muted { color: var(--text-dim); font-size: 13px; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 5px;
  word-break: break-all;
}

/* --- Season progress chart ------------------------------------------------ */

/* Chart.js sizes to the parent, so the parent is what sets the height. */
.chart {
  position: relative;
  height: 260px;
  margin-top: 4px;
}

.chart__delta {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  vertical-align: middle;
  margin-left: 8px;
}
.chart__delta--ahead { color: var(--accent); background: var(--accent-soft); }
.chart__delta--behind { color: var(--warn); background: var(--warn-soft); }

.chart__note { color: var(--text-dim); font-size: 13px; margin: 12px 0 0; }

@media (min-width: 640px) {
  .chart { height: 320px; }
}

/* --- Centered auth pages -------------------------------------------------- */

.narrow { max-width: 400px; margin: 48px auto; padding: 0 16px; }
.narrow h1 { font-size: 22px; letter-spacing: -0.02em; }

.htmx-request .btn { opacity: 0.6; pointer-events: none; }

@media print {
  .topbar, .btn, .no-print { display: none !important; }
  .card { box-shadow: none; break-inside: avoid; }
}

@media (min-width: 640px) {
  .entry__grid { grid-template-columns: repeat(4, 1fr); }
  .entry__grid .full { grid-column: 1 / -1; }
  .entry__grid .span2 { grid-column: span 2; }
}
