/* ── مندوب — تنسيق عربي RTL، موبايل أولاً ─────────────────────────────────
   قواعد التصميم هنا مشتقة من ظرف الاستخدام لا من الذوق:
   المروج يستعمل الشاشة بيد واحدة، تحت شمس، وأحياناً بشبكة ضعيفة. لذلك
   أهداف اللمس ≥ 48px، التباين عالٍ، والأزرار الأساسية عريضة بعرض الشاشة.  */

:root {
  --brand: #0f5ea8;
  --brand-dark: #0b467d;
  --brand-soft: #e8f1fa;
  --ink: #14202e;
  --ink-2: #4a5a6c;
  --ink-3: #7c8b9c;
  --line: #dfe6ee;
  --bg: #f4f7fa;
  --card: #ffffff;

  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn-soft: #fffbeb;
  --ok-soft: #f0fdf4;

  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,32,52,.06), 0 4px 14px rgba(16,32,52,.06);
  --tap: 48px;
}

/* الخط مقسّم عربي\/لاتيني بـ unicode-range: المتصفح يحمّل الشريحة العربية
   وحدها في معظم الصفحات (13 كيلوبايت للوزن) ويؤجّل اللاتينية حتى تظهر
   أرقام أو أسماء إنجليزية فعلاً. على شبكة موبايل ضعيفة هذا فرق ملموس. */
@font-face {
  font-family: 'Cairo'; font-weight: 400; font-display: swap;
  src: url('/fonts/cairo/cairo-arabic-400.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: 'Cairo'; font-weight: 400; font-display: swap;
  src: url('/fonts/cairo/cairo-latin-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}
@font-face {
  font-family: 'Cairo'; font-weight: 600; font-display: swap;
  src: url('/fonts/cairo/cairo-arabic-600.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: 'Cairo'; font-weight: 600; font-display: swap;
  src: url('/fonts/cairo/cairo-latin-600.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}
@font-face {
  font-family: 'Cairo'; font-weight: 700; font-display: swap;
  src: url('/fonts/cairo/cairo-arabic-700.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: 'Cairo'; font-weight: 700; font-display: swap;
  src: url('/fonts/cairo/cairo-latin-700.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: 'Cairo', system-ui, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: env(safe-area-inset-bottom); }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── الهيكل ─────────────────────────────────────────────────────────── */
.topbar {
  background: var(--brand); color: #fff;
  padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  position: sticky; top: 0; z-index: 40;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.topbar .brand { font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.topbar .brand span.sub { font-weight: 400; opacity: .8; font-size: .8rem; }
.topbar a, .topbar button { color: #fff; }
.topbar form { margin: 0; }

.logout-btn {
  background: rgba(255,255,255,.15); border: 0; color: #fff;
  border-radius: 10px; padding: 8px 14px; font-family: inherit;
  font-size: .85rem; cursor: pointer; min-height: 40px;
}
.logout-btn:hover { background: rgba(255,255,255,.25); }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ── جرس الإشعارات ──────────────────────────────────────────────────── */
.notif-bell { position: relative; }
.bell-btn {
  background: rgba(255,255,255,.15); border: 0; color: #fff;
  border-radius: 10px; width: 40px; height: 40px; font-size: 1.05rem;
  cursor: pointer; position: relative; display: flex; align-items: center; justify-content: center;
}
.bell-btn:hover { background: rgba(255,255,255,.25); }
.notif-count {
  position: absolute; top: -4px; inset-inline-end: -4px;
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: .62rem; font-weight: 700; padding: 1px 5px; min-width: 16px;
  line-height: 1.4; border: 2px solid var(--brand);
}
.notif-dropdown {
  position: absolute; top: calc(100% + 8px); inset-inline-end: 0;
  width: 320px; max-width: calc(100vw - 24px); max-height: 70vh; overflow-y: auto;
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); z-index: 60;
}
.notif-head {
  padding: 12px 14px; font-weight: 700; border-bottom: 1px solid var(--line);
}
.notif-empty { padding: 24px 14px; text-align: center; color: var(--ink-3); font-size: .85rem; }
.notif-item {
  display: block; padding: 10px 14px; border-bottom: 1px solid var(--line);
  color: var(--ink); text-decoration: none;
}
.notif-item:hover { background: var(--bg); text-decoration: none; }
.notif-item:last-child { border-bottom: 0; }
.notif-item.unread { background: var(--brand-soft); }
.notif-title { font-weight: 600; font-size: .88rem; }
.notif-body { font-size: .8rem; color: var(--ink-2); margin-top: 2px; }
.notif-time { font-size: .72rem; color: var(--ink-3); margin-top: 4px; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 16px; }
.wrap.narrow { max-width: 720px; }

/* شريط تنقل سفلي للمروج — الإبهام يصل إليه بيد واحدة */
.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 50;
  background: #fff; border-top: 1px solid var(--line);
  display: flex; justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 12px rgba(16,32,52,.06);
}
.tabbar a {
  flex: 1; text-align: center; padding: 10px 4px 8px;
  color: var(--ink-3); font-size: .72rem; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-height: var(--tap); text-decoration: none;
}
.tabbar a.active { color: var(--brand); }
.tabbar .icon { font-size: 1.25rem; line-height: 1; }
.tabbar .badge {
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: .62rem; padding: 1px 6px; margin-inline-start: 4px;
}
body.has-tabbar .wrap { padding-bottom: 84px; }

/* تنقل الأدمن — أفقي قابل للتمرير على الموبايل */
.adminnav {
  background: var(--brand-dark); display: flex; gap: 2px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  padding: 0 8px; position: sticky; top: 56px; z-index: 30;
}
.adminnav::-webkit-scrollbar { display: none; }
.adminnav .navbadge { background: var(--danger); margin-inline-start: 4px; padding: 1px 7px; font-size: .68rem; }
.adminnav a {
  color: rgba(255,255,255,.78); padding: 12px 14px; white-space: nowrap;
  font-size: .88rem; font-weight: 600; border-bottom: 3px solid transparent;
  text-decoration: none;
}
.adminnav a.active { color: #fff; border-bottom-color: #fff; }

/* ── البطاقات والجداول ──────────────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 16px;
}
.card > h2, .card > h3 { margin: 0 0 12px; font-size: 1.05rem; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; font-size: 1.05rem; }

.muted { color: var(--ink-3); }
.small { font-size: .82rem; }
.center { text-align: center; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
}
.stat .n { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat .l { font-size: .78rem; color: var(--ink-3); font-weight: 600; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 10px 8px; text-align: right; border-bottom: 1px solid var(--line); }
th { color: var(--ink-2); font-weight: 700; font-size: .8rem; background: #fafcfe; white-space: nowrap; }
tbody tr:hover { background: #fafcfe; }
td.num, th.num { text-align: left; font-variant-numeric: tabular-nums; direction: ltr; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 600; color: #fff; white-space: nowrap;
}
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: .74rem; font-weight: 600;
  background: var(--brand-soft); color: var(--brand-dark);
}

/* ── التنبيهات ──────────────────────────────────────────────────────── */
.alert { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; font-size: .9rem; }
.alert-danger { background: var(--danger-soft); border: 1px solid #fecaca; color: #991b1b; }
.alert-warn   { background: var(--warn-soft);   border: 1px solid #fde68a; color: #92400e; }
.alert-ok     { background: var(--ok-soft);     border: 1px solid #bbf7d0; color: #166534; }
.alert ul { margin: 6px 0 0; padding-inline-start: 20px; }

/* شريط الإنذار الأحمر في لوحة الأدمن — لافت عمداً */
.alert-speed {
  background: var(--danger); color: #fff; border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 16px;
}
.alert-speed h3 { margin: 0 0 8px; font-size: 1rem; }
.alert-speed .row {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 7px 0; border-top: 1px solid rgba(255,255,255,.25); font-size: .86rem;
}
.alert-speed a { color: #fff; text-decoration: underline; }

/* ── النماذج ────────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field > label {
  display: block; font-weight: 600; font-size: .9rem;
  margin-bottom: 7px; color: var(--ink-2);
}
.field .req { color: var(--danger); }
.hint { font-size: .78rem; color: var(--ink-3); margin-top: 5px; }

input[type=text], input[type=tel], input[type=password], input[type=date],
input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 12px 14px; min-height: var(--tap);
  border: 1px solid var(--line); border-radius: 12px;
  font-family: inherit; font-size: 1rem; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15,94,168,.14);
}
textarea { min-height: 88px; resize: vertical; }
input[type=tel], input[type=number] { direction: ltr; text-align: right; }
/* type=date لا يُعامَل كحقل نصي: ودجت نظام أصلي (خصوصاً iOS Safari)، ومزج
   direction:ltr مع text-align:right عليه تحديداً يُحدث خللاً معروفاً في
   WebKit يُكرّر مقطع السنة داخل الودجت (مثل "202026/09/"). direction:ltr
   وحدها كافية لعرضه بالاتجاه الصحيح دون هذا الخلل. */
input[type=date] { direction: ltr; }

/* اختيار بأزرار كبيرة بدل قوائم منسدلة: الاختيار بضغطة واحدة في الشارع
   أسرع وأقل خطأً من فتح قائمة والتمرير فيها. */
.choice { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 560px) { .choice.c3 { grid-template-columns: repeat(3, 1fr); } }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice label {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 56px; padding: 10px 8px; cursor: pointer;
  border: 2px solid var(--line); border-radius: 12px; background: #fff;
  font-weight: 600; font-size: .92rem; transition: all .12s ease;
}
.choice label:active { transform: scale(.98); }
.choice input:checked + label {
  border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark);
}
.choice.outcomes input:checked + label {
  border-color: var(--oc, var(--brand));
  background: color-mix(in srgb, var(--oc, var(--brand)) 12%, #fff);
  color: var(--oc, var(--brand-dark));
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 12px 20px; border: 0; border-radius: 12px;
  background: var(--brand); color: #fff; font-family: inherit;
  font-size: 1rem; font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-lg { min-height: 58px; font-size: 1.08rem; }
.btn-ghost { background: #fff; color: var(--brand); border: 2px solid var(--brand); }
.btn-ghost:hover { background: var(--brand-soft); color: var(--brand-dark); }
.btn-sm { min-height: 38px; padding: 6px 14px; font-size: .84rem; font-weight: 600; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-ok { background: var(--ok); }
.btn-ok:hover { background: #15803d; }

/* ── الموقع والصورة ─────────────────────────────────────────────────── */
.geo-box, .photo-box {
  border: 2px dashed var(--line); border-radius: 12px;
  padding: 14px; background: #fbfdff;
}
.geo-box.ok, .photo-box.ok { border-style: solid; border-color: var(--ok); background: var(--ok-soft); }
.geo-box.err { border-style: solid; border-color: var(--danger); background: var(--danger-soft); }
.geo-box.warn { border-style: solid; border-color: var(--warn); background: var(--warn-soft); }
.geo-status { font-size: .86rem; margin-top: 10px; }
.geo-coords { direction: ltr; text-align: left; font-size: .8rem; color: var(--ink-2); }
.photo-preview { max-width: 100%; border-radius: 10px; margin-top: 10px; display: block; }
.photo-input { display: none; }

.spinner {
  width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff; border-radius: 50%;
  display: inline-block; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── الفلاتر ────────────────────────────────────────────────────────── */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
@media (min-width: 900px) { .filters { grid-template-columns: repeat(5, 1fr); } }
.filters .field { margin-bottom: 0; }
.filters .actions { display: flex; gap: 8px; }

/* ── /admin/site: تبويبات ومحرّر المنتجات ──────────────────────────────── */
.site-tabs {
  display: flex; gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  margin-bottom: 16px; border-bottom: 1px solid var(--line);
}
.site-tabs .tab-link {
  padding: 10px 16px; white-space: nowrap; font-weight: 600; font-size: .9rem;
  color: var(--ink-2); border-bottom: 3px solid transparent;
}
.site-tabs .tab-link.active { color: var(--brand); border-bottom-color: var(--brand); }
.prod-row {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 14px;
}
.prod-row legend { font-weight: 700; padding: 0 6px; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: .88rem; margin-inline-end: 16px; }
.chk input { width: auto; }

/* ── /admin/site: رفع الوسائط والشركاء ─────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 28px; text-align: center; color: var(--ink-3); cursor: pointer;
  font-weight: 600; transition: border-color .15s, background .15s;
}
.drop-zone.drag { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.media-item { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.media-item img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.media-meta { padding: 6px 8px; font-size: .72rem; color: var(--ink-3); }
.media-item .media-delete { width: 100%; border-radius: 0; }
.partner-row {
  display: flex; align-items: center; gap: 12px; padding: 10px;
  border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px;
  cursor: grab; background: #fff;
}
.partner-row.dragging { opacity: .5; }
.partner-thumb { width: 44px; height: 44px; object-fit: contain; border-radius: 6px; background: var(--bg); }
.partner-row-body { flex: 1; display: flex; flex-direction: column; }

/* ── الخريطة ────────────────────────────────────────────────────────── */
#map { height: 68vh; min-height: 380px; border-radius: var(--radius); border: 1px solid var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: .82rem; }
.legend .item { display: flex; align-items: center; gap: 6px; }
.legend .dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.2); }

/* ── القوائم على الموبايل ───────────────────────────────────────────── */
.list-item {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.list-item .li-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.list-item .li-title { font-weight: 700; }
.list-item .li-meta { font-size: .8rem; color: var(--ink-3); margin-top: 3px; }
.list-item.overdue { border-inline-start: 4px solid var(--danger); }

.bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; min-width: 60px; }
.bar > span { display: block; height: 100%; background: var(--brand); }

.pager { display: flex; gap: 8px; justify-content: center; margin-top: 16px; }

.empty { text-align: center; padding: 34px 16px; color: var(--ink-3); }
.empty .big { font-size: 2.2rem; margin-bottom: 8px; }

/* ── جولات المتابعة: أزرار سريعة، شارة "جديد"، نافذة الحذف، التقرير ──── */
.quick-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.count-chip {
  display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 999px;
  background: rgba(255,255,255,.25); font-size: .78rem; font-weight: 700; text-align: center;
}
.btn-ghost .count-chip { background: var(--brand-soft); color: var(--brand-dark); }
.count-chip.warn, .btn-ghost .count-chip.warn { background: var(--warn); color: #fff; }
.badge-new { background: var(--warn); }
tr.row-new td:first-child { box-shadow: inset -3px 0 0 var(--warn); }

dialog.modal {
  border: 0; border-radius: var(--radius); padding: 18px; width: min(460px, calc(100vw - 32px));
  box-shadow: 0 10px 40px rgba(16,32,52,.25);
}
dialog.modal::backdrop { background: rgba(16,32,52,.45); }
dialog.modal h3 { margin: 0 0 10px; font-size: 1.05rem; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.modal-actions .btn { flex: 1; }

.report-table tfoot th { background: var(--brand-soft); color: var(--ink); }
.week-details > summary { cursor: pointer; list-style: none; flex-wrap: wrap; gap: 6px; }
.week-details > summary::-webkit-details-marker { display: none; }
.week-details > summary h3::before { content: '▸ '; color: var(--ink-3); }
.week-details[open] > summary h3::before { content: '▾ '; }
.status-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.note-row { border-top: 1px solid var(--line); padding: 10px 0; }
.note-row .li-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.note-text { margin: 4px 0; white-space: pre-wrap; }

/* جدول يتحوّل إلى بطاقات على الموبايل بدل التمرير الأفقي. */
@media (max-width: 700px) {
  table.table-cards thead { display: none; }
  table.table-cards, table.table-cards tbody { display: block; }
  table.table-cards tr {
    display: block; border: 1px solid var(--line); border-radius: 12px;
    margin-bottom: 10px; padding: 6px 12px; background: var(--card);
  }
  table.table-cards tr.row-new { border-inline-start: 4px solid var(--warn); }
  table.table-cards tr.row-new td:first-child { box-shadow: none; }
  table.table-cards td {
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    border: 0; padding: 5px 0; text-align: left;
  }
  table.table-cards td::before {
    content: attr(data-label); font-weight: 700; color: var(--ink-3); font-size: .78rem;
    text-align: right; flex-shrink: 0;
  }
  table.table-cards td[data-label=""]::before { content: none; }
}

@media print {
  .topbar, .adminnav, .tabbar, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ccc; }
  .note-row, tr { break-inside: avoid; }
  .table-scroll { overflow: visible; }
  .report-table { font-size: .72rem; }
  .report-table th, .report-table td { padding: 4px; }
  a { color: inherit; text-decoration: none; }
}

/* ── شريط نسخة الديمو (DEMO_MODE=1 فقط) ── */
.demo-banner {
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; justify-content: center;
  padding: 7px 14px; background: var(--warn-soft); border-bottom: 1px solid #fde68a;
  color: #92400e; font-size: .85rem; text-align: center;
}
.demo-banner a { color: #92400e; font-weight: 700; }
