/*
 * stats.css — Statistics view: summary tiles, stacked discipline chart and
 *             shaded year tables.
 *
 * @copyright  2026 Karl Dyson
 * @license    Apache-2.0
 * @version    1.7.0
 */

#view-stats {
  --stats-series-1: #2a78d6;  /* categorical slots, fixed order (CVD-checked) */
  --stats-series-2: #eb6834;
  --stats-series-3: #1baf7a;
  --stats-series-4: #eda100;
  --stats-series-5: #e87ba4;
  --stats-series-6: #008300;
  --stats-series-7: #6250d6;
  --stats-series-8: #e34948;
  --stats-h1: #cde2fb;        /* days shading: one hue, more days = darker */
  --stats-h2: #9ec5f4;
  --stats-h3: #6da7ec;
  --stats-h4: #3987e5;
  --stats-h5: #1c5cab;
  --stats-grid: #eceef2;

  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
#admin-stats > h2 { margin-bottom: 0; }

.stats-page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}
.stats-page-head h2 { margin-bottom: 0; }
.stats-print-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
}

#admin-stats {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-top: 1rem;
}

/* ---------------------------------------------------------------------------
   Summary tiles
   --------------------------------------------------------------------------- */

.stats-tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}
/* Even rows of tiles: 4, then 2, then 1 — never 3 + 1 */
@media (max-width: 900px) { .stats-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .stats-tiles { grid-template-columns: 1fr; } }
.stats-tiles:empty { display: none; }

.stats-tile {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.stats-tile-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stats-tile-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.stats-tile-value.stats-tile-text { font-size: 1.15rem; line-height: 1.3; padding-top: 0.35rem; }
.stats-tile-sub { font-size: 0.85rem; color: var(--color-text-muted); }
.stats-up   { color: var(--color-success); font-weight: 600; }
.stats-down { color: var(--color-danger);  font-weight: 600; }

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

.stats-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.15rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}
.stats-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}
.stats-card-head h3 {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stats-card-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
}
.stats-empty { color: var(--color-text-muted); font-size: 0.9rem; }

/* ---------------------------------------------------------------------------
   Stacked discipline chart
   --------------------------------------------------------------------------- */

.stats-chart { width: 100%; height: auto; display: block; }
.stats-grid-line { stroke: var(--stats-grid); stroke-width: 1; }
.stats-axis { font-size: 12px; fill: var(--color-text-muted); }
.stats-axis-year { font-size: 13px; }
.stats-seg-label { font-size: 12px; font-weight: 600; fill: #fff; pointer-events: none; }
.stats-total-label { font-size: 13px; font-weight: 700; fill: var(--color-text); }

.stats-legend { display: flex; flex-wrap: wrap; gap: 1rem; font-size: 0.85rem; color: var(--color-text-muted); }
.stats-legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.stats-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* ---------------------------------------------------------------------------
   Shaded year tables
   --------------------------------------------------------------------------- */

.stats-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  cursor: pointer;
  user-select: none;
}
.stats-switch input { accent-color: var(--color-primary); }

.stats-key { display: flex; align-items: center; gap: 4px; font-size: 0.75rem; color: var(--color-text-muted); }
.stats-key i { width: 18px; height: 12px; border-radius: 3px; display: inline-block; }

.stats-scroll { overflow-x: auto; }

.stats-heat {
  border-collapse: separate;
  border-spacing: 2px;
  width: 100%;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
.stats-heat th {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-align: center;
  padding: 0.25rem 0.15rem;
  white-space: nowrap;
}
.stats-heat td {
  text-align: center;
  height: 2.2rem;
  min-width: 3rem;
  border-radius: 4px;
}
.stats-heat .stats-name {
  text-align: left;
  white-space: nowrap;
  padding: 0 0.75rem 0 0.4rem;
  min-width: 0;
}
.stats-heat .stats-nodata { color: var(--color-text-muted); font-style: italic; }
.stats-heat .stats-total { font-weight: 700; padding: 0 0.4rem; }
.stats-heat .stats-zero::after { content: "·"; color: var(--color-text-muted); opacity: 0.6; }
.stats-heat tr.stats-group th {
  text-align: left;
  color: var(--color-text);
  font-size: 0.85rem;
  padding: 0.75rem 0.4rem 0.25rem;
  border-bottom: 1px solid var(--stats-grid);
}
.stats-heat tbody tr.stats-group:first-child th { padding-top: 0.25rem; }

.stats-h1 { background: var(--stats-h1); color: #10233d; }
.stats-h2 { background: var(--stats-h2); color: #10233d; }
.stats-h3 { background: var(--stats-h3); color: #10233d; }
.stats-h4 { background: var(--stats-h4); color: #fff; }
.stats-h5 { background: var(--stats-h5); color: #fff; }

.stats-heat td.stats-cell { cursor: pointer; }
.stats-heat td.stats-cell:hover,
.stats-heat td.stats-cell:focus-visible { outline: 2px solid var(--color-primary); outline-offset: -2px; }
.stats-heat td.sel { outline: 2px solid var(--color-text); outline-offset: -2px; }

/* ---------------------------------------------------------------------------
   Events behind a cell
   --------------------------------------------------------------------------- */

.stats-detail {
  border-top: 1px solid var(--stats-grid);
  padding-top: 0.6rem;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}
.stats-detail strong { color: var(--color-text); }

.stats-events {
  list-style: none;
  margin-top: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stats-event {
  width: 100%;
  display: grid;
  grid-template-columns: 9rem minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: baseline;
  text-align: left;
  font: inherit;
  color: var(--color-text);
  background: none;
  border: none;
  border-radius: 4px;
  padding: 0.35rem 0.4rem;
  cursor: pointer;
}
.stats-event:hover,
.stats-event:focus-visible { background: var(--color-bg); outline: none; }
.stats-event-date { color: var(--color-text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.stats-event-name { font-weight: 600; min-width: 0; }
.stats-event-meta { color: var(--color-text-muted); font-size: 0.85rem; text-align: right; }

@media (max-width: 600px) {
  .stats-event { grid-template-columns: 1fr; gap: 0.1rem; }
  .stats-event-meta { text-align: left; }
}
