:root {
  --arafat: #0e7c7b;
  --arafat-dark: #095958;
  --mina: #c2410c;
  --mina-dark: #9a3412;
  --bg: #0f172a;
  --panel: rgba(15, 23, 42, 0.92);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --radius: 10px;
  --shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.45);
  --topbar-h: 64px;
  --side-w: 320px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "IBM Plex Sans Arabic", "Noto Sans Arabic", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-columns: var(--side-w) 1fr;
  grid-template-areas:
    "topbar topbar"
    "filters map";
}

/* topbar */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: linear-gradient(180deg, #052723 0%, #053f3d 100%);
  color: #fff;
  border-bottom: 1px solid var(--panel-border);
  position: relative;
  z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo {
  height: 40px;
  width: auto;
  background: #fff;
  padding: 4px 8px;
  border-radius: 6px;
}
.brand-title {
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-sub {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.75);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.count-pill {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.10);
}
#count {
  font-size: 1.15rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.count-label {
  font-size: 0.78rem;
  color: var(--muted);
}
.filters-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

/* filters sidebar */
.filters {
  grid-area: filters;
  background: var(--panel);
  border-inline-end: 1px solid var(--panel-border);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  font-size: 0.92rem;
}
.filter-group { margin: 0; padding: 0; border: 0; }
.filter-group legend {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
  padding: 0;
}
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  cursor: pointer;
  user-select: none;
  font-size: 0.85rem;
  transition: background 0.15s, border-color 0.15s;
}
.chip input {
  appearance: none;
  width: 0;
  height: 0;
  margin: 0;
}
.chip:hover { border-color: rgba(255, 255, 255, 0.24); }
.chip:has(input:checked) {
  background: var(--accent);
  color: #042331;
  border-color: var(--accent);
  font-weight: 600;
}
.chip-arafat:has(input:checked) { background: var(--arafat); color: #fff; border-color: var(--arafat); }
.chip-mina:has(input:checked) { background: var(--mina); color: #fff; border-color: var(--mina); }

/* count badge appended to site / kind chips */
#site-chips .chip span[data-count]::after,
#kind-chips .chip span[data-count]::after {
  content: " (" attr(data-count) ")";
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  opacity: 0.85;
  margin-inline-start: 2px;
}

.chip-hospital:has(input:checked) {
  background: #b91c1c;
  color: #fff;
  border-color: #b91c1c;
}

#search {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
}
#search::placeholder { color: var(--muted); }
#search:focus {
  outline: none;
  border-color: var(--accent);
}
.reset-btn {
  margin-top: auto;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  font: inherit;
  cursor: pointer;
}
.reset-btn:hover { background: rgba(255, 255, 255, 0.14); }

/* map */
#map {
  grid-area: map;
  background: #1e293b;
}

/* pin */
.pin {
  position: relative;
  width: 22px;
  height: 22px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.pin-arafat { background: var(--arafat); }
.pin-mina { background: var(--mina); }
.pin-hospital::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  background: #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

/* popup — match the dark theme + Arabic */
.leaflet-popup-content-wrapper {
  background: #0b1726;
  color: var(--text);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: #0b1726; }
.leaflet-popup-content {
  margin: 12px 14px;
  font-family: inherit;
  direction: rtl;
  min-width: 220px;
}
.leaflet-popup-close-button {
  inset-inline-end: auto;
  inset-inline-start: 6px;
  color: var(--muted) !important;
}
.popup-title {
  font-weight: 700;
  font-size: 1rem;
  margin: 0 0 8px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.popup-title .badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-weight: 500;
}
.popup-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 0.85rem;
  margin: 0 0 10px;
}
.popup-grid dt { color: var(--muted); }
.popup-grid dd { margin: 0; }
.popup-grid dd[dir="ltr"] { text-align: start; }
.popup-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.popup-actions a, .popup-actions button {
  font: inherit;
  font-size: 0.82rem;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.popup-actions a:hover, .popup-actions button:hover {
  background: rgba(255, 255, 255, 0.14);
}
.popup-actions .primary {
  background: var(--accent);
  color: #042331;
  border-color: var(--accent);
  font-weight: 600;
}

/* legend */
.legend {
  position: absolute;
  inset-inline-end: 16px;
  bottom: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 500;
  box-shadow: var(--shadow);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.legend-arafat { background: var(--arafat); }
.legend-mina { background: var(--mina); }

/* leaflet layer-switcher control — RTL friendly */
.leaflet-control-layers {
  background: var(--panel) !important;
  color: var(--text);
  border: 1px solid var(--panel-border) !important;
  border-radius: 8px !important;
  box-shadow: var(--shadow);
}
.leaflet-control-layers-expanded { padding: 10px 12px; }
.leaflet-control-layers label { font-size: 0.88rem; }
.leaflet-control-attribution {
  background: rgba(15, 23, 42, 0.78) !important;
  color: var(--muted) !important;
  font-size: 11px !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }

/* mobile */
@media (max-width: 768px) {
  body {
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-columns: 1fr;
    grid-template-areas: "topbar" "map";
  }
  .filters-toggle { display: inline-flex; }
  .filters {
    grid-area: unset;
    position: fixed;
    top: var(--topbar-h);
    inset-inline-start: 0;
    inset-inline-end: 0;
    max-height: calc(100% - var(--topbar-h));
    z-index: 999;
    border-bottom: 1px solid var(--panel-border);
  }
  .filters[hidden] { display: none; }
  .brand-title { font-size: 0.95rem; }
  .brand-sub { font-size: 0.7rem; }
}
