/* ---------- Tokens (light) ---------- */
:root {
  --bg: #fbfbfc;
  --bg-sidebar: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --surface-3: #e8eaed;
  --border: rgba(15, 17, 22, 0.07);
  --border-strong: rgba(15, 17, 22, 0.12);

  --text: #1a1d21;
  --text-2: #4a4f55;
  --text-muted: #6e7178;
  --text-faint: #9da0a6;

  --accent: #5e6ad2;
  --accent-hover: #4f5bc4;
  --accent-faint: rgba(94, 106, 210, 0.10);
  --accent-soft: rgba(94, 106, 210, 0.06);

  --danger: #c93636;
  --danger-faint: rgba(201, 54, 54, 0.08);
  --success: #2f8e5a;
  --success-faint: rgba(47, 142, 90, 0.10);

  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 8px;

  --sidebar-w: 240px;
  --topbar-h: 88px;

  --shadow-card: 0 1px 0 rgba(15,17,22,.03), 0 1px 2px rgba(15,17,22,.04);
  --shadow-pop: 0 1px 2px rgba(15,17,22,.06), 0 8px 24px rgba(15,17,22,.06);

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

@supports (font-variation-settings: normal) {
  :root { --font-sans: "Inter var", -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  font-feature-settings: "cv11", "ss01", "ss03";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

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

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 16px;
}
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  background: linear-gradient(135deg, #5e6ad2 0%, #8e54e9 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.brand-name { font-size: 13px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav button {
  all: unset;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius);
  color: var(--text-2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 80ms ease, color 80ms ease;
}
.nav button .icon { color: var(--text-muted); flex: 0 0 auto; }
.nav button:hover { background: rgba(15,17,22,.045); color: var(--text); }
.nav button:hover .icon { color: var(--text-2); }
.nav button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border), 0 1px 1px rgba(15,17,22,.04);
}
.nav button.active .icon { color: var(--accent); }
.nav button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.sidebar-footer {
  margin-top: auto;
  padding: 10px 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kv { display: flex; flex-direction: column; gap: 2px; }
.kv-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}
.kv code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-2);
  background: transparent;
  padding: 0;
  word-break: break-all;
}
.link {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
}
.link:hover { color: var(--text); }

/* ---------- Main ---------- */

main {
  min-width: 0;
  padding: 28px 32px 48px;
}

.tab { display: none; }
.tab.active { display: block; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.page-head h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
  color: var(--text);
}
.page-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.toolbar .spacer { flex: 1; }
.toolbar .counter {
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.toolbar .status {
  color: var(--text-muted);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
}
.toolbar .status.ok { color: var(--success); background: var(--success-faint); }
.toolbar .status.err { color: var(--danger); background: var(--danger-faint); }

.select-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Buttons ---------- */

button {
  appearance: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 0 12px;
  height: 28px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  box-shadow: 0 1px 1px rgba(15,17,22,.03);
  transition: background 80ms ease, color 80ms ease, border-color 80ms ease, box-shadow 80ms ease;
}
button:hover { background: var(--surface-2); border-color: var(--border-strong); }
button:active { background: var(--surface-3); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 1px 2px rgba(94,106,210,.25), inset 0 1px 0 rgba(255,255,255,.18);
}
button.primary:hover { background: var(--accent-hover); color: #fff; }

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  box-shadow: none;
}
button.ghost:hover { background: rgba(15,17,22,.05); color: var(--text); }

button.danger {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  box-shadow: none;
}
button.danger:hover { background: var(--danger-faint); color: var(--danger); border-color: transparent; }

/* ---------- Inputs ---------- */

input[type="text"],
input[type="number"],
textarea,
select {
  appearance: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 12.5px;
  font-family: inherit;
  height: 28px;
  outline: none;
  transition: border-color 80ms ease, box-shadow 80ms ease;
}
input[type="number"] { width: 72px; text-align: right; font-variant-numeric: tabular-nums; }
textarea {
  width: 100%;
  height: auto;
  min-height: 64px;
  resize: vertical;
  padding: 8px 10px;
  line-height: 1.5;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-faint);
}
select { padding-right: 28px; background-image:
  linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
  linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 12px, calc(100% - 9px) 12px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

/* ---------- Card / Tables ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

table { width: 100%; border-collapse: collapse; }
thead th {
  background: transparent;
  color: var(--text-faint);
  font-weight: 500;
  text-align: left;
  padding: 9px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}
thead th.num { text-align: right; }
tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); color: var(--text); }
tbody td.num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-muted); }

tbody td code {
  font-family: var(--font-mono);
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  color: var(--text);
  border: 1px solid var(--border);
}

.kv code, code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}
.sidebar-footer .kv code {
  background: transparent;
  border: none;
  padding: 0;
  font-size: 11px;
  color: var(--text-muted);
}

/* row actions: hide-until-hover style */
tbody td .row-actions { display: inline-flex; gap: 4px; opacity: 0; transition: opacity 80ms ease; }
tbody tr:hover .row-actions, tbody tr:focus-within .row-actions { opacity: 1; }

/* ---------- Type cards (Scenario editor) ---------- */

.type-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  margin-bottom: 12px;
  overflow: hidden;
  transition: border-color 80ms ease;
}
.type-card:hover { border-color: var(--border-strong); }

.type-card > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
}
.type-card > summary::-webkit-details-marker { display: none; }
.type-card > summary::before {
  content: "›";
  display: inline-block;
  width: 14px;
  color: var(--text-muted);
  transition: transform 120ms ease;
  font-size: 16px;
  line-height: 1;
}
.type-card[open] > summary::before { transform: rotate(90deg); }
.type-card .summary { color: var(--text-muted); font-size: 12px; font-weight: 400; margin-left: auto; }

.type-card[open] > summary { border-bottom: 1px solid var(--border); margin-bottom: 0; }
.type-card[open] > :not(summary) {
  padding-left: 16px;
  padding-right: 16px;
}
.type-card[open] > .row:first-of-type { padding-top: 14px; }
.type-card[open] > .type-actions { padding-bottom: 16px; padding-top: 4px; }
.type-card[open] > .steps { padding-bottom: 4px; }

.type-card .row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}
.type-card .row label {
  color: var(--text-faint);
  min-width: 110px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}
.type-card .row input[type="text"],
.type-card .row textarea { flex: 1; }
.type-card .row input[type="checkbox"] { accent-color: var(--accent); }

.step {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-top: 10px;
}
.step-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.step-head strong {
  color: var(--accent);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.phases table { background: transparent; }
.phases thead th { background: transparent; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.phases tbody td { border-bottom: 1px solid var(--border); padding: 6px 8px; }
.phases tbody tr:hover td { background: transparent; }
.phases select { padding: 4px 24px 4px 8px; height: 26px; }
.phases input[type="number"] { height: 26px; }

.type-actions, .step-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

/* ---------- Status pills (utility) ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border-strong);
}
.pill.accent { background: var(--accent-faint); color: var(--accent-hover); border-color: transparent; }
.pill.success { background: var(--success-faint); color: var(--success); border-color: transparent; }
.pill.danger { background: var(--danger-faint); color: var(--danger); border-color: transparent; }

/* ---------- Headset live tiles ---------- */
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin: 8px 0 12px;
  letter-spacing: -0.005em;
}
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.tile-empty {
  grid-column: 1 / -1;
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 100ms ease, transform 100ms ease;
}
.tile:hover { border-color: var(--border-strong); }
.tile-head {
  display: flex; align-items: center; gap: 10px;
}
.tile-id {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.tile .spacer { flex: 1; }
.tile-sensor { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }
.tile-user { font-size: 13px; font-weight: 500; color: var(--text); min-height: 18px; }
.tile-meta { font-size: 12px; color: var(--text-muted); min-height: 16px; }
.tile-actions { display: flex; gap: 6px; margin-top: 4px; }
.tile-actions button { height: 30px; flex: 1; }

.tile.offline { opacity: 0.55; }
.tile.in-session { border-color: rgba(94,106,210,.28); }
.tile.orphan { border-color: rgba(217,72,72,.45); background: #fffafa; }
.dot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; }
.dot-green { background: var(--success); box-shadow: 0 0 0 3px rgba(47,142,90,.15); }
.dot-grey  { background: #b5b8be; }
.dot-indigo { background: var(--accent); box-shadow: 0 0 0 3px rgba(94,106,210,.15); }
.dot-red    { background: var(--danger); box-shadow: 0 0 0 3px rgba(217,72,72,.18); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 17, 22, 0.45);
  display: none;
  align-items: center; justify-content: center;
  z-index: 100;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  width: 440px;
  max-width: calc(100vw - 32px);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.modal .sub { margin: 0; color: var(--text-muted); font-size: 12.5px; }
.modal .form-grid { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; align-items: center; }
.modal label { color: var(--text-muted); font-size: 12px; font-weight: 500; }
.modal input { width: 100%; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.modal .error { color: var(--danger); font-size: 12.5px; min-height: 1.2em; }

/* ---------- Footer (legacy hook, kept in case JS needs it) ---------- */
footer { display: none; }

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(15,17,22,.12); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: rgba(15,17,22,.20); }

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
  body { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 8px 12px;
    gap: 4px;
  }
  .sidebar-footer, .brand .brand-text { display: none; }
  .nav { flex-direction: row; flex: 1; overflow-x: auto; }
  .nav button { padding: 6px 10px; }
  .nav button span { display: none; }
  main { padding: 16px; }
  .page-head { flex-direction: column; align-items: stretch; }
}
