/* The page around the grid. The grid brings its own stylesheet. */

:root {
  --ink: #101828;
  --ink-soft: #475467;
  --line: #e4e7ec;
  --page: #f7f8fa;
  --panel: #ffffff;
  --accent: #123a6b;
  --live: #1b8a3f;
  --alarm: #b42318;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/*
 * The page is read down, not fitted to the fold. This column holds a
 * masthead, five figures, six charts, a table and a set of summaries: more
 * than a screen's worth, so it is given a screen as its minimum and allowed
 * to grow past it. Pinned to exactly the viewport's height instead, the
 * items share out less room than they ask for and each one is squeezed.
 */
#app {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 100%;
  padding: 16px 20px 12px;
}

/* The masthead */

.head {
  align-items: flex-end;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
}

.head h1 {
  color: var(--accent);
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0 0 3px;
}

.lede {
  color: var(--ink-soft);
  margin: 0;
  max-width: 88ch;
}

.head-note {
  align-items: center;
  color: var(--ink-soft);
  display: flex;
  flex-wrap: wrap;
  font-size: 12px;
  gap: 10px;
  /* The provenance line carries a whole sentence about where the data came
     from and when. Left unbreakable it sets the width of the masthead, and on
     a phone that one line pushed the whole page sideways. It wraps instead. */
  min-width: 0;
}

.pill {
  align-items: center;
  background: var(--accent);
  border-radius: 999px;
  color: #fff;
  display: inline-flex;
  font-size: 11px;
  font-weight: 600;
  gap: 6px;
  letter-spacing: 0.02em;
  padding: 4px 10px;
  text-transform: uppercase;
}

/* The pulse that shows a poll landed. */
.dot {
  background: #9fe0b4;
  border-radius: 50%;
  height: 7px;
  transition: background 0.2s ease, transform 0.2s ease;
  width: 7px;
}

.dot.beat {
  background: #ffffff;
  transform: scale(1.5);
}

.freshness {
  min-width: 0;
  overflow-wrap: anywhere;
}

.freshness.failed {
  color: var(--alarm);
  font-weight: 600;
}

/* The headline tiles */

.kpi-strip {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.kpi-tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 0;
  padding: 12px 14px;
}

/*
 * The wrapper above is the card, so the tile inside it draws no chrome of its
 * own -- with one exception the grid keeps: a tile carrying a status band
 * draws it down the inline-start edge, and that band is more specific than
 * this rule. Give it room, or it sits under the first character of the label.
 */
.kpi-tile .lat-stat {
  border: 0;
  padding: 0;
}

/*
 * A tile carrying a status band is still one card.
 *
 * The grid draws that band down the inline-start edge of the stat it renders,
 * which sits inside this wrapper -- so the band, with the stat's own rounded
 * corners, read as a second card edge inset within the first, on the one tile
 * that had a band and on none of its neighbours. The band belongs to the card
 * a reader sees, so the wrapper takes it and the inner edge is turned off.
 */
.kpi-tile .lat-stat[data-tone] {
  border-inline-start-width: 0;
  padding-inline-start: 0;
}

.kpi-tile:has(.lat-stat[data-tone='good']) {
  border-left: 3px solid var(--live);
}

.kpi-tile:has(.lat-stat[data-tone='warn']) {
  border-left: 3px solid #d97706;
}

.kpi-tile:has(.lat-stat[data-tone='bad']) {
  border-left: 3px solid var(--alarm);
}

.kpi-error {
  color: var(--alarm);
  font-size: 12px;
}

/* Charts */

.chart-wrap {
  display: grid;
  flex: 0 0 auto;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: 210px;
}

.chart-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  padding: 4px;
}

.chart-error {
  color: var(--alarm);
  font-size: 12px;
  padding: 10px;
}

/* The controls */

.actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.actions[hidden] {
  display: none;
}

.actions-label {
  color: var(--ink-soft);
  font-size: 12px;
  margin-right: 2px;
}

.actions-gap {
  width: 14px;
}

.action {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  padding: 4px 11px;
}

.action:hover {
  background: #eef2f7;
  border-color: #c7d2e0;
}

.action:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.action.toggle.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* The detail grid and the summary tabs */

.primary-host {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  /* A height of its own, so the table is as tall as it needs to be to be
     worth looking at rather than whatever is left over. */
  flex: 0 0 auto;
  height: 520px;
  overflow: hidden;
}

.primary-host .lattice,
.primary-host > .lattice {
  height: 100%;
}

.tabs-host {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  /* The basis, not `height`: this is a flex item in a column, and the tabs
     module injects a rule of its own for the height at runtime. */
  flex: 0 0 420px;
  flex-direction: column;
  overflow: hidden;
  padding: 10px 12px 12px;
}

.tabs-host [role='tabpanel'] {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.tabs-host [role='tabpanel'] > * {
  flex: 1;
  min-height: 0;
}

/* Waiting and failure */

.loading {
  margin: auto;
  max-width: 480px;
  text-align: center;
}

.loading h1 {
  color: var(--accent);
  font-size: 20px;
  margin: 0 0 8px;
}

.loading-message {
  color: var(--ink-soft);
  margin: 0 0 14px;
}

.loading-bar {
  background: var(--line);
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
}

.loading-fill {
  background: var(--accent);
  height: 100%;
  transition: width 0.2s ease;
  width: 0;
}

/* The credit line */

.foot {
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 12px;
  padding-top: 10px;
}

.foot p {
  margin: 0 0 2px;
}

.foot a {
  color: var(--accent);
}

/* Said when the saved copy is standing in for data that could not be fetched. */
.notice {
  background: #fdf3e3;
  border: 1px solid #f0d9a8;
  border-radius: 7px;
  color: #6b4d12;
  margin: 8px 0 0;
  padding: 6px 10px;
}


/* ------------------------------------------------------------------ */
/* One column on a phone                                               */
/* ------------------------------------------------------------------ */

/*
 * Below this width the page stops being a dashboard laid out across and
 * becomes a single column read down. Every multi-column strip folds to one
 * track, the charts get a height of their own instead of sharing a row's,
 * and nothing is allowed to set a width the screen has to scroll to reach.
 *
 * The KPI panel sizes its own tracks from `--lat-kpi-tile-min`, which
 * `columns: 4` sets as an inline style on the panel; `!important` is what
 * lets a stylesheet have the last word over that inline value, so the four
 * columns asked for on a desktop become one here rather than four tiles too
 * narrow to read.
 */
@media (max-width: 640px) {
  #app {
    padding: 12px 12px 10px;
  }

  .head h1 {
    font-size: 19px;
  }

  .kpi-strip,
  .chart-wrap {
    grid-template-columns: minmax(0, 1fr);
  }

  .chart-wrap {
    grid-template-rows: none;
  }

  .chart-box {
    height: 240px;
  }

  .primary-host {
    flex: 0 0 auto;
    height: 460px;
  }

  .tabs-host {
    flex: 0 0 420px;
  }

  .kpi-panel.lat-kpi {
    --lat-kpi-tile-min: 100% !important;
  }
}
