:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --side: #111827;
  --side-2: #1f2937;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --danger: #ef4444;
  --ok: #10b981;
  --border: #2b3648;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0,0,0,.25);
  --side-w: 340px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app { display: flex; height: 100vh; width: 100vw; }

/* ===== الشريط الجانبي ===== */
#sidebar {
  width: var(--side-w);
  flex: 0 0 var(--side-w);
  background: var(--side);
  display: flex;
  flex-direction: column;
  border-inline-end: 1px solid var(--border);
  transition: margin-left .3s ease;
  z-index: 1000;
}
#app.collapsed #sidebar { margin-left: calc(-1 * var(--side-w)); }

.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand > i {
  font-size: 26px; color: var(--primary);
  background: rgba(37,99,235,.15); padding: 10px; border-radius: 12px;
}
.brand h1 { font-size: 18px; font-weight: 700; }
.brand span { font-size: 11px; color: var(--muted); letter-spacing: 1px; }

.icon-btn {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; width: 34px; height: 34px; border-radius: 8px;
  display: grid; place-items: center; font-size: 15px; transition: .15s;
}
.icon-btn:hover { background: var(--side-2); color: var(--text); }

/* البحث */
.search-box {
  position: relative; margin: 14px 14px 8px; display: flex; align-items: center;
  background: var(--side-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 0 12px; gap: 8px;
}
.search-box i { color: var(--muted); }
.search-box input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); padding: 11px 0; font-family: inherit; font-size: 14px;
}
.search-results {
  list-style: none; margin: 0 14px; background: var(--side-2);
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  max-height: 240px; overflow-y: auto;
}
.search-results li {
  padding: 10px 14px; cursor: pointer; font-size: 13px;
  border-bottom: 1px solid var(--border); transition: .12s;
}
.search-results li:last-child { border-bottom: none; }
.search-results li:hover { background: var(--primary); }
.search-results li i { color: var(--primary); margin-inline-end: 8px; }
.search-results li:hover i { color: #fff; }

/* زر فتح الاتجاهات */
.dir-open {
  margin: 4px 14px 0; background: var(--side-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px;
  cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 8px; transition: .15s;
}
.dir-open i { color: var(--primary); }
.dir-open:hover { border-color: var(--primary); }

/* لوحة الاتجاهات */
.dir-panel {
  margin: 8px 14px 0; background: var(--side-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px; max-height: 55vh; overflow-y: auto;
}
.dir-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.dir-head h2 { font-size: 14px; display: flex; align-items: center; gap: 8px; }
.dir-head h2 i { color: var(--primary); }

.dir-inputs { position: relative; display: flex; flex-direction: column; gap: 8px; }
.dir-field { position: relative; display: flex; align-items: center; gap: 8px;
  background: var(--side); border: 1px solid var(--border); border-radius: 9px; padding: 0 10px; }
.dir-field input { flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); padding: 10px 0; font-family: inherit; font-size: 13px; }
.dot { width: 11px; height: 11px; border-radius: 50%; flex: 0 0 11px; }
.dot.start { background: var(--ok); }
.dot.end { background: var(--danger); }
.pick-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 4px; }
.pick-btn:hover, .pick-btn.active { color: var(--primary); }
.swap-btn { position: absolute; inset-inline-end: 8px; top: 50%; transform: translateY(-50%);
  background: var(--side); border: 1px solid var(--border); color: var(--primary);
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer; z-index: 2; }
.swap-btn:hover { background: var(--primary); color: #fff; }

.dir-results { position: absolute; top: 100%; inset-inline: 0; margin-top: 4px; z-index: 5;
  list-style: none; background: var(--side); border: 1px solid var(--border); border-radius: 9px;
  overflow: hidden; max-height: 180px; overflow-y: auto; }
.dir-results li { padding: 9px 12px; font-size: 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.dir-results li:last-child { border-bottom: none; }
.dir-results li:hover { background: var(--primary); }

.dir-modes { display: flex; gap: 6px; margin-top: 10px; }
.mode { width: 42px; height: 40px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--side); color: var(--text); cursor: pointer; font-size: 15px; transition: .15s; }
.mode:hover { border-color: var(--primary); }
.mode.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.dir-go { flex: 1; background: var(--primary); color: #fff; border: none; border-radius: 9px;
  cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 8px; }
.dir-go:hover { background: var(--primary-d); }

.dir-summary { margin-top: 12px; background: var(--side); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; display: flex; align-items: center; gap: 16px; }
.dir-summary .big { font-size: 20px; font-weight: 700; color: var(--primary); }
.dir-summary .sub { font-size: 12px; color: var(--muted); }
.dir-summary .save-route { margin-inline-start: auto; background: rgba(37,99,235,.15);
  color: var(--primary); border: none; padding: 8px 10px; border-radius: 8px; cursor: pointer;
  font-family: inherit; font-size: 12px; }
.dir-summary .save-route:hover { background: var(--primary); color: #fff; }

.dir-steps { list-style: none; margin-top: 10px; counter-reset: step; }
.dir-steps li { display: flex; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--border);
  font-size: 12px; line-height: 1.6; align-items: flex-start; }
.dir-steps li:last-child { border-bottom: none; }
.dir-steps .s-ico { width: 26px; height: 26px; flex: 0 0 26px; border-radius: 7px;
  background: var(--side); display: grid; place-items: center; color: var(--primary); font-size: 12px; }
.dir-steps .s-txt { flex: 1; }
.dir-steps .s-dist { color: var(--muted); font-size: 11px; }

/* أدوات سريعة */
.quick-tools {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px 14px;
}
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--side-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 12px 6px; cursor: pointer; transition: .15s;
  font-family: inherit; font-size: 12px;
}
.tool i { font-size: 18px; color: var(--primary); }
.tool:hover { border-color: var(--primary); transform: translateY(-2px); }
.tool.active { background: var(--primary); border-color: var(--primary); }
.tool.active i { color: #fff; }

/* اللوحة */
.panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 0 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px; }
.panel-head h2 { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.panel-head h2 i { color: var(--primary); }
.badge {
  background: var(--primary); color: #fff; font-size: 11px;
  padding: 1px 8px; border-radius: 20px; font-weight: 700;
}
.text-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 6px; border-radius: 6px; }
.text-btn:hover { background: var(--side-2); }
.text-btn.danger:hover { color: var(--danger); }

.item-list { list-style: none; overflow-y: auto; flex: 1; }
.item-list li {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  border-radius: 10px; cursor: pointer; transition: .12s; margin-bottom: 6px;
  background: var(--side-2); border: 1px solid transparent;
}
.item-list li:hover { border-color: var(--primary); }
.item-list .it-icon {
  width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center;
  color: #fff; flex: 0 0 34px; font-size: 14px;
}
.item-list .it-body { flex: 1; min-width: 0; }
.item-list .it-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-list .it-meta { font-size: 11px; color: var(--muted); }
.item-list .it-del { color: var(--muted); opacity: 0; transition: .12s; }
.item-list li:hover .it-del { opacity: 1; }
.item-list .it-del:hover { color: var(--danger); }

.empty-hint { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 10px; line-height: 1.7; }

.side-foot { display: flex; gap: 8px; padding: 14px; border-top: 1px solid var(--border); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 10px; padding: 10px 14px; cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 600; transition: .15s; flex: 1;
}
.btn.ghost { background: var(--side-2); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.danger { background: rgba(239,68,68,.15); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }

/* زر التوسيع */
.expand-btn {
  position: absolute; top: 16px; inset-inline-end: 16px; z-index: 1100;
  background: var(--side); color: var(--text); border: 1px solid var(--border);
  width: 42px; height: 42px; border-radius: 10px; cursor: pointer; box-shadow: var(--shadow);
}

/* ===== الخريطة ===== */
#mapWrap { position: relative; flex: 1; }
#map { width: 100%; height: 100%; background: #1a2233; }

.map-controls {
  position: absolute; bottom: 28px; inset-inline-end: 16px; z-index: 600;
  display: flex; flex-direction: column; gap: 8px;
}
.map-btn {
  width: 44px; height: 44px; border-radius: 10px; border: none; cursor: pointer;
  background: var(--panel); color: #334155; font-size: 17px; box-shadow: var(--shadow);
  display: grid; place-items: center; transition: .15s;
}
.map-btn:hover { background: var(--primary); color: #fff; }

.layer-switch {
  position: absolute; top: 16px; inset-inline-start: 16px; z-index: 600;
  background: var(--panel); border-radius: 12px; padding: 5px; box-shadow: var(--shadow);
  display: flex; gap: 4px;
}
.layer-opt {
  border: none; background: transparent; color: #475569; cursor: pointer;
  padding: 8px 12px; border-radius: 8px; font-family: inherit; font-size: 12px;
  font-weight: 600; display: flex; align-items: center; gap: 6px; transition: .15s;
}
.layer-opt:hover { background: #f1f5f9; }
.layer-opt.active { background: var(--primary); color: #fff; }

/* إظهار الأماكن */
.poi-control {
  position: absolute; top: 70px; inset-inline-start: 16px; z-index: 600;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
}
.poi-btn {
  background: var(--panel); color: #334155; border: none; cursor: pointer;
  padding: 10px 14px; border-radius: 10px; font-family: inherit; font-size: 13px;
  font-weight: 600; box-shadow: var(--shadow); display: flex; align-items: center; gap: 8px;
  transition: .15s;
}
.poi-btn i { color: var(--primary); }
.poi-btn:hover { background: #f1f5f9; }
.poi-btn.active { background: var(--primary); color: #fff; }
.poi-btn.active i { color: #fff; }

.poi-filters {
  background: var(--panel); border-radius: 10px; padding: 6px; box-shadow: var(--shadow);
  display: flex; flex-wrap: wrap; gap: 4px; max-width: 320px;
}
.poi-cat {
  border: none; background: transparent; color: #475569; cursor: pointer;
  padding: 6px 10px; border-radius: 7px; font-family: inherit; font-size: 12px;
  font-weight: 600; display: flex; align-items: center; gap: 5px; transition: .12s;
}
.poi-cat i { font-size: 11px; }
.poi-cat:hover { background: #f1f5f9; }
.poi-cat.active { background: var(--primary); color: #fff; }

/* علامات الأماكن */
.poi-marker {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); border: 2px solid currentColor;
}
.poi-marker i { font-size: 12px; }
.poi-popup .pt { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.poi-popup .pc { font-size: 12px; color: var(--primary); margin-bottom: 6px; }
.poi-popup .pr { font-size: 12px; color: #475569; display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.poi-popup .pr i { color: #94a3b8; width: 14px; }
.poi-popup .pin-add {
  margin-top: 8px; background: var(--primary); color: #fff; border: none;
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-family: inherit; font-size: 12px;
}

.status-bar {
  position: absolute; bottom: 28px; inset-inline-start: 16px; z-index: 600;
  background: rgba(15,23,42,.85); color: #fff; padding: 8px 14px; border-radius: 10px;
  font-size: 12px; backdrop-filter: blur(6px); box-shadow: var(--shadow);
  display: none; max-width: 60%;
}
.status-bar.show { display: block; }

/* ===== النافذة المنبثقة ===== */
.modal {
  position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,.6);
  display: grid; place-items: center; backdrop-filter: blur(3px);
}
.modal-card {
  background: var(--side); width: 420px; max-width: 92vw; border-radius: 16px;
  border: 1px solid var(--border); box-shadow: var(--shadow); overflow: hidden;
}
.modal-card header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.modal-card header h3 { font-size: 16px; display: flex; align-items: center; gap: 8px; }
.modal-card header h3 i { color: var(--primary); }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-body label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.modal-body input[type=text], .modal-body textarea, .modal-body select {
  background: var(--side-2); border: 1px solid var(--border); border-radius: 9px;
  padding: 10px 12px; color: var(--text); font-family: inherit; font-size: 14px; outline: none;
}
.modal-body input:focus, .modal-body textarea:focus, .modal-body select:focus { border-color: var(--primary); }
.modal-body .row { display: flex; gap: 12px; }
.modal-body .row .grow { flex: 1; }
.modal-body input[type=color] { height: 42px; padding: 4px; cursor: pointer; }
.modal-card footer { display: flex; gap: 10px; padding: 16px 18px; border-top: 1px solid var(--border); }
.modal-card footer .btn { flex: 1; }

/* دبوس مخصص */
.custom-pin {
  display: grid; place-items: center; width: 32px; height: 32px;
  border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  box-shadow: 0 3px 8px rgba(0,0,0,.4); border: 2px solid #fff;
}
.custom-pin i { transform: rotate(45deg); color: #fff; font-size: 14px; }

/* نوافذ Leaflet */
.leaflet-popup-content-wrapper { border-radius: 12px; }
.leaflet-popup-content { font-family: 'Inter', sans-serif; margin: 12px 14px; direction: ltr; }
.popup-title { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.popup-note { font-size: 13px; color: #475569; white-space: pre-wrap; }
.popup-btn {
  margin-top: 8px; background: var(--primary); color: #fff; border: none;
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-family: inherit; font-size: 12px;
}

/* العمل بدون إنترنت */
.modal-body input[type=range] { width: 100%; accent-color: var(--primary); cursor: pointer; }
.modal-body input[readonly] { opacity: .7; cursor: default; }
.off-estimate {
  display: flex; gap: 18px; flex-wrap: wrap; background: var(--side-2);
  border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; font-size: 13px;
}
.off-estimate i { color: var(--primary); margin-inline-end: 4px; }
.off-progress { display: flex; align-items: center; gap: 10px; }
.off-progress .bar { flex: 1; height: 10px; background: var(--side-2); border-radius: 20px; overflow: hidden; }
.off-progress .fill { height: 100%; width: 0%; background: var(--primary); transition: width .2s; }
.off-progress span { font-size: 12px; color: var(--muted); min-width: 38px; }

.off-saved { border-top: 1px solid var(--border); padding-top: 12px; }
.off-saved h4 { font-size: 13px; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.off-saved h4 i { color: var(--primary); }
.off-list { list-style: none; max-height: 180px; overflow-y: auto; }
.off-list li {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; background: var(--side-2);
  border: 1px solid var(--border); border-radius: 9px; margin-bottom: 6px;
}
.off-list .ol-body { flex: 1; min-width: 0; }
.off-list .ol-name { font-size: 13px; font-weight: 600; }
.off-list .ol-meta { font-size: 11px; color: var(--muted); }
.off-list .ol-act { background: none; border: none; color: var(--muted); cursor: pointer; padding: 5px; border-radius: 6px; font-size: 13px; }
.off-list .ol-act:hover { background: var(--side); color: var(--primary); }
.off-list .ol-act.del:hover { color: var(--danger); }

.offline-badge {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 700;
  background: #b45309; color: #fff; padding: 8px 16px; border-radius: 20px; font-size: 12px;
  font-weight: 600; box-shadow: var(--shadow); display: flex; align-items: center; gap: 8px;
}

/* دائرة معاينة منطقة الحفظ */
.save-circle { stroke-dasharray: 8 6; }

.hidden { display: none !important; }

/* تجاوب */
@media (max-width: 720px) {
  :root { --side-w: 100vw; }
  #sidebar { position: absolute; inset: 0; }
}

/* شريط التمرير */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }
