/* =================================================================
   Ported from Tk Theme (cctv_incident_detector.py)
   Dark navy / cyan accent
   ================================================================= */
:root {
  --bg-base:    #0a0e1a;
  --bg-surface: #111827;
  --bg-raised:  #1a2332;
  --bg-input:   #0d1320;
  --bg-sidebar: #0e1422;
  --border:     #1f2937;
  --border-active: #374151;
  --text-primary:   #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted:     #6b7280;
  --accent:       #06b6d4;
  --accent-hover: #0891b2;
  --accent-glow:  #22d3ee;
  --success: #10b981;
  --warning: #f59e0b;
  --danger:  #ef4444;
  --info:    #3b82f6;
  --purple:  #a855f7;
}

html, body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  min-height: 100vh;
  margin: 0;
}

/* Bootstrap dark overrides */
[data-bs-theme="dark"] {
  --bs-body-bg: var(--bg-base);
  --bs-body-color: var(--text-primary);
  --bs-border-color: var(--border);
  --bs-primary: var(--accent);
  --bs-secondary: #475569;
  --bs-success: var(--success);
  --bs-warning: var(--warning);
  --bs-danger: var(--danger);
  --bs-info: var(--info);
}

/* =================================================================
   Layout — sidebar + content
   ================================================================= */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: 240px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 18px 0;
  z-index: 10;
}
.sidebar-brand {
  font-size: 1.1rem; font-weight: 700; letter-spacing: .02em;
  color: var(--accent-glow);
  padding: 0 20px 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-nav {
  list-style: none; padding: 14px 0; margin: 0; flex: 1;
}
.sidebar-nav li a {
  display: block; padding: 11px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background .15s, border-color .15s, color .15s;
}
.sidebar-nav li a i { width: 18px; display: inline-block; text-align: center; }
.sidebar-nav li a:hover {
  background: var(--bg-raised); color: var(--text-primary);
}
.sidebar-nav li a.active {
  background: var(--bg-raised);
  color: var(--accent-glow);
  border-left-color: var(--accent);
}
.sidebar-status {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  font-size: .8rem;
  color: var(--text-muted);
}
.status-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; background: var(--text-muted);
  margin-right: 6px; vertical-align: middle;
}
.status-dot.online  { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.offline { background: var(--text-muted); }
.status-dot.error   { background: var(--danger); }

.content { margin-left: 240px; padding: 24px 28px; min-height: 100vh; }

/* =================================================================
   Typography / page header
   ================================================================= */
.page-header h1 {
  font-size: 1.6rem; font-weight: 700; margin: 0;
  color: var(--text-primary);
}
.page-header { padding-bottom: 8px; border-bottom: 1px solid var(--border); }

/* =================================================================
   Cards (surfaces)
   ================================================================= */
.card.surface {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.card.surface .card-header {
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  font-weight: 600;
}
.card.surface .card-body { color: var(--text-primary); }

/* Inputs */
.form-control, .form-select {
  background: var(--bg-input); color: var(--text-primary);
  border: 1px solid var(--border);
}
.form-control:focus, .form-select:focus {
  background: var(--bg-input); color: var(--text-primary);
  border-color: var(--accent);
  box-shadow: 0 0 0 .15rem rgba(6,182,212,.2);
}
.form-check-input { background-color: var(--bg-input); border-color: var(--border-active); }
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }

/* Tabs */
.nav-tabs .nav-link {
  color: var(--text-secondary); border-color: transparent;
  background: transparent;
}
.nav-tabs .nav-link.active {
  background: var(--bg-raised); color: var(--accent-glow);
  border-color: var(--border) var(--border) var(--bg-raised);
}

/* Buttons */
.btn-primary {
  background: var(--accent); border-color: var(--accent);
}
.btn-primary:hover, .btn-primary:focus {
  background: var(--accent-hover); border-color: var(--accent-hover);
}
.btn-outline-light { color: var(--text-primary); border-color: var(--border-active); }
.btn-outline-light:hover { background: var(--bg-raised); color: var(--accent-glow); }

/* =================================================================
   Video panes
   ================================================================= */
.video-pane {
  position: relative;
  min-height: 320px;
  background: #000;
  border-radius: 0 0 8px 8px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.video-pane img {
  max-width: 100%; height: auto;
  display: block;
}
/* Hide the <img> entirely while it has no source yet — otherwise the
   browser draws a broken-image icon + alt text on top of the
   placeholder message.  Re-appears the moment JS sets a real src.
   Covers single-cam (.video-pane) AND multi-cam (.cell-video). */
.video-pane img:not([src]),
.video-pane img[src=""],
.cell-video img:not([src]),
.cell-video img[src=""] {
  display: none;
}
.placeholder-msg {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-muted); text-align: center;
}
.placeholder-msg i { font-size: 2.4rem; opacity: .4; margin-bottom: 6px; }

/* Pill */
.status-pill {
  display: inline-block; padding: 4px 12px;
  border-radius: 999px; font-weight: 700; font-size: .78rem;
  letter-spacing: .03em;
  background: #1f2937; color: var(--text-muted);
}
.status-pill.live { background: #0d2a1f; color: var(--success); }
.status-pill.idle { background: #1f2937; color: var(--text-muted); }
.status-pill.error { background: #2a0d0d; color: var(--danger); }

/* Log panel */
.log-panel {
  background: var(--bg-input);
  color: #cbd5e1;
  border-radius: 6px;
  border: 1px solid var(--border);
  padding: 10px 12px;
  font-family: Consolas, "Courier New", monospace;
  font-size: .8rem;
  max-height: 220px; overflow-y: auto;
  white-space: pre-wrap;
}

/* =================================================================
   Multi-cam grid
   ================================================================= */
.grid-2x2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.grid-cell {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  display: flex; flex-direction: column;
}
.cell-header {
  background: var(--bg-raised);
  padding: 6px 10px;
  display: flex; justify-content: space-between;
  font-size: .85rem; color: var(--text-secondary);
}
.cell-video {
  position: relative;
  min-height: 240px;
  background: #000;
  display: flex; align-items: center; justify-content: center;
}
.cell-video img { max-width: 100%; height: auto; display: block; }

/* =================================================================
   Zone editor
   ================================================================= */
.zone-canvas-wrap {
  background: #0d1320;
  display: flex; justify-content: center;
  padding: 12px;
}
#z-canvas {
  background: #000;
  border: 1px solid var(--border);
  cursor: crosshair;
  max-width: 100%; height: auto;
}
.zone-list {
  list-style: none; padding: 0; margin: 0;
  max-height: 240px; overflow-y: auto;
}
.zone-list li {
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 6px;
  display: flex; justify-content: space-between;
  align-items: center;
}
.zone-list .ztype-badge {
  font-size: .7rem; padding: 2px 8px; border-radius: 999px;
  background: var(--bg-raised); color: var(--text-secondary);
}

/* =================================================================
   Incidents grid
   ================================================================= */
.incident-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.incident-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: border-color .15s, box-shadow .15s;
}
.incident-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(6,182,212,.25);
}
.inc-select-wrap {
  position: absolute;
  top: 8px; left: 8px;
  z-index: 4;
  background: rgba(10,14,26,0.65);
  border-radius: 4px;
  padding: 4px 6px;
  cursor: pointer;
}
.inc-select-wrap input[type="checkbox"] {
  cursor: pointer;
  width: 16px; height: 16px;
  margin: 0;
}
.incident-card img {
  width: 100%; aspect-ratio: 16/10;
  object-fit: cover;
  cursor: zoom-in;
  background: #000;
}
.incident-card .ic-body {
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 4px;
  font-size: .85rem;
}
.incident-card .ic-type {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: .7rem; font-weight: 700; letter-spacing: .03em;
  background: var(--accent); color: #001;
}
.incident-card .ic-meta { color: var(--text-secondary); font-size: .78rem; }
.incident-card .ic-foot {
  border-top: 1px solid var(--border);
  padding: 6px 12px;
  display: flex; justify-content: space-between;
}

/* Type-specific badge colors */
.ic-type.t-IDLE       { background: var(--danger);  color: white; }
.ic-type.t-PHONE_USE  { background: var(--warning); color: #001; }
.ic-type.t-ZONE_INTRUSION { background: var(--purple); color: white; }
.ic-type.t-LOITERING  { background: #9333ea; color: white; }
.ic-type.t-COUNTER_WAIT { background: var(--info); color: white; }
.ic-type.t-UNATTENDED { background: var(--purple); color: white; }
.ic-type.t-CASH_FRAUD { background: var(--success); color: #001; }
.ic-type.t-NO_HAIRNET { background: #16a34a; color: white; }
.ic-type.t-NO_GLOVES  { background: #0f172a; color: white; border:1px solid var(--accent-glow); }
.ic-type.t-CROWD      { background: #ea580c; color: white; }
.ic-type.t-AFTER_HOURS { background: var(--info); color: white; }
.ic-type.t-SERVICE_WAIT { background: #d97706; color: white; }

/* Toast tweaks */
.toast.surface {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
}

/* Responsive — collapse sidebar */
@media (max-width: 820px) {
  .sidebar { width: 64px; }
  .sidebar-brand span,
  .sidebar-nav li a span:not(.badge),
  .sidebar-status span:not(.status-dot) { display: none; }
  .sidebar-nav li a { padding-left: 22px; }
  .content { margin-left: 64px; padding: 14px; }
  .grid-2x2 { grid-template-columns: 1fr; }
}
