/* ============================================================
   style.css — VFS Map Project: Illinois Food Access Map (POC)
   ============================================================ */

/* ── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── CSS Custom Properties ────────────────────────────────── */
:root {
  --bg-dark:       #0d1117;
  --bg-panel:      #161b22;
  --bg-panel-alt:  #1c2230;
  --bg-card:       #21262d;
  --border-color:  #30363d;
  --text-primary:  #e6edf3;
  --text-secondary:#8b949e;
  --text-muted:    #484f58;
  --accent-green:  #2ecc71;
  --accent-blue:   #3498db;
  --accent-orange: #f39c12;
  --accent-red:    #e74c3c;
  --accent-purple: #9b59b6;
  --shadow:        0 4px 20px rgba(0,0,0,0.4);
  --radius:        10px;
  --radius-sm:     6px;
  --sidebar-width: 320px;
  --header-height: 48px;
  --transition:    0.2s ease;
}

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.5;
}

/* ── Map Container ────────────────────────────────────────── */
#map {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  bottom: 0;
  z-index: 1;
  background: #1a1f2e;
  transition: left var(--transition);
}

/* Leaflet attribution styling */
.leaflet-control-attribution {
  background: rgba(22, 27, 34, 0.85) !important;
  color: var(--text-secondary) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--accent-blue) !important; }

/* ── Sidebar ──────────────────────────────────────────────── */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
  transition: width var(--transition), transform var(--transition);
  box-shadow: 4px 0 20px rgba(0,0,0,0.3);
}

#sidebar.collapsed {
  width: 0;
  overflow: hidden;
}

#sidebar.collapsed ~ #map {
  left: 0;
}

/* Sidebar header */
.sidebar-header {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-dark);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.sidebar-subtitle {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Sidebar collapse button */
#sidebar-collapse-btn {
  position: fixed;
  left: var(--sidebar-width);
  top: 50%;
  transform: translateY(-50%);
  z-index: 1001;
  width: 22px;
  height: 44px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: left var(--transition), background var(--transition);
}
#sidebar-collapse-btn:hover { background: var(--bg-card); color: var(--text-primary); }
#sidebar.collapsed ~ #sidebar-collapse-btn { left: 0; }

/* Sidebar scrollable body */
.sidebar-body {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}
.sidebar-body::-webkit-scrollbar { width: 4px; }
.sidebar-body::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

/* ── Control Sections ─────────────────────────────────────── */
.control-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
}

.section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

/* ── Toggle Switches ──────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 8px;
}

.toggle-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.toggle-label .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--text-muted);
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform var(--transition), background var(--transition);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent-green);
  border-color: var(--accent-green);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
  background: #fff;
}

/* Count badge */
.count-badge {
  font-size: 10px;
  font-weight: 600;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 32px;
  text-align: center;
}
.count-badge.badge-empty { color: var(--text-muted); }

/* ── SNAP Bucket Filters ──────────────────────────────────── */
.snap-filters {
  margin: 8px 0 4px 0;
  padding: 8px 10px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.filter-label {
  font-size: 10px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 5px;
  cursor: pointer;
}

.filter-item input[type="checkbox"] {
  accent-color: var(--accent-green);
  width: 13px;
  height: 13px;
  cursor: pointer;
}

.filter-item .filter-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.filter-item-label {
  font-size: 11px;
  color: var(--text-primary);
}

/* ── Legend ───────────────────────────────────────────────── */
.legend-section {
  padding: 10px 14px 12px;
  border-bottom: 1px solid var(--border-color);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,0.15);
}

.legend-text {
  font-size: 11px;
  color: var(--text-primary);
  flex: 1;
}

.legend-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  border-radius: 8px;
}
.badge-counts  { background: rgba(46, 204, 113, 0.15); color: var(--accent-green); border: 1px solid rgba(46,204,113,0.3); }
.badge-no-count{ background: rgba(231, 76, 60, 0.12);  color: var(--accent-red);   border: 1px solid rgba(231,76,60,0.3);  }

/* Health gradient legend */
.health-gradient {
  height: 10px;
  border-radius: 4px;
  margin-bottom: 3px;
}
.health-gradient-labels {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-secondary);
}

/* ── Loading Status ───────────────────────────────────────── */
#loading-status {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  z-index: 2000;
  box-shadow: var(--shadow);
  display: none;
  animation: fadeIn 0.2s ease;
}

/* ── Info Panel ───────────────────────────────────────────── */
#info-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 540px;
  max-width: 92vw;
  max-height: 80vh;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.25s ease;
}

#info-panel.hidden { display: none; }

.info-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.info-panel-title {
  font-size: 14px;
  font-weight: 700;
}

#info-panel-close {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background var(--transition);
}
#info-panel-close:hover { background: var(--bg-card); color: var(--text-primary); }

#info-panel-content {
  overflow-y: auto;
  padding: 14px 18px 18px;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.info-section {
  margin-bottom: 16px;
}

.info-section h4 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.info-section p {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  line-height: 1.6;
}

.info-list {
  list-style: none;
  padding: 0;
}

.info-list li {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 3px 0 3px 14px;
  position: relative;
  line-height: 1.6;
}

.info-list li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--text-muted);
}

.info-poc-banner {
  background: rgba(231, 76, 60, 0.08);
  border: 1px solid rgba(231, 76, 60, 0.25);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.info-poc-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-red);
  margin-bottom: 6px;
}

.info-limitations {
  background: rgba(243, 156, 18, 0.06);
  border: 1px solid rgba(243, 156, 18, 0.2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.info-note {
  font-size: 11px;
  color: var(--text-muted) !important;
  font-style: italic;
}

/* ── Popups ───────────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  background: var(--bg-panel) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: var(--radius) !important;
  color: var(--text-primary) !important;
  box-shadow: var(--shadow) !important;
}

.leaflet-popup-tip { background: var(--bg-panel) !important; }
.leaflet-popup-content { margin: 0 !important; }

.popup-snap, .popup-wic, .popup-health, .popup-combined {
  padding: 12px 14px;
  min-width: 200px;
}

.popup-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.popup-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 3px;
}

.popup-address {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.popup-hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 8px 0;
}

.popup-bucket {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.bucket-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 8px;
  margin-top: 4px;
}
.badge-yes { background: rgba(46,204,113,0.15); color: var(--accent-green); border: 1px solid rgba(46,204,113,0.3); }
.badge-no  { background: rgba(231,76,60,0.12);  color: var(--accent-red);   border: 1px solid rgba(231,76,60,0.3);  }

.popup-note {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.4;
}

.poc-note {
  background: rgba(243,156,18,0.08);
  border: 1px solid rgba(243,156,18,0.2);
  border-radius: var(--radius-sm);
  padding: 5px 7px;
  color: #c0892b;
}

/* Combined score badge */
.popup-score-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  margin: 8px 0;
}
.score-number {
  font-size: 24px;
  font-weight: 800;
  color: #fff;
  line-height: 1;
}
.score-label {
  font-size: 12px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
}

.popup-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin: 6px 0;
}
.popup-table td {
  padding: 3px 2px;
  color: var(--text-secondary);
  vertical-align: top;
}
.popup-table td:last-child { color: var(--text-primary); text-align: right; }

/* ── Cluster Icons ────────────────────────────────────────── */
.cluster-icon {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-family: 'Inter', sans-serif;
  border: 2px solid rgba(255,255,255,0.3);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.cluster-icon span { font-size: 11px; }

.cluster-snap { background: radial-gradient(circle, #27ae60, #1e8449); }
.cluster-wic  { background: radial-gradient(circle, #f39c12, #d68910); }

.cluster-small  { width: 28px; height: 28px; }
.cluster-medium { width: 36px; height: 36px; }
.cluster-large  { width: 44px; height: 44px; }
.cluster-large span { font-size: 13px; }

/* ── Map Header Bar ───────────────────────────────────────── */
#map-header {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--header-height);
  background: rgba(13, 17, 23, 0.90);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-color);
  z-index: 999;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  transition: left var(--transition);
}

#sidebar.collapsed ~ #map-header { left: 0; }

.map-header-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.map-header-divider {
  width: 1px;
  height: 20px;
  background: var(--border-color);
}

.map-header-note {
  font-size: 11px;
  color: var(--text-secondary);
}

.map-header-btn {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  font-family: inherit;
}
.map-header-btn:hover { background: var(--bg-card); color: var(--text-primary); }

/* ── Address Search ───────────────────────────────────────── */
#address-search-container {
  position: fixed;
  top: calc(var(--header-height) + 10px);
  right: 12px;
  z-index: 998;
  width: 260px;
}

#address-search-form {
  display: flex;
  gap: 0;
  box-shadow: var(--shadow);
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-color);
}

#address-search-input {
  flex: 1;
  padding: 8px 10px;
  background: var(--bg-panel);
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  outline: none;
  min-width: 0;
}

#address-search-input::placeholder {
  color: var(--text-muted);
}

#address-search-input:focus {
  background: var(--bg-card);
}

#address-search-btn {
  padding: 8px 14px;
  background: var(--bg-card);
  border: none;
  border-left: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}

#address-search-btn:hover:not(:disabled) {
  background: var(--accent-blue);
  color: #fff;
}

#address-search-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.search-msg {
  font-size: 11px;
  padding: 4px 2px 0;
  min-height: 0;
  color: transparent; /* hidden when empty */
}

.search-msg-error {
  color: var(--accent-red);
}

/* ── Loading Overlay ──────────────────────────────────────── */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(13, 17, 23, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  transition: opacity 0.4s ease;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-color);
  border-top-color: var(--accent-green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  font-size: 14px;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Animations ───────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, -48%); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}

/* ── Responsive: small screens ────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-width: 260px; }
}
@media (max-width: 480px) {
  #sidebar { width: 100%; position: fixed; height: 45%; bottom: 0; top: auto; left: 0; border-right: none; border-top: 1px solid var(--border-color); }
  #map { left: 0; bottom: 45%; }
  #map-header { left: 0; }
}
