/*
 * Voice Agent design system: "Dense / terminal" product UI.
 * Geist + Geist Mono (mono only for data: numbers, IDs, keys, code) · 1.25 type scale on a 14px base ·
 * 2px radius · no shadows · structure from 1px rules · "Graphite & Teal": cool neutrals, one teal
 * accent for actions, selection and live state; green/amber/red reserved for status.
 * Light/dark follow the system unless the theme switch sets :root[data-theme].
 */

:root {
  --font-sans: "Geist", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Type scale: 14px × 1.25ⁿ */
  --fs-2xs: 11px;
  --fs-xs: 12px;
  --fs-base: 14px;
  --fs-md: 17.5px;
  --fs-lg: 21.875px;
  --fs-xl: 27.34px;
  --fs-2xl: 34.18px;
  --fs-3xl: 42.72px;

  /* Spacing: 4px scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-12: 48px;
  --sp-16: 64px;

  --radius: 2px;
  --control-h: 32px;
  --rail-w: 208px;
  --inspector-w: 336px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  /* Light palette: cool graphite neutrals, teal accent */
  --bg: #f5f6f7;
  --surface: #ffffff;
  --sunken: #eef0f2;
  --text: #111417;
  --muted: #59616a;
  --border: #dce0e4;
  --border-strong: #b8bfc6;
  --accent: #0f766e;
  --accent-hover: #0b5f58;
  --accent-text: #ffffff;
  --accent-soft: #ddf1ee;
  --ok: #2e7d32;
  --ok-soft: #e3f1e4;
  --warn: #946200;
  --warn-soft: #f7ecd2;
  --danger: #b42318;
  --danger-soft: #fbe4e1;
  --backdrop: rgb(17 20 23 / 0.45);

  color-scheme: light;
}

/* Dark palette: re-tuned, not inverted. Applies when chosen in the theme switch, or when the
   system is dark and no explicit choice was made. */
:root[data-theme="dark"] {
  --bg: #0f1214;
  --surface: #171b1e;
  --sunken: #0b0d0f;
  --text: #e8ecee;
  --muted: #9aa3ab;
  --border: #2a3035;
  --border-strong: #3d454c;
  --accent: #34b8a5;
  --accent-hover: #4fcdb9;
  --accent-text: #04201c;
  --accent-soft: #10302c;
  --ok: #5fbf77;
  --ok-soft: #14281a;
  --warn: #e0b04c;
  --warn-soft: #2e2716;
  --danger: #f2837a;
  --danger-soft: #351c1a;
  --backdrop: rgb(0 0 0 / 0.6);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1214;
    --surface: #171b1e;
    --sunken: #0b0d0f;
    --text: #e8ecee;
    --muted: #9aa3ab;
    --border: #2a3035;
    --border-strong: #3d454c;
    --accent: #34b8a5;
    --accent-hover: #4fcdb9;
    --accent-text: #04201c;
    --accent-soft: #10302c;
    --ok: #5fbf77;
    --ok-soft: #14281a;
    --warn: #e0b04c;
    --warn-soft: #2e2716;
    --danger: #f2837a;
    --danger-soft: #351c1a;
    --backdrop: rgb(0 0 0 / 0.6);
    color-scheme: dark;
  }
}

@media (pointer: coarse) {
  :root { --control-h: 44px; }
}

/* ---- base -------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

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

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

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

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.15; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }
code, kbd, .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
code { font-size: 0.92em; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border: 3px solid transparent; background-clip: padding-box; }

/* Small uppercase labels: the visible structure of the interface */
.label {
  font: 600 var(--fs-2xs) / 1.3 var(--font-sans);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

kbd {
  display: inline-block;
  min-width: 18px;
  padding: 0 4px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius);
  font-size: var(--fs-2xs);
  line-height: 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
}

/* ---- controls ---------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--control-h);
  padding: 0 var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: 500 var(--fs-base) / 1 var(--font-sans);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease);
}
.btn:hover { background: var(--sunken); border-color: var(--text); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] {
  cursor: not-allowed;
  color: var(--muted);
  background: transparent;
  border-style: dashed;
  border-color: var(--border);
  transform: none;
}
.btn kbd { margin-left: var(--sp-1); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-text); }
.btn-primary kbd { background: transparent; color: inherit; border-color: currentColor; }

.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: var(--surface); }

.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-quiet:hover { background: var(--sunken); border-color: var(--border); }

.btn-sm { min-height: 26px; padding: 0 var(--sp-2); font-size: var(--fs-xs); }
@media (pointer: coarse) { .btn-sm { min-height: 44px; } }

.btn[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }

.input, .select, .textarea {
  width: 100%;
  min-height: var(--control-h);
  padding: 0 var(--sp-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: 400 var(--fs-base) / 1.4 var(--font-sans);
}
.textarea { padding: var(--sp-2); font: 400 var(--fs-base) / 1.55 var(--font-sans); resize: vertical; }
.textarea.code { font: 400 var(--fs-xs) / 1.55 var(--font-mono); }
.input.mono { font-family: var(--font-mono); font-size: var(--fs-xs); }
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: 0.8; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--sunken); color: var(--muted); border-color: var(--border); cursor: not-allowed; }
.input[aria-invalid="true"] { border-color: var(--danger); }

.field { display: grid; gap: var(--sp-1); }
.field > span:first-child { font-size: var(--fs-xs); font-weight: 500; color: var(--text); }
.field .hint { font-size: var(--fs-xs); color: var(--muted); }

.check { display: inline-flex; align-items: center; gap: var(--sp-2); min-height: var(--control-h); cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

/* ---- structure --------------------------------------------------------------------- */

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: 44px;
  padding: 0 var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.panel-head h2, .panel-head h3 { font-size: var(--fs-base); }
.panel-body { padding: var(--sp-4); }
.rule { border: 0; border-top: 1px solid var(--border); margin: 0; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  border-bottom: 1px solid var(--border-strong);
  text-align: left;
  font: 600 var(--fs-2xs) / 1.3 var(--font-sans);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.table th.num { text-align: right; }
.table td { padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .sub { display: block; font: 400 var(--fs-xs) / 1.4 var(--font-sans); color: var(--muted); }
.table .sub.mono { font: 400 var(--fs-2xs) / 1.5 var(--font-mono); }
.table tr[data-selectable] { cursor: pointer; }
.table tr[data-selectable]:hover td { background: var(--sunken); }
.table tr[aria-selected="true"] td { background: var(--accent-soft); }
.table tr[aria-selected="true"] td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.table .row-empty td { padding: var(--sp-8) var(--sp-4); color: var(--muted); text-align: left; }

/* Status: a coloured square + word, never colour alone */
.status { display: inline-flex; align-items: center; gap: 6px; font: 500 var(--fs-xs) / 1 var(--font-sans); white-space: nowrap; }
.status::before { content: ""; width: 7px; height: 7px; background: currentColor; }
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.danger { color: var(--danger); }
.status.idle { color: var(--muted); }
.status.live { color: var(--accent); }

.notice {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-left: 3px solid var(--warn);
  background: var(--warn-soft);
  color: var(--text);
  font-size: var(--fs-base);
}
.notice.danger { border-left-color: var(--danger); background: var(--danger-soft); }
.notice.ok { border-left-color: var(--ok); background: var(--ok-soft); }

/* ---- dialog and toasts -------------------------------------------------------------- */

dialog.dialog {
  width: min(480px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
dialog.dialog::backdrop { background: var(--backdrop); }
dialog.dialog[open] { animation: dialog-in 150ms var(--ease); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(6px); } }
.dialog form { display: grid; gap: var(--sp-4); padding: var(--sp-6); }
.dialog h2 { font-size: var(--fs-md); }
.dialog .dialog-body { color: var(--muted); white-space: pre-line; }
.dialog .dialog-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); padding-top: var(--sp-2); }

.toasts {
  position: fixed;
  right: var(--sp-4);
  bottom: var(--sp-4);
  z-index: 50;
  display: grid;
  gap: var(--sp-2);
  width: min(380px, calc(100vw - 32px));
}
.toast {
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--ok);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: var(--fs-base);
  animation: dialog-in 150ms var(--ease);
}
.toast.danger { border-left-color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---- top bar (shared) -------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-6);
  min-height: 56px;
  padding: var(--sp-2) var(--sp-6);
  border-bottom: 1px solid var(--border-strong);
  background: var(--surface);
}
.theme-switch { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.theme-switch button {
  min-height: 28px;
  padding: 0 var(--sp-2);
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 500 var(--fs-xs) / 1 var(--font-sans);
  cursor: pointer;
  transition: background-color 150ms var(--ease), color 150ms var(--ease);
}
.theme-switch button + button { border-left: 1px solid var(--border); }
.theme-switch button:hover { color: var(--text); background: var(--sunken); }
.theme-switch button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.theme-switch button:focus-visible { outline-offset: -2px; }
@media (pointer: coarse) { .theme-switch button { min-height: 44px; padding: 0 var(--sp-3); } }

.wordmark { display: flex; align-items: baseline; gap: var(--sp-2); white-space: nowrap; text-decoration: none; color: var(--text); }
.wordmark strong { font: 600 var(--fs-md) / 1 var(--font-sans); letter-spacing: -0.02em; }
.wordmark span { font: 600 var(--fs-2xs) / 1 var(--font-sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.topbar .spacer { flex: 1; }
.topbar-form { display: flex; align-items: center; gap: var(--sp-2); }
.topbar-form .input { width: 260px; }
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4); }
  .topbar .spacer { display: none; }
  .topbar-form { width: 100%; }
  .topbar-form .input { width: auto; flex: 1; min-width: 0; }
}
