:root {
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --primary-dark: #1e3a8a;
  --accent: #ef4444;
  --accent-orange: #f97316;
  --accent-green: #10b981;
  --accent-purple: #8b5cf6;
  --bg: #f0f4ff;
  --surface: #ffffff;
  --surface2: #f8faff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --shadow: 0 4px 24px rgba(30,64,175,0.10);
  --shadow-lg: 0 8px 40px rgba(30,64,175,0.16);
  --radius: 16px;
  --radius-sm: 10px;
}

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

body {
  font-family: 'Montserrat', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── HEADER ─── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 1000;
  box-shadow: 0 2px 12px rgba(30,64,175,0.08);
  flex-shrink: 0;
}

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

.back-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  transition: all 0.2s;
}
.back-btn:hover { background: var(--bg); border-color: var(--primary-light); }

.header-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-title .logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: white;
  font-size: 14px;
}
.header-title h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.header-title span {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

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

.panic-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
  font-family: 'Montserrat', sans-serif;
}
.panic-btn:hover { background: #dc2626; transform: scale(1.02); }

/* ─── MAIN LAYOUT ─── */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── SIDEBAR ─── */
.sidebar {
  width: 360px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-top {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}

/* Search */
.search-box {
  position: relative;
  margin-bottom: 12px;
}
.search-box i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
}
.search-box input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: 'Montserrat', sans-serif;
  background: white;
  outline: none;
  transition: border-color 0.2s;
}
.search-box input:focus { border-color: var(--primary-light); }

/* Filters */
.filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.filter-btn {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: white;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Montserrat', sans-serif;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
}
.filter-btn.active { border-color: currentColor; color: white; }
.filter-btn[data-type="all"].active { background: var(--primary); border-color: var(--primary); color: white; }
.filter-btn[data-type="police"].active { background: #1e40af; border-color: #1e40af; color: white; }
.filter-btn[data-type="crisis"].active { background: var(--accent); border-color: var(--accent); color: white; }
.filter-btn[data-type="psychology"].active { background: var(--accent-green); border-color: var(--accent-green); color: white; }
.filter-btn[data-type="hotline"].active { background: var(--accent-orange); border-color: var(--accent-orange); color: white; }

/* Geo button */
.geo-btn {
  width: 100%;
  margin-top: 10px;
  padding: 9px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--primary-light);
  background: #eff6ff;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Montserrat', sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
}
.geo-btn:hover { background: var(--primary); color: white; }

/* Stats row */
.stats-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.stat-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 10px;
  background: white;
  border-radius: 20px;
  border: 1px solid var(--border);
}
.stat-chip .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
}

/* List */
.services-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.services-list::-webkit-scrollbar { width: 4px; }
.services-list::-webkit-scrollbar-track { background: transparent; }
.services-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.service-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.service-card:hover { border-color: var(--primary-light); box-shadow: var(--shadow); transform: translateY(-1px); }
.service-card.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }

.card-type-bar {
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
}

.card-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-left: 8px;
}

.card-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.card-info { flex: 1; min-width: 0; }
.card-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-region {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}
.card-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

.card-details {
  margin-top: 10px;
  margin-left: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.card-detail {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.card-detail i { width: 14px; text-align: center; color: var(--primary-light); }
.card-detail a { color: var(--primary); text-decoration: none; font-weight: 600; }
.card-detail a:hover { text-decoration: underline; }

.card-actions {
  margin-top: 10px;
  margin-left: 8px;
  display: flex;
  gap: 6px;
}
.card-action-btn {
  flex: 1;
  padding: 6px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Montserrat', sans-serif;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all 0.2s;
}
.card-action-btn.call { border-color: var(--accent-green); color: var(--accent-green); }
.card-action-btn.call:hover { background: var(--accent-green); color: white; }
.card-action-btn.route { border-color: var(--primary-light); color: var(--primary); }
.card-action-btn.route:hover { background: var(--primary); color: white; }

.no-results {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 14px;
}
.no-results i { font-size: 36px; margin-bottom: 12px; display: block; opacity: 0.3; }

/* ─── MAP ─── */
#map {
  flex: 1;
  z-index: 1;
}

/* Leaflet popup custom */
.leaflet-popup-content-wrapper {
  border-radius: 12px !important;
  box-shadow: var(--shadow-lg) !important;
  border: none !important;
  padding: 0 !important;
  overflow: hidden;
}
.leaflet-popup-content {
  margin: 0 !important;
  width: 240px !important;
}
.leaflet-popup-tip-container { display: none; }
.leaflet-popup-close-button {
  top: 8px !important;
  right: 8px !important;
  color: #64748b !important;
  font-size: 18px !important;
  z-index: 10;
}

.popup-inner {
  padding: 16px;
  font-family: 'Montserrat', sans-serif;
}
.popup-type {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  margin-bottom: 8px;
  display: inline-block;
}
.popup-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
  line-height: 1.3;
}
.popup-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.popup-row i { color: var(--primary-light); width: 14px; text-align: center; }
.popup-row a { color: var(--primary); font-weight: 600; text-decoration: none; }
.popup-actions {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}
.popup-btn {
  flex: 1;
  padding: 7px;
  border-radius: 7px;
  border: none;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  font-family: 'Montserrat', sans-serif;
  transition: all 0.2s;
}
.popup-btn.call { background: #ecfdf5; color: #10b981; }
.popup-btn.call:hover { background: #10b981; color: white; }
.popup-btn.route { background: #eff6ff; color: var(--primary); }
.popup-btn.route:hover { background: var(--primary); color: white; }

/* ─── MOBILE ─── */
@media (max-width: 768px) {
  body { 
    overflow: hidden;
    height: 100vh;
  }
  
  header {
    height: 50px;
    padding: 0 12px;
  }
  
  .header-title h1 {
    font-size: 14px;
  }
  
  .header-title span { 
    display: none; 
  }
  
  .back-btn {
    font-size: 12px;
    padding: 4px 10px;
    gap: 4px;
  }
  
  .panic-btn {
    padding: 6px 10px;
    font-size: 11px;
    gap: 4px;
  }
  
  .main { 
    flex-direction: column;
    height: calc(100vh - 50px);
  }
  
  .sidebar { 
    width: 100%;
    height: 45%;
    max-height: 45%;
    border-right: none; 
    border-bottom: 1px solid var(--border); 
    order: 2;
  }
  
  #map { 
    height: 55%;
    flex: none;
    order: 1;
  }
  
  .sidebar-top {
    padding: 10px;
  }
  
  .search-box input {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 8px 10px 8px 32px;
  }
  
  .filters {
    gap: 4px;
  }
  
  .filter-btn {
    font-size: 11px;
    padding: 4px 8px;
  }
  
  .geo-btn {
    font-size: 12px;
    padding: 8px;
    margin-top: 8px;
  }
  
  .stats-row { 
    overflow-x: auto;
    padding: 8px 10px;
    gap: 6px;
  }
  
  .stat-chip {
    font-size: 10px;
    padding: 3px 8px;
    flex-shrink: 0;
  }
  
  .services-list {
    padding: 8px;
    gap: 6px;
  }
  
  .service-card {
    padding: 10px;
  }
  
  .card-icon {
    width: 32px;
    height: 32px;
    font-size: 13px;
  }
  
  .card-name {
    font-size: 14px;
  }
  
  .card-badge {
    font-size: 9px;
  }
  
  .card-detail {
    font-size: 13px;
  }
  
  .card-action-btn {
    padding: 8px;
    font-size: 12px;
    min-height: 40px; /* Better touch target */
  }
}

/* Extra small screens */
@media (max-width: 380px) {
  .filter-btn {
    font-size: 10px;
    padding: 3px 6px;
  }
  
  .header-title h1 {
    font-size: 13px;
  }
  
  .panic-btn span {
    display: none;
  }
  
  .panic-btn i {
    margin: 0;
  }
}

/* ─── DISTANCE BADGE ─── */
.distance-badge {
  font-size: 10px;
  color: var(--accent-green);
  font-weight: 700;
  background: #ecfdf5;
  padding: 1px 6px;
  border-radius: 10px;
  border: 1px solid #a7f3d0;
}

/* Pulse animation for user location */
@keyframes pulse-ring {
  0% { transform: scale(0.8); opacity: 1; }
  100% { transform: scale(2.5); opacity: 0; }
}
.user-marker-pulse {
  position: relative;
  width: 16px; height: 16px;
  background: #3b82f6;
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(59,130,246,0.5);
  animation: pulse-shadow 2s infinite;
}
@keyframes pulse-shadow {
  0% { box-shadow: 0 0 0 0 rgba(59,130,246,0.5); }
  70% { box-shadow: 0 0 0 12px rgba(59,130,246,0); }
  100% { box-shadow: 0 0 0 0 rgba(59,130,246,0); }
}
