/* ==========================================================================
   VALIKAATTI (வழிகாட்டி) — POLICE & AUTHORITY EMERGENCY DASHBOARD STYLES (CSS)
   Premium light-paper aesthetic matching the passenger Valikaatti app.
   ========================================================================== */

:root {
  /* Color System */
  --bg-main: #F4F5F8;
  --bg-sidebar: #FFFFFF;
  --bg-card: #FFFFFF;
  --border-color: #E6E8F0;
  
  --text-main: #1E2229;
  --text-muted: #626B7A;
  
  /* Slate & Block accents */
  --accent-dark: #1E2229;
  --accent-light: #F4F5F8;
  
  /* Status Colors */
  --color-safest: #1B5E20;       /* Deep Forest Green */
  --color-accessible: #0D47A1;   /* Deep Blue */
  --color-shade: #E65100;        /* Deep Clay Amber */
  --color-danger: #B71C1C;       /* Flat Red */
  
  /* Police Accents */
  --accent-pink: #D81B60;        /* Pink Patrol Accent */
  --accent-pink-light: #FCE4EC;
  
  --font-family: 'Outfit', -apple-system, sans-serif;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 30px rgba(30, 34, 41, 0.06);
  --radius-sm: 8px;
  --radius-lg: 12px;
}

/* Base resets */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  margin: 0;
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  height: 100vh;
  width: 100vw;
  position: relative;
}

/* ==========================================================================
   SIDEBAR
   ========================================================================== */
#sidebar {
  width: 480px;
  flex: 0 0 480px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

.app-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.logo-orb {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--accent-pink);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 16px;
  box-shadow: 0 0 10px rgba(216, 27, 96, 0.4);
}

.brand-text h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--accent-dark);
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.brand-tamil {
  font-family: 'Noto Sans Tamil', var(--font-family);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-pink);
}

.brand-text .tagline {
  font-size: 9px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.mute-btn {
  background: var(--accent-light);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.mute-btn:hover {
  background: var(--border-color);
}

/* ==========================================================================
   NAVIGATION TABS
   ========================================================================== */
.nav-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  background: #FAFAFB;
  padding: 4px;
}

.tab-btn {
  flex: 1;
  border: 0;
  background: transparent;
  font-family: var(--font-family);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 10px 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.02);
}

.tab-btn.active {
  color: #FFFFFF;
  background: var(--accent-dark);
}

.tab-btn.active-emergency {
  background: var(--color-danger) !important;
  color: #FFFFFF !important;
}

/* Scroll area */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.sidebar-content::-webkit-scrollbar {
  width: 5px;
}
.sidebar-content::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-content::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}

/* ==========================================================================
   CARDS & STATS
   ========================================================================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 2px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.kpi-val {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-main);
}

.kpi-lbl {
  font-size: 7.5px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.1;
}

/* ==========================================================================
   ACTIVE SOS WARNING BEACON (RED ALARM CARD)
   ========================================================================== */
.sos-alarm-container {
  display: none; /* JS toggled */
  background: #FFF5F5;
  border: 2px solid var(--color-danger);
  box-shadow: 0 4px 15px rgba(183, 28, 28, 0.15);
  animation: border-flash 1s infinite alternate;
}

@keyframes border-flash {
  0% { border-color: rgba(183, 28, 28, 0.4); }
  100% { border-color: rgba(183, 28, 28, 1); }
}

.sos-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #FFCDCD;
  padding-bottom: 6px;
  margin-bottom: 10px;
}

.sos-badge {
  background: var(--color-danger);
  color: #FFFFFF;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  animation: blink 0.8s infinite alternate;
}

@keyframes blink {
  0% { opacity: 0.4; }
  100% { opacity: 1; }
}

.sos-time {
  font-size: 10px;
  color: var(--color-danger);
  font-weight: 700;
}

.sos-details {
  font-size: 11px;
  margin-bottom: 10px;
  line-height: 1.4;
}

.sos-details table {
  width: 100%;
  margin-top: 4px;
}

.sos-details td {
  padding: 2px 0;
}
.sos-details td.lbl {
  color: var(--text-muted);
  width: 75px;
}

.sos-actions {
  display: flex;
  gap: 6px;
}

.btn-dispatch {
  flex: 1;
  background: var(--color-danger);
  color: white;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 8px 0;
  font-family: var(--font-family);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(183, 28, 28, 0.2);
  transition: opacity 0.2s;
}
.btn-dispatch:hover {
  opacity: 0.9;
}

.btn-resolve {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: var(--font-family);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.btn-resolve:hover {
  background: var(--accent-light);
}

.sos-dispatched-banner {
  background: #E8F5E9;
  border: 1.5px solid var(--color-safest);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 10.5px;
  line-height: 1.4;
  margin-top: 8px;
  color: var(--color-safest);
}

/* ==========================================================================
   CCTV MOCK MONITOR
   ========================================================================== */
.cctv-widget {
  background: #11141A;
  border: 1px solid var(--accent-dark);
  border-radius: var(--radius-lg);
  padding: 10px;
  margin-bottom: 12px;
}

.cctv-widget-header {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
  border-bottom: 1px solid #202633;
  padding-bottom: 4px;
}

.cctv-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.cctv-pane {
  background: #000;
  border: 1px solid #202633;
  border-radius: 4px;
  position: relative;
  height: 70px;
  overflow: hidden;
}

.cctv-label {
  position: absolute;
  top: 4px;
  left: 4px;
  font-size: 7px;
  color: #00FF00;
  font-family: monospace;
  background: rgba(0,0,0,0.6);
  padding: 1px 3px;
  border-radius: 2px;
  z-index: 5;
}

.cctv-rec {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #FF0000;
  animation: blink 0.8s infinite alternate;
  z-index: 5;
}

.cctv-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ==========================================================================
   INCIDENT FEED
   ========================================================================== */
.filter-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.filter-select {
  flex: 1;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px;
  border-radius: var(--radius-sm);
  font-size: 10.5px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
}

.incident-feed {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 250px;
  overflow-y: auto;
}

.incident-card {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.incident-card:hover {
  border-color: var(--text-muted);
  background: var(--accent-light);
}

.incident-card.active-focus {
  border-color: var(--accent-pink);
  background: var(--accent-pink-light);
}

.incident-card.sev-high { border-left-color: var(--color-danger); }
.incident-card.sev-medium { border-left-color: var(--color-shade); }
.incident-card.sev-low { border-left-color: var(--color-accessible); }

.incident-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.incident-title {
  font-size: 11px;
  font-weight: 700;
}

.incident-badge {
  font-size: 7.5px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 4px;
  border-radius: 2px;
}
.badge-high { background: rgba(183, 28, 28, 0.08); color: var(--color-danger); }
.badge-medium { background: rgba(230, 81, 0, 0.08); color: var(--color-shade); }
.badge-low { background: rgba(13, 71, 161, 0.08); color: var(--color-accessible); }

.incident-desc {
  font-size: 10.5px;
  color: var(--text-muted);
  line-height: 1.35;
  margin-bottom: 6px;
}

.incident-img-thumb {
  width: 100%;
  max-height: 80px;
  border-radius: 4px;
  overflow: hidden;
  margin: 4px 0;
  border: 1px solid var(--border-color);
}
.incident-img-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.incident-meta {
  font-size: 8.5px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.status-indicator {
  font-size: 8.5px;
  font-weight: 700;
  text-transform: uppercase;
}
.status-open { color: var(--color-shade); }
.status-progress { color: var(--color-accessible); }
.status-resolved { color: var(--color-safest); }

.incident-actions {
  display: flex;
  gap: 4px;
  border-top: 1px solid var(--border-color);
  padding-top: 6px;
  margin-top: 2px;
}

.action-btn-sm {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 4px;
  padding: 4px 0;
  font-family: var(--font-family);
  font-size: 8.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.action-btn-sm:hover {
  background: var(--accent-light);
  border-color: var(--text-muted);
}

.action-btn-sm.btn-resolve-inc {
  color: var(--color-safest);
}
.action-btn-sm.btn-resolve-inc:hover {
  background: rgba(27, 94, 32, 0.05);
  border-color: var(--color-safest);
}

/* ==========================================================================
   VOLUNTEERS (LOCAL GUARDIANS) SECTION
   ========================================================================== */
.volunteer-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.volunteer-card {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px;
  box-shadow: var(--shadow-sm);
}

.volunteer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.volunteer-name {
  font-size: 11px;
  font-weight: 700;
}

.volunteer-badge {
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 4px;
  border-radius: 2px;
}
.status-pending { background: #FFF9C4; color: #F57F17; }
.status-approved { background: #E8F5E9; color: var(--color-safest); }

.volunteer-details {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 8px;
}

.volunteer-actions {
  display: flex;
  gap: 4px;
}

.btn-approve {
  flex: 1;
  background: var(--color-safest);
  color: white;
  border: 0;
  border-radius: 4px;
  padding: 5px 0;
  font-family: var(--font-family);
  font-size: 9px;
  font-weight: 700;
  cursor: pointer;
}
.btn-reject {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  color: var(--color-danger);
  border-radius: 4px;
  padding: 5px 8px;
  font-family: var(--font-family);
  font-size: 9px;
  font-weight: 600;
  cursor: pointer;
}

/* ==========================================================================
   PATROLS SECTION
   ========================================================================== */
.patrol-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.patrol-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 10.5px;
}

.patrol-info {
  display: flex;
  align-items: center;
  gap: 6px;
}

.patrol-bullet {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.bullet-online {
  background: var(--color-safest);
  box-shadow: 0 0 6px var(--color-safest);
}
.bullet-busy {
  background: var(--accent-pink);
  box-shadow: 0 0 6px var(--accent-pink);
}

.patrol-name {
  font-weight: 700;
}

.patrol-status {
  font-size: 9px;
  color: var(--text-muted);
}

/* ==========================================================================
   REAL-TIME RUNNING LOG TERMINAL
   ========================================================================== */
.log-terminal {
  background: #11141A;
  border: 1px solid var(--accent-dark);
  border-radius: var(--radius-lg);
  padding: 10px;
  font-family: monospace;
  font-size: 8.5px;
  color: #00FF00;
  max-height: 95px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.log-entry {
  display: flex;
  gap: 4px;
  line-height: 1.25;
}

.log-time {
  color: #888;
  flex-shrink: 0;
}

.log-text {
  word-break: break-all;
}

/* ==========================================================================
   MAP VIEWPORT
   ========================================================================== */
#map-container {
  flex: 1;
  position: relative;
  height: 100%;
}

#map {
  width: 100%;
  height: 100%;
}

.leaflet-container {
  background: var(--bg-main) !important;
}

/* Floating custom layers switcher (Left side) */
.map-layer-selector {
  position: absolute;
  top: 12px;
  left: 55px;
  z-index: 1000;
}

.map-ctrl-btn {
  width: 34px;
  height: 34px;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-main);
  transition: all 0.2s;
}
.map-ctrl-btn:hover {
  background: var(--accent-light);
}

.base-layer-dropdown {
  position: absolute;
  top: 38px;
  left: 0;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 110px;
}

.layer-opt {
  background: transparent;
  border: 0;
  border-radius: 4px;
  padding: 6px 8px;
  text-align: left;
  font-family: var(--font-family);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.layer-opt:hover {
  background: var(--accent-light);
  color: var(--text-main);
}
.layer-opt.active {
  background: var(--accent-dark);
  color: #FFFFFF;
}

/* Floating LOGIN Button on Map (Top-Right Screen Corner) */
.map-login-container {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
}

.map-login-btn {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-family);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.map-login-btn:hover {
  background: var(--accent-light);
  border-color: var(--text-muted);
}

/* Floating HUD Legends */
.map-hud {
  position: absolute;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  font-size: 10px;
}

.map-legend {
  bottom: 24px;
  left: 24px;
  width: 180px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.map-legend h4 {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-color-line {
  width: 24px;
  height: 4px;
  border-radius: 2px;
  display: inline-block;
}
.line-route { background: var(--accent-pink); height: 5px; }

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot-patrol { background: var(--accent-pink); box-shadow: 0 0 6px var(--accent-pink); }
.dot-sos { background: var(--color-danger); box-shadow: 0 0 10px var(--color-danger); }
.dot-guardian { background: var(--color-safest); box-shadow: 0 0 6px var(--color-safest); }

/* Blinking animations for map points */
@keyframes glow-pulse-red {
  0% { box-shadow: 0 0 4px rgba(183, 28, 28, 0.4); }
  100% { box-shadow: 0 0 18px rgba(183, 28, 28, 0.9); }
}

@keyframes glow-pulse-pink {
  0% { box-shadow: 0 0 4px rgba(216, 27, 96, 0.4); }
  100% { box-shadow: 0 0 12px rgba(216, 27, 96, 0.8); }
}

.blinking-marker {
  animation: glow-pulse-red 0.5s infinite alternate !important;
}

/* ==========================================================================
   RESPONSIVE LAYOUTS
   ========================================================================== */
@media (max-width: 768px) {
  #app {
    flex-direction: column-reverse;
  }
  
  #sidebar {
    width: 100%;
    flex: 0 0 50vh;
    height: 50vh;
    border-right: 0;
    border-top: 1px solid var(--border-color);
  }
  
  #map-container {
    flex: 1;
    height: 50vh;
  }
  
  .map-legend {
    top: 12px;
    bottom: auto;
    right: 12px;
    padding: 6px;
    width: 150px;
  }
  
  .sidebar-content {
    padding: 12px 16px;
  }
}
