/* =========================================================
   Living map (map.html) — group E
   Leaflet canvas + synced list. Logical properties only; the map canvas itself runs
   dir="ltr" (Leaflet's internals are physical), everything around it mirrors in Arabic.
   ========================================================= */

:root {
  --pin-available: var(--athar-green);
  --pin-adopted: var(--athar-brown);
  --pin-zayed: var(--athar-tan);
  --map-h: clamp(520px, calc(100svh - var(--header-h) - 120px), 820px);
}

/* ---------- hero: a short one (shared .hero-grid), so the map starts in the first screen ---------- */
.map-hero { padding-block: clamp(1.5rem, 3vw, 2.5rem) clamp(1.25rem, 2.5vw, 2rem); }
.map-hero .hero-grid { align-items: end; }
.map-hero .label { margin-block-end: 1rem; }
.map-hero .rule { margin-block-end: 0; }
.map-hero .lead { margin: 0; }
@media (max-width: 960px) {
  .map-hero .hero-grid { row-gap: 1rem; }
}

/* ---------- toolbar: filters (the chips carry the counts) ---------- */
.map-section { position: relative; padding-block-end: clamp(3.5rem, 7vw, 6rem); }
/* the map sits in the same shell as the header and the hero, so every left edge lines up */
.map-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem 2rem; margin-block-end: 1.25rem; }
.map-filters .chip { gap: .5rem; padding-inline: 1rem .55rem; }
.map-filters .chip .count {
  min-width: 1.9rem; height: 1.9rem; padding-inline: .45rem; border-radius: var(--radius-pill);
  display: inline-grid; place-items: center; background: var(--athar-sand); color: var(--athar-brown);
  font-family: var(--font-num); font-weight: 700; font-size: .875rem; line-height: 1;
}
.map-filters .chip[aria-pressed="true"] .count { background: rgba(252, 248, 239, .2); color: var(--athar-cream); }
.map-filters .chip[aria-pressed="true"] .dot { box-shadow: 0 0 0 2px var(--athar-cream); }
.map-filters .chip:hover { border-color: var(--athar-brown); }
.chip-short { display: none; }
/* under the map: what the colours mean (one line), then the "sample trees" caption */
.map-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 2rem; margin-block-start: 1.25rem; }
.map-key { display: flex; flex-wrap: wrap; gap: .5rem 1.75rem; }
.map-key li { display: inline-flex; align-items: center; gap: .55rem; font-size: .9375rem; color: var(--muted); }
.map-key b { color: var(--athar-brown); font-weight: 800; }
.map-key .dot { box-shadow: none; }
html[lang="ar"] .map-key li { font-size: 1rem; }
.map-sample { display: flex; align-items: center; gap: .5rem; font-size: .875rem; color: var(--muted); max-width: 60ch; }
@media (max-width: 620px) {
  .map-key { flex-direction: column; gap: .4rem; }
}
.map-sample .ms { font-size: 1.25rem; color: var(--athar-brown); }
html[lang="ar"] :is(.tcard-meta, .map-sample) { font-size: .9375rem; }

/* colour dots shared by chips, cards and popups */
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; display: inline-block; background: var(--pin-available); box-shadow: 0 0 0 2px var(--athar-ivory); }
.dot.available { background: var(--pin-available); }
.dot.adopted { background: var(--pin-adopted); }
.dot.zayed { background: var(--pin-zayed); }

/* ---------- layout: map + list ---------- */
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) clamp(340px, 28vw, 440px); gap: var(--gap); align-items: stretch; }
.map-layout > * { min-width: 0; }
.map-frame { position: relative; height: var(--map-h); border-radius: 28px; overflow: hidden; background: var(--athar-sand); box-shadow: var(--shadow-card); isolation: isolate; }
.map-canvas { position: absolute; inset: 0; z-index: 0; background: var(--athar-sand); font-family: var(--font-latin); }
html[lang="ar"] .map-canvas { font-family: var(--font-arabic); }

.map-list { height: var(--map-h); display: flex; flex-direction: column; background: var(--athar-ivory); border-radius: 28px; box-shadow: var(--shadow-card); overflow: hidden; }
.map-list-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem 1rem; padding: 1.1rem 1.25rem; border-block-end: 1px solid var(--line); }
.map-list-count { font-weight: 700; color: var(--athar-brown); font-size: .9375rem; }
.map-list-count b { font-family: var(--font-num); font-size: 1.25rem; color: var(--athar-green); margin-inline-end: .15rem; }
.tlist { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: .75rem; display: grid; gap: .5rem; align-content: start; scrollbar-width: thin; scrollbar-color: var(--athar-tan) transparent; }
/* desktop: the list fades out at the bottom, so it reads as "more below", not as cut off */
@media (min-width: 1001px) {
  .tlist {
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 56px), transparent);
    mask-image: linear-gradient(to bottom, #000 calc(100% - 56px), transparent);
    padding-block-end: 56px;
  }
}

/* tablets and phones: the map on top, the list becomes a horizontal rail of cards */
@media (max-width: 1000px) {
  .map-layout { grid-template-columns: minmax(0, 1fr); }
  .map-frame { height: clamp(340px, 56svh, 480px); }
  .map-list { height: auto; background: none; box-shadow: none; border-radius: 0; overflow: visible; }
  .map-list-head { padding: .25rem .25rem .5rem; border: 0; }
  .tlist {
    display: grid; grid-auto-flow: column; grid-auto-columns: min(86%, 360px); align-content: stretch;
    overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scroll-padding-inline: .25rem;
    padding: .25rem .25rem .75rem; gap: .75rem;
  }
  .tlist:has(.tlist-empty) { grid-auto-columns: 100%; }
  .tcard { scroll-snap-align: start; background: var(--athar-ivory); box-shadow: inset 0 0 0 1px var(--line); }
  .tcard:hover, .tcard.is-hover { background: var(--athar-ivory); box-shadow: inset 0 0 0 1.5px var(--athar-tan); }
  .tcard.is-active { background: var(--athar-ivory); box-shadow: inset 0 0 0 2px var(--athar-green); }
  .tlist-loading { grid-auto-flow: column; grid-auto-columns: min(86%, 360px); }
  .tcard { grid-template-columns: 64px minmax(0, 1fr) auto; gap: .75rem; }
  .tcard-img { width: 64px; height: 64px; border-radius: 14px; }
}
/* the jump bar and the chips fade where they run off the edge */
@media (max-width: 768px) {
  .map-jump {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 2.5rem), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 2.5rem), transparent);
  }
  html[dir="rtl"] .map-jump {
    -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 2.5rem), transparent);
    mask-image: linear-gradient(to left, #000 calc(100% - 2.5rem), transparent);
  }
}
@media (max-width: 620px) {
  .map-frame { border-radius: 22px; }
  .map-filters {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-block: 2px;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 2.5rem), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 2.5rem), transparent);
  }
  html[dir="rtl"] .map-filters {
    -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 2.5rem), transparent);
    mask-image: linear-gradient(to left, #000 calc(100% - 2.5rem), transparent);
  }
  .map-filters::-webkit-scrollbar { display: none; }
  .map-filters .chip { flex: none; }
  .chip-long { display: none; }
  .chip-short { display: inline; }
}

/* ---------- tree cards in the list ---------- */
.tcard {
  position: relative; display: grid; grid-template-columns: 84px minmax(0, 1fr) auto; gap: 1rem; align-items: center;
  padding: .65rem; border-radius: 20px; background: transparent; transition: background-color .2s, box-shadow .2s;
}
.tcard:hover, .tcard.is-hover { background: var(--athar-cream); }
.tcard.is-active { background: var(--athar-cream); box-shadow: inset 0 0 0 2px var(--athar-green); }
.tcard-hit { position: absolute; inset: 0; z-index: 1; border: 0; background: transparent; border-radius: inherit; cursor: pointer; padding: 0; }
.tcard-hit:focus-visible { outline-offset: -3px; }
.tcard-img { width: 84px; height: 84px; border-radius: 16px; object-fit: cover; background: var(--athar-sand); }
.tcard-body { min-width: 0; display: grid; gap: .2rem; }
.tcard-kicker { display: flex; align-items: center; gap: .45rem; font-size: .75rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--athar-brown); }
html[lang="ar"] .tcard-kicker { letter-spacing: 0; text-transform: none; font-size: .8125rem; }
.tcard-kicker .dot { width: 10px; height: 10px; box-shadow: none; }
.tcard-title { font-weight: 800; font-size: 1.0625rem; line-height: 1.25; color: var(--athar-green); }
html[lang="ar"] .tcard-title { font-family: var(--font-arabic-display); font-weight: 700; }
.tcard-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .6rem; font-size: .8125rem; color: var(--muted); }
.tcard-meta .tree-id { font-size: .8125rem; }
.tcard-meta .warn { color: var(--warn); font-weight: 700; display: inline-flex; align-items: center; gap: .2rem; }
.tcard-meta .warn .ms { font-size: 1rem; }
.tcard-open {
  position: relative; z-index: 2; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  border: 1.5px solid var(--line); color: var(--athar-brown); text-decoration: none; background: var(--athar-ivory);
  transition: background-color .2s, color .2s, border-color .2s;
}
.tcard-open:hover, .tcard-open:focus-visible { background: var(--athar-green); border-color: var(--athar-green); color: var(--athar-cream); }
.tcard-open .ms { font-size: 1.25rem; }

/* list loading skeleton and empty state */
.tlist-loading { display: grid; gap: .5rem; }
.tlist-loading span { height: 98px; border-radius: 20px; background: linear-gradient(90deg, var(--athar-dune), var(--athar-cream), var(--athar-dune)); background-size: 200% 100%; animation: map-shimmer 1.4s linear infinite; }
@keyframes map-shimmer { to { background-position: -200% 0; } }
.tlist-empty { display: grid; justify-items: center; text-align: center; gap: .75rem; padding: 2.5rem 1.25rem; color: var(--muted); }
.tlist-empty .h4 { color: var(--athar-green); }

/* ---------- map overlays: loading / error, jump-to ---------- */
.map-state {
  position: absolute; inset: 0; z-index: 5; display: grid; place-content: center; justify-items: center; gap: .75rem;
  text-align: center; padding: 2rem; background: var(--athar-sand); color: var(--athar-brown); font-weight: 700;
  transition: opacity .5s var(--ease), visibility .5s;
}
.map-state[hidden] { display: none; }
.map-state.is-done { opacity: 0; visibility: hidden; pointer-events: none; }
.map-state-mark { width: 56px; height: auto; animation: map-breathe 2.4s var(--ease) infinite; }
@keyframes map-breathe { 50% { opacity: .45; transform: scale(.94); } }
.map-state.is-error { background: var(--athar-dune); font-weight: 400; max-width: none; }
.map-state.is-error .h4 { margin-block-start: .25rem; }
.map-state.is-error .btn { margin-block-start: .5rem; }

/* soft notice when only the tiles fail (pins and list keep working) */
.map-note {
  position: absolute; z-index: 4; inset-block-start: 1rem; inset-inline: 4.5rem 1rem; margin-inline: auto; max-width: 420px;
  display: flex; align-items: center; gap: .6rem; padding: .7rem 1rem; border-radius: 16px;
  background: rgba(254, 253, 249, .96); box-shadow: 0 8px 24px rgba(56, 40, 20, .14);
  font-size: .875rem; font-weight: 600; color: var(--athar-brown);
}
.map-note[hidden] { display: none; }
.map-note .ms { font-size: 1.25rem; }
/* phones: one finger scrolls the page, two fingers move the map */
.map-hint {
  position: absolute; z-index: 4; inset: 0; display: flex; align-items: center; justify-content: center; gap: .5rem;
  padding: 2rem; background: rgba(28, 22, 14, .42); color: var(--athar-cream); font-weight: 700; font-size: 1.0625rem; text-align: center;
  opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .3s, visibility .3s;
}
.map-hint.show { opacity: 1; visibility: visible; }

.map-jump {
  position: absolute; z-index: 4; inset-block-end: 1.75rem; inset-inline: 1rem auto; max-width: calc(100% - 2rem);
  display: flex; gap: .35rem; padding: .35rem; border-radius: var(--radius-pill);
  background: rgba(254, 253, 249, .94); box-shadow: 0 8px 24px rgba(56, 40, 20, .14);
  overflow-x: auto; scrollbar-width: none;
}
.map-jump::-webkit-scrollbar { display: none; }
.map-jump[hidden] { display: none; }
.jump {
  flex: none; display: inline-flex; align-items: center; gap: .35rem; min-height: 40px; padding: .35rem .9rem;
  border-radius: var(--radius-pill); border: 0; background: transparent; color: var(--athar-brown);
  font-weight: 700; font-size: .875rem; cursor: pointer; white-space: nowrap;
}
.jump .ms { font-size: 1.15rem; }
.jump:hover { background: var(--athar-dune); }
.jump[aria-pressed="true"] { background: var(--athar-green); color: var(--athar-cream); }
@media (max-width: 620px) {
  .map-jump { inset-block-end: 1.6rem; inset-inline: .6rem; max-width: none; }
  .jump { min-height: 44px; }
}

/* ---------- Leaflet skin ---------- */
.map-canvas .leaflet-tile-pane { filter: sepia(.18) saturate(.7) brightness(1.03); }
.map-canvas.leaflet-container { background: var(--athar-sand); }
.map-canvas .leaflet-container a, .map-canvas a { color: inherit; }
.map-canvas .leaflet-control-zoom { border: 0; border-radius: 16px; overflow: hidden; box-shadow: 0 8px 24px rgba(56, 40, 20, .14); margin: 1rem; }
.map-canvas .leaflet-control-zoom a {
  width: 44px; height: 44px; line-height: 44px; font-size: 1.35rem; font-weight: 400;
  background: rgba(254, 253, 249, .96); color: var(--athar-brown); border-block-end-color: var(--line);
}
.map-canvas .leaflet-control-zoom a:hover { background: var(--athar-dune); }
.map-canvas .leaflet-control-attribution { font-size: 10px; background: rgba(252, 248, 239, .82); color: var(--muted); border-radius: 8px; margin: 0 .4rem .4rem; }
.map-canvas .leaflet-control-attribution a { color: var(--athar-brown); }

/* brand pins: ivory ring, colour by kind, a soft warm shadow */
.pin-wrap { background: none; border: 0; }
.pin {
  display: block; width: 22px; height: 22px; margin: 3px; border-radius: 50%; background: var(--pin-available);
  border: 3px solid var(--athar-ivory); box-shadow: 0 2px 8px rgba(56, 40, 20, .38);
  transition: transform .25s var(--ease), box-shadow .25s;
}
.pin.adopted { background: var(--pin-adopted); }
.pin.zayed { background: var(--pin-zayed); }
.pin.zayed::after { content: ""; display: block; width: 6px; height: 6px; margin: 5px auto 0; border-radius: 50%; background: var(--athar-brown); }
.leaflet-marker-icon:hover .pin, .pin.is-hover { transform: scale(1.18); }
.pin.is-active { transform: scale(1.32); box-shadow: 0 0 0 5px rgba(63, 89, 59, .22), 0 4px 12px rgba(56, 40, 20, .4); }
.pin.adopted.is-active { box-shadow: 0 0 0 5px rgba(104, 73, 37, .22), 0 4px 12px rgba(56, 40, 20, .4); }
.pin.zayed.is-active { box-shadow: 0 0 0 5px rgba(200, 176, 138, .4), 0 4px 12px rgba(56, 40, 20, .4); }
.leaflet-marker-icon:focus-visible { outline: none; }
.leaflet-marker-icon:focus-visible .pin { box-shadow: 0 0 0 3px var(--athar-cream), 0 0 0 6px var(--athar-green); }

/* region pins (below zoom 10): one green disc per area, the count inside, a permanent name label */
.pin-region {
  width: 40px; height: 40px; margin: 2px; border-radius: 50%; display: grid; place-items: center;
  background: var(--athar-green); color: var(--athar-cream); border: 3px solid var(--athar-ivory);
  font: 700 1rem/1 var(--font-num); box-shadow: 0 4px 12px rgba(56, 40, 20, .35);
  transition: transform .25s var(--ease);
}
.pin-region b { font-weight: 700; }
.leaflet-marker-icon:hover .pin-region { transform: scale(1.08); }
.leaflet-marker-icon:focus-visible .pin-region { box-shadow: 0 0 0 3px var(--athar-cream), 0 0 0 6px var(--athar-green); }
.map-canvas .leaflet-tooltip.region-tip {
  padding: .3rem .65rem; border: 0; border-radius: var(--radius-pill); background: rgba(254, 253, 249, .94);
  box-shadow: 0 4px 12px rgba(56, 40, 20, .14); white-space: nowrap;
  font: 700 12px/1.3 var(--font-latin); letter-spacing: var(--track-caps); text-transform: uppercase; color: rgba(104, 73, 37, .7);
}
.map-canvas .leaflet-tooltip.region-tip::before { display: none; }
.region-tip [lang="ar"] { font-family: var(--font-arabic); letter-spacing: 0; text-transform: none; font-size: 13px; }

/* popup card */
.athar-popup .leaflet-popup-content-wrapper { border-radius: 22px; padding: 0; background: var(--athar-ivory); box-shadow: 0 18px 44px rgba(28, 22, 14, .22); overflow: hidden; }
.athar-popup .leaflet-popup-content { margin: 0; width: 260px !important; line-height: 1.45; font-size: 1rem; }
.athar-popup .leaflet-popup-tip { background: var(--athar-ivory); }
.pop { position: relative; font-family: var(--font-latin); color: var(--athar-ink); }
.pop:lang(ar) { font-family: var(--font-arabic); }
.pop-img { width: 100%; height: 132px; object-fit: cover; display: block; background: var(--athar-sand); }
.pop-body { padding: .9rem 1.1rem 1.1rem; display: grid; gap: .3rem; }
.pop-kicker { margin: 0 !important; display: flex; align-items: center; gap: .45rem; font-size: .75rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--athar-brown); }
.pop:lang(ar) .pop-kicker { letter-spacing: 0; text-transform: none; font-size: .8125rem; }
.pop-kicker .dot { width: 10px; height: 10px; box-shadow: none; }
.pop-title { margin: 0 !important; font-weight: 800; font-size: 1.125rem; line-height: 1.25; color: var(--athar-green); }
.pop-meta { margin: 0 !important; display: flex; flex-wrap: wrap; gap: .1rem .6rem; font-size: .8125rem; color: var(--muted); }
.pop .btn { margin-block-start: .6rem; min-height: 44px; color: var(--athar-cream); }
.pop .btn:hover { color: var(--athar-cream); }
.pop-close {
  position: absolute; inset-block-start: .5rem; inset-inline-end: .5rem; z-index: 1; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; border: 0; background: rgba(254, 253, 249, .92); color: var(--athar-brown); cursor: pointer;
  box-shadow: 0 2px 8px rgba(28, 22, 14, .2);
}
.pop-close::before { content: ""; position: absolute; inset: -4px; }
.pop-close .ms { font-size: 1.2rem; }

@media (prefers-reduced-motion: reduce) {
  .map-state-mark, .tlist-loading span { animation: none; }
}
