:root {
  color-scheme: light;
  --ink: #111;
  --muted: #62666d;
  --line: #d8dce2;
  --surface: #f6f7f9;
  --accent: #1457d9;
  --danger: #a60018;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 224px 1fr;
  background: white;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.auth-pending > .rail,
body.auth-pending > main { visibility: hidden; }

.hidden { display: none !important; }

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  grid-template-columns: minmax(220px, 34vw) minmax(360px, 520px) 1fr;
  align-items: center;
  background: #fff;
}

.auth-screen.authenticated { display: none; }
.auth-brand {
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: #0b0c0f;
  color: #fff;
  font-size: 20px;
}
.auth-brand img { width: 70px; height: 70px; object-fit: contain; filter: invert(1) contrast(1.4); }
.auth-form { padding: 48px 56px; display: grid; gap: 18px; }
.auth-form h1 { font-size: 28px; }
.auth-form input,
form input:not([type="checkbox"]):not([type="range"]) {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
.auth-form button { min-height: 40px; border: 0; border-radius: 4px; background: #111; color: #fff; cursor: pointer; }
.auth-form button.secondary { border: 1px solid var(--line); background: #fff; color: var(--ink); }
.auth-error { grid-column: 2; align-self: start; padding: 0 56px; color: var(--danger); min-height: 20px; }
.totp-qr { width: 240px; height: 240px; image-rendering: pixelated; }
.manual-key { max-width: 320px; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.rail {
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  background: #0b0c0f;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.rail { display: flex; flex-direction: column; }
.rail nav { flex: 1; }
.rail-action { border: 0; background: transparent; color: #9da3ad; text-align: left; padding: 10px; cursor: pointer; }

.rail img {
  display: block;
  width: 74px;
  height: 74px;
  object-fit: contain;
  filter: invert(1) contrast(1.4);
  margin: 0 0 32px;
}

nav { display: grid; gap: 4px; }
button, select {
  font: inherit;
}

nav button {
  height: 38px;
  border: 0;
  border-left: 3px solid transparent;
  text-align: left;
  padding: 0 10px;
  background: transparent;
  color: #c9cdd4;
  cursor: pointer;
}

nav button.active {
  border-left-color: white;
  color: white;
  background: #171a20;
}

main { padding: 28px 34px; min-width: 0; }
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 30px; font-weight: 650; }
h2 { font-size: 18px; font-weight: 650; margin: 28px 0 12px; }

.status {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
}

#healthDot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #d49b00;
}

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

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 28px;
  border-bottom: 1px solid var(--line);
}
.chart-grid section { min-width: 0; padding-bottom: 22px; }
.chart-grid canvas { display: block; width: 100%; height: 180px; }

.metrics div {
  padding: 24px 20px 22px 0;
}

.metrics strong {
  display: block;
  font-size: 34px;
  font-weight: 620;
}

.metrics span, .muted {
  color: var(--muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px 12px 0;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
}

form {
  max-width: 720px;
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

select {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: white;
  color: var(--ink);
  padding: 0 10px;
}

#locationMap {
  width: 100%;
  height: min(62vh, 620px);
  min-height: 420px;
  border: 1px solid var(--line);
}
.map-timeline { display: grid; grid-template-columns: minmax(200px, 1fr) minmax(240px, auto); gap: 24px; align-items: center; margin-top: 18px; }
.map-timeline input { width: 100%; }
.map-timeline div { display: grid; gap: 3px; }
.map-timeline span { color: var(--muted); font-size: 13px; }
.camera-toolbar { display: flex; gap: 10px; align-items: center; margin: 18px 0; }
.camera-stage { position: relative; min-height: 380px; background: #111; display: grid; place-items: center; overflow: hidden; }
.camera-stage img { display: none; width: 100%; height: min(62vh, 660px); object-fit: contain; }
.camera-stage img.active { display: block; }
.camera-stage p { color: #c8cbd0; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

form button, .action {
  width: fit-content;
  min-height: 36px;
  border: 1px solid #111;
  border-radius: 4px;
  background: #111;
  color: white;
  padding: 0 13px;
  cursor: pointer;
}

.action:disabled {
  border-color: var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: not-allowed;
}
.secondary-action { background: #fff; color: #111; }

.danger { color: var(--danger); font-weight: 650; }
pre {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 14px;
  overflow: auto;
}

@media (max-width: 760px) {
  body { grid-template-columns: 1fr; }
  .rail {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 10px 12px;
  }
  .rail img { width: 40px; height: 40px; margin: 0; }
  nav { display: flex; overflow-x: auto; }
  nav button { white-space: nowrap; }
  main { padding: 20px 16px; }
  header { align-items: flex-start; flex-direction: column; }
  .metrics { grid-template-columns: 1fr; }
  .chart-grid { grid-template-columns: 1fr; }
  .auth-screen { grid-template-columns: 1fr; align-content: start; overflow: auto; }
  .auth-brand { align-self: auto; min-height: 120px; }
  .auth-form { padding: 32px 24px; }
  .auth-error { grid-column: 1; padding: 0 24px 30px; }
  .map-timeline { grid-template-columns: 1fr; }
}
