/* analytics.css — owned by the analytics worker (docs/SPEC.md §5). Every
   class here is prefixed `an-`; only the tokens core's style.css defines are
   used: --bg --surface --surface-2 --line --text --muted --accent
   --accent-ink --coach --warmup --drop --failure --amrap --ok --danger
   --radius --pad --maxw. No new tokens are declared here. */

/* ---- search / filters (exercises library) --------------------------------- */
.an-search {
  margin-bottom: 2px;
}
.an-chiprow {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.an-chiprow::-webkit-scrollbar { display: none; }
.an-chip {
  flex: 0 0 auto;
  font: inherit;
  font-size: 13.5px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  min-height: 36px;
}
.an-chip-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
}
.an-filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.an-select {
  flex: 1 1 auto;
  min-width: 140px;
}
.an-fav-toggle {
  font: inherit;
  font-size: 14px;
  padding: 9px 14px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.an-fav-toggle-active {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 650;
}

/* ---- exercise list rows ----------------------------------------------------- */
.an-list { display: grid; gap: 8px; }
.an-ex-row { gap: 10px; }
.an-ex-name { flex: 1; text-align: left; }
.an-star {
  font: inherit;
  font-size: 18px;
  line-height: 1;
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  min-width: 32px;
  min-height: 32px;
}
.an-star-active { color: var(--accent); }

/* ---- exercise detail --------------------------------------------------------- */
.an-detail-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.an-detail-title { flex: 1; margin: 0; text-align: center; }
.an-subtabs {
  display: flex;
  gap: 6px;
  margin-bottom: 2px;
}
.an-subtab {
  flex: 1;
  font: inherit;
  font-size: 13.5px;
  padding: 9px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  min-height: 40px;
}
.an-subtab-active {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 650;
}
.an-detail-body { display: grid; gap: 12px; }

.an-about { gap: 10px; }
.an-about-row { padding: 2px 0; }
.an-about-notes { display: grid; gap: 4px; }
.an-about-notes p { margin: 0; white-space: pre-wrap; }
.an-about-flags { display: flex; gap: 8px; flex-wrap: wrap; }

.an-records-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 380px) { .an-records-grid { grid-template-columns: 1fr; } }
.an-record-card { display: grid; gap: 2px; }
.an-record-value { font-size: 20px; font-weight: 700; color: var(--accent); }
.an-record-day { font-size: 12.5px; color: var(--muted); }

.an-history { display: grid; gap: 10px; }
.an-history-date { font-weight: 650; }
.an-history-sets { display: grid; gap: 6px; margin-top: 4px; }
.an-set-row { display: flex; align-items: center; gap: 8px; font-size: 14.5px; }
.an-set-detail { flex: 1; }

.an-chart-wrap { display: grid; gap: 10px; }
.an-chart-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.an-chart-controls .an-select { flex: 0 0 auto; min-width: 150px; }
.an-chart { width: 100%; }
.an-chart svg { display: block; }
.an-chart-empty {
  padding: 28px 8px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
/* A bar chart whose every value is zero (owner review, 2026-09-24) — a
   one-line caption at roughly the compact chart height, not a 28px-padded
   block plus an axis that tops out at "1 lb". */
.an-chart-empty-compact {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 8px;
}
.an-axis-label {
  font-size: 9px;
  font-family: inherit;
  fill: var(--muted);
}
.an-last-label {
  font-size: 10.5px;
  font-weight: 700;
  font-family: inherit;
  fill: var(--text);
}
.an-spark-label {
  font-size: 9px;
  font-weight: 700;
  font-family: inherit;
  fill: var(--text);
}
.an-grid-line {
  stroke: var(--line);
  stroke-width: 1;
  opacity: 0.55;
}
/* Value label drawn above every non-zero bar (owner review, 2026-09-24 —
   replaces the old single floating "last value" label that clipped at the
   chart edge). */
.an-bar-value {
  font-size: 9.5px;
  font-weight: 700;
  font-family: inherit;
  fill: var(--text);
}

/* Fixed, compact chart height — bar charts scale by width only; height comes
   from these rules, never from the SVG's own aspect ratio (chart.js sets
   preserveAspectRatio="none" for exactly this reason). ~150px on phone,
   ~180px on desktop, per the owner's "tighten everything up" review. */
.an-chart-bar svg {
  display: block;
  width: 100%;
  height: 150px;
}
@media (min-width: 960px) {
  .an-chart-bar svg { height: 180px; }
}

/* Chart cards run tighter than the default card padding — the chart itself
   already carries visual weight, so the surrounding whitespace doesn't need
   to. Selector chained on the page wrapper's own two classes to out-rank
   each theme's `[data-theme] .card{padding:…}` rule regardless of load
   order (docs/SPEC.md §5 — analytics.css owns every `an-` rule but the
   base `.card` padding is core's). */
.an-progress.stack .an-chart-card { padding: 12px 14px; }

/* Legend: a proper swatch + label pair, laid out under the chart as DOM
   (never SVG text) so it stays readable at any zoom and matches whatever
   `barChart(el, bars, { stacked: true })` actually painted. */
.an-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: var(--muted);
}
.an-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.an-legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: 0 0 auto;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
/* Same fills as the stacked bar's own segments (chart.js barChart) — direct
   is the solid neutral segment, fractional is the accent tint on top. */
.an-swatch-fractional {
  background: var(--accent);
  opacity: 0.4;
  border-color: transparent;
}

/* ---- progress dashboard ------------------------------------------------------ */
/* Consistent section rhythm (owner review, 2026-09-24 — "tighten everything
   up"): every section label on this page gets the same top margin, rather
   than each theme's own generic `.section-label` spacing (meant for the
   whole app) compounding with the page's own `.stack` gap into oversized
   gaps between chart cards and streak/PR tiles. Chained on both of the page
   wrapper's own classes (`.an-progress.stack`) so this out-ranks each
   theme's `[data-theme] .section-label{margin:…}` rule regardless of CSS
   load order — see the `.an-chart-card` rule below for the same trick. */
.an-progress.stack .section-label { margin-top: 20px; }
.an-stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.an-stat-tile { gap: 4px; }
.an-stat-label { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.an-stat-value { font-size: 22px; font-weight: 700; }
.an-stat-delta { font-size: 12.5px; color: var(--muted); }
.an-stat-delta-pos { color: var(--ok); }
.an-stat-delta-neg { color: var(--danger); }

/* Recent PRs — one card, one compact row per exercise+day (owner review,
   2026-09-24 — was a card per PR, 20 tall cards for 5 sessions). */
.an-pr-rows { display: grid; }
.an-pr-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.an-pr-row:last-child { border-bottom: 0; }
.an-pr-row-left {
  font-weight: 650;
  font-size: 14px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.an-pr-row-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  flex: 0 1 auto;
}
.an-pr-chip {
  font-size: 12px;
  font-weight: 650;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  white-space: nowrap;
}
.an-pr-showall { margin: 10px 0 6px; }

.an-sparkline { max-width: 220px; }

/* ---- body -------------------------------------------------------------------- */
.an-metric-chips { margin-bottom: 2px; }
.an-body-quick { gap: 12px; }
.an-metric-row { gap: 8px; }

/* ---- calendar ------------------------------------------------------------------ */
.an-cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.an-cal-month { flex: 1; text-align: center; margin: 0; }
.an-cal-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 650;
}
.an-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.an-cal-cell {
  font: inherit;
  aspect-ratio: 1;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  padding: 2px;
  min-height: 44px;
}
.an-cal-cell-blank {
  visibility: hidden;
  border: 0;
  background: none;
  cursor: default;
}
.an-cal-cell-today { border-color: var(--accent); }
.an-cal-daynum { font-size: 13px; }
.an-cal-dots { display: flex; gap: 2px; min-height: 6px; }
.an-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); display: inline-block; }
.an-dot-planned { background: var(--muted); }
.an-dot-active { background: var(--accent); }
.an-dot-done { background: var(--ok); }
.an-cal-legend { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 12.5px; }

/* ---- settings ------------------------------------------------------------------- */
.an-field { gap: 12px; }
.an-plates-list { display: flex; gap: 8px; flex-wrap: wrap; }
.an-plate-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px 5px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 13.5px;
}
.an-plate-remove {
  font: inherit;
  font-size: 12px;
  line-height: 1;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 0;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.an-toggle-row { display: flex; gap: 20px; flex-wrap: wrap; }

/* ==========================================================================
   DESKTOP (docs/SPEC.md §11.5) — additive only; every rule below either
   targets an element that exists on desktop alone or sits inside the
   @media block. The phone layout above is unchanged.
   ========================================================================== */

/* Chart pairs are wrapped by views/progress.js unconditionally; on phone the
   wrapper is a plain single-column stack. */
.an-charts-2up { display: grid; gap: 12px; }
.an-chart-block { display: grid; gap: 8px; }

/* Workout names inside calendar cells (§11.5) — built unconditionally by
   views/calendar.js, shown only on desktop where there is room. */
.an-cal-names { display: none; }

/* The desktop exercise library table (§11.5). */
.an-ex-table { display: none; }

@media (min-width: 960px) {
  /* ---- progress dashboard: tiles 4-up, charts 2-up --------------------- */
  .an-stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
  .an-charts-2up { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
  .an-records-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .an-sparkline { max-width: 420px; }

  /* ---- exercise library: a table, with the detail in the right pane ----- */
  .an-list { display: none; }
  .an-ex-table { display: block; width: 100%; overflow-x: auto; }
  .an-ex-table table { width: 100%; border-collapse: collapse; font-size: 14px; }
  .an-ex-table th {
    text-align: left;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 650;
    padding: 6px 10px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
  }
  .an-ex-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); }
  .an-ex-table tbody tr { cursor: pointer; }
  .an-ex-table tbody tr:hover { background: var(--surface-2); }
  .an-ex-table tbody tr.an-ex-row-active { background: color-mix(in srgb, var(--accent) 14%, transparent); }
  .an-ex-table tbody tr.archived { opacity: 0.6; }
  .an-ex-table .an-ex-cell-name { font-weight: 650; }
  .an-ex-table .an-ex-cell-star { width: 40px; text-align: center; }
  .an-ex-table .an-ex-cell-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

  /* ---- calendar: fills the width, names inside the cells ---------------- */
  .an-cal-grid { gap: 8px; }
  .an-cal-cell {
    aspect-ratio: auto;
    min-height: 92px;
    align-items: stretch;
    justify-content: flex-start;
    padding: 6px 8px;
    text-align: left;
  }
  .an-cal-daynum { font-size: 14px; font-weight: 650; align-self: flex-start; }
  .an-cal-names { display: grid; gap: 2px; width: 100%; }
  .an-cal-name {
    font-size: 11.5px;
    line-height: 1.25;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .an-cal-name-done { color: var(--ok); }
  .an-cal-name-active { color: var(--accent); }
  .an-cal-head { font-size: 13px; }

  /* ---- exercise detail in a pane --------------------------------------- */
  .pane-detail .an-detail-head { justify-content: flex-start; }
  .pane-detail .an-detail-title { text-align: left; }
}

/* ==========================================================================
   §19.3 desktop Exercise Explorer (owner, 2026-09-24) — replaces the plain
   `.an-ex-table` two-pane library above at >= 960px. Deliberately its own
   grid, not `.two-pane`/`.pane-list`/`.pane-detail` (docs/SPEC-NOTES.md,
   "Frontend deviations (§19)"): those are fixed 320px/1fr for the routines
   builder, and this screen needs full-width-until-selected then ~60/40.
   ========================================================================== */

/* Category chips WRAP here (never a scrolling row) — the explorer-only
   modifier, so the phone library's own `.an-chiprow` (which still scrolls)
   is untouched. */
.an-chiprow-wrap { flex-wrap: wrap; overflow: visible; }

.an-explorer-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start; }
.an-explorer-tablewrap {
  container-type: inline-size;
  container-name: an-explorer;
  min-width: 0;
  overflow: visible;
}
.an-explorer-detail { display: none; min-width: 0; }

/* A CSS-grid "table" (never a real <table> with min-widths, per the owner's
   layout rules) so hiding a column at a narrow container width is just one
   fewer track, never horizontal scroll. Header + each row are `display:
   contents` so every cell is a direct grid child and auto-placement lines
   columns up without explicit grid-column indices. */
.an-explorer-grid {
  display: grid;
  grid-template-columns:
    minmax(0, 2.2fr) minmax(0, 1fr) minmax(0, 0.9fr) minmax(0, 0.9fr)
    minmax(0, 1.8fr) minmax(0, 1fr) minmax(0, 0.7fr) minmax(0, 0.8fr) minmax(0, 0.5fr);
  column-gap: 10px;
  font-size: 14px;
}
.an-explorer-headrow, .an-explorer-row { display: contents; }
.an-exp-th {
  font: inherit;
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 650;
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
  background: none;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  cursor: default;
}
.an-exp-th-sort { cursor: pointer; }
.an-exp-th-sort:hover { color: var(--text); }
.an-exp-cell {
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
  overflow-wrap: anywhere;
}
/* Long names wrap, never truncate (owner layout rule). */
.exp-c-name { white-space: normal; }
.an-explorer-row { cursor: pointer; }
.an-explorer-row:hover .an-exp-cell { background: var(--surface-2); }
.an-explorer-row.an-ex-row-active .an-exp-cell { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.an-explorer-row.archived .an-exp-cell { opacity: 0.6; }
.exp-c-last, .exp-c-times, .exp-c-7d { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.exp-c-star { text-align: center; }
.exp-c-frac.an-exp-cell { display: flex; }

/* Column collapse order (owner layout rule, narrowest first as the
   container — the table pane, not the viewport — shrinks, e.g. once a row
   is selected and the detail pane takes ~40%): 7-day sets -> Times ->
   Last done -> Kind -> Equipment. Name + Category + Counts for + ★ never
   collapse. Equipment isn't named in the owner's explicit collapse list
   (docs/SPEC-NOTES.md "Frontend deviations (§19)") — it is the one column
   left unaccounted for between the four collapsible ones and the four
   that "always stay", so it collapses last, just before Kind's own
   threshold would otherwise leave Equipment orphaned as the widest of the
   remaining lower-priority columns. */
@container an-explorer (max-width: 900px) {
  .exp-c-7d { display: none; }
  .an-explorer-grid {
    grid-template-columns:
      minmax(0, 2.2fr) minmax(0, 1fr) minmax(0, 0.9fr) minmax(0, 0.9fr)
      minmax(0, 1.8fr) minmax(0, 1fr) minmax(0, 0.7fr) minmax(0, 0.5fr);
  }
}
@container an-explorer (max-width: 760px) {
  .exp-c-times { display: none; }
  .an-explorer-grid {
    grid-template-columns:
      minmax(0, 2.2fr) minmax(0, 1fr) minmax(0, 0.9fr) minmax(0, 0.9fr)
      minmax(0, 1.8fr) minmax(0, 1fr) minmax(0, 0.5fr);
  }
}
@container an-explorer (max-width: 620px) {
  .exp-c-last { display: none; }
  .an-explorer-grid {
    grid-template-columns:
      minmax(0, 2.2fr) minmax(0, 1fr) minmax(0, 0.9fr) minmax(0, 0.9fr)
      minmax(0, 1.8fr) minmax(0, 0.5fr);
  }
}
@container an-explorer (max-width: 520px) {
  .exp-c-kind { display: none; }
  .an-explorer-grid {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 0.9fr) minmax(0, 1.8fr) minmax(0, 0.5fr);
  }
}
@container an-explorer (max-width: 440px) {
  .exp-c-equip { display: none; }
  .an-explorer-grid { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1.8fr) minmax(0, 0.5fr); }
}

@media (min-width: 960px) {
  /* No selection: table gets the full width. Selected: ~60/40. */
  .an-explorer-layout.has-detail { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
  .an-explorer-layout.has-detail .an-explorer-detail { display: block; }
}

/* One-off "undo" snackbar for the explorer's immediate-PATCH chip edits
   (js/views/exercises.js's `showUndoToast`) — not shared.js's `#toast`,
   which is text-only. */
.an-undo-toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  font-size: 14px;
  color: var(--text);
}

/* Legend for the stacked "sets per muscle group" bar (§19.3) — same hue,
   lighter for fractional credit, matching js/chart.js's `barChart` fill. */
.an-chart-legend { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.an-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.an-legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; background: var(--accent); }
.an-legend-fractional { opacity: 0.4; }

/* PR rows: name + date on their own line, chips wrapping beneath — the
   side-by-side layout truncated "Bench Press · Wed, Sep 23" to "We···". */
.an-pr-row { flex-direction: column; align-items: stretch; gap: 6px; }
.an-pr-row-left { white-space: normal; overflow: visible; text-overflow: clip; }
.an-pr-row-chips { justify-content: flex-start; }
@media (min-width: 960px) {
  .an-pr-row { flex-direction: row; align-items: center; }
  .an-pr-row-left { flex: 0 0 240px; }
  .an-pr-row-chips { justify-content: flex-end; }
}
