/* ============================================================
   BASE LAYOUT
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Segoe UI', Arial, sans-serif;
  background: #1a1a2e;
}

#app {
  display: flex;
  height: 100vh;
}

/* ============================================================
   SIDEBAR TOGGLE BUTTON — flex sibling of #sidebar
   ============================================================ */
#sidebar-toggle {
  align-self: center;
  flex-shrink: 0;
  z-index: 1001;
  background: #0f3460;
  color: #fff;
  border: none;
  border-radius: 0 8px 8px 0;
  width: 22px;
  height: 52px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 2px 0 6px rgba(0,0,0,0.4);
}
#sidebar-toggle:hover { background: #1a5090; }

/* ============================================================
   SIDEBAR
   ============================================================ */
#sidebar {
  width: 280px;
  min-width: 220px;
  background: #16213e;
  color: #e0e0e0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 2px solid #0f3460;
  z-index: 1000;
  transition: width 0.25s ease, min-width 0.25s ease;
}

#sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

/* Filter section */
#filter-section {
  padding: 12px;
  border-bottom: 1px solid #0f3460;
}

#filter-section h2 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #aac4e6;
}

.filter-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.filter-row label {
  font-size: 12px;
  color: #d0d8e8;
}

#score-filter {
  width: 100%;
  accent-color: #4a9eff;
  cursor: pointer;
}

#score-count {
  font-size: 11px;
  color: #7a9bbf;
  min-height: 16px;
}

#sidebar-header {
  background: #0f3460;
  padding: 14px 16px 10px;
}

#sidebar-header h1 {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
}

#sidebar-header p {
  margin: 0;
  font-size: 11px;
  color: #aac4e6;
}

#dash-link {
  display: inline-block;
  margin-top: 8px;
  padding: 5px 10px;
  background: #2563EB;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  text-decoration: none;
  letter-spacing: 0.2px;
}
#dash-link:hover { background: #1d4ed8; }

/* Search */
#search-box {
  padding: 10px 12px;
  border-bottom: 1px solid #0f3460;
  position: relative;
}

#search-input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid #0f3460;
  background: #0f3460;
  color: #fff;
  font-size: 13px;
  outline: none;
}

#search-input::placeholder { color: #7a9bbf; }
#search-input:focus { border-color: #4a9eff; }

#search-results {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  max-height: 200px;
  overflow-y: auto;
}

#search-results li {
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
  color: #e0e0e0;
}
#search-results li:hover { background: #0f3460; }
#search-results .result-presbyter { color: #a96fdb; }

/* Layer toggles */
#layer-section {
  padding: 12px;
  border-bottom: 1px solid #0f3460;
}

#layer-section h2 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #aac4e6;
}

#layer-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  color: #d0d8e8;
}

.toggle-row input[type="checkbox"] {
  accent-color: #4a9eff;
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* Status / Region filter sections */
#status-filter-section,
#region-filter-section,
#quick-filter-section {
  padding: 12px;
  border-bottom: 1px solid #0f3460;
}

#status-filter-section h2,
#region-filter-section h2,
#quick-filter-section h2 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #aac4e6;
}

#status-filter-panel,
#region-filter-panel {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* Score min slider */
#score-min-filter {
  width: 100%;
  accent-color: #4a9eff;
  cursor: pointer;
}

/* Quick filter buttons */
#quick-filter-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.quick-filter-btn {
  background: #0f3460;
  color: #aac4e6;
  border: 1px solid #1a4a8a;
  border-radius: 5px;
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.quick-filter-btn:hover  { background: #1a4a8a; color: #fff; }
.quick-filter-btn.active { background: #2563EB; color: #fff; border-color: #2563EB; }

/* Legend */
#legend-section {
  padding: 12px;
  flex: 1;
  overflow-y: auto;
}

#legend-section h2 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #aac4e6;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 5px;
  color: #d0d8e8;
}

.legend-swatch {
  display: inline-block;
  width: 20px;
  height: 14px;
  border-radius: 3px;
  border: 1.5px solid;
  flex-shrink: 0;
}

.legend-circle {
  display: inline-block;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid;
  flex-shrink: 0;
}

.legend-star {
  display: inline-block;
  width: 20px;
  color: #7b2fbe;
  font-size: 16px;
  text-align: center;
  flex-shrink: 0;
}

.legend-divider {
  border-top: 1px solid #0f3460;
  margin: 6px 0;
}

/* Loading */
#loading-msg {
  font-size: 11px;
  color: #f5c842;
  padding: 6px 12px;
  min-height: 22px;
}

/* ============================================================
   MAP
   ============================================================ */
#map {
  flex: 1;
  height: 100%;
}

/* ============================================================
   POPUPS
   ============================================================ */
.popup-header {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.popup-name {
  font-weight: 700;
  font-size: 14px;
  color: #1a1a2e;
  flex: 1;
}

.presbyter-header { align-items: center; }
.presb-star { color: #7b2fbe; font-size: 18px; }

.popup-sub {
  font-size: 11px;
  color: #666;
  margin-bottom: 6px;
  font-style: italic;
}

.popup-row {
  font-size: 12px;
  margin-bottom: 4px;
  color: #333;
  word-break: break-word;
}

.popup-row a { color: #0056b3; }

.triage-badge {
  background: #1a1a2e;
  color: #fff;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  white-space: nowrap;
}

.status-badge {
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 5px;
  white-space: nowrap;
}

.status-closing { background: #FF6600; color: #fff; }
.status-closed  { background: #FF0000; color: #fff; }

.leaflet-popup-content-wrapper {
  border-radius: 8px;
  box-shadow: 0 3px 14px rgba(0,0,0,0.3);
}

.leaflet-popup-content { margin: 12px 14px; min-width: 220px; }

/* ============================================================
   SECTION LABELS (on map)
   ============================================================ */
.section-label {
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  text-shadow:
    -1px -1px 0 rgba(255,255,255,0.85),
     1px -1px 0 rgba(255,255,255,0.85),
    -1px  1px 0 rgba(255,255,255,0.85),
     1px  1px 0 rgba(255,255,255,0.85);
  pointer-events: none;
  letter-spacing: 0.04em;
}

/* ============================================================
   MULTIPLIER ICON (on map)
   ============================================================ */
.multiplier-icon {
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  font-size: 18px;
  color: #1a8c38;
  text-shadow:
    -1px -1px 0 #fff,
     1px -1px 0 #fff,
    -1px  1px 0 #fff,
     1px  1px 0 #fff,
     0    0   4px rgba(0,0,0,0.4);
  cursor: pointer;
}

.multiplier-popup-icon {
  color: #1a8c38;
  font-size: 16px;
  margin-right: 2px;
}

.legend-triangle {
  display: inline-block;
  width: 20px;
  color: #1a8c38;
  font-size: 15px;
  text-align: center;
  flex-shrink: 0;
}

/* ============================================================
   PRESBYTER ICON (on map)
   ============================================================ */
.presbyter-icon {
  width: 28px;
  height: 28px;
  line-height: 28px;
  text-align: center;
  font-size: 20px;
  color: #7b2fbe;
  text-shadow:
    -1px -1px 0 #fff,
     1px -1px 0 #fff,
    -1px  1px 0 #fff,
     1px  1px 0 #fff,
     0    0   4px rgba(0,0,0,0.5);
  cursor: pointer;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 600px) {
  #sidebar { width: 200px; }
  #sidebar-header h1 { font-size: 13px; }
}
