:root{--navy:#17345c;--blue:#2457c5;--bg:#f3f6fb;--line:#e0e6ef;--muted:#667085;--green:#147d5a;--red:#b42318;--amber:#9a6700}*{box-sizing:border-box}body{margin:0;font-family:Tahoma,Arial,sans-serif;background:var(--bg);color:#182230}header{background:var(--navy);color:#fff;padding:18px 22px;display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}.brand{font-size:21px;font-weight:bold}.sub{font-size:12px;color:#d5e0ef;margin-top:5px}.wrap{max-width:1400px;margin:20px auto;padding:0 14px}.layout{display:grid;grid-template-columns:220px minmax(0,1fr);gap:16px}nav,.panel,.stat{background:white;border:1px solid var(--line);border-radius:13px}nav{padding:9px;height:max-content;position:sticky;top:12px}nav button{display:block;width:100%;text-align:right;border:0;background:transparent;padding:11px;border-radius:8px;color:#27354b;cursor:pointer;font:inherit}nav button.active,nav button:hover{background:#edf3ff;color:var(--blue);font-weight:bold}main{min-width:0}.topline{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap;margin-bottom:14px}h1{font-size:23px;margin:0 0 5px}h2{font-size:17px;margin:0 0 14px}p,.muted{color:var(--muted);font-size:13px;margin:0;line-height:1.7}.stats{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:10px;margin-bottom:14px}.stat{padding:15px}.stat small{color:var(--muted)}.num{font-size:24px;font-weight:bold;margin-top:8px}.panel{padding:15px;margin-bottom:14px}.primary,button.primary{background:var(--blue);color:white;border:0;border-radius:8px;padding:10px 13px;cursor:pointer;font:inherit;font-weight:bold}.secondary{background:white;border:1px solid var(--line);border-radius:8px;padding:9px 12px;cursor:pointer;font:inherit}.danger{color:var(--red)}.tablewrap{overflow:auto}table{width:100%;border-collapse:collapse;min-width:660px}th,td{text-align:right;padding:11px 9px;border-bottom:1px solid var(--line);font-size:13px;vertical-align:top}th{color:var(--muted);background:#fafbfc;font-weight:600}.pill{display:inline-block;padding:4px 8px;border-radius:20px;background:#eef2f7;color:#344054;font-size:12px;white-space:nowrap}.pending{background:#fff4d6;color:var(--amber)}.approved{background:#dcfce7;color:var(--green)}.rejected{background:#fee4e2;color:var(--red)}.invoiced{background:#e0eaff;color:#244db5}.actions{display:flex;gap:5px;flex-wrap:wrap}.mini{border:1px solid var(--line);background:white;border-radius:7px;padding:6px 8px;cursor:pointer;font:inherit;font-size:12px}.field{display:grid;gap:6px;margin-bottom:11px}.field label{font-size:13px;font-weight:bold}.field input,.field select,.field textarea{width:100%;padding:10px;border:1px solid #cfd7e3;border-radius:8px;font:inherit;background:white}.formgrid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}.full{grid-column:1/-1}.hidden{display:none!important}.notice{background:#fffaeb;border:1px solid #fedf89;padding:11px;border-radius:9px;color:#7a4e00;font-size:12px;line-height:1.8;margin-bottom:14px}.toolbar{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:12px}.empty{text-align:center;color:var(--muted);padding:25px}.totalbox{padding:12px;background:#f1f6ff;border-radius:9px;font-weight:bold}.invoice-classic{border:2px solid #24558a!important;border-radius:0!important;padding:24px!important;color:#172b4d}.invoice-classic h1,.invoice-classic h2{color:var(--invoice-color,#24558a)}.invoice-classic table th{background:#eaf1fa;color:#17345c}.footer{font-size:11px;color:var(--muted);padding:8px 0 24px}.lineitems{display:grid;grid-template-columns:2fr 1fr 1fr 1fr;gap:8px}.lineitems .field{margin:0}@media(max-width:800px){.layout{grid-template-columns:1fr}nav{position:static;display:flex;overflow:auto;gap:4px}nav button{white-space:nowrap;width:auto}.stats{grid-template-columns:repeat(2,minmax(0,1fr))}.formgrid{grid-template-columns:1fr}.full{grid-column:auto}.lineitems{grid-template-columns:1fr 1fr}h1{font-size:20px}}@media print{body.printing-invoice *{visibility:hidden!important}body.printing-invoice #invoicePrint,body.printing-invoice #invoicePrint *{visibility:visible!important}body.printing-invoice #invoicePrint{display:block!important;position:absolute!important;inset:0!important;width:100%!important;margin:0!important;padding:12mm!important;border:2px solid var(--invoice-color,#24558a)!important;box-shadow:none!important;background:#fff!important}body.printing-invoice #invoicePrint .no-print{display:none!important}body.printing-invoice #invoicePrint .tablewrap{overflow:visible!important}body.printing-invoice #invoicePrint table{width:100%!important;border-collapse:collapse!important}body.printing-invoice #invoicePrint th,body.printing-invoice #invoicePrint td{border:1px solid #ccd5e2!important;padding:7px!important}body.printing-invoice #invoicePrint th{background:#eaf1fa!important;color:#17345c!important;-webkit-print-color-adjust:exact;print-color-adjust:exact}body:not(.printing-invoice) header,body:not(.printing-invoice) nav,body:not(.printing-invoice) .topline button,body:not(.printing-invoice) .toolbar,body:not(.printing-invoice) .actions,body:not(.printing-invoice) .notice,body:not(.printing-invoice) .footer{display:none!important}body:not(.printing-invoice) .layout{display:block}body:not(.printing-invoice) .wrap{max-width:none;margin:0;padding:0}body:not(.printing-invoice) .hidden{display:none!important}}
.invoice-classic{background:#fff!important;border:1.5px solid #17345c!important;border-radius:0!important;padding:10mm!important;color:#172b4d!important;}
.invoice-inner{min-height:260mm;display:flex;flex-direction:column;font-family:Tahoma,Arial,sans-serif;}
.invoice-head{display:flex;align-items:center;justify-content:space-between;gap:12mm;border-bottom:2px solid #17345c;padding-bottom:5mm;}
.invoice-logo{width:43%;max-width:68mm;height:29mm;object-fit:contain;}
.invoice-company{text-align:center;flex:1;}
.invoice-company h1{font-size:19pt;margin:0 0 3mm;color:#17345c;}
.invoice-company p{font-size:9pt;margin:1mm 0;color:#344054;}
.invoice-meta{display:flex;justify-content:space-between;align-items:flex-start;gap:8mm;padding:5mm 0;min-height:29mm;}
.invoice-meta h2{font-size:14pt;margin:0 0 3mm;color:#17345c;}
.invoice-meta p{font-size:9pt;margin:1mm 0;color:#344054;}
.invoice-customer{border:1px solid #8798ad;padding:3mm 5mm;min-width:48mm;}
.invoice-table-wrap{flex:1;min-height:120mm;overflow:visible!important;display:flex;}
.invoice-table{width:100%!important;min-width:0!important;height:100%;border-collapse:collapse;table-layout:fixed;}
.invoice-table th,.invoice-table td{border:1px solid #8291a5!important;padding:2.5mm 2mm!important;font-size:9pt;text-align:center;}
.invoice-table th{background:#eaf1fa!important;color:#17345c!important;font-weight:bold;}
.invoice-table th:nth-child(1){width:16%}.invoice-table th:nth-child(2){width:42%}.invoice-table th:nth-child(3){width:12%}.invoice-table th:nth-child(4){width:14%}.invoice-table th:nth-child(5){width:16%}
.invoice-fill-row{height:100%;}
.invoice-fill-row td{border-top:0!important;border-bottom:0!important;}
.invoice-bottom{display:flex;justify-content:space-between;align-items:flex-end;gap:8mm;padding-top:5mm;}
.invoice-details{font-size:9pt;line-height:1.8;flex:1;}
.invoice-details p{font-size:9pt;margin:1mm 0;color:#344054;}
.invoice-totals{border:1.5px solid #17345c;min-width:65mm;padding:3mm 4mm;}
.invoice-totals div{display:flex;justify-content:space-between;gap:10mm;padding:1mm 0;font-size:10pt;}
.invoice-totals .grand{border-top:1.5px solid #17345c;margin-top:2mm;padding-top:3mm;font-size:13pt;font-weight:bold;color:#17345c;}
.invoice-legal{border-top:1px solid #17345c;margin-top:5mm;padding-top:2mm;text-align:center;font-size:8pt;color:#344054;}
@page{size:A4 portrait;margin:8mm;}
@media print{body.printing-invoice #invoicePrint{position:absolute!important;inset:0!important;width:100%!important;height:281mm!important;min-height:281mm!important;margin:0!important;padding:0!important;border:0!important;}
body.printing-invoice #invoicePrint .invoice-inner{height:281mm!important;min-height:281mm!important;padding:2mm!important;}
body.printing-invoice #invoicePrint .invoice-table-wrap{flex:1 1 auto!important;}
body.printing-invoice #invoicePrint .invoice-table{height:100%!important;}
body.printing-invoice #invoicePrint .no-print{display:none!important;}
body.printing-invoice #invoicePrint .invoice-table th,body.printing-invoice #invoicePrint .invoice-totals{ -webkit-print-color-adjust:exact;print-color-adjust:exact;}}
@media screen{#invoicePrint{max-width:900px;margin:12px auto!important;}}

/* Invoice print layout: fixed A4 geometry and clear carton column */
.invoice-classic{padding:0!important;overflow:visible!important;}
.invoice-inner{height:265mm;min-height:265mm;box-sizing:border-box;padding:5mm;display:flex;flex-direction:column;gap:0;}
.invoice-head{flex:0 0 auto;min-height:30mm;gap:8mm;}
.invoice-logo{width:auto;max-width:58mm;height:27mm;object-fit:contain;}
.invoice-company h1{font-size:17pt;}
.invoice-meta{flex:0 0 auto;min-height:25mm;padding:4mm 0;}
.invoice-table-wrap{flex:1 1 auto;min-height:90mm;display:flex;overflow:visible!important;}
.invoice-table{height:100%!important;min-width:0!important;table-layout:fixed;}
.invoice-table th:nth-child(1){width:19%}.invoice-table th:nth-child(2){width:37%}.invoice-table th:nth-child(3){width:13%}.invoice-table th:nth-child(4){width:14%}.invoice-table th:nth-child(5){width:17%}
.invoice-table td:first-child{line-height:1.6;white-space:normal;}
.invoice-fill-row{height:100%;}
.invoice-bottom{flex:0 0 auto;min-height:32mm;}
.invoice-legal{flex:0 0 auto;}
#cartonSummary .stats{grid-template-columns:repeat(2,minmax(0,1fr));}
.carton-summary-table{min-width:560px!important;}
.carton-invoice-heading td{background:#edf3fb;font-weight:bold;border-top:2px solid #9aabc0;}
@media print{@page{size:A4 portrait;margin:8mm;}body.printing-invoice #invoicePrint{position:absolute!important;left:0!important;top:0!important;inset:auto!important;width:100%!important;height:281mm!important;min-height:281mm!important;margin:0!important;padding:0!important;border:0!important;overflow:hidden!important;}body.printing-invoice #invoicePrint .invoice-inner{height:281mm!important;min-height:281mm!important;padding:2mm!important;box-sizing:border-box!important;}body.printing-invoice #invoicePrint .invoice-table-wrap{flex:1 1 auto!important;min-height:0!important;}body.printing-invoice #invoicePrint .invoice-table{height:100%!important;}body.printing-invoice #invoicePrint .invoice-fill-row{height:100%!important;}body.printing-invoice #invoicePrint .invoice-bottom{min-height:30mm!important;}}

/* ===== النسخة السحابية: الدخول والنوافذ والإشعارات ===== */
body{min-height:100vh}
.authwrap{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:18px;background:linear-gradient(160deg,#17345c 0%,#2457c5 100%)}
.authcard{width:100%;max-width:440px;background:#fff;border-radius:16px;padding:26px 24px;box-shadow:0 18px 50px rgba(8,20,45,.35)}
.authcard img.logo{display:block;max-width:190px;max-height:84px;object-fit:contain;margin:0 auto 10px}
.authcard h1{text-align:center;font-size:20px;margin:0 0 4px}
.authcard .lead{text-align:center;margin-bottom:16px}
.tabs{display:grid;grid-template-columns:1fr 1fr;gap:6px;background:#eef2f7;border-radius:10px;padding:4px;margin-bottom:16px}
.tabs button{border:0;background:transparent;padding:10px;border-radius:8px;cursor:pointer;font:inherit;color:#475467}
.tabs button.active{background:#fff;color:var(--blue);font-weight:bold;box-shadow:0 1px 3px rgba(16,24,40,.12)}
.authcard .primary{width:100%;padding:12px}
.linkbtn{background:none;border:0;color:var(--blue);cursor:pointer;font:inherit;font-size:13px;padding:6px 0}
.msg{border-radius:9px;padding:10px 12px;font-size:13px;line-height:1.7;margin-bottom:12px}
.msg.err{background:#fef3f2;border:1px solid #fecdca;color:#b42318}
.msg.ok{background:#ecfdf3;border:1px solid #abefc6;color:#067647}
.msg.info{background:#eff8ff;border:1px solid #b2ddff;color:#175cd3}
.centerbox{text-align:center;padding:6px 0}
.centerbox .big{font-size:42px;margin-bottom:6px}
.userchip{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.userchip .who{font-size:13px;color:#fff;text-align:left}
.rolepill{background:rgba(255,255,255,.16);color:#fff;border-radius:20px;padding:3px 10px;font-size:12px}
header .secondary{background:rgba(255,255,255,.08);border-color:rgba(255,255,255,.3);color:#fff}
.badge{display:inline-block;min-width:20px;padding:1px 6px;border-radius:20px;background:#b42318;color:#fff;font-size:11px;text-align:center;margin-inline-start:6px}
.modalbg{position:fixed;inset:0;background:rgba(16,24,40,.55);display:flex;align-items:center;justify-content:center;padding:16px;z-index:50}
.modal{background:#fff;border-radius:14px;padding:20px;width:100%;max-width:460px;max-height:90vh;overflow:auto}
.modal h2{margin-bottom:12px}
.modal .row{display:flex;gap:8px;justify-content:flex-start;margin-top:6px}
#toast{position:fixed;bottom:18px;left:50%;transform:translateX(-50%);z-index:60;display:flex;flex-direction:column;gap:8px;align-items:center;pointer-events:none}
#toast div{background:#182230;color:#fff;padding:10px 16px;border-radius:10px;font-size:14px;box-shadow:0 6px 20px rgba(0,0,0,.25);max-width:90vw}
#toast div.err{background:#b42318}
.loading{text-align:center;color:var(--muted);padding:40px}
.pill.disabled,.pill.cancelled{background:#f2f4f7;color:#667085}
.pill.admin{background:#e0eaff;color:#244db5}
button:disabled{opacity:.55;cursor:not-allowed}
.small{font-size:12px;color:var(--muted)}
.nav-sep{height:1px;background:var(--line);margin:6px 4px}
@media(max-width:800px){header{padding:12px 14px}.brand{font-size:17px}.userchip .who{display:none}}
@media print{#toast,.modalbg,.authwrap{display:none!important}}
input[type=email],input[type=password]{direction:ltr;text-align:left}
.invbg{align-items:flex-start;overflow:auto}
.invwrap{background:#fff;border-radius:10px;width:100%;max-width:940px;padding:12px;margin:0 auto}
.invwrap .toolbar{margin-bottom:8px}
@media print{
  body.printing-invoice #root,body.printing-invoice #toast{display:none!important}
  body.printing-invoice .modalbg{position:static!important;display:block!important;padding:0!important;background:none!important;overflow:visible!important}
  body.printing-invoice .invwrap{max-width:none!important;padding:0!important;border-radius:0!important;margin:0!important}
}
@media print{
  body.printing-invoice{background:#fff!important}
  body.printing-invoice #invoicePrint{height:274mm!important;min-height:0!important}
  body.printing-invoice #invoicePrint .invoice-inner{height:274mm!important;min-height:0!important;padding:2mm!important}
}
@media print{
  body.printing-invoice #invoicePrint .invoice-head{min-height:0!important;height:28mm!important}
  body.printing-invoice #invoicePrint .invoice-meta{min-height:0!important;padding:2mm 0!important}
  body.printing-invoice #invoicePrint .invoice-bottom{min-height:0!important}
  body.printing-invoice #invoicePrint .invoice-table-wrap{min-height:0!important;overflow:hidden!important}
  body.printing-invoice #invoicePrint .invoice-legal{margin-top:2mm!important}
}
@media print{
  body.printing-invoice #invoicePrint .invoice-table-wrap{flex:1 1 0!important;height:0;min-height:0!important}
  body.printing-invoice #invoicePrint .invoice-inner{overflow:hidden!important}
}
@media print{ body.printing-invoice .invwrap>.toolbar{display:none!important} }
