:root {
  --brand: #8a1538;
  --brand-d: #650d28;
  --brand-soft: #f8ecef;
  --accent: #01af86;
  --accent-d: #00795e;
  --bg: #f5f2ee;
  --surface: #fff;
  --ink: #0f172a;
  --muted: #6f666a;
  --line: #e6dfd9;
  --ok: #1f7a4d;
  --ok-soft: #e5f4ec;
  --warn: #8a5a00;
  --warn-soft: #fff3d1;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --info: #1d5a8a;
  --info-soft: #e5f0f8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(35, 28, 31, .05), 0 6px 20px rgba(35, 28, 31, .05);
  --font: "Readex Pro", "Segoe UI", Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; font-weight: 400; line-height: 1.75; color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { margin: 0; line-height: 1.35; text-wrap: balance; }
p { margin: 0 0 .6rem; }
.muted { color: var(--muted); }
.ic { width: 1.25em; height: 1.25em; flex: none; vertical-align: -.22em; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 2px; border-radius: 6px; }

/* ---------- الهيكل ---------- */
.shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }
.side { background: linear-gradient(180deg, var(--brand) 0%, var(--brand-d) 100%); color: #fff; display: flex; flex-direction: column; padding: 22px 14px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; padding: 0 8px 20px; border-bottom: 1px solid rgba(255, 255, 255, .15); margin-bottom: 14px; }
.brand:hover { text-decoration: none; }
.brand strong { display: block; font-size: 1.12rem; }
.brand small { display: block; opacity: .78; font-size: .8rem; }
.brand-mark { width: 48px; height: 48px; flex: none; display: grid; place-items: center; border-radius: 13px; background: #fff; padding: 6px; }
.brand-mark svg { width: 100%; height: 100%; display: block; }
.brand-mark.lg { width: 62px; height: 62px; }
.brand-mark.xl { width: 84px; height: 84px; }
.brand-mark.plain { background: none; padding: 0; border-radius: 0; }
.lang { font-size: .82rem; font-weight: 600; padding: 6px 12px; border-radius: 99px; border: 1px solid rgba(255, 255, 255, .35); color: #fff; white-space: nowrap; }
.lang:hover { background: rgba(255, 255, 255, .14); text-decoration: none; }
.auth-card { position: relative; }
.auth-card > .lang { position: absolute; top: 16px; inset-inline-end: 16px; color: var(--brand); border-color: var(--line); }
.auth-card > .lang:hover { background: var(--brand-soft); }
.credit { text-align: center; color: var(--muted); font-size: .8rem; margin: 22px 0 0; }
.credit b { color: var(--accent-d); }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: rgba(255, 255, 255, .86); font-weight: 500; min-height: 44px; }
.nav a:hover { background: rgba(255, 255, 255, .1); text-decoration: none; color: #fff; }
.nav a.on { background: #fff; color: var(--brand); }
.nav .count { margin-inline-start: auto; background: var(--accent); color: #062a21; font-weight: 700; border-radius: 99px; padding: 0 9px; font-size: .8rem; line-height: 1.7; }
.side-user { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 8px 0; border-top: 1px solid rgba(255, 255, 255, .15); }
.side-user strong { display: block; font-size: .95rem; }
.side-user small { opacity: .78; font-size: .8rem; }
.icon-btn { background: rgba(255, 255, 255, .12); border: 0; color: #fff; width: 42px; height: 42px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(255, 255, 255, .22); }

.main { padding: 26px clamp(16px, 3vw, 38px) 60px; max-width: 1280px; width: 100%; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.top h1 { font-size: 1.6rem; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.clock { color: var(--muted); font-weight: 500; display: inline-flex; gap: 6px; align-items: center; }
.welcome { color: var(--muted); margin-top: -12px; margin-bottom: 18px; }
.sec-title { font-size: 1.08rem; margin: 26px 0 12px; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; }

/* ---------- عناصر عامة ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; margin: 0 0 16px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 640px; }
.card h2 { font-size: 1.05rem; margin-bottom: 14px; display: flex; gap: 8px; align-items: center; }
fieldset.card { min-inline-size: 0; }
legend { font-weight: 600; font-size: 1.05rem; padding: 0 8px; display: flex; align-items: center; gap: 10px; }
.step-no { width: 28px; height: 28px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-size: .9rem; font-weight: 700; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; background: #faf7f4; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-d); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ok:hover { background: #17603c; }
.btn.bad { background: var(--surface); border-color: var(--bad); color: var(--bad); }
.btn.bad:hover { background: var(--bad-soft); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.ghost-bad { border-color: transparent; background: none; color: var(--bad); }
.btn.lg { min-height: 48px; padding: 10px 22px; font-size: 1.02rem; }
.btn.block { width: 100%; }

.badge { display: inline-block; padding: 2px 11px; border-radius: 99px; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.b-pending { background: var(--warn-soft); color: var(--warn); }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-muted { background: #eee9e5; color: var(--muted); }
.badge.g-wait { background: var(--info-soft); color: var(--info); }
.badge.g-active { background: var(--ok-soft); color: var(--ok); }
.badge.g-late { background: var(--bad); color: #fff; }
.badge.g-done { background: #eee9e5; color: var(--muted); }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; border: 1px solid; }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe3cf; }
.alert-bad { background: var(--bad-soft); color: var(--bad); border-color: #f5c6c0; }

.empty { text-align: center; color: var(--muted); padding: 44px 16px; }
.empty .ic { width: 42px; height: 42px; opacity: .45; }

/* ---------- الرئيسية ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.stat { display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; color: var(--ink); box-shadow: var(--shadow); }
.stat:hover { text-decoration: none; border-color: var(--brand); }
.stat b { display: block; font-size: 1.8rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); }
.stat-ic { width: 46px; height: 46px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-size: 1.2rem; }
.stat.accent { background: var(--brand); border-color: var(--brand); color: #fff; }
.stat.accent small { color: rgba(255, 255, 255, .85); }
.stat.accent .stat-ic { background: rgba(255, 255, 255, .16); color: #fff; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.tile { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; color: var(--ink); box-shadow: var(--shadow); transition: transform .12s, border-color .12s; }
.tile:hover { text-decoration: none; border-color: var(--brand); transform: translateY(-2px); }
.tile strong { display: block; margin: 10px 0 2px; }
.tile small { color: var(--muted); display: block; line-height: 1.5; }
.tile-ic { width: 44px; height: 44px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-size: 1.25rem; }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: start; font-size: .82rem; color: var(--muted); font-weight: 600; background: #faf7f4; padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fdfbf9; }
.ref { font-weight: 700; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; white-space: nowrap; }
.ref.big { font-size: 1.35rem; color: var(--brand); margin-inline-end: 8px; }
.type { display: inline-flex; align-items: center; gap: 7px; }
.type .ic { color: var(--brand); }

/* ---------- النماذج ---------- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px 16px; }
.col-2 { grid-column: span 2; } .col-3 { grid-column: span 3; } .col-4 { grid-column: span 4; }
.col-6 { grid-column: span 6; } .col-8 { grid-column: span 8; } .col-12 { grid-column: 1 / -1; }
.stack { display: grid; gap: 14px; }
.field { min-width: 0; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 5px; }
.req { color: var(--bad); }
input[type=text], input[type=tel], input[type=number], input[type=date], input[type=time], input[type=password], input[type=search], input:not([type]), select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid #d5ccc5; border-radius: 10px; background: #fff; font: inherit; color: var(--ink);
}
textarea { resize: vertical; min-height: 92px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
input.file { width: 100%; padding: 12px; border: 1.5px dashed #cfc4bb; border-radius: 10px; background: #faf7f4; font: inherit; }
.hint { display: block; color: var(--muted); font-size: .82rem; margin-top: 4px; }
.err { display: block; color: var(--bad); font-size: .85rem; font-weight: 600; margin-top: 4px; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--bad); }
.list-inputs { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.checks { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: 6px 0; font-weight: 500; }
.check input { width: 20px; height: 20px; margin-top: 4px; accent-color: var(--brand); flex: none; }
.check.strong { font-weight: 700; margin-top: 8px; }
.pledge { background: #fffaf0; border-color: #ecdcb8; }
.pledge ul { margin: 0 0 8px; padding-inline-start: 20px; }
.pledge.has-error { border-color: var(--bad); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.cancel-row { text-align: end; }
.filters { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; padding: 16px; }
.filters .field { min-width: 170px; }
.filters .grow { flex: 1 1 260px; }
.two-col { display: grid; grid-template-columns: minmax(300px, 420px) minmax(0, 1fr); gap: 16px; align-items: start; }
.roles-help { margin: 0; padding-inline-start: 20px; }

/* ---------- عرض الطلب ---------- */
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 22px; margin: 0; }
.kv .wide { grid-column: 1 / -1; }
.kv dt { color: var(--muted); font-size: .82rem; }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.kv.compact { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 16px; }
.names, .ticks { margin: 0; padding-inline-start: 20px; }
.ticks { list-style: "✓  "; }
.req-head > div { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.flow { list-style: none; display: flex; flex-wrap: wrap; gap: 8px 0; padding: 0; margin: 16px 0 0; }
.flow li { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 500; font-size: .92rem; }
.flow li + li::before { content: ""; width: 34px; height: 2px; background: var(--line); margin-inline: 10px; }
.flow span { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: #eee9e5; font-size: .85rem; font-weight: 700; }
.flow .done { color: var(--ok); } .flow .done span { background: var(--ok); color: #fff; }
.flow .now { color: var(--brand); font-weight: 700; } .flow .now span { background: var(--brand); color: #fff; box-shadow: 0 0 0 4px var(--brand-soft); }
.flow .stop { color: var(--bad); } .flow .stop span { background: var(--bad); color: #fff; }
.action-box { border: 2px solid var(--brand); background: var(--brand-soft); }
.action-box .field { margin-bottom: 12px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 12px; }
.thumb { width: 168px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; color: var(--ink); background: #faf7f4; }
.thumb img { display: block; width: 100%; height: 118px; object-fit: cover; }
.thumb span { display: block; padding: 6px 10px; font-size: .8rem; line-height: 1.4; }
.thumb.pdf { display: grid; place-items: center; padding-top: 22px; text-align: center; }
.thumb.pdf .ic { width: 40px; height: 40px; color: var(--brand); }
.log { list-style: none; margin: 0; padding: 0; border-inline-start: 2px solid var(--line); }
.log li { position: relative; padding: 0 0 16px; padding-inline-start: 18px; }
.log li:last-child { padding-bottom: 0; }
.log li::before { content: ""; position: absolute; inset-inline-start: -7px; top: 8px; width: 12px; height: 12px; border-radius: 50%; background: var(--ok); border: 2px solid #fff; }
.log li.reject::before, .log li.cancel::before { background: var(--bad); }
.log li.submit::before { background: var(--accent); }
.log small { display: block; color: var(--muted); }
.log p { margin: 6px 0 0; background: #faf7f4; border-radius: 8px; padding: 8px 12px; }

/* ---------- البوابة ---------- */
.gate-search { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); margin-bottom: 14px; }
.gate-search > .ic { color: var(--muted); font-size: 1.2rem; }
.gate-search input { border: 0; box-shadow: none; flex: 1; font-size: 1.05rem; min-width: 0; }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 16px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); color: var(--ink); font-weight: 600; white-space: nowrap; min-height: 42px; display: inline-flex; align-items: center; gap: 8px; }
.tabs a:hover { text-decoration: none; }
.tabs a.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.tabs b { background: rgba(0, 0, 0, .08); border-radius: 99px; padding: 0 8px; font-size: .82rem; }
.tabs a.on b { background: rgba(255, 255, 255, .22); }
.passes { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 430px), 1fr)); gap: 16px; }
.pass { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border-inline-start: 6px solid var(--info); display: flex; flex-direction: column; }
.pass.g-active { border-inline-start-color: var(--ok); }
.pass.g-late { border-inline-start-color: var(--bad); background: #fffafa; }
.pass.g-done { border-inline-start-color: #c9c0b9; opacity: .85; }
.pass > header { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.pass-body { display: flex; gap: 14px; padding: 14px 16px; flex: 1; }
.pass-info { flex: 1; min-width: 0; }
.when { font-weight: 700; color: var(--brand); display: flex; gap: 6px; align-items: center; }
.pass .kv dd { font-size: 1.02rem; }
.plate { display: inline-block; border: 2px solid var(--ink); border-radius: 6px; padding: 0 10px; font-size: 1.15rem !important; letter-spacing: .06em; direction: ltr; background: #fff; }
.idno { direction: ltr; text-align: end; font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.pass-photos { display: flex; flex-direction: column; gap: 8px; flex: none; }
.pass-photos img { width: 118px; height: 80px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.pdf-chip { display: inline-flex; gap: 6px; align-items: center; font-size: .85rem; }
.pass > footer { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; background: #faf7f4; border-top: 1px solid var(--line); }
.pass > footer small { color: var(--muted); }
.pass > footer form { margin-inline-start: auto; }

.lightbox { position: fixed; inset: 0; background: rgba(20, 14, 16, .88); display: grid; place-items: center; z-index: 50; padding: 20px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 92vh; border-radius: 10px; background: #fff; }

/* ---------- الدخول ---------- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 20px; background: linear-gradient(160deg, var(--brand) 0%, var(--brand-d) 55%, #3d0818 100%); }
.auth-card { background: var(--surface); border-radius: 20px; padding: 34px 30px; width: min(100%, 420px); box-shadow: 0 24px 60px rgba(0, 0, 0, .3); }
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand .brand-mark { margin: 0 auto 14px; }
.auth-brand h1 { font-size: 1.3rem; }
.auth-brand p { color: var(--muted); margin: 4px 0 0; }
.auth-card h2 { font-size: 1.05rem; }

/* ---------- الطباعة ---------- */
body.print { background: #e9e4df; }
.print-bar { display: flex; gap: 10px; justify-content: center; padding: 14px; }
.sheet { background: #fff; width: 210mm; max-width: 100%; min-height: 290mm; margin: 0 auto 30px; padding: 16mm 15mm; box-shadow: var(--shadow); font-size: 12.5pt; }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; border-bottom: 3px double var(--brand); padding-bottom: 10px; }
.sheet-head strong, .sheet-head small { display: block; }
.sheet-meta { text-align: end; font-size: 10.5pt; }
.sheet-meta span { display: block; }
.sheet h1 { text-align: center; font-size: 18pt; margin: 16px 0 2px; color: var(--brand); }
.sheet-status { text-align: center; font-size: 11pt; }
.sheet h2 { font-size: 12pt; background: var(--brand-soft); color: var(--brand); padding: 4px 10px; border-radius: 4px; margin: 14px 0 6px; }
.sheet-table { width: 100%; border-collapse: collapse; }
.sheet-table th, .sheet-table td { border: 1px solid #bdb3ac; padding: 5px 9px; text-align: start; vertical-align: top; }
.sheet-table th { width: 34%; background: #faf7f4; font-weight: 600; }
.sheet-pledge { margin: 0; padding-inline-start: 22px; font-size: 11.5pt; }
.sheet-note { border: 1px solid #bdb3ac; padding: 8px 10px; margin: 0; }
.signs { display: grid; grid-template-columns: repeat(auto-fit, minmax(42mm, 1fr)); gap: 10px; margin-top: 22px; break-inside: avoid; }
.signs div { border: 1px solid #bdb3ac; border-radius: 6px; padding: 8px 10px; min-height: 26mm; }
.signs small, .signs b, .signs i { display: block; }
.signs small { color: var(--muted); font-size: 9.5pt; }
.signs i { font-style: normal; font-size: 9.5pt; color: var(--muted); margin-top: 6px; }
.sheet-foot { margin-top: 18px; border-top: 1px solid #bdb3ac; padding-top: 6px; text-align: center; font-size: 9pt; color: var(--muted); }

@media print {
  @page { size: A4; margin: 12mm; }
  body.print { background: #fff; }
  .no-print { display: none !important; }
  .sheet { box-shadow: none; margin: 0; padding: 0; width: auto; min-height: 0; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- الجوال ---------- */
@media (max-width: 900px) {
  .shell { display: block; }
  .side { position: static; height: auto; padding: 12px 16px; }
  .brand { padding: 0 0 10px; margin-bottom: 8px; }
  .nav { flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 6px; margin-inline: -16px; padding-inline: 16px; }
  .nav a { white-space: nowrap; flex: none; padding: 8px 12px; }
  .side-user { position: absolute; top: 12px; inset-inline-end: 16px; border: 0; padding: 0; }
  .side-user > div { display: none; }
  .side { position: relative; }
  .main { padding: 18px 16px 50px; }
  .top h1 { font-size: 1.3rem; }
  .col-2, .col-3, .col-4 { grid-column: span 6; }
  .col-6, .col-8 { grid-column: 1 / -1; }
  .two-col { grid-template-columns: 1fr; }
  .flow li + li::before { width: 14px; margin-inline: 6px; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 10px 16px; border-bottom: 1px solid var(--line); }
  .table td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: end; }
  .table td[data-l]::before { content: attr(data-l); color: var(--muted); font-size: .82rem; flex: none; }
  .pass-body { flex-direction: column; }
  .pass-photos { flex-direction: row; flex-wrap: wrap; }
  .pass > footer form, .pass > footer .btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
