/* ── مندوب — تنسيق عربي 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); }

.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 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], input[type=date] { direction: ltr; text-align: right; }

/* اختيار بأزرار كبيرة بدل قوائم منسدلة: الاختيار بضغطة واحدة في الشارع
   أسرع وأقل خطأً من فتح قائمة والتمرير فيها. */
.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-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; }

/* ── الخريطة ────────────────────────────────────────────────────────── */
#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; }

@media print {
  .topbar, .adminnav, .tabbar, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}
