:root {
  --primary: #0b6e99;
  --primary-dark: #08597c;
  --primary-tint: #eaf2f7;
  --red: #a9534e;
  --red-tint: #f7eceb;
  --green: #3e7d5f;
  --green-tint: #e9f2ed;
  --brown: #8a6a35;
  --text: #1f2a33;
  --muted: #6b7a86;
  --line: #dfe5ea;
  --bg: #f5f7f9;
  --card: #ffffff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Cairo", Tahoma, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- الشريط اللي فوق ---------------- */
.topbar {
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 8px 24px;
  min-height: 56px;
  flex-wrap: wrap;
}
.topbar .brand { font-weight: 700; font-size: 19px; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a {
  color: #fff;
  padding: 7px 12px;
  border-radius: 8px;
  opacity: .88;
}
.topbar nav a:hover, .topbar nav a.on { background: rgba(255,255,255,.16); opacity: 1; text-decoration: none; }
.topbar .who { font-size: 13px; opacity: .9; display: flex; align-items: center; gap: 10px; }
.topbar .who button {
  background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.5);
  border-radius: 8px; padding: 4px 10px; cursor: pointer; font: inherit;
}

main { max-width: 1150px; margin: 24px auto; padding: 0 20px; }

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 18px;
}

.flash {
  padding: 11px 14px; border-radius: 10px; margin-bottom: 16px;
  background: var(--green-tint); color: var(--green); font-weight: 600;
}
.flash.error { background: var(--red-tint); color: var(--red); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.stat .n { font-size: 28px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }
.stat.bad .n { color: var(--red); }

/* ---------------- الجداول ---------------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 13px; background: #fafbfc; }
tr:hover td { background: #fafcfd; }
td.num, th.num { text-align: left; white-space: nowrap; }
.code { font-family: Consolas, monospace; direction: ltr; unicode-bidi: embed; color: var(--muted); }
.owe { color: var(--red); }
.credit { color: var(--green); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.on { background: var(--green-tint); color: var(--green); }
.badge.off { background: #eceff2; color: var(--muted); }
.badge.err { background: var(--red-tint); color: var(--red); }

/* ---------------- الفورمز ---------------- */
form.inline { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
input[type=text], input[type=password], input[type=search], select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid #c9d3db; border-radius: 8px;
  background: #fff; min-width: 200px;
}
input:focus, select:focus { outline: 2px solid var(--primary-tint); border-color: var(--primary); }
input.money { direction: ltr; text-align: left; min-width: 130px; width: 130px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer; border: 0; border-radius: 8px;
  padding: 9px 16px; background: var(--primary); color: #fff; display: inline-block;
}
button:hover, .btn:hover { background: var(--primary-dark); text-decoration: none; }
button.light, .btn.light { background: var(--primary-tint); color: var(--primary); }
button.danger { background: var(--red); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs a { padding: 7px 14px; border-radius: 20px; background: #fff; border: 1px solid var(--line); color: var(--text); }
.tabs a.on { background: var(--primary); border-color: var(--primary); color: #fff; }

.row { display: flex; gap: 18px; flex-wrap: wrap; }
.row > .card { flex: 1; min-width: 300px; }
.muted { color: var(--muted); font-size: 13px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.big { font-size: 24px; font-weight: 700; }
.head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.head h1 { margin: 0; }

/* ---------------- صفحة الدخول ---------------- */
.login-box { max-width: 380px; margin: 90px auto; }
.login-box h1 { text-align: center; color: var(--primary); }
.login-box input { width: 100%; }
.login-box button { width: 100%; margin-top: 6px; padding: 11px; }

/* ---------------- التقارير ---------------- */
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.quick a { padding: 4px 12px; border-radius: 20px; border: 1px solid var(--line); color: var(--text); font-size: 13px; }
.quick a.on { background: var(--primary-tint); border-color: var(--primary); color: var(--primary); }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.report-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-bottom: 14px; }
.report-card { color: var(--text); }
.report-card:hover { border-color: var(--primary); text-decoration: none; }
.report-card h2 { color: var(--primary); }
.card.wide { overflow-x: auto; }
table.report td, table.report th { padding: 7px 8px; font-size: 14px; }
tr.total td { font-weight: 700; background: #eef2f5; }
.strong { font-weight: 700; }
.stat.supply { background: #3a3f44; border-color: #3a3f44; }
.stat.supply .n, .stat.supply .l { color: #fff; }
.kv-wide { grid-template-columns: 170px 1fr; }
tr.kind-مرتجع td { background: var(--red-tint); }
tr.kind-تحصيل td { background: var(--green-tint); }
tr.kind-تحميل td, tr.kind-جرد td { background: #f6f1e8; }
.print-only { display: none; }

@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; font-size: 11px; }
  .topbar, .no-print, .flash { display: none !important; }
  .print-only { display: block; }
  .print-head { font-size: 15px; margin-bottom: 8px; }
  main { margin: 0; max-width: none; padding: 0; }
  .card { border: 0; padding: 0; margin-bottom: 10px; }
  .stats { gap: 6px; }
  .stat { padding: 6px 8px; }
  .stat .n { font-size: 16px; }
  table.report td, table.report th { padding: 3px 5px; font-size: 10px; }
  tr { break-inside: avoid; }
  a { color: inherit; }
}

/* ---------------- مسار الرجوع ---------------- */
.crumbs { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; font-size: 14px; }
.crumbs a { color: var(--primary); font-weight: 600; }
.crumbs span { color: var(--muted); }
.crumbs .sep { color: #b5c0c9; }

/* ---------------- تفصيلي النقلة ---------------- */
.section-title { margin: 22px 0 10px; color: var(--brown); }
.load-card { border-top: 4px solid var(--brown); }
.load-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; font-size: 16px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.split h3 { font-size: 15px; margin: 0 0 8px; color: var(--muted); }
tr.credit-row td { background: var(--red-tint); }
@media (max-width: 800px) { .split { grid-template-columns: 1fr; } }
@media print { .split { gap: 10px; } .load-card { border-top: 2px solid #999; } }

tr.item-row td { color: var(--muted); font-size: 13px; padding-top: 2px; padding-bottom: 2px; border-bottom: 0; }
tr.item-row td:nth-child(2) { padding-right: 28px; }

/* ---------------- العروض ---------------- */
.inline-fields { display: flex; gap: 14px; flex-wrap: wrap; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 4px 12px; }
.big-note { font-size: 17px; font-weight: 600; color: var(--primary); margin: -6px 0 16px; }
form h2 { margin-top: 18px; color: var(--primary); }

/* ---------------- الخزن ---------------- */
/* الإيرادات يمين والمصروفات شمال (الصفحة RTL: الأول = اليمين). */
.cash-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.cash-cols .card { margin-bottom: 0; }
.cash-in { border-top: 4px solid var(--green); }
.cash-in h2 { color: var(--green); }
.cash-out { border-top: 4px solid var(--red); }
.cash-out h2 { color: var(--red); }
.cash-sum { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 18px 0; }
.cash-sum .stat { flex: 1; min-width: 150px; }
.cash-sum .op { font-size: 26px; font-weight: 700; color: var(--muted); }
tr.reversed td { color: var(--muted); text-decoration: line-through; }
tr.reversed td .muted { text-decoration: none; }
@media (max-width: 800px) { .cash-cols { grid-template-columns: 1fr; } }
@media print {
  .cash-cols { gap: 8px; }
  .cash-sum .stat { padding: 4px 8px; }
  .cash-sum .op { font-size: 16px; }
}

/* ---------------- القوايم المنسدلة ---------------- */
.topbar nav { align-items: center; }
.menu { position: relative; color: #fff; padding: 7px 12px; border-radius: 8px; opacity: .88; cursor: pointer; outline: none; }
.menu:hover, .menu:focus-within, .menu.on { background: rgba(255,255,255,.16); opacity: 1; }
.menu-list {
  display: none; position: absolute; top: 100%; right: 0; z-index: 50; min-width: 210px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.14); margin-top: 4px;
}
.menu-list::before { content: ""; position: absolute; top: -8px; left: 0; right: 0; height: 8px; }
.menu:hover .menu-list, .menu:focus-within .menu-list { display: block; }
.topbar nav .menu-list a { display: block; color: var(--text); opacity: 1; padding: 8px 12px; border-radius: 6px; white-space: nowrap; }
.topbar nav .menu-list a:hover { background: var(--primary-tint); color: var(--primary); text-decoration: none; }
.topbar nav .menu-list a.on { background: var(--primary-tint); color: var(--primary); font-weight: 700; }

/* الرصيد المرحّل (فوق اليومية) والتحويلات */
.carried { display: flex; justify-content: space-between; align-items: center; gap: 16px;
  background: #eef2f5; border: 1px solid var(--line); border-right: 5px solid var(--primary);
  border-radius: 12px; padding: 14px 18px; margin-bottom: 18px; }
.carried .l { font-weight: 700; font-size: 16px; }
.carried .n { font-size: 26px; font-weight: 700; color: var(--primary); white-space: nowrap; }
.transfers-card { margin-top: 18px; border-top: 4px solid var(--brown); }
.transfers-card h2 { color: var(--brown); }
.incoming { border-top: 4px solid var(--primary); background: var(--primary-tint); }

/* رسالة التأكيد جوه الصفحة */
dialog.ask { border: 0; border-radius: 14px; padding: 22px; min-width: 320px; max-width: 460px;
  box-shadow: 0 16px 48px rgba(0,0,0,.25); font: inherit; }
dialog.ask::backdrop { background: rgba(20, 30, 40, .45); }
dialog.ask p { font-size: 16px; font-weight: 600; margin: 0 0 14px; }
.ask-buttons { display: flex; gap: 8px; margin-top: 16px; }

tr.debt-customer td { background: #f3f6f8; border-top: 2px solid var(--line); }

/* خريطة المناديب */
.map-box { height: 68vh; min-height: 420px; border-radius: 12px; border: 1px solid var(--line); margin-bottom: 10px; }
.map-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; font-size: 14px; }
.map-legend .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: middle; }
.map-legend .line { display: inline-block; width: 22px; height: 4px; border-radius: 2px; vertical-align: middle; }
.truck-icon div { width: 36px; height: 36px; border-radius: 50%; background: #fff; border: 3px solid;
  display: flex; align-items: center; justify-content: center; font-size: 18px; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.map-pop { direction: rtl; text-align: right; font-family: "Cairo", Tahoma, sans-serif; min-width: 200px; }
.map-pop ul { margin: 4px 0; padding-right: 18px; }
.leaflet-container { font-family: "Cairo", Tahoma, sans-serif; }

/* الشريط والقوايم المنسدلة فوق الخريطة (Leaflet بيستخدم z-index لحد 1000) */
.topbar { position: relative; z-index: 3000; }
.menu-list { z-index: 3001; }

/* ---------------- التارجت ---------------- */
.tbar { position: relative; height: 20px; background: #eceff2; border-radius: 10px; overflow: hidden; min-width: 120px; }
.tbar span { position: absolute; inset-block: 0; right: 0; border-radius: 10px; }
.tbar.ok span { background: #9fd3b5; }
.tbar.late span { background: #efb3ae; }
.tbar b { position: relative; display: block; text-align: center; font-size: 12px; line-height: 20px; }

/* ---------------- الشركات ---------------- */
.company-pick select { background: #fff; color: #2c2c2a; border-radius: 6px; padding: 4px 8px; font-size: 13px; border: 0; }

/* الشريط فوق ومسار الرجوع ثابتين مع النزول (طلب محمود 17 نوفمبر) */
.sticky-top { position: sticky; top: 0; z-index: 60; }
.sticky-top .crumbs { background: var(--bg, #f4f6f8); margin: 0; padding: 8px max(20px, calc((100% - 1150px) / 2 + 20px)); border-bottom: 1px solid var(--line, #dde3e8); }
@media print { .sticky-top { position: static; } }

.menu-list .menu-head { color: var(--muted, #6b7280); font-size: 12px; font-weight: 700; padding: 8px 12px 2px; border-top: 1px solid #eee; }
.menu-list .menu-head:first-child { border-top: 0; }

/* زرار صغير شكله لينك (شيل رقم زيادة) */
button.link { background: none; border: 0; color: #A9534E; padding: 0 4px; min-height: 0; cursor: pointer; font-size: 12px; box-shadow: none; }
button.link:hover { text-decoration: underline; }

/* جدول الصلاحيات (خطوة 4.5) */
.perm-table td, .perm-table th { padding: 6px 8px; }
.perm-table td.num, .perm-table th.num { text-align: center; width: 90px; }
.perm-table tr:hover td { background: rgba(11, 110, 153, 0.05); }
.perm-table input[type=radio] { width: 18px; height: 18px; cursor: pointer; }

/* الشغل بدل المندوب (خطوة 5.5) */
.proxy-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.proxy-box button { width: 100%; text-align: right; background: #fff; color: var(--text); border: 1px solid var(--line, #dde3e8); border-radius: 10px; padding: 12px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.proxy-box button:hover { border-color: #0b6e99; }
.proxy-box button[disabled] { opacity: .6; cursor: not-allowed; }
.proxy-box .tag { font-size: 12px; padding: 2px 8px; border-radius: 6px; align-self: flex-start; background: #eef1f3; color: #555; }
.tone-ok .tag { background: #e3f1ea; color: #2c6a4c; }
.tone-warn .tag { background: #faeeda; color: #633806; }
.tone-bad .tag { background: #f6e2e1; color: #8a3a35; }
.tone-acc .tag { background: #e3eef6; color: #0b5a7d; }
.proxy-banner { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: #e3eef6; color: #0b4a66; border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; flex-wrap: wrap; }

/* خطوة 7: النسخة التجريبية */
.trial-bar { background: #c07a2c; color: #fff; text-align: center; font-weight: 600; padding: 6px 10px; font-size: 14px; }

/* خطوة 7.7: جرس التنبيهات */
.bell { position: relative; color: #fff; text-decoration: none; font-size: 18px; margin: 0 8px; }
.bell-n { position: absolute; top: -6px; left: -10px; background: #c0392b; color: #fff; border-radius: 999px;
  font-size: 11px; padding: 1px 6px; font-weight: 700; }
.alert-row { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid #eee; }
.alert-row.seen { opacity: .55; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 10px 0; }
.kpi { background: #fff; border: 1px solid #e3e3e3; border-radius: 10px; padding: 10px 12px; }
.kpi .n { font-size: 22px; font-weight: 700; }
.kpi .d { font-size: 12px; color: #666; }
.kpi .up { color: #2e7d4f; } .kpi .down { color: #a9534e; }

/* صفحة الدخول: اللوجو (docs/logo/README.md) */
.login-logo { text-align: center; margin-bottom: 14px; }
.login-logo img { border-radius: 24px; display: block; margin: 0 auto 8px; }
.login-logo .login-name { font-size: 24px; font-weight: 700; color: #1f3b4d; }
