:root{
  --navy:#0f2540; --navy-2:#1c3b63; --gold:#c8a24a; --gold-soft:#f5efe0;
  --burgundy:#833358; --orange:#e19a4a;
  --bg:#f3f5f8; --card:#fff; --line:#e3e7ee; --text:#1c2430; --muted:#6b7688;
  --ok:#1f8a4c; --ok-bg:#e7f6ec; --warn:#b97a12; --warn-bg:#fdf3e0;
  --danger:#c0392b; --danger-bg:#fdeceb; --info:#1f5fa8; --info-bg:#eaf2fb;
}
*{box-sizing:border-box;}
html,body{margin:0;height:100%;}
body{
  background:var(--bg); color:var(--text); font-size:15px; line-height:1.6;
  font-family:-apple-system,"SF Arabic","Segoe UI",Tahoma,"Noto Sans Arabic",sans-serif;
}
a{color:var(--info);}
button,input,select,textarea{font-family:inherit; font-size:14px;}
.hidden{display:none !important;}
.muted{color:var(--muted); font-size:13px;}
.ltr{direction:ltr; unicode-bidi:embed; text-align:left; display:inline-block;}
.mono{font-family:ui-monospace,Menlo,Consolas,monospace; direction:ltr; unicode-bidi:embed;}

/* ===== الهيكل العام ===== */
.app{display:flex; min-height:100vh;}
.sidebar{
  width:236px; background:var(--navy); color:#dbe3f0; flex-shrink:0;
  display:flex; flex-direction:column; position:sticky; top:0; height:100vh; overflow-y:auto;
}
.brand{padding:18px 16px 14px; text-align:center; border-bottom:1px solid rgba(255,255,255,.08);}
.brand .logo-box{background:#fff; border-radius:12px; padding:8px 12px; display:inline-block;}
.brand img{height:38px; display:block;}
.brand .name{margin-top:10px; font-weight:800; color:#fff; font-size:14px;}
.brand .sub{font-size:11.5px; color:#9fb0c9;}
.nav{padding:10px 10px; flex:1;}
.nav button{
  display:flex; align-items:center; gap:10px; width:100%; text-align:right; background:none; border:none;
  color:#cdd7e6; padding:11px 12px; border-radius:9px; cursor:pointer; font-weight:600; margin-bottom:3px;
}
.nav button:hover{background:rgba(255,255,255,.07);}
.nav button.active{background:var(--gold); color:var(--navy);}
.nav .ico{width:22px; text-align:center; font-size:17px;}
.nav .count{margin-inline-start:auto; background:var(--danger); color:#fff; border-radius:20px; font-size:11px; padding:1px 8px; font-weight:800;}
.side-foot{padding:12px 14px; border-top:1px solid rgba(255,255,255,.08); font-size:12.5px;}
.side-foot .who{color:#fff; font-weight:700;}
.side-foot button{margin-top:8px; width:100%; background:rgba(255,255,255,.1); color:#fff; border:none; border-radius:8px; padding:8px; cursor:pointer;}
.main{flex:1; min-width:0; display:flex; flex-direction:column;}
.topbar{
  background:#fff; border-bottom:1px solid var(--line); padding:12px 22px; display:flex; align-items:center; gap:12px;
  position:sticky; top:0; z-index:20;
}
.topbar h1{margin:0; font-size:18px; color:var(--navy); flex:1;}
.menu-btn{display:none; background:var(--navy); color:#fff; border:none; border-radius:8px; padding:7px 12px; cursor:pointer; font-size:16px;}
.content{padding:22px; max-width:1200px; width:100%; margin:0 auto;}

/* ===== عناصر عامة ===== */
.card{background:var(--card); border:1px solid var(--line); border-radius:14px; padding:18px; margin-bottom:16px; box-shadow:0 1px 3px rgba(20,30,50,.04);}
.card h2{margin:0 0 12px; font-size:16px; color:var(--navy);}
.card h2 small{font-weight:500; color:var(--muted); font-size:12.5px;}
.card-head{display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:12px; flex-wrap:wrap;}
.card-head h2{margin:0;}
.grid{display:grid; gap:12px;}
.g2{grid-template-columns:repeat(2,1fr);}
.g3{grid-template-columns:repeat(3,1fr);}
.g4{grid-template-columns:repeat(4,1fr);}
.gauto{grid-template-columns:repeat(auto-fit,minmax(220px,1fr));}
label{display:block; font-size:12.5px; font-weight:700; color:var(--muted); margin-bottom:5px;}
input,select,textarea{
  width:100%; padding:9px 11px; border:1px solid var(--line); border-radius:9px; background:#fbfcfe; color:var(--text);
}
input:focus,select:focus,textarea:focus{outline:none; border-color:var(--gold); background:#fff; box-shadow:0 0 0 3px rgba(200,162,74,.18);}
textarea{resize:vertical; min-height:70px;}
.field{margin-bottom:0;}
.btn{
  background:var(--navy); color:#fff; border:none; border-radius:9px; padding:9px 16px; font-weight:700; cursor:pointer;
  display:inline-flex; align-items:center; gap:6px; white-space:nowrap;
}
.btn:hover{background:var(--navy-2);}
.btn:disabled{opacity:.5; cursor:not-allowed;}
.btn.gold{background:var(--gold); color:var(--navy);}
.btn.gold:hover{filter:brightness(1.06);}
.btn.ghost{background:#eef1f6; color:var(--navy);}
.btn.ghost:hover{background:#e2e8f1;}
.btn.danger{background:var(--danger-bg); color:var(--danger);}
.btn.danger:hover{background:#f8d7d4;}
.btn.ok{background:var(--ok-bg); color:var(--ok);}
.btn.sm{padding:5px 10px; font-size:12.5px; border-radius:7px;}
.row{display:flex; gap:8px; align-items:center; flex-wrap:wrap;}
.spacer{flex:1;}
.badge{display:inline-block; padding:2px 10px; border-radius:20px; font-size:12px; font-weight:700; white-space:nowrap;}
.badge.green{background:var(--ok-bg); color:var(--ok);}
.badge.gold{background:var(--warn-bg); color:var(--warn);}
.badge.orange{background:#fdeadb; color:#b45d0e;}
.badge.red{background:var(--danger-bg); color:var(--danger);}
.badge.blue{background:var(--info-bg); color:var(--info);}
.badge.gray{background:#eceff4; color:#5b6678;}
.table-wrap{overflow-x:auto; margin:0 -4px; padding:0 4px;}
table{width:100%; border-collapse:collapse; font-size:13.5px;}
th,td{text-align:right; padding:10px 8px; border-bottom:1px solid var(--line); vertical-align:middle;}
th{color:var(--muted); font-size:12px; font-weight:800; background:#fafbfd; white-space:nowrap;}
tr:hover td{background:#fafbfe;}
td.actions{white-space:nowrap;}
.empty{padding:34px 10px; text-align:center; color:var(--muted);}
.empty .big{font-size:34px; display:block; margin-bottom:6px;}
.pager{display:flex; align-items:center; justify-content:space-between; margin-top:12px; flex-wrap:wrap; gap:8px;}
.hint{background:var(--info-bg); color:#184a80; border-radius:10px; padding:10px 14px; font-size:13.5px;}
.hint.warn{background:var(--warn-bg); color:#7a4f0a;}
.hint.danger{background:var(--danger-bg); color:#8c2a20;}
.hint.ok{background:var(--ok-bg); color:#166a3a;}

/* ===== بطاقات الإحصائيات ===== */
.stats{display:grid; grid-template-columns:repeat(auto-fit,minmax(170px,1fr)); gap:12px; margin-bottom:16px;}
.stat{background:#fff; border:1px solid var(--line); border-radius:14px; padding:14px 16px; position:relative; overflow:hidden;}
.stat .num{font-size:28px; font-weight:800; color:var(--navy); line-height:1.1;}
.stat .lbl{font-size:12.5px; color:var(--muted); margin-top:4px;}
.stat::after{content:""; position:absolute; inset-inline-start:0; top:0; bottom:0; width:4px; background:var(--gold);}
.stat.green::after{background:var(--ok);} .stat.red::after{background:var(--danger);} .stat.blue::after{background:var(--info);} .stat.orange::after{background:var(--orange);}
.stat.clickable{cursor:pointer;} .stat.clickable:hover{border-color:var(--gold);}
.bars{display:flex; align-items:flex-end; gap:10px; height:150px; padding-top:10px;}
.bar-col{flex:1; display:flex; flex-direction:column; align-items:center; justify-content:flex-end; height:100%;}
.bar{width:100%; max-width:46px; background:linear-gradient(180deg,var(--gold),#b18c36); border-radius:7px 7px 0 0; min-height:3px;}
.bar-col .v{font-size:12px; font-weight:800; color:var(--navy); margin-bottom:3px;}
.bar-col .d{font-size:11px; color:var(--muted); margin-top:5px;}
.hbar{height:9px; background:#eceff4; border-radius:9px; overflow:hidden;}
.hbar i{display:block; height:100%; background:var(--gold);}
.steps{list-style:none; padding:0; margin:0;}
.steps li{display:flex; align-items:center; gap:10px; padding:9px 0; border-bottom:1px dashed var(--line);}
.steps li:last-child{border-bottom:none;}
.steps .tick{width:24px; height:24px; border-radius:50%; background:#eceff4; color:#8a93a3; display:flex; align-items:center; justify-content:center; font-weight:800; font-size:13px; flex-shrink:0;}
.steps li.done .tick{background:var(--ok); color:#fff;}
.steps li.done .t{color:var(--muted); text-decoration:line-through;}

/* ===== الفلاتر ===== */
.filters{display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:10px; align-items:end; margin-bottom:14px;}

/* ===== نافذة منبثقة ===== */
.overlay{position:fixed; inset:0; background:rgba(12,22,40,.55); z-index:100; display:flex; align-items:flex-start; justify-content:center; padding:24px 12px; overflow-y:auto;}
.modal{background:#fff; border-radius:16px; width:100%; max-width:640px; padding:20px; margin:auto 0; box-shadow:0 20px 60px rgba(0,0,0,.3);}
.modal.wide{max-width:900px;}
.modal-head{display:flex; align-items:center; gap:10px; margin-bottom:14px;}
.modal-head h3{margin:0; font-size:17px; color:var(--navy); flex:1;}
.x{background:#eef1f6; border:none; border-radius:8px; width:32px; height:32px; cursor:pointer; font-size:16px;}
.kv{display:grid; grid-template-columns:110px 1fr; gap:4px 10px; font-size:13.5px;}
.kv dt{color:var(--muted);} .kv dd{margin:0; font-weight:600; word-break:break-word;}
.box{border:1px solid var(--line); border-radius:12px; padding:12px 14px; background:#fbfcfe;}
.box h4{margin:0 0 8px; font-size:13.5px; color:var(--navy);}
.timeline{list-style:none; margin:0; padding:0 18px 0 0; border-inline-end:2px solid var(--line);}
.timeline li{position:relative; padding:0 0 14px 0; margin-inline-end:0;}
.timeline li::before{content:""; position:absolute; inset-inline-end:-25px; top:5px; width:12px; height:12px; border-radius:50%; background:var(--gold); border:2px solid #fff; box-shadow:0 0 0 2px var(--gold);}
.timeline .t{font-weight:700;} .timeline .m{font-size:12px; color:var(--muted);}
.keybox{background:var(--navy); color:#fff; border-radius:12px; padding:14px; display:flex; align-items:center; gap:10px; flex-wrap:wrap;}
.keybox code{flex:1; min-width:200px; font-size:15px; word-break:break-all; color:var(--gold); direction:ltr; text-align:left;}
pre.code{background:#0f1b2e; color:#d6e2f5; border-radius:11px; padding:14px; overflow-x:auto; direction:ltr; text-align:left; font-size:12.5px; line-height:1.55; margin:8px 0; white-space:pre;}
.tabs{display:flex; gap:6px; margin-bottom:8px; flex-wrap:wrap;}
.tabs button{background:#eef1f6; border:none; border-radius:20px; padding:6px 14px; cursor:pointer; font-weight:700; color:var(--navy);}
.tabs button.active{background:var(--navy); color:#fff;}
details{margin-top:10px;} summary{cursor:pointer; color:var(--muted); font-size:13px;}

/* ===== شركات الشحن ===== */
.carrier-card{border:1px solid var(--line); border-radius:14px; padding:16px; background:#fff; margin-bottom:14px;}
.carrier-head{display:flex; align-items:center; gap:10px; flex-wrap:wrap; margin-bottom:10px;}
.carrier-head h3{margin:0; font-size:16px; color:var(--navy);}
.switch{display:inline-flex; align-items:center; gap:8px; cursor:pointer; font-size:13px; font-weight:700; color:var(--muted);}
.switch input{width:auto;}

/* ===== شاشة الدخول ===== */
.login-wrap{min-height:100vh; display:flex; align-items:center; justify-content:center; padding:20px; background:linear-gradient(160deg,var(--navy) 0%,var(--navy-2) 100%);}
.login-card{background:#fff; border-radius:20px; padding:30px 26px; width:100%; max-width:400px; box-shadow:0 30px 80px rgba(0,0,0,.35);}
.login-card .logo{text-align:center; margin-bottom:16px;} .login-card .logo img{height:54px;}
.login-card h1{font-size:19px; text-align:center; margin:0 0 4px; color:var(--navy);}
.login-card p.sub{text-align:center; margin:0 0 18px; color:var(--muted); font-size:13.5px;}
.login-card .field{margin-bottom:12px;}
.login-card .btn{width:100%; justify-content:center; padding:11px;}

/* ===== إشعار عائم ===== */
#toast{position:fixed; bottom:22px; left:50%; transform:translateX(-50%) translateY(20px); background:var(--navy); color:#fff; padding:11px 22px; border-radius:11px; z-index:300; opacity:0; transition:.25s; max-width:90%; text-align:center; pointer-events:none;}
#toast.show{opacity:1; transform:translateX(-50%) translateY(0);}
#toast.err{background:var(--danger);} #toast.ok{background:var(--ok);}

/* ===== الطباعة ===== */
#print-area{display:none;}
.waybill{width:130mm; margin:0 auto; border:2px solid #000; padding:6mm; font-size:11pt; color:#000;}
.waybill .wh{display:flex; justify-content:space-between; align-items:center; border-bottom:2px solid #000; padding-bottom:3mm; margin-bottom:3mm;}
.waybill .wh img{height:12mm;}
.waybill .ref{font-size:20pt; font-weight:800; letter-spacing:1px; direction:ltr; text-align:center;}
.waybill .two{display:grid; grid-template-columns:1fr 1fr; gap:3mm; margin:3mm 0;}
.waybill .blk{border:1px solid #000; padding:2.5mm; min-height:24mm;}
.waybill .blk b{display:block; border-bottom:1px solid #999; margin-bottom:1.5mm; font-size:10pt;}
.waybill .cod{border:3px solid #000; text-align:center; padding:3mm; font-size:15pt; font-weight:800; margin:3mm 0;}
.waybill .qr svg{width:28mm; height:28mm;}
.guide h1{font-size:20px;} .guide h2{font-size:16px; margin-top:22px;}
.guide pre.code{white-space:pre-wrap;}
@media print{
  body *{visibility:hidden;}
  #print-area,#print-area *{visibility:visible;}
  #print-area{display:block; position:absolute; inset:0; padding:10mm; background:#fff;}
  pre.code{background:#f4f4f4 !important; color:#000 !important; border:1px solid #ccc;}
}

/* ===== الجوال ===== */
@media (max-width:900px){
  .sidebar{position:fixed; inset-block:0; inset-inline-start:0; transform:translateX(100%); transition:.25s; z-index:90; width:260px;}
  body.nav-open .sidebar{transform:translateX(0);}
  body.nav-open::after{content:""; position:fixed; inset:0; background:rgba(0,0,0,.45); z-index:80;}
  .menu-btn{display:inline-block;}
  .content{padding:14px;}
  .g2,.g3,.g4{grid-template-columns:1fr;}
  .kv{grid-template-columns:90px 1fr;}
}
