:root {
  --paper: #f3f5f4;
  --card: #ffffff;
  --ink: #142033;
  --ink-2: #455062;
  --mute: #6b7684;
  --line: #d8dedc;
  --line-2: #eaeeec;
  --teal: #0b6e75;
  --teal-d: #084f54;
  --teal-l: #e1f0f0;
  --red: #bf2b2b;
  --red-l: #fbe9e8;
  --amber: #a96a06;
  --amber-l: #fcf0d9;
  --green: #2c7a4b;
  --green-l: #e3f2e9;
  --blue: #2f55a4;
  --blue-l: #e6ecf8;
  --r: 6px;
  --font: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.65;
  font-variant-numeric: tabular-nums;
}
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.35; font-weight: 600; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #f2b705; outline-offset: 2px; }
[hidden] { display: none !important; }
.num { direction: ltr; unicode-bidi: embed; display: inline-block; }

/* ---------- القشرة ---------- */
.topbar { background: var(--ink); color: #fff; }
.topbar-in { max-width: 1280px; margin: 0 auto; padding: 0 20px; display: flex; align-items: center; gap: 24px; min-height: 56px; }
.brand { font-weight: 600; font-size: 1.05rem; white-space: nowrap; display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; position: relative; flex: none; }
.brand-mark::before, .brand-mark::after { content: ''; position: absolute; top: 7px; width: 3px; height: 3px; background: #fff; border-radius: 50%; }
.brand-mark::before { inset-inline-start: 6px; }
.brand-mark::after { inset-inline-end: 6px; }
.brand-mark i { position: absolute; bottom: 4px; inset-inline: 6px; height: 5px; border-bottom: 2px solid #fff; border-radius: 0 0 8px 8px; }
.topnav { display: flex; flex-wrap: wrap; gap: 0 2px; flex: 1; min-width: 0; }
.topnav a { color: #c9d3df; padding: 16px 10px; white-space: nowrap; border-bottom: 3px solid transparent; font-size: .95rem; }
.topnav a:hover { color: #fff; text-decoration: none; }
.topnav a.on { color: #fff; border-bottom-color: #f2b705; }
.me { display: flex; align-items: center; gap: 12px; font-size: .9rem; color: #c9d3df; white-space: nowrap; }
.me b { color: #fff; font-weight: 500; }
.me button { background: none; border: 1px solid #55657a; color: #fff; padding: 4px 12px; border-radius: var(--r); cursor: pointer; }
.me button:hover { background: #22324b; }
main { max-width: 1280px; margin: 0 auto; padding: 24px 20px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; color: var(--mute); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- أزرار وحقول ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--teal); background: var(--teal); color: #fff; cursor: pointer;
  padding: 8px 16px; border-radius: var(--r); font-weight: 500; min-height: 40px; line-height: 1.2;
}
.btn:hover { background: var(--teal-d); border-color: var(--teal-d); text-decoration: none; }
.btn.ghost { background: transparent; color: var(--teal); }
.btn.ghost:hover { background: var(--teal-l); }
.btn.danger { background: var(--red); border-color: var(--red); }
.btn.danger.ghost { background: transparent; color: var(--red); }
.btn.danger.ghost:hover { background: var(--red-l); }
.btn.sm { min-height: 32px; padding: 4px 12px; font-size: .9rem; }
.btn[disabled] { opacity: .55; cursor: wait; }
label.f { display: block; font-size: .9rem; font-weight: 500; color: var(--ink-2); margin-bottom: 14px; }
label.f .hint { display: block; font-weight: 400; color: var(--mute); font-size: .85rem; margin-top: 2px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=month], input[type=search], input[type=tel], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px; background: #fff; border: 1px solid #b9c3c0; border-radius: var(--r); margin-top: 4px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); }
.check { display: flex; gap: 8px; align-items: center; font-size: .95rem; margin-bottom: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--teal); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.err { background: var(--red-l); color: var(--red); border: 1px solid #efc3c0; padding: 10px 12px; border-radius: var(--r); margin-bottom: 14px; }
.info { background: var(--blue-l); color: #20407e; border: 1px solid #c5d3ee; padding: 10px 12px; border-radius: var(--r); margin-bottom: 14px; font-size: .92rem; }

/* ---------- أسطح ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
.panel-h { padding: 12px 16px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-b { padding: 16px; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.stack > * + * { margin-top: 20px; }
.muted { color: var(--mute); }
.small { font-size: .88rem; }
.empty { padding: 36px 16px; text-align: center; color: var(--mute); }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; font-weight: 600; }

/* ---------- شريط الأرقام (لوحة المتابعة) ---------- */
.ledger { display: flex; flex-wrap: wrap; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 20px; }
.ledger a {
  flex: 1 1 130px; padding: 14px 18px; color: var(--ink); border-inline-start: 1px solid var(--line-2);
  display: flex; flex-direction: column; gap: 0; min-width: 120px;
}
.ledger a:first-child { border-inline-start: 0; }
.ledger a:hover { background: #f8faf9; text-decoration: none; }
.ledger .v { font-size: 2.1rem; font-weight: 600; line-height: 1.15; }
.ledger .l { color: var(--mute); font-size: .88rem; }
.ledger .bad .v { color: var(--red); }
.ledger .warn .v { color: var(--amber); }
.ledger .lead { background: var(--ink); color: #fff; }
.ledger .lead .l { color: #b9c5d4; }
.ledger .lead:hover { background: #1c2d47; }

/* ---------- جداول ---------- */
.tw { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th { text-align: start; font-weight: 600; color: var(--ink-2); background: #f7f9f8; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; font-size: .88rem; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8faf9; }
tr.s-overdue td:first-child { box-shadow: inset -4px 0 0 var(--red); }
tr.s-warning td:first-child { box-shadow: inset -4px 0 0 #e0a21b; }
tr.s-closed { color: var(--mute); }
td .sub { display: block; color: var(--mute); font-size: .85rem; }
td.nw, th.nw { white-space: nowrap; }
td.n, th.n { text-align: center; }

/* ---------- شارات ---------- */
.chip { display: inline-block; padding: 1px 10px; border-radius: 99px; font-size: .82rem; font-weight: 500; white-space: nowrap; border: 1px solid transparent; }
.chip.ok { background: var(--green-l); color: var(--green); }
.chip.warn { background: var(--amber-l); color: var(--amber); }
.chip.bad { background: var(--red-l); color: var(--red); }
.chip.mute { background: #eceff0; color: var(--mute); }
.chip.st-new { background: var(--blue-l); color: var(--blue); }
.chip.st-in_progress { background: var(--teal-l); color: var(--teal-d); }
.chip.st-on_hold { background: var(--amber-l); color: var(--amber); }
.chip.st-result_ready, .chip.st-sent { background: var(--green-l); color: var(--green); }
.chip.st-closed, .chip.st-cancelled { background: #eceff0; color: var(--mute); }
.chip.flag { background: #fff; border-color: var(--red); color: var(--red); }
.chip.flag.urgent { background: var(--red); color: #fff; }
.left-bad { color: var(--red); font-weight: 500; }
.left-warn { color: var(--amber); font-weight: 500; }

/* ---------- مراحل المعاملة ---------- */
.stages { list-style: none; margin: 0; padding: 0; }
.stage { display: grid; grid-template-columns: 22px 1fr auto; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); align-items: start; position: relative; }
.stage:last-child { border-bottom: 0; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 3px solid #b9c3c0; margin-top: 6px; background: #fff; }
.stage.done_ok .dot { background: var(--green); border-color: var(--green); }
.stage.done_late .dot { background: var(--amber); border-color: var(--amber); }
.stage.pending .dot { border-color: var(--teal); }
.stage.overdue .dot { background: var(--red); border-color: var(--red); }
.stage.future { color: var(--mute); }
.stage .t { font-weight: 500; }
.stage .r { text-align: end; font-size: .92rem; }
.banner { padding: 12px 16px; border-radius: var(--r); border: 1px solid; margin-bottom: 20px; }
.banner.hold { background: var(--amber-l); border-color: #ebd199; }
.banner.esc { background: var(--red-l); border-color: #efc3c0; }
.banner b { display: block; }
.banner dl { margin: 6px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: .92rem; }
.banner dt { color: var(--ink-2); }
.banner dd { margin: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: .93rem; }
.kv dt { color: var(--mute); }
.kv dd { margin: 0; word-break: break-word; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.log { list-style: none; margin: 0; padding: 0; }
.log li { padding: 10px 16px; border-bottom: 1px solid var(--line-2); font-size: .93rem; }
.log li:last-child { border-bottom: 0; }
.log .who { color: var(--mute); font-size: .85rem; }

/* ---------- فلاتر ---------- */
.filters { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line-2); align-items: end; }
.filters label { font-size: .82rem; color: var(--mute); }
.filters input, .filters select { margin-top: 2px; min-height: 36px; padding: 4px 8px; }

/* ---------- أشرطة ---------- */
.bars .b { display: grid; grid-template-columns: 1fr 40px; gap: 10px; align-items: center; margin-bottom: 10px; font-size: .9rem; }
.bars .track { height: 6px; background: var(--line-2); border-radius: 3px; margin-top: 3px; }
.bars .fill { height: 100%; background: var(--teal); border-radius: 3px; }

/* ---------- نافذة منبثقة ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20, 32, 51, .55); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; overflow-y: auto; z-index: 50; }
.modal { background: #fff; border-radius: 8px; width: 100%; max-width: 560px; border: 1px solid var(--line); }
.modal.wide { max-width: 820px; }
.modal-h { padding: 14px 18px; border-bottom: 1px solid var(--line-2); display: flex; justify-content: space-between; align-items: center; }
.modal-b { padding: 18px; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--line-2); display: flex; gap: 8px; justify-content: flex-start; }
.x { background: none; border: 0; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--mute); padding: 0 6px; }
.toasts { position: fixed; bottom: 18px; inset-inline-start: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--r); font-size: .93rem; max-width: 340px; }
.toast.bad { background: var(--red); }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.25rem; background: #f3f5f4; border: 1px dashed #98a5a2; padding: 10px 14px; border-radius: var(--r); direction: ltr; text-align: center; user-select: all; margin: 10px 0; }

/* ---------- شاشات الدخول ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-side { background: var(--ink); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side h1 { font-size: 2rem; max-width: 14ch; line-height: 1.4; }
.auth-side p { color: #b9c5d4; max-width: 34ch; margin: 12px 0 0; }
.auth-side .hours { font-size: .9rem; color: #b9c5d4; border-top: 1px solid #2c3d57; padding-top: 14px; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 32px 20px; }
.auth-box { width: 100%; max-width: 380px; }
.auth-box h2 { margin-bottom: 18px; }
.policy { max-height: 46vh; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r); padding: 6px 16px; background: #fff; margin-bottom: 16px; font-size: .93rem; }
.policy h3 { margin: 14px 0 4px; color: var(--teal-d); }
.policy ul { margin: 4px 0; padding-inline-start: 20px; }
.policy li { margin-bottom: 3px; }

/* ---------- التقارير ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tabs a { padding: 10px 16px; color: var(--ink-2); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--teal-d); border-bottom-color: var(--teal); font-weight: 500; }
.tabs a:hover { text-decoration: none; background: #eaf0ef; }
.rsec { margin-bottom: 20px; }
.rsec h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.rsec h3 .c { background: var(--ink); color: #fff; border-radius: 99px; font-size: .8rem; padding: 0 9px; }

@media (max-width: 900px) {
  .cols { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth-side { padding: 24px; }
  .auth-side h1 { font-size: 1.4rem; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .topbar-in { flex-wrap: wrap; gap: 0 16px; padding-top: 8px; }
  .topnav { order: 3; flex-basis: 100%; }
  .topnav a { padding: 10px 10px; }
  .me { margin-inline-start: auto; }
  .ledger .v { font-size: 1.7rem; }
}
@media print {
  .topbar, .no-print, .toasts { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .panel { border: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.pw { position: relative; display: block; margin-top: 4px; }
.pw input { width: 100%; padding-inline-start: 12px; padding-inline-end: 64px; }
.pw-t { position: absolute; inset-inline-end: 6px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; color: var(--teal); font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.pw-t:hover { background: rgba(11,110,117,.08); }

.badge { display: inline-block; min-width: 18px; padding: 0 6px; margin-inline-start: 6px; border-radius: 99px; background: #c62828; color: #fff; font-size: .72rem; line-height: 18px; text-align: center; font-weight: 700; }
.badge[hidden] { display: none; }
input[type=file] { width: 100%; padding: 8px; border: 1px dashed var(--line); border-radius: var(--r); background: #fff; font: inherit; }
.notice { border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; margin: 12px 16px; background: #fff; }
.notice.open { border-inline-start: 4px solid #e0a100; }
.notice.done { opacity: .85; }
.notice .nh { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin-bottom: 6px; }
.notice .msg { white-space: pre-wrap; margin: 6px 0; }
.files { list-style: none; margin: 0; padding: 0; }
.files li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.files li:last-child { border-bottom: 0; }
.chip.k-approved { background: #e3f4e6; color: #1b6b2f; }
.chip.k-shortage { background: #fff3d6; color: #8a5a00; }
.chip.k-rejected { background: #fbe4e4; color: #9b1c1c; }
.chip.k-other { background: #e8eef3; color: #34495e; }

.langbtn { border: 1px solid var(--line); background: #fff; color: var(--teal); border-radius: 8px; padding: 4px 10px; font: inherit; font-size: .85rem; cursor: pointer; margin-inline: 8px; }
.langbtn:hover { background: #f3f7f6; }
.langrow { margin-top: 18px; text-align: center; }
.langrow .langbtn { margin: 0; }
