/* --- GLOBAL LAYOUT --- */
body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", "Roboto", Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background-color: #f0f2f5;
}

/* 1. TOP HEADER */
#top-header {
  height: 64px;
  background: linear-gradient(135deg, #00695c 0%, #00897b 100%);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 25px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  z-index: 10;
}
#top-header h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* 2. CONTENT CONTAINER */
#main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* --- SIDEBAR --- */
#sidebar {
  width: 320px;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  z-index: 2;
  box-shadow: 4px 0 15px rgba(0, 0, 0, 0.05);
  border-right: 1px solid #e0e0e0;
}

/* STATS CARDS */
#stats-container {
  background-color: #f8f9fa;
  padding: 20px;
  display: flex;
  gap: 15px;
  border-bottom: 1px solid #e0e0e0;
}
.stat-card {
  background: white;
  border-radius: 12px;
  padding: 15px 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  border-top: 4px solid #ddd;
}
.card-blue {
  border-top-color: #2980b9;
}
.card-red {
  border-top-color: #e74c3c;
}

.stat-icon {
  font-size: 1.2rem;
  margin-bottom: 5px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.user-icon {
  background-color: #ebf5fb;
  color: #2980b9;
}
.hospital-icon {
  background-color: #fdedec;
  color: #e74c3c;
}
.stat-val {
  display: block;
  font-size: 1.2rem;
  font-weight: 700;
  color: #2c3e50;
}
.stat-label {
  font-size: 0.7rem;
  color: #7f8c8d;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* Search Bar */
#search-container {
  padding: 15px 20px;
  background: #ffffff;
  border-bottom: 1px solid #f0f0f0;
  position: relative;
}


.collapsed-search {
  display: none;
}


#district-search {
  width: 100%;
  padding: 10px 40px 10px 15px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #333;
  transition: all 0.2s ease;
  outline: none;
  background-color: #f8f9fa;
}
#district-search:focus {
  border-color: #00695c;
  background-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(0, 105, 92, 0.1);
}
#district-search::placeholder {
  color: #999;
}
#search-icon {
  position: absolute;
  right: 35px;
  top: 50%;
  transform: translateY(-50%);
  color: #7f8c8d;
  pointer-events: none;
}

/* District List */
#district-label {
  padding: 15px 25px;
  background: #ffffff;
  border-bottom: 1px solid #f0f0f0;
  font-weight: 700;
  color: #00695c;
  text-transform: uppercase;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background 0.2s;
}
#district-label:hover {
  background-color: #f8f9fa;
}
#district-arrow {
  transition: transform 0.3s ease;
  display: none; /* Hidden on desktop */
}
#sidebar.collapsed-districts #district-arrow {
  transform: rotate(-90deg);
}
#sidebar.collapsed-districts #district-list-container {
  display: none;
}

#district-list-container {
  flex-grow: 1;
  overflow-y: auto;
}
.district-item {
  padding: 12px 25px;
  border-bottom: 1px solid #f9f9f9;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.95rem;
  color: #555;
  border-left: 4px solid transparent;
}
.district-item:hover {
  background-color: #e0f2f1;
  padding-left: 28px;
  color: #00695c;
  font-weight: 600;
  border-left: 4px solid #00695c;
}
.district-item.active {
  background-color: #b2dfdb;
  border-left: 4px solid #004d40;
  color: #004d40;
  font-weight: 700;
  padding-left: 28px;
}

/* --- MAP --- */
#map {
  flex-grow: 1;
  height: 100%;
  position: relative;
  background-color: #e5e9f2;
}

/* info icon */
#info-icon {
  position: absolute;
  top: 15px;
  left: 15px;
  background-color: #00695c !important;
  color: white !important;
  border-radius: 50% !important;
  width: 30px !important;
  height: 30px !important;
  font-size: 18px !important;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer !important;
  border: 2px solid white !important;
  z-index: 1000;
  transition: all 0.2s ease;
}

#info-icon:hover {
  background-color: #004d40 !important;
  transform: scale(1.1);
}

#info-modal {
  position: absolute;
  top: 17px;
  left: 15px;
  background: white;
  padding: 28px;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  max-width: 480px;
  z-index: 500;
  display: none;
}

#info-modal-closer {
  position: absolute;
  top: 8px;
  right: 10px;
  color: #95a5a6;
  font-size: 1.1rem;
  cursor: pointer;
}

#info-modal h3 {
  margin: 0 0 12px;
  font-size: 1.2rem;
  font-weight: 600;
  color: #1f2937;
}

#info-modal p {
  margin: 0 0 12px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #374151;
}

#info-modal strong {
  font-weight: 600;
  color: #111827;
}

.info-footer {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid #e5e7eb;
}

.info-footer p {
  margin: 4px 0;
  font-size: 0.85rem;
  color: #4b5563;
}

.search-container {
  position: relative;
  padding: 10px;
  border-bottom: 1px solid #ddd;
}

.district-search {
  width: 80%;
  padding: 8px 35px 8px 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
}

/* --- BUTTONS --- */
.ol-control {
  background-color: transparent !important;
  padding: 0 !important;
  border-radius: 0 !important;
}
.ol-control button {
  background-color: #00695c !important;
  color: white !important;
  border-radius: 50% !important;
  width: 40px !important;
  height: 40px !important;
  margin: 5px !important;
  font-size: 16px !important;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2) !important;
  cursor: pointer !important;
  border: 2px solid white !important;
  transition: all 0.2s ease;
  outline: none !important;
}
.ol-control button:hover {
  background-color: #004d40 !important;
  transform: scale(1.1);
}

/* Bottom Left Controls */
.ol-zoom {
  top: auto;
  left: auto;
  bottom: 90px;
  right: 20px;
}
.ol-zoom-extent {
  top: auto;
  left: auto;
  bottom: 30px;
  right: 20px;
}

/* FIXED: Scale Line Position */
.ol-scale-line {
  background: rgba(255, 255, 255, 0.8);
  border-radius: 4px;
  bottom: 38px; /* Aligned vertically with Home button */
  right: 80px; /* Just to the right of the Home button (20px left + 40px button + 20px gap) */
  left: auto; /* IMPORTANT: Prevent stretching */
  padding: 4px 8px;
  color: #333;
  font-weight: 600;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.ol-scale-line-inner {
  border: 1px solid #333;
  border-top: none;
  color: #333;
  font-size: 10px;
}

/* --- LAYER SWITCHER --- */
#layer-switcher {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.95);
  padding: 0;
  border-radius: 12px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  z-index: 100;
  width: 240px;
  backdrop-filter: blur(5px);
  overflow: hidden;
  transition: width 0.3s;
}
#layer-switcher-header {
  padding: 15px 20px;
  background: #ffffff;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid transparent;
  transition: background 0.2s;
  font-weight: 600;
  color: #00695c;
}
#layer-switcher-header:hover {
  background-color: #f8f9fa;
}
#layer-switcher-content {
  padding: 0 20px 20px 20px;
  display: block;
}
.collapsed #layer-switcher-content {
  display: none;
}
.collapsed #layer-switcher-header {
  border-bottom: none;
}
#layer-arrow {
  transition: transform 0.3s ease;
}
.collapsed #layer-arrow {
  transform: rotate(-90deg);
}

/* --- LEGEND --- */
#legend {
  position: absolute;
  bottom: 90px;
  left: 20px;
  background: rgba(255, 255, 255, 0.95);
  padding: 15px;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  width: 170px;
  font-size: 0.8rem;
  z-index: 99;
}
.legend-gradient {
  height: 12px;
  width: 100%;
  margin: 8px 0;
  background: linear-gradient(to right, #ffffff, #ffcccc, #ff0000);
  border-radius: 6px;
  border: 1px solid #ccc;
}
.legend-labels {
  display: flex;
  justify-content: space-between;
  color: #555;
  font-weight: 600;
}

/* Controls */
label {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  cursor: pointer;
  font-size: 0.95rem;
  color: #555;
}
input[type="checkbox"] {
  margin-right: 12px;
  transform: scale(1.2);
  accent-color: #00695c;
  cursor: pointer;
}
hr {
  border: 0;
  border-top: 1px solid #eee;
  margin: 15px 0;
}

/* --- POPUP --- */
.ol-popup {
  position: absolute;
  background-color: white;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  padding: 20px;
  border-radius: 15px;
  border: none;
  bottom: 15px;
  left: -50px;
  min-width: 280px;
  z-index: 1000;
}
.ol-popup-closer {
  text-decoration: none;
  position: absolute;
  top: 12px;
  right: 15px;
  color: #95a5a6;
  font-size: 1.1rem;
  transition: color 0.2s;
  z-index: 2000;
}
.ol-popup-closer:hover {
  color: #e74c3c;
  cursor: pointer;
}

.popup-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 0.9em;
}
.popup-table td {
  padding: 8px 0;
  border-bottom: 1px solid #f5f5f5;
}
.popup-key {
  font-weight: 600;
  color: #555;
  padding-right: 10px;
}
.popup-val {
  text-align: right;
  color: #333;
}

/* --- MOBILE RESPONSIVE STYLES --- */

/* Tablet and Below (768px) */
@media (max-width: 768px) {
  /* Header adjustments */
  #top-header {
    height: auto;
    padding: 12px 15px;
  }
  #top-header h1 {
    font-size: 1.2rem;
    line-height: 1.3;
  }

  /* Stack layout vertically on mobile */
  #main-container {
    flex-direction: column;
  }

  /* Sidebar becomes horizontal scrollable section */
  #sidebar {
    width: 100%;
    max-height: 35vh;
    flex-direction: column;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    border-right: none;
    border-bottom: 1px solid #e0e0e0;
  }

  /* Stats cards in row */
  #stats-container {
    padding: 15px;
    gap: 10px;
  }
  .stat-card {
    padding: 12px 8px;
  }
  .stat-icon {
    font-size: 1rem;
    width: 32px;
    height: 32px;
  }
  .stat-val {
    font-size: 1rem;
  }
  .stat-label {
    font-size: 0.65rem;
  }

  /* Search bar mobile */
  #search-container {
    padding: 12px 15px;
  }
  #district-search {
    padding: 8px 35px 8px 12px;
    font-size: 0.85rem;
  }
  #search-icon {
    right: 28px;
  }

  /* District list scrollable */
  #district-label {
    padding: 12px 15px;
    font-size: 0.8rem;
  }
  #district-arrow {
    display: block; /* Show arrow on mobile */
  }
  #district-list-container {
    max-height: 25vh;
    overflow-y: auto;
  }
  .district-item {
    padding: 10px 15px;
    font-size: 0.9rem;
  }
  .district-item:hover,
  .district-item.active {
    padding-left: 18px;
  }

  /* Map takes remaining space */
  #map {
    flex: 1;
    min-height: 400px;
  }

  /* Layer switcher adjustments */
  #layer-switcher {
    top: 10px;
    right: 10px;
    width: 200px;
    font-size: 0.9rem;
  }
  #layer-switcher-header {
    padding: 12px 15px;
    font-size: 0.9rem;
  }
  #layer-switcher-content {
    padding: 0 15px 15px 15px;
  }
  label {
    font-size: 0.85rem;
    margin-bottom: 10px;
  }

  /* Legend adjustments */
  #legend {
    bottom: 20px;
    right: 10px;
    padding: 12px;
    width: 140px;
    font-size: 0.75rem;
  }

  /* Control buttons smaller */
  .ol-control button {
    width: 36px !important;
    height: 36px !important;
    font-size: 14px !important;
    margin: 3px !important;
  }
  .ol-zoom {
    bottom: 80px;
    left: 10px;
  }
  .ol-zoom-extent {
    bottom: 25px;
    left: 10px;
  }
  .ol-scale-line {
    bottom: 33px;
    left: 60px;
    font-size: 9px;
    padding: 3px 6px;
  }

  /* Popup adjustments */
  .ol-popup {
    padding: 15px;
    min-width: 240px;
    max-width: calc(100vw - 40px);
    left: -120px;
  }
  .popup-table {
    font-size: 0.85em;
  }
  .popup-table td {
    padding: 6px 0;
  }
}

/* Mobile Phones (480px and below) */
@media (max-width: 480px) {
  /* Header compact */
  #top-header {
    padding: 10px 12px;
  }
  #top-header h1 {
    font-size: 1rem;
  }
  #top-header h1 span:last-child {
    font-size: 0.5em;
    margin-top: 1px;
  }

  /* Sidebar more compact */
  #sidebar {
    max-height: 40vh;
  }

  /* Search bar compact */
  #search-container {
    padding: 10px 12px;
  }
  #district-search {
    padding: 7px 32px 7px 10px;
    font-size: 0.8rem;
  }
  #search-icon {
    right: 24px;
    font-size: 0.9rem;
  }

  /* Stats cards stack vertically on very small screens */
  #stats-container {
    flex-direction: column;
    gap: 8px;
    padding: 12px;
  }
  .stat-card {
    flex-direction: row;
    justify-content: flex-start;
    padding: 10px 12px;
    gap: 12px;
  }
  .stat-icon {
    margin-bottom: 0;
  }
  .stat-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }

  /* District list */
  #district-list-container {
    max-height: 22vh;
  }
  .district-item {
    padding: 8px 12px;
    font-size: 0.85rem;
  }

  /* Layer switcher even more compact */
  #layer-switcher {
    width: 180px;
    top: 8px;
    right: 8px;
  }
  #layer-switcher-header {
    padding: 10px 12px;
    font-size: 0.85rem;
  }
  #layer-switcher-content {
    padding: 0 12px 12px 12px;
  }
  label {
    font-size: 0.8rem;
    margin-bottom: 8px;
  }
  input[type="checkbox"] {
    transform: scale(1.1);
  }

  /* Legend compact */
  #legend {
    bottom: 70px;
    right: 8px;
    padding: 10px;
    width: 120px;
    font-size: 0.7rem;
  }
  .legend-gradient {
    height: 10px;
    margin: 6px 0;
  }

  /* Controls very compact */
  .ol-control button {
    width: 32px !important;
    height: 32px !important;
    font-size: 12px !important;
    margin: 2px !important;
    border: 1px solid white !important;
  }
  .ol-zoom {
    bottom: 70px;
    left: 8px;
  }
  .ol-zoom-extent {
    bottom: 20px;
    left: 8px;
  }
  .ol-scale-line {
    bottom: 28px;
    left: 52px;
    font-size: 8px;
    padding: 2px 5px;
  }

  /* Popup mobile optimized */
  .ol-popup {
    padding: 12px;
    min-width: 200px;
    max-width: calc(100vw - 30px);
    left: -100px;
    bottom: 10px;
    border-radius: 12px;
  }
  .ol-popup-closer {
    top: 8px;
    right: 10px;
    font-size: 1rem;
  }
  .popup-table {
    font-size: 0.8em;
  }
  .popup-table td {
    padding: 5px 0;
  }
}

/* Landscape Mobile Optimization */
@media (max-width: 768px) and (orientation: landscape) {
  #sidebar {
    max-height: 50vh;
  }
  #district-list-container {
    max-height: 35vh;
  }
  #map {
    min-height: 300px;
  }
}
