:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111111;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #12275a;
  --primary-2: #1d3b82;
  --accent: #fff1e6;
  --orange: #f26b1d;
  --orange-2: #d9560c;
  --danger: #dc2626;
  --ok: #15803d;
  --warn: #b45309;
  --side: #0d0d0f;
  --side-text: #d4d4d8;
  --head: #12275a;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif; background: var(--bg); color: var(--text); font-size: 16px; }
a { color: var(--primary-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; }
h3 { font-size: 17.5px; margin-bottom: 10px; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }
.ltr { direction: ltr; unicode-bidi: embed; }
.txt-bad { color: var(--danger); font-weight: 700; }
.txt-ok { color: var(--ok); font-weight: 700; }

/* layout */
#app { min-height: 100vh; }
.side { position: fixed; inset: 0 0 0 auto; width: 250px; background: var(--side); color: var(--side-text); overflow-y: auto; z-index: 30; }
.brand { padding: 18px 18px 14px; font-size: 25.5px; font-weight: 700; color: #fff; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand small { display: block; font-size: 14px; font-weight: 400; color: var(--side-text); }
.nav-sec { padding: 12px 18px 4px; font-size: 12.5px; color: var(--orange); font-weight: 700; letter-spacing: .3px; }
.nav a { display: block; padding: 7px 18px; color: var(--side-text); font-size: 15.5px; border-right: 3px solid transparent; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(255,255,255,.1); color: #fff; border-right-color: var(--orange); font-weight: 600; }
.main { margin-right: 250px; min-height: 100vh; display: flex; flex-direction: column; }
.top { height: 56px; background: var(--card); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 0 20px; position: sticky; top: 0; z-index: 20; }
.top .spacer { flex: 1; }
.user-box { display: flex; align-items: center; gap: 8px; }
.user-box small { color: var(--muted); }
.icon-btn { display: none; background: none; border: 0; font-size: 25.5px; cursor: pointer; }
#view { padding: 20px; flex: 1; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h2 { font-size: 23px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* cards & grids */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 14px; }
.grid .full { grid-column: 1 / -1; }
.grid .span2 { grid-column: span 2; }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; border-top: 3px solid var(--primary-2); }
.stat.warn { border-top-color: var(--warn); }
.stat-label { color: var(--muted); font-size: 14.5px; }
.stat-value { font-size: 27.5px; font-weight: 700; margin-top: 2px; }
.stat-sub { color: var(--muted); font-size: 14px; }

/* forms */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 14.5px; color: var(--muted); font-weight: 600; }
.req { color: var(--danger); }
input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid #cbd5e1; border-radius: 7px; background: #fff; color: var(--text); width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #fdba8c; border-color: var(--orange); }
input:disabled, select:disabled { background: #f1f5f9; color: #64748b; }
textarea { resize: vertical; }
input.scan { font-size: 19.5px; padding: 10px 12px; direction: ltr; text-align: left; font-weight: 600; letter-spacing: .5px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 15px; cursor: pointer; }
.check input { width: auto; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px 12px; align-items: end; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 7px 14px; border-radius: 7px; border: 1px solid #cbd5e1; background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 3px 9px; font-size: 14.5px; }
.btn.lg { padding: 10px 22px; font-size: 17.5px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.quick-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.quick { padding: 9px 14px; border-radius: 8px; background: color-mix(in srgb, var(--c) 10%, white); color: var(--c); font-weight: 700; border: 1px solid color-mix(in srgb, var(--c) 30%, white); }
.quick:hover { text-decoration: none; background: color-mix(in srgb, var(--c) 18%, white); }

/* tables */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 8px; max-height: 70vh; }
.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th { background: var(--head); color: #fff; font-weight: 600; text-align: right; padding: 8px 10px; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.tbl td { padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.tbl td .chips { white-space: normal; }
.tbl tbody tr:nth-child(even) { background: #f8fafc; }
.tbl tbody tr:hover { background: var(--accent); }
.tbl tfoot td { font-weight: 700; background: #e8ebf3; position: sticky; bottom: 0; }
.tbl .num { text-align: left; direction: ltr; white-space: nowrap; }
.tbl td.code { direction: ltr; text-align: left; font-family: Consolas, monospace; font-size: 14.5px; white-space: nowrap; }
.tbl td.actions { white-space: nowrap; }
.tbl tr.low td { background: #fff7ed; }
.tbl input { padding: 3px 6px; width: 90px; }
.empty { padding: 26px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: 8px; }
.count-line { margin-top: 6px; color: var(--muted); font-size: 14.5px; }
.chips { display: flex; flex-wrap: wrap; gap: 3px; max-width: 520px; }
.chip { background: #e8ebf3; color: var(--primary); border-radius: 4px; padding: 0 6px; font-size: 13px; direction: ltr; font-family: Consolas, monospace; }
.bar { height: 6px; background: #fdba8c; border-radius: 4px; margin-top: 3px; }

/* badges */
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 14px; font-weight: 600; background: #e2e8f0; color: #334155; white-space: nowrap; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.bad { background: #fee2e2; color: #991b1b; }
.badge.dt { background: color-mix(in srgb, var(--c) 14%, white); color: var(--c); }
.st-in_stock { background: #dcfce7; color: #166534; }
.st-sold { background: #dbeafe; color: #1e40af; }
.st-returned { background: #ede9fe; color: #5b21b6; }
.st-deducted { background: #fee2e2; color: #991b1b; }
.st-void { background: #e5e7eb; color: #4b5563; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 640px; max-width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: 920px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head .x { background: none; border: 0; font-size: 27.5px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px 18px; }
.modal-err, .form-err { color: var(--danger); padding: 0 18px; font-weight: 600; }
.modal-foot { display: flex; justify-content: flex-start; gap: 8px; padding: 12px 18px 16px; }
.perm-group { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.perm-group h4 { margin: 0 0 8px; font-size: 15px; color: var(--primary); }
.perm-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 6px; }

/* toasts */
#toasts { position: fixed; top: 70px; left: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 420px; }
.toast.ok { background: #166534; }
.toast.err { background: #991b1b; }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0d0d0f, #12275a 70%, #1d3b82); padding: 16px; }
.login { width: 380px; max-width: 100%; padding: 28px; }
.login h2 { margin-bottom: 4px; }
.login .field { margin: 12px 0; }

/* document entry */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tab { padding: 8px 16px; cursor: pointer; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.entry-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.entry-row .field { flex: 1; min-width: 160px; }
.entry-row .field.grow { flex: 3; }
.msgs { margin-top: 10px; max-height: 180px; overflow-y: auto; }
.msg { padding: 5px 10px; border-radius: 6px; margin-bottom: 4px; font-size: 15px; }
.msg.ok { background: #dcfce7; color: #166534; }
.msg.err { background: #fee2e2; color: #991b1b; }
.save-bar { margin-top: 14px; position: sticky; bottom: 0; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; box-shadow: 0 -4px 14px rgba(15,23,42,.06); flex-wrap: wrap; }
.save-bar b { font-size: 20.5px; }
.section-title { font-size: 15px; font-weight: 700; color: var(--primary); margin: 4px 0 8px; }

/* document view */
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px 16px; margin-bottom: 16px; }
.info { display: flex; flex-direction: column; border-bottom: 1px dashed var(--border); padding-bottom: 4px; }
.info span { color: var(--muted); font-size: 14px; }
.info b { overflow-wrap: anywhere; }
.info.full { grid-column: 1 / -1; }
.doc-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

/* trace */
.timeline { position: relative; padding-right: 22px; }
.timeline::before { content: ''; position: absolute; right: 7px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.tl-item { position: relative; margin-bottom: 12px; }
.tl-dot { position: absolute; right: -22px; top: 12px; width: 14px; height: 14px; border-radius: 50%; background: var(--c); border: 3px solid #fff; box-shadow: 0 0 0 1px var(--c); }
.tl-body { background: #fff; border: 1px solid var(--border); border-right: 4px solid var(--c); border-radius: 8px; padding: 10px 14px; }
.tl-item.cancelled .tl-body { opacity: .55; text-decoration: line-through; }
.tl-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.tl-route { margin: 6px 0 2px; font-weight: 600; }
.tl-meta { color: var(--muted); font-size: 14.5px; }
.big-serial { font-size: 27.5px; font-weight: 700; direction: ltr; font-family: Consolas, monospace; }

/* proof of delivery */
.pod { background: #fff; padding: 18px; }
.pod h1 { text-align: center; font-size: 22px; margin-bottom: 12px; letter-spacing: 1px; }
.pod table { width: 100%; border-collapse: collapse; font-size: 13px; direction: ltr; }
.pod td, .pod th { border: 1px solid #333; padding: 5px 8px; text-align: left; }
.pod .pod-head td:nth-child(odd) { font-weight: 700; background: #f1f5f9; }
.pod .pod-lines th { background: #12275a; color: #fff; }
.pod .sign { height: 54px; }
.print-only { display: none; }

@media (max-width: 900px) {
  .side { transform: translateX(100%); transition: transform .2s; }
  .side.open { transform: none; }
  .main { margin-right: 0; }
  .icon-btn { display: block; }
  .cols2 { grid-template-columns: 1fr; }
  #view { padding: 12px; }
  .user-box small { display: none; }
}

@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; font-size: 12px; }
  .side, .top, .no-print, .page-head .actions, #toasts { display: none !important; }
  .main { margin: 0; }
  #view { padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .table-wrap { max-height: none; overflow: visible; border: 0; }
  .tbl th { position: static; background: #ddd !important; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .tbl td, .tbl th { border: 1px solid #999; }
  .print-only { display: block; }
  .pod .pod-lines th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* keep focused fields visible above the sticky save bar */
#view input, #view select, #view textarea, #view button { scroll-margin-bottom: 120px; }

/* in transit */
.st-in_transit { background: #fef3c7; color: #92400e; }

/* alerts bell */
.bell-wrap { position: relative; }
.bell-n { position: absolute; top: -4px; left: -4px; background: var(--danger); color: #fff; border-radius: 999px; font-size: 12.5px; padding: 0 6px; line-height: 17px; }
.bell-panel { position: absolute; top: 40px; left: 0; width: 340px; max-width: 90vw; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 30px rgba(15,23,42,.18); z-index: 50; padding: 6px; }
.alert-row { display: block; padding: 8px 10px; border-radius: 7px; margin: 3px 0; color: var(--text); border-right: 4px solid #94a3b8; background: #f8fafc; }
.alert-row:hover { text-decoration: none; background: var(--accent); }
.alert-row.warn { border-right-color: var(--warn); }
.alert-row.bad { border-right-color: var(--danger); }
.alert-row.info { border-right-color: var(--primary-2); }

/* attachments */
.att-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.att { border: 1px solid var(--border); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.att img { width: 100%; height: 130px; object-fit: cover; border-radius: 6px; background: #f1f5f9; }
.att-pdf { display: flex; align-items: center; justify-content: center; height: 130px; background: #fee2e2; color: #991b1b; font-weight: 700; border-radius: 6px; }
.att-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* barcode labels */
.labels { display: grid; gap: 4mm; direction: ltr; }
.labels.a4 { grid-template-columns: repeat(3, 1fr); }
.labels.thermal { grid-template-columns: 50mm; }
.label { border: 1px dashed #cbd5e1; padding: 2mm 3mm; text-align: center; background: #fff; break-inside: avoid; overflow: hidden; }
.labels.thermal .label { width: 50mm; height: 30mm; }
.label .lb-code { font-weight: 700; font-size: 11px; }
.label .lb-name { font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.label svg { max-width: 100%; height: auto; }
@media print {
  .labels.thermal { gap: 0; }
  .labels.thermal .label { border: 0; break-after: page; }
  .label { border-color: #eee; }
}

/* ===== printed documents (A4 / A4 landscape / A5 / PDF) ===== */
.print-head { display: none; }
.print-area { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.sheet { position: relative; background: #fff; color: #111; width: 210mm; padding: 10mm; box-shadow: 0 2px 12px rgba(15,23,42,.12); font-size: 12px; overflow: hidden; }
.size-a4l .sheet { width: 297mm; }
.size-a5 .sheet { width: 148mm; padding: 6mm; font-size: 10px; }
.ph { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; border-bottom: 2px solid #12275a; padding-bottom: 6px; margin-bottom: 8px; }
.ph-company { display: flex; gap: 10px; align-items: center; }
.ph-logo { max-height: 60px; max-width: 130px; object-fit: contain; }
.size-a5 .ph-logo { max-height: 38px; max-width: 80px; }
.ph-name { font-size: 18px; font-weight: 700; }
.size-a5 .ph-name { font-size: 13px; }
.ph-name-en { direction: ltr; text-align: right; font-size: 11px; color: #444; }
.ph-sub { font-size: 10.5px; color: #444; }
.ph-doc { display: flex; flex-direction: column; align-items: flex-end; text-align: left; }
.ph-title { font-size: 17px; font-weight: 700; color: #12275a; }
.size-a5 .ph-title { font-size: 13px; }
.ph-title-en { direction: ltr; font-size: 10.5px; color: #555; }
.doc-barcode { height: 44px; max-width: 210px; }
.size-a5 .doc-barcode { height: 34px; max-width: 150px; }
.pinfo { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 8px; }
.size-a4l .pinfo { grid-template-columns: repeat(6, 1fr); }
.size-a5 .pinfo { grid-template-columns: repeat(2, 1fr); }
.pbox { border: 1px solid #cbd5e1; border-radius: 4px; padding: 3px 6px; display: flex; flex-direction: column; min-width: 0; }
.pbox span { font-size: 9.5px; color: #555; }
.pbox b { font-size: 11.5px; overflow-wrap: anywhere; }
.pbox.wide { grid-column: 1 / -1; }
.plines { width: 100%; border-collapse: collapse; }
.plines thead { display: table-header-group; }
.plines tr { break-inside: avoid; page-break-inside: avoid; }
.plines th { background: #12275a; color: #fff; padding: 4px 5px; font-size: 10.5px; text-align: right; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.plines td { border: 1px solid #cbd5e1; padding: 3px 5px; vertical-align: top; }
.plines tbody tr:nth-child(even) td { background: #f8fafc; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.plines .num { text-align: left; direction: ltr; white-space: nowrap; }
.plines .ltr { direction: ltr; text-align: left; font-family: Consolas, monospace; font-size: 10.5px; }
.pserials { direction: ltr; text-align: left; font-family: Consolas, monospace; font-size: 9.5px; word-break: break-all; }
.ptotals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 8px; break-inside: avoid; }
.pnotes { margin-top: 6px; border: 1px dashed #cbd5e1; padding: 4px 6px; }
.psign { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 12px; margin-top: 24px; break-inside: avoid; }
.psign div { border-top: 1px solid #333; padding-top: 4px; text-align: center; min-height: 44px; }
.psign i { display: block; font-size: 11px; color: #777; font-style: normal; }
.pfoot { display: flex; justify-content: space-between; gap: 10px; margin-top: 12px; font-size: 9.5px; color: #666; border-top: 1px solid #e2e8f0; padding-top: 4px; }
.watermark { position: absolute; top: 38%; left: 0; right: 0; text-align: center; font-size: 126.5px; font-weight: 700; color: rgba(220,38,38,.13); transform: rotate(-25deg); pointer-events: none; }
.size-a5 .watermark { font-size: 70px; }
.pcancel { background: #fee2e2; color: #991b1b; padding: 4px 8px; border-radius: 4px; margin-bottom: 6px; font-weight: 700; }
.sheet-break { break-after: page; page-break-after: always; height: 0; width: 100%; }
.pdf-mode .sheet { box-shadow: none; }
@media print {
  .print-head { display: flex; justify-content: space-between; border-bottom: 1px solid #999; margin-bottom: 6px; padding-bottom: 4px; font-size: 11px; }
  .print-area { display: block; }
  .sheet { box-shadow: none; width: auto !important; padding: 0; margin: 0; overflow: visible; }
  .sheet-break { display: block; }
}

.page-head .actions select { width: auto; }

/* ===== fixes from the UI review ===== */
/* phone width: grid children may shrink, tables scroll inside their card */
.cols2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.cols2 > *, .main, .card, .grid > * { min-width: 0; }
@media (max-width: 900px) {
  .cols2 { grid-template-columns: minmax(0, 1fr); }
  .top { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .top form { order: 3; flex-basis: 100%; max-width: none !important; }
}
.brand { font-size: 20.5px; overflow-wrap: anywhere; line-height: 1.3; }
/* labels like "Move order #" keep their own direction inside the RTL page */
.field label, .pbox span, .info span, .tbl th { unicode-bidi: plaintext; text-align: right; }
/* printed documents: codes and serials stay whole, long names wrap */
.plines td { overflow-wrap: anywhere; }
.plines .pcode, .plines .pserial { direction: ltr; text-align: left; font-family: Consolas, monospace; font-size: 10.5px; white-space: nowrap; }
.size-a5 .plines .pserial, .size-a5 .plines .pcode { font-size: 8.5px; white-space: normal; overflow-wrap: anywhere; }
.size-a5 .plines td, .size-a5 .plines th { padding: 2px 3px; }
.pserials { word-break: normal; overflow-wrap: normal; }
.pserials span { display: inline-block; white-space: nowrap; margin: 0 3px 1px 0; }
.col-serials { width: 45%; }
.plines tr.long { break-inside: auto; page-break-inside: auto; }
@media print {
  /* the screen title / toolbar and report filters are not part of the paper */
  .page-head, .filters { display: none !important; }
  .tbl { font-size: 9.5px; }
  .tbl td, .tbl th { white-space: normal !important; overflow-wrap: anywhere; padding: 3px 4px; }
  .tbl td.code { white-space: normal !important; }
  .labels.thermal .label { margin: 0; }
}

/* ===== bold text everywhere ===== */
body, input, select, textarea, button, table, th, td, label, a, span, div, p, small, li, option { font-weight: 700 !important; }
h1, h2, h3, h4, .brand, .stat-value, .big-serial { font-weight: 800 !important; }

/* form sections inside the item window */
.grid > .section-title { grid-column: 1 / -1; margin: 10px 0 0; padding-top: 8px; border-top: 1px solid var(--border); }
.grid > .grid-break { grid-column: 1 / -1; height: 0; }

/* drop-down lists of the typed choices */
input.combo { padding-left: 30px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2364748b' stroke-width='2'/%3E%3C/svg%3E") no-repeat left 10px center; }
.combo-box { position: fixed; z-index: 1000; background: #fff; border: 1px solid #cbd5e1; border-radius: 8px; box-shadow: 0 8px 24px rgba(15,23,42,.18); overflow-y: auto; padding: 4px 0; }
.combo-box > div { padding: 7px 12px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combo-box > div:hover, .combo-box > div.on { background: var(--accent); color: var(--primary); }
.combo-box > div.sel { color: var(--primary); }
.combo-box > div.more { cursor: default; white-space: normal; font-size: 13px; }
.combo-box > div.more:hover { background: none; }
@media print { .combo-box { display: none !important; } }

/* search inside the drop-down lists and above the tables */
.ss-panel { display: flex; flex-direction: column; padding: 0; }
.ss-panel .ss-q { margin: 6px; width: calc(100% - 12px); }
.ss-panel .ss-list { overflow-y: auto; padding-bottom: 4px; }
.ss-panel .ss-list > div { padding: 7px 12px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-panel .ss-list > div:hover, .ss-panel .ss-list > div.on { background: var(--accent); color: var(--primary); }
.ss-panel .ss-list > div.sel { color: var(--primary); }
.tbl-tools { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.tbl-tools .tbl-search { max-width: 320px; }
@media print { .tbl-tools, .ss-panel { display: none !important; } }

.st-consumed { background: #ffe4e6; color: #9f1239; }

/* scrolling to an element keeps it below the sticky top bar */
html { scroll-padding-top: 80px; scroll-padding-bottom: 80px; }

/* dashboard by role */
.dash-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.dash-sec { margin-bottom: 18px; }
.dash-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0 10px; }
.dash-head h2 { font-size: 21px; color: var(--primary); }
.dash-head .quick-grid { margin: 0; }
.stat-link { color: inherit; }
.stat-link:hover { color: var(--primary-2); }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 170px; padding-top: 6px; overflow-x: auto; }
.bar-day { flex: 1 0 28px; display: flex; flex-direction: column; align-items: center; height: 100%; }
.bar-pair { flex: 1; display: flex; align-items: flex-end; gap: 2px; width: 100%; justify-content: center; }
.bar { display: inline-block; width: 10px; border-radius: 3px 3px 0 0; min-height: 2px; }
.bar.out { background: #16a34a; }
.bar.in { background: #ea580c; }
.bar-day small { font-size: 11px; color: var(--muted); margin-top: 3px; direction: ltr; }
.bar-legend { display: flex; gap: 16px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.bar-legend i { height: 10px; vertical-align: middle; }
@media print { .dash-sec[hidden] { display: none; } }
.dash-sec .tbl td { white-space: normal; overflow-wrap: anywhere; }
.dash-sec .tbl td.code { white-space: nowrap; }
.dash-sec .table-wrap { max-height: 420px; }

/* drop-down choices show their whole text */
.ss-panel { max-width: min(640px, calc(100vw - 24px)); }
.ss-panel .ss-list > div { white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; line-height: 1.5; }
.combo-box > div { white-space: normal; overflow-wrap: anywhere; }

@media screen and (max-width: 900px) { #print-area { overflow-x: auto; max-width: 100%; } }

/* reports: tables from left to right */
.ltr-report .tbl, .ltr-report .table-wrap { direction: ltr; }
.ltr-report .tbl th, .ltr-report .tbl td { text-align: left; }
.ltr-report .tbl th.num, .ltr-report .tbl td.num { text-align: right; }
.ltr-report .tbl td .chips { justify-content: flex-start; }

/* the whole report page reads left to right: title, buttons, filters, cards and tables */
.ltr-report { direction: ltr; }
.ltr-report .field label, .ltr-report .info span, .ltr-report .stat-label, .ltr-report .stat-sub, .ltr-report h2, .ltr-report h3,
.ltr-report .section-title, .ltr-report .count-line, .ltr-report .muted, .ltr-report .empty, .ltr-report .tl-route, .ltr-report .tl-meta { text-align: left; }
.ltr-report .tbl-tools .tbl-search { direction: rtl; }
.ltr-report input, .ltr-report select, .ltr-report textarea { text-align: left; }
.ltr-report .chips { direction: ltr; }
.ltr-report .timeline { padding-right: 0; padding-left: 22px; }
.ltr-report .timeline::before { right: auto; left: 7px; }
.ltr-report .tl-dot { right: auto; left: -22px; }
.ltr-report .tl-body { border-right: 1px solid var(--border); border-left: 4px solid var(--c); }
/* mixed Arabic / English text keeps its own reading order inside the left-to-right report */
.ltr-report .info b, .ltr-report .info span, .ltr-report select, .ltr-report option, .ltr-report label, .ltr-report td, .ltr-report th,
.ltr-report h2, .ltr-report h3, .ltr-report .stat-value, .ltr-report .stat-label, .ltr-report .stat-sub, .ltr-report .muted,
.ltr-report .section-title, .ltr-report .tl-route, .ltr-report .tl-meta, .ltr-report .btn { unicode-bidi: plaintext; }
.ltr-report select, .ltr-report option { direction: rtl; text-align: right; unicode-bidi: normal; }

/* forms: inputs of a row line up even when a label is longer */
.grid { align-items: end; }
/* one-line rows (document header): short labels on one line, the explanation in the tooltip */
.grid.line { grid-template-columns: repeat(auto-fill, minmax(138px, 1fr)); }
.grid.line .field label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid.line .field label .muted { font-weight: 400; }

/* ===== colors: navy, black, orange ===== */
.brand { border-bottom: 3px solid var(--orange); }
.nav a:hover { color: #fff; }
.nav a.active { color: #fff; background: rgba(242,107,29,.14); }
.stat { border-top-color: var(--orange); }
.stat.warn { border-top-color: var(--danger); }
.tab.active { color: var(--primary); border-bottom-color: var(--orange); }
.section-title, .dash-head h2, .page-head h2 { color: var(--primary); }
.page-head h2 { border-inline-start: 4px solid var(--orange); padding-inline-start: 10px; }
a { color: var(--primary-2); }
a:hover { color: var(--orange-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-2); }
.btn.accent, .save-bar .btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.accent:hover, .save-bar .btn.primary:hover { background: var(--orange-2); border-color: var(--orange-2); }
.save-bar { border-top: 3px solid var(--orange); }
.tbl th { border-bottom: 2px solid var(--orange); }
.combo-box > div:hover, .combo-box > div.on, .ss-panel .ss-list > div:hover, .ss-panel .ss-list > div.on { background: var(--accent); color: var(--orange-2); }
.badge.ok { background: #e7f6ec; }
.bell-n { background: var(--orange); }
/* dashboard: sections open / close from their title */
.dash-toggle { display: inline-flex; align-items: center; gap: 8px; background: none; border: 0; padding: 4px 0; cursor: pointer; font: inherit; font-size: 21px; font-weight: 800 !important; color: var(--primary); }
.dash-toggle:hover { color: var(--orange-2); }
.dash-toggle:focus-visible { outline: 2px solid var(--orange); outline-offset: 3px; border-radius: 6px; }
.dash-toggle .caret { display: inline-block; color: var(--orange); transition: transform .15s; }
.dash-sec.closed .dash-toggle .caret { transform: rotate(90deg); }
.dash-sec.closed .dash-body { display: none; }
.dash-sec.closed .dash-head .quick-grid { display: none; }
.dash-sec { border-bottom: 1px solid var(--border); padding-bottom: 6px; }
@media (prefers-reduced-motion: reduce) { .dash-toggle .caret { transition: none; } }

/* dashboard sub-titles open / close their card */
.dash-sub { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; padding: 0; cursor: pointer; font: inherit; font-size: 18px; font-weight: 700 !important; color: var(--primary); text-align: start; }
.dash-sub:hover { color: var(--orange-2); }
.dash-sub:focus-visible { outline: 2px solid var(--orange); outline-offset: 3px; border-radius: 6px; }
.dash-sub .caret { color: var(--orange); transition: transform .15s; display: inline-block; }
.dash-card .dash-card-body { margin-top: 10px; }
.dash-card.closed .dash-card-body { display: none; }
.dash-card.closed .dash-sub .caret { transform: rotate(90deg); }
.dash-card.closed { padding-block: 12px; }
@media (prefers-reduced-motion: reduce) { .dash-sub .caret { transition: none; } }
.dash-sec .cols2 { align-items: start; }

/* filter bars: fields flow on one line, options next to them, the buttons on a row of their own */
.filters { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; }
.filters > .field { flex: 1 1 180px; min-width: 160px; max-width: 300px; }
.filters > .field.span2 { flex: 2 1 280px; max-width: 460px; }
.filters > .field label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.filters > .check { flex: 0 0 auto; white-space: nowrap; padding-bottom: 9px; }
.filters > .filter-actions { flex: 1 0 100%; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; border-top: 1px dashed var(--border); padding-top: 10px; }
.filters > .filter-actions .btn { min-width: 90px; }
.page-head .actions .btn, .page-head > .btn { white-space: nowrap; }

/* side menu: groups open / close from their title */
.nav-group .nav-sec { display: flex; align-items: center; justify-content: space-between; width: 100%; background: none; border: 0; cursor: pointer; font-family: inherit; text-align: start; }
.nav-group .nav-sec:hover { color: #fdba8c; }
.nav-group .nav-sec:focus-visible { outline: 2px solid var(--orange); outline-offset: -2px; }
.nav-group .nav-sec .caret { transition: transform .15s; font-size: 12px; }
.nav-group.closed .nav-sec .caret { transform: rotate(90deg); }
.nav-group.closed .nav-items { display: none; }
.nav-group { border-bottom: 1px solid rgba(255,255,255,.06); }
@media (prefers-reduced-motion: reduce) { .nav-group .nav-sec .caret { transition: none; } }
