/*
 * Internal statistics dashboard (/statistics).
 *
 * Builds on the tokens in application.css. Chart chrome is deliberately
 * recessive — hairline grid, muted axis text — so the only loud thing on the
 * page is the data itself. Series colours live in the view (the controller
 * hands each chart its own hex) because they are data identity, not styling.
 */

/* ===== Range switcher ==================================================== */

/* One filter row above everything it scopes: both charts and totals re-render
   from the same slice, so the numbers on the page always agree. */
.stats__filters {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.stats__range {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 16px;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.stats__range:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.stats__range--active {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}

.stats__range:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ===== Chart card ======================================================== */

.stats-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 20px 12px;
  margin-bottom: 20px;
}

.stats-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.stats-card__title {
  display: inline;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

/* The series colour rides beside the title as a mark, never on the text —
   a light hue is illegible as type on this surface. */
.stats-card__key {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 8px;
  vertical-align: middle;
}

.stats-card__total {
  text-align: right;
  line-height: 1.2;
}

/* Proportional figures: tabular-nums would make a standalone number like 121
   look loose at this size. */
.stats-card__total-value {
  display: block;
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
}

.stats-card__total-label {
  font-size: 12px;
  color: var(--muted-2);
}

/* Anchors the absolutely-positioned tooltip. */
.stats-card__plot {
  position: relative;
  margin-top: 4px;
}

.stats-chart {
  display: block;
  width: 100%;
  overflow: visible;
}

.stats-chart:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 4px;
  border-radius: var(--radius-sm);
}

/* ===== Chart marks & chrome ============================================== */

.stats-chart__line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* The 2px ring is the surface colour: it keeps dots legible where they sit on
   the line or crowd a neighbour, without a border adding non-data ink. */
.stats-chart__dot {
  stroke: var(--surface);
  stroke-width: 2;
}

.stats-chart__grid {
  stroke: var(--border);
  stroke-width: 1;
}

.stats-chart__baseline {
  stroke: var(--border-strong);
  stroke-width: 1;
}

.stats-chart__crosshair {
  stroke: var(--border-strong);
  stroke-width: 1;
  pointer-events: none;
}

.stats-chart__tick,
.stats-chart__date {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  fill: var(--muted-2);
}

/* At 30 days the labels sit close enough to the line that they cross it in the
   valleys. The surface-coloured stroke behind the glyphs is the text version of
   the dot's surface ring — it separates without adding a box or a leader. */
.stats-chart__value {
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  fill: var(--muted);
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 3px;
  stroke-linejoin: round;
}

/* ===== Tooltip =========================================================== */

.stats-tooltip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}

/* Value leads, label follows — the reader already knows the series. */
.stats-tooltip__value {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 15px;
  font-weight: 700;
}

/* A short stroke of the series colour, not a filled box: at tooltip density a
   box is data-weight ink doing a label's job. */
.stats-tooltip__key {
  display: inline-block;
  width: 12px;
  height: 2px;
  border-radius: 1px;
}

.stats-tooltip__meta {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.72);
  margin-top: 2px;
}

/* ===== Table twin ======================================================== */

.stats-card__table {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.stats-card__table > summary {
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  list-style-position: inside;
}

.stats-card__table > summary:hover {
  color: var(--text);
}

.stats-card__table .stats-table {
  margin-top: 10px;
  max-width: 320px;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.stats-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted-2);
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.stats-table td {
  padding: 9px 12px 9px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
}

.stats-table tr:last-child td {
  border-bottom: none;
}

/* Columns of numbers do align vertically, so tabular figures belong here. */
.stats-table__num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ===== Recent requests =================================================== */

.stats-recent {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}

.stats-recent__title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.stats-recent__empty {
  font-size: 14px;
  color: var(--muted);
  margin-top: 8px;
}

/* Wide content scrolls inside its own box so the page never scrolls sideways. */
.stats-recent__scroll {
  overflow-x: auto;
  margin-top: 8px;
}

.stats-table--recent {
  min-width: 560px;
}

.stats-recent__download {
  font-weight: 600;
  font-size: 13px;
}

/* Status wears a word, never colour alone. */
.stats-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 3px 10px;
  border: 1px solid transparent;
}

.stats-badge--ok {
  color: var(--muted);
  background: var(--fill);
  border-color: var(--border);
}

.stats-badge--failed {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

@media (max-width: 640px) {
  .stats-card__head {
    flex-direction: column;
  }

  .stats-card__total {
    text-align: left;
  }
}
