:root {
  --bg: #0b0f14;
  --panel: #131a22;
  --panel-raised: #182029;
  --border: #263140;
  --text: #e6edf3;
  --text-dim: #8b96a3;
  --text-faint: #5b6673;
  --accent: #58a6ff;
  --live: #3fb950;
  --live-dim: #2a5d34;
  --alert: #f85149;
  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--panel), var(--bg));
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 8px var(--live);
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.brand h1 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
}

.topbar-right { display: flex; align-items: center; gap: 16px; }

.refresh-note {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}

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

.btn {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--panel-raised);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #05131f;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost { background: transparent; }

.btn-small { padding: 5px 10px; font-size: 12px; }

.btn-danger { color: var(--alert); }
.btn-danger:hover { border-color: var(--alert); }

/* ---------- Layout ---------- */

main { padding: 24px 28px 60px; max-width: 1400px; margin: 0 auto; }

.location-block { margin-bottom: 36px; }

.location-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.location-head h2 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.location-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-faint);
}

.camera-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-dim);
}
.empty-state p { margin-bottom: 16px; }

.location-empty {
  color: var(--text-faint);
  font-size: 13px;
  font-family: var(--font-mono);
  padding: 16px 0;
}

/* ---------- Camera tile ---------- */

.tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.tile:hover { border-color: var(--accent); transform: translateY(-1px); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tile-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #05080b;
  overflow: hidden;
}

.tile-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile-osd-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: linear-gradient(180deg, rgba(0,0,0,0.65), transparent);
  font-family: var(--font-mono);
  font-size: 11px;
  color: #d8dee6;
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.ok { background: var(--live); box-shadow: 0 0 5px var(--live); }
.status-dot.error { background: var(--alert); box-shadow: 0 0 5px var(--alert); }
.status-dot.unknown { background: var(--text-faint); }

.tile-osd-bottom {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  padding: 5px 8px;
  background: linear-gradient(0deg, rgba(0,0,0,0.65), transparent);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
}

.tile-name {
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
}

/* ---------- Modal / drawer shared ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 10, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.live-modal { max-width: 900px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-family: var(--font-display); font-weight: 600; font-size: 15px; }
.modal-subtitle { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); margin-top: 2px; }

.live-view-wrap {
  position: relative;
  background: #000;
  aspect-ratio: 16 / 9;
}
.live-view { width: 100%; height: 100%; object-fit: contain; display: block; }
.live-status {
  position: absolute;
  bottom: 10px; left: 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  background: rgba(0,0,0,0.5);
  padding: 3px 8px;
  border-radius: 4px;
}

/* ---------- Admin drawer ---------- */

.drawer {
  margin-left: auto;
  height: 100%;
  width: 420px;
  max-width: 100%;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.drawer-header h2 { font-family: var(--font-display); font-size: 16px; margin: 0; }

.drawer-body { padding: 20px; overflow-y: auto; flex: 1; }

.admin-section { margin-bottom: 28px; }
.admin-section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.admin-section-head h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); margin: 0; font-weight: 600; }

.admin-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }

.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.admin-row-main { min-width: 0; }
.admin-row-title { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-row-sub { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); }

.admin-row-actions { display: flex; gap: 4px; flex-shrink: 0; }

.admin-empty { color: var(--text-faint); font-size: 12px; font-family: var(--font-mono); padding: 10px 0; }

/* ---------- Forms ---------- */

.form { padding: 18px; display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; flex: 1; }
.field span { font-size: 12px; color: var(--text-dim); }
.field input, .field select {
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
}
.field input::placeholder { color: var(--text-faint); }

.field-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.field-grow { flex: 2; min-width: 180px; }

.field-checkbox { flex-direction: row; align-items: center; gap: 8px; }
.field-checkbox input { width: auto; }
.field-checkbox span { font-size: 12px; }

.form-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.form-footer-buttons { display: flex; justify-content: flex-end; gap: 8px; }

.test-result {
  font-family: var(--font-mono);
  font-size: 12px;
  min-height: 16px;
}
.test-result.ok { color: var(--live); }
.test-result.error { color: var(--alert); }
.test-result.pending { color: var(--text-dim); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .topbar { padding: 14px 16px; }
  main { padding: 16px 16px 40px; }
  .refresh-note { display: none; }
  .drawer { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .brand-dot { animation: none; }
  .tile { transition: none; }
}
