@font-face { font-family: "Plex Arabic"; src: url("../fonts/IBMPlexSansArabic-Regular.f36223390481.ttf"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Arabic"; src: url("../fonts/IBMPlexSansArabic-SemiBold.ab61f0dde312.ttf"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Plex Arabic"; src: url("../fonts/IBMPlexSansArabic-Bold.2e56c2f3563a.ttf"); font-weight: 700; font-display: swap; }

:root {
  --navy: #14304A;      /* هيكل الواجهة */
  --navy-2: #1F4566;
  --steel: #4F6475;     /* نص ثانوي */
  --line: #D6DDE4;
  --bg: #EEF1F4;
  --surface: #FFFFFF;
  --ink: #16202B;
  --signal: #E8A317;    /* ينتظر إجراء */
  --signal-bg: #FDF3DC;
  --ok: #2E7D4F;
  --ok-bg: #E3F1E8;
  --danger: #B3261E;
  --danger-bg: #FBE7E5;
  --radius-s: 4px;
  --radius-m: 8px;
  --tap: 48px;
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; font-family: "Plex Arabic", "Segoe UI", Tahoma, sans-serif; color: var(--ink); background: var(--bg);
       line-height: 1.6; font-feature-settings: "tnum" 1; }
a { color: var(--navy-2); }
bdi.ref, .ref { font-weight: 600; letter-spacing: .01em; unicode-bidi: isolate; direction: ltr; }
:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; }

/* الشريط العلوي */
.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 24px; padding: 0 20px; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { color: #D9E3EC; text-decoration: none; padding: 14px 12px; border-bottom: 3px solid transparent; }
.nav a:hover { color: #fff; }
.nav a.on { color: #fff; border-bottom-color: var(--signal); }
.nav-badge { display: inline-block; min-width: 18px; padding: 1px 5px; margin-inline-start: 4px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700; text-align: center; }
.who { display: flex; align-items: center; gap: 10px; font-size: .9rem; color: #C7D3DE; }
.who form { margin: 0; }
.who .who-pw { color: #fff; border: 1px solid #5E7A93; border-radius: var(--radius-s); padding: 4px 10px; text-decoration: none; white-space: nowrap; }
.who .who-pw:hover { background: rgba(255,255,255,.08); }
.who button { background: transparent; color: #fff; border: 1px solid #5E7A93; border-radius: var(--radius-s); padding: 4px 10px; cursor: pointer; font: inherit; }

main { max-width: 1900px; margin: 0 auto; padding: 24px 20px 64px; }
h1 { font-size: 1.6rem; margin: 0 0 4px; line-height: 1.3; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.sub { color: var(--steel); margin: 0 0 20px; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }

/* الأقسام */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 20px; margin-bottom: 20px; }
.panel.flat { padding: 0; overflow: hidden; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } main { padding: 16px 12px 48px; } }

/* الحقول */
label.f { display: block; font-size: .9rem; color: var(--steel); }
label.f > span { display: block; margin-bottom: 4px; }
label.f.req > span::after { content: " *"; color: var(--danger); }
input, select, textarea { font: inherit; color: var(--ink); width: 100%; min-height: var(--tap); padding: 8px 12px;
  border: 1px solid #B8C3CE; border-radius: var(--radius-s); background: #fff; }
textarea { min-height: 88px; }
input[type=checkbox], input[type=radio] { width: 22px; height: 22px; min-height: 0; vertical-align: middle; accent-color: var(--navy); }
input.ltr, .ltr { direction: ltr; text-align: right; }
.err input, .err select, .err textarea, input.err { border-color: var(--danger); background: var(--danger-bg); }
.ferr { color: var(--danger); font-size: .85rem; margin-top: 4px; display: block; }
.help { color: var(--steel); font-size: .85rem; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.checks label { display: flex; gap: 8px; align-items: center; min-height: 40px; }

/* الأزرار */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 0 20px;
  border-radius: var(--radius-s); border: 1px solid var(--navy); background: var(--navy); color: #fff; font: inherit;
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--navy-2); }
.btn.ghost { background: #fff; color: var(--navy); }
.btn.ghost:hover { background: #F2F6F9; }
.btn.warn { background: var(--signal); border-color: #C98B0C; color: #2B1D00; }
.btn.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn.big { min-height: 56px; font-size: 1.05rem; padding: 0 28px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* الرسائل */
.msgs { list-style: none; padding: 0; margin: 0 0 16px; }
.msgs li { padding: 12px 16px; border-radius: var(--radius-s); margin-bottom: 8px; border-inline-start: 5px solid; }
.msgs .success { background: var(--ok-bg); border-color: var(--ok); }
.msgs .error { background: var(--danger-bg); border-color: var(--danger); }
.msgs .info, .msgs .warning { background: var(--signal-bg); border-color: var(--signal); }
.blocker { background: var(--signal-bg); border: 1px solid #EAC46B; border-radius: var(--radius-s); padding: 12px 16px; margin-bottom: 12px; }
.blocker ul { margin: 6px 0 0; padding-inline-start: 20px; }

/* الجداول */
table.t { width: 100%; border-collapse: collapse; font-size: .95rem; }
.t th { text-align: right; font-weight: 600; color: var(--steel); background: #F5F7F9; border-bottom: 1px solid var(--line); padding: 10px 12px; position: sticky; top: 0; }
.t td { border-bottom: 1px solid #E7ECF0; padding: 10px 12px; vertical-align: top; }
.t tr:last-child td { border-bottom: 0; }
.t td.num, .t th.num { text-align: left; direction: ltr; white-space: nowrap; }
.t tfoot td { font-weight: 700; background: #F5F7F9; border-top: 2px solid var(--line); }
.scroll { overflow-x: auto; }

/* الحالات */
.st { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.st.confirmed { background: var(--ok-bg); color: var(--ok); }
.st.draft, .st.provisional { background: var(--signal-bg); color: #7A5200; }
.st.cancelled { background: #ECEFF2; color: var(--steel); text-decoration: line-through; }

/* رأس الإيصال */
.receipt-head { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: start; }
.bigref { font-size: 2rem; font-weight: 700; direction: ltr; text-align: right; line-height: 1.2; margin: 0; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 24px; margin: 0; }
.kv div { min-width: 0; }
.kv dt { color: var(--steel); font-size: .85rem; }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.totals { display: flex; gap: 32px; flex-wrap: wrap; }
.totals .n { font-size: 1.7rem; font-weight: 700; line-height: 1.2; direction: ltr; text-align: right; }
.totals .l { color: var(--steel); font-size: .88rem; }

/* شبكة الطرود: كل طرد مادي مربع يعرض حالته الآن */
.pieces { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.pc { position: relative; border: 2px solid var(--navy); border-radius: var(--radius-s); background: #fff; padding: 6px 8px 5px;
      text-decoration: none; color: var(--ink); min-height: 72px; display: flex; flex-direction: column; justify-content: space-between; }
.pc .s { font-size: 1.35rem; font-weight: 700; line-height: 1; direction: ltr; text-align: right; }
.pc .s small { font-size: .7rem; color: var(--steel); font-weight: 600; }
.pc .loc { font-size: .72rem; color: var(--steel); direction: ltr; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc.released { background: #DCE3E9; border-color: #9AAAB8; color: #52606D; }
.pc.in_transit { border-style: dashed; border-color: #C98B0C; background: repeating-linear-gradient(-45deg, #fff 0 8px, var(--signal-bg) 8px 16px); }
.pc.damaged { border-color: var(--danger); background: var(--danger-bg); }
.pc.consumed { border-style: dotted; border-color: #9AAAB8; color: #6B7885; }
.pc.nested { box-shadow: inset 0 -4px 0 var(--navy-2); }
.pc.void { opacity: .45; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .85rem; color: var(--steel); margin-top: 12px; }
.legend i { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--navy); border-radius: 2px; vertical-align: -2px; margin-inline-end: 4px; }

/* نموذج الأسطر */
.lines-table input, .lines-table select { min-height: 44px; padding: 6px 8px; }
.lines-table td { padding: 6px; }
.lines-table .vol { font-weight: 700; white-space: nowrap; direction: ltr; text-align: left; min-width: 80px; }
.rm { background: none; border: 0; color: var(--danger); font-size: 1.4rem; cursor: pointer; min-width: 40px; min-height: 40px; }
.sticky-foot-unused { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 12px 20px;
  display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin: 0 -20px -20px; border-radius: 0 0 var(--radius-m) var(--radius-m); }
.livetotal { font-size: 1.05rem; }
.livetotal b { font-size: 1.3rem; direction: ltr; display: inline-block; }

/* لوحة التشغيل */
.stat .n { font-size: 2.2rem; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--steel); }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { padding: 10px 0; border-bottom: 1px solid #E7ECF0; display: flex; justify-content: space-between; gap: 12px; }
.list-plain li:last-child { border-bottom: 0; }
.empty { color: var(--steel); padding: 16px 0; }

/* المسح */
.scanbox input { font-size: 1.4rem; min-height: 64px; direction: ltr; text-align: center; letter-spacing: .04em; }

.filters { display: grid; grid-template-columns: 2fr repeat(4, 1fr) auto; gap: 12px; align-items: end; }
@media (max-width: 900px) { .filters { grid-template-columns: 1fr 1fr; } }
.pager { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }

.login { max-width: 400px; margin: 10vh auto; }
.login .brandline { color: var(--navy); font-weight: 700; font-size: 1.3rem; margin-bottom: 4px; }

.track { max-width: 560px; margin: 40px auto; }
.muted { color: var(--steel); }
.nowrap { white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* الأرقام الطويلة لا تُقص ولا تنكسر */
.bigref, bdi.ref { white-space: nowrap; }
.pc .st-line { font-size: .72rem; font-weight: 600; white-space: nowrap; }
.pc.released .st-line { color: #52606D; }
.pc.damaged .st-line { color: var(--danger); }
.pc.in_transit .st-line { color: #7A5200; }
.savebar { position: sticky; bottom: 0; z-index: 5; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m);
  padding: 12px 20px; display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  box-shadow: 0 -6px 16px rgba(20, 48, 74, .08); }
@media (max-width: 720px) {
  .topbar { gap: 0 12px; padding: 0 12px; justify-content: space-between; }
  .nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .nav a { padding: 10px 10px; white-space: nowrap; }
  .who span { display: none; }
  .receipt-head { grid-template-columns: 1fr; }
  .bigref { font-size: clamp(1.25rem, 7vw, 2rem); }
  .totals { gap: 16px 24px; }
  .totals .n { font-size: 1.35rem; }
}

/* Unified freight operations workspace */
.ops-filters { display:grid; grid-template-columns:minmax(260px,2fr) repeat(3,minmax(140px,1fr)) auto; gap:12px; align-items:end; }
.ops-table { min-width:1180px; }
.mode { display:inline-block; padding:2px 10px; border-radius:999px; color:#fff; font-size:.82rem; font-weight:700; }
.mode.air { background:#6f42c1; }.mode.ocean { background:#087f9c; }.mode.land { background:#2e7d4f; }
.ops-stage { display:flex; justify-content:flex-end; gap:0; margin-bottom:14px; overflow-x:auto; }
.ops-stage span { position:relative; padding:7px 18px; background:#e3e8ed; color:#617180; white-space:nowrap; border-inline-end:2px solid #fff; font-size:.86rem; }
.ops-stage span.active { background:var(--navy); color:#fff; font-weight:700; }
.ops-tabs { display:flex; overflow-x:auto; border-bottom:1px solid var(--line); margin-bottom:16px; background:#fff; }
.ops-tabs span { white-space:nowrap; padding:10px 14px; border-inline-end:1px solid var(--line); color:var(--steel); }
.ops-tabs span.active { color:var(--navy); border-bottom:3px solid var(--navy); font-weight:700; }
.mode-fields[hidden] { display:none; }
.cargo-picker { margin-top:14px; }.cargo-picker > summary { width:max-content; list-style:none; }.cargo-picker > form { margin-top:12px; }
.receipt-picker { border:1px solid var(--line); border-radius:var(--radius-m); padding:12px; background:#f7f9fb; max-height:480px; overflow:auto; }
.timeline { border-inline-start:3px solid #dbe3ea; margin-inline-start:8px; padding-inline-start:18px; }
.timeline > div { position:relative; padding:0 0 16px; }.timeline > div::before { content:""; position:absolute; inset-inline-start:-25px; top:5px; width:11px; height:11px; background:var(--navy); border-radius:50%; }
.timeline span { color:var(--steel); font-size:.85rem; margin-inline-start:12px; }.timeline p { margin:2px 0 0; }
@media(max-width:1000px){.ops-filters{grid-template-columns:1fr 1fr}.ops-filters .btn{width:100%}}
@media(max-width:560px){.ops-filters{grid-template-columns:1fr}.ops-stage{justify-content:flex-start}.ops-tabs{margin-inline:-12px}}

.ops-tabs a{padding:12px 16px;text-decoration:none;white-space:nowrap}html[dir=ltr] .t th,html[dir=ltr] .bigref,html[dir=ltr] .totals .n{text-align:left}
.lookup{position:relative}.lookup-create{border:0;background:transparent;color:#17618c;cursor:pointer;padding:5px}.lookup-results{position:absolute;top:48px;left:0;right:0;z-index:20;background:white;box-shadow:0 8px 18px #0002;max-height:230px;overflow:auto}.lookup-results:empty{display:none}.lookup-results button{display:block;width:100%;text-align:left;background:white;border:0;padding:10px;cursor:pointer}.lookup-results button:hover{background:#e7f2fa}.definition-modal{width:min(540px,95vw);border:0;border-radius:12px;padding:24px}.definition-modal::backdrop{background:#142b4577}.definition-modal label{display:block;margin:10px 0}.definition-modal [role=alert]{color:#a22}.cargo-receipt{padding:12px;border-bottom:1px solid #ddd}.cargo-receipt summary{cursor:pointer;padding:10px}#cargo-selection-total{font-weight:bold;position:sticky;top:0;background:#e3f1e8;padding:14px;z-index:5}.errorlist{color:#a22}
