/* =============================================================
   Jerusalem Shelter Finder — styles.css
   Design: Frank Ruhl Libre (display) + Heebo (UI) + Azeret Mono (data)
   Palette: warm charcoal · cream text · teal action · brick emergency
   ============================================================= */

/* ── Tokens ── */
:root {
  /* Primary action — calm teal, not alarming red */
  --teal:           #3A8FA8;
  --teal-hi:        #4BA3BE;
  --teal-glow:      rgba(58,143,168,0.28);
  --teal-subtle:    rgba(58,143,168,0.12);

  /* Shelter type colors — readable but not harsh */
  --parking-color:  #C4714A;   /* terracotta */
  --public-color:   #5B9EC9;   /* soft blue   */
  --school-color:   #6BA368;   /* sage green  */
  --access-color:   #6BAA8A;   /* soft mint   */

  /* Warm dark backgrounds */
  --bg:         #1A1816;
  --bg-2:       #201E1B;
  --surface:    #272420;
  --surface-2:  #302D29;
  --surface-3:  #3A3733;
  --border:     #3A3733;
  --border-hi:  #4D4A45;

  /* Warm cream text — contrast ratios against --bg: text ~11:1, text-2 ~5.5:1, text-3 ~3.4:1 */
  --text:       #F0EBE3;
  --text-2:     #BDB5AC;
  --text-3:     #8A827A;

  --font-display: 'Frank Ruhl Libre', serif;
  --font-ui:      'Heebo', sans-serif;
  --font-mono:    'Azeret Mono', 'JetBrains Mono', monospace;

  --r:          10px;
  --r-sm:       6px;
  --r-pill:     999px;
  --ease:       0.18s ease;

  /* Layout heights (for flex math) */
  --h-header:   54px;
  --h-tabs:     44px;
  --h-controls: 106px; /* find-btn 52px + filter-row 38px + padding */
  --h-chrome:   calc(var(--h-header) + var(--h-tabs) + var(--h-controls));
}

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

html {
  height: 100%;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

/* KEY FIX: use full-height flex column so #map fills remaining space
   without fragile calc(100dvh - ...) arithmetic */
body {
  height: 100%;
  display: flex;
  flex-direction: column;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow: hidden; /* prevent body scroll; views scroll internally */
  direction: rtl;
}

/* ── Chrome (everything above the map/list) ── */
#chrome {
  flex-shrink: 0;
  z-index: 100;
}

/* ── Header ── */
#top-bar {
  height: var(--h-header);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
}

#app-brand {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

#brand-he {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 900;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -0.01em;
}

#brand-en {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--text-3);
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#count-badge {
  background: var(--surface-3);
  border: 1px solid var(--border-hi);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Offline ── */
#offline-banner {
  background: #5D4037;
  color: #FFCC80;
  text-align: center;
  padding: 7px 16px;
  font-size: 12.5px;
  font-weight: 600;
}

/* ── Tab bar ── */
#tab-bar {
  height: var(--h-tabs);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-2);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: color var(--ease), border-color var(--ease), background var(--ease);
  min-height: 44px;
  letter-spacing: 0.01em;
}

.tab:hover { background: rgba(255,255,255,0.03); color: var(--text); }

.tab.active {
  color: var(--teal-hi);
  border-bottom-color: var(--teal);
}

/* ── Controls (CTA + filters) ── */
#controls {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Find Nearest button */
#find-btn {
  width: 100%;
  height: 50px;
  background: var(--teal);
  color: #fff;
  border: none;
  border-radius: var(--r);
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  box-shadow: 0 4px 20px var(--teal-glow);
  transition: background var(--ease), box-shadow var(--ease), transform 0.1s;
  position: relative;
  overflow: hidden;
}
#find-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0);
  transition: background 0.1s;
}
#find-btn:hover { background: var(--teal-hi); box-shadow: 0 6px 24px var(--teal-glow); }
#find-btn:active { transform: scale(0.98); }
#find-btn:active::after { background: rgba(255,255,255,0.06); }
#find-btn:disabled {
  background: var(--surface-2);
  color: var(--text-2);
  box-shadow: none;
  cursor: not-allowed;
}

.find-icon { flex-shrink: 0; }
.find-text-he { font-size: 15px; }
.find-text-en {
  font-size: 11px;
  font-family: var(--font-mono);
  opacity: 0.8;
  letter-spacing: 0.04em;
}

/* Filter chips */
#filter-row {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  direction: rtl;
  padding-bottom: 1px;
}
#filter-row::-webkit-scrollbar { display: none; }

.chip {
  background: var(--surface);
  border: 1.5px solid var(--border-hi);
  color: var(--text-2);
  border-radius: var(--r-pill);
  padding: 5px 13px;
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all var(--ease);
  min-height: 32px;
  display: flex;
  align-items: center;
}
.chip:hover { border-color: var(--teal); color: var(--text); }
.chip.active {
  background: var(--teal-subtle);
  border-color: var(--teal);
  color: var(--teal-hi);
}

/* ── Main content (flex: grows to fill remaining height) ── */
#main-content {
  flex: 1;
  position: relative;
  overflow: hidden; /* clip; each view handles its own scroll */
}

/* ── Views ── */
.view {
  position: absolute;
  inset: 0;
  display: none;
  overflow: hidden;
}
.view.active {
  display: flex;
  flex-direction: column;
}

/* ── Map ── */
#view-map.active { overflow: hidden; }

/* KEY: #map fills its flex parent completely */
#map {
  flex: 1;
  width: 100%;
  min-height: 0; /* allow flex shrink below content size */
  background: #13110F;
}

/* ── Leaflet overrides (dark theme) ── */
.leaflet-container {
  background: #13110F !important;
  font-family: var(--font-ui) !important;
}

.leaflet-control-zoom a {
  background: var(--surface-2) !important;
  color: var(--text) !important;
  border-color: var(--border-hi) !important;
}
.leaflet-control-zoom a:hover { background: var(--surface-3) !important; }
.leaflet-bar { border: 1px solid var(--border-hi) !important; border-radius: var(--r-sm) !important; box-shadow: 0 4px 16px rgba(0,0,0,0.6) !important; }

.leaflet-popup-content-wrapper {
  background: var(--surface-2) !important;
  color: var(--text) !important;
  border-radius: var(--r) !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.7) !important;
  border: 1px solid var(--border-hi) !important;
  padding: 0 !important;
  overflow: hidden;
}
.leaflet-popup-content { margin: 0 !important; width: auto !important; }
.leaflet-popup-tip { background: var(--surface-2) !important; }
.leaflet-popup-close-button { color: var(--text-2) !important; font-size: 18px !important; top: 8px !important; right: 8px !important; }

/* Popup inner */
.popup-inner {
  padding: 13px 16px 12px;
  min-width: 210px;
  direction: rtl;
}
.popup-name {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 3px;
  padding-left: 22px; /* room for close btn */
}
.popup-address { font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.popup-meta { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 10px; }
.popup-open-detail {
  width: 100%;
  background: var(--teal);
  color: #fff;
  border: none;
  border-radius: var(--r-sm);
  padding: 8px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--ease);
}
.popup-open-detail:hover { background: var(--teal-hi); }

/* Marker user location */
.marker-user {
  background: var(--teal);
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 4px var(--teal-glow);
  animation: user-ring 2s ease-in-out infinite;
}
@keyframes user-ring {
  0%, 100% { box-shadow: 0 0 0 4px var(--teal-glow); }
  50%       { box-shadow: 0 0 0 12px rgba(58,143,168,0); }
}

/* ── List view ── */
#view-list { overflow-y: auto; }

#shelter-list {
  list-style: none;
  padding: 6px 0 80px;
}

.shelter-card {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background var(--ease);
  min-height: 68px;
}
.shelter-card:hover, .shelter-card:focus-visible { background: var(--surface); outline: none; }

.card-pip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.pip-parking { background: var(--parking-color); }
.pip-public  { background: var(--public-color); }
.pip-school  { background: var(--school-color); }

.card-body { flex: 1; min-width: 0; }
.card-name {
  font-family: var(--font-ui);
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-addr {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-access {
  font-size: 13px;
  margin-top: 3px;
  opacity: 0.7;
}

.card-end { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0; }
.dist-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--r-pill);
  direction: ltr;
  white-space: nowrap;
  background: var(--surface-3);
  color: var(--text);
}
.dist-badge.nearest { background: color-mix(in srgb, var(--access-color) 15%, transparent); color: var(--access-color); border: 1px solid color-mix(in srgb, var(--access-color) 30%, transparent); }
.card-arrow { color: var(--text-3); font-size: 16px; line-height: 1; }

/* Empty state */
.empty-state {
  padding: 60px 24px;
  text-align: center;
  color: var(--text-2);
}
.empty-state-icon { font-size: 44px; display: block; margin-bottom: 12px; }
.empty-state-text { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.empty-state-sub  { font-size: 13px; }

/* ── Footer ── */
#footer {
  padding: 16px;
  text-align: center;
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.7;
  border-top: 1px solid var(--border);
  direction: rtl;
}
#footer strong { color: var(--text-2); }
#footer a { color: var(--text-2); text-decoration: none; border-bottom: 1px solid var(--border-hi); }
#footer a:hover { color: var(--text); }

/* ── Detail sheet ── */
#sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
#sheet-backdrop.visible { opacity: 1; pointer-events: auto; }

#detail-sheet {
  position: fixed;
  bottom: 0;
  inset-inline: 0;
  background: var(--surface);
  border-radius: var(--r) var(--r) 0 0;
  z-index: 1000;
  max-height: 82vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -12px 48px rgba(0,0,0,0.7);
  border-top: 1px solid var(--border-hi);
  direction: rtl;
}
#detail-sheet.open { transform: translateY(0); }

.sheet-grip {
  /* Large transparent hit target */
  width: 88px;
  height: 24px;
  margin: 6px auto 0;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sheet-grip::before {
  /* Visual pill only */
  content: '';
  width: 40px;
  height: 4px;
  background: var(--border-hi);
  border-radius: 2px;
  transition: background 0.15s;
}
.sheet-grip:active { cursor: grabbing; }
#detail-sheet.open:hover .sheet-grip::before,
#detail-sheet.open:focus-within .sheet-grip::before {
  background: var(--text-3);
}

#sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 18px 12px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

#sheet-title { flex: 1; min-width: 0; }
#sheet-name {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 3px;
}
#sheet-name-en { font-family: var(--font-mono); font-size: 11px; color: var(--text-2); letter-spacing: 0.02em; }

#sheet-close {
  background: var(--surface-2);
  border: 1px solid var(--border-hi);
  color: var(--text-2);
  width: 34px; height: 34px;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all var(--ease);
}
#sheet-close:hover { background: var(--surface-3); color: var(--text); }

#sheet-body { padding: 14px 18px 20px; }

#sheet-address {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  color: var(--text-2);
  font-size: 13px;
}
#sheet-address svg { flex-shrink: 0; margin-top: 2px; color: var(--text-3); }
#sheet-addr-he { color: var(--text); font-size: 14px; margin-bottom: 2px; }
#sheet-addr-en { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.01em; }

#sheet-badges {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

/* Reusable badge */
.badge {
  padding: 5px 12px;
  border-radius: var(--r-pill);
  font-size: 12.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.badge-parking  { background: color-mix(in srgb, var(--parking-color) 15%, transparent); color: #D4917A; border: 1px solid color-mix(in srgb, var(--parking-color) 30%, transparent); }
.badge-public   { background: color-mix(in srgb, var(--public-color)  15%, transparent); color: #8BBDD6; border: 1px solid color-mix(in srgb, var(--public-color)  30%, transparent); }
.badge-school   { background: color-mix(in srgb, var(--school-color)  15%, transparent); color: #91BC8E; border: 1px solid color-mix(in srgb, var(--school-color)  30%, transparent); }
.badge-capacity { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-hi); font-family: var(--font-mono); }
.badge-access   { background: color-mix(in srgb, var(--access-color)  12%, transparent); color: #8EC9AD; border: 1px solid color-mix(in srgb, var(--access-color) 25%, transparent); }
.badge-noaccess { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

#sheet-distance {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--access-color);
  margin-bottom: 16px;
  display: none;
  align-items: center;
  gap: 7px;
}
#sheet-distance.visible { display: flex; }

#sheet-nav { display: flex; gap: 10px; }

.nav-btn {
  flex: 1;
  height: 48px;
  border-radius: var(--r);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--ease);
  border: none;
}
.nav-btn.waze  { background: #00BFFF; color: #000; }
.nav-btn.waze:hover { background: #00AADD; }
.nav-btn.gmaps { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-hi); }
.nav-btn.gmaps:hover { background: var(--surface-3); }

/* ── Loading spinner ── */
.loading-spinner {
  width: 18px; height: 18px;
  border: 2.5px solid rgba(255,255,255,0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Focus ── */
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; border-radius: 4px; }
button:focus-visible, a:focus-visible { border-radius: var(--r-sm); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 3px; }

/* ── Desktop: constrain width ── */
@media (min-width: 600px) {
  body { align-items: center; }
  #chrome, #main-content {
    width: 100%;
    max-width: 540px;
  }
  #sheet-backdrop { display: none; } /* use inline sheet on desktop */
  #detail-sheet {
    max-width: 540px;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    border-radius: var(--r);
    bottom: 16px;
    inset-inline: unset;
    right: auto;
  }
  #detail-sheet.open { transform: translateX(-50%) translateY(0); }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
