/* Phit stylesheet, part 2 of 8. The run list, the comparison, the sticky compare bar, the wide-screen layout, the overlay charts and the splits table.
   The parts are one stylesheet cut into files: they must load in this order (index.html and the plain pages list them), because a later rule can override an earlier one. */

/* ----- run list ----- */
.runs { display: flex; flex-direction: column; gap: 0.5rem; }

.run, .train-run {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.15rem 0.75rem;
  align-items: center;
  padding: 0.7rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.run.selected { border-color: var(--accent); background: rgb(var(--accent-rgb) / 0.08); }
.run input, .train-run input { width: 22px; height: 22px; align-self: center; accent-color: var(--accent); flex: none; cursor: pointer; }
.run > div, .train-run > div { min-width: 0; }
.run-name { font-weight: 600; display: flex; align-items: center; gap: 0.15rem; min-width: 0; }
.run-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; text-align: left; }
.run-rename-btn { flex: none; opacity: 0.55; font-size: var(--fs-sm); padding: 0 0.25rem; }
.run:hover .run-rename-btn, .train-run:hover .run-rename-btn, .run-rename-btn:focus-visible { opacity: 1; }
@media (hover: none) { .run-rename-btn { opacity: 0.8; } }
.run-meta { color: var(--muted); font-size: var(--fs-md); }
.train-run-ro { grid-template-columns: minmax(0, 1fr); }            /* the by-week view has no tick box */
.run-stats { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; font-size: var(--fs-base); }

/* The body of a card (runcard.js): the name, the line under it, the figures, the heart-rate zone bar and a rough outline of the route. Where they sit follows the card's own
   width, so the same card is right in the narrow Runs list and across the whole page. Narrow: the name has the full width, and the outline sits at the right of everything
   under it. Wide: the text, the bar and the outline are one row. (The text block gives its three lines to the grid, so each can have its own place.) */
.rc-body { container-type: inline-size; min-width: 0; }
.rc-grid { display: grid; grid-template-columns: minmax(0, 1fr) 3.6rem; grid-template-areas: "name name" "meta map" "stats map" "zones map"; column-gap: 0.7rem; row-gap: 0; align-items: center; }
.rc-text { display: contents; }
.rc-grid .run-name { grid-area: name; }
.rc-grid .run-meta { grid-area: meta; }
.rc-grid .run-stats { grid-area: stats; }
.rc-zones { grid-area: zones; min-width: 0; margin-top: 0.4rem; }
.wk-bar.rc-zones { height: 20px; }
.rc-zones.wk-none { font-size: var(--fs-sm); }
.rc-map { grid-area: map; width: 3.6rem; height: 3.6rem; overflow: visible; }
.rc-trace { fill: none; stroke: var(--muted); stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.rc-start { fill: var(--good); }
.rc-blank { display: block; }
@container (min-width: 42rem) {
  .rc-grid { grid-template-columns: minmax(0, 26rem) minmax(8rem, 1fr) 4.5rem; grid-template-areas: "name zones map" "meta zones map" "stats zones map"; column-gap: 1.25rem; }
  .rc-zones { margin-top: 0; }
  .wk-bar.rc-zones { height: 22px; }
  .rc-map { width: 4.5rem; height: 4.5rem; }
}

/* ----- comparison ----- */
.run-title { font-weight: 600; margin-bottom: 0.15rem; }
.run-title .run-edit-btn { margin-left: 0.5rem; font-weight: 400; font-size: var(--fs-sm); color: var(--muted); }
.run-title .run-edit-btn:hover { color: var(--accent); }
.run-subtitle { color: var(--muted); font-size: var(--fs-sm); margin-bottom: 0.75rem; }

.compare-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr 1.2fr;
  gap: 0.6rem 0.5rem;
  align-items: center;
  font-size: var(--fs-base);
}
.compare-grid .header {
  align-self: end;                                  /* a header taller than the others (a run's date, with its buttons under it) keeps every header's line on the same level */
  font-weight: 600;
  color: var(--muted);
  font-size: var(--fs-sm);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
}
.compare-grid .label { color: var(--muted); }
.compare-grid .run-col { display: flex; flex-direction: column; gap: 0.25rem; }
.compare-grid .run-col { position: relative; padding-right: 1.25rem; }
.draggable-col { cursor: grab; }
.draggable-col .col-title { cursor: grab; }
.col-grip { position: absolute; left: -0.55rem; top: 0.05rem; color: var(--muted); letter-spacing: -0.2em; opacity: 0.6; font-size: var(--fs-sm); user-select: none; }
.compare-grid .run-col .col-title { white-space: nowrap; }
.draggable-col:hover .col-grip { opacity: 1; }
.col-dragging { opacity: 0.4; }
.run-col.drop-left { box-shadow: inset 3px 0 0 var(--accent); }
.run-col.drop-right { box-shadow: inset -3px 0 0 var(--accent); }
.col-title:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.col-tools { display: flex; justify-content: flex-end; gap: 0.2rem; margin-top: 0.2rem; opacity: 0.55; transition: opacity 0.12s; }          /* its own line under the date, so the edit and remove buttons never sit on it */
.compare-grid .run-col:not(.draggable-col) .col-tools { position: absolute; top: 0; right: 0; margin: 0; }          /* one run: just the cross, beside the date, so the header is one line */
.run-col:hover .col-tools, .run-col:focus-within .col-tools { opacity: 1; }
.col-btn { min-height: 22px; min-width: 24px; padding: 0 0.3rem; font-size: var(--fs-xs); line-height: 1; border-radius: var(--r-sm); border: 1px solid var(--border); background: transparent; color: var(--muted); }
.col-btn:hover:not(:disabled) { color: var(--text); border-color: var(--muted); }
.col-btn:disabled { opacity: 0.3; cursor: default; }
.col-remove { font-size: var(--fs-lg); }
.col-remove:hover:not(:disabled) { color: var(--bad); border-color: var(--bad); }
.compare-grid .reset-order { font-size: var(--fs-xs); font-weight: 500; margin-left: 0.3rem; color: var(--accent); }
.delta-up { color: var(--good); }
.delta-down { color: var(--bad); }

/* ----- sticky compare bar (thumb-reachable on phones) ----- */
.compare-bar {
  position: sticky;
  bottom: var(--bottom-nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.compare-bar[hidden] { display: none; }

/* ----- large-screen layout: runs on the left, results on the right ----- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  max-width: 1800px;
  margin: 1rem auto;
  padding: 0 0.75rem;
  align-items: start;
}
.layout .panel { max-width: none; margin: 0; }
.results { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.empty { color: var(--muted); }
.empty :is(h1, h2) { color: var(--text); }
.empty[hidden], #compare-panel[hidden] { display: none; }

.sidebar .compare-bar { position: static; margin-top: 0.75rem; padding: 0.75rem 0 0; background: none; }

@media (min-width: 1000px) {
  .layout { grid-template-columns: 350px minmax(0, 1fr); padding: 0 1.25rem; gap: 1.25rem; }
  .sidebar {
    position: sticky; top: calc(var(--stick) + 1rem);
    max-height: calc(100vh - var(--stick) - 2rem);
    display: flex; flex-direction: column;
  }
  .sidebar .runs { overflow-y: auto; overflow-x: hidden; flex: 1; min-height: 0; padding-right: 4px; }
}

@media (min-width: 1200px) {
  .results-body { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 1.75rem; align-items: start; }
  .numbers-col { position: sticky; top: calc(var(--stick) + 1rem); }
  .results-body.multi { grid-template-columns: minmax(0, 1fr) 560px; } /* room for 3-5 run columns */
  .results-body.tables-folded, .results-body.multi.tables-folded { grid-template-columns: minmax(0, 1fr) auto; }   /* folded: the charts have the width, only the Expand button stays */
}
.numbers-col { display: flex; flex-direction: column; min-width: 0; }
.numbers-col .fold-btn { display: none; align-self: flex-end; margin-bottom: 0.5rem; }
@media (min-width: 1200px) { .numbers-col .fold-btn { display: flex; } }        /* the tables sit beside the charts only here; below, each table folds on its own */
.results-body.tables-folded .numbers { display: none; }

.run.dim { opacity: 0.38; }
.run:hover, .train-run:hover { border-color: var(--muted); }

button.ghost {
  min-height: 34px; padding: 0.25rem 0.8rem;
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); font-weight: 500; font-size: var(--fs-md);
}
button.ghost:hover { color: var(--text); border-color: var(--muted); }

/* ----- overlay charts (d3) ----- */
.chart-card { margin: 0.25rem 0 1.25rem; min-width: 0; }

.chart-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin-bottom: 0.75rem; }
.seg-group { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; }
.seg {
  min-height: 34px; padding: 0.25rem 0.85rem; border-radius: 0;
  background: transparent; color: var(--muted); font-size: var(--fs-md); font-weight: 500;
}
.seg + .seg { border-left: 1px solid var(--border); }
.seg[aria-pressed="true"] { background: rgb(var(--ink-rgb) / 0.09); color: var(--text); }

.chart-legend { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; font-size: var(--fs-base); color: var(--muted); margin-bottom: 0.5rem; }
.legend-item, .readout-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.line-key { display: inline-block; width: 16px; height: 3px; border-radius: 2px; flex: none; }

.chart-readout {
  min-height: 1.7rem; /* stable height so the charts don't jump while you hover */
  display: flex; flex-wrap: wrap; align-items: center; align-content: flex-start;
  gap: 0.25rem 1.4rem; font-size: var(--fs-base); margin-bottom: 0.35rem;
}
.readout-x { color: var(--text); font-weight: 600; min-width: 4.2rem; font-variant-numeric: tabular-nums; }
.readout-group { display: inline-flex; align-items: center; gap: 0.6rem; }
.chart-readout strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.readout-delta { color: var(--muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }

.chart-plot { width: 100%; position: relative; }
.chart-svg { display: block; width: 100%; height: auto; user-select: none; -webkit-user-select: none; }
.chart-svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.chart-svg .grid line { stroke: var(--border); stroke-width: 1; }
.chart-svg .y-axis text, .chart-svg .x-axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-svg .x-axis line { stroke: var(--border); }
.chart-svg .panel-title { fill: var(--text); font-size: 12px; font-weight: 600; }
.chart-svg .panel-unit { fill: var(--muted); font-weight: 400; }
.chart-svg .axis-title { fill: var(--muted); font-size: 11px; }
.chart-svg .series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-svg .crosshair { stroke: var(--muted); stroke-width: 1; pointer-events: none; }
.chart-svg .cross-dot { stroke: var(--panel); stroke-width: 2; pointer-events: none; } /* 2px surface ring */
.chart-svg .brush .selection { fill: rgb(var(--ink-rgb) / 0.1); stroke: var(--muted); stroke-width: 1; }
.chart-svg .brush .overlay { cursor: crosshair; }

/* zoomed-segment comparison */
.segment-card { margin-top: 1rem; padding: 0.9rem 1rem; border: 1px solid var(--border); border-radius: var(--r-lg); }
.segment-card:empty { display: none; }
.segment-title { font-weight: 600; margin-bottom: 0.5rem; font-variant-numeric: tabular-nums; }
.segment-table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); font-variant-numeric: tabular-nums; }
.segment-table th, .segment-table td { text-align: right; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); }
.segment-table th:first-child, .segment-table td:first-child { text-align: left; color: var(--muted); }
.segment-table th { color: var(--muted); font-weight: 500; font-size: var(--fs-sm); }
.segment-table th .line-key { margin-right: 0.4rem; vertical-align: middle; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 0.3rem; }
.dot.s1 { background: var(--series-1); }
.dot.s2 { background: var(--series-2); }

/* ----- splits table (also the chart's table view) ----- */
details.splits { margin-top: 1.25rem; }
details.splits.metrics-section { margin-top: 0; }                      /* the first section sits at the top, like the others it shares a summary look with */
details.splits.metrics-section > .compare-grid { margin-top: 0.5rem; }
details.splits summary { cursor: pointer; color: var(--accent); font-size: var(--fs-base); min-height: 36px; display: flex; align-items: center; }
.similar .hint { margin: 0.1rem 0 0.5rem; font-size: var(--fs-sm); }
.similar summary .chip { margin-left: 0.3rem; vertical-align: 0.05em; }
.sim-list { display: flex; flex-direction: column; gap: 0.3rem; }
.sim-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 0.1rem 0.6rem; align-items: center; padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: var(--r-md); }
.sim-item.on { border-color: var(--accent); background: rgb(var(--accent-rgb) / 0.1); }
.sim-pick { grid-row: 1 / span 2; width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.sim-name { text-align: left; font-weight: 650; font-size: var(--fs-md); min-height: 0; }
.sim-m { grid-column: 2; color: var(--muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.sim-d { grid-column: 3; grid-row: 1 / span 2; font-size: var(--fs-sm); font-weight: 650; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.sim-d.good { color: var(--good); }
.sim-d.bad { color: var(--bad); }
.sim-bar { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-top: 0.6rem; }
.sim-all { color: var(--accent); font-weight: 600; font-size: var(--fs-sm); }
.sim-go { border-radius: var(--r-pill); padding-left: 1.1rem; padding-right: 1.1rem; }
table.splits-table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; font-size: var(--fs-md); font-variant-numeric: tabular-nums; }
.splits-table th, .splits-table td { text-align: right; padding: 0.35rem 0.4rem; border-bottom: 1px solid var(--border); }
.splits-table th:first-child, .splits-table td:first-child { text-align: left; color: var(--muted); }
.splits-table th { color: var(--muted); font-weight: 500; font-size: var(--fs-sm); }
.splits-table .rep-cell { text-align: left; white-space: nowrap; color: var(--muted); }
.splits-table .split-time { display: block; color: var(--muted); font-size: var(--fs-xs); font-weight: 400; }

