/*
 * One stylesheet, no preprocessor. Dark by default because this is an operations screen that tends to
 * sit open on a wall display, and light when the viewer's system asks for it.
 */

:root {
  --bg: #0f1115;
  --bg-raised: #171a21;
  --bg-input: #10131a;
  --border: #262b36;
  --border-strong: #373f4f;
  --text: #e6e9ef;
  --text-muted: #9aa4b6;
  --text-faint: #6b7688;
  --accent: #4c8dff;
  --accent-quiet: #1e2b45;
  --pass: #35c98a;
  --pass-quiet: #12291f;
  --fail: #ff5c6c;
  --fail-quiet: #2c1418;
  --warn: #f0b429;
  --warn-quiet: #2c2210;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --bg-raised: #ffffff;
    --bg-input: #ffffff;
    --border: #e1e4ea;
    --border-strong: #c8cdd6;
    --text: #171a21;
    --text-muted: #5c6675;
    --text-faint: #8b95a5;
    --accent: #2563eb;
    --accent-quiet: #e8efff;
    --pass: #12855a;
    --pass-quiet: #e6f7ef;
    --fail: #c8323f;
    --fail-quiet: #fdecee;
    --warn: #97650a;
    --warn-quiet: #fdf3dd;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

/* ── top bar ─────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  height: 52px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }

.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--pass);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--pass) 22%, transparent);
}

.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  padding: 5px 11px;
  border-radius: 6px;
  color: var(--text-muted);
  font-weight: 500;
}
.topbar nav a:hover { background: var(--bg-input); text-decoration: none; color: var(--text); }
.topbar nav a.active { background: var(--accent-quiet); color: var(--accent); }

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

/* ── layout ──────────────────────────────────────────────────────────────── */

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 22px;
}
.page-head h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.page-head .sub { color: var(--text-muted); margin-top: 3px; font-size: 13px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.crumbs { font-size: 12.5px; color: var(--text-faint); margin-bottom: 6px; }
.crumbs a { color: var(--text-muted); }

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
}
.card > h2 {
  margin: 0;
  padding: 13px 16px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.card > h2 .hint {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--text-faint);
  margin-left: 8px;
}
.card-body { padding: 16px; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

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

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--border); }
th {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 600;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--bg-input); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }

/* ── pills and status ────────────────────────────────────────────────────── */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.pill-pass { background: var(--pass-quiet); color: var(--pass); }
.pill-fail { background: var(--fail-quiet); color: var(--fail); }
.pill-warn { background: var(--warn-quiet); color: var(--warn); }
.pill-muted { background: var(--bg-input); color: var(--text-faint); border: 1px solid var(--border); }
.pill-accent { background: var(--accent-quiet); color: var(--accent); }

.metric { padding: 14px 16px; }
.metric .label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 600;
}
.metric .value {
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.metric .value.pass { color: var(--pass); }
.metric .value.fail { color: var(--fail); }

/* Recent-run strip: one block per execution, newest on the right. */
.sparks { display: flex; gap: 2px; align-items: center; }
.sparks i {
  display: block;
  width: 7px;
  height: 20px;
  border-radius: 2px;
  background: var(--pass);
  opacity: 0.85;
}
.sparks i.f { background: var(--fail); opacity: 1; }
.sparks i.empty { background: var(--border); }

/* ── forms ───────────────────────────────────────────────────────────────── */

label.field { display: block; }
label.field > span.lbl {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}
label.field > span.lbl .req { color: var(--fail); margin-left: 2px; }
label.field > span.help {
  display: block;
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 4px;
}

/*
 * Every text-like control, listed by type rather than bare `input` so checkboxes keep their own sizing.
 * password belongs here: while it was missing, the three credential fields — Teams webhook, PagerDuty
 * routing key, ElevenLabs key — fell back to the browser default and rendered as bright white boxes on a
 * dark form.
 */
input[type=text], input[type=password], input[type=number], input[type=time],
input[type=url], input[type=email], select, textarea {
  width: 100%;
  padding: 7px 9px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
input.invalid, select.invalid { border-color: var(--fail); }

/*
 * Credential fields. A stored secret is write-only — the API never returns it — so the field itself is always
 * empty and cannot show its own value. The badge on the label carries that state instead, which is the
 * difference between "this customer cannot alert" and "this is configured, just hidden".
 */
.mono-input { font-family: var(--mono); font-size: 12.5px; letter-spacing: 0.02em; }
label.field-secret > span.lbl { display: flex; align-items: center; gap: 7px; }
.secret-state {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.03em;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid transparent;
  text-transform: none;
}
.secret-state.is-set {
  color: var(--pass);
  background: color-mix(in srgb, var(--pass) 12%, transparent);
  border-color: color-mix(in srgb, var(--pass) 34%, transparent);
}
.secret-state.is-unset {
  color: var(--text-faint);
  background: var(--bg-input);
  border-color: var(--border);
}

/*
 * Placeholders have to read as absent, not as a value someone already entered.
 * The browser default is bright enough on a dark ground that a hint like "reward question" was
 * mistakable for a filled-in field.
 */
::placeholder { color: var(--text-faint); opacity: 1; }
input::placeholder, textarea::placeholder { font-style: italic; }
textarea { resize: vertical; min-height: 60px; }
input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); }

.check {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 8px 0;
}
.check .lbl { font-weight: 600; font-size: 13px; }
.check .help { font-size: 11.5px; color: var(--text-faint); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); color: #fff; }
.btn-danger { color: var(--fail); border-color: var(--fail); }
.btn-danger:hover:not(:disabled) { background: var(--fail-quiet); color: var(--fail); }
.btn-sm { padding: 4px 9px; font-size: 12.5px; }
.btn-icon { padding: 4px 7px; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* Ordered lists of turns and validators. */
.rows { display: flex; flex-direction: column; gap: 10px; }
.rowcard {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  padding: 12px;
}
.rowcard .rowhead {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.rowcard .seq {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-faint);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
}
.rowcard .rowhead .grow { flex: 1; font-weight: 600; }
.empty-hint {
  color: var(--text-faint);
  font-size: 13px;
  padding: 14px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

/* ── advanced (collapsed) ────────────────────────────────────────────────── */

details.adv { border-top: 1px solid var(--border); }
details.adv > summary {
  cursor: pointer;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  list-style: none;
}
details.adv > summary::-webkit-details-marker { display: none; }
details.adv > summary::before { content: "▸ "; color: var(--text-faint); }
details.adv[open] > summary::before { content: "▾ "; }
details.adv > summary:hover { color: var(--text); }
details.adv .card-body { padding-top: 0; }

/* ── misc ────────────────────────────────────────────────────────────────── */

.mono { font-family: var(--mono); font-size: 12.5px; }
/* An outbound link inside a clickable row: it must read as the exception to the row, not compete with it. */
.lnk { color: var(--accent); text-decoration: none; }
.lnk:hover { text-decoration: underline; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.spacer { flex: 1; }

pre.json {
  margin: 0;
  padding: 13px 16px;
  background: var(--bg-input);
  border-radius: 6px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-muted);
  max-height: 460px;
}

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

.banner {
  padding: 11px 14px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-size: 13px;
  border: 1px solid;
}
.banner-fail { background: var(--fail-quiet); border-color: var(--fail); color: var(--fail); }
.banner-warn { background: var(--warn-quiet); border-color: var(--warn); color: var(--warn); }
.banner-info { background: var(--accent-quiet); border-color: var(--accent); color: var(--accent); }

/* ── paging ──────────────────────────────────────────────────────────────── */

.pager {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 16px;
  border-top: 1px solid var(--border);
}

/* ── audio library ───────────────────────────────────────────────────────── */

.clip {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.clip:last-child { border-bottom: none; }
.clip .clip-main { flex: 1; min-width: 0; }
.clip .clip-name { font-weight: 600; }
.clip .clip-text {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
  overflow-wrap: anywhere;
}
.clip .clip-meta { color: var(--text-faint); font-size: 11.5px; margin-top: 3px; }
.clip audio { height: 32px; max-width: 220px; }

/* ── toasts ──────────────────────────────────────────────────────────────── */

.toasts {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  max-width: 420px;
}
.toast {
  padding: 11px 14px;
  border-radius: var(--radius);
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.32);
  font-size: 13px;
}
.toast.err { border-color: var(--fail); color: var(--fail); }
.toast.ok { border-color: var(--pass); color: var(--pass); }

/* ── modal ───────────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 70;
}
.modal {
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 20px;
  width: min(440px, calc(100vw - 32px));
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}
.modal h3 { margin: 0 0 10px; font-size: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ── run-now result ──────────────────────────────────────────────────────── */

.runresult { border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.runresult .rr-head {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.runresult .rr-head.pass { background: var(--pass-quiet); }
.runresult .rr-head.fail { background: var(--fail-quiet); }
.vlist { list-style: none; margin: 0; padding: 0; }
.vlist li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 9px 16px;
  border-bottom: 1px solid var(--border);
}
.vlist li:last-child { border-bottom: none; }
.vlist .vwhat { flex: 1; }
.vlist .vdetail { font-size: 12px; color: var(--text-faint); margin-top: 2px; }

.spin {
  width: 13px; height: 13px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
