/* Fleet dashboard — one small design system, no build step.
   Dark by default (a wall of camera tiles reads best on dark). */

:root {
  --bg: #0f1116;
  --bg-2: #14171e;
  --panel: #1a1e27;
  --panel-2: #20252f;
  --line: #2a303c;
  --line-2: #364050;
  --text: #e8eaf0;
  --text-2: #c3c8d4;
  --muted: #8a93a6;
  --ok: #3fb950;
  --ok-bg: rgba(63, 185, 80, .14);
  --warn: #d9a531;
  --warn-bg: rgba(217, 165, 49, .14);
  --bad: #f4655b;
  --bad-bg: rgba(244, 101, 91, .14);
  --accent: #5aa7ff;
  --accent-2: #3b82f6;
  --accent-bg: rgba(90, 167, 255, .14);
  --radius: 10px;
  --radius-s: 7px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 8px 24px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
b, strong { font-weight: 600; color: var(--text); }
code, .mono { font-family: var(--mono); font-size: .93em; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
p { margin: 0 0 10px; }
p.muted { color: var(--muted); }
p.lead { color: var(--text-2); font-size: 15px; max-width: 72ch; }

/* ---- header / navigation ------------------------------------------------ */

header.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  height: 52px;
  background: rgba(20, 23, 30, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
header.top .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -.01em;
}
header.top .brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
header.top nav { display: flex; gap: 2px; margin-left: 6px; }
header.top nav a {
  padding: 6px 11px;
  border-radius: var(--radius-s);
  color: var(--text-2);
  font-weight: 500;
}
header.top nav a:hover { background: var(--panel-2); text-decoration: none; color: var(--text); }
header.top nav a.active { background: var(--accent-bg); color: var(--accent); }
header.top .spacer { flex: 1; }
header.top .crumb { color: var(--muted); }
header.top .crumb b { color: var(--text); }
header.top .keybox { display: flex; align-items: center; gap: 6px; }
header.top .keybox input { width: 220px; }
#status { color: var(--muted); font-size: 12px; }
#status.error { color: var(--bad); }
#status.ok { color: var(--ok); }

/* what the server thinks of the key */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  border: 1px solid var(--line-2); color: var(--text-2); background: var(--panel);
}
.chip::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.chip.ok { border-color: rgba(63, 185, 80, .4); color: var(--ok); background: var(--ok-bg); }
.chip.ok::before { background: var(--ok); }
.chip.warn { border-color: rgba(217, 165, 49, .4); color: var(--warn); background: var(--warn-bg); }
.chip.warn::before { background: var(--warn); }
.chip.bad { border-color: rgba(244, 101, 91, .4); color: var(--bad); background: var(--bad-bg); }
.chip.bad::before { background: var(--bad); }

/* ---- layout -------------------------------------------------------------- */

main { padding: 20px 18px 60px; max-width: 1400px; margin: 0 auto; }
main.narrow { max-width: 1100px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.cols { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: start; }
.cols > .panel { margin: 0; min-width: 0; }

/* ---- panels -------------------------------------------------------------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.panel > h2 {
  font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em;
  margin: 0 0 10px; display: flex; align-items: center; gap: 8px;
}
.panel > h2 .count { color: var(--text-2); background: var(--panel-2); border-radius: 999px; padding: 0 7px; font-size: 11px; }
.panel .hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; max-width: 80ch; }

details.panel summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-weight: 600;
}
details.panel summary::-webkit-details-marker { display: none; }
details.panel summary::before { content: '▸'; color: var(--muted); transition: transform .15s; }
details.panel[open] summary::before { transform: rotate(90deg); }
details.panel[open] summary { margin-bottom: 12px; }
details > summary { cursor: pointer; }

/* ---- forms --------------------------------------------------------------- */

button, select, input, textarea {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-s);
  padding: 7px 10px;
  font: inherit;
  line-height: 1.3;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
input[type="checkbox"] { padding: 0; width: 15px; height: 15px; vertical-align: -2px; accent-color: var(--accent); }
textarea { width: 100%; min-height: 120px; font-family: var(--mono); font-size: 13px; }

button { cursor: pointer; font-weight: 500; white-space: nowrap; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent-2); color: #fff; border-color: var(--accent-2); font-weight: 600; }
button.primary:hover { background: var(--accent); border-color: var(--accent); }
button.ghost { background: transparent; }
button.small { padding: 3px 8px; font-size: 12px; }
button.danger { color: var(--bad); }
button.danger:hover { border-color: var(--bad); background: var(--bad-bg); }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row + .row { margin-top: 8px; }
.row > input, .row > select, .row > textarea, .row > .field { min-width: 0; max-width: 100%; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > input, .field > select { width: 100%; }
.field > span { font-size: 12px; color: var(--muted); }
.field.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text-2); }
label.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }

.status { font-size: 13px; }
.muted { color: var(--muted); }
.error { color: var(--bad); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.empty { color: var(--muted); padding: 22px; text-align: center; }

/* ---- tables -------------------------------------------------------------- */

.table-wrap { overflow-x: auto; max-width: 100%; }
.panel { min-width: 0; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255, 255, 255, .02); }
td.mono { font-family: var(--mono); font-size: 12.5px; }
td.actions { white-space: nowrap; text-align: right; }
tr.muted td { color: var(--muted); }
td .id { display: inline-flex; align-items: center; gap: 6px; }

/* ---- pills --------------------------------------------------------------- */

.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
}
.pill.streaming, .pill.live, .pill.viewer { background: var(--ok-bg); color: var(--ok); }
.pill.retrying, .pill.operator { background: var(--warn-bg); color: var(--warn); }
.pill.offline, .pill.dark, .pill.revoked { background: var(--bad-bg); color: var(--bad); }
.pill.unknown, .pill.env { background: rgba(138, 147, 166, .18); color: var(--muted); }
.pill.admin { background: rgba(139, 92, 246, .18); color: #b79cff; }
.pill.site { background: var(--accent-bg); color: var(--accent); text-transform: none; letter-spacing: 0; }

/* ---- camera grid --------------------------------------------------------- */

#grid { display: grid; gap: 12px; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); }

.tile {
  position: relative; border: 2px solid var(--line); border-radius: var(--radius);
  overflow: hidden; background: #000; aspect-ratio: 16 / 9; cursor: pointer;
  transition: border-color .2s;
}
.tile.live { border-color: var(--ok); }
.tile.dark { border-color: var(--bad); }
.tile:hover { border-color: var(--accent); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.tile img.poster { width: 100%; height: 100%; object-fit: cover; display: block; opacity: .75; }
.tile .nomedia { width: 100%; height: 100%; background: repeating-linear-gradient(135deg, #0b0d12 0 12px, #10131a 12px 24px); }
.tile .overlay {
  position: absolute; inset: auto 0 0 0; padding: 8px 10px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .85));
  display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: 12px; pointer-events: none;
}
.tile .name { font-weight: 600; margin-right: auto; }
.stat { color: var(--text-2); }

.player { width: 100%; aspect-ratio: 16 / 9; border: 1px solid var(--line); border-radius: var(--radius); background: #000; overflow: hidden; }
.player video { width: 100%; height: 100%; max-height: 70vh; background: #000; display: block; }

/* ---- code ---------------------------------------------------------------- */

pre.code, pre.mono {
  position: relative; white-space: pre-wrap; word-break: break-word;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: 12px 14px; margin: 8px 0 12px; font-family: var(--mono); font-size: 12.5px; line-height: 1.5; color: var(--text-2);
}
pre.code .copy { position: absolute; top: 8px; right: 8px; }
.url { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.url .mono { overflow-wrap: anywhere; min-width: 0; }

/* one-time secret reveal */
.reveal {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--warn-bg); border: 1px solid rgba(217, 165, 49, .45); border-radius: var(--radius-s);
  padding: 10px 12px; margin: 10px 0;
}
.reveal .mono { font-size: 13px; overflow-wrap: anywhere; color: var(--text); }
.reveal .note { color: var(--warn); font-size: 12px; width: 100%; }

/* ---- quick-start steps --------------------------------------------------- */

.steps { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-bottom: 16px; }
.step { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.step .n { display: inline-flex; width: 24px; height: 24px; align-items: center; justify-content: center; border-radius: 50%; background: var(--accent-bg); color: var(--accent); font-weight: 700; font-size: 12px; margin-bottom: 8px; }
.step h3 { font-size: 14px; margin-bottom: 4px; }
.step p { color: var(--muted); font-size: 13px; margin: 0; }
.step a { font-weight: 500; }

/* tabs for the samples */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 8px; flex-wrap: wrap; }
.tabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); padding: 8px 10px; }
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab { display: none; }
.tab.active { display: block; }

/* endpoint reference */
.endpoints { display: grid; gap: 8px; }
.endpoint { display: grid; grid-template-columns: 70px 1fr; gap: 6px 12px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); }
.endpoint:last-child { border-bottom: 0; }
.endpoint .method { font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--accent); }
.endpoint .method.post { color: var(--ok); }
.endpoint .path { font-family: var(--mono); font-size: 13px; }
.endpoint .desc { grid-column: 2; color: var(--muted); font-size: 13px; }

/* ---- device page imaging (phones) --------------------------------------- */

.imaging { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(200px, 320px); gap: 16px; align-items: start; }
.imaging .controls { display: grid; gap: 10px; }
.imaging label { display: grid; grid-template-columns: 92px auto; gap: 6px 10px; align-items: center; color: var(--muted); font-size: 12px; }
.imaging label input[type="range"] { grid-column: 1 / -1; width: 100%; }
.imaging label.check { grid-template-columns: auto auto; justify-content: start; }
.imaging output { color: var(--text); }
.imaging .snapshot { margin: 0; }
.imaging .snapshot img { width: 100%; border-radius: 8px; border: 1px solid var(--line); display: block; background: #000; }
.imaging figcaption { font-size: 12px; margin-top: 6px; }
#events { max-height: 60vh; overflow: auto; }

/* ---- operator sign-in (the gate) ---------------------------------------- */

body.gated header.top nav, body.gated header.top .crumb, body.gated header.top #pill, body.gated header.top #status, body.gated #signout, body.gated #whoami { display: none; }
#login {
  position: fixed; inset: 0; z-index: 4;
  display: flex; align-items: center; justify-content: center; padding: 76px 20px 24px;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(90, 167, 255, .10), transparent 60%), var(--bg);
}
.login-card {
  width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 26px 26px 22px; box-shadow: var(--shadow); display: grid; gap: 12px;
}
.login-card .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; }
.login-card .brand .dot { width: 10px; height: 10px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), #8b5cf6); box-shadow: 0 0 0 3px var(--accent-bg); }
.login-card h1 { font-size: 20px; }
.login-card p { color: var(--muted); margin: 0; font-size: 13px; }
.login-card input { width: 100%; font-family: var(--mono); }
.login-card button { padding: 9px 12px; }
.login-card .status { margin-top: -4px; }

/* ---- toasts -------------------------------------------------------------- */

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 20; }
.toast {
  padding: 10px 14px; border-radius: var(--radius-s); background: var(--panel-2); border: 1px solid var(--line-2);
  color: var(--text); font-size: 13px; box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; max-width: 380px;
}
.toast.show { opacity: 1; transform: none; }
.toast.ok { border-color: rgba(63, 185, 80, .5); }
.toast.error { border-color: rgba(244, 101, 91, .5); }

/* ---- responsive ---------------------------------------------------------- */

@media (max-width: 900px) {
  /* Header: brand + identity on the first row, navigation on its own
     scrollable row underneath. */
  header.top { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 6px 10px; }
  header.top nav {
    order: 10; flex: 1 1 100%; margin: 2px -12px -8px; padding: 0 12px 8px;
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  header.top nav::-webkit-scrollbar { display: none; }
  header.top nav a { flex: 0 0 auto; }
  header.top .crumb { order: 11; flex: 1 1 100%; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  header.top #pill { order: 12; }
  #status { display: none; }
  main { padding: 14px 12px 60px; }
  .page-head { margin-bottom: 14px; }
  .page-head h1 { font-size: 19px; }
  .page-head .field { flex-direction: row; align-items: center; gap: 8px; }
  .panel { padding: 14px 12px; }
  .imaging { grid-template-columns: 1fr; }
  #grid { grid-template-columns: 1fr; }
  #login { align-items: flex-start; padding-top: 96px; }
  .login-card { padding: 20px 18px 18px; }
}

@media (max-width: 640px) {
  /* Forms stack: every control takes the full row; buttons share a row. */
  .row > input, .row > select, .row > textarea, .row > .field { flex: 1 1 100%; width: 100%; }
  .row > button { flex: 1 1 auto; }
  .row > label.check { flex: 1 1 100%; }
  .cols { grid-template-columns: 1fr; }
  .steps { grid-template-columns: 1fr; gap: 8px; }
  .step { padding: 12px 14px; }
  table { font-size: 12.5px; }
  th, td { padding: 6px 8px; }
  pre.code, pre.mono { font-size: 12px; padding: 10px 12px; }
  .endpoint { grid-template-columns: 1fr; gap: 2px; }
  .endpoint .desc { grid-column: 1; }
  .tile .overlay { font-size: 11px; padding: 6px 8px; }
}
