:root {
  /* surfaces — layered near-black */
  --bg: oklch(16% 0.015 265);
  --surface-0: oklch(19% 0.018 265);
  --surface-1: oklch(22% 0.02 265);
  --surface-2: oklch(26% 0.024 265);
  --line: oklch(30% 0.02 265);
  --line-strong: oklch(38% 0.03 265);

  /* text */
  --text: oklch(96% 0.01 265);
  --text-dim: oklch(74% 0.02 265);
  --text-faint: oklch(58% 0.02 265);

  /* accent + semantics */
  --accent: oklch(78% 0.14 205);
  --accent-ink: oklch(22% 0.06 240);
  --received: oklch(80% 0.13 85);
  --processed: oklch(78% 0.16 150);
  --failed: oklch(72% 0.16 45);
  --dead: oklch(64% 0.2 20);

  --radius-s: 8px;
  --radius: 14px;
  --radius-l: 20px;

  --text-hero: clamp(2rem, 1.2rem + 2.4vw, 3.2rem);
  --shadow: 0 1px 0 oklch(100% 0 0 / 0.04) inset, 0 18px 40px -24px oklch(0% 0 0 / 0.7);

  --dur: 220ms;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  --font-sans: 'Space Grotesk', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(120% 90% at 85% -10%, oklch(24% 0.05 250 / 0.7), transparent 60%),
    radial-gradient(90% 70% at -5% 0%, oklch(22% 0.05 200 / 0.5), transparent 55%), var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.01em;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

main {
  position: relative;
  z-index: 1;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 clamp(1rem, 0.5rem + 2vw, 2.5rem) 5rem;
}

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem clamp(1rem, 0.5rem + 2vw, 2.5rem);
  max-width: 1240px;
  margin: 0 auto;
  backdrop-filter: blur(12px);
  background: linear-gradient(oklch(16% 0.015 265 / 0.9), oklch(16% 0.015 265 / 0.55));
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: conic-gradient(from 200deg, var(--accent), oklch(70% 0.18 150), oklch(72% 0.16 45), var(--accent));
  box-shadow: 0 0 0 1px var(--line-strong), 0 6px 18px -6px var(--accent);
  position: relative;
}
.brand-mark::after {
  content: '';
  position: absolute;
  inset: 9px;
  border-radius: 4px;
  background: var(--bg);
}

.brand-text h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.brand-text p {
  margin: 0;
  font-size: 0.74rem;
  color: var(--text-faint);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.health {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-0);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: var(--text-dim);
}
.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
}
.health[data-state='ok'] .health-dot {
  background: var(--processed);
  box-shadow: 0 0 0 3px oklch(78% 0.16 150 / 0.18);
}
.health[data-state='down'] .health-dot {
  background: var(--dead);
  box-shadow: 0 0 0 3px oklch(64% 0.2 20 / 0.2);
}
@media (prefers-reduced-motion: no-preference) {
  .health[data-state='ok'] .health-dot {
    animation: pulse 2.4s var(--ease) infinite;
  }
}
@keyframes pulse {
  50% {
    box-shadow: 0 0 0 6px oklch(78% 0.16 150 / 0);
  }
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--text-dim);
  user-select: none;
}
.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.switch-track {
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  position: relative;
  transition: background var(--dur) var(--ease);
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.switch input:checked + .switch-track {
  background: oklch(78% 0.14 205 / 0.25);
  border-color: var(--accent);
}
.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(14px);
  background: var(--accent);
}
.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  border: 1px solid var(--line-strong);
  background: var(--surface-1);
  padding: 0.45rem 0.8rem;
  border-radius: var(--radius-s);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}
.btn:hover {
  background: var(--surface-2);
  border-color: var(--accent);
}
.btn:active {
  transform: translateY(1px);
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn-ghost {
  background: transparent;
}
.btn-icon {
  font-size: 0.95rem;
  color: var(--accent);
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 600;
}
.btn-primary:hover {
  background: oklch(84% 0.14 205);
}
.btn-icononly {
  padding: 0.3rem 0.55rem;
  font-size: 0.9rem;
}

/* ---------- stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.85rem;
  padding: 1.6rem 0 0.6rem;
}
.tile {
  grid-column: span 1;
  background: var(--surface-0);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.05rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.tile-accent {
  grid-column: span 1;
  border-color: var(--line-strong);
  background: linear-gradient(160deg, oklch(24% 0.05 240), var(--surface-0));
}
.tile-alert {
  border-color: oklch(45% 0.12 20);
}
.tile-soft {
  background: var(--surface-1);
}
.tile-label {
  font-size: 0.72rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.tile-value {
  font-family: var(--font-mono);
  font-size: clamp(1.6rem, 1rem + 1.4vw, 2.3rem);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.tile-foot {
  font-size: 0.72rem;
  color: var(--text-faint);
}

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  gap: 0.3rem;
  margin: 2rem 0 1rem;
  border-bottom: 1px solid var(--line);
}
.tab {
  appearance: none;
  background: none;
  border: 0;
  color: var(--text-faint);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  position: relative;
  transition: color var(--dur) var(--ease);
}
.tab::after {
  content: '';
  position: absolute;
  left: 0.9rem;
  right: 0.9rem;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--dur) var(--ease);
}
.tab:hover {
  color: var(--text-dim);
}
.tab.is-active {
  color: var(--text);
}
.tab.is-active::after {
  transform: scaleX(1);
}
.tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- panel + filters ---------- */
.panel-head {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-0);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  padding: 0.32rem 0.65rem;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
    color var(--dur) var(--ease);
}
.chip:hover {
  border-color: var(--line-strong);
  color: var(--text);
}
.chip.is-active {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--text);
}
.chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- table ---------- */
.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-0);
}
.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.grid thead th {
  text-align: left;
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  padding: 0.7rem 1rem;
  background: var(--surface-1);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.grid th.num,
.grid td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.grid tbody tr {
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.grid tbody tr:hover {
  background: var(--surface-1);
}
.grid tbody tr:not(:last-child) td {
  border-bottom: 1px solid var(--line);
}
.grid td {
  padding: 0.7rem 1rem;
  color: var(--text-dim);
  vertical-align: middle;
}
.grid td.mono,
.mono {
  font-family: var(--font-mono);
  color: var(--text);
}
.err-col {
  max-width: 260px;
}
.grid td.err {
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--failed);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}
.ticket-key {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text);
}
.ticket-key::before {
  content: '#';
  color: var(--text-faint);
}
.title-cell {
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.muted {
  color: var(--text-faint);
}

.empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.85rem;
}

/* ---------- badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
}
.s-received {
  background: var(--received);
}
.s-processed {
  background: var(--processed);
}
.s-failed {
  background: var(--failed);
}
.s-dead {
  background: var(--dead);
}
.badge-received {
  color: var(--received);
  border-color: oklch(80% 0.13 85 / 0.35);
  background: oklch(80% 0.13 85 / 0.1);
}
.badge-processed {
  color: var(--processed);
  border-color: oklch(78% 0.16 150 / 0.35);
  background: oklch(78% 0.16 150 / 0.1);
}
.badge-failed {
  color: var(--failed);
  border-color: oklch(72% 0.16 45 / 0.35);
  background: oklch(72% 0.16 45 / 0.1);
}
.badge-dead {
  color: var(--dead);
  border-color: oklch(64% 0.2 20 / 0.4);
  background: oklch(64% 0.2 20 / 0.12);
}
.badge-neutral {
  color: var(--text-dim);
  border-color: var(--line-strong);
  background: var(--surface-1);
}

.prio {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.prio[data-p='3'],
.prio[data-p='4'] {
  color: var(--failed);
  font-weight: 600;
}

/* ---------- pager ---------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.8rem;
  padding: 0.9rem 0.2rem 0;
  font-size: 0.8rem;
  color: var(--text-faint);
  font-family: var(--font-mono);
}
.pager-info {
  margin-right: auto;
}

/* ---------- drawer ---------- */
.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: oklch(10% 0.02 265 / 0.55);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}
.drawer-scrim.is-open {
  opacity: 1;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  height: 100dvh;
  width: min(560px, 94vw);
  background: var(--surface-0);
  border-left: 1px solid var(--line-strong);
  box-shadow: -30px 0 60px -30px oklch(0% 0 0 / 0.8);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--dur) var(--ease);
  will-change: transform;
}
.drawer.is-open {
  transform: translateX(0);
}
.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.2rem 1.3rem;
  border-bottom: 1px solid var(--line);
}
.drawer-kicker {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}
.drawer-head h2 {
  margin: 0.2rem 0 0;
  font-size: 1.15rem;
  font-weight: 600;
  font-family: var(--font-mono);
  word-break: break-all;
}
.drawer-body {
  padding: 1.2rem 1.3rem 3rem;
  overflow-y: auto;
}

.field {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 0.6rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.84rem;
}
.field dt {
  color: var(--text-faint);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.field dd {
  margin: 0;
  color: var(--text);
  font-family: var(--font-mono);
  word-break: break-word;
}

.section-label {
  margin: 1.5rem 0 0.7rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

pre.json {
  margin: 0;
  padding: 0.9rem 1rem;
  background: oklch(13% 0.015 265);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--text-dim);
  overflow-x: auto;
  white-space: pre;
}
.jk {
  color: var(--accent);
}
.js {
  color: var(--processed);
}
.jn {
  color: var(--received);
}
.jb {
  color: var(--failed);
}

.comment {
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.6rem;
  background: var(--surface-1);
}
.comment-meta {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-faint);
  margin-bottom: 0.35rem;
}
.comment-body {
  font-size: 0.86rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.drawer-actions {
  margin-top: 1.4rem;
  display: flex;
  gap: 0.6rem;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 1.4rem;
  left: 50%;
  transform: translate(-50%, 1rem);
  z-index: 60;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  font-size: 0.84rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.toast.is-show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast[data-kind='ok'] {
  border-color: oklch(78% 0.16 150 / 0.5);
}
.toast[data-kind='err'] {
  border-color: oklch(64% 0.2 20 / 0.5);
}

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .stats {
    grid-template-columns: repeat(3, 1fr);
  }
}
@media (max-width: 720px) {
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .err-col {
    display: none;
  }
  .grid td.err {
    display: none;
  }
  .topbar .switch-text {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
