:root {
  --bg: #0c0d10;
  --surface: #13151a;
  --surface-2: #191c22;
  --surface-hover: #20242c;
  --border: #252932;
  --border-strong: #343a47;
  --text: #e8eaef;
  --text-dim: #8c94a3;
  --text-muted: #5f6775;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

/* Top Navigation Bar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  min-height: 54px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

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

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  display: grid;
  place-items: center;
  color: var(--text);
}

.brand-title {
  display: flex;
  flex-direction: column;
}

.brand-title strong {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-title span {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--mono);
}

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}

.nav-tab {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  border-radius: 4px;
  transition: background 0.12s, color 0.12s;
}

.nav-tab:hover {
  color: var(--text);
}

.nav-tab.active {
  background: var(--surface-2);
  color: var(--text);
}

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

.telemetry-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 11.5px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

.status-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
  flex-shrink: 0;
}

.status-dot.ok {
  background: var(--ok);
}

.status-dot.err {
  background: var(--err);
}

.status-text.ok {
  color: var(--text);
}

.status-text.warn {
  color: var(--warn);
}

.status-text.err {
  color: var(--err);
}

.divider-v {
  width: 1px;
  height: 12px;
  background: var(--border);
}

.quick-select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 12px;
  font-family: var(--mono);
  cursor: pointer;
}

.quick-select:focus {
  outline: none;
  border-color: var(--accent);
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-tag {
  font-size: 12px;
  color: var(--text-dim);
}

/* Alert Strip */
.alert-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 20px;
  background: #2a1215;
  border-bottom: 1px solid #7f1d1d;
  color: #fecaca;
  font-size: 12.5px;
  font-weight: 600;
}

.alert-banner-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  transition: background 0.12s, border-color 0.12s;
}

.btn:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: #454d5e;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-2);
}

.btn-danger {
  background: transparent;
  border-color: #5c2125;
  color: #fca5a5;
}

.btn-danger:hover:not(:disabled) {
  background: #2b1416;
  border-color: #991b1b;
}

.btn-sm {
  padding: 4px 8px;
  font-size: 11.5px;
}

/* Main Monitor Layout */
.monitor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  padding: 16px 20px 24px;
  max-width: 1520px;
  margin: 0 auto;
}

@media (max-width: 1080px) {
  .monitor-layout {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

.panel-sub {
  font-size: 11.5px;
  color: var(--text-dim);
  font-family: var(--mono);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.video-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #060709;
}

.video-stage img,
.video-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.video-stage canvas {
  z-index: 2;
}

.video-stage.drawing canvas {
  cursor: crosshair;
}

.draw-hint,
.stream-overlay {
  position: absolute;
  z-index: 3;
  left: 14px;
  right: 14px;
  padding: 8px 12px;
  border-radius: 4px;
  background: rgba(12, 13, 16, 0.9);
  border: 1px solid var(--border-strong);
  font-size: 12px;
  text-align: center;
}

.draw-hint {
  bottom: 14px;
  border-color: var(--accent);
}

.stream-overlay {
  top: 50%;
  transform: translateY(-50%);
  max-width: 440px;
  margin: 0 auto;
  border-color: var(--warn);
}

/* Controls Strip */
.controls-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.control-cell {
  padding: 11px 14px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-cell:last-child {
  border-right: none;
}

.control-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}

.control-check input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  margin: 0;
}

.control-desc {
  font-size: 11.5px;
  color: var(--text-dim);
}

.range-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  font-weight: 500;
}

.range-header span:last-child {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-dim);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Events Sidebar */
.events-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 96px);
}

.events-list {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex: 1;
}

.event-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.event-row:hover {
  background: var(--surface-2);
}

.event-row img {
  width: 92px;
  height: 54px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: #060709;
}

.event-meta {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 0;
}

.event-meta strong {
  font-size: 12.5px;
  color: var(--text);
  font-weight: 600;
}

.event-meta span {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.empty-state {
  color: var(--text-muted);
  font-size: 12.5px;
  text-align: center;
  padding: 36px 16px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(6, 7, 9, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  max-width: 840px;
  width: 100%;
  overflow: hidden;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  font-weight: 600;
}

.modal-card img {
  width: 100%;
  display: block;
  background: #060709;
}

/* Admin Layout & Forms */
.admin-container {
  max-width: 1220px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

@media (max-width: 960px) {
  .admin-container {
    grid-template-columns: 1fr;
  }
}

.panel-body {
  padding: 16px;
}

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

@media (max-width: 600px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
}

.input,
.select {
  width: 100%;
  padding: 7px 10px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

.input.mono {
  font-family: var(--mono);
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
}

.field-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.feedback {
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 5px;
  border: 1px solid var(--border);
  margin-top: 12px;
}

.feedback.ok {
  background: #0d2318;
  border-color: #166534;
  color: #bbf7d0;
}

.feedback.err {
  background: #2b1416;
  border-color: #991b1b;
  color: #fecaca;
}

/* Camera Table */
.camera-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.camera-table th,
.camera-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}

.camera-table th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.tag {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-family: var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.tag.active {
  background: #0d2318;
  border-color: #166534;
  color: #86efac;
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* Login Page */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 24px;
}

.login-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.login-head h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.login-head p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-submit {
  width: 100%;
  padding: 9px 12px;
  margin-top: 4px;
}

.hidden {
  display: none !important;
}
