:root {
  --color-bg: #f5f6f8;
  --color-panel: #ffffff;
  --color-border: #dfe3e8;
  --color-text: #1c2027;
  --color-text-muted: #5f6672;
  --color-accent: #2f6f4f;
  --color-accent-dark: #234f38;
  --topbar-h: 56px;
  --footer-h: 34px;
  --sidebar-w: 280px;
  --detail-w: 340px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
}

button { font-family: inherit; }

/* ---------------- Topbar ---------------- */

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 16px;
  background: var(--color-accent-dark);
  color: #fff;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
}
.brand-sub {
  font-weight: 400;
  font-size: 0.8rem;
  opacity: 0.75;
  margin-left: 6px;
}

.mainnav { display: flex; gap: 4px; flex: 1; }
.nav-link {
  color: #fff;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  opacity: 0.85;
}
.nav-link.active { background: rgba(255,255,255,0.18); opacity: 1; }
.nav-link.disabled { opacity: 0.4; cursor: default; pointer-events: none; }

.topbar-actions { display: flex; gap: 8px; }

/* ---------------- Layout ---------------- */

.app-layout {
  display: flex;
  height: calc(100vh - var(--topbar-h) - var(--footer-h));
  min-height: 0;
}

.map-main {
  flex: 1;
  min-width: 0;
  position: relative;
}
#map {
  width: 100%;
  height: 100%;
  background: #cfd8dc;
}

.sidebar {
  background: var(--color-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.filter-sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  border-right: 1px solid var(--color-border);
}
.detail-sidebar {
  width: var(--detail-w);
  flex: 0 0 var(--detail-w);
  border-left: 1px solid var(--color-border);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border);
  flex: 0 0 auto;
}
.sidebar-header h2 { margin: 0; font-size: 1rem; }

.sidebar-body {
  padding: 14px;
  overflow-y: auto;
  flex: 1 1 auto;
}

/* ---------------- Buttons ---------------- */

.btn-icon {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.4);
  color: inherit;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.85rem;
}
.sidebar .btn-icon {
  border-color: var(--color-border);
  color: var(--color-text);
  font-size: 1.1rem;
  line-height: 1;
  padding: 4px 9px;
}

.btn-secondary {
  display: block;
  width: 100%;
  margin: 8px 0 16px;
  padding: 8px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-secondary:hover { background: #eceff2; }

.link-btn {
  background: none;
  border: none;
  color: var(--color-accent);
  cursor: pointer;
  padding: 0;
  font-size: 0.8rem;
  text-decoration: underline;
}

.mobile-only { display: none; }

/* ---------------- Filters ---------------- */

.filter-count {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.filter-group { margin-bottom: 18px; }
.filter-group-title {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 6px;
}
.filter-group-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 6px;
}
.filter-group-actions { display: flex; gap: 8px; }

#search-input, #country-search {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.checkbox-list { display: flex; flex-direction: column; gap: 4px; }
.checkbox-list.scrollable { max-height: 220px; overflow-y: auto; border: 1px solid var(--color-border); border-radius: 6px; padding: 6px 8px; }

/* Collapsed-by-default multi-select dropdown: one compact row until opened. */
.multiselect { position: relative; }
.multiselect-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 7px 10px;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--color-text);
}
.multiselect-toggle:hover { background: var(--color-bg); }
.multiselect-toggle .chev { color: var(--color-text-muted); font-size: 0.75rem; margin-left: 8px; }
.multiselect.open .multiselect-toggle { border-color: var(--color-accent); }
.multiselect.open .multiselect-toggle .chev { transform: rotate(180deg); }

.multiselect-panel {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 40;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  padding: 10px;
  max-height: 280px;
  overflow-y: auto;
}
.multiselect.open .multiselect-panel { display: block; }
.multiselect-panel #country-search { margin-bottom: 8px; }
.multiselect-panel .checkbox-list.scrollable { max-height: 200px; border: none; padding: 0; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.85rem;
  cursor: pointer;
}
.checkbox-row input { flex: 0 0 auto; }

/* ---------------- Detail panel ---------------- */

.detail-placeholder { color: var(--color-text-muted); font-size: 0.9rem; }

.detail-title { font-size: 1.15rem; font-weight: 700; }
.detail-subtitle { color: var(--color-text-muted); margin-bottom: 12px; font-size: 0.9rem; }

.detail-section { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--color-border); }
.detail-section h3 {
  margin: 0 0 6px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 0;
  font-size: 0.87rem;
  border-bottom: 1px dashed #eef0f2;
}
.detail-label { color: var(--color-text-muted); flex: 0 0 auto; }
.detail-value { text-align: right; }

/* ---------------- Hover card ---------------- */

.hover-card {
  position: fixed;
  z-index: 1200;
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
  padding: 10px 12px;
  font-size: 0.8rem;
  max-width: 260px;
  pointer-events: none;
}
.hc-title { font-weight: 700; margin-bottom: 4px; }
.hc-row { padding: 1px 0; color: var(--color-text); }
.hc-row strong { color: var(--color-text-muted); font-weight: 600; }

/* ---------------- Markers & labels ---------------- */

.ree-marker-icon { filter: drop-shadow(0 1px 2px rgba(0,0,0,0.45)); }
.ree-marker-icon.selected-marker { filter: drop-shadow(0 0 0 2px #000) drop-shadow(0 2px 4px rgba(0,0,0,0.5)); }

.leaflet-tooltip.ree-label {
  background: rgba(255,255,255,0.88);
  border: none;
  box-shadow: none;
  padding: 1px 5px;
  font-size: 11px;
  font-weight: 600;
  color: #1c2027;
  border-radius: 3px;
}
.leaflet-tooltip.ree-label::before { display: none; }
#map.labels-hidden .leaflet-tooltip.ree-label { display: none; }

/* ---------------- Legend ---------------- */

.legend-control {
  background: var(--color-panel);
  border-radius: 8px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.3);
  font-size: 0.78rem;
  overflow: hidden;
  max-width: 300px;
}
.legend-toggle {
  width: 100%;
  border: none;
  background: var(--color-bg);
  padding: 7px 10px;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  text-align: left;
}
.legend-body {
  display: flex;
  gap: 16px;
  padding: 10px 12px;
}
.legend-col-title { font-weight: 700; margin-bottom: 5px; color: var(--color-text-muted); }
.legend-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; white-space: nowrap; }
.legend-swatch { width: 16px; height: 16px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0,0,0,0.25); }

/* ---------------- Footer ---------------- */

.app-footer {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  background: var(--color-panel);
}

/* ---------------- Modal ---------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: #fff;
  border-radius: 10px;
  max-width: 720px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-border);
}
.modal-header h2 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 16px 18px; overflow-y: auto; font-size: 0.88rem; }

.data-notes-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 0.82rem; }
.data-notes-table th, .data-notes-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}
.data-notes-table th { color: var(--color-text-muted); font-size: 0.75rem; text-transform: uppercase; }

.load-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #b3261e;
  padding: 24px;
  text-align: center;
}

/* ---------------- Mobile ---------------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1400;
  display: none;
}

@media (max-width: 900px) {
  .mobile-only { display: inline-block; }

  .scrim.open { display: block; }

  .filter-sidebar, .detail-sidebar {
    position: fixed;
    top: var(--topbar-h);
    bottom: var(--footer-h);
    width: min(85vw, 340px);
    flex-basis: auto;
    z-index: 1500;
    box-shadow: 0 0 24px rgba(0,0,0,0.25);
    transition: transform 0.25s ease;
  }
  .filter-sidebar { left: 0; transform: translateX(-105%); }
  .filter-sidebar.open { transform: translateX(0); }

  .detail-sidebar { right: 0; transform: translateX(105%); }
  .detail-sidebar.open { transform: translateX(0); }

  .brand-sub { display: none; }
  .mainnav { flex: 0; }
}
