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

:root {
  --sidebar-w: 360px;
  --detail-w: 380px;
  --header-bg: #1e3a5f;
  --accent: #3b82f6;
  --surface: #ffffff;
  --surface2: #f3f4f6;
  --border: #e5e7eb;
  --text: #111827;
  --text2: #6b7280;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.12);
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }

/* ── App shell ─────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* ── Map ───────────────────────────────────────────────────────────────────── */
#map {
  flex: 1;
  height: 100vh;
  min-height: 0;
  z-index: 0;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 10;
  box-shadow: 2px 0 12px rgba(0,0,0,0.08);
  overflow: hidden;
}

#sidebar-header {
  background: var(--header-bg);
  padding: 16px 14px 12px;
  flex-shrink: 0;
}

/* Logo */
#logo-area {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

#learning-link {
  margin-left: auto;
  background: #7c3aed;
  color: white;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  transition: background 0.2s;
}
#learning-link:hover { background: #6d28d9; }

#logo-icon {
  font-size: 28px;
  background: rgba(255,255,255,0.15);
  border-radius: 10px;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
}

#logo-title {
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
}

#logo-subtitle {
  color: rgba(255,255,255,0.7);
  font-size: 12px;
}

/* Search */
#search-box {
  display: flex;
  align-items: center;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  padding: 0 10px;
  margin-bottom: 12px;
}

.search-icon { font-size: 14px; color: rgba(255,255,255,0.6); margin-right: 6px; }

#search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 14px;
  padding: 9px 0;
}

#search-input::placeholder { color: rgba(255,255,255,0.5); }

#search-clear {
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.2);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  width: 20px; height: 20px;
  font-size: 11px;
  padding: 0;
}

/* Filter buttons */
#filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.filter-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 10px;
  transition: all 0.15s;
  white-space: nowrap;
}

.filter-btn:hover { background: rgba(255,255,255,0.2); color: #fff; }

.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* Municipality + count */
#municipality-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#municipality-filter {
  flex: 1;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  color: #fff;
  font-size: 13px;
  padding: 6px 8px;
  outline: none;
}

#municipality-filter option { background: #1e3a5f; color: #fff; }

#result-count {
  color: rgba(255,255,255,0.6);
  font-size: 12px;
  white-space: nowrap;
}

/* ── Facility list ─────────────────────────────────────────────────────────── */
#facility-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 8px 0;
}

#facility-list::-webkit-scrollbar { width: 6px; }
#facility-list::-webkit-scrollbar-track { background: transparent; }
#facility-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.facility-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.facility-item:hover { background: var(--surface2); }
.facility-item.active { background: #eff6ff; border-left: 3px solid var(--accent); }

.facility-icon {
  flex-shrink: 0;
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  opacity: 0.9;
}

.facility-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.facility-meta {
  font-size: 12px;
  color: var(--text2);
  margin-top: 2px;
}

.facility-programs {
  font-size: 12px;
  color: var(--accent);
  margin-top: 3px;
}

/* ── Detail Panel ──────────────────────────────────────────────────────────── */
#detail-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  width: var(--detail-w);
  max-height: calc(100vh - 24px);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 20;
  overflow-y: auto;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

#detail-panel.hidden {
  transform: translateX(calc(var(--detail-w) + 20px));
  opacity: 0;
  pointer-events: none;
}

#detail-panel::-webkit-scrollbar { width: 6px; }
#detail-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

#detail-close {
  position: absolute;
  top: 12px; right: 12px;
  background: var(--surface2);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  z-index: 1;
  transition: background 0.12s;
}
#detail-close:hover { background: var(--border); }

#detail-content {
  padding: 20px 18px 24px;
}

.detail-type-badge {
  display: inline-block;
  border-radius: 20px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  margin-bottom: 10px;
}

#detail-content h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  padding-right: 30px;
}

.detail-location, .detail-address, .detail-contact {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 5px;
}

.detail-contact a { color: var(--accent); text-decoration: none; }
.detail-contact a:hover { text-decoration: underline; }

.programs-heading {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin: 18px 0 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
}

.program-card {
  background: var(--surface2);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}

.program-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.program-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.program-meta span {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text2);
  font-size: 11px;
  padding: 3px 7px;
}

.program-fee {
  background: #ecfdf5 !important;
  border-color: #a7f3d0 !important;
  color: #065f46 !important;
  font-weight: 600 !important;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  #app { flex-direction: column; }

  #sidebar {
    width: 100%;
    height: 42vh;
    flex-direction: column;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  #map { height: 58vh; }

  #detail-panel {
    width: calc(100vw - 24px);
    top: auto;
    bottom: 12px;
    right: 12px;
    max-height: 55vh;
  }

  #detail-panel.hidden { transform: translateY(calc(55vh + 24px)); }
}
