:root {
  --bg: #050505;
  --surface: #0a0a0a;
  --surface-2: #0f0f0f;
  --hover: #131313;
  --border: #161616;
  --border-strong: #242424;
  --text: #ededed;
  --text-dim: #707070;
  --text-faint: #404040;
  --accent: #bdff00;
  --accent-dim: rgba(189, 255, 0, 0.10);
  --accent-strong: rgba(189, 255, 0, 0.22);
  --red: #ff4d4d;
  --red-dim: rgba(255, 77, 77, 0.10);
  --blue: #4da6ff;
  --amber: #ffb547;
  --amber-dim: rgba(255, 181, 71, 0.12);
  --amber-strong: rgba(255, 181, 71, 0.30);
  --accent-contrast: #000;
  --accent-hover: #d7ff57;
  --menu-bg: #000;
  --menu-shadow: 0 16px 34px rgba(0, 0, 0, 0.45);
  --inset-bg: #070707;
  --picker-filter: invert(1);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
}

html[data-theme="light"] {
  --bg: #e9e9e3;
  --surface: #f3f3ef;
  --surface-2: #e7e7e1;
  --hover: #deded7;
  --border: #d8d8d0;
  --border-strong: #c1c2b8;
  --text: #0c0c0c;
  --text-dim: #57574f;
  --text-faint: #97978d;
  --accent: #55a300;
  --accent-dim: rgba(85, 163, 0, 0.12);
  --accent-strong: rgba(85, 163, 0, 0.26);
  --red: #cc2b2b;
  --red-dim: rgba(204, 43, 43, 0.10);
  --blue: #1a68c9;
  --amber: #a86a08;
  --amber-dim: rgba(168, 106, 8, 0.13);
  --amber-strong: rgba(168, 106, 8, 0.32);
  --accent-contrast: #fff;
  --accent-hover: #468700;
  --menu-bg: #fbfbf8;
  --menu-shadow: 0 16px 34px rgba(20, 20, 15, 0.16);
  --inset-bg: #edede7;
  --picker-filter: none;
}

/* Chain logos are <img> SVGs with a baked-in white fill; invert to black on light. */
html[data-theme="light"] .chain-icon img { filter: invert(1); }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

body {
  min-width: 0;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

::selection { background: var(--accent); color: var(--accent-contrast); }

/* TOPBAR */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 24px;
  height: 52px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mark {
  position: relative;
  width: 18px;
  height: 18px;
  box-shadow: 0 0 12px var(--accent-strong);
}

.mark img {
  width: 100%;
  height: 100%;
  display: block;
}

.wordmark {
  font-family: var(--sans);
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 13px;
  color: var(--text);
}

.meta-tag {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 3px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-self: center;
}

.nav-links a {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  padding: 8px 14px;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: color 80ms ease;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.nav-links a:hover { color: var(--text); }
.nav-links a.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.chain-picker {
  position: relative;
}

.chain-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding: 0 10px 0 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: color 80ms, background 80ms, border-color 80ms;
}

.chain-trigger:hover,
.chain-picker.open .chain-trigger {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--hover);
}

.chain-icon {
  width: 15px;
  height: 15px;
  display: inline-grid;
  place-items: center;
  color: currentColor;
}

.chain-icon svg,
.chain-icon img {
  width: 15px;
  height: 15px;
  display: block;
  fill: currentColor;
}

.chain-name {
  display: inline-block;
  min-width: 5ch;
  text-align: left;
}

.chain-caret {
  width: 6px;
  height: 6px;
  margin-left: 2px;
  margin-top: -3px;
  border: solid currentColor;
  border-width: 0 1px 1px 0;
  color: var(--text-faint);
  transform: rotate(45deg);
  transform-origin: center;
  transition: transform 100ms ease, margin 100ms ease;
}

.chain-picker.open .chain-caret {
  margin-top: 3px;
  transform: rotate(-135deg);
}

.chain-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 210px;
  padding: 4px;
  border: 1px solid var(--border-strong);
  background: var(--menu-bg);
  box-shadow: var(--menu-shadow);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 100ms ease, transform 100ms ease, visibility 100ms ease;
  z-index: 60;
}

.chain-picker.open .chain-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.chain-option {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  text-align: left;
  outline: 1px solid transparent;
  outline-offset: -1px;
}

.chain-option:hover {
  color: var(--text);
  background: var(--hover);
}

.chain-option.active {
  color: var(--text);
  background: var(--surface-2);
  outline-color: var(--border-strong);
}

.chain-option-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.chain-option-name,
.chain-option-id {
  font-family: var(--mono);
  white-space: nowrap;
}

.chain-option-name {
  font-size: 11px;
  font-weight: 600;
}

.chain-option-id {
  font-size: 9.5px;
  color: currentColor;
  opacity: 0.62;
}

.status-block {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.top-refresh {
  color: var(--text-faint);
  border-left: 1px solid var(--border);
  margin-left: 4px;
  padding-left: 12px;
}

.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  margin-left: 4px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
  transition: color 80ms, background 80ms, border-color 80ms;
}

.theme-toggle:hover {
  color: var(--text);
  background: var(--hover);
  border-color: var(--border-strong);
}

.theme-toggle svg {
  width: 14px;
  height: 14px;
  display: block;
}

.theme-toggle .icon-moon { display: none; }
html[data-theme="light"] .theme-toggle .icon-moon { display: block; }
html[data-theme="light"] .theme-toggle .icon-sun { display: none; }

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
}
.dot.connected { background: var(--blue); }
.dot.sync { background: var(--amber); }
.dot.live  { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.dot.error { background: var(--red);    box-shadow: 0 0 8px var(--red); }

#status-text.error { color: var(--red); }

/* MAIN */
main {
  max-width: 1480px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* KPI ROW */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0;
  border: 1px solid var(--border);
  background: var(--surface);
}

.kpi {
  padding: 16px 18px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi:last-child { border-right: none; }

.kpi-label {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.kpi-value {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.kpi-sub {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-faint);
  letter-spacing: 0.01em;
}

.kpi-sub .pct { color: var(--accent); }

/* PANELS */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}

.panel-title {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  gap: 10px;
  min-width: min(100%, 220px);
}

.title-tag {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 3px 6px;
  border: 1px solid var(--accent-dim);
}

.panel-title h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--text);
}

.info-tip {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  background: var(--surface-2);
  appearance: none;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  cursor: help;
  outline: none;
}

.info-tip::before {
  content: "i";
  transform: translateY(-0.5px);
}

.info-tip:hover,
.info-tip:focus {
  color: var(--text);
  background: var(--hover);
  border-color: var(--border-strong);
}

.info-tip::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  top: calc(100% + 9px);
  transform: translateX(-50%);
  width: max-content;
  max-width: min(280px, calc(100vw - 32px));
  padding: 8px 10px;
  background: var(--menu-bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-family: var(--sans);
  font-size: 11px;
  line-height: 1.35;
  text-transform: none;
  letter-spacing: 0;
  white-space: normal;
  pointer-events: none;
  z-index: 50;
  /* Hidden tooltips must not occupy layout: an absolutely-positioned,
     visibility:hidden box still contributes horizontal overflow and, on
     narrow screens, pushes the whole page off-screen. display:none removes
     it from layout entirely. */
  display: none;
}

.info-tip:hover::after,
.info-tip:focus::after {
  display: block;
}

/* SEGMENTED CONTROL */
.seg {
  display: flex;
  flex: 0 0 auto;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.seg::-webkit-scrollbar {
  display: none;
}

.seg button {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 5px 12px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: color 80ms, background 80ms;
}

.seg button:hover { color: var(--text); }
.seg button.active {
  background: var(--accent);
  color: var(--accent-contrast);
}

.range-custom-btn,
.range-apply,
.range-clear {
  height: 27px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: color 80ms, background 80ms, border-color 80ms;
}

.range-custom-btn {
  padding: 0 10px;
}

.range-custom-btn:hover,
.range-custom-btn.active,
.range-apply:hover,
.range-clear:hover {
  color: var(--text);
  background: var(--hover);
  border-color: var(--border-strong);
}

.custom-range {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--inset-bg);
  min-width: 0;
}

.custom-range[hidden] {
  display: none;
}

.range-fields {
  display: flex;
  align-items: center;
  flex: 1 1 320px;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.range-fields[hidden] {
  display: none;
}

.range-mode,
.range-fields input {
  height: 27px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--mono);
  font-size: 10.5px;
  outline: none;
  line-height: 27px;
}

.range-mode {
  flex: 0 0 92px;
  width: 92px;
  padding: 0 28px 0 8px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-faint) 50%),
    linear-gradient(135deg, var(--text-faint) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) 11px,
    calc(100% - 9px) 11px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.range-fields input {
  flex: 1 1 150px;
  width: auto;
  min-width: 0;
  padding: 0 10px;
}

.range-fields input[type="datetime-local"] {
  padding-right: 12px;
}

.range-fields input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: var(--picker-filter);
  opacity: 0.82;
  margin-left: 8px;
  cursor: pointer;
}

.range-fields input[type="number"] {
  flex-basis: 130px;
  appearance: textfield;
  -moz-appearance: textfield;
}

.range-fields input[type="number"]::-webkit-outer-spin-button,
.range-fields input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.range-fields input:focus,
.range-mode:focus {
  border-color: var(--border-strong);
}

.range-summary {
  flex: 999 1 160px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 10px;
}

.range-apply,
.range-clear {
  padding: 0 9px;
}

.range-apply {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 700;
}

.range-apply:hover {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
  color: var(--accent-contrast);
}

/* CHARTS */
.chart-wrap {
  position: relative;
  height: 200px;
  padding: 16px 18px;
  overflow: hidden;
}

.chart-wrap.pannable {
  cursor: grab;
  user-select: none;
}

.chart-wrap.pannable.dragging {
  cursor: grabbing;
}

.chart-wrap.tall { height: 270px; }

/* A bare <canvas> reports its default 300px intrinsic width as min-content,
   which forces grid/flex parents wider than the viewport on small screens.
   Cap it so charts always shrink to their container. */
.chart-wrap canvas {
  display: block;
  max-width: 100%;
}

/* TABLE */
.table-wrap {
  overflow-x: auto;
  max-height: 480px;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

thead {
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

th, td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Recent-deployments column widths so the whole row is visible at a glance.
   Sums to ~100% so no horizontal scroll on desktop. */
.table-wrap.recent table { table-layout: fixed; }
.table-wrap.recent th:nth-child(1), .table-wrap.recent td:nth-child(1) { width: 11%; }
.table-wrap.recent th:nth-child(2), .table-wrap.recent td:nth-child(2) { width: 24%; }
.table-wrap.recent th:nth-child(3), .table-wrap.recent td:nth-child(3) { width: 24%; }
.table-wrap.recent th:nth-child(4), .table-wrap.recent td:nth-child(4) { width: 11%; }
.table-wrap.recent th:nth-child(5), .table-wrap.recent td:nth-child(5) { width: 10%; text-align: right; }
.table-wrap.recent th:nth-child(6), .table-wrap.recent td:nth-child(6) { width: 20%; }

/* PAGER */
.pager {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pager-range {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  margin-right: 4px;
}

.pager-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 28px;
  height: 26px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  font-family: var(--mono);
  transition: color 80ms, background 80ms, border-color 80ms;
}

.pager-btn:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: var(--accent-dim);
}

.pager-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

th {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  font-weight: 500;
  border-bottom: 1px solid var(--border-strong);
}

td.num, th.num { text-align: right; }

tbody tr { transition: background 60ms ease; }
tbody tr:hover { background: var(--hover); }
tbody tr:last-child td { border-bottom: none; }

.address {
  color: var(--blue);
  letter-spacing: 0.01em;
}
.address:hover { color: var(--accent); }

.dim-text { color: var(--text-faint); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 1px solid transparent;
}
.badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}
.badge.ok  { color: var(--accent); border-color: var(--accent-dim); background: var(--accent-dim); }
.badge.no  { color: var(--amber); border-color: var(--amber-strong); background: var(--amber-dim); }
.badge.dim { color: var(--text-dim); border-color: var(--border); background: var(--surface-2); }

/* QUERY */
.query-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.query-status {
  max-width: 360px;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 10.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.run-btn {
  height: 28px;
  padding: 0 14px;
  border: 1px solid var(--accent-dim);
  background: var(--accent);
  color: var(--accent-contrast);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.run-btn:disabled {
  opacity: 0.45;
  cursor: wait;
}

.export-btn {
  height: 28px;
  padding: 0 14px;
  border: 1px solid var(--accent-dim);
  background: transparent;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.export-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.query-body {
  display: grid;
  grid-template-columns: minmax(320px, 0.42fr) minmax(0, 1fr);
  min-height: 360px;
}

.query-editor {
  width: 100%;
  min-height: 360px;
  resize: vertical;
  border: none;
  border-right: 1px solid var(--border);
  background: var(--inset-bg);
  color: var(--text);
  padding: 16px 18px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  outline: none;
  tab-size: 2;
}

.query-editor:focus {
  box-shadow: inset 0 0 0 1px var(--accent-dim);
}

.table-wrap.query {
  max-height: 520px;
}

.table-wrap.query table {
  table-layout: auto;
  min-width: 720px;
}

.query-empty {
  color: var(--text-faint);
  text-align: center;
  padding: 42px 18px;
}

/* RESPONSIVE */
@media (max-width: 1100px) {
  .kpi-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi:nth-child(3n) { border-right: none; }
  .kpi { border-bottom: 1px solid var(--border); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .query-body { grid-template-columns: minmax(0, 1fr); }
  .query-editor {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .nav-links { display: none; }
  .topbar {
    height: auto;
    min-height: 52px;
    flex-wrap: wrap;
    padding-top: 10px;
    padding-bottom: 10px;
  }
  .brand { flex: 1 1 auto; }
  .chain-menu { left: 0; right: auto; }
}

@media (max-width: 760px) {
  .panel-head {
    align-items: flex-start;
    gap: 10px;
    justify-content: flex-start;
  }

  .panel-title {
    flex-basis: 100%;
    width: 100%;
  }

  /* Heads with a compact trailing cluster (pager, query actions) keep their
     title and controls on one row instead of stacking. */
  .pager-head,
  .query-panel .panel-head {
    flex-wrap: nowrap;
    align-items: center;
  }
  .pager-head .panel-title,
  .query-panel .panel-title {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
  }
  .pager-head .pager,
  .query-panel .query-actions {
    flex: 0 0 auto;
  }

  .panel-head .seg {
    flex: 0 0 auto;
  }

  .custom-range {
    align-items: stretch;
  }

  .range-mode {
    flex: 0 0 104px;
    width: 104px;
  }

  .range-fields {
    flex-basis: 100%;
    order: 2;
  }

  .range-summary {
    order: 3;
    flex-basis: 100%;
  }

  .range-apply,
  .range-clear {
    order: 4;
  }
}

@media (max-width: 600px) {
  main { padding: 16px; gap: 12px; }
  .topbar {
    flex-wrap: nowrap;
    align-items: center;
    padding: 10px 12px;
    gap: 8px;
  }
  .brand {
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
    gap: 8px;
  }
  .status-block {
    flex: 0 1 auto;
    min-width: 0;
    gap: 8px;
  }
  /* keep the status on one line; the colored dot already conveys state */
  #status-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #status-text .status-detail { display: none; }
  /* In the tight single-row heads the hover-only info tooltip has no room and
     its button overflows into the trailing controls — drop it on mobile. */
  .pager-head .info-tip,
  .query-panel .panel-title .info-tip {
    display: none;
  }
  .query-actions {
    width: auto;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 8px;
  }
  .query-status {
    max-width: none;
    flex: 0 1 auto;
    min-width: 0;
  }
  .top-refresh { display: none; }
  .chain-picker { position: static; }
  .chain-menu {
    left: 12px;
    right: auto;
    min-width: 0;
    max-width: calc(100% - 24px);
  }
  .chain-trigger { max-width: 132px; }
  .chain-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi:nth-child(odd)  { border-right: 1px solid var(--border); }
  .kpi:nth-child(even) { border-right: none; }
  .kpi-value { font-size: 18px; }
  .panel-title h2 { font-size: 12px; }
  .panel-head {
    padding: 12px;
  }
  /* seg + Custom share one tidy toolbar row under the title */
  .panel-head .seg {
    flex: 0 0 auto;
    width: auto;
  }
  .seg button {
    flex: 0 0 auto;
    padding: 6px 10px;
  }
  .range-custom-btn {
    flex: 0 0 auto;
    width: auto;
    padding: 0 12px;
  }
  /* custom range: clean full-width stack, two action buttons on one row */
  .custom-range {
    padding: 12px;
    gap: 8px;
  }
  .range-mode {
    flex: 0 0 auto;
    width: 100%;
  }
  .range-fields {
    flex: 1 1 100%;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  .range-fields input {
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
  }
  /* In the column layout flex-basis maps to the main (vertical) axis, so the
     row-layout `flex-basis: 130px` on number inputs would balloon their height.
     Higher specificity than `.range-fields input`, so reset it explicitly. */
  .range-fields input[type="number"] {
    flex-basis: auto;
    height: 27px;
  }
  .range-summary {
    flex: 1 1 100%;
    width: 100%;
    white-space: normal;
  }
  .range-apply,
  .range-clear {
    flex: 1 1 0;
    width: auto;
  }
  .chart-wrap {
    height: 200px;
    padding: 12px;
  }
  .chart-wrap.tall {
    height: 240px;
  }
  .table-wrap.recent table {
    min-width: 760px;
  }
  .query-body {
    min-height: 0;
  }
  .query-editor {
    min-height: 280px;
  }
}

/* Very small phones (<340px): the transient query status has no room next to
   the title and two action buttons — drop it so the row stays clean. */
@media (max-width: 340px) {
  .query-status { display: none; }
}

/* ============================================================
   DOCS
   ============================================================ */
.doc-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 80ms, background 80ms, border-color 80ms;
}
.doc-link:hover {
  color: var(--text);
  background: var(--hover);
  border-color: var(--border-strong);
}
.doc-link svg { width: 13px; height: 13px; display: block; }

.docs-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 64px;
  display: flex;
  gap: 40px;
  align-items: flex-start;
  /* Match the dashboard's monospace identity across the whole docs body. */
  font-family: var(--mono);
}

.docs-sidebar {
  position: sticky;
  top: 68px;
  align-self: flex-start;
  flex: 0 0 216px;
  min-width: 0;
}

/* A flex item with min-width:0 clamps to the row (a grid item did not here),
   so the wide code blocks and tables scroll inside the content column instead
   of pushing the page out at narrow-desktop widths. */
.docs-content { flex: 1 1 0; }

.docs-sidebar-title {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 0 10px 8px;
}

.docs-nav {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-left: 1px solid var(--border);
}

/* The green active indicator is a single element that slides between items. */
.docs-nav-slider {
  position: absolute;
  left: -1px;
  top: 0;
  width: 2px;
  height: 0;
  background: var(--accent);
  pointer-events: none;
  transition: transform 240ms cubic-bezier(0.4, 0, 0.2, 1),
              height 240ms cubic-bezier(0.4, 0, 0.2, 1);
}
.docs-nav-slider.no-anim { transition: none; }

.docs-nav-item {
  display: block;
  padding: 7px 12px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--text-dim);
  font-size: 12.5px;
  cursor: pointer;
  transition: color 120ms ease, background 80ms;
}
.docs-nav-item:hover { color: var(--text); background: var(--hover); }
.docs-nav-item.active { color: var(--accent); }

.docs-content { min-width: 0; }

.docs-page { min-width: 0; }
.docs-page[hidden] { display: none; }

.docs-page h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.docs-lede {
  margin: 0 0 28px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
}
.docs-page h2 {
  margin: 36px 0 12px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.docs-page h3 {
  margin: 24px 0 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}
.docs-page p,
.docs-page li {
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.65;
}
.docs-page p { margin: 0 0 12px; }
.docs-page ul,
.docs-page ol { margin: 0 0 14px; padding-left: 20px; }
.docs-page li { margin: 4px 0; }
.docs-page a.inline {
  color: var(--accent);
  border-bottom: 1px solid transparent;
}
.docs-page a.inline:hover { border-bottom-color: var(--accent); }
.docs-page strong { color: var(--text); font-weight: 600; }

.docs-page code {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 1px 5px;
  border: 1px solid var(--accent-dim);
  overflow-wrap: anywhere;
}

.docs-page pre {
  margin: 0 0 16px;
  padding: 14px 16px;
  background: var(--inset-bg);
  border: 1px solid var(--border);
  overflow-x: auto;
}
.docs-page pre code {
  color: var(--text);
  background: none;
  border: none;
  padding: 0;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre;
}

.docs-page table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 18px;
  table-layout: auto;
}
.docs-table-wrap { overflow-x: auto; margin: 0 0 18px; }
.docs-table-wrap table { margin: 0; min-width: 520px; }
.docs-page th,
.docs-page td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  white-space: normal;
}
.docs-page th {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border-strong);
}
.docs-page td { color: var(--text-dim); }
.docs-page td code { white-space: nowrap; }

.docs-callout {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-left: 2px solid var(--amber);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.6;
}
.docs-callout strong { color: var(--amber); }

.docs-pager {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 44px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.docs-pager a {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  min-width: 0;
  transition: border-color 80ms, background 80ms;
}
.docs-pager a:hover { border-color: var(--border-strong); background: var(--hover); }
.docs-pager a.next { text-align: right; align-items: flex-end; margin-left: auto; }
.docs-pager .pager-dir {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.docs-pager .pager-label { font-size: 13px; color: var(--text); }
.docs-pager a[hidden] { display: none; }

@media (max-width: 860px) {
  /* Plain block stacking on mobile: a single-column grid item does not reliably
     clamp to its track, so wide <pre>/tables blow the page out instead of
     scrolling. As blocks they take the container width and scroll internally. */
  .docs-shell {
    display: block;
    padding: 16px 16px 48px;
  }
  .docs-sidebar {
    position: static;
    top: auto;
    margin-bottom: 20px;
  }
  .docs-content { width: 100%; }
  .docs-sidebar-title { display: none; }
  .docs-nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    border-left: none;
    border-bottom: 1px solid var(--border);
    gap: 0;
  }
  .docs-nav::-webkit-scrollbar { display: none; }
  .docs-nav-slider { display: none; }
  .docs-nav-item {
    flex: 0 0 auto;
    margin-left: 0;
    margin-bottom: -1px;
    border-left: none;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
  }
  .docs-nav-item.active {
    border-left-color: transparent;
    border-bottom-color: var(--accent);
  }
  .docs-page h1 { font-size: 22px; }
}

/* Hide the Docs link's text label on small screens; keep the icon. */
@media (max-width: 600px) {
  .doc-link { padding: 0 8px; }
  .doc-link .doc-link-text { display: none; }
}
