/* ============================================================
   CCTV Kabupaten OKU Selatan
   Palet warna mengikuti referensi cctv.palembang.go.id:
   navy #001847 / #002060 / #003087, aksen #00A3E0, latar #F5F8FF
   ============================================================ */

:root {
  --navy-1: #001847;
  --navy-2: #002060;
  --navy-3: #003087;
  --accent: #00A3E0;
  --light: #F5F8FF;
  --emerald: #10b981;
  --emerald-light: #6ee7b7;
  --red: #ef4444;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 24, 71, 0.25);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* Atribut hidden harus selalu menang atas display flex/grid apa pun */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ---------- Layar loading ---------- */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy-1), var(--navy-2), var(--navy-3));
  transition: opacity 0.45s ease;
}
#loading-screen.hidden { opacity: 0; pointer-events: none; }

.loading-spinner-wrap { position: relative; margin-bottom: 1.5rem; }
.loading-spinner {
  height: 4rem;
  width: 4rem;
  border-radius: 9999px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
.loading-cam-icon {
  position: absolute;
  inset: 0;
  margin: auto;
  color: rgba(255, 255, 255, 0.6);
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-size: 0.875rem;
  font-weight: 500;
  color: #bfdbfe;
}
.loading-subtext {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: rgba(147, 197, 253, 0.5);
}

/* ---------- Peta ---------- */
#map {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: #dbe4f0;
}

/* ---------- Kartu header ---------- */
.map-header {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 500;
  max-width: 300px;
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--navy-1), var(--navy-3));
  color: #fff;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.map-header-top {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.map-header-logo {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
}
.map-header-title {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
}
.map-header-sub {
  margin-top: 2px;
  font-size: 0.68rem;
  color: rgba(191, 219, 254, 0.85);
}
.map-header-hint {
  margin-top: 0.55rem;
  font-size: 0.65rem;
  color: rgba(191, 219, 254, 0.55);
}
.map-header-status {
  margin-top: 0.45rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}
.status-text {
  font-size: 0.68rem;
  color: var(--emerald-light);
}

/* ---------- Tombol daftar CCTV ---------- */
.sheet-trigger {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--navy-2), var(--navy-3));
  color: #fff;
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, filter 0.15s ease;
}
.sheet-trigger:hover { filter: brightness(1.15); transform: translateY(-1px); }

/* ---------- Panel (sheet) daftar CCTV ---------- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 800;
  background: rgba(0, 24, 71, 0.45);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.sheet-overlay.show { opacity: 1; }

.sheet {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 900;
  width: min(360px, 92vw);
  display: flex;
  flex-direction: column;
  background: var(--light);
  box-shadow: -12px 0 40px rgba(0, 24, 71, 0.3);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
.sheet.open { transform: translateX(0); }

.sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 1rem 1.1rem 0.8rem;
  background: linear-gradient(135deg, var(--navy-1), var(--navy-3));
  color: #fff;
}
.sheet-title { font-size: 1rem; font-weight: 700; }
.sheet-desc { margin-top: 3px; font-size: 0.7rem; color: rgba(191, 219, 254, 0.8); }
.sheet-close {
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 8px;
  padding: 0.35rem;
  cursor: pointer;
  display: flex;
  transition: background 0.15s ease;
}
.sheet-close:hover { background: rgba(255, 255, 255, 0.22); }

.sheet-tools {
  padding: 0.75rem 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.search-wrap { position: relative; }
.search-icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(0, 48, 135, 0.45);
  pointer-events: none;
}
#search-input {
  width: 100%;
  padding: 0.55rem 0.75rem 0.55rem 2.1rem;
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--navy-2);
  background: #fff;
  border: 1px solid rgba(0, 48, 135, 0.18);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 163, 224, 0.15);
}
#kecamatan-filter {
  width: 100%;
  padding: 0.5rem 0.7rem;
  font-family: var(--font);
  font-size: 0.8rem;
  color: var(--navy-2);
  background: #fff;
  border: 1px solid rgba(0, 48, 135, 0.18);
  border-radius: 10px;
  outline: none;
  cursor: pointer;
}

.cctv-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.cctv-list::-webkit-scrollbar { width: 6px; }
.cctv-list::-webkit-scrollbar-thumb { background: rgba(0, 48, 135, 0.2); border-radius: 3px; }

.cctv-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.75rem;
  background: #fff;
  border: 1px solid rgba(0, 48, 135, 0.1);
  border-radius: 12px;
  cursor: pointer;
  font-family: var(--font);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.cctv-item:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(0, 163, 224, 0.15);
  transform: translateY(-1px);
}
.cctv-item-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy-2), var(--navy-3));
  color: #fff;
}
.cctv-item.offline .cctv-item-icon {
  background: linear-gradient(135deg, #64748b, #94a3b8);
}
.cctv-item-info { flex: 1; min-width: 0; }
.cctv-item-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--navy-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cctv-item-loc {
  margin-top: 2px;
  font-size: 0.68rem;
  color: rgba(0, 32, 96, 0.55);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cctv-item-badge {
  flex-shrink: 0;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
}
.cctv-item-badge.online { background: rgba(16, 185, 129, 0.12); color: #059669; }
.cctv-item-badge.offline { background: rgba(239, 68, 68, 0.1); color: #dc2626; }

.list-empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: rgba(0, 32, 96, 0.5);
}
.list-empty p:first-child { font-size: 0.85rem; font-weight: 600; color: rgba(0, 32, 96, 0.6); }
.list-empty p:last-child { margin-top: 0.3rem; font-size: 0.72rem; }

/* ---------- Marker kamera ---------- */
.cctv-marker { background: transparent; border: none; }
.cctv-marker svg { filter: drop-shadow(0 3px 4px rgba(0, 24, 71, 0.4)); }

.leaflet-popup-content-wrapper {
  border-radius: 12px;
  font-family: var(--font);
}
.leaflet-popup-content { margin: 10px 14px; }
.popup-title { font-size: 0.8rem; font-weight: 700; color: var(--navy-2); }
.popup-loc { margin-top: 2px; font-size: 0.68rem; color: rgba(0, 32, 96, 0.55); }
.popup-btn {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: none;
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  background: linear-gradient(135deg, var(--navy-2), var(--navy-3));
  color: #fff;
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}
.popup-btn:hover { filter: brightness(1.15); }

/* ---------- Modal pemutar ---------- */
.player-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 24, 71, 0.75);
  backdrop-filter: blur(4px);
}
.player-modal {
  width: min(860px, 100%);
  border-radius: 16px;
  overflow: hidden;
  background: #0b1220;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 1rem;
  background: linear-gradient(135deg, var(--navy-1), var(--navy-3));
}
.player-header-info {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #fff;
  background: var(--red);
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
}
.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  animation: blink 1.2s infinite;
}
@keyframes blink { 50% { opacity: 0.3; } }
.player-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-location {
  margin-top: 1px;
  font-size: 0.68rem;
  color: rgba(191, 219, 254, 0.7);
}
.player-close {
  flex-shrink: 0;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 8px;
  padding: 0.4rem;
  cursor: pointer;
  display: flex;
  transition: background 0.15s ease;
}
.player-close:hover { background: rgba(255, 255, 255, 0.25); }

.player-body {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
}
#player-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.player-youtube { width: 100%; height: 100%; }
.player-youtube iframe { width: 100%; height: 100%; border: 0; }

.player-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  color: #94a3b8;
  background: #0b1220;
  text-align: center;
  padding: 1rem;
}
.player-state p { font-size: 0.8rem; }
.player-spinner {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: #fff;
  animation: spin 1s linear infinite;
}
.player-offline-title { font-size: 0.9rem !important; font-weight: 700; color: #cbd5e1; }
.player-offline-sub { font-size: 0.72rem !important; color: #64748b; }
.retry-btn {
  margin-top: 0.4rem;
  border: 1px solid rgba(0, 163, 224, 0.5);
  background: rgba(0, 163, 224, 0.12);
  color: var(--accent);
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.45rem 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.retry-btn:hover { background: rgba(0, 163, 224, 0.25); }

/* ---------- Kontrol Leaflet ---------- */
.leaflet-control-layers,
.leaflet-control-zoom {
  border: none !important;
  box-shadow: 0 4px 16px rgba(0, 24, 71, 0.2) !important;
  border-radius: 10px !important;
  overflow: hidden;
}
.leaflet-control-zoom a { color: var(--navy-2) !important; }
.leaflet-control-attribution {
  font-size: 0.6rem !important;
  background: rgba(255, 255, 255, 0.75) !important;
}

/* ---------- Responsif ---------- */
@media (max-width: 640px) {
  .map-header {
    max-width: calc(100vw - 2rem);
    top: 0.75rem;
    left: 0.75rem;
    padding: 0.7rem 0.85rem;
  }
  .map-header-hint { display: none; }
  .sheet-trigger {
    top: auto;
    bottom: 1.25rem;
    right: 1rem;
  }
  .player-modal { width: 100%; }
}
