/* Layout and components. Every colour, size and space is a token from tokens.css. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: var(--space-4);
  max-width: var(--page-max-width);
  margin-inline: auto;
}

h1,
h2 {
  margin: 0;
  line-height: var(--leading-tight);
}

h1 {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
}

h2 {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-2);
}

/* Header: title, week picker, freshness line. */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-4);
}

.page-header .asof {
  flex-basis: 100%;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.week-picker {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
  font-size: var(--text-sm);
}

.week-picker select {
  font: inherit;
  font-family: var(--font-mono);
  color: var(--color-text);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
}

/* Status banner (loading / error). */
.status {
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-4);
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
}

.status.is-error {
  background: var(--color-error-bg);
  color: var(--color-error);
}

/* Tiles: two across from 375 px, more as the viewport widens. */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile-min-width), 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.tile {
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-tile);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.tile.is-wide {
  grid-column: 1 / -1;
}

.tile .label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.tile .value {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  font-variant-numeric: tabular-nums;
}

.tile .sub {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

.tile .spark {
  position: relative;
  height: var(--sparkline-height);
  margin-top: var(--space-1);
}

.tile .spark canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

/* Fallback when the chart library did not load: the 13 values as text. */
.tile .spark-text {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress {
  height: var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--color-progress-track);
  overflow: hidden;
  margin-top: var(--space-1);
}

.progress > span {
  display: block;
  height: 100%;
  background: var(--color-progress-fill);
}

/* Drill-down tables: each scrolls inside its own box; the page never scrolls sideways. */
.drill {
  margin-bottom: var(--space-5);
}

.table-wrap {
  overflow-x: auto;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: var(--table-min-width);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

caption {
  text-align: left;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding: var(--space-2) var(--space-3);
}

th,
td {
  padding: var(--space-2) var(--space-3);
  text-align: right;
  border-top: var(--border-width) solid var(--color-border);
  white-space: nowrap;
}

th {
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  background: var(--color-surface-muted);
  border-top: 0;
}

th:first-child,
td:first-child {
  text-align: left;
  font-family: var(--font-mono);
}

tr.is-selected td {
  background: var(--color-surface-muted);
  font-weight: var(--weight-semibold);
}

td.empty {
  text-align: left;
  color: var(--color-text-faint);
  font-family: var(--font-sans);
}

.pill {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
}

.pill.ok {
  color: var(--color-ok);
  background: var(--color-ok-bg);
}

.pill.warn {
  color: var(--color-warn);
  background: var(--color-warn-bg);
}

.pill.error {
  color: var(--color-error);
  background: var(--color-error-bg);
}

.health-error {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  white-space: normal;
  max-width: 28em;
}

footer {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  padding-top: var(--space-4);
  border-top: var(--border-width) solid var(--color-border);
}
