/* LiveKit Dashboard — dark console theme. */
:root {
  --bg: #0d0f12;
  --panel: #14171c;
  --panel-2: #191d23;
  --line: #252a32;
  --text: #e6e9ee;
  --muted: #8b94a3;
  --accent: #22c55e;
  --accent-dim: #16351f;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }

.shell { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 228px;
  flex: 0 0 228px;
  background: #0a0c0f;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px; border-bottom: 1px solid var(--line);
}
.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 10px var(--accent);
}
.brand strong { display: block; font-size: 14px; }
.brand small { color: var(--muted); font-size: 11px; }

.sidebar nav { padding: 10px 0; flex: 1; }
.group {
  padding: 16px 16px 6px; font-size: 10px; letter-spacing: .12em;
  text-transform: uppercase; color: #5b6472;
}
.sidebar nav a, .sidebar nav .soon {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; font-size: 13px; color: #c3cad6;
  border-left: 2px solid transparent;
}
.sidebar nav a:hover { background: #11151a; color: #fff; }
.sidebar nav a.active {
  color: var(--accent); background: var(--accent-dim);
  border-left-color: var(--accent);
}
.sidebar nav .soon { color: #4d5563; cursor: not-allowed; }
.sidebar nav .soon em {
  font-style: normal; font-size: 9px; color: #454d5b;
  border: 1px solid #232830; border-radius: 4px; padding: 1px 5px;
}
.sidebar-foot { padding: 14px 16px; border-top: 1px solid var(--line); }
.sidebar-foot a { color: var(--muted); font-size: 12px; }
.sidebar-foot a:hover { color: var(--text); }

/* ---------- layout ---------- */
main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 600; }
.topbar-right { color: var(--muted); font-size: 12px; display: flex; gap: 14px; align-items: center; }
.content { padding: 22px 24px 60px; }

/* ---------- cards ---------- */
.grid { display: grid; gap: 14px; }
.grid.k4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.k2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.card h2 {
  margin: 0 0 12px; font-size: 12px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted); font-weight: 600;
}
.stat .value { font-size: 27px; font-weight: 650; line-height: 1.1; }
.stat .label {
  font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .08em; margin-top: 6px;
}
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.value.accent { color: var(--accent); }

/* ---------- meters ---------- */
.meter { height: 6px; background: #10141a; border-radius: 99px; overflow: hidden; margin-top: 10px; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.meter > span.warn { background: var(--warn); }
.meter > span.danger { background: var(--danger); }
.meter-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.meter-row + .meter { margin-bottom: 14px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 10px; border-bottom: 1px solid #1c2027; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel-2); }
td.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.empty { color: var(--muted); text-align: center; padding: 34px 10px; }
.empty strong { display: block; color: var(--text); margin-bottom: 6px; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: 11px; border: 1px solid var(--line); color: var(--muted);
}
.badge.live { color: var(--accent); border-color: #1e4b2e; background: var(--accent-dim); }
.badge.ok { color: var(--accent); border-color: #1e4b2e; }
.badge.off { color: var(--danger); border-color: #4b1e1e; }
.badge.warn { color: var(--warn); border-color: #4b3a1e; }

/* ---------- forms ---------- */
input, select, button {
  font: inherit; color: var(--text); background: #0f1216;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
input:focus, select:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 5px;
        text-transform: uppercase; letter-spacing: .07em; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1; min-width: 130px; margin-bottom: 0; }

button, .btn {
  background: var(--accent); border-color: var(--accent); color: #06210f;
  font-weight: 600; cursor: pointer; white-space: nowrap;
}
button:hover, .btn:hover { filter: brightness(1.08); }
button.ghost, .btn.ghost { background: transparent; color: var(--text); border-color: var(--line); font-weight: 500; }
button.ghost:hover { background: var(--panel-2); }
button.danger { background: transparent; color: var(--danger); border-color: #4b1e1e; }
button.danger:hover { background: #2a1414; }
button.tiny, .btn.tiny { padding: 4px 9px; font-size: 12px; border-radius: 6px; }

.checkline { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text); }
.checkline input { width: auto; }
.checkline label { margin: 0; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); }

/* ---------- flash ---------- */
.flash { margin: 14px 24px -4px; padding: 10px 14px; border-radius: 8px; font-size: 13px; }
.flash.ok { background: var(--accent-dim); color: #86efac; border: 1px solid #1e4b2e; }
.flash.err { background: #2a1414; color: #fca5a5; border: 1px solid #4b1e1e; }
/* Neither success nor failure: the page worked, but something downstream of it
   is not running. Used by the SIP pages when livekit-sip is absent. */
.flash.warn { background: #2a2314; color: #fcd34d; border: 1px solid #4b3a1e; }

/* ---------- misc ---------- */
.tokenbox {
  background: #0b0e12; border: 1px solid var(--line); border-radius: 8px; padding: 12px;
  font-family: ui-monospace, Menlo, monospace; font-size: 11px; word-break: break-all;
  color: #9ae6b4; max-height: 150px; overflow-y: auto;
}
pre.json {
  background: #0b0e12; border: 1px solid var(--line); border-radius: 8px; padding: 12px;
  font-size: 11px; overflow-x: auto; color: #cbd5e1; margin: 0;
}
.pager { display: flex; gap: 8px; align-items: center; margin-top: 16px; font-size: 13px; color: var(--muted); }
.spark { width: 100%; height: 54px; display: block; }
.kv { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid #1c2027; font-size: 13px; }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin-top: 10px; }
details.evt summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details.evt[open] summary { color: var(--text); margin-bottom: 8px; }

/* ---------- login ---------- */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 350px; background: var(--panel);
              border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.login-card h1 { margin: 0 0 4px; font-size: 19px; }
.login-card p.sub { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 6px; padding: 10px; }

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  .sidebar nav { display: flex; flex-wrap: wrap; }
  .group, .soon { display: none !important; }
}

/* ---------- stat cards ---------- */
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.statcard {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
}
.statcard .label {
  color: var(--muted); font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; display: flex; align-items: center; gap: 6px;
}
.statcard .value { font-size: 30px; font-weight: 600; margin-top: 6px; }
.statcard .value.accent { color: var(--accent); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a, .tabs button {
  background: transparent; border: 1px solid transparent; border-bottom: none;
  color: var(--muted); padding: 9px 15px; font-size: 13px; cursor: pointer;
  border-radius: 8px 8px 0 0; margin-bottom: -1px; font-family: inherit;
}
.tabs a:hover, .tabs button:hover { color: var(--text); }
.tabs a.active, .tabs button.active {
  color: var(--text); background: var(--panel);
  border-color: var(--line); border-bottom: 1px solid var(--panel);
}
.tabpane { display: none; }
.tabpane.active { display: block; }

/* ---------- id chip + copy ---------- */
.idchip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 7px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px; max-width: 210px;
}
.idchip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copybtn {
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  padding: 2px 4px; border-radius: 4px; font-size: 12px; line-height: 1;
}
.copybtn:hover { color: var(--text); background: var(--line); }
.copybtn.done { color: var(--accent); }

/* ---------- icon action buttons ---------- */
.actions { display: flex; gap: 6px; justify-content: flex-end; }
.iconbtn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 6px; padding: 5px 8px; cursor: pointer; font-size: 12px; line-height: 1.1;
}
.iconbtn:hover { color: var(--text); border-color: #39414e; }
.iconbtn.edit:hover  { color: var(--accent); border-color: #1e4b2e; }
.iconbtn.del:hover   { color: var(--danger); border-color: #4b1e1e; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.66);
  display: none; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 50; overflow-y: auto;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  width: 100%; max-width: 680px; box-shadow: 0 18px 50px rgba(0,0,0,.5);
}
.modal.wide { max-width: 940px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--line);
}
.modal-close {
  background: transparent; border: none; color: var(--muted);
  font-size: 20px; cursor: pointer; line-height: 1; padding: 0 4px;
}
.modal-close:hover { color: var(--text); }

/* ---------- notes ---------- */
.note {
  border-radius: 8px; padding: 9px 12px; font-size: 12px; margin: 10px 0;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--muted);
}
.note.warn { border-color: #4b3a1e; background: #241d10; color: #fcd34d; }
.note.info { border-color: #1e3a4b; background: #101d24; color: #7dd3fc; }

/* ---------- toggle ---------- */
.toggle { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13px; }
.toggle input { display: none; }
.toggle .track {
  width: 38px; height: 21px; border-radius: 11px; background: #2b313b;
  position: relative; transition: background .15s; flex: 0 0 38px;
}
.toggle .track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 15px; height: 15px; border-radius: 50%; background: #7b8494; transition: .15s;
}
.toggle input:checked + .track { background: var(--accent-dim); }
.toggle input:checked + .track::after { left: 20px; background: var(--accent); }

/* ---------- range ---------- */
.rangerow { display: flex; align-items: center; gap: 12px; }
.rangerow input[type=range] { flex: 1; accent-color: var(--accent); }
.rangeval {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px;
  padding: 2px 8px; font-size: 12px; min-width: 54px; text-align: center;
}
.scale { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 3px; }

/* ---------- misc ---------- */
.pilllist { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 10px; font-size: 12px;
}
.pill button { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0; font-size: 13px; }
.pill button:hover { color: var(--danger); }
.sectionhead {
  font-size: 13px; font-weight: 600; margin: 20px 0 10px;
  padding-bottom: 7px; border-bottom: 1px solid var(--line);
}
.sectionhead:first-child { margin-top: 0; }
textarea { width: 100%; font-family: inherit; resize: vertical; }
textarea.code, .jsonbox {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }

/* Brand logo replaces the old wordmark. max-width keeps it inside the sidebar
   if a future logo file is wider than the current one. */
.brand { justify-content: center; padding: 16px 14px; }
.brandlogo { max-width: 100%; height: auto; display: block; }

/* ---------- form layout fixes ---------- */
/* Inputs kept their intrinsic ~200px width while textareas were width:100%, so
   a form read as a row of stubby boxes next to edge-to-edge text areas. Fields
   now fill their column, which is what the two-column grid was assuming. */
.field input,
.field select,
.field textarea { width: 100%; }
/* Checkboxes must stay their natural size — the rule above would stretch them
   into a full-width bar. */
.field input[type="checkbox"],
.field input[type="radio"] { width: auto; }

/* Long-form text is unreadable at 1900px line length. This caps the measure
   without boxing in tables, which still need the full width to avoid scrolling. */
.content { max-width: 1500px; }

/* The system prompt scrolled sideways instead of wrapping, hiding the ends of
   lines. Prompts are prose, so they should wrap like prose while keeping the
   monospace alignment that makes structure visible. */
textarea.code {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  line-height: 1.55;
}

/* Sit the range readout and its scale under a full-width slider rather than
   letting the slider collapse to its default width. */
.rangerow input[type=range] { width: 100%; }

/* ---------- dark native widgets ---------- */
/* The single most important line here. Without it the browser paints its own
   chrome in light mode: <select> popup lists, date/time pickers, scrollbars and
   autofill highlights all render white on a dark page. color-scheme tells the
   engine this is a dark UI so it themes those natively. */
:root { color-scheme: dark; }

/* textarea was missing from the base `input, select, button` rule, so it fell
   back to the browser default — white background, black text — on every prompt
   and metadata box. */
textarea {
  font: inherit;
  color: var(--text);
  background: #0f1216;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

/* The dropdown popup is drawn by the OS. color-scheme handles most engines;
   these make the option rows match the panel colour where it does not. */
select option,
select optgroup {
  background: var(--panel);
  color: var(--text);
}

/* Scrollbars inside dark panels, so the prompt box does not get a light gutter. */
* { scrollbar-color: #39414e var(--panel); scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--panel); }
::-webkit-scrollbar-thumb { background: #39414e; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #4b5563; }

/* Chrome paints autofilled inputs pale yellow. The inset shadow is the only
   reliable way to override it. */
input:-webkit-autofill,
input:-webkit-autofill:focus,
textarea:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px #0f1216 inset;
  caret-color: var(--text);
}

/* The native date and time picker icons render as dark glyphs, invisible on a
   dark field, so they are inverted to read as light. */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator { filter: invert(0.8); }
