/*
 * The operator console.
 *
 * Dark, because it is used at night with a customer on the line; dense,
 * because the point is to see everything at once; monospace wherever there is
 * an identifier, because an operator reads ids aloud over the phone and
 * "BBVC-J3CN" must never be mistaken for "BBVC-J3CM".
 */
:root {
  --base: #090c12;
  --sunken: #0d1118;
  --surface: #111620;
  --raised: #171d29;
  --overlay: #1d2431;
  --hairline: #232b39;
  --divider: #1a2130;
  --ink: #eef1f6;
  --ink-2: #b7bfcc;
  --ink-3: #7f8a9c;
  --ink-4: #566173;
  --gold: #e8b45c;
  --gold-deep: #a9761f;
  --gold-wash: rgba(232, 180, 92, 0.12);
  --gold-edge: rgba(232, 180, 92, 0.45);
  --live: #e0473d;
  --live-wash: rgba(224, 71, 61, 0.14);
  --ok: #3fbf7f;
  --ok-wash: rgba(63, 191, 127, 0.14);
  --warn: #e8b45c;
  --sans: -apple-system, 'Inter', 'Segoe UI', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
  --nav: 232px;
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--base);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: '';
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(232, 180, 92, 0.07), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(63, 191, 127, 0.05), transparent 60%);
}
a { color: var(--gold); text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--ink); }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); font-size: 12.5px; letter-spacing: 0.02em; }
.muted { color: var(--ink-3); }
.dim { color: var(--ink-4); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ── gate ──────────────────────────────────────────────────────────────── */
.gate {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: var(--base);
}
.gate__card {
  width: min(380px, 92vw);
  padding: 36px 32px 28px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(232, 180, 92, 0.08);
  animation: gate-in 520ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes gate-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } }
.gate__mark { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.gate__mark img { width: 34px; height: 34px; }
.gate__mark strong { font-size: 18px; letter-spacing: -0.01em; }
.gate__mark span { display: block; font-size: 11px; letter-spacing: 0.18em; color: var(--ink-4); text-transform: uppercase; }
.gate label { display: block; font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 8px; }
.gate input {
  width: 100%; padding: 12px 14px;
  background: var(--sunken); border: 1px solid var(--hairline); border-radius: var(--radius);
  outline: none; transition: border-color 160ms;
  font-family: var(--mono);
}
.gate input:focus { border-color: var(--gold-edge); box-shadow: 0 0 0 3px var(--gold-wash); }
.gate .btn { width: 100%; margin-top: 16px; }
.gate__error { min-height: 20px; margin-top: 12px; color: var(--live); font-size: 13px; }
.gate__host { margin-top: 22px; font-size: 11px; color: var(--ink-4); text-align: center; }

/* ── shell ─────────────────────────────────────────────────────────────── */
.shell { position: relative; z-index: 1; display: grid; grid-template-columns: var(--nav) 1fr; min-height: 100vh; }
.nav {
  position: sticky; top: 0; height: 100vh;
  padding: 22px 16px;
  background: var(--sunken); border-right: 1px solid var(--hairline);
  display: flex; flex-direction: column; gap: 4px;
}
.nav__brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }
.nav__brand img { width: 26px; height: 26px; }
.nav__brand b { font-size: 15px; }
.nav__brand small { display: block; font-size: 10px; letter-spacing: 0.18em; color: var(--gold-deep); text-transform: uppercase; }
.nav__section { margin: 14px 8px 6px; font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-4); }
.nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 8px; color: var(--ink-2);
  transition: background 120ms, color 120ms;
}
.nav a:hover { background: var(--raised); color: var(--ink); }
.nav a.active { background: var(--gold-wash); color: var(--gold); }
.nav a .count { font-family: var(--mono); font-size: 11px; color: var(--ink-4); }
.nav a.active .count { color: var(--gold-deep); }
.nav__foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--hairline); font-size: 12px; color: var(--ink-4); }
.nav__foot button { display: block; width: 100%; margin-top: 8px; }

.main { padding: 26px 34px 60px; min-width: 0; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.topbar h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; font-weight: 650; }
.topbar .eyebrow { font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold-deep); margin-bottom: 4px; }
.topbar__tools { display: flex; gap: 8px; align-items: center; }

/* ── controls ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 8px;
  background: var(--raised); border: 1px solid var(--hairline); color: var(--ink);
  transition: background 120ms, border-color 120ms, transform 80ms;
}
.btn:hover { background: var(--overlay); border-color: #2e3848; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn--gold { background: var(--gold); border-color: var(--gold); color: #1a1206; font-weight: 600; }
.btn--gold:hover { background: #f0c26f; border-color: #f0c26f; }
.btn--danger { color: var(--live); border-color: rgba(224, 71, 61, 0.35); }
.btn--danger:hover { background: var(--live-wash); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--ink-3); }
.btn--ghost:hover { background: var(--raised); color: var(--ink); }
.btn--sm { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }

.field { display: flex; align-items: center; gap: 8px; }
.field input, .field select, textarea.input, input.input {
  padding: 8px 12px; background: var(--sunken); border: 1px solid var(--hairline); border-radius: 8px; outline: none;
  transition: border-color 160ms;
}
.field input:focus, .field select:focus, textarea.input:focus, input.input:focus { border-color: var(--gold-edge); box-shadow: 0 0 0 3px var(--gold-wash); }
.field input[type="search"] { width: 280px; }
.seg { display: inline-flex; background: var(--sunken); border: 1px solid var(--hairline); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { padding: 5px 11px; border: 0; background: transparent; border-radius: 6px; color: var(--ink-3); font-size: 12.5px; }
.seg button.active { background: var(--raised); color: var(--ink); }

/* ── cards & KPIs ──────────────────────────────────────────────────────── */
.grid { display: grid; gap: 14px; }
.grid--kpi { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid--2 { grid-template-columns: 1.6fr 1fr; }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1100px) { .grid--2, .grid--3 { grid-template-columns: 1fr; } }
.card {
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius);
  padding: 18px 20px;
}
.card h3 { margin: 0 0 12px; font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; }
.kpi { position: relative; overflow: hidden; }
.kpi .value { font-size: 30px; font-weight: 650; letter-spacing: -0.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .label { margin-top: 6px; color: var(--ink-3); font-size: 12.5px; }
.kpi--gold .value { color: var(--gold); }
.kpi--live .value { color: var(--live); }
.kpi--ok .value { color: var(--ok); }
.kpi::after { content: ''; position: absolute; right: -30px; top: -30px; width: 90px; height: 90px; border-radius: 50%; background: currentColor; opacity: 0.04; }
.stack { margin-top: 18px; }

/* ── tables ────────────────────────────────────────────────────────────── */
.tablewrap { overflow-x: auto; border: 1px solid var(--hairline); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 10px 14px; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-4); font-weight: 600; border-bottom: 1px solid var(--hairline); white-space: nowrap;
  background: var(--sunken); position: sticky; top: 0;
}
thead th.sortable { cursor: pointer; }
thead th.sortable:hover { color: var(--ink-2); }
thead th.sorted { color: var(--gold); }
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--divider); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.row--link { cursor: pointer; }
tbody tr.row--link:hover td { background: var(--raised); }
td.num { font-variant-numeric: tabular-nums; text-align: right; }
.empty { padding: 40px; text-align: center; color: var(--ink-4); }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; color: var(--ink-3); font-size: 12.5px; }
.pager .btns { display: flex; gap: 6px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; letter-spacing: 0.04em; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill--active { background: var(--ok-wash); color: var(--ok); }
.pill--expiring { background: var(--gold-wash); color: var(--gold); }
.pill--expired { background: var(--live-wash); color: var(--live); }
.pill--neutral { background: var(--raised); color: var(--ink-3); }
.pill--neutral::before { display: none; }
.kind { font-family: var(--mono); font-size: 11px; padding: 2px 7px; border-radius: 4px; background: var(--raised); color: var(--ink-2); text-transform: uppercase; }

/* ── drawer ────────────────────────────────────────────────────────────── */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 40; backdrop-filter: blur(2px); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 96vw); z-index: 41;
  background: var(--sunken); border-left: 1px solid var(--hairline);
  box-shadow: -30px 0 80px rgba(0, 0, 0, 0.5);
  overflow-y: auto; padding: 26px 30px 60px;
  animation: drawer-in 260ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes drawer-in { from { transform: translateX(40px); opacity: 0; } }
.drawer__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.drawer__head h2 { margin: 0; font-family: var(--mono); font-size: 22px; letter-spacing: 0.04em; }
.drawer__head .sub { color: var(--ink-3); margin-top: 4px; }
.drawer h3 { margin: 26px 0 10px; font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-3); }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.plist { display: grid; gap: 10px; }
.pcard { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 14px 16px; }
.pcard__head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.pcard__head b { font-size: 14px; }
.secret { display: inline-flex; align-items: center; gap: 8px; }
.secret code { font-family: var(--mono); font-size: 12px; background: var(--sunken); padding: 2px 7px; border-radius: 4px; color: var(--gold); }
.secret .masked { color: var(--ink-4); letter-spacing: 0.2em; }
.form { display: grid; gap: 10px; margin-top: 10px; }
.form label { display: grid; gap: 4px; font-size: 12px; color: var(--ink-3); }
.form input { padding: 8px 10px; background: var(--sunken); border: 1px solid var(--hairline); border-radius: 6px; outline: none; font-family: var(--mono); font-size: 12.5px; }
.form input:focus { border-color: var(--gold-edge); }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.keybox { margin-top: 10px; padding: 14px; background: var(--gold-wash); border: 1px solid var(--gold-edge); border-radius: var(--radius); }
.keybox code { font-family: var(--mono); font-size: 20px; letter-spacing: 0.12em; color: var(--gold); }

/* ── chart ─────────────────────────────────────────────────────────────── */
.chart { width: 100%; height: 160px; display: block; }
.chart .bar { fill: var(--gold); opacity: 0.85; }
.chart .bar--exp { fill: var(--live); opacity: 0.55; }
.chart .axis { stroke: var(--hairline); }
.chart text { fill: var(--ink-4); font-size: 10px; font-family: var(--mono); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--ink-3); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.legend .l-reg { background: var(--gold); }
.legend .l-exp { background: var(--live); opacity: 0.7; }

/* ── logs & misc ───────────────────────────────────────────────────────── */
pre.log {
  margin: 0; padding: 14px 16px; background: #05070b; border: 1px solid var(--hairline); border-radius: var(--radius);
  font-family: var(--mono); font-size: 12px; line-height: 1.55; color: var(--ink-2);
  max-height: 70vh; overflow: auto; white-space: pre-wrap; word-break: break-all;
}
.meter { height: 6px; background: var(--raised); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.meter i { display: block; height: 100%; background: var(--gold); border-radius: 3px; }
.meter i.hot { background: var(--live); }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 60;
  padding: 10px 16px; border-radius: 10px; background: var(--overlay); border: 1px solid var(--hairline);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5); font-size: 13px;
  animation: gate-in 200ms both;
}
.toast--error { border-color: rgba(224, 71, 61, 0.5); color: var(--live); }
.confirm { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; background: rgba(0, 0, 0, 0.6); }
.confirm__box { width: min(440px, 92vw); background: var(--surface); border: 1px solid var(--hairline); border-radius: 14px; padding: 24px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6); }
.confirm__box h4 { margin: 0 0 8px; font-size: 16px; }
.confirm__box p { margin: 0 0 18px; color: var(--ink-2); }
.confirm__box .actions { justify-content: flex-end; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--hairline); border-top-color: var(--gold); border-radius: 50%; animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--hairline); }
  .nav__section, .nav__foot, .nav__brand small { display: none; }
  .main { padding: 18px 16px 40px; }
}

/* Device events: the kind carries the colour, so a failure is found by eye. */
tbody tr.tone-bad td:nth-child(-n + 4) { color: var(--live); }
tbody tr.tone-warn td { color: var(--warn); }
tbody tr.tone-bad .dim, tbody tr.tone-warn .dim { color: inherit; opacity: 0.8; }
