/*
 * Colour is reserved for service status. Everything else is neutral, so any
 * colour on screen means something. History bars also differ in height, so
 * status never depends on telling red from green. The three status colours
 * pass a colour-blind separation check in both themes.
 */

:root {
  color-scheme: light;
  --ground: #f4f6f8;
  --surface: #ffffff;
  --hover: #eef1f5;
  --ink: #101922;
  --ink-2: #4d5b6a;
  --line: #e0e5eb;
  --focus: #2563eb;
  --shadow: 0 10px 28px rgb(16 25 34 / 0.16);

  --up: #12a182;
  --partial: #f0a500;
  --major: #b8322e;
  --none: #d5dce4;

  --up-ink: #0a6b55;
  --partial-ink: #7d5500;
  --major-ink: #9b2723;

  --up-wash: #e3f3ee;
  --partial-wash: #fdf0d3;
  --major-wash: #f8e3e2;
  --idle-wash: #e8ecf1;

  --show-moon: block;
  --show-sun: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ground: #0b1016;
    --surface: #121923;
    --hover: #1b2634;
    --ink: #e8eef5;
    --ink-2: #9eacbc;
    --line: #233142;
    --focus: #7aa7ff;
    --shadow: 0 10px 28px rgb(0 0 0 / 0.55);
    --up: #22b894;
    --partial: #f4b32b;
    --major: #d9473f;
    --none: #2a394b;
    --up-ink: #55d5b4;
    --partial-ink: #f7c35c;
    --major-ink: #ff938b;
    --up-wash: #0f2824;
    --partial-wash: #2b2212;
    --major-wash: #321b1d;
    --idle-wash: #161f2a;
    --show-moon: none;
    --show-sun: block;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #0b1016;
  --surface: #121923;
  --hover: #1b2634;
  --ink: #e8eef5;
  --ink-2: #9eacbc;
  --line: #233142;
  --focus: #7aa7ff;
  --shadow: 0 10px 28px rgb(0 0 0 / 0.55);
  --up: #22b894;
  --partial: #f4b32b;
  --major: #d9473f;
  --none: #2a394b;
  --up-ink: #55d5b4;
  --partial-ink: #f7c35c;
  --major-ink: #ff938b;
  --up-wash: #0f2824;
  --partial-wash: #2b2212;
  --major-wash: #321b1d;
  --idle-wash: #161f2a;
  --show-moon: none;
  --show-sun: block;
}

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

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main { flex: 1; }
a { color: inherit; }
.wrap { width: min(100% - 2rem, 62rem); margin-inline: auto; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- header ---------- */

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }

.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  min-height: 4rem;
  padding-block: 0.6rem;
}

.brand { margin: 0; display: flex; align-items: center; gap: 0.75rem; }

.brand-name {
  font-family: "Cormorant Garamond", "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  font-size: 1.25rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.brand-sub { padding-left: 0.75rem; border-left: 1px solid var(--line); color: var(--ink-2); }

.topbar-actions { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }

.freshness {
  margin: 0 0.35rem 0 0;
  color: var(--ink-2);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.icon-btn:hover { background: var(--hover); }

.icon-btn svg {
  width: 1.05rem;
  height: 1.05rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-moon { display: var(--show-moon); }
.icon-sun { display: var(--show-sun); }
.icon-btn.busy svg { animation: spin 0.9s linear infinite; }

/* ---------- verdict ---------- */

.verdict {
  --signal: var(--ink-2);
  display: flex;
  gap: clamp(0.9rem, 2.5vw, 1.4rem);
  margin-top: 1.5rem;
  padding: clamp(1.25rem, 4vw, 2.25rem);
  background: var(--idle-wash);
  border-radius: 12px;
}

.no-js .verdict { display: none; }
.verdict[data-state="up"] { --signal: var(--up); background: var(--up-wash); }
.verdict[data-state="partial"] { --signal: var(--partial); background: var(--partial-wash); }
.verdict[data-state="down"] { --signal: var(--major); background: var(--major-wash); }

.verdict-signal {
  position: relative;
  flex: none;
  width: 1.05rem;
  height: 1.05rem;
  margin-top: calc(clamp(1.6rem, 4.5vw, 2.5rem) * 0.575 - 0.525rem);
  background: var(--signal);
  border-radius: 50%;
}

/* A slow ping: the page is live and still watching. */
.verdict-signal::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid var(--signal);
  border-radius: inherit;
  animation: ping 2.6s cubic-bezier(0.2, 0.6, 0.4, 1) infinite;
}

.verdict-text { min-width: 0; }

.verdict h1 {
  margin: 0;
  font-size: clamp(1.6rem, 4.5vw, 2.5rem);
  font-weight: 650;
  line-height: 1.15;
  letter-spacing: -0.022em;
}

.verdict p { margin: 0.45rem 0 0; color: var(--ink-2); font-size: 1rem; overflow-wrap: anywhere; }
.verdict-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }

.notice {
  margin: 1rem 0 0;
  padding: 0.75rem 1rem;
  background: var(--partial-wash);
  border-left: 3px solid var(--partial);
  border-radius: 6px;
}

/* ---------- sections and controls ---------- */

#updates,
#report,
#report > section + section { margin-top: 2.25rem; }

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 0.75rem;
}

h2 { margin: 0; font-size: 1.1rem; font-weight: 650; letter-spacing: -0.008em; }
.day-list { margin-top: 1rem; }
.day-list summary { width: fit-content; margin-bottom: 0.6rem; font-weight: 600; cursor: pointer; }
.section-note { margin: -0.35rem 0 0.75rem; color: var(--ink-2); font-size: 0.85rem; }
.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  min-height: 2.25rem;
  padding: 0.35rem 0.85rem;
  font: inherit;
  font-size: 0.875rem;
  color: var(--ink);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.btn:hover { background: var(--hover); }

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.segmented button {
  padding: 0.25rem 0.75rem;
  font: inherit;
  font-size: 0.875rem;
  color: var(--ink-2);
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

.segmented button:hover { background: var(--hover); }
.segmented button[aria-pressed="true"] { color: var(--surface); background: var(--ink); }

/* ---------- history ledger: every row shares one date axis ---------- */

.ledger-grid {
  display: grid;
  grid-template-columns: minmax(0, 12.5rem) minmax(0, 1fr) 4.5rem;
  align-items: center;
  column-gap: 1.25rem;
  padding-inline: 1.25rem;
}

.ledger-head {
  padding-block: 0.65rem;
  color: var(--ink-2);
  font-size: 0.78rem;
}

.axis { display: flex; justify-content: space-between; }
.head-uptime { text-align: right; }

.row { padding-block: 0.8rem; border-top: 1px solid var(--line); }
.who { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }

.name {
  max-width: 100%;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.state {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--ink-2);
}

.state svg {
  width: 0.8rem;
  height: 0.8rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.state.up { color: var(--up-ink); }
.state.down { color: var(--major-ink); font-weight: 700; }

.strip {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 2.1rem;
  border-radius: 3px;
  cursor: crosshair;
  touch-action: pan-y;
}

.cell {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  background: var(--up);
  border-radius: 2px;
  transform-origin: bottom;
}

.cell.partial { height: 66%; background: var(--partial); }
.cell.major { height: 40%; background: var(--major); }
.cell.none { height: 14%; background: var(--none); }

/* Inspecting a day lifts that column across every service. */
.ledger.inspecting .cell { opacity: 0.35; }
.ledger.inspecting .cell.hot { opacity: 1; box-shadow: 0 0 0 1px var(--ink); }

.ledger.sweep .cell {
  animation: rise 0.4s ease-out backwards;
  animation-delay: calc(var(--i) * 7ms);
}

.pct { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
  margin: 0;
  padding: 0.75rem 1.25rem;
  list-style: none;
  color: var(--ink-2);
  font-size: 0.8rem;
  border-top: 1px solid var(--line);
}

.legend li { display: inline-flex; align-items: flex-end; gap: 0.45rem; }
.key { display: inline-block; width: 5px; height: 16px; background: var(--up); border-radius: 2px; }
.key.partial { height: 11px; background: var(--partial); }
.key.major { height: 7px; background: var(--major); }
.key.none { height: 4px; background: var(--none); }

/* ---------- tables ---------- */

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

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
th, td { padding: 0.6rem 1rem; text-align: left; white-space: nowrap; }
thead th { color: var(--ink-2); font-size: 0.78rem; font-weight: 600; }
tbody tr { border-top: 1px solid var(--line); }
tbody th { font-weight: 600; }
.num { text-align: right; }
.empty { padding: 1rem 1.25rem; color: var(--ink-2); }

/* ---------- outages and updates ---------- */

.outages,
.updates { margin: 0; padding: 0; list-style: none; }

.outages li {
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
}

.outages li + li,
.updates li + li { border-top: 1px solid var(--line); }

.outages .when { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.outages .what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.outages .long { font-weight: 600; font-variant-numeric: tabular-nums; }
.outages li.empty { display: block; }

.updates li { padding: 1rem 1.25rem; }
.updates h3 { margin: 0; font-size: 0.95rem; }
.updates p { margin: 0.35rem 0 0; white-space: pre-line; overflow-wrap: anywhere; }
.updates .meta { color: var(--ink-2); font-size: 0.8rem; }

/* ---------- tooltip ---------- */

.tooltip {
  position: fixed;
  z-index: 10;
  width: 17rem;
  max-width: calc(100vw - 1rem);
  padding: 0.7rem 0.85rem;
  font-size: 0.82rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.tooltip p { margin: 0; }
.tip-date, .tip-sub { color: var(--ink-2); overflow-wrap: anywhere; }
.tip-value { font-size: 1.25rem; line-height: 1.35; }
.tip-value span { color: var(--ink-2); font-size: 0.82rem; }
.tip-fleet { margin-top: 0.55rem; padding-top: 0.55rem; border-top: 1px solid var(--line); }
.tip-fleet ul { margin: 0.3rem 0 0; padding: 0; list-style: none; }
.tip-fleet li { display: grid; grid-template-columns: 0.6rem minmax(0, 1fr) auto; align-items: center; gap: 0.45rem; }
.tip-fleet li .tip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tip-fleet li strong { font-variant-numeric: tabular-nums; }
.tip-line { height: 3px; border-radius: 2px; background: var(--partial); }
.tip-line.major { background: var(--major); }
.tip-more { color: var(--ink-2); }

/* ---------- footer ---------- */

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-top: 2.5rem;
  padding-block: 1.25rem 1.75rem;
  color: var(--ink-2);
  font-size: 0.82rem;
  border-top: 1px solid var(--line);
}

.footer p { margin: 0; }

/* ---------- small screens: name and uptime on top, history below ---------- */

@media (max-width: 760px) {
  .ledger-grid {
    grid-template-columns: minmax(0, 1fr) auto;
    row-gap: 0.55rem;
    padding-inline: 1rem;
  }

  .row .who { grid-column: 1; grid-row: 1; }
  .row .pct { grid-column: 2; grid-row: 1; align-self: start; }
  .row .strip { grid-column: 1 / -1; grid-row: 2; }
  .who { flex-direction: row; align-items: center; gap: 0.6rem; }

  .ledger-head > :first-child,
  .ledger-head .head-uptime { display: none; }
  .ledger-head .axis { grid-column: 1 / -1; }

  .legend, .outages li { padding-inline: 1rem; }
  .outages .what { white-space: normal; overflow-wrap: anywhere; }
}

@media (max-width: 520px) {
  .strip[data-range="90"] { gap: 1px; }
  .strip[data-range="90"] .cell { border-radius: 1px; }
  .topbar-actions { width: 100%; }
  .freshness { margin-right: auto; }
  .freshness .next { display: none; }
}

/* ---------- motion and high contrast ---------- */

@keyframes ping {
  0% { opacity: 0.8; transform: scale(1); }
  70%, 100% { opacity: 0; transform: scale(2.4); }
}

@keyframes rise {
  from { opacity: 0; transform: scaleY(0.15); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { animation: none !important; }
}

@media (forced-colors: active) {
  .cell, .key, .tip-line, .verdict-signal { forced-color-adjust: none; }
}
