/* ==========================================================================
   صيدلية الحداد التعليمية — تصميم نظيف: خريطة أولاً، وبطاقة سفلية هادئة
   ========================================================================== */
:root {
  --primary: #1A8F83;
  --primary-ink: #0F6B62;
  --primary-soft: #E8F5F3;
  --secondary: #1F5FBF;
  --bg: #FFFFFF;
  --bg-soft: #F4F6F9;
  --text: #17212F;
  --muted: #667689;
  --line: #E8ECF1;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(23, 33, 47, .12), 0 1px 3px rgba(23, 33, 47, .06);
  --t: .25s;
  --gap: 14px;
  --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; }
[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); }

/* ---------- الشريط العلوي ---------- */
.topbar {
  position: absolute; z-index: 1000; pointer-events: none;
  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));
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.brand, .pill-btn {
  pointer-events: auto; background: #fff; box-shadow: var(--shadow);
  border-radius: 999px; height: 44px;
}
.brand { display: flex; align-items: center; gap: 8px; padding: 0 16px 0 14px; min-width: 0; }
.brand img { width: 28px; height: 28px; object-fit: contain; flex: none; }
.brand h1 { margin: 0; font-size: .98rem; font-weight: 700; line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill-btn {
  flex: none; min-width: 44px; padding: 0 16px; border: 0; cursor: pointer;
  font-weight: 700; font-size: .9rem; color: var(--secondary);
  transition: transform var(--t), background var(--t);
}
.pill-btn:hover { background: var(--bg-soft); }
.pill-btn:active { transform: scale(.96); }

/* ---------- أزرار الخريطة ---------- */
.controls {
  position: absolute; z-index: 1050;
  top: calc(max(var(--gap), env(safe-area-inset-top)) + 44px + 12px);
  inset-inline-end: max(var(--gap), env(safe-area-inset-right));
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
}
.ctl-group, .ctl-solo {
  background: var(--bg); box-shadow: var(--shadow); border-radius: 14px;
}
.ctl-group { display: flex; flex-direction: column; overflow: hidden; }
.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:hover { background: var(--bg-soft); }
.ctl-solo { background: var(--bg); box-shadow: var(--shadow); border-radius: 14px; }
.ctl-solo:hover { background: var(--bg-soft); }
.ctl svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ctl[aria-expanded="true"] { color: var(--primary); }
.ctl:disabled { opacity: .4; cursor: default; }
.ctl.busy svg { animation: spin 1s linear infinite; color: var(--primary); }
@media (pointer: coarse) { .zoom-group { display: none; } }

.ctl-wrap { position: relative; }
.layers-pop {
  position: absolute; top: 0; inset-inline-end: calc(100% + 10px);
  min-width: 150px; padding: 6px; display: flex; flex-direction: column; gap: 2px;
  background: var(--bg); border-radius: 14px; box-shadow: var(--shadow);
  animation: fade .18s ease both;
}
.layers-pop button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border: 0; border-radius: 10px; background: transparent;
  text-align: start; font-weight: 600; font-size: .9rem; cursor: pointer; transition: background var(--t);
}
.layers-pop button:hover { background: var(--bg-soft); }
.layers-pop .dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #c3ccd8; 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: 0; inset-inline: 0;
  max-height: 72vh; max-height: 72dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: 8px 18px calc(16px + env(safe-area-inset-bottom));
  background: #fff; border-radius: 24px 24px 0 0;
  box-shadow: 0 -8px 30px rgba(23, 33, 47, .14);
  animation: rise .5s cubic-bezier(.2, .8, .2, 1) .1s both;
}


.peek { display: flex; gap: 14px; align-items: center; }
.info-logo { width: 48px; height: 48px; object-fit: contain; flex: none; padding: 8px; background: var(--primary-soft); border-radius: 14px; }
.peek-text { min-width: 0; display: flex; flex-direction: column; gap: 3px; align-items: flex-start; }
.chip { font-size: .85rem; font-weight: 700; color: var(--primary-ink); }
.addr { font-size: .95rem; font-weight: 600; line-height: 1.5; }
.addr .lbl { display: none; }
.dist { font-size: .82rem; font-weight: 600; color: var(--secondary); }

.actions { display: flex; gap: 10px; margin-top: 14px; }
.btn-primary {
  flex: 1 1 auto; min-height: 52px; padding: 0 20px; border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  background: linear-gradient(120deg, #17A08F 0%, #1A8F83 40%, #1F5FBF 130%); color: #fff; text-decoration: none;
  font-size: 1.1rem; font-weight: 700;
  box-shadow: 0 8px 20px rgba(26, 143, 131, .28);
  transition: transform var(--t), filter var(--t);
}
.btn-primary:hover { filter: brightness(1.06) saturate(1.05); }
.btn-primary:active { transform: scale(.985); }
.btn-primary svg { width: 20px; height: 20px; fill: currentColor; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }
[dir="rtl"] .btn-primary svg { transform: scaleX(-1); }
.btn-secondary {
  min-height: 52px; padding: 0 18px; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-soft); color: var(--text); text-decoration: none; font-weight: 700; transition: background var(--t);
}
.btn-secondary:hover { background: #e9edf2; }

.nearby { margin-top: 6px; }
.nearby-toggle {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  padding: 12px 2px 6px; border: 0; background: transparent; cursor: pointer;
  font-weight: 700; font-size: .9rem; color: var(--muted);
}
.nearby-toggle:hover { color: var(--text); }
.nearby-toggle svg { width: 20px; height: 20px; 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); }

.near-panel { animation: fade .25s ease both; }
.desc { margin: 4px 2px 10px; font-size: .88rem; line-height: 1.7; color: var(--muted); }
.near-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.near-item + .near-item { border-top: 1px solid var(--line); }
.near-item button {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 2px;
  border: 0; background: transparent; text-align: start; cursor: pointer; border-radius: 10px;
  transition: background var(--t);
}
.near-item button:hover { background: var(--bg-soft); }
.near-ico { width: 34px; height: 34px; border-radius: 10px; flex: none; display: grid; place-items: center; background: var(--c, var(--secondary)); }
.near-ico svg { width: 18px; height: 18px; }
.near-text { flex: 1; min-width: 0; }
.near-name { display: block; font-size: .9rem; font-weight: 700; line-height: 1.35; }
.near-dist { flex: none; font-size: .82rem; color: var(--muted); font-weight: 600; }

/* ---------- رموز الخريطة ---------- */
.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: 2.5px solid #fff;
  box-shadow: 0 2px 8px rgba(20, 30, 50, .32);
  display: grid; place-items: center;
}
.mk svg { width: 62%; height: 62%; }
.mk-hit { position: absolute; inset: -9px; border-radius: 50%; }
.mk-pos.main .mk { border: 3px solid var(--primary); background: #fff; box-shadow: 0 4px 14px rgba(26, 143, 131, .5); }
.mk-pos.main .mk img { width: 72%; height: 72%; object-fit: contain; display: block; pointer-events: none; }
.sonar {
  position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  border: 2px solid rgba(255, 255, 255, .95);
  background: radial-gradient(circle, rgba(52, 214, 188, .05) 40%, rgba(26, 143, 131, .55) 100%);
  box-shadow: 0 0 14px rgba(26, 143, 131, .55);
  opacity: 0; transform: scale(1);
  animation: sonar 3.2s cubic-bezier(.15, .6, .3, 1) 4 both;
}
.sonar.s2 { animation-delay: 1.6s; }
.mk-label {
  position: absolute; top: calc(100% + 5px); left: 50%; transform: translateX(-50%);
  white-space: nowrap; padding: 3px 10px; border-radius: 999px;
  background: #fff; color: var(--text); font: 700 12px/1.4 var(--font); unicode-bidi: plaintext;
  box-shadow: 0 2px 8px rgba(20, 30, 50, .2); opacity: 0; pointer-events: none; transition: opacity var(--t);
}
.show-labels .mk-label, .mk-pos.main .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: 14px; box-shadow: var(--shadow); padding: 2px; }
.leaflet-popup-content { margin: 10px 14px; font-family: var(--font); line-height: 1.5; }
.pop { min-width: 140px; max-width: 230px; }
.pop strong { display: block; font-size: .92rem; }
.pop span { display: block; font-size: .82rem; color: var(--muted); }
.pop a { display: inline-block; margin-top: 6px; font-weight: 700; color: var(--secondary); text-decoration: none; }

/* ---------- تنبيه ---------- */
.toast {
  position: absolute; z-index: 1100; left: 50%; transform: translate(-50%, -8px);
  top: calc(max(var(--gap), env(safe-area-inset-top)) + 44px + 12px);
  width: max-content; max-width: min(88vw, 400px); padding: 10px 16px; border-radius: 14px;
  background: rgba(23, 33, 47, .94); color: #fff; font-size: .88rem; 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(280px, 64vw); height: auto; }
#loader.done { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-bar { width: 120px; 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 rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes sonar { 0% { transform: scale(.9); opacity: .9; } 70% { opacity: .25; } 100% { transform: scale(3.2); 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; }
  .sonar { display: none; }
}

/* ---------- الشاشات الكبيرة: البطاقة تطفو كلوحة جانبية ---------- */
@media (min-width: 840px) {
  .info {
    inset-inline: auto; inset-inline-start: 20px; bottom: 20px; width: 400px;
    max-height: calc(100dvh - 120px); border-radius: 22px; padding-bottom: 16px; box-shadow: var(--shadow);
  }
  .sheet-grip { display: none; }
  .info { padding-top: 18px; }
  .topbar { inset-inline: 20px; }
  .controls { inset-inline-end: 20px; }
}
@media (max-height: 520px) and (max-width: 839px) {
  .info { max-height: 60dvh; }
  .info-logo { display: none; }
}

/* ---------- معلومات المسار داخل النافذة ---------- */
.route-info {
  margin-top: 8px; padding: 8px 10px; border-radius: 12px;
  background: linear-gradient(135deg, #E6F6F3, #E6EEFB);
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px;
}
.pop .route-info span { display: inline; }
.pop .ri-label { font-size: .82rem; font-weight: 600; color: var(--muted); }
.pop .ri-time { font-size: 1.05rem; font-weight: 800; color: var(--primary-ink); }
.pop .ri-dist { font-size: .82rem; font-weight: 600; color: var(--secondary); }
.pop .ri-note { display: block; flex-basis: 100%; font-size: .82rem; color: var(--muted); line-height: 1.4; }

/* ---------- بطاقة المعلم والمسار (تحل محل النافذة المنبثقة) ---------- */
.route-view { animation: fade .25s ease both; }
.rv-head { display: flex; align-items: center; gap: 12px; }
.rv-ico {
  width: 46px; height: 46px; border-radius: 14px; flex: none; display: grid; place-items: center;
  background: var(--c, #1F5FBF);
}
.rv-ico svg { width: 24px; height: 24px; }
.rv-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rv-title strong { font-size: 1.05rem; font-weight: 700; line-height: 1.35; }
.rv-title span { font-size: .82rem; color: var(--muted); font-weight: 600; }
.rv-close {
  flex: none; width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--bg-soft);
  display: grid; place-items: center; cursor: pointer; transition: background var(--t);
}
.rv-close:hover { background: #e6ebf1; }
.rv-close svg { width: 18px; height: 18px; fill: none; stroke: var(--text); stroke-width: 2.4; stroke-linecap: round; }

.rv-stats { display: grid; grid-template-columns: 1.3fr 1fr; gap: 10px; margin-top: 14px; }
.stat {
  padding: 12px 14px; border-radius: 16px; display: flex; flex-direction: column; gap: 2px;
  background: var(--primary-soft);
}
.stat .k { font-size: .82rem; font-weight: 600; color: var(--muted); }
.stat .v { font-size: 1.45rem; font-weight: 800; line-height: 1.3; color: var(--primary-ink); }
.stat.alt { background: #EAF1FC; }
.stat.alt .v { color: var(--secondary); }
.route-view.loading .v { opacity: .35; animation: blink 1s ease-in-out infinite alternate; }
.rv-note { margin: 10px 2px 14px; font-size: .82rem; line-height: 1.6; color: var(--muted); }
.route-view .btn-primary { width: 100%; }
@keyframes blink { to { opacity: .8; } }

/* المعلم المختار على الخريطة */
.mk-pos.sel { z-index: 5; }
.mk-pos.sel .mk { box-shadow: 0 0 0 5px rgba(255, 255, 255, .55), 0 3px 12px rgba(20, 30, 50, .4); }
.mk-pos.sel .mk-label { opacity: 1; }

/* ---------- حقوق التصميم (خفيفة) ---------- */
.credit {
  display: flex; align-items: center; gap: 9px; margin-top: 12px; padding: 12px 2px 0;
  border-top: 1px solid var(--line); color: var(--muted); text-decoration: none; font-size: .82rem; font-weight: 600;
}
.credit-logo { flex: none; width: 24px; height: 24px; border-radius: 8px; display: grid; place-items: center; background: #14181F; }
.credit-logo img { width: 12px; height: 14px; display: block; }
.credit-text { flex: 1; min-width: 0; line-height: 1.45; }
.credit-btn { flex: none; font-weight: 700; color: var(--primary-ink); }
.credit-btn::after { content: ' ←'; }
[dir="ltr"] .credit-btn::after { content: ' →'; }
.credit:hover .credit-btn { text-decoration: underline; }

/* ---------- إضافات الجولة الأخيرة ---------- */

.chip-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.status { font-size: .82rem; font-weight: 700; color: #138A4B; }
.status::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; margin-inline-end: 6px; }
.status.closed { color: #B4452F; }

.addr { display: flex; align-items: flex-start; gap: 6px; }
.copy-btn { flex: none; width: 32px; height: 32px; margin: -4px 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; transition: background var(--t); }
.copy-btn:hover { background: var(--bg-soft); }
.copy-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.btn-secondary { width: 52px; padding: 0; flex: none; }
.btn-secondary svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-secondary.wa { color: #1B9E52; }
.btn-secondary.wa svg { stroke: none; fill: currentColor; }

.store-photo { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 14px; margin: 4px 0 10px; background: var(--bg-soft); }

.route-view .btn-link {
  display: flex; align-items: center; justify-content: center; min-height: 44px; margin-top: 4px;
  font-weight: 700; font-size: .9rem; color: var(--secondary); text-decoration: none; border-radius: 12px;
}
.route-view .btn-link:hover { background: var(--bg-soft); }

/* مقبض الورقة السفلية: منطقة لمس أكبر وتلميح بصري */
.sheet-grip { height: 28px; margin: -8px -18px 0; display: grid; place-items: center; cursor: grab; touch-action: none; }
.sheet-grip span { width: 40px; height: 4px; border-radius: 4px; background: #d5dbe3; display: block; }
.info { touch-action: pan-y; }
@media (min-width: 840px) { .sheet-grip { display: none; } }

/* ---------- تعديلات التنسيق النهائية ---------- */
.pill-btn { padding: 0 14px; }
.peek-text { flex: 1; min-width: 0; }
.addr { width: 100%; }
.addr #infoAddress { flex: 1 1 auto; min-width: 0; }
.btn-secondary { width: 48px; }
.btn-primary { padding: 0 14px; font-size: 1.05rem; white-space: nowrap; }
.mk-pos.main .mk-label { top: auto; bottom: calc(100% + 8px); }

/* ---------- شريط التنبيه، زر المتجر، رابط التقييم ---------- */
.notice {
  position: absolute; z-index: 1040;
  top: calc(max(var(--gap), env(safe-area-inset-top)) + 44px + 10px);
  inset-inline-start: max(var(--gap), env(safe-area-inset-right));
  inset-inline-end: calc(max(var(--gap), env(safe-area-inset-left)) + 56px);
  display: flex; align-items: center; gap: 8px; padding: 9px 12px 9px 8px; border-radius: 14px;
  background: #FFF4D6; color: #6B4700; font-weight: 700; font-size: .88rem; line-height: 1.45;
  box-shadow: var(--shadow); animation: fade .3s ease both;
}
.notice span { flex: 1; min-width: 0; }
.notice button { flex: none; width: 30px; height: 30px; border: 0; border-radius: 50%; background: rgba(107, 71, 0, .1); color: inherit; display: grid; place-items: center; cursor: pointer; }
.notice svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
@media (min-width: 840px) { .notice { inset-inline-start: 20px; inset-inline-end: auto; max-width: 420px; } }

.btn-outline {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; margin-top: 10px; min-height: 48px;
  border: 1.5px solid var(--primary); border-radius: 14px; background: #fff; color: var(--primary-ink);
  font-size: 1rem; font-weight: 700; cursor: pointer; transition: background var(--t);
}
.btn-outline:hover { background: var(--primary-soft); }
.btn-outline svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-outline b { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 99px; background: var(--primary); color: #fff; font-size: .8rem; display: inline-grid; place-items: center; }

.review-link { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 0 2px; font-size: .88rem; font-weight: 700; color: var(--muted); text-decoration: none; }
.review-link:hover { color: var(--text); text-decoration: underline; }
