/* ============================================================ أساسيات */
:root {
  --bg: #090b0e;
  --bg-2: #101419;
  --bg-3: #171c23;
  --card: rgba(255, 255, 255, 0.045);
  --card-2: rgba(255, 255, 255, 0.08);
  --card-3: rgba(255, 255, 255, 0.13);
  --text: #f3f5f7;
  --muted: #9aa3ae;
  --faint: #6b7480;
  --green: #22c55e;
  --green-ink: #052e16;
  --amber: #f59e0b;
  --red: #ef4444;
  --blue: #60a5fa;
  --r: 14px;
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.6 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
button:disabled { opacity: 0.45; cursor: default; }
a { color: var(--blue); text-decoration: none; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); direction: ltr; unicode-bidi: isolate; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.between { justify-content: space-between; }
.center { justify-content: center; }
.stack { display: grid; gap: 10px; }

/* ============================================================ أزرار وحقول */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 14px; border-radius: 12px;
  background: var(--card-2); color: var(--text); font-weight: 600; text-align: center;
  transition: background 0.15s, transform 0.05s;
}
.btn:hover:not(:disabled) { background: var(--card-3); }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn-primary { background: var(--green); color: var(--green-ink); }
.btn-primary:hover:not(:disabled) { background: #4ade80; }
.btn-danger { background: rgba(239, 68, 68, 0.16); color: #fca5a5; }
.btn-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.27); }
.btn-lg { min-height: 54px; font-size: 17px; border-radius: 16px; }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 13px; border-radius: 10px; }
.btn-block { width: 100%; }

.field, .input {
  min-height: 40px; padding: 0 12px; border-radius: 10px; border: 0;
  background: var(--card-2); min-width: 0;
}
.field:focus, .input:focus { background: var(--card-3); outline: none; }
.input { min-height: 48px; font-size: 17px; border-radius: 14px; }
select.field { padding: 0 8px; }
select.field option { background: var(--bg-3); }

/* ============================================================ شارات وتنبيهات */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px;
  border-radius: 999px; font-size: 13px; background: var(--card-2); white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.plain::before { display: none; }
.ok { color: var(--green); }
.warn { color: var(--amber); }
.bad { color: var(--red); }
.info { color: var(--blue); }
.off { color: var(--faint); }

.banner { padding: 12px 14px; border-radius: 12px; background: var(--card-2); font-weight: 500; }
.banner.danger { background: rgba(239, 68, 68, 0.15); color: #fecaca; }
.banner.warning { background: rgba(245, 158, 11, 0.14); color: #fde68a; }
.banner.success { background: rgba(34, 197, 94, 0.14); color: #bbf7d0; }

.spinner {
  width: 18px; height: 18px; border-radius: 50%; flex: none;
  border: 2.5px solid currentColor; border-left-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 20px; left: 50%; z-index: 5000;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px;
  background: #1f2630; color: var(--text); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #3b1414; color: #fecaca; }

/* ============================================================ الخريطة */
.leaflet-container { background: #0d1117; font-family: var(--font); }
.dark-tiles .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.88) saturate(0.55); }
.mk-wrap { background: none; border: 0; }
.mk {
  position: absolute; transform: translate(-50%, -50%);
  padding: 3px 10px; border-radius: 999px; white-space: nowrap; direction: ltr;
  font: 700 12px/1.4 var(--font); color: #fff; background: #475467;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}
.mk.available { background: #16a34a; }
.mk.ride { background: #2563eb; }
.mk.out { background: #dc2626; }
.mk.open { background: #d97706; }
.mk.offline { background: #475467; }
.mk.target { background: transparent; box-shadow: none; padding: 0; width: 16px; height: 16px; border-radius: 50%; border: 3px solid #fff; }

/* دبوس السكوتر: رأسه على المكان بالضبط */
.pin-wrap { background: none; border: 0; }
.pin { display: block; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.55)); cursor: pointer; overflow: visible; }
.pin-body { fill: #475467; stroke: #fff; stroke-width: 2; }
.pin.available .pin-body { fill: #16a34a; }
.pin.ride .pin-body { fill: #2563eb; }
.pin.out .pin-body { fill: #dc2626; }
.pin.open .pin-body { fill: #d97706; }
.pin.unknown .pin-body { fill: #7c3aed; }
.leaflet-tooltip.pin-label {
  padding: 4px 10px; border: 0; border-radius: 8px; background: #0f141a; color: #fff; text-align: center;
  font: 700 13px/1.4 var(--font); direction: rtl; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}
.pin-label .pl-code { display: block; direction: ltr; unicode-bidi: isolate; font-size: 14px; }
.pin-label .pl-sub { display: block; font-weight: 500; font-size: 12px; color: #c7cdd4; }
.leaflet-tooltip.pin-label::before { border-top-color: #0f141a; }

/* زر القمر الصناعي */
.map-style-btn {
  display: block; padding: 6px 10px; border-radius: 8px; background: #fff; color: #111;
  font: 700 13px/1.2 var(--font); box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4); cursor: pointer;
}
.map-style-btn:hover { background: #f1f5f9; }

/* نقاط تعديل المناطق */
.vx-wrap { background: none; border: 0; }
.vx, .vx-mid, .vx-move { width: 100%; height: 100%; border-radius: 50%; box-sizing: border-box; }
.vx { background: #fff; border: 3px solid var(--vx); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6); cursor: grab; }
.vx.sel { background: #facc15; border-color: #111; transform: scale(1.3); }
.vx.vx-radius { border-radius: 4px; cursor: ew-resize; }
.vx-mid { background: rgba(255, 255, 255, 0.6); border: 2px solid var(--vx); opacity: 0.75; cursor: copy; }
.vx-mid:hover { opacity: 1; transform: scale(1.25); }
.vx-move {
  display: grid; place-items: center; background: rgba(9, 11, 14, 0.85); color: #fff;
  border: 2px solid var(--vx); cursor: move; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

/* البحث عن مكان */
.map-search {
  position: absolute; top: 10px; left: 60px; right: 12px; z-index: 1000; max-width: 380px;
  display: flex; gap: 6px; direction: rtl;
}
.map-search .field { flex: 1; min-height: 38px; background: rgba(9, 11, 14, 0.88); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4); }
.map-search .btn { min-height: 38px; background: rgba(9, 11, 14, 0.88); }
.map-results {
  position: absolute; top: 54px; left: 60px; right: 12px; z-index: 1000; max-width: 380px; max-height: 50%;
  overflow-y: auto; border-radius: 12px; background: rgba(9, 11, 14, 0.94); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}
.map-results button { display: block; width: 100%; padding: 9px 12px; text-align: start; font-size: 13.5px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.map-results button:hover { background: var(--card-2); }
.kbd-hint { font-size: 12px; color: var(--faint); }

/* ============================================================ صفحات الزبون */
body.customer { min-height: 100dvh; display: flex; flex-direction: column; }
.customer .map { height: 40dvh; min-height: 230px; }
.sheet {
  position: relative; z-index: 1001; flex: 1; margin-top: -20px;
  padding: 22px 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg-2); border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.35);
}
.sheet-in { max-width: 520px; margin: 0 auto; display: grid; gap: 16px; }
.title { margin: 0; font-size: 22px; font-weight: 700; }
.code { font-weight: 700; direction: ltr; unicode-bidi: isolate; }
.label { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 10px; }
.pay-card { padding: 14px; border-radius: 16px; background: var(--card); display: grid; gap: 10px; }
.pay-total { padding-top: 10px; border-top: 1px solid rgba(255, 255, 255, 0.08); font-size: 18px; }
.pay-methods { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two.three { grid-template-columns: 1fr 1fr 1fr; }
.plan { padding: 12px 8px; border-radius: 14px; background: var(--card); display: grid; gap: 2px; text-align: center; }
.plan b { font-size: 18px; }
.plan .price { font-size: 13px; color: var(--muted); }
.plan .price s { color: var(--faint); }
.plan.sel { background: rgba(34, 197, 94, 0.15); box-shadow: inset 0 0 0 2px var(--green); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { padding: 10px 6px; border-radius: 14px; background: var(--card); text-align: center; }
.stat b { display: block; font-size: 20px; font-variant-numeric: lining-nums tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.countdown { text-align: center; }
.countdown .big {
  font-size: 58px; font-weight: 700; line-height: 1.1; direction: ltr;
  font-variant-numeric: tabular-nums; letter-spacing: 1px;
}
.countdown .big.warn { color: var(--amber); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rules { margin: 0; padding: 0 18px 0 0; color: var(--muted); font-size: 13.5px; display: grid; gap: 4px; }
.test-note { font-size: 13px; color: var(--amber); margin-top: 8px; }
.code-box { display: flex; gap: 8px; }
.code-box .input { flex: 1; text-transform: uppercase; }

body.landing .sheet { margin-top: 0; border-radius: 0; display: grid; align-content: center; min-height: 100dvh; }
.logo { width: 64px; height: 64px; }

/* ============================================================ لوحة التحكم */
body.admin { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--bg-2);
}
.brand { font-weight: 700; font-size: 17px; }
.topbar a.mono { font-size: 13px; }
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 440px minmax(0, 1fr); }
.side { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg-2); }
.tabs { display: flex; gap: 4px; padding: 8px 10px; overflow-x: auto; scrollbar-width: none; flex: none; }
.tabs button { padding: 7px 12px; border-radius: 10px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tabs button.on { background: var(--card-2); color: var(--text); }
.panel { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 12px 20px; display: grid; gap: 10px; align-content: start; }
.mapbox { position: relative; min-height: 0; }
.mapbox #map { position: absolute; inset: 0; }
.map-hint {
  position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 1000; max-width: calc(100% - 24px);
  text-align: center; width: max-content;
  padding: 8px 14px; border-radius: 12px; background: rgba(9, 11, 14, 0.88); font-size: 14px;
}
.card { padding: 12px; border-radius: var(--r); background: var(--card); display: grid; gap: 8px; }
.card.focus { box-shadow: inset 0 0 0 2px var(--blue); }
.card .code { font-size: 16px; }
.facts, .actions { display: flex; flex-wrap: wrap; gap: 6px; }
.section-title { margin: 6px 2px 0; font-size: 13px; color: var(--muted); }
.form { display: grid; gap: 8px; }
.form .row > .field, .grow > .field { flex: 1; }
.shape-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: var(--card); }
.shape-tabs button { padding: 7px 4px; border-radius: 9px; color: var(--muted); font-weight: 600; }
.shape-tabs button.on { background: var(--card-3); color: var(--text); }
.field.num { width: 110px; flex: none; }
details.card summary { cursor: pointer; color: var(--muted); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--green); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.allowed { background: var(--green); }
.dot.slow { background: var(--amber); }
.dot.forbidden { background: var(--red); }
.steps { margin: 0; padding: 0 18px 0 0; font-size: 13.5px; }
.sim { cursor: pointer; }
.sim input[type="radio"] { width: 16px; height: 16px; accent-color: var(--blue); }

.log {
  height: calc(100dvh - 190px); overflow-y: auto; padding: 8px; border-radius: 12px;
  background: #05070a; font: 12px/1.55 var(--mono);
}
.log > div { display: flex; gap: 8px; padding: 1px 0; direction: ltr; }
.log .t { flex: none; color: var(--faint); direction: ltr; }
.log .who { flex: none; min-width: 36px; color: var(--muted); direction: ltr; }
.log .k { flex: none; padding: 0 6px; border-radius: 6px; background: var(--card-2); font: 11px/1.7 var(--font); }
.log .k.in { color: #93c5fd; }
.log .k.out { color: #86efac; }
.log .k.warn { color: #fca5a5; }
.log .k.info { color: #d1d5db; }
.log .x { flex: 1; white-space: pre-wrap; word-break: break-word; font-family: var(--font); text-align: start; }
.log .x.raw { word-break: break-all; font-family: var(--mono); }

/* تبويب الأحداث */
.audit {
  height: calc(100dvh - 330px); min-height: 220px; overflow-y: auto; padding: 6px; border-radius: 12px;
  background: #05070a; font-size: 13px; display: flex; flex-direction: column; gap: 2px;
}
.au {
  display: grid; grid-template-columns: auto auto auto minmax(0, 1fr); gap: 2px 10px; align-items: baseline;
  padding: 6px 8px; border-radius: 8px; border-inline-start: 3px solid transparent;
}
.au .t { font: 11.5px var(--mono); color: var(--faint); direction: ltr; white-space: nowrap; }
.au .who { font: 12px var(--mono); color: var(--muted); direction: ltr; min-width: 30px; }
.au .k { padding: 0 7px; border-radius: 6px; background: var(--card-2); font-size: 11.5px; line-height: 1.8; white-space: nowrap; }
.au .k.warn { color: #fde68a; background: rgba(245, 158, 11, 0.14); }
.au .k.alert { color: #fecaca; background: rgba(239, 68, 68, 0.22); }
.au .x { text-align: start; word-break: break-word; }
.au .tail { grid-column: 1 / -1; font: 11.5px var(--mono); color: var(--faint); direction: ltr; text-align: end; }
.au.warn { border-color: rgba(245, 158, 11, 0.6); }
.au.alert { border-color: #ef4444; background: rgba(239, 68, 68, 0.1); }
.au.alert .x { color: #fecaca; font-weight: 600; }
.au.fresh { animation: au-in 1.2s ease-out; }
@keyframes au-in { from { background: rgba(255, 255, 255, 0.14); } }
.audit-stats { display: flex; flex-wrap: wrap; gap: 6px; }
.audit-stats .pill.alert { color: #fecaca; background: rgba(239, 68, 68, 0.2); }
.badge {
  display: inline-block; min-width: 18px; margin-inline-start: 5px; padding: 0 5px; border-radius: 999px;
  background: #ef4444; color: #fff; font-size: 11px; line-height: 18px; text-align: center; vertical-align: 1px;
}
.audit-empty { padding: 20px; text-align: center; color: var(--faint); }

.modal { position: fixed; inset: 0; z-index: 4000; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, 0.6); }
.modal-box { width: min(420px, 100%); padding: 20px; border-radius: 18px; background: var(--bg-3); display: grid; gap: 12px; text-align: center; }
.qr-img { justify-self: center; padding: 14px; border-radius: 14px; background: #fff; }
.qr-img img { display: block; width: 240px; height: 240px; image-rendering: pixelated; }
.qr-code { font-size: 30px; font-weight: 700; letter-spacing: 2px; direction: ltr; }
.qr-url { font-size: 12px; word-break: break-all; }

@media (max-width: 900px) {
  body.admin { height: auto; overflow: visible; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .mapbox { order: -1; height: 46dvh; }
  .side { min-height: 60dvh; }
  .panel { overflow: visible; }
  .log { height: 60dvh; }
  .audit { height: 50dvh; }
}

@media print {
  body * { visibility: hidden !important; }
  .print-area, .print-area * { visibility: visible !important; }
  .print-area { position: fixed; inset: 0; width: auto; background: #fff; color: #000; align-content: center; }
  .no-print { display: none !important; }
}
