/*
 * The operator UI's one stylesheet, drawn on @neurovolt/ui's tokens.
 *
 * Every colour is a var() of a token from /ui/tokens.css, which holds the
 * light and the dark palette and switches between them on data-theme on
 * <html> (theme.js). Nothing here names a colour value or a typeface:
 * test/tokens-only.test.ts fails on a hex literal or a font-family that is not
 * a var(). The two typefaces are tokens too: every font-family reads
 * --font-sans or --font-mono from tokens.css, and fonts.css loads the files.
 *
 * The shared vocabulary is NeuroGRID's (.mono, .eyebrow, .card, .pill, .dot,
 * .btn, .btn-primary, .btn-ghost), so a rule here reads like the design
 * canvas in docs/design/. The class names app.js writes into its markup
 * (.panel, .badge, .primary, .dev-pill, .tag ...) are kept, because renaming
 * them would touch the rendering logic, and each is styled beside the NG
 * class it corresponds to rather than through a second set of values.
 *
 * Radii are 10px for a card, 8px for a control, 999px for a pill. Elevation
 * is a 1px hairline and never a shadow: --line between rows inside a card,
 * --line-strong for the structural edges (header, rail, card, drawer). The
 * light palette is the default ground; dark is the token sheet's override.
 *
 * Signal colours keep the meanings tokens.css gives them: --danger a fault,
 * --warn a protection operation, --ok healthy or cleared, --cyan a measured
 * value, --violet ground and earthing, and the four --phase-* tokens a
 * conductor on a trace. --deep is the brand blue for selection, links and
 * the primary action.
 *
 * Icons drawn by CSS are an SVG used as a mask over currentColor, so they
 * take the text colour of their element in both themes; a background-image
 * would carry a fixed stroke colour of its own.
 */

:root {
  /* A border a step darker than --line for structural edges, as NeuroGRID mixes it. */
  --line-strong: color-mix(in oklab, var(--ink) 18%, var(--panel));
  /* The ghost-button border the canvas draws: 20% ink over the panel. */
  --line-control: color-mix(in oklab, var(--ink) 20%, var(--panel));

  --icon-bolt: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M13 2 4 14h7l-1 8 9-12h-7z'/%3E%3C/svg%3E");
  --icon-shield: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z'/%3E%3C/svg%3E");
  --icon-file: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 2v6h6'/%3E%3C/svg%3E");
  --icon-sigma: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 4H6l6 8-6 8h12'/%3E%3C/svg%3E");
  --icon-chart: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 3v18h18'/%3E%3Cpath d='m7 14 4-4 3 3 5-6'/%3E%3C/svg%3E");
  --icon-alert: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 9v4M12 17h.01M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z'/%3E%3C/svg%3E");
  --icon-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  --icon-close: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M6 6l12 12M18 6 6 18'/%3E%3C/svg%3E");

  /* Native scrollbars and form controls follow the palette on screen. */
  color-scheme: light;
}
:root[data-theme="dark"] {
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  letter-spacing: -0.022em;
  font-weight: 600;
  line-height: 1.15;
}

a {
  color: var(--deep);
  text-decoration: none;
}
a:hover {
  color: var(--deep-ink);
}

button,
input {
  font-family: var(--font-sans);
  font-size: inherit;
  color: inherit;
}

a,
button,
[role="button"],
label {
  cursor: pointer;
}
button:disabled {
  cursor: not-allowed;
}

:focus-visible {
  outline: 2px solid var(--electric);
  outline-offset: 2px;
}

/* Inter's semibold is the canvas's bold, in prose and in pills alike. */
b,
strong {
  font-weight: 600;
}

pre,
code {
  font-family: var(--font-mono);
  font-variant-ligatures: none;
}

/* The one utility that must win over any component's own display, whatever its specificity. */
.hidden {
  /* biome-ignore lint/complexity/noImportantStyles: app.js hides and shows by toggling this class on elements whose own rules set display. */
  display: none !important;
}

/* NeuroGRID's shared vocabulary, as docs/design/_style.html draws it. */

.mono,
.dev-pill,
.ov-meta,
.rid {
  font-family: var(--font-mono);
  font-variant-ligatures: none;
}

.eyebrow,
.panel-head h3,
.sidebar h2,
.ov-label,
.cp-col-head,
.src-group-label,
.dbg-label,
.report-head h3,
.report h4,
.chat h4,
.sessions-table th {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.09em;
  line-height: 1.5;
  text-transform: uppercase;
  color: var(--muted);
}

.card,
.panel,
.report {
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel);
}

.pill,
.badge,
.tag,
.ied-chip,
.dev-pill,
.cp-note,
.src,
.role {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
  white-space: nowrap;
}
a.pill:hover,
button.pill:hover {
  border-color: var(--ink);
  background: var(--surface);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  flex: none;
}

.btn,
.btn-ghost,
.primary,
.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 32px;
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}
/* A plain .btn in app.js's markup is a secondary action, which the canvas draws as ghost. */
.btn,
.btn-ghost,
.ghost-btn {
  border-color: var(--line-control);
  background: var(--panel);
  color: var(--ink);
}
.btn:hover:not(:disabled),
.btn-ghost:hover:not(:disabled),
.ghost-btn:hover {
  background: var(--surface);
}
.btn-primary,
.primary,
#cp-apply {
  border-color: var(--deep);
  background: var(--deep);
  color: var(--on-deep);
}
.btn-primary:hover:not(:disabled),
.primary:hover:not(:disabled),
#cp-apply:hover:not(:disabled) {
  border-color: var(--deep-ink);
  background: var(--deep-ink);
}
.btn:disabled,
.primary:disabled {
  opacity: 0.55;
}
.btn + .btn {
  margin-left: 8px;
}

/* Header: 52px, mark and title on the left, status and switches on the right. */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 52px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line-strong);
  background: var(--panel);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
/* The NeuroVolt mark, filled as NeuroGRID's header fills it. */
.brand-mark {
  flex: none;
  width: 24px;
  height: 22px;
}
.brand-mark .mark-left {
  fill: var(--deep);
}
.brand-mark .mark-right,
.brand-mark .mark-bolt {
  fill: var(--electric);
}
.brand-mark .mark-split {
  fill: var(--panel);
}
.brand-mark .mark-bolt {
  stroke: var(--panel);
  stroke-width: 13;
  stroke-linejoin: round;
  paint-order: stroke;
}

.topbar-sep {
  width: 1px;
  height: 20px;
  flex: none;
  background: var(--line);
}

.topbar-event {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.topbar-event:has(.topbar-event-id:empty) {
  display: none;
}
.topbar-event .topbar-sep {
  margin-right: 3px;
}
.topbar-event-id {
  font-size: 11.5px;
  color: var(--muted);
}
.topbar-event-label {
  overflow: hidden;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  margin-left: auto;
  padding-left: 8px;
}

/* The LLM status pill and the report's provenance pill share one look. */
.badge.live {
  border-color: var(--ok-line);
  background: var(--ok-bg);
  color: var(--ok);
}
.badge.live::before,
.badge.mock::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 999px;
  background: currentColor;
}
.badge.mock {
  color: var(--muted);
}
.badge.approx {
  border-color: var(--warn-line);
  background: var(--warn-bg);
  color: var(--warn);
  white-space: normal;
}

/* Each switch is a <fieldset>, a native group; its default margin and padding go. */
.theme-toggle,
.lang-toggle {
  display: flex;
  min-width: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.theme-toggle button,
.lang-toggle button {
  display: flex;
  align-items: center;
  border: none;
  background: transparent;
  color: var(--muted);
}
.theme-toggle button {
  padding: 5px 9px;
}
.theme-toggle button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--deep);
}
.lang-toggle button {
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 600;
}
.lang-toggle button.active {
  background: var(--deep);
  color: var(--on-deep);
}
.theme-toggle button + button {
  border-left: 1px solid var(--line);
}

/* Shell: the 280px events rail beside the event page. */

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: calc(100vh - 52px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line-strong);
  background: var(--surface);
}
.sidebar > h2,
.rail-head {
  padding: 12px 14px 8px;
}
.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.rail-head h2 {
  padding: 0;
}
.rail-count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
}

.record-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  margin: 0;
  padding: 0 8px 10px;
  overflow-y: auto;
  list-style: none;
}
.record-list li {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}
.record-list li:hover {
  border-color: var(--line);
  background: var(--panel);
}
.record-list li.active {
  border-color: var(--deep-line);
  background: var(--panel);
}
.record-list .rid {
  font-size: 11.5px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.record-list li.active .rid {
  color: var(--deep);
}
.record-list .rlabel {
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--muted);
}
.record-list li.active .rlabel {
  color: var(--ink);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding-top: 1px;
}
.tag,
.ied-chip {
  padding: 1px 7px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.tag.real {
  border-color: var(--ok-line);
  background: var(--ok-bg);
  color: var(--ok);
}
.tag.synthetic {
  border-color: var(--warn-line);
  background: var(--warn-bg);
  color: var(--warn);
}

.hint {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  margin: 0;
  padding: 11px 14px;
  border-top: 1px solid var(--line);
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--muted);
}
.hint::before {
  content: "";
  width: 12px;
  height: 12px;
  margin-top: 2px;
  flex: none;
  background: currentColor;
  -webkit-mask: var(--icon-shield) center / contain no-repeat;
  mask: var(--icon-shield) center / contain no-repeat;
}

.content {
  min-width: 0;
  padding: 18px 22px;
  overflow-y: auto;
}
.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
}

/* Event page: head, then the cards in a 12px rhythm. */

.detail {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}
.detail-head > div {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.detail-head h1 {
  font-size: 22px;
}
.event-eyebrow .mono {
  text-transform: none;
  letter-spacing: 0;
}
.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}

#analyze-btn {
  min-height: 36px;
  padding: 8px 18px;
  font-size: 13px;
}
#analyze-btn:not(:disabled)::before {
  content: "";
  width: 14px;
  height: 14px;
  flex: none;
  background: currentColor;
  -webkit-mask: var(--icon-bolt) center / contain no-repeat;
  mask: var(--icon-bolt) center / contain no-repeat;
}

/* Collapsible cards: the head toggles the body. */

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 16px;
  cursor: pointer;
  user-select: none;
}
.panel-head h3 {
  display: flex;
  align-items: center;
  gap: 9px;
}
.panel-head .head-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
}
.panel-count,
.wave-note,
.ov-meta {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
}
.chev {
  display: inline-block;
  width: 12px;
  height: 12px;
  flex: none;
  font-size: 0;
  background: var(--muted);
  -webkit-mask: var(--icon-chevron) center / contain no-repeat;
  mask: var(--icon-chevron) center / contain no-repeat;
  transition: transform 0.15s;
}
.collapsible.collapsed .chev {
  transform: rotate(-90deg);
}
.panel-body {
  padding: 14px 16px 16px;
  border-top: 1px solid var(--line);
}
.collapsible.collapsed .panel-body {
  display: none;
}

/* A relay id as a neutral pill: the sequence, the waveform head, the overview. */
.dev-pill {
  padding: 1px 8px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--ink);
}

/* Station overview: summary, the one-line diagram, the active relay's detail. */

.ov-summary {
  max-width: 120ch;
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.65;
}
.ov-schematic {
  margin-bottom: 14px;
  padding: 10px 14px 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.ov-schematic-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 14px;
}
.ov-schematic-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}
.ov-schematic-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  color: var(--muted);
}
.ov-schematic-legend i {
  width: 12px;
  height: 8px;
  border: 1.5px solid;
  border-radius: 3px;
}
.ov-schematic-legend .lg-operated {
  border-color: var(--warn);
  background: var(--warn-bg);
}
.ov-schematic-legend .lg-faultzone {
  height: 12px;
  border-style: dashed;
  border-color: var(--danger);
  background: var(--danger-bg);
}
#plant-diagram {
  max-height: 520px;
  overflow: auto;
}

/* The SVG one-line diagram reads the same tokens through presentation styles. */
.oneline {
  display: block;
  height: auto;
  margin: 0 auto;
}
.oneline .pd-edge {
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
}
.oneline .pd-backdrop {
  fill: var(--surface);
  stroke: none;
}
.oneline .pd-glyph {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.oneline .pd-glyph-fill {
  fill: var(--ink);
  stroke: none;
}
.oneline .pd-bus {
  stroke: var(--ink);
  stroke-width: 5;
  stroke-linecap: round;
}
.oneline .pd-sym {
  fill: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  text-anchor: middle;
}
.oneline .pd-sym.sm {
  font-size: 11px;
}
.oneline .pd-label {
  fill: var(--ink);
  stroke: var(--surface);
  stroke-width: 4;
  paint-order: stroke;
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 500;
  text-anchor: middle;
}
.oneline .pd-connector {
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-dasharray: 2 2;
}
.oneline .pd-badge-box {
  fill: var(--panel);
  stroke: var(--line-strong);
  stroke-width: 1;
}
.oneline .pd-badge-text {
  fill: var(--ink);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-anchor: middle;
}
.oneline .pd-badge-g {
  cursor: pointer;
}
.oneline .pd-badge-g:hover .pd-badge-box {
  stroke: var(--deep);
}
.oneline .pd-badge-g.ghost {
  cursor: default;
  opacity: 0.4;
}
/* After analysis: a relay whose elements asserted reads as operated. */
.oneline .pd-badge-g.asserted .pd-badge-box {
  fill: var(--warn-bg);
  stroke: var(--warn);
  stroke-width: 1.5;
}
.oneline .pd-badge-g.asserted .pd-badge-text {
  fill: var(--warn);
}
.oneline .pd-badge-g.asserted .pd-connector {
  stroke: var(--warn);
}
.oneline .pd-badge-g.ghost:hover .pd-badge-box {
  stroke: var(--line-strong);
}
/* After analysis: the model's fault zone, outlined dashed and captioned. */
.oneline .pd-node-g.faultzone .pd-backdrop {
  fill: var(--danger-bg);
  stroke: var(--danger);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
}
.oneline .pd-node-g.faultzone .pd-glyph,
.oneline .pd-node-g.faultzone .pd-bus {
  stroke: var(--danger);
}
.oneline .pd-node-g.faultzone .pd-glyph-fill,
.oneline .pd-node-g.faultzone .pd-sym {
  fill: var(--danger);
}
.oneline .pd-node-g.faultzone .pd-label {
  fill: var(--danger);
  stroke: var(--surface);
  font-weight: 600;
}
.oneline .pd-faultcap {
  fill: var(--danger);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-anchor: middle;
}

.ov-device {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.ov-device-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.ov-device .ov-summary {
  max-width: 130ch;
  margin: 0;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
}
.ov-cols {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 22px;
}
@media (max-width: 900px) {
  .ov-cols {
    grid-template-columns: 1fr;
  }
}
.ov-label {
  margin-bottom: 4px;
}
.ov-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.ov-list li {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.ov-list li:last-child {
  border-bottom: none;
}
/* Measurement and protection ids are domain identifiers; equipment names are prose.
   :where() keeps the :has() test out of the specificity, so this does not outrank
   every later rule about a <b>. */
:where(.ov-list li:has(code, .ansi)) b {
  font-family: var(--font-mono);
}
.ov-list b {
  margin-right: 6px;
  font-weight: 600;
  color: var(--ink);
}
.ov-list code {
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
}
.ov-list li .ansi {
  display: inline-flex;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--muted);
}
.ov-list li span:not(.ansi) {
  display: block;
  margin-top: 1px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}
.ov-list .ov-more {
  font-style: italic;
  color: var(--muted);
}

/* Merged sequence of events: one grid row per transition, full card width. */

#soe-panel .panel-body {
  padding: 0;
}
.timeline {
  margin: 0;
  padding: 0;
  list-style: none;
}
.timeline li {
  display: grid;
  grid-template-columns: 14px 104px 112px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--line);
}
.timeline li:last-child {
  border-bottom: none;
}
.timeline li::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--muted);
}
.timeline li.status-change::before {
  background: var(--warn);
}
.timeline li.status-change.reset::before {
  background: var(--ok);
}
.timeline .dev-pill {
  justify-self: start;
}
/* The waveform head's relay id sits inside an eyebrow; it keeps its own case. */
.panel-head h3 .dev-pill {
  letter-spacing: 0;
  text-transform: none;
}
.timeline .t {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--deep);
}
.timeline .d {
  font-size: 12.5px;
  overflow-wrap: anywhere;
}
.timeline code {
  font-size: inherit;
  font-weight: 600;
}
.timeline li .ref {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--deep);
  overflow-wrap: anywhere;
}
.timeline li.clickable {
  cursor: pointer;
}
.timeline li.clickable:hover {
  background: var(--surface);
}
.timeline li.clickable:hover .d {
  color: var(--deep);
}
@media (max-width: 1100px) {
  .timeline li {
    grid-template-columns: 14px auto minmax(0, 1fr);
    row-gap: 3px;
  }
  .timeline .d,
  .timeline li .ref {
    grid-column: 2 / -1;
  }
}

/* Waveforms: channel picker, device tabs, the canvas, the legend. */

.cp-toggle {
  min-height: 26px;
  padding: 3px 11px;
  font-size: 12px;
}
.cp-toggle.open {
  border-color: var(--deep-line);
  background: var(--deep-bg);
  color: var(--deep);
}

.chan-picker {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--deep-line);
  border-radius: 8px;
  background: var(--surface);
}
.cp-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.cp-filter {
  flex: 0 1 280px;
  min-width: 140px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-size: 12px;
}
.cp-filter::placeholder,
.chat-form input::placeholder {
  color: var(--muted);
}
.cp-filter:focus,
.chat-form input:focus {
  border-color: var(--deep);
  outline: none;
}
.cp-note {
  padding: 2px 8px;
  border-color: var(--warn-line);
  background: var(--warn-bg);
  color: var(--warn);
}
.cp-error {
  font-size: 12px;
  color: var(--danger);
}
.cp-spacer {
  flex: 1;
}
.cp-top .btn {
  min-height: 28px;
  padding: 4px 12px;
}
.cp-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 900px) {
  .cp-cols {
    grid-template-columns: 1fr;
  }
}
.cp-col-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.cp-count {
  font-size: 10.5px;
  letter-spacing: 0;
  color: var(--muted);
}
/* Bounded and scrollable: a real record carries 96 channels and more. */
.cp-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  align-content: start;
  gap: 0 4px;
  max-height: 240px;
  padding: 4px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.cp-item {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
}
.cp-item:hover {
  background: var(--surface);
}
.cp-item input {
  flex: none;
  margin: 0;
  accent-color: var(--deep);
}
.cp-item .cp-id {
  min-width: 0;
  overflow: hidden;
  font-family: var(--font-mono);
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.cp-item .cp-sub {
  flex: none;
  font-size: 11px;
  color: var(--muted);
}
.cp-item.cp-off {
  opacity: 0.45;
  cursor: not-allowed;
}
.cp-item.cp-hidden {
  display: none;
}

.device-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  width: fit-content;
  max-width: 100%;
  margin: 0 0 12px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
}
.device-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}
.device-tab:hover {
  background: var(--panel);
}
.device-tab .mono {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink);
}
.device-tab .tab-name {
  max-width: 28ch;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.device-tab.active {
  border-color: var(--deep-line);
  background: var(--deep-bg);
  color: var(--ink);
}
.device-tab.active .mono {
  color: var(--deep);
}
.device-tab .tab-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 999px;
  background: var(--warn);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
#wave {
  cursor: crosshair;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 10px;
  font-size: 11.5px;
}
.legend > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.legend i {
  display: inline-block;
  width: 14px;
  height: 3px;
  flex: none;
  border-radius: 2px;
}
/* A digital channel's swatch is a hollow bar in its trace colour, as its lane is a step. */
.legend i.lg-step {
  height: 8px;
  border: 1.5px solid;
  background: transparent;
}
/* Long channel ids (Chinese substations) truncate; the full id is in the title. */
.legend .lg-name {
  max-width: 30ch;
  overflow: hidden;
  font-family: var(--font-mono);
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* The AI fault report and the follow-up chat, one card. */

.report-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
}
#report-badge {
  padding: 2px 8px;
  font-size: 10.5px;
}
.ghost-btn {
  min-height: 28px;
  margin-left: auto;
  padding: 4px 11px;
  font-size: 12px;
}
#report-body {
  padding: 16px 18px 18px;
}
.report .headline {
  max-width: 90ch;
  margin: 0 0 14px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.022em;
  line-height: 1.3;
}
.report .classify {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin: 0 0 6px;
  font-size: 12.5px;
}
.report .classify .pill {
  font-size: 11.5px;
  font-weight: 600;
}
.report .classify .pill.hit {
  border-color: var(--danger-line);
  background: var(--danger-bg);
  color: var(--danger);
}
.report .classify .pill.hit:not(.zone)::before {
  content: "";
  width: 12px;
  height: 12px;
  flex: none;
  background: currentColor;
  -webkit-mask: var(--icon-alert) center / contain no-repeat;
  mask: var(--icon-alert) center / contain no-repeat;
}
.report .classify .pill.ok {
  border-color: var(--ok-line);
  background: var(--ok-bg);
  color: var(--ok);
}
.report .classify .pill.zone {
  border-style: dashed;
  border-color: var(--line-strong);
  color: var(--ink);
}
.report .classify .pill.zone.hit {
  border-color: var(--danger);
  background: var(--danger-bg);
  color: var(--danger);
}
.cls b {
  margin-right: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}
.report h4 {
  margin: 18px 0 7px;
  font-weight: 600;
  color: var(--ink);
}
.report p,
.report ol {
  max-width: 118ch;
  margin: 0;
  font-size: 13.5px;
  line-height: 1.7;
}
.report ol {
  padding-left: 20px;
}
.report .conf {
  font-size: 12.5px;
  color: var(--muted);
  text-transform: capitalize;
}
.src-group-label {
  margin: 10px 0 6px;
}
.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.report .sources .src {
  cursor: pointer;
}
.report .sources .src:hover {
  border-color: var(--ink);
  background: var(--surface);
}
.src.doc {
  border-color: var(--deep-line);
  font-size: 11.5px;
  color: var(--deep);
}
.src.evidence {
  color: var(--ink);
}
.src b {
  font-weight: 600;
}
.src::before {
  content: "";
  width: 11px;
  height: 11px;
  flex: none;
  background: currentColor;
}
.src.doc::before {
  -webkit-mask: var(--icon-file) center / contain no-repeat;
  mask: var(--icon-file) center / contain no-repeat;
}
.src.evidence::before {
  -webkit-mask: var(--icon-chart) center / contain no-repeat;
  mask: var(--icon-chart) center / contain no-repeat;
}
/* A computed figure is a measured value in the palette's sense, so it takes --cyan. */
.src.figure {
  color: var(--ink);
}
.src.figure::before {
  color: var(--cyan);
  -webkit-mask: var(--icon-sigma) center / contain no-repeat;
  mask: var(--icon-sigma) center / contain no-repeat;
}
.src.figure .mono {
  color: var(--cyan);
}
/* The line under the headline when stated figures were removed for having no matching derivation. */
.figure-warning {
  margin: -6px 0 12px;
  padding: 6px 10px;
  border: 1px solid var(--warn-line);
  border-radius: 8px;
  background: var(--warn-bg);
  font-size: 12.5px;
  color: var(--warn);
}
.sources code {
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  color: var(--ink);
}
.sources .dim {
  font-size: 11px;
  color: var(--muted);
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid color-mix(in oklab, var(--on-deep) 35%, transparent);
  border-top-color: var(--on-deep);
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin 0.7s linear infinite;
}
.bubble .spinner {
  border-color: var(--line);
  border-top-color: var(--deep);
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.doc-md {
  line-height: 1.6;
}
.doc-md h1 {
  margin: 0 0 10px;
  font-size: 18px;
}
.doc-md h2 {
  margin: 18px 0 6px;
  font-size: 15px;
  color: var(--deep);
}
.doc-md h3 {
  margin: 14px 0 4px;
  font-size: 13px;
}
.doc-md code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface);
  font-size: 12px;
}
.doc-md ul,
.doc-md ol {
  padding-left: 20px;
}
.doc-md .kw {
  font-size: 12px;
  color: var(--muted);
}
.doc-md table {
  margin: 8px 0;
  border-collapse: collapse;
  font-size: 13px;
}
.doc-md th,
.doc-md td {
  padding: 5px 9px;
  border: 1px solid var(--line);
  text-align: left;
}
.doc-md th {
  background: var(--surface);
  font-weight: 600;
  color: var(--muted);
}
.doc-md hr {
  margin: 12px 0;
  border: none;
  border-top: 1px solid var(--line);
}
.doc-md blockquote {
  margin: 8px 0;
  padding-left: 10px;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

.chat {
  padding: 12px 18px 18px;
  border-top: 1px solid var(--line);
}
.chat h4 {
  margin: 0 0 9px;
  font-weight: 600;
  color: var(--ink);
}
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 340px;
  margin-bottom: 12px;
  overflow-y: auto;
}
.chat-log:empty {
  display: none;
}
.bubble {
  max-width: 82%;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.user {
  align-self: flex-end;
  border-color: var(--deep-line);
  border-bottom-right-radius: 3px;
  background: var(--deep-bg);
}
.bubble.assistant {
  align-self: flex-start;
  border-bottom-left-radius: 3px;
  background: var(--surface);
}
.bubble.pending {
  color: var(--muted);
}
/* The figure chips under an assistant bubble, aligned with it. */
.chat-figures {
  align-self: flex-start;
  max-width: 82%;
  margin-top: -4px;
}
.chat-figures .figure-warning {
  margin: 0 0 6px;
}
.bubble p {
  margin: 0 0 8px;
}
.bubble p:last-child,
.bubble ul:last-child,
.bubble ol:last-child {
  margin-bottom: 0;
}
.bubble ul,
.bubble ol {
  margin: 6px 0;
}
.bubble h1,
.bubble h2,
.bubble h3 {
  margin: 8px 0 4px;
}
.chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  font-size: 12.5px;
}
.chat-form .primary {
  min-height: 36px;
}

/* The drawer: evidence, documents, the debug view. The page fades behind it. */

.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: color-mix(in oklab, var(--bg) 60%, transparent);
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  width: min(740px, 92vw);
  height: 100vh;
  border-left: 1px solid var(--line-strong);
  background: var(--panel);
}
.drawer.hidden,
.drawer-overlay.hidden {
  display: none;
}
.drawer-head {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h3 {
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}
.drawer-close {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  font-size: 0;
  color: var(--muted);
}
.drawer-close::before {
  content: "";
  width: 13px;
  height: 13px;
  background: currentColor;
  -webkit-mask: var(--icon-close) center / contain no-repeat;
  mask: var(--icon-close) center / contain no-repeat;
}
.drawer-close:hover {
  background: var(--surface);
  color: var(--ink);
}
.drawer-body {
  padding: 16px 20px;
  overflow-y: auto;
}

/* The debug view: the request as handed to llm-kit, and the model's tool calls. */

.dbg-meta {
  display: flex;
  gap: 18px;
  margin-bottom: 8px;
  font-size: 12.5px;
  color: var(--muted);
}
.dbg-meta b {
  color: var(--ink);
}
.dbg-meta b.live {
  color: var(--ok);
}
.dbg-meta b.mock {
  color: var(--warn);
}
.dbg-sec {
  margin-top: 16px;
}
.dbg-label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.dbg-label .role {
  padding: 1px 7px;
  font-size: 10.5px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--deep);
}
.dbg-label .btn {
  min-height: 24px;
  padding: 2px 9px;
  font-family: var(--font-sans);
  font-size: 11.5px;
  letter-spacing: 0;
  text-transform: none;
}
.dbg-pre {
  max-height: 42vh;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.trace-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.trace-list .dim {
  font-size: 12.5px;
  color: var(--muted);
}
.trace-item {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.trace-line {
  font-size: 12.5px;
  color: var(--muted);
}
.trace-line b {
  font-family: var(--font-mono);
  color: var(--deep);
}
.trace-args {
  display: block;
  margin-top: 6px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.dbg-turn {
  margin-top: 12px;
}
.dbg-turn:first-child {
  margin-top: 0;
}
.dbg-turn-head {
  margin-bottom: 6px;
  font-size: 12.5px;
  color: var(--muted);
}
.dbg-turn-q {
  color: var(--ink);
}

/* The evidence drawer's body: the explanation, the decoded rows, the raw .dat lines. */

.evidence-explain {
  margin-bottom: 12px;
  padding: 10px 14px;
  border: 1px solid var(--deep-line);
  border-left: 3px solid var(--deep);
  border-radius: 8px;
  background: var(--deep-bg);
  font-size: 12.5px;
  line-height: 1.6;
}
.evidence-explain b {
  color: var(--ink);
}
.evidence-meta {
  margin-bottom: 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}
.evidence-meta b {
  color: var(--ink);
}
div:has(> .log-table) {
  border: 1px solid var(--line);
  border-radius: 8px;
}
.log-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-variant-ligatures: none;
}
.log-table th,
.log-table td {
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}
.log-table td {
  padding: 2px 5px;
  color: var(--ink);
}
/* Long channel-id headers wrap in a bounded column; the full id is in the title. */
.log-table th {
  position: sticky;
  top: 0;
  min-width: 48px;
  max-width: 130px;
  padding: 5px;
  background: var(--panel);
  font-weight: 600;
  line-height: 1.25;
  color: var(--muted);
  vertical-align: bottom;
  white-space: normal;
  overflow-wrap: anywhere;
}
.log-table td:first-child,
.log-table th:first-child {
  color: var(--muted);
}
/* The column the timeline event refers to. */
.log-table .evcol {
  background: var(--deep-bg);
}
.log-table th.evcol {
  color: var(--deep);
}
.log-table .status-on {
  font-weight: 600;
  color: var(--warn);
}
.log-table tr.hit td,
.log-table tr.hit td:first-child {
  border-top: 1px solid var(--deep-line);
  border-bottom: 1px solid var(--deep-line);
  background: var(--deep-bg);
  font-weight: 600;
  color: var(--deep);
}
.raw-log {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin-top: 14px;
}
.raw-log > * {
  flex: 1 1 100%;
}
.raw-log > .btn {
  flex: none;
  margin-left: 0;
}
.raw-log .cap,
.cols-note {
  font-size: 11px;
  color: var(--muted);
}
.raw-log .cap code {
  color: var(--ink);
}
.cols-note {
  margin-top: 6px;
}
.raw-log pre {
  margin: 0;
  padding: 9px 12px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 10.5px;
  line-height: 1.55;
  color: var(--muted);
}
.raw-log pre .hit {
  display: inline-block;
  min-width: calc(100% + 24px);
  margin: 0 -12px;
  padding: 0 12px;
  background: var(--deep-bg);
  font-weight: 600;
  color: var(--deep);
}
/* A binary record has no text .dat to show; this says where the table came from. */
.binary-note {
  margin-top: 14px;
  padding: 10px 14px;
  border: 1px solid var(--warn-line);
  border-left: 3px solid var(--warn);
  border-radius: 8px;
  background: var(--warn-bg);
  font-size: 12.5px;
  line-height: 1.5;
}

/* /sessions: full width, the rail hidden; a reopened session uses the normal shell. */

.sessions-mode .sidebar {
  display: none;
}
.sessions-mode .layout {
  grid-template-columns: minmax(0, 1fr);
}
.sessions-mode .content {
  padding: 22px 28px;
}
.sessions-view {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sessions-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 22px;
}
.sessions-title .rail-count {
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0;
}
.sessions-empty {
  padding: 24px 0;
  color: var(--muted);
}
.sessions-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel);
}
.sessions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.sessions-table th {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}
/* biome-ignore lint/style/noDescendingSpecificity: the earlier rule is .log-table's highlighted row; the two tables never share a cell, the rule only compares the trailing td. */
.sessions-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.sessions-table tbody tr:last-child td {
  border-bottom: none;
}
.sessions-table tbody tr {
  cursor: pointer;
}
.sessions-table tbody tr:hover td {
  background: var(--surface);
}
.sessions-table tbody tr:has(td.s-err:not(:empty)) td {
  background: var(--danger-bg);
}
.sessions-table td:nth-child(2) {
  font-weight: 500;
}
.sessions-table td:nth-child(3) {
  color: var(--muted);
}
.sessions-table .s-time {
  font-family: var(--font-mono);
  font-size: 11.5px;
  white-space: nowrap;
  color: var(--muted);
}
.sessions-table th.s-turns,
.sessions-table td.s-turns {
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.sessions-table td.s-turns {
  font-family: var(--font-mono);
}
.sessions-table .s-err {
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--danger);
}
.sessions-table .s-lang .pill {
  padding: 1px 7px;
  font-size: 10px;
}

.sessions-back {
  display: inline-block;
  margin-top: 16px;
  font-size: 13px;
  font-weight: 600;
}
.sessions-back:hover {
  text-decoration: underline;
}

/* The report slot of a reopened session with no report, and a session dead end. */
.session-note {
  margin: 0 0 12px;
  line-height: 1.6;
  color: var(--muted);
}
.session-error {
  margin: 8px 0;
  padding: 14px 16px;
  border: 1px solid var(--danger-line);
  border-radius: 8px;
  background: var(--danger-bg);
}
.session-error .se-title {
  font-weight: 600;
  color: var(--danger);
}
.session-error pre {
  margin: 10px 0 0;
  padding: 10px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
}
