:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --panel-2: #f0f0ec;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --border: #e0e0da;
  --accent: #2f5fd0;
  --accent-soft: #e5ecfb;
  --on-accent: #ffffff;
  --fatal: #8f1d4f;
  --fatal-bg: #f9e3ec;
  --error: #c4321f;
  --error-bg: #fbe6e2;
  --warn: #a86300;
  --warn-bg: #fbf0db;
  --info: #3b6e9e;
  --debug: #8a8a84;
  --ok: #2e7d4f;
  --mark: #ffe08a;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413;
    --panel: #1c1c1a;
    --panel-2: #242422;
    --text: #e8e8e3;
    --muted: #9a9a93;
    --border: #33332f;
    --accent: #7ea2f0;
    --accent-soft: #23304d;
    --on-accent: #0d1424;
    --fatal: #f07aa8;
    --fatal-bg: #3d1a2a;
    --error: #f08a78;
    --error-bg: #3d211b;
    --warn: #e7b24f;
    --warn-bg: #362a14;
    --info: #85b2df;
    --debug: #7c7c76;
    --ok: #6cc290;
    --mark: #6b5a1e;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #141413;
  --panel: #1c1c1a;
  --panel-2: #242422;
  --text: #e8e8e3;
  --muted: #9a9a93;
  --border: #33332f;
  --accent: #7ea2f0;
  --accent-soft: #23304d;
  --on-accent: #0d1424;
  --fatal: #f07aa8;
  --fatal-bg: #3d1a2a;
  --error: #f08a78;
  --error-bg: #3d211b;
  --warn: #e7b24f;
  --warn-bg: #362a14;
  --info: #85b2df;
  --debug: #7c7c76;
  --ok: #6cc290;
  --mark: #6b5a1e;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden],
[x-cloak] {
  /* biome-ignore lint/complexity/noImportantStyles: the hidden attribute must beat every component's display */
  display: none !important;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font: 14px / 1.45 var(--sans);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

input,
select {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

button.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
}

code,
.mono {
  font-family: var(--mono);
  font-size: 12.5px;
}

.muted {
  color: var(--muted);
}

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topnav .brand {
  font-weight: 600;
}

.topnav nav {
  display: flex;
  gap: 14px;
}

.topnav nav a.active {
  color: var(--text);
  font-weight: 600;
}

.topnav .spacer {
  flex: 1;
}

.explore {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  overflow: auto;
  padding: 10px;
}

.sidebar h4 {
  margin: 12px 4px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.field {
  border-radius: 6px;
}

.field > .field-head {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 3px 6px;
  border-radius: 6px;
}

.field > .field-head:hover {
  background: var(--panel-2);
}

.field .path {
  font-family: var(--mono);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.badge {
  font-size: 10.5px;
  border-radius: 4px;
  padding: 0 4px;
  background: var(--panel-2);
  color: var(--muted);
  white-space: nowrap;
}

.badge.conflict {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge.stale {
  background: none;
  border: 1px dashed var(--border);
}

.values {
  margin: 2px 0 6px 10px;
}

.value-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
  width: 100%;
  background: none;
  border: none;
  padding: 2px 6px;
  text-align: left;
  position: relative;
}

.value-row:hover {
  background: var(--accent-soft);
}

.value-row .bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  background: var(--accent);
  opacity: 0.5;
}

.main {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 0;
}

.querybar {
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: grid;
  gap: 8px;
}

.qrow {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.qbox {
  position: relative;
  flex: 1;
  min-width: 360px;
}

.qbox .hl,
.qbox input {
  font-family: var(--mono);
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 6px;
  white-space: pre;
  letter-spacing: 0;
}

.qbox input {
  width: 100%;
  position: relative;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  z-index: 2;
}

.qbox .hl {
  position: absolute;
  inset: 0;
  border: 1px solid transparent;
  background: var(--panel);
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
  color: var(--text);
}

.hl .t-field {
  color: var(--accent);
}

.hl .t-kw {
  color: var(--fatal);
  font-weight: 600;
}

.hl .t-str {
  color: var(--ok);
}

.hl .t-re {
  color: var(--warn);
}

.hl .t-op {
  color: var(--muted);
}

.hl .t-err {
  text-decoration: wavy underline var(--error);
  text-underline-offset: 3px;
  background: var(--error-bg);
}

.suggest {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  min-width: 280px;
  max-height: 320px;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.15);
  z-index: 20;
}

.suggest button {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  border: none;
  border-radius: 0;
  background: none;
  text-align: left;
  padding: 5px 10px;
  font-family: var(--mono);
  font-size: 12.5px;
}

.suggest button.on {
  background: var(--accent-soft);
}

.presets {
  display: flex;
  gap: 2px;
}

.presets button {
  padding: 4px 8px;
  font-size: 12.5px;
}

.presets button.on {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.range input {
  width: 190px;
  font-family: var(--mono);
  font-size: 12.5px;
}

.error-banner {
  background: var(--error-bg);
  color: var(--error);
  border-radius: 6px;
  padding: 6px 10px;
}

.warn-banner {
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12.5px;
}

.results {
  overflow: auto;
  min-height: 0;
  position: relative;
}

.hist {
  height: 92px;
  padding: 6px 14px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

table.logs {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.logs th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  z-index: 3;
}

table.logs td {
  padding: 3px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 420px;
}

table.logs td.msg {
  white-space: normal;
  max-width: none;
  word-break: break-word;
}

table.logs tr.row {
  cursor: pointer;
}

table.logs tr.row:hover td {
  background: var(--panel-2);
}

table.logs tr.row.cur td {
  background: var(--accent-soft);
}

table.logs tr.row.lv-fatal td:first-child {
  box-shadow: inset 4px 0 var(--fatal);
}

table.logs tr.row.lv-error td:first-child {
  box-shadow: inset 4px 0 var(--error);
}

table.logs tr.row.lv-warn td:first-child {
  box-shadow: inset 4px 0 var(--warn);
}

.lvl {
  display: inline-block;
  min-width: 42px;
  text-align: center;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 0 4px;
}

.lvl.lv-fatal {
  background: var(--fatal);
  color: var(--on-accent);
}

.lvl.lv-error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid var(--error);
}

.lvl.lv-warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.lvl.lv-info {
  color: var(--info);
}

.lvl.lv-debug {
  color: var(--debug);
}

tr.detail td {
  background: var(--panel);
  white-space: normal;
  padding: 10px 14px;
  max-width: none;
}

.detail-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.json {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  margin: 0;
}

.json .k {
  color: var(--accent);
}

.json .kv {
  background: none;
  border: none;
  padding: 0 2px;
  border-radius: 3px;
  font: inherit;
  text-align: left;
}

.json .kv:hover {
  background: var(--accent-soft);
}

.json .s {
  color: var(--ok);
}

.json .n {
  color: var(--warn);
}

.json .b,
.json .z {
  color: var(--fatal);
}

.footer {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  position: sticky;
  bottom: 0;
}

.page .footer {
  position: static;
}

.empty {
  padding: 40px;
  text-align: center;
  color: var(--muted);
}

.page {
  padding: 16px 20px;
  overflow: auto;
}

.page h1 {
  font-size: 20px;
  margin: 0 0 12px;
}

.cards {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  min-width: 140px;
}

.card .v {
  font-size: 22px;
  font-weight: 600;
}

table.grid {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}

table.grid th,
table.grid td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

table.grid th a {
  color: var(--text);
}

table.grid td.n,
table.grid th.n {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  margin-right: 6px;
}

.dot.silent {
  background: var(--error);
}

.chart {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 14px;
}

.sessions {
  font-size: 12px;
  color: var(--muted);
  margin: 4px 0 0;
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  box-sizing: border-box;
}

.auth {
  width: 100%;
  max-width: 380px;
  display: grid;
  gap: 20px;
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.auth-mark {
  width: 32px;
  height: 32px;
}

.auth-mark rect {
  fill: var(--accent);
}

.auth-mark path {
  stroke: var(--panel);
  stroke-width: 2.4;
  stroke-linecap: round;
  fill: none;
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  display: grid;
  gap: 16px;
  box-shadow:
    0 1px 2px rgb(0 0 0 / 4%),
    0 8px 24px rgb(0 0 0 / 6%);
}

.auth-card h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.auth-sub {
  margin: -10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.auth-card .field {
  display: grid;
  gap: 6px;
}

.auth-card label {
  font-size: 13px;
  font-weight: 500;
}

.auth-card input {
  height: 40px;
  padding: 0 12px;
  font-size: 14px;
  border-radius: 8px;
  box-sizing: border-box;
  width: 100%;
}

.auth-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-card input[aria-invalid="true"] {
  border-color: var(--error);
}

.auth-error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid color-mix(in srgb, var(--error) 30%, transparent);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}

.auth-submit {
  height: 40px;
  width: 100%;
  border-radius: 8px;
  font-weight: 600;
  margin-top: 4px;
}

.auth-submit:disabled {
  opacity: 0.7;
  cursor: progress;
}

.auth-foot {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
}

.builder {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px dashed var(--border);
  border-radius: 8px;
}

.builder .brow {
  display: flex;
  gap: 6px;
  align-items: center;
}

.builder .brow input {
  font-family: var(--mono);
  font-size: 12.5px;
}

.cols {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  align-items: center;
}

.chip {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1px 4px 1px 8px;
}

.chip button {
  border: none;
  background: none;
  padding: 0 4px;
  color: var(--muted);
}

.spin {
  opacity: 0;
  transition: opacity 0.2s;
  font-size: 12px;
  color: var(--muted);
}

.htmx-request .spin,
.htmx-request.spin {
  opacity: 1;
}

@media (max-width: 1100px) {
  .explore {
    grid-template-columns: 220px 1fr;
  }
}

@media (max-width: 860px) {
  .explore {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .qbox {
    min-width: 0;
  }
}

.tail-bar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}

.tail-bar ~ table.logs th {
  top: 37px;
}

.tail-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.tail-dot[data-state="live"] {
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent);
}

.tail-dot[data-state="connecting"] {
  background: var(--warn);
}

.tail-dot[data-state="down"],
.tail-dot[data-state="stopped"] {
  background: var(--error);
}

.tail-note {
  margin: 6px 14px;
}

.tail-empty {
  padding: 32px;
  text-align: center;
}

.tail-pill {
  position: sticky;
  bottom: 14px;
  display: block;
  margin: 0 auto;
  border-radius: 999px;
  background: var(--accent);
  color: var(--panel);
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgb(0 0 0 / 20%);
  z-index: 4;
}

table.logs tr.fresh {
  animation: tail-fresh 1.6s ease-out;
}

@keyframes tail-fresh {
  from {
    background: var(--accent-soft);
  }
}

@media (prefers-reduced-motion: reduce) {
  table.logs tr.fresh {
    animation: none;
  }
}

[data-tail-toggle].on {
  background: var(--ok);
  border-color: var(--ok);
  color: var(--panel);
}

:root {
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s5: #e87ba4;
  --s6: #008300;
  --s-other: #8a8a84;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --s5: #d55181;
    --s6: #008300;
    --s-other: #7c7c76;
  }
}

:root[data-theme="dark"] {
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --s6: #008300;
  --s-other: #7c7c76;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}

.kpi .v {
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.kpi .d {
  font-size: 12px;
  color: var(--muted);
}

.kpi .d b.up {
  color: var(--error);
}

.kpi .d b.down {
  color: var(--ok);
}

.kpi.good-up .d b.up {
  color: var(--ok);
}

.kpi.good-up .d b.down {
  color: var(--error);
}

.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

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

.panel h2 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 8px;
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.panel h2 .muted {
  font-weight: 400;
  font-size: 12px;
}

.chart {
  height: 200px;
}

.chart .u-legend {
  font-size: 12px;
}

.bar-cell {
  position: relative;
  min-width: 90px;
}

.bar-cell i {
  position: absolute;
  inset: 3px auto 3px 0;
  background: var(--accent-soft);
  border-radius: 0 3px 3px 0;
}

.bar-cell span {
  position: relative;
}

svg.spark {
  display: block;
}

svg.spark path {
  fill: none;
  stroke: var(--error);
  stroke-width: 1.5;
}

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

.badge.new {
  background: var(--error-bg);
  color: var(--error);
}

.better {
  color: var(--ok);
}

.worse {
  color: var(--error);
}

.tpl {
  font-family: var(--mono);
  font-size: 12.5px;
  word-break: break-word;
}

a.btn {
  display: inline-block;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: inherit;
  text-decoration: none;
}

a.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.presets a.btn {
  padding: 4px 8px;
  font-size: 12.5px;
}

.presets a.btn.on {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.scroll-x {
  overflow-x: auto;
  max-width: 100%;
}

.problem-cell {
  max-width: 520px;
}

.subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

nav.subnav a {
  padding: 6px 10px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

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

.notice {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 12px;
}

.form-row {
  flex-wrap: wrap;
  margin-bottom: 6px;
}

button.danger {
  color: var(--error);
  border-color: var(--error);
}

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

.alert-form {
  display: grid;
  gap: 10px;
  max-width: 760px;
}

.alert-form label {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.alert-form fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
