/* ─────────── سامانه هوشمند برنامه‌ریزی مسیر ویزیتور ─────────── */
@font-face { font-family: 'Vazirmatn'; src: url('../fonts/Vazirmatn-Regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Vazirmatn'; src: url('../fonts/Vazirmatn-Medium.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Vazirmatn'; src: url('../fonts/Vazirmatn-Bold.woff2') format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --bg: #f2f5f4;
  --panel: #ffffff;
  --ink: #17242a;
  --ink2: #5b6b72;
  --line: #e2e9e7;
  --primary: #0e7c66;
  --primary-dark: #0a5f4f;
  --primary-soft: #e3f2ee;
  --accent: #f5a623;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --ok: #1e8e5a;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(23, 36, 42, .08);
  --header-h: 60px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}
body {
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  background: var(--bg); color: var(--ink);
  overflow: hidden; font-size: 14px;
  -webkit-text-size-adjust: 100%;
}
button { font-family: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
input, select { font-family: inherit; }
.hidden { display: none !important; }
.muted { color: var(--ink2); }
.small { font-size: 12px; line-height: 1.9; }

/* ── هدر ── */
#topbar {
  height: var(--header-h); display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(0,0,0,.04); position: relative; z-index: 1200; gap: 8px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 38px; height: 38px; border-radius: 12px; background: linear-gradient(135deg, var(--primary), #14a385);
  display: flex; align-items: center; justify-content: center; font-size: 20px; flex: none;
}
.brand h1 { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { font-size: 11px; color: var(--ink2); }
.status-chips { display: flex; gap: 8px; align-items: center; flex: none; }
.chip {
  background: var(--primary-soft); color: var(--primary-dark); border: 1px solid #cfe5df;
  border-radius: 999px; padding: 5px 12px; font-size: 12px; display: inline-flex; gap: 6px; align-items: center;
}
button.chip:hover { background: #d5ebe4; }
.dot { font-size: 10px; }

/* ── چیدمان: نقشه فول‌اسکرین + پنل کشویی ── */
#layout { position: relative; display: block; height: calc(100% - var(--header-h)); }
@supports (height: 100dvh) { #layout { height: calc(100dvh - var(--header-h)); } }
#map-wrap { position: absolute; inset: 0; background: #dfe7e4; }
#map { position: absolute; inset: 0; background: #dfe7e4; }
#panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 50vw; max-width: 640px; min-width: 360px;
  background: var(--panel); border-right: 1px solid var(--line); box-shadow: -10px 0 34px rgba(23,36,42,.18);
  display: flex; flex-direction: column; z-index: 1150;
  transform: translateX(106%); transition: transform .32s cubic-bezier(.25,.8,.3,1);
}
#panel.open { transform: translateX(0); }
.panel-grip { display: none; }
.panel-close {
  position: absolute; top: 10px; left: 10px; z-index: 5; width: 32px; height: 32px; border: 1px solid var(--line);
  border-radius: 10px; background: #f0f5f3; color: var(--ink2); font-size: 15px;
}
.panel-close:hover { background: #e5eeeb; }
.panel-scroll { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 16px 14px calc(14px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }

/* ── کارت‌ها ── */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card h2 { font-size: 13.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.stepnum {
  width: 22px; height: 22px; border-radius: 8px; background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; flex: none;
}
.badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 9px; font-size: 11.5px; }

.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 12px; color: var(--ink2); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: #fbfdfc; font-size: 13.5px; color: var(--ink);
}
.field input:focus, .field select:focus { outline: 2px solid #b5dcd2; border-color: var(--primary); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.checkline { display: flex; align-items: center; gap: 7px; font-size: 12.5px; margin: 8px 0; cursor: pointer; }
.checkline input { accent-color: var(--primary); width: 16px; height: 16px; }
.field-group { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; }
.field-head { font-size: 12px; font-weight: 700; color: var(--primary-dark); margin-bottom: 6px; }
.point-label { font-size: 12px; margin-top: 6px; min-height: 16px; }

.btn { border: none; border-radius: 11px; padding: 10px 14px; font-size: 13.5px; font-weight: 500; transition: .15s; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn.secondary { background: #134e6f; color: #fff; }
.btn.secondary:hover:not(:disabled) { background: #0d3b55; }
.btn.ghost { background: #f0f5f3; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover:not(:disabled) { background: #e5eeeb; }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.big { width: 100%; padding: 12px; font-size: 14.5px; }
.btn.small { padding: 7px 10px; font-size: 12px; border-radius: 9px; }
.btn-row { display: flex; gap: 8px; margin: 8px 0; }
.btn-row.wrap { flex-wrap: wrap; }
.btn-row .btn { flex: 1; }
.btn-row .btn.small { flex: 1 1 auto; }

.progress { margin-top: 10px; }
.bar { height: 6px; border-radius: 99px; background: #e8eeec; overflow: hidden; }
#fetch-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--primary), #14a385); transition: width .3s; border-radius: 99px; }
#fetch-note { margin-top: 5px; }

.note { background: #fff8e8; border: 1px solid #f0e0b2; color: #7a5c12; border-radius: 10px; padding: 9px 11px; font-size: 12px; margin-top: 10px; line-height: 1.9; }
.note.error { background: var(--danger-soft); border-color: #f2c6c0; color: var(--danger); }
.note.warn { background: #fff8e8; }
.note.info { background: #e8f1fb; border-color: #c4d9f2; color: #1c4d8f; }

.results-meta { margin-top: 10px; font-size: 12.5px; background: #f6faf9; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; line-height: 2; }
.results-meta b { color: var(--primary-dark); }

/* ── لیست فروشگاه‌ها ── */
.store-list { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.store-item {
  display: flex; gap: 9px; align-items: flex-start; padding: 9px 10px; border: 1px solid var(--line);
  border-radius: 11px; cursor: pointer; transition: .12s; background: #fff;
}
.store-item:hover { border-color: #bcd9d1; background: #f7fbfa; }
.store-item.selected { border-color: var(--primary); background: var(--primary-soft); }
.store-item input { accent-color: var(--primary); width: 16px; height: 16px; margin-top: 2px; flex: none; }
.store-item .s-body { min-width: 0; flex: 1; }
.store-item .s-name { font-weight: 700; font-size: 12.5px; margin-bottom: 2px; }
.store-item .s-addr { font-size: 11px; color: var(--ink2); line-height: 1.7; }
.store-item .s-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.tag { font-size: 10px; border-radius: 6px; padding: 1px 6px; background: #eef3f2; color: var(--ink2); }
.tag.brand { background: #e3f2ee; color: var(--primary-dark); }
.tag.src-neshan { background: #fff3e0; color: #a3651a; }
.tag.src-osm { background: #e8f1fb; color: #1c4d8f; }
.tag.num { background: var(--primary); color: #fff; }
.empty { padding: 14px; text-align: center; font-size: 12.5px; }

/* ── نقشه ── */
.map-overlay { position: absolute; z-index: 1000; }
#map-search { top: 12px; left: 12px; width: 300px; }
#place-search {
  width: 100%; padding: 10px 12px; border: none; border-radius: 12px; box-shadow: var(--shadow);
  font-size: 13px; background: var(--panel);
}
#search-results {
  margin-top: 6px; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow);
  max-height: 260px; overflow-y: auto; padding: 4px;
}
#search-results .sr-item { padding: 8px 10px; border-radius: 9px; cursor: pointer; font-size: 12px; line-height: 1.7; }
#search-results .sr-item:hover { background: var(--primary-soft); }
#search-results .sr-title { font-weight: 700; font-size: 12.5px; }

#map-tools { top: 12px; right: 12px; display: flex; flex-direction: column; gap: 6px; }
.mapbtn {
  width: 40px; height: 40px; border-radius: 11px; border: none; background: var(--panel);
  box-shadow: var(--shadow); font-size: 15px; color: var(--ink);
}
.mapbtn.active { background: var(--primary); color: #fff; }

.legend { bottom: 24px; right: 12px; background: rgba(255,255,255,.96); border-radius: 12px; box-shadow: var(--shadow); padding: 10px 12px; font-size: 11.5px; max-width: 250px; }
.legend .lg-row { display: flex; align-items: center; gap: 7px; margin: 4px 0; }
.legend .lg-swatch { width: 22px; height: 5px; border-radius: 3px; flex: none; }
.legend .lg-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: 9px; }

.detail {
  bottom: 12px; left: 12px; width: 330px; max-width: calc(100% - 24px);
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; max-height: 46%; overflow-y: auto;
}
.detail h3 { font-size: 14px; margin-bottom: 6px; }
.detail .d-row { display: flex; gap: 6px; font-size: 12px; margin: 3px 0; line-height: 1.8; }
.detail .d-row b { color: var(--ink2); min-width: 84px; font-weight: 500; flex: none; }
.detail .d-actions { display: flex; gap: 8px; margin-top: 10px; }
.detail .d-close { position: absolute; top: 8px; left: 10px; border: none; background: none; font-size: 16px; color: var(--ink2); }
.detail { position: absolute; }
#store-detail { position: absolute; }

#toast-wrap { position: absolute; top: 70px; left: 50%; transform: translateX(-50%); z-index: 1500; display: flex; flex-direction: column; gap: 8px; width: min(420px, 90%); }
.toast { background: #263238; color: #fff; border-radius: 12px; padding: 11px 14px; font-size: 12.5px; box-shadow: var(--shadow); line-height: 1.9; animation: fadein .25s; }
.toast.error { background: #8e2f24; }
.toast.ok { background: var(--ok); }
@keyframes fadein { from { opacity: 0; transform: translateY(-8px); } }

/* ── مسیر / نتایج ── */
#route-summary .rs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.rs-cell { background: #f6faf9; border: 1px solid var(--line); border-radius: 11px; padding: 9px 11px; }
.rs-cell .v { font-size: 16px; font-weight: 700; color: var(--primary-dark); }
.rs-cell .k { font-size: 11px; color: var(--ink2); margin-top: 2px; }
.traffic-box { background: #f4f7ff; border: 1px solid #d4defa; border-radius: 11px; padding: 10px 12px; font-size: 12px; margin-bottom: 10px; line-height: 2; }
.traffic-box .t-late { color: #b3261e; font-weight: 700; }
.compare-box { background: #fdf6ec; border: 1px solid #eddec2; border-radius: 11px; padding: 10px 12px; font-size: 12px; margin-bottom: 10px; line-height: 2.1; }
.compare-box table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.compare-box th, .compare-box td { padding: 4px 6px; text-align: right; border-bottom: 1px solid #f0e6d2; }
.compare-box .saved { color: var(--ok); font-weight: 700; }

.day-card { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; overflow: hidden; }
.day-card.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.day-head { display: flex; align-items: center; gap: 8px; padding: 9px 12px; font-size: 12.5px; font-weight: 700; color: #fff; cursor: pointer; flex-wrap: wrap; }
.day-head .d-stats { font-weight: 400; font-size: 11px; }
.day-show {
  margin-inline-start: auto; border: none; border-radius: 8px; background: rgba(255,255,255,.22); color: #fff;
  font-size: 11px; padding: 4px 9px; cursor: pointer; flex: none;
}
.day-show:hover { background: rgba(255,255,255,.4); }
.day-stops { max-height: 240px; overflow-y: auto; }
.stop-row { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-top: 1px solid #f0f4f3; font-size: 11.5px; cursor: pointer; }
.stop-row:hover { background: #f7fbfa; }
.stop-row .n {
  width: 21px; height: 21px; border-radius: 50%; color: #fff; display: inline-flex; align-items: center;
  justify-content: center; font-size: 10.5px; flex: none;
}
.stop-row .s-main { flex: 1; min-width: 0; }
.stop-row .s-name { font-weight: 700; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stop-row .s-meta { color: var(--ink2); font-size: 10.5px; margin-top: 1px; }
.stop-row .s-eta { color: var(--primary-dark); font-weight: 700; font-size: 11px; flex: none; }

/* ── فنی ── */
#sec-tech h2 { cursor: pointer; }
#sec-tech .chev { margin-inline-start: auto; transition: .2s; }
#sec-tech h2.open .chev { transform: rotate(180deg); }
#tech-content { line-height: 2.1; word-break: break-word; }
#tech-content .terr { color: var(--danger); }
#tech-content .tok { color: var(--ok); }

.weekday-row { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 4px; }
.weekday {
  display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 10px; font-size: 11.5px; cursor: pointer; background: #fbfdfc;
  user-select: none;
}
.weekday:has(input:checked) { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); font-weight: 700; }
.weekday input { accent-color: var(--primary); width: 13px; height: 13px; }

.app-footer { text-align: center; padding: 6px 0 12px; }

/* ── Leaflet RTL fixes ── */
.leaflet-container { font-family: inherit; }
.leaflet-popup-content { font-family: inherit; direction: rtl; text-align: right; }
.leaflet-popup-content b { font-size: 13px; }
.leaflet-control-zoom a { border-radius: 8px !important; }
.store-marker {
  background: var(--primary); color: #fff; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg);
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3); font-weight: 700; font-size: 11px;
}
.store-marker > span { transform: rotate(45deg); }
.store-marker.sel { background: var(--accent); }
.store-marker.dim { background: #8aa39b; }
.origin-marker, .dest-marker {
  width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 15px; background: #134e6f; color: #fff; border: 2.5px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.dest-marker { background: var(--danger); }

.only-mobile { display: none; }

/* ═══════ تبلت (۸۶۱ تا ۱۲۰۰px): پنل کشویی کنار صفحه ═══════ */
@media (min-width: 861px) and (max-width: 1200px) {
  #panel { width: 46vw; max-width: 560px; min-width: 340px; }
}

/* ═══════ موبایل (≤۸۶۰px): نقشه فول‌اسکرین + باتم‌شیت ═══════ */
@media (max-width: 860px) {
  #panel {
    left: 0; right: 0; top: auto; bottom: 0; width: 100%; max-width: none; min-width: 0;
    height: 62%; border-right: none; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(0,0,0,.18); transform: translateY(calc(100% - 56px));
    padding-bottom: env(safe-area-inset-bottom);
  }
  @supports (height: 62dvh) { #panel { height: 62dvh; } }
  #panel.open { transform: translateY(0); }
  .panel-grip {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    height: 56px; cursor: pointer; font-size: 13px; font-weight: 700; color: var(--primary-dark);
    border-bottom: 1px solid var(--line); background: var(--panel); flex: none;
  }
  .panel-grip::before { content: ''; position: absolute; top: 8px; left: 50%; transform: translateX(-50%); width: 44px; height: 5px; border-radius: 99px; background: var(--line); }
  .panel-close { display: none; } /* دستگیره بالای باتم‌شیت، باز/بسته می‌کند */
  .brand h1 { font-size: 12.5px; }
  .subtitle { display: none; }
  .status-chips { gap: 5px; }
  .chip { padding: 4px 9px; font-size: 11px; }
  #map-search { width: min(300px, calc(100% - 116px)); }
  #map-tools { top: auto; bottom: calc(72px + env(safe-area-inset-bottom)); }
  #store-detail { bottom: calc(66px + env(safe-area-inset-bottom)); width: calc(100% - 24px); max-height: 42%; }
  .legend { bottom: calc(66px + env(safe-area-inset-bottom)); right: 60px; max-width: calc(100vw - 140px); }
  /* جلوگیری از زوم خودکار iOS در فوکوس ورودی‌ها */
  .field input, .field select, #place-search { font-size: 16px; }
  .rs-grid { gap: 6px; }
  .rs-cell { padding: 8px 9px; }
  .rs-cell .v { font-size: 14.5px; }
}

/* ═══════ موبایل باریک (≤۴۰۰px) ═══════ */
@media (max-width: 400px) {
  .two-col { grid-template-columns: 1fr; }
  .brand h1 { font-size: 11.5px; }
  #chip-services b, #mapsrc { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }
  .store-item .s-name { font-size: 12px; }
}

/* ═══════ گوشی در حالت افقی: پنل به‌شکل کشوی کنار صفحه ═══════ */
@media (max-height: 520px) and (orientation: landscape) and (max-width: 950px) {
  #panel {
    left: auto; top: 0; bottom: 0; right: 0; width: min(52vw, 480px); height: 100%;
    border-radius: 0; border-top: none; border-right: 1px solid var(--line);
    transform: translateX(106%); padding-bottom: 0;
  }
  @supports (height: 100dvh) { #panel { height: 100dvh; } }
  #panel.open { transform: translateX(0); }
  .panel-grip { display: none; }
  .panel-close { top: 10px; }
}

/* ═══════ اهداف لمسی بزرگ‌تر برای تبلت/گوشی ═══════ */
@media (pointer: coarse) {
  .mapbtn { width: 44px; height: 44px; font-size: 17px; }
  .btn { min-height: 42px; }
  .btn.small { min-height: 38px; }
  .store-item { padding: 11px; }
  .stop-row { padding: 11px 12px; }
  .weekday { padding: 7px 12px; }
  .checkline input, .store-item input { width: 18px; height: 18px; }
  .day-show { padding: 7px 12px; }
}

/* ═══════ کاهش حرکت برای کاربران حساس ═══════ */
@media (prefers-reduced-motion: reduce) {
  #panel { transition: none; }
  * { animation-duration: .01ms !important; }
}
