/* أسطول كنز — الهوية: أحمر كنز #C8102E وكحلي كنز #0B1B4D
   عناوين: Noto Kufi Arabic — نصوص: IBM Plex Sans Arabic */

:root {
  --red: #C8102E;
  --red-strong: #A50D26;
  --red-soft: #FBE9EC;
  --navy: #0B1B4D;
  --bg: #F4F5F9;
  --surface: #FFFFFF;
  --surface-2: #F8F9FC;
  --text: #121833;
  --muted: #5A6380;
  --border: #E1E4EE;
  --focus: #3B5BDB;

  --violation: #C8102E;
  --violation-bg: #FCECEF;
  --warning: #9A5B00;
  --warning-bg: #FFF4DE;
  --missing: #4B5675;
  --missing-bg: #EEF0F6;
  --ok: #157A4C;
  --ok-bg: #E5F5EC;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(11, 27, 77, .06), 0 4px 16px rgba(11, 27, 77, .05);
  --font-head: "Noto Kufi Arabic", "IBM Plex Sans Arabic", system-ui, sans-serif;
  --font-body: "IBM Plex Sans Arabic", "Noto Kufi Arabic", system-ui, sans-serif;
  --nav-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --red: #EF3E5A; --red-strong: #FF5C75; --red-soft: #3A1520;
    --bg: #080D1C; --surface: #111933; --surface-2: #0D1429; --text: #E9ECF5; --muted: #98A2BE;
    --border: #232E52; --focus: #8EA6FF;
    --violation: #FF6B80; --violation-bg: #3A1520; --warning: #F5B94A; --warning-bg: #33260C;
    --missing: #A9B2CC; --missing-bg: #1B2442; --ok: #4CD08F; --ok-bg: #0F2E21;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --red: #EF3E5A; --red-strong: #FF5C75; --red-soft: #3A1520;
  --bg: #080D1C; --surface: #111933; --surface-2: #0D1429; --text: #E9ECF5; --muted: #98A2BE;
  --border: #232E52; --focus: #8EA6FF;
  --violation: #FF6B80; --violation-bg: #3A1520; --warning: #F5B94A; --warning-bg: #33260C;
  --missing: #A9B2CC; --missing-bg: #1B2442; --ok: #4CD08F; --ok-bg: #0F2E21;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-size: 16px; line-height: 1.6;
}
h1, h2, h3 { font-family: var(--font-head); line-height: 1.35; margin: 0; font-weight: 700; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
a { color: inherit; }
p { margin: 0; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.icon { width: 22px; height: 22px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 18px; height: 18px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ── الهيكل ── */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--navy); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; }
.brand img { width: 34px; height: 34px; }
.brand b { font-family: var(--font-head); font-size: 1.05rem; }
.topbar .spacer { flex: 1; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px;
  border-radius: 50%; border: 0; background: transparent; color: inherit; cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, .12); }
.user-chip { display: flex; flex-direction: column; line-height: 1.25; text-align: start; }
.user-chip small { opacity: .75; font-size: .75rem; }
.brand b { white-space: nowrap; }
@media (max-width: 480px) { .user-chip { display: none; } .topbar { gap: 4px; } }

.layout { display: flex; min-height: calc(100vh - 62px); }
.sidebar { display: none; }
.content { flex: 1; min-width: 0; padding: 18px 16px calc(var(--nav-h) + 28px); max-width: 1180px; margin-inline: auto; }

.bottomnav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30; display: flex; height: var(--nav-h);
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a, .bottomnav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font: inherit; font-size: .72rem; background: none; border: 0; cursor: pointer;
}
.bottomnav .active { color: var(--red); font-weight: 600; }

.more-sheet { position: fixed; inset: 0; z-index: 40; display: none; background: rgba(8, 13, 28, .45); }
.more-sheet.open { display: block; }
.more-sheet .sheet {
  position: absolute; inset-inline: 0; bottom: 0; background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 10px 10px calc(16px + env(safe-area-inset-bottom));
}

@media (min-width: 900px) {
  .bottomnav, .more-sheet { display: none !important; }
  .sidebar {
    display: block; width: 236px; flex: none; padding: 18px 12px; background: var(--surface);
    border-inline-start: 1px solid var(--border);
  }
  .content { padding: 26px 28px 40px; }
}
.navlink {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: var(--radius-sm);
  text-decoration: none; color: var(--text); font-weight: 500;
}
.navlink:hover { background: var(--surface-2); }
.navlink.active { background: var(--red-soft); color: var(--red); font-weight: 600; }

/* ── عناصر عامة ── */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card, .section + .section { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
@media (min-width: 700px) { .grid-2 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.grid-4 { grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 1000px) { .grid-4 { grid-template-columns: repeat(4, 1fr); gap: 14px; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 18px;
  border-radius: var(--radius-sm); border: 1px solid transparent; background: var(--red); color: #fff;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--red-strong); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .88rem; }
.btn-block { width: 100%; }
.btn-danger-outline { background: transparent; color: var(--violation); border-color: currentColor; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; white-space: nowrap;
}
.badge-violation { background: var(--violation-bg); color: var(--violation); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-missing { background: var(--missing-bg); color: var(--missing); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat b { font-family: var(--font-head); font-size: 1.7rem; line-height: 1.2; }
.grid-4 > .stat { padding: 12px 14px; }
.stat span { color: var(--muted); font-size: .88rem; }
.stat.is-violation b { color: var(--violation); }
.stat.is-warning b { color: var(--warning); }

.plate {
  display: inline-flex; align-items: center; gap: 8px; padding: 3px 10px; border: 2px solid var(--text);
  border-radius: 8px; font-weight: 700; background: var(--surface); white-space: nowrap;
}
.plate .latin { direction: ltr; font-family: ui-monospace, monospace; font-size: .85em; color: var(--muted); }

/* القوائم */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; padding-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.row-link { text-decoration: none; display: block; }
.row-link:hover .title { color: var(--red); }
.title { font-weight: 600; }

.alert-item { display: flex; gap: 10px; align-items: flex-start; }
.alert-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 8px; flex: none; }
.alert-dot.violation { background: var(--violation); }
.alert-dot.warning { background: var(--warning); }
.alert-dot.missing { background: var(--missing); }

.kv { display: grid; grid-template-columns: minmax(120px, 38%) 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

.empty { text-align: center; padding: 22px 12px; color: var(--muted); }
.placeholder { border: 1.5px dashed var(--border); background: var(--surface-2); box-shadow: none; }
.placeholder .phase { font-size: .8rem; color: var(--muted); }

/* الجداول (تتحول لبطاقات على الجوال) */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: start; color: var(--muted); font-weight: 600; padding: 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }

/* النماذج */
.form-grid { display: grid; gap: 14px; }
@media (min-width: 760px) { .form-grid { grid-template-columns: repeat(2, 1fr); } .form-grid .full { grid-column: 1 / -1; } }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: .92rem; }
.field .help { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.field .error { color: var(--violation); font-size: .85rem; margin-top: 4px; font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: var(--radius-sm); border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea.input { min-height: 90px; }
.input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.field.has-error .input { border-color: var(--violation); }
.check-row { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.check { width: 22px; height: 22px; accent-color: var(--red); }
.form-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.fieldset-title { grid-column: 1 / -1; margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--border); color: var(--muted); font-size: .9rem; }

/* الرسائل */
.messages { display: grid; gap: 8px; margin-bottom: 16px; }
.msg { padding: 12px 14px; border-radius: var(--radius-sm); font-weight: 500; border: 1px solid transparent; }
.msg-success { background: var(--ok-bg); color: var(--ok); }
.msg-error { background: var(--violation-bg); color: var(--violation); }
.msg-warning { background: var(--warning-bg); color: var(--warning); }
.msg-info { background: var(--missing-bg); color: var(--missing); }

/* شاشة الدخول */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: var(--navy); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.auth-logo { display: block; margin: 0 auto 6px; height: 64px; }
.auth h1 { text-align: center; margin-bottom: 4px; }
.auth .sub { text-align: center; color: var(--muted); margin-bottom: 20px; }

/* شاشة السائق: أزرار كبيرة وحالة واضحة */
.driver-hero { text-align: center; padding: 26px 16px; }
.driver-hero h1 { font-size: 1.5rem; }
.big-action {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 76px; padding: 16px 18px; border-radius: 16px;
  border: 1.5px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 1.1rem; font-weight: 600;
  text-decoration: none;
}
.big-action[aria-disabled="true"] { opacity: .55; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.filters .input { width: auto; min-width: 150px; flex: 1; }
.pager { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 16px; }
.diff { font-size: .85rem; }
.diff div { margin-top: 2px; }
.diff del { color: var(--violation); text-decoration: line-through; }
.diff ins { color: var(--ok); text-decoration: none; font-weight: 600; }

/* ── أوامر الحركة ── */
:root { --progress: #1D5FD1; --progress-bg: #E6EEFC; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --progress: #7DA7FF; --progress-bg: #15254A; } }
:root[data-theme="dark"] { --progress: #7DA7FF; --progress-bg: #15254A; }
.badge-progress { background: var(--progress-bg); color: var(--progress); }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; }
.tab {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface); text-decoration: none; font-weight: 500; font-size: .9rem;
}
.tab.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.tab .count { font-size: .78rem; opacity: .8; }

.route { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.route .arrow { color: var(--muted); font-weight: 400; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 22px 18px 0; border-inline-start: 2px solid var(--border); margin-inline-start: 7px; }
.timeline li:last-child { border-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; inset-inline-start: -8px; top: 4px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--muted);
}
.timeline li.done::before { border-color: var(--ok); background: var(--ok); }
.timeline li.current::before { border-color: var(--progress); }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-top: 8px; }
.photos a, .photos img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.photo-caption { font-size: .78rem; color: var(--muted); margin-top: 2px; }

/* شاشة خطوة السائق */
.step-head { text-align: center; padding: 8px 0 18px; }
.step-head h1 { font-size: 1.5rem; }
.capture {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 170px;
  border: 2px dashed var(--border); border-radius: 18px; background: var(--surface); cursor: pointer; text-align: center;
  font-size: 1.1rem; font-weight: 600; padding: 18px;
}
.capture .icon { width: 44px; height: 44px; color: var(--red); }
.capture input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.capture-preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-top: 10px; }
.capture-preview img { width: 100%; border-radius: 12px; }
.big-input { font-size: 1.6rem; text-align: center; letter-spacing: 2px; min-height: 64px; font-weight: 700; }
.btn-xl { min-height: 64px; font-size: 1.2rem; border-radius: 16px; }
.status-hero { text-align: center; padding: 22px 16px; border-radius: 18px; }
.status-hero .badge { font-size: .95rem; padding: 4px 14px; }
.status-hero.progress { background: var(--progress-bg); }
.status-hero.ok { background: var(--ok-bg); }
.status-hero.warning { background: var(--warning-bg); }
.pending-banner { display: flex; align-items: center; gap: 10px; }
.flag-row { display: flex; gap: 10px; align-items: flex-start; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.inline-form .input { flex: 1; min-width: 180px; min-height: 40px; }
details.card > summary { list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary { margin-bottom: 4px; }
