/* =================================================================
   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);
}
.sidebar-nvr {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: .85rem;
}
.sidebar-nvr .nvr-label {
  color: var(--accent-glow);
  letter-spacing: .02em;
  margin-bottom: 2px;
}
.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);
}

/* =================================================================
   MOBILE — hamburger + slide-in sidebar
   Visible only on small screens; desktop hides these elements.
   ================================================================= */
.mobile-menu-btn,
.sidebar-close-btn,
.sidebar-backdrop { display: none; }

/* ----- Tablet (≤ 820px): icon-only sidebar still pinned ----- */
@media (max-width: 820px) and (min-width: 641px) {
  .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; }
}

/* ----- Phone (≤ 640px): off-canvas drawer ----- */
@media (max-width: 640px) {
  /* Sidebar starts off-screen, slides in when body.sidebar-open */
  .sidebar {
    width: 260px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 1050;        /* above modals' backdrop fade */
  }
  body.sidebar-open .sidebar { transform: translateX(0); }

  /* Backdrop behind the open sidebar */
  .sidebar-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1040;
    opacity: 0; pointer-events: none;
    transition: opacity .25s ease;
  }
  body.sidebar-open .sidebar-backdrop {
    opacity: 1; pointer-events: auto;
  }

  /* Hamburger button — fixed top-left */
  .mobile-menu-btn {
    display: inline-flex;
    align-items: center; justify-content: center;
    position: fixed; top: 10px; left: 10px;
    width: 44px; height: 44px;
    background: rgba(14, 20, 34, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    color: var(--accent-glow);
    font-size: 1.5rem;
    z-index: 1030;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
    cursor: pointer;
  }
  .mobile-menu-btn:active { transform: scale(0.96); }

  /* Close (×) button shown inside the open sidebar */
  .sidebar-close-btn {
    display: inline-flex;
    align-items: center; justify-content: center;
    background: transparent; border: none;
    color: var(--text-secondary);
    font-size: 1.2rem; padding: 4px 8px;
    margin-left: auto;
    cursor: pointer;
  }
  .sidebar-close-btn:hover { color: var(--accent-glow); }

  /* Content full-width with extra top space for the hamburger */
  .content {
    margin-left: 0;
    padding: 64px 14px 20px;
  }

  /* Stack everything that was multi-column */
  .grid-2x2 { grid-template-columns: 1fr; gap: 10px; }
  .incident-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
  }

  /* Tighten page header */
  .page-header h1 { font-size: 1.25rem; }
  .page-header { padding-bottom: 8px; }

  /* Cards a bit lighter on padding */
  .card-body { padding: 12px; }

  /* Video panes — keep aspect, don't enforce huge min height */
  .video-pane { min-height: 200px; }
  .cell-video { min-height: 180px; }

  /* Form inputs — tappable */
  .form-control, .form-select { font-size: 0.95rem; padding: 10px 12px; }

  /* Bigger tap targets for nav links inside the drawer */
  .sidebar-nav li a { padding: 14px 20px; font-size: 1rem; }
  .sidebar-brand    { padding: 14px 20px 18px; }

  /* Buttons that often appear in toolbars — let them wrap */
  .btn-toolbar, .d-flex.flex-wrap { gap: 6px; }

  /* Toast container — fit screen */
  .toast-container { padding: 8px !important; }
  .toast { max-width: calc(100vw - 24px); }

  /* Modal — full-width with safe margins */
  .modal-dialog { margin: 8px; max-width: calc(100vw - 16px); }

  /* Zone editor canvas wrap — let it scroll horizontally if too wide */
  .zone-canvas-wrap { padding: 6px; overflow-x: auto; }

  /* Multi-cam cell header — wrap action buttons under title */
  .cell-header { flex-wrap: wrap; gap: 4px; padding: 8px; }

  /* Tables — horizontal scroll instead of overflow chaos */
  .table-responsive, table { font-size: 0.85rem; }
}

/* ----- Very small (≤ 380px): even tighter ----- */
@media (max-width: 380px) {
  .content { padding: 60px 10px 16px; }
  .page-header h1 { font-size: 1.1rem; }
  .incident-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .card-body { padding: 10px; }
}
