/* =============================================================================
   Kilifi Atlas — walterland.app
   Sahara-fieldwork theme: cream backgrounds, burnt-umber accents,
   structured typography, polished cards.
   ============================================================================= */

:root {
  --bg-app:        #F3ECDD;
  --bg-panel:      #F7EFE0;
  --bg-panel-alt:  #EDE3CC;
  --border:        #D0BD96;
  --border-soft:   #E4D6B8;
  --text:          #211C12;
  --text-soft:     #4A4232;
  --text-faint:    #8A7C60;
  --brand:         #211C12;
  --brand-soft:    #4A4232;
  --accent:        #C2641E;
  --accent-deep:   #B14A22;
  --ochre:         #E8A53A;
  --shadow-card:   0 1px 2px rgba(33, 28, 18, 0.06), 0 6px 16px rgba(33, 28, 18, 0.10);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; min-height: 100%; }

body {
  font-family: 'Hanken Grotesk', -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  display: flex;
  min-height: 100vh;
  background: var(--bg-app);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* =============================================================================
   SIDEBAR
   ============================================================================= */

#sidebar {
  width: 340px;
  flex-shrink: 0;
  padding: 20px 22px 24px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#sidebar::-webkit-scrollbar { width: 6px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
#sidebar > * { flex-shrink: 0; }

/* ---- Hero / brand ---- */
.hero { padding-bottom: 4px; }
.brand-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}
.brand-mark {
  font-size: 16px;
  color: var(--accent);
  line-height: 1;
}
.brand {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--text-faint);
}
.hero h1 {
  font-family: 'Archivo', sans-serif;
  font-size: 24px;
  font-weight: 800;
  color: var(--brand);
  margin-bottom: 6px;
  letter-spacing: -0.6px;
}
.tagline {
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1.5;
}

/* ---- CTA card ---- */
.cta {
  display: block;
  text-decoration: none;
  color: inherit;
  background: linear-gradient(135deg, #2A2417 0%, #1A160E 100%);
  color: #F3ECDD;
  padding: 16px 18px;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.cta::before {
  content: '';
  position: absolute;
  top: 0; right: 0; width: 70px; height: 100%;
  background: linear-gradient(90deg, transparent 0%, rgba(232, 165, 58, 0.22) 100%);
  pointer-events: none;
}
.cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(91, 58, 29, 0.1), 0 8px 18px rgba(91, 58, 29, 0.14);
}
.cta-eyebrow {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--ochre);
  margin-bottom: 8px;
}
.cta-title {
  font-family: 'Archivo', sans-serif;
  font-size: 19px;
  font-weight: 800;
  line-height: 1.04;
  margin-bottom: 8px;
  letter-spacing: -0.4px;
}
.cta-sub {
  font-size: 11.5px;
  color: rgba(243, 236, 221, 0.74);
  line-height: 1.5;
  margin-bottom: 12px;
}
.cta-arrow {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--ochre);
  letter-spacing: 0.2px;
}

/* ---- Start-here block ---- */
.start-here {
  background: var(--bg-panel-alt);
  border-left: 3px solid var(--accent);
  padding: 12px 14px 12px 16px;
  border-radius: 0 6px 6px 0;
}
.start-here h2 {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.3px;
  text-transform: uppercase;
  color: var(--accent-deep);
  margin-bottom: 8px;
}
.start-here ol {
  margin: 0;
  padding-left: 18px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-soft);
}
.start-here li { margin-bottom: 3px; }
.start-here strong { color: var(--brand); font-weight: 600; }

/* ---- Layer groups ---- */
.group h2, .legend h2 {
  font-family: 'Space Mono', monospace;
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  color: var(--text-faint);
  margin-bottom: 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border-soft);
}

.group label {
  display: block;
  font-size: 11.5px;
  padding: 3px 6px 3px 4px;
  margin: 0 -6px 0 -4px;
  cursor: pointer;
  color: var(--text);
  line-height: 1.35;
  border-radius: 4px;
  transition: background 0.1s ease;
}
.group label:hover {
  background: var(--bg-panel-alt);
}
.group input {
  margin-right: 8px;
  vertical-align: -1px;
  accent-color: var(--accent);
  cursor: pointer;
}
.muted {
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 400;
  margin-left: 3px;
}

/* ---- Layers disclosure (collapsed by default — keeps landing page clean) ---- */
.layers-panel {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-panel);
  overflow: hidden;
}
.layers-panel summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 14px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  color: var(--text-soft);
  background: var(--bg-panel-alt);
  transition: background 0.15s ease;
}
.layers-panel summary::-webkit-details-marker { display: none; }
.layers-panel summary:hover { background: #efe4cc; }
.layers-panel summary::after {
  content: '+';
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
  color: var(--accent);
  transition: transform 0.2s ease;
}
.layers-panel[open] summary::after { transform: rotate(45deg); }
.layers-panel[open] summary { border-bottom: 1px solid var(--border-soft); }
.layers-count {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-faint);
  letter-spacing: 0.4px;
  text-transform: none;
  margin-left: auto;
  margin-right: 10px;
}
.layers-label { flex: 0 0 auto; }
.layers-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---- Legend ---- */
.legend h3 {
  font-family: 'Archivo', sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: var(--brand-soft);
  margin: 10px 0 4px;
}
.legend h3:first-of-type { margin-top: 0; }
.legend ul { list-style: none; }
.legend li {
  display: flex;
  align-items: center;
  font-size: 10.5px;
  padding: 3px 0;
  color: var(--text-soft);
  line-height: 1.3;
}
.legend .swatch {
  width: 13px;
  height: 13px;
  border-radius: 2px;
  margin-right: 8px;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.2);
}
.legend .swatch.point {
  border-radius: 50%;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(33, 28, 18, 0.18);
}
.legend .health-public { background: #1f78b4; }
.legend .health-private { background: #fffbf0; border: 2px solid #6a3d9a; }
.legend .health-unknown { background: #6c757d; }
.legend .school { background: #0f6b62; }
.legend .power { background: #c46d3d; }
.line-swatch {
  width: 22px;
  height: 0;
  margin-right: 8px;
  flex-shrink: 0;
  border-top: 5px solid #fffaf0;
  box-shadow: 0 0 0 1px rgba(33, 28, 18, 0.12);
  position: relative;
}
.line-swatch::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -4px;
  border-top: 2px solid currentColor;
}
.line-33kv { color: #ff8c00; }
.line-132kv { color: #c1121f; }

/* ---- Footer ---- */
#sidebar footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#sidebar footer small {
  font-size: 10px;
  color: var(--text-faint);
  line-height: 1.55;
}
#sidebar footer small strong { color: var(--brand); font-weight: 600; }

/* =============================================================================
   MAP
   ============================================================================= */

#map {
  flex: 1;
  min-width: 0;
  height: 100vh;
  min-height: 420px;
  position: relative;
}

/* =============================================================================
   POPUP CARDS — restructured as definition lists with type pills
   ============================================================================= */

.maplibregl-popup { z-index: 50; }

.maplibregl-popup-content {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  padding: 0;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(91, 58, 29, 0.18), 0 1px 3px rgba(91, 58, 29, 0.1);
  border: 1px solid var(--border);
  max-width: 290px;
  overflow: hidden;
}

.popup-card { font-size: 12px; line-height: 1.5; color: var(--text); }

.popup-card .pill {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--accent-deep);
  background: rgba(196, 109, 61, 0.13);
  padding: 3px 8px;
  border-radius: 3px;
  margin: 12px 14px 0;
}

.popup-card h3 {
  margin: 6px 14px 2px;
  font-size: 14px;
  font-weight: 700;
  color: var(--brand);
  letter-spacing: -0.1px;
  line-height: 1.3;
}

.popup-card .subtitle {
  margin: 0 14px 10px;
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.4;
}

.popup-card dl {
  margin: 0;
  padding: 10px 14px 12px;
  background: var(--bg-panel-alt);
  border-top: 1px solid var(--border-soft);
  display: grid;
  grid-template-columns: minmax(0, auto) 1fr;
  gap: 4px 14px;
  font-size: 11.5px;
}
.popup-card dt {
  color: var(--text-faint);
  font-weight: 500;
  font-size: 11px;
}
.popup-card dd {
  margin: 0;
  color: var(--text);
  font-weight: 500;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.popup-card dd b { color: var(--brand); font-weight: 700; }

.popup-card .status {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  text-align: left;
}
.popup-card .yes { color: #2d6a31; background: #e0eedb; }
.popup-card .no  { color: #8b3000; background: #f3dccb; }

.maplibregl-popup-close-button {
  font-size: 18px;
  padding: 4px 8px;
  color: var(--text-faint);
  border-radius: 0 0 0 4px;
}
.maplibregl-popup-close-button:hover {
  background: transparent;
  color: var(--brand);
}

/* =============================================================================
   MAP CONTROLS
   ============================================================================= */

.maplibregl-ctrl-group {
  border-radius: 6px !important;
  box-shadow: var(--shadow-card) !important;
  overflow: hidden;
}
.maplibregl-ctrl-group button {
  background: var(--bg-panel) !important;
  border-bottom: 1px solid var(--border-soft) !important;
}
.maplibregl-ctrl-scale {
  background: rgba(255, 251, 240, 0.85) !important;
  border-color: var(--border) !important;
  font-size: 10px !important;
  color: var(--text-soft) !important;
}

/* =============================================================================
   RESPONSIVE
   ============================================================================= */

@media (max-width: 720px) {
  html, body {
    min-height: 100svh;
    overflow: hidden;
  }

  body {
    flex-direction: column;
    height: 100svh;
  }

  #map {
    order: 1;
    flex: 0 0 52svh;
    width: 100%;
    height: 52svh;
    min-height: 300px;
  }

  #sidebar {
    order: 2;
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    max-height: none;
    padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--border);
    gap: 14px;
    overflow-y: auto;
  }

  .hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
    padding-bottom: 0;
  }

  .brand-row { margin-bottom: 2px; }
  .brand { font-size: 10px; letter-spacing: 1.2px; }
  .hero h1 { font-size: 22px; margin-bottom: 0; }
  .tagline { font-size: 12px; line-height: 1.4; }

  .cta {
    padding: 13px 14px;
  }

  .cta-title {
    font-size: 17px;
  }

  .cta-sub {
    margin-bottom: 9px;
  }

  .start-here {
    padding: 11px 12px 11px 14px;
  }

  .group h2, .legend h2 {
    margin-bottom: 6px;
  }

  .group label {
    min-height: 34px;
    display: flex;
    align-items: center;
    padding: 7px 8px;
    margin: 0 -8px;
    font-size: 12.5px;
  }

  .group input {
    width: 18px;
    height: 18px;
    margin-right: 10px;
    flex: 0 0 auto;
  }

  .legend li {
    min-height: 24px;
    font-size: 11.5px;
  }

  .maplibregl-ctrl-top-right,
  .maplibregl-ctrl-top-left {
    top: 10px !important;
  }

  .maplibregl-ctrl-top-right {
    right: 10px !important;
  }

  .maplibregl-ctrl-bottom-left,
  .maplibregl-ctrl-bottom-right {
    bottom: 10px !important;
  }

  .maplibregl-popup-content {
    max-width: min(292px, calc(100vw - 28px));
  }
}

@media (max-width: 430px) {
  #map {
    flex-basis: 50svh;
    height: 50svh;
    min-height: 280px;
  }

  #sidebar {
    padding-left: 14px;
    padding-right: 14px;
  }

  .hero h1 {
    font-size: 20px;
  }

  .cta-sub,
  .start-here ol {
    font-size: 11px;
  }
}

/* =============================================================================
   SEARCH
   ============================================================================= */

.search-wrap { position: relative; }

#search-input {
  width: 100%;
  font: 500 12.5px 'Hanken Grotesk', sans-serif;
  color: var(--text);
  background: #fffdf6;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(194, 100, 30, 0.14);
}
#search-input::placeholder { color: var(--text-faint); }

#search-results {
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fffdf6;
  box-shadow: var(--shadow-card);
  max-height: 288px;
  overflow-y: auto;
}
.search-hit {
  display: block;
  width: 100%;
  text-align: left;
  cursor: pointer;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border-soft);
  padding: 7px 12px;
  font-family: inherit;
}
.search-hit:last-child { border-bottom: 0; }
.search-hit:hover, .search-hit:focus { background: var(--bg-panel-alt); }
.search-hit strong {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--brand);
}
.search-hit small {
  display: block;
  font-size: 10.5px;
  color: var(--text-faint);
}

/* =============================================================================
   VIEW CONTROLS — basemap chips + terrain toggle
   ============================================================================= */

.basemap-switch {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.basemap-switch .chip {
  flex: 1;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 4px;
  cursor: pointer;
  background: #fffdf6;
  color: var(--text-soft);
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.basemap-switch .chip:hover { border-color: var(--accent); }
.basemap-switch .chip:has(input:checked) {
  background: var(--brand);
  color: #F3ECDD;
  border-color: var(--brand);
}
.basemap-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

/* ---- Feature counts on layer toggles ---- */
.group label .count {
  float: right;
  margin-left: auto;
  font-size: 10px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* =============================================================================
   MAP ACTIONS — share link + image export
   ============================================================================= */

.map-actions {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 20;
  display: flex;
  gap: 6px;
}
.map-actions button {
  font: 700 10.5px 'Space Mono', monospace;
  letter-spacing: 0.4px;
  color: var(--text);
  background: rgba(247, 239, 224, 0.95);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 11px;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.map-actions button:hover {
  background: #fffdf6;
  border-color: var(--accent);
  color: var(--accent-deep);
}

/* ---- Hover tooltip ---- */
.hover-tip { pointer-events: none; z-index: 40; }
.hover-tip .maplibregl-popup-content {
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--brand);
  background: rgba(255, 253, 246, 0.95);
  border-radius: 5px;
  max-width: 260px;
}
.hover-tip .maplibregl-popup-tip { display: none; }

@media (max-width: 720px) {
  .map-actions { top: auto; bottom: 34px; left: 10px; }
  .map-actions button { padding: 6px 9px; font-size: 10px; }
}
