/* map.css - Styles for Map Dashboard Layout */

.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background-color: var(--bg);
}

/* Sidebar */
.sidebar {
  width: 250px;
  background-color: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 1000;
}

.sidebar-header {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

/* Full logo lockup — wordmark is part of the image, so no brand text beside it. */
.sidebar-header .logo {
  display: flex;
  align-items: center;
  width: 100%;
}

.sidebar-header .brand-logo {
  height: 46px;
  width: auto;
  max-width: 100%;
  display: block;
}

.sidebar-header .brand-logo-dark { display: none; }
[data-theme="dark"] .sidebar-header .brand-logo-light { display: none; }
[data-theme="dark"] .sidebar-header .brand-logo-dark { display: block; }

.sidebar-nav {
  padding: 20px 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  border-radius: 8px;
  transition: all 0.2s;
}

.nav-item:hover {
  background-color: var(--surface-2);
  color: var(--text);
}

.nav-item.active {
  background-color: var(--cyan);
  color: var(--bg);
  font-weight: 600;
}

.nav-item.active .nav-icon {
  filter: brightness(0) saturate(100%);
}

.sidebar-stats {
  padding: 20px;
  border-top: 1px solid var(--border);
  background-color: var(--surface-2);
}

.stat-header {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text);
}

.stat-val {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.top-header {
  height: 64px;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
}

.department-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: var(--surface-2);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
}

.department-selector .arrow {
  font-size: 10px;
  color: var(--text-muted);
}

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

.area-select {
  background-color: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  padding: 7px 12px;
  font-family: inherit;
  font-size: 13px;
  max-width: 220px;
  cursor: pointer;
}
.area-select:focus { outline: none; border-color: var(--cyan); }

.search-bar {
  display: flex;
  align-items: center;
  background-color: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 12px;
  width: 250px;
  position: relative;   /* anchors the results dropdown */
}
.search-bar:focus-within { border-color: var(--cyan); }

.search-clear {
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); font-size: 12px; padding: 0 2px;
}
.search-clear:hover { color: var(--text); }

/* Results dropdown — sits above the map, which Leaflet keeps at z-index 1 */
.search-results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;                 /* wider than the 250px bar — grows leftwards */
  min-width: 340px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 2000;
  padding: 4px;
}
.search-group {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 8px 10px 4px;
}
.search-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.search-item:hover, .search-item.active { background: var(--surface-2); }
.search-item .si-main { font-weight: 600; white-space: nowrap; }
.search-item .si-sub {
  margin-left: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.search-empty {
  padding: 14px 10px; text-align: center;
  color: var(--text-dim); font-size: 12px;
}

.search-bar input {
  background: transparent;
  border: none;
  color: var(--text);
  margin-left: 8px;
  width: 100%;
  font-size: 13px;
}

.search-bar input:focus {
  outline: none;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  border-left: 1px solid var(--border);
  padding-left: 16px;
}

.user-info {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
}

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

/* Map Area */
.map-wrapper {
  flex: 1;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
  background-color: var(--map-fallback); /* Fallback map bg */
  z-index: 1;
}

/* Leaflet overrides */
.leaflet-container {
  font-family: inherit;
}

/* OSM raster tiles are light already — they are inverted for the dark theme
   only, so --tile-filter resolves to none in light mode. */
.dark-tiles {
  filter: var(--tile-filter);
}

.leaflet-popup-content-wrapper {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 0;
}

.leaflet-popup-tip {
  background-color: var(--surface);
  border: 1px solid var(--border);
}

.leaflet-popup-content {
  margin: 0;
  width: 300px !important;
}

.leaflet-popup-close-button {
  color: var(--text-muted) !important;
  right: 8px !important;
  top: 8px !important;
}

.leaflet-popup-close-button:hover {
  color: var(--text) !important;
}

/* Custom Marker CSS */
.custom-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background-color: var(--surface);
  border-radius: 50%;
  border: 2px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 14px;
}

.custom-marker.online {
  border-color: var(--green);
}

.custom-marker.offline {
  border-color: var(--red);
}

.custom-marker.selected {
  border-color: var(--cyan);
  background-color: var(--cyan);
  color: var(--bg);
}

.custom-marker .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.custom-marker.online .dot { background-color: var(--green); }
.custom-marker.offline .dot { background-color: var(--red); }
.custom-marker.selected .dot { display: none; }

/* Right Panel (Area Cameras) */
.right-panel {
  position: absolute;
  top: 0;
  right: -350px;
  width: 300px;
  height: 100%;
  background-color: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 1000;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.right-panel.open {
  right: 0;
}

.panel-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.panel-title-container {
  display: flex;
  gap: 12px;
}

.panel-icon {
  font-size: 24px;
}

.panel-header h3 {
  font-size: 16px;
  margin-bottom: 4px;
}

.panel-sub {
  font-size: 13px;
  color: var(--text-muted);
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}

.close-btn:hover {
  color: var(--text);
}

.camera-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.camera-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background-color 0.2s;
}

.camera-item:hover {
  background-color: var(--surface-2);
}

.camera-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.camera-icon {
  font-size: 18px;
}

.camera-name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
}

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

/* Popup Content styling */
.cam-popup {
  padding: 16px;
}

.cam-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.cam-popup-title {
  font-size: 16px;
  font-weight: 700;
}

.cam-popup-status {
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.cam-popup-status.online {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid var(--green-border);
}

.cam-popup-status.offline {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red-border);
}

.cam-popup-img {
  width: 100%;
  height: 140px;
  background-color: var(--surface-2);
  border-radius: 8px;
  margin-bottom: 12px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.cam-popup-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 12px;
}

.detail-lbl {
  color: var(--text-muted);
}

.detail-val {
  font-weight: 500;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cam-popup-actions {
  display: flex;
  gap: 8px;
}

.btn-popup {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
}

.btn-live {
  background-color: var(--cyan);
  color: var(--bg);
}

.btn-ai {
  background-color: var(--violet);
  color: #fff;
}

/* ─── Live stream modal ───────────────────────────────────────────────── */
.live-overlay {
  position: fixed; inset: 0; z-index: 3000;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.live-modal {
  width: min(720px, 100%);
  max-height: 90vh; overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px;
}
.live-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.live-title { font-size: 16px; font-weight: 700; }
.live-sub {
  font-family: 'JetBrains Mono', monospace; font-size: 11px;
  color: var(--text-muted); margin-top: 3px;
}
.live-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 16px; line-height: 1; padding: 4px;
}
.live-close:hover { color: var(--text); }

.live-stage { position: relative; }
.live-video {
  width: 100%; aspect-ratio: 16 / 9;
  background: #000; border-radius: 10px; display: block;
}
.live-badge {
  position: absolute; top: 10px; left: 10px;
  background: var(--red); color: #fff;
  font-family: 'JetBrains Mono', monospace; font-size: 10px; font-weight: 700;
  letter-spacing: 0.08em; padding: 3px 8px; border-radius: 4px;
  pointer-events: none;
}
.live-placeholder-msg { font-size: 13px; color: var(--text); }
.live-placeholder {
  position: absolute; inset: 0;
  aspect-ratio: 16 / 9;
  background: var(--surface-2);
  border: 1px dashed var(--border-bright);
  border-radius: 10px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px;
  text-align: center; padding: 20px;
  font-size: 13px; color: var(--text-muted);
}
/* With no video element the placeholder has nothing to overlay, so it needs
   to hold its own height. */
.live-stage:not(:has(.live-video)) .live-placeholder { position: static; }
.live-placeholder-icon { font-size: 30px; }
.live-hint { font-size: 11px; color: var(--text-dim); max-width: 420px; line-height: 1.5; }
.live-hint code {
  font-family: 'JetBrains Mono', monospace;
  background: var(--surface-3); padding: 1px 5px; border-radius: 4px;
}

.live-actions {
  margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap;
}
.live-actions .btn-popup { text-decoration: none; text-align: center; }


/* ─── PHONES & SMALL TABLETS ──────────────────────────────────────────────────
   Below 860px the sidebar becomes a slide-in menu (☰ added to the header by
   js/mobile-nav.js) so the page gets the whole screen; the header wraps onto
   more lines instead of running off the edge. Desktop unchanged. */
.menu-btn, .nav-backdrop { display: none; }
@media (max-width: 860px) {
  .app-layout { width: 100%; height: 100vh; height: 100dvh; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(280px, 82vw);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    z-index: 4000;
  }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, 0.35); }
  .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 3999;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0; pointer-events: none; transition: opacity 0.2s;
  }
  body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  .menu-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; flex: none;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface-2); color: var(--text);
    font-size: 20px; line-height: 1; cursor: pointer;
  }
  .top-header {
    height: auto; min-height: 56px;
    flex-wrap: wrap; gap: 8px; padding: 8px 12px;
  }
  .top-header .department-selector {
    flex: 1 1 0; min-width: 0; padding: 6px 10px; font-size: 13px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .header-right { gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
  .user-info { display: none; }
  /* map header on landscape phones / small tablets: one compact row */
  .area-select { max-width: 170px; }
  .search-bar { width: 190px; }
  .search-results { left: 0; right: 0; min-width: 0; }
  .right-panel { width: 88vw; right: -100vw; }        /* map area panel: nearly full width when open */
  .right-panel.open { right: 0; }
  input, select, textarea { font-size: 16px; }      /* iOS: no auto-zoom when a field is tapped */
}
@media (max-width: 600px) {
  /* portrait phones: map area filter + search get their own full-width rows */
  .top-header:has(.search-bar) .header-right { width: 100%; }
  .area-select { flex: 1 1 140px; max-width: none; }
  .search-bar { order: 10; flex: 1 1 100%; width: auto; }
}
