/* delta-agent console.
 *
 * An operator console is scanned, not read: the job of this stylesheet is
 * to make state legible at a glance (a 5xx, a dead delivery, a ring that is
 * dropping) without the reader parsing numbers. Dense rows, tabular digits,
 * one accent colour, and semantic colour reserved for severity.
 */

:root {
  color-scheme: light dark;

  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c2129;
  --line: #2a313c;
  --text: #e6edf3;
  --dim: #8b949e;
  --accent: #58a6ff;

  --ok: #3fb950;
  --info: #58a6ff;
  --warn: #d29922;
  --bad: #f85149;

  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo,
    Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* ── header ─────────────────────────────────────────────────────────── */

header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}

.brand .muted {
  color: var(--dim);
  font-weight: 400;
}

/* Connection state as a shape, not a sentence: green and steady means the
 * last poll succeeded. */
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--dim);
  transition: background 0.2s;
}

.dot.live {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgb(63 185 80 / 0.18);
}

.target {
  display: flex;
  gap: 8px;
  flex: 1 1 380px;
}

.target input[type="url"] {
  flex: 2 1 220px;
}

.target input[type="password"] {
  flex: 1 1 120px;
}

nav {
  display: flex;
  gap: 4px;
}

/* ── controls ───────────────────────────────────────────────────────── */

input,
select,
button {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  min-width: 0;
}

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

button {
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button.ghost {
  background: transparent;
}

.tab {
  background: transparent;
  border-color: transparent;
  color: var(--dim);
  padding: 6px 12px;
}

.tab.active {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--line);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 12px 20px;
}

.toolbar input[type="search"] {
  flex: 1 1 280px;
}

.count {
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}

/* ── banners ────────────────────────────────────────────────────────── */

.banner {
  margin: 0;
  padding: 10px 20px;
  background: rgb(248 81 73 / 0.12);
  border-bottom: 1px solid rgb(248 81 73 / 0.3);
  color: #ffb4ae;
}

.banner.hint {
  background: var(--surface-2);
  border-bottom-color: var(--line);
  color: var(--dim);
}

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

/* ── metric cards ───────────────────────────────────────────────────── */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  padding: 16px 20px;
}

.cards article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
}

.cards h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--dim);
}

.stat {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 5px 0;
  border-top: 1px solid var(--line);
}

.stat:first-of-type {
  border-top: none;
}

.stat .label {
  color: var(--dim);
  white-space: nowrap;
}

.stat .value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  overflow-wrap: anywhere;
}

/* ── tables ─────────────────────────────────────────────────────────── */

/* The page itself must never scroll sideways; wide tables scroll inside. */
.grid {
  display: block;
  overflow-x: auto;
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
  font-size: 13px;
}

.grid thead th {
  position: sticky;
  top: 0;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 8px 12px;
}

.grid td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}

.grid tbody tr:hover {
  background: var(--surface);
}

.mono {
  font-family: var(--mono);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

.route {
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clip {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Status colour is semantic and separate from the accent. */
.ok {
  color: var(--ok);
}
.info {
  color: var(--info);
}
.warn {
  color: var(--warn);
}
.bad {
  color: var(--bad);
  font-weight: 600;
}
.none {
  color: var(--dim);
}

.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 11px;
  letter-spacing: 0.04em;
}

.pill.ingress {
  color: var(--info);
  border-color: rgb(88 166 255 / 0.4);
}

.pill.egress {
  color: #bc8cff;
  border-color: rgb(188 140 255 / 0.4);
}

.pill.level-warn {
  color: var(--warn);
}
.pill.level-error {
  color: var(--bad);
}

.pill.status-Delivered {
  color: var(--ok);
}
.pill.status-Dead {
  color: var(--bad);
}
.pill.status-Pending,
.pill.status-InFlight {
  color: var(--warn);
}

/* ── light theme ────────────────────────────────────────────────────── */

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa;
    --surface: #ffffff;
    --surface-2: #f0f3f6;
    --line: #d8dee4;
    --text: #1f2328;
    --dim: #636c76;
    --accent: #0969da;
    --ok: #1a7f37;
    --info: #0969da;
    --warn: #9a6700;
    --bad: #cf222e;
  }

  .banner {
    color: #82071e;
  }

  .pill.egress {
    color: #8250df;
  }
}
