/* Tokens first. The palette is nerve's, so the two dashboards read as one family. Light text tokens are
   darkened from nerve's to pass WCAG AA on every surface they sit on. Components use only these tokens,
   never a raw colour, so a theme change needs no other edits. The dark values appear twice on purpose:
   once for the system preference and once for an explicit data-theme="dark". An explicit
   data-theme="light" always wins over the system preference. */
:root {
  color-scheme: light;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --bg: #fae4ca;
  --card: #fdf0e0;
  --ink: #4a2801;
  --ink-2: #6f4c2b;
  --rule: #e6c7a0;
  --edge: #94704a;
  --track: #f0d3b0;
  --on-accent: #fdf0e0;
  --grid: rgba(74, 40, 1, 0.12);
  --focus: #0a625c;
  --ok: #365a0a;
  --warn: #7a4a00;
  --alarm: #a32b1f;
  --alarm-soft: #f6dccd;
  /* Chart series. uPlot reads these by name, so the names stay. */
  --s1: #0f766e;
  --s2: #1d4ed8;
  --s3: #7c3aed;
  --s4: #b5179e;
  --s5: #c81e1e;
  --s6: #ea580c;
  --s7: #4d7c0f;
  --s8: #a16207;
  --s9: #475569;
  /* Type scale: five sizes. Weights are 400 and 500 only. */
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-base: 0.9375rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.625rem;
  /* Radius scale: controls, surfaces, and pills for badges. */
  --r-control: 8px;
  --r-surface: 12px;
  --r-pill: 999px;
  /* Touch targets grow on coarse pointers; see the media query below. */
  --hit: 36px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1f1409;
    --card: #2a1c0e;
    --ink: #f4e4cc;
    --ink-2: #b89c78;
    --rule: #43301b;
    --edge: #927450;
    --track: #3a2814;
    --on-accent: #1f1409;
    --grid: rgba(244, 228, 204, 0.1);
    --focus: #2dd4bf;
    --ok: #a3e635;
    --warn: #ebb13f;
    --alarm: #f07a6c;
    --alarm-soft: #3b1f18;
    --s1: #2dd4bf;
    --s2: #60a5fa;
    --s3: #a78bfa;
    --s4: #f0abfc;
    --s5: #f87171;
    --s6: #fb923c;
    --s7: #a3e635;
    --s8: #facc15;
    --s9: #cbd5e1;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1f1409;
  --card: #2a1c0e;
  --ink: #f4e4cc;
  --ink-2: #b89c78;
  --rule: #43301b;
  --edge: #927450;
  --track: #3a2814;
  --on-accent: #1f1409;
  --grid: rgba(244, 228, 204, 0.1);
  --focus: #2dd4bf;
  --ok: #a3e635;
  --warn: #ebb13f;
  --alarm: #f07a6c;
  --alarm-soft: #3b1f18;
  --s1: #2dd4bf;
  --s2: #60a5fa;
  --s3: #a78bfa;
  --s4: #f0abfc;
  --s5: #f87171;
  --s6: #fb923c;
  --s7: #a3e635;
  --s8: #facc15;
  --s9: #cbd5e1;
}

/* Base. The hidden attribute must win over any display rule a component sets. */
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--fs-base) / 1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--track); color: var(--ink); }
h1, h2, h3, p, dl, dd, dt, ul, table, figure { margin: 0; }
dd { margin: 0; }
ul { padding: 0; list-style: none; }
h1 { font-size: clamp(1.25rem, 1rem + 1vw, var(--fs-xl)); font-weight: 500; line-height: 1.25; letter-spacing: -0.01em; overflow-wrap: anywhere; }
h2 { font-size: var(--fs-lg); font-weight: 500; line-height: 1.3; overflow-wrap: anywhere; }
h3 { font-size: var(--fs-base); font-weight: 500; line-height: 1.4; overflow-wrap: anywhere; }
a { color: var(--focus); text-underline-offset: 3px; overflow-wrap: anywhere; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
#main:focus { outline: none; }

/* Buttons. Labels are 13 px and medium weight; the height keeps a target a finger can hit. */
button {
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--edge);
  border-radius: var(--r-control);
  min-height: var(--hit);
  padding: 0 14px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
button:hover:not(:disabled) { background: var(--track); }
button:disabled { color: var(--ink-2); border-color: var(--rule); cursor: default; }
button.primary { background: var(--focus); border-color: var(--focus); color: var(--on-accent); }
button.primary:hover:not(:disabled) { background: var(--focus); opacity: 0.9; }
button.primary:disabled { background: var(--track); border-color: var(--rule); color: var(--ink-2); }
button.danger { color: var(--alarm); }
.confirm button.danger { background: var(--alarm); border-color: var(--alarm); color: var(--on-accent); }
.confirm button.danger:hover:not(:disabled) { background: var(--alarm); opacity: 0.9; }
.confirm button.danger:disabled { background: var(--track); border-color: var(--rule); color: var(--ink-2); }

/* Fields. Inputs sit on the page surface, inset into the card, with an edge that passes 3:1. The
   16 px size stops iOS from zooming into the field when it takes focus. */
input {
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--edge);
  border-radius: var(--r-control);
  min-height: var(--hit);
  min-width: 0;
  max-width: 100%;
  padding: 0 10px;
  width: 100%;
}
input::placeholder { color: var(--ink-2); opacity: 1; }
input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
select {
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--edge);
  border-radius: var(--r-control);
  min-height: var(--hit);
  min-width: 0;
  max-width: 100%;
  padding: 0 10px;
  width: 100%;
}
select:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
.field { display: grid; gap: 6px; min-width: 0; }
.filters { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
.pager { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.field label { color: var(--ink-2); font-size: var(--fs-sm); }

/* Layout. The gutter is 16 px at phone width. Nothing may force a page-level scroll. */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--rule);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-lg);
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
}
.brand::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--focus);
}
.links { display: flex; flex-wrap: wrap; gap: 4px; }
.links a {
  display: inline-flex;
  align-items: center;
  min-height: var(--hit);
  padding: 0 10px;
  border-radius: var(--r-control);
  color: var(--ink-2);
  text-decoration: none;
}
.links a:hover { color: var(--ink); background: var(--track); }
/* The current page is marked with a flat bar, so its corners stay square. */
.links a { position: relative; }
.account { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; }
.account button {
  font: inherit; color: inherit; background: none; cursor: pointer;
  border: 1px solid currentColor; border-radius: 6px; padding: 2px 10px;
}
.account button:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.links a[aria-current="page"] { color: var(--ink); }
.links a[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 0;
  height: 2px;
  background: var(--focus);
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 16px 16px 56px; min-width: 0; }
.page { display: grid; gap: 24px; min-width: 0; }
.stack { display: grid; gap: 12px; min-width: 0; align-content: start; }
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  min-width: 0;
}
.title { display: grid; gap: 4px; min-width: 0; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.crumbs { font-size: var(--fs-sm); }
.crumbs a {
  display: inline-flex;
  align-items: center;
  min-height: var(--hit);
  color: var(--ink-2);
  text-decoration: none;
}
.crumbs a:hover { color: var(--ink); text-decoration: underline; }

.sub { color: var(--ink-2); font-size: var(--fs-sm); overflow-wrap: anywhere; }
.note { color: var(--ink-2); font-size: var(--fs-sm); }
.meta { display: grid; gap: 2px; min-width: 0; }
/* Empty states say what is missing and what to do, inside a dashed panel that reads as a placeholder. */
.empty {
  padding: 16px;
  border: 1px dashed var(--edge);
  border-radius: var(--r-surface);
  color: var(--ink-2);
  font-size: var(--fs-sm);
}
.status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 1.5em;
  margin: 0 0 4px;
  color: var(--ink-2);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}
.status:not(:empty)::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--focus);
}
.alert {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--r-control);
  background: var(--alarm-soft);
  color: var(--alarm);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

/* Cards. One surface, one hairline, one radius. */
.card {
  display: grid;
  gap: 12px;
  align-content: start;
  min-width: 0;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--r-surface);
}

/* Overview: one card per node, equal heights in a row, a minimum width of 260 px. */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 264px), 1fr));
  gap: 12px;
}
.grid > .card { padding: 16px; }
/* The name sits over its badges in every card, so the rows line up whatever the badge count. */
.card-top { display: grid; gap: 8px; align-content: start; justify-items: start; min-width: 0; }
.name { font-size: var(--fs-base); font-weight: 500; min-width: 0; }
/* Node names are links in ink, with an edge-coloured underline, so they read as names rather than alerts. */
.name a, .node-row > a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--edge); }
.name a:hover, .node-row > a:hover { text-decoration-color: var(--focus); text-decoration-thickness: 2px; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
/* Badges are text in a pill. The tone sets the text colour, so no dot or fill is needed, and three
   of them fit on one line in a 264 px card. */
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--rule);
  border-radius: var(--r-pill);
  color: var(--ink-2);
  font-size: var(--fs-sm);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); }
.badge.warn { color: var(--warn); }
.badge.alarm { color: var(--alarm); }
.badge.muted { color: var(--ink-2); }

/* Key numbers: two fixed columns, so a dash in one never moves the other. */
.figures {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
}
.figures dt { color: var(--ink-2); font-size: var(--fs-sm); }
.figures dd { font-size: var(--fs-xl); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* The sparkline keeps its height whether or not it has data, so the card does not change size. */
.spark { height: 44px; min-width: 0; overflow: hidden; }

/* Node page. */
.node-body { display: grid; gap: 24px; min-width: 0; }
.head-row { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 24px; min-width: 0; }
.head-info { display: grid; gap: 8px; min-width: 0; }
.confirm {
  display: grid;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: var(--r-surface);
}
.confirm p { font-size: var(--fs-sm); }
.chart-card { gap: 8px; }
.chart { width: 100%; min-width: 0; }

/* Segmented control: the theme toggle and the time range share it. */
.seg {
  display: inline-flex;
  max-width: 100%;
  padding: 3px;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: var(--r-surface);
}
.seg button {
  min-height: calc(var(--hit) - 6px);
  padding: 0 12px;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--ink-2);
}
.seg button:hover:not(:disabled) { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--track); color: var(--ink); }

/* Tabs: text with an underline, in a row that scrolls inside its own box on a phone. */
.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: thin;
  border-bottom: 1px solid var(--rule);
}
.tabs [role="tab"] {
  flex: none;
  min-height: var(--hit);
  padding: 0 12px;
  border: 0;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--ink-2);
}
.tabs [role="tab"]:hover:not(:disabled) { background: transparent; color: var(--ink); }
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--focus); }
.tabs [role="tab"]:focus-visible { outline-offset: -2px; }

/* Tables. Rows are separated by hairlines. A long table scrolls inside its box with its header held
   in place, and a wide one scrolls sideways inside the box, never the page. */
.table-wrap {
  max-width: 100%;
  max-height: 28rem;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--r-surface);
}
.table-wrap:empty { display: none; }
/* Scoped to the table box: uPlot's legend is also a table, and it keeps its own layout. */
.table-wrap table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table-wrap th, .table-wrap td {
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--rule);
  overflow-wrap: anywhere;
}
.table-wrap th { color: var(--ink-2); font-weight: 500; }
.table-wrap thead th { position: sticky; top: 0; z-index: 1; background: var(--card); white-space: nowrap; }
.table-wrap tbody tr:last-child > * { border-bottom: 0; }
.table-wrap tbody th { width: 40%; color: var(--ink-2); font-weight: 400; }
pre.raw {
  margin: 0;
  padding: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 400 var(--fs-sm) / 1.5 var(--mono);
}

/* Token form and the one-time token box. */
.token-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
  gap: 12px;
  align-items: end;
  min-width: 0;
}
.token-form button { justify-self: start; }
.token-box { padding-top: 12px; border-top: 1px solid var(--rule); }
.token-box strong { font-weight: 500; color: var(--warn); }
.token {
  display: block;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--edge);
  border-radius: var(--r-control);
  font: 400 var(--fs-sm) / 1.5 var(--mono);
  overflow-wrap: anywhere;
  user-select: all;
}

/* Node lists: one row per node, with the time at the far end on a wide screen. */
.site { padding-top: 16px; border-top: 1px solid var(--rule); }
.node-list { display: grid; }
.node-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  min-width: 0;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
}
.node-row:last-child { border-bottom: 0; }
.node-row > a, .node-row > span { font-weight: 500; min-width: 0; }
.node-row > time { margin-left: auto; }

/* uPlot draws on canvas. These rules size and colour the chrome around it. */
.uplot { color: var(--ink); font-family: var(--font); }
.u-legend { color: var(--ink-2); font-size: var(--fs-sm); text-align: left; margin: 0; padding: 4px 0 0; }
.u-legend table { width: auto; margin: 0; border-collapse: collapse; }
.u-legend th, .u-legend td { padding: 2px 10px 2px 0; border: 0; white-space: nowrap; overflow-wrap: normal; }
.u-legend th { color: var(--ink-2); font-weight: 400; }
.u-legend .u-value { color: var(--ink); }

/* Motion: state changes only. A page rises into place when it is switched to, the node details
   arrive with it, and a theme change cross-fades. Nothing animates on the periodic refresh. */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.reveal { animation: rise 0.2s ease-out both; }
html.theming, html.theming * { transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease !important; }

/* Touch: targets grow to 44 px on a finger-sized screen. */
@media (pointer: coarse) {
  :root { --hit: 44px; }
}

/* Phone. The header stacks, the theme toggle spans the width, and the gutter is 16 px. */
@media (max-width: 559px) {
  .seg { display: flex; width: 100%; }
  .seg button { flex: 1 1 0; padding: 0 8px; }
  .head-row .actions { width: 100%; }
  .head-row .actions button { flex: 1 1 0; }
  /* A section heading takes its own row, so its controls wrap beneath it at full width. */
  .page-head > h2 { flex: 1 0 100%; }
  .card { padding: 14px; }
}

@media (min-width: 720px) {
  .top { padding: 12px 24px; }
  .wrap { padding: 24px 24px 64px; }
}

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