/* ==========================================================================
   صيدلية الحداد التعليمية — Minimal Light / موثوق ومطمئن
   ========================================================================== */
:root {
  --primary: #1A8F83;
  --primary-ink: #127068;      /* نسخة أغمق من الأخضر المزرق للنصوص الصغيرة (تباين أفضل) */
  --secondary: #1F5FBF;
  --bg: #FFFFFF;
  --bg-soft: #F5F7FA;
  --text: #1E2A3A;
  --muted: #5A6A7E;
  --line: #E3E8EF;
  --glass: rgba(255, 255, 255, .9);
  --radius: 12px;
  --shadow: 0 10px 32px rgba(30, 42, 58, .13), 0 2px 8px rgba(30, 42, 58, .06);
  --t: .3s;
  --gap: 12px;
  --font: 'Cairo', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-soft);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 3px solid var(--secondary); outline-offset: 2px; }

/* ---------- الهيكل ---------- */
#app { position: fixed; inset: 0; overflow: hidden; background: #e9edf1; }
#map { position: absolute; inset: 0; z-index: 0; direction: ltr; background: #e9edf1; font-family: var(--font); }
#map.leaflet-container { font-family: var(--font); }

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(10px) saturate(1.15);
  backdrop-filter: blur(10px) saturate(1.15);
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: rgba(255, 255, 255, .97); }
}

/* ---------- الترويسة ---------- */
.topbar {
  position: absolute; z-index: 1000;
  top: max(var(--gap), env(safe-area-inset-top));
  inset-inline: max(var(--gap), env(safe-area-inset-left)) max(var(--gap), env(safe-area-inset-right));
  height: 60px; padding: 0 12px;
  display: flex; align-items: center; gap: 12px;
  animation: fade var(--t) ease both;
}
.topbar-emblem { width: 40px; height: 40px; object-fit: contain; flex: none; }
.topbar-text { min-width: 0; flex: 1; }
.topbar h1 {
  margin: 0; font-size: 1.1rem; line-height: 1.3; font-weight: 700; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.lang-btn {
  flex: none; min-width: 64px; height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); font-weight: 700; font-size: .95rem; color: var(--secondary);
  cursor: pointer; transition: background var(--t), border-color var(--t), transform var(--t);
}
.lang-btn:hover { background: var(--bg-soft); border-color: #cfd8e3; }
.lang-btn:active { transform: scale(.97); }

/* ---------- أزرار الخريطة ---------- */
.controls {
  position: absolute; z-index: 1050;     /* فوق بطاقة المعلومات لتظهر قائمة الأنماط فوقها */
  top: calc(max(var(--gap), env(safe-area-inset-top)) + 60px + var(--gap));
  inset-inline-end: max(var(--gap), env(safe-area-inset-right));
  display: flex; flex-direction: column; gap: 10px;
  animation: fade var(--t) ease both;
}
.ctl-group { display: flex; flex-direction: column; position: relative; }
.ctl {
  width: 44px; height: 44px; padding: 0; border: 0; background: transparent;
  display: grid; place-items: center; cursor: pointer;
  color: var(--text); transition: background var(--t), color var(--t);
}
.ctl + .ctl { border-top: 1px solid var(--line); }
.ctl:first-child { border-start-start-radius: var(--radius); border-start-end-radius: var(--radius); }
.ctl:last-child { border-end-start-radius: var(--radius); border-end-end-radius: var(--radius); }
.ctl:hover { background: var(--bg-soft); }
.ctl:active { background: #e9eef4; }
.ctl svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ctl[aria-pressed="true"], .ctl[aria-expanded="true"] { color: var(--primary); }
.ctl:disabled { opacity: .4; cursor: default; }
.ctl .ic-exit { display: none; }
.is-fullscreen .ctl .ic-enter { display: none; }
.is-fullscreen .ctl .ic-exit { display: block; }
.ctl.busy svg { animation: spin 1s linear infinite; color: var(--primary); }

.ctl-wrap { position: relative; }
.layers-pop {
  position: absolute; bottom: 0; inset-inline-end: calc(100% + 10px);
  min-width: 168px; padding: 6px; display: flex; flex-direction: column; gap: 2px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  animation: fade .2s ease both;
}
.layers-pop button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 6px 12px; border: 0; border-radius: 8px; background: transparent; line-height: 1.4;
  text-align: start; font-weight: 600; font-size: .92rem; cursor: pointer;
  transition: background var(--t);
}
.layers-pop button:hover { background: var(--bg-soft); }
.layers-pop button .dot {
  width: 14px; height: 14px; border-radius: 50%; border: 2px solid #b8c3d1; flex: none;
}
.layers-pop button[aria-checked="true"] { color: var(--primary-ink); }
.layers-pop button[aria-checked="true"] .dot { border-color: var(--primary); background: radial-gradient(circle, var(--primary) 0 45%, #fff 50%); }

/* ---------- بطاقة المعلومات ---------- */
.info {
  position: absolute; z-index: 1000;
  bottom: max(var(--gap), env(safe-area-inset-bottom));
  inset-inline: max(var(--gap), env(safe-area-inset-left)) max(var(--gap), env(safe-area-inset-right));
  max-height: min(54vh, 520px); max-height: min(54dvh, 520px);
  overflow-y: auto; overscroll-behavior: contain;
  padding: 12px 16px 8px;
  animation: fade .45s ease .1s both;
}
.info-head { display: flex; gap: 12px; align-items: center; }
.info-logo { width: 96px; height: auto; flex: none; }
.info-head-text { min-width: 0; }
.chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  background: rgba(26, 143, 131, .12); color: var(--primary-ink);
  font-size: .8rem; font-weight: 700;
}
.info-head-text p { margin: 6px 0 0; font-size: .9rem; line-height: 1.55; color: var(--muted); }

.info-row { display: flex; gap: 10px; align-items: flex-start; margin-top: 10px; font-size: .95rem; line-height: 1.5; }
.info-row svg { width: 22px; height: 22px; flex: none; margin-top: 1px; fill: none; stroke: var(--secondary); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.info-row .lbl { display: block; font-size: .75rem; font-weight: 600; color: var(--muted); }
.distance-row { padding: 8px 10px; border-radius: 10px; background: rgba(31, 95, 191, .08); color: var(--text); font-weight: 600; }
.distance-row svg { margin-top: 2px; }

.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btn-primary {
  flex: 1 1 auto; min-height: 50px; padding: 0 20px; border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--primary); color: #fff; text-decoration: none;
  font-size: 1.2rem; font-weight: 700;      /* نص كبير وعريض لضمان التباين على الأخضر المزرق */
  box-shadow: 0 6px 16px rgba(26, 143, 131, .3);
  transition: transform var(--t), box-shadow var(--t), background var(--t);
}
.btn-primary:hover { background: #167f74; box-shadow: 0 8px 20px rgba(26, 143, 131, .38); }
.btn-primary:active { transform: translateY(1px) scale(.99); }
.btn-primary svg { width: 22px; height: 22px; fill: currentColor; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }
[dir="rtl"] .btn-primary svg { transform: scaleX(-1); }
.btn-primary:focus-visible { outline-color: var(--secondary); }
.btn-secondary {
  min-height: 50px; padding: 0 18px; border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--secondary); color: var(--secondary); text-decoration: none;
  font-weight: 700; background: var(--bg); transition: background var(--t);
}
.btn-secondary:hover { background: rgba(31, 95, 191, .07); }

.nearby { margin-top: 6px; }
.nearby-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.nearby h2 { margin: 0; font-size: 1rem; font-weight: 700; }
.nearby-head span { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.near-list {
  list-style: none; margin: 8px -4px 0; padding: 2px 4px 8px;
  display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x proximity;
  scrollbar-width: thin;
}
.near-item { flex: 0 0 auto; scroll-snap-align: start; }
.near-item button {
  display: flex; align-items: center; gap: 10px; min-width: 168px; max-width: 220px;
  padding: 8px 12px 8px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-soft); text-align: start; cursor: pointer;
  transition: background var(--t), border-color var(--t), transform var(--t);
}
.near-item button:hover { background: #fff; border-color: #cbd5e1; }
.near-item button:active { transform: scale(.98); }
.near-ico {
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--c, var(--secondary));
}
.near-ico svg { width: 19px; height: 19px; }
.near-name { display: block; font-size: .85rem; font-weight: 700; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.near-dist { display: block; font-size: .78rem; color: var(--muted); font-weight: 600; margin-top: 1px; }


.nearby-toggle {
  display: grid; place-items: center; width: 100%; height: 30px; padding: 0;
  border: 0; background: transparent; cursor: pointer; color: var(--muted); border-radius: 8px;
}
.nearby-toggle:hover { background: var(--bg-soft); color: var(--text); }
.nearby-toggle svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; transition: transform var(--t); }
.nearby.open .nearby-toggle svg { transform: rotate(180deg); }

/* ---------- رموز الخريطة ---------- */
.mk-wrap { background: none !important; border: 0 !important; }
.mk-pos {
  --d: calc(var(--base, 28px) * var(--scale, 1));
  position: absolute; left: 0; top: 0; width: var(--d); height: var(--d);
  transform: translate(-50%, -50%);
  transition: width var(--t) ease, height var(--t) ease;
}
.mk {
  position: absolute; inset: 0; border-radius: 50%;
  background: var(--c); border: 2px solid #fff;
  box-shadow: 0 3px 10px rgba(20, 30, 50, .35);
  display: grid; place-items: center;
}
.mk svg { width: 58%; height: 58%; }
.mk-pos.main .mk { border-width: 3px; box-shadow: 0 4px 14px rgba(31, 95, 191, .45); }
.pulse {
  position: absolute; inset: 0; border-radius: 50%;
  background: rgba(26, 143, 131, .5);
  animation: pulse 2.6s ease-out infinite;
  pointer-events: none;
}
.mk-label {
  position: absolute; top: calc(100% + 4px); left: 50%; transform: translateX(-50%);
  white-space: nowrap; padding: 2px 9px; border-radius: 999px;
  background: rgba(255, 255, 255, .94); color: var(--text);
  font: 700 12px/1.4 var(--font); unicode-bidi: plaintext;
  box-shadow: 0 2px 8px rgba(20, 30, 50, .22);
  opacity: 0; pointer-events: none; transition: opacity var(--t);
}
.show-labels .mk-label { opacity: 1; }

.me-dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--secondary); border: 3px solid #fff;
  box-shadow: 0 0 0 0 rgba(31, 95, 191, .5), 0 2px 8px rgba(0, 0, 0, .35);
  animation: me-pulse 2.2s ease-out infinite;
}

/* نافذة المعلومات المنبثقة */
.leaflet-popup-content-wrapper { border-radius: var(--radius); box-shadow: var(--shadow); padding: 2px; }
.leaflet-popup-content { margin: 10px 14px; font-family: var(--font); line-height: 1.5; }
.pop { min-width: 150px; max-width: 240px; }
.pop strong { display: block; font-size: .95rem; color: var(--text); }
.pop span { display: block; font-size: .8rem; color: var(--muted); }
.pop a { display: inline-block; margin-top: 6px; font-weight: 700; color: var(--secondary); text-decoration: none; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

/* ---------- تنبيه ---------- */
.toast {
  position: absolute; z-index: 1100; left: 50%; transform: translate(-50%, -8px);
  top: calc(max(var(--gap), env(safe-area-inset-top)) + 60px + var(--gap));
  width: max-content; max-width: min(92vw, 420px);
  padding: 10px 16px; border-radius: var(--radius);
  background: rgba(30, 42, 58, .94); color: #fff; font-size: .9rem; line-height: 1.5; text-align: center;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity var(--t), transform var(--t);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- شاشة التحميل ---------- */
#loader {
  position: fixed; inset: 0; z-index: 3000; background: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px;
  transition: opacity .45s ease, visibility .45s;
}
#loader img { width: min(300px, 68vw); height: auto; }
#loader.done { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-bar { width: 140px; height: 3px; border-radius: 3px; background: #e3eeed; overflow: hidden; position: relative; }
.loader-bar span { position: absolute; top: 0; bottom: 0; width: 45%; background: var(--primary); border-radius: 3px; animation: bar 1.2s ease-in-out infinite; }

.noscript { position: fixed; inset: 0; z-index: 4000; margin: 0; padding: 24px; display: grid; place-items: center; text-align: center; background: #fff; font-family: var(--font); }

/* ---------- حركة ---------- */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0% { transform: scale(1); opacity: .6; } 100% { transform: scale(2.5); opacity: 0; } }
@keyframes me-pulse { 0% { box-shadow: 0 0 0 0 rgba(31, 95, 191, .5), 0 2px 8px rgba(0,0,0,.35); } 100% { box-shadow: 0 0 0 16px rgba(31, 95, 191, 0), 0 2px 8px rgba(0,0,0,.35); } }
@keyframes bar { 0% { inset-inline-start: -45%; } 100% { inset-inline-start: 100%; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .pulse { display: none; }
}

/* ---------- الشاشات الكبيرة ---------- */
@media (min-width: 840px) {
  .info {
    inset-inline-end: auto;
    inset-inline-start: max(16px, env(safe-area-inset-left));
    bottom: max(16px, env(safe-area-inset-bottom));
    width: 440px; max-height: calc(100vh - 160px); max-height: calc(100dvh - 160px);
  }
  .topbar { inset-inline: 16px; max-width: 440px; inset-inline-end: auto; }
  .controls { inset-inline-end: 16px; }
}

@media (max-height: 560px) and (max-width: 839px) {
  .info { max-height: 46vh; }
  .info-logo { display: none; }
}
