/* Middleware console — Voice Stack theme.
 *
 * Same design system as voice.xpin.ae: warm cream ground, Instrument Serif
 * display type, Inter for UI, JetBrains Mono for labels and code, 1px borders
 * and no shadows, pill controls, black-pill active nav.
 *
 * Chart series colours are validated against THIS theme's card surfaces
 * (#FFFDF8 light / #171614 dark), not the generic ones — see charts.js.
 */

:root {
  color-scheme: light;

  /* Voice Stack palette */
  --plane:        #FAF7EE;   /* page ground (cream) */
  --surface:      #FFFDF8;   /* cards */
  --surface-2:    #F1ECDF;
  --surface-3:    #ECE6D6;
  --sidebar:      #F4F0E4;
  --sidebar-hover:#E8E2D2;

  --ink:          #141310;
  --ink-2:        #4c4a43;
  --muted:        #8f8b80;
  --hairline:     #e4dfd0;
  --line-strong:  #d9d3c2;

  --brand:        #5b3fae;   /* Voice Stack purple */
  --lavender:     #DCCFF8;
  --forest:       #1F4A38;
  --accent:       var(--brand);
  --accent-ink:   #FAF7EE;
  --accent-soft:  var(--lavender);

  /* Status — fixed, never themed; always paired with a text label. */
  --good:         #0ca30c;
  --warning:      #fab219;
  --serious:      #ec835a;
  --critical:     #d03b3b;
  --good-text:    #006300;
  --destructive:  #c8383f;

  /* Chart series, validated against --surface in this mode. */
  --series-1:     #5b3fae;
  --series-2:     #eb6834;
  --grid:         #e4dfd0;
  --axis:         #d9d3c2;

  --shell-max: 1760px;  /* topbar and content share this, so their right edges line up */
  --shell-pad: 28px;
  --radius:   14px;   /* 0.875rem, matching the app */
  --radius-s: 10px;
  --pill:     9999px;

  --sans:  "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono:  "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --serif: "Instrument Serif", Georgia, "Times New Roman", serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:        #0F0F0E;
  --surface:      #171614;
  --surface-2:    #1d1c19;
  --surface-3:    #23211d;
  --sidebar:      #0F0F0E;
  --sidebar-hover:#23211d;
  --ink:          #FAF7EE;
  --ink-2:        #a8a396;
  --muted:        #8f8b80;
  --hairline:     #2a2823;
  --line-strong:  #33302a;
  --brand:        #CBB9F8;
  --accent:       #CBB9F8;
  --accent-ink:   #141310;
  --accent-soft:  #33305c;
  --good-text:    #0ca30c;
  --destructive:  #f05a5f;
  --series-1:     #9085e9;
  --series-2:     #d95926;
  --grid:         #2a2823;
  --axis:         #33302a;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--plane);
  font-feature-settings: "cv11", "ss01";
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
::selection { background: color-mix(in oklab, var(--lavender) 70%, transparent); }

.scrollbar-thin::-webkit-scrollbar { width: 8px; height: 8px; }
.scrollbar-thin::-webkit-scrollbar-thumb {
  background: color-mix(in oklab, var(--muted) 30%, transparent); border-radius: 9999px; }

/* ------------------------------------------------------------------ shell */
.shell { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }
.sidebar {
  border-right: 1px solid var(--hairline);
  background: var(--sidebar);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px 18px; border-bottom: 1px solid var(--hairline);
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 10px;
  background: var(--ink); color: var(--plane);
  display: grid; place-items: center;
  font-family: var(--serif); font-size: 17px; line-height: 1;
  padding-bottom: 2px;
}
.brand-name {
  font-family: var(--serif); font-size: 20px; line-height: 1.1;
  letter-spacing: -0.01em; color: var(--ink);
}
.brand-sub {
  font-family: var(--mono); font-size: 9.5px; text-transform: uppercase;
  letter-spacing: 0.16em; color: var(--muted); margin-top: 2px;
}
.nav { padding: 14px 12px; flex: 1; }
.nav-group { margin-bottom: 18px; }
.nav-label {
  font-family: var(--mono); font-size: 9.5px; text-transform: uppercase;
  letter-spacing: 0.16em; color: var(--muted); padding: 0 10px 7px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: var(--pill);
  color: var(--ink-2); cursor: pointer; font-size: 13.5px;
  border: 1px solid transparent; width: 100%; text-align: left;
  background: none; font-family: inherit; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--sidebar-hover); color: var(--ink); text-decoration: none; }
.nav-item.active { background: var(--ink); color: var(--plane); border-color: var(--ink); }
.nav-item .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .5; }
.nav-foot { border-top: 1px solid var(--hairline); padding: 14px; }
.who { font-size: 12px; color: var(--muted); }
.who strong { display: block; color: var(--ink); font-weight: 600; font-size: 13px; }

.main { min-width: 0; display: flex; flex-direction: column; }
/* The bar itself is full-bleed so its rule spans the window; its contents are
   constrained to the same box as .content, so the action buttons sit exactly
   above the right edge of the cards rather than floating off to the side. */
.topbar {
  border-bottom: 1px solid var(--hairline);
  background: var(--plane); position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px var(--shell-pad);
  max-width: var(--shell-max); width: 100%; margin: 0 auto;
}
.topbar h1 {
  margin: 0; font-family: var(--serif); font-size: 27px; font-weight: 400;
  letter-spacing: -0.02em; line-height: 1.15;
}
.topbar .sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.content { padding: 24px var(--shell-pad) 72px; max-width: var(--shell-max);
  width: 100%; margin: 0 auto; }

/* ----------------------------------------------------------------- pieces */
.card {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 18px;
}
.card + .card { margin-top: 14px; }
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.card-title {
  font-family: var(--serif); font-size: 18px; font-weight: 400;
  letter-spacing: -0.01em; line-height: 1.2;
}
.card-note { font-size: 12px; color: var(--muted); }
.eyebrow {
  font-family: var(--mono); font-size: 9.5px; text-transform: uppercase;
  letter-spacing: 0.16em; color: var(--muted);
}
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.g-2-1 { grid-template-columns: 2fr 1fr; }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .g3, .g-2-1 { grid-template-columns: 1fr; } }
@media (max-width: 860px) { .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .g2, .g4 { grid-template-columns: 1fr; }
  :root { --shell-pad: 18px; } }

/* stat tile — the figure stays in the UI sans, never the display serif,
   so numbers keep tabular alignment and chart-adjacent consistency. */
.stat { background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 16px 18px; }
.stat .label {
  font-family: var(--mono); font-size: 9.5px; text-transform: uppercase;
  letter-spacing: 0.15em; color: var(--muted);
}
.stat .value { font-size: 30px; font-weight: 600; letter-spacing: -0.03em; margin-top: 8px; }
.stat .foot { font-size: 12px; color: var(--ink-2); margin-top: 4px; }

/* buttons — pill, matching the app */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  font: inherit; font-size: 13px; padding: 8px 16px; cursor: pointer;
  border-radius: var(--pill); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); transition: background .12s, opacity .12s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--ink); color: var(--plane); border-color: var(--ink); }
.btn.primary:hover { opacity: .86; background: var(--ink); }
.btn.danger { color: var(--destructive); border-color: color-mix(in srgb, var(--destructive) 45%, transparent);
  background: transparent; }
.btn.danger:hover { background: color-mix(in srgb, var(--destructive) 9%, transparent); }
.btn.sm { padding: 5px 11px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* forms */
label.field { display: block; margin-bottom: 14px; }
label.field > span {
  display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; font-weight: 500;
}
label.field .hint { font-weight: 400; color: var(--muted); font-size: 11.5px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=url], input[type=date], select, textarea {
  width: 100%; font: inherit; font-size: 13.5px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-s); padding: 8px 12px;
}
/* Identical box height across control types — a native select is ~2px shorter
   than a text input at the same padding, which reads as a misaligned row. */
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=url], input[type=date], select {
  height: 38px; line-height: 1.35;
}
select { padding-right: 30px; }
textarea { font-family: var(--mono); font-size: 12.5px; line-height: 1.6; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand);
}
.check { display: flex; align-items: center; gap: 9px; font-size: 13px; margin-bottom: 10px; }
.check input { width: auto; accent-color: var(--brand); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 165px; }
/* Labels in a row vary in height — a longer hint wraps to two lines. Anchoring
   the control to the bottom of the cell keeps every input on one baseline
   regardless of how tall its caption ended up. */
.row > label.field { display: flex; flex-direction: column; justify-content: flex-end; }
.row > label.field > span { flex: none; }

/* table */
.table-wrap { overflow-x: auto; border: 1px solid var(--hairline);
  border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); }
th {
  text-align: left; font-family: var(--mono); font-size: 9.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.13em; color: var(--muted);
  padding: 11px 14px; border-bottom: 1px solid var(--hairline); white-space: nowrap;
  background: var(--surface-2);
}
th:first-child { border-top-left-radius: var(--radius); }
th:last-child { border-top-right-radius: var(--radius); }
td { padding: 11px 14px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; }

/* badges & status */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.08em; padding: 3px 9px; border-radius: var(--pill);
  border: 1px solid var(--line-strong); color: var(--ink-2); white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.good { color: var(--good-text); border-color: color-mix(in srgb, var(--good) 45%, transparent);
  background: color-mix(in srgb, var(--good) 7%, transparent); }
.badge.warn { color: #8a5a00; border-color: color-mix(in srgb, var(--warning) 55%, transparent);
  background: color-mix(in srgb, var(--warning) 12%, transparent); }
.badge.bad  { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 45%, transparent);
  background: color-mix(in srgb, var(--critical) 7%, transparent); }
.badge.info { color: var(--brand); border-color: color-mix(in srgb, var(--brand) 40%, transparent);
  background: color-mix(in srgb, var(--lavender) 40%, transparent); }
:root[data-theme="dark"] .badge.warn { color: var(--warning); }
:root[data-theme="dark"] .badge.info { background: color-mix(in srgb, var(--brand) 16%, transparent); }

/* code */
pre.code {
  margin: 0; background: var(--surface-2); border: 1px solid var(--hairline);
  border-radius: var(--radius-s); padding: 14px 15px; overflow-x: auto;
  font-family: var(--mono); font-size: 12.3px; line-height: 1.65; color: var(--ink);
  white-space: pre; tab-size: 2;
}
.code-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 8px;
}
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  font: inherit; font-size: 12px; padding: 5px 12px; cursor: pointer;
  background: none; border: 1px solid transparent; border-radius: var(--pill); color: var(--muted);
}
.tab:hover { color: var(--ink); background: var(--surface-2); }
.tab.active { color: var(--ink); border-color: var(--line-strong); background: var(--surface); }

/* token reveal — lavender panel, the app's highlight surface */
.token-box {
  border: 1px solid color-mix(in srgb, var(--brand) 35%, transparent);
  background: color-mix(in srgb, var(--lavender) 45%, var(--surface));
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
:root[data-theme="dark"] .token-box {
  background: color-mix(in srgb, var(--brand) 14%, var(--surface));
}
.token-value {
  font-family: var(--mono); font-size: 13px; word-break: break-all;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius-s); padding: 11px 13px; margin: 10px 0;
}

/* modal */
.modal-back {
  position: fixed; inset: 0; background: color-mix(in srgb, #141310 45%, transparent);
  display: grid; place-items: center; padding: 20px; z-index: 100;
}
.modal {
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 20px; width: min(680px, 100%);
  max-height: 88vh; overflow-y: auto;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--hairline); position: sticky; top: 0;
  background: var(--surface); border-radius: 20px 20px 0 0;
}
.modal-title { font-family: var(--serif); font-size: 20px; font-weight: 400; letter-spacing: -0.01em; }
.modal-body { padding: 20px 22px; }
.modal-foot {
  padding: 14px 22px; border-top: 1px solid var(--hairline);
  display: flex; gap: 8px; justify-content: flex-end; position: sticky; bottom: 0;
  background: var(--surface); border-radius: 0 0 20px 20px;
}

/* misc */
.empty { padding: 40px 18px; text-align: center; color: var(--muted); font-size: 13px; }
.toast-wrap { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 200; }
.toast {
  background: var(--ink); color: var(--plane); padding: 11px 16px;
  border-radius: var(--pill); font-size: 13px; max-width: 400px;
}
.toast.bad { background: var(--destructive); color: #fff; }
.split { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: grid; gap: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }
.notice {
  border: 1px solid var(--hairline); border-left: 3px solid var(--brand);
  background: color-mix(in srgb, var(--lavender) 28%, var(--surface));
  border-radius: var(--radius-s);
  padding: 12px 14px; font-size: 12.5px; color: var(--ink-2); margin-bottom: 14px;
}
:root[data-theme="dark"] .notice { background: var(--surface-2); }
.notice.warn { border-left-color: var(--warning);
  background: color-mix(in srgb, var(--warning) 10%, var(--surface)); }

/* auth pages — cream ground with a serif lockup, like the app's login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: var(--plane); }
.auth-card { width: min(420px, 100%); }

/* ------------------------------------------------------------ theme toggle */
/* Light is the default everywhere; dark is opt-in and remembered per browser. */
.theme-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: var(--pill); padding: 5px 12px; cursor: pointer;
  font: inherit; font-size: 12px; color: var(--ink-2); line-height: 1;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--ink); }
.theme-toggle svg { width: 14px; height: 14px; flex: none; }
/* Each glyph shows only in the mode where it is the *action*, not the state. */
.theme-toggle .to-dark { display: inline-flex; }
.theme-toggle .to-light { display: none; }
:root[data-theme="dark"] .theme-toggle .to-dark { display: none; }
:root[data-theme="dark"] .theme-toggle .to-light { display: inline-flex; }

/* ------------------------------------------------------------- filter bar */
/* Filters sit on one baseline: every control is the same height, and a
   checkbox filter is rendered as a full-height pill rather than a bare box
   floating half a row above the selects. */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px;
}
.filters .filter {
  display: flex; flex-direction: column; gap: 6px;
  flex: 1 1 190px; min-width: 150px; margin: 0;
}
.filters .filter > span {
  font-size: 12px; color: var(--ink-2); font-weight: 500; line-height: 1;
}
.filters .filter > input,
.filters .filter > select { margin: 0; }
/* A toggle filter keeps the control row's height so nothing sits off-baseline. */
.filters .filter-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 14px; margin: 0; flex: 0 0 auto;
  border: 1px solid var(--line-strong); border-radius: var(--pill);
  background: var(--surface); cursor: pointer; font-size: 13px; color: var(--ink-2);
  white-space: nowrap;
}
.filters .filter-toggle:hover { background: var(--surface-2); color: var(--ink); }
.filters .filter-toggle input { width: auto; height: auto; margin: 0; }
.filters .filter-toggle:has(input:checked) {
  border-color: var(--brand); color: var(--ink);
  background: color-mix(in srgb, var(--lavender) 40%, var(--surface));
}
.filters .filter-actions { margin-left: auto; display: flex; gap: 8px; align-items: flex-end; }
