:root {
  --bg: #f8f6f2;
  --surface: #ffffff;
  --surface-2: #f1eee8;
  --ink: #1c1a1b;
  --ink-2: #5d5856;
  --ink-3: #8f8984;
  --line: #e6e1d9;
  --brand: #1c1a1b;
  --brand-ink: #ffffff;
  --accent: #a8834f;
  --danger: #b9382a;
  --ok: #2f7d4f;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(27,42,47,.06), 0 6px 24px rgba(27,42,47,.06);
  --st-ordered: #5b6b8c;  --st-ordered-bg: #e8ecf5;
  --st-us-warehouse: #936c24; --st-us-warehouse-bg: #f7efd9;
  --st-partially-shipped: #936c24; --st-partially-shipped-bg: #f7efd9;
  --st-shipped: #1f6fb2;  --st-shipped-bg: #e2effa;
  --st-lb-warehouse: #6c5a83; --st-lb-warehouse-bg: #eee8f4;
  --st-packed: #55704e; --st-packed-bg: #e9f1e7;
  --st-out-for-delivery: #9a5e18; --st-out-for-delivery-bg: #f8ecd9;
  --st-arrived: #a46a07;  --st-arrived-bg: #fbf0d9;
  --st-delivered: #2f7d4f; --st-delivered-bg: #e1f2e7;
  --st-cancelled: #8a5a55; --st-cancelled-bg: #f2e6e4;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: "Cormorant Garamond", Georgia, serif; font-weight: 600; letter-spacing: .005em; margin: 0; }
h1 { font-size: 32px; } h2 { font-size: 24px; } h3 { font-size: 19px; }
a { color: var(--brand); }
.muted { color: var(--ink-2); } .small { font-size: 13px; } .tiny { font-size: 12px; color: var(--ink-3); }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; } .spread { justify-content: space-between; } .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }

/* Buttons & inputs */
button, .btn {
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
}
button:hover { border-color: var(--ink-3); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--brand); }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-wa { background: #25d366; border-color: #25d366; color: #0b2e17; }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
.field { margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.lockup { display: inline-flex; align-items: center; gap: 12px; }
.logo-mark { height: 34px; width: auto; display: block; }
.logo-word { height: 13px; width: auto; display: block; }
.logo-full { height: 110px; width: auto; display: block; margin: 0 auto 6px; }
@media (max-width: 420px) { .logo-word { height: 11px; } .logo-mark { height: 28px; } }
.brand-mark { width: 30px; height: 30px; flex: none; }
.page { max-width: 1100px; margin: 0 auto; padding: 18px 16px 80px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 18px; }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; width: fit-content; max-width: 100%; overflow-x: auto; }
.tabs button { border: 0; background: transparent; color: var(--ink-2); padding: 8px 14px; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 10px; margin: 16px 0; }
.stat { padding: 14px 16px; }
.stat .num { font-family: "Cormorant Garamond", Georgia, serif; font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: 12px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .06em; }
/* Clickable dashboard tiles: look like cards, open the matching list */
button.stat-link { display: block; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; min-height: 0; height: auto; font-weight: 400; white-space: normal; transition: border-color .15s, transform .15s; }
button.stat-link:hover { border-color: var(--ink-3); transform: translateY(-1px); }
button.stat-link:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.chip { border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* Status pill */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; text-transform: capitalize; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-ordered { color: var(--st-ordered); background: var(--st-ordered-bg); }
.st-us_warehouse { color: var(--st-us-warehouse); background: var(--st-us-warehouse-bg); }
.st-partially_shipped { color: var(--st-partially-shipped); background: var(--st-partially-shipped-bg); }
.st-shipped { color: var(--st-shipped); background: var(--st-shipped-bg); }
.st-lb_warehouse { color: var(--st-lb-warehouse); background: var(--st-lb-warehouse-bg); }
.st-packed { color: var(--st-packed); background: var(--st-packed-bg); }
.st-out_for_delivery { color: var(--st-out-for-delivery); background: var(--st-out-for-delivery-bg); }
.st-arrived { color: var(--st-arrived); background: var(--st-arrived-bg); }
.st-arrived { color: var(--st-arrived); background: var(--st-arrived-bg); }
.st-delivered { color: var(--st-delivered); background: var(--st-delivered-bg); }
.st-cancelled { color: var(--st-cancelled); background: var(--st-cancelled-bg); }

/* Lists */
.list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.order-row { display: flex; gap: 12px; align-items: center; padding: 12px 14px; cursor: pointer; transition: border-color .15s; }
.order-row:hover { border-color: var(--ink-3); }
.order-row.saida-order { border: 2px solid #9b3d00; border-left-width: 7px; background: #fff3e4; }
.saida-badge { display: inline-flex; align-items: center; width: fit-content; padding: 2px 7px; border-radius: 999px; background: #8f3600; color: #fff; font-size: 10px; line-height: 1.35; font-weight: 800; letter-spacing: .035em; white-space: nowrap; }
.thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; flex: none; background: var(--surface-2); display: grid; place-items: center; color: var(--ink-3); }
.order-row .title { font-weight: 700; }
.order-shipment-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.order-row .items { color: var(--ink-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; }
.invoice-shipment-final { display: inline-flex; align-items: center; border-radius: 6px; padding: 2px 7px; font-size: 10px; line-height: 1.35; font-weight: 800; white-space: nowrap; }
.invoice-shipment-final { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--ok) 40%, var(--line)); }
.invoice-payment-status { display: inline-flex; align-items: center; border-radius: 6px; padding: 2px 7px; border: 1px solid transparent; font-size: 10px; line-height: 1.35; font-weight: 800; white-space: nowrap; }
.invoice-payment-status.payment-paid { color: #236b40; background: #e7f5eb; border-color: #a9d9b7; }
.invoice-payment-status.payment-unpaid { color: #982c2c; background: #fdeceb; border-color: #edb7b3; }
.invoice-payment-status.payment-partial { color: #805600; background: #fff4d8; border-color: #e6cc84; }
.empty { text-align: center; padding: 40px 16px; color: var(--ink-2); }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(10,20,24,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 720px) { .modal-back { align-items: center; padding: 24px; } }
.modal { background: var(--surface); width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; box-shadow: var(--shadow); }
@media (min-width: 720px) { .modal { border-radius: 18px; } }
.modal-head { position: sticky; top: 0; background: var(--surface); padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; z-index: 2; }
.modal-body { padding: 18px; }
.modal-foot { position: sticky; bottom: 0; background: var(--surface); padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* AI box */
.ai-box { border: 1.5px dashed color-mix(in srgb, var(--brand) 45%, var(--line)); background: color-mix(in srgb, var(--brand) 6%, var(--surface)); border-radius: var(--radius); padding: 14px; }
.ai-box h3 { display: flex; align-items: center; gap: 8px; }
.ai-photo { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; }

/* Item editor */
.item-ed { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; grid-template-columns: 64px 1fr; gap: 12px; }
.item-ed .img-slot { width: 64px; height: 64px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; cursor: pointer; border: 1px dashed var(--line); color: var(--ink-3); font-size: 11px; text-align: center; }
.source-unverified { margin: 6px 0 0; padding: 6px 9px; border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line)); border-radius: 8px; background: color-mix(in srgb, var(--accent) 9%, var(--surface)); color: var(--ink-2); font-size: 12px; }
.item-ed .img-slot img { width: 100%; height: 100%; object-fit: cover; }
.item-ed .qp { display: grid; grid-template-columns: 80px 1fr auto; gap: 8px; align-items: end; }
.item-ed .qp.no-box { grid-template-columns: 70px 1fr auto; }
.item-view { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item-view:last-child { border-bottom: 0; }
.item-view img, .item-view .thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; }

/* Timeline */
.timeline { display: flex; gap: 0; margin: 8px 0 4px; }
.timeline .step { flex: 1; text-align: center; position: relative; font-size: 12px; color: var(--ink-3); }
.timeline .step .dot { width: 26px; height: 26px; border-radius: 50%; margin: 0 auto 6px; display: grid; place-items: center; background: var(--surface-2); border: 2px solid var(--line); position: relative; z-index: 1; color: transparent; font-size: 13px; }
.timeline .step::before { content: ""; position: absolute; top: 12px; left: -50%; width: 100%; height: 3px; background: var(--line); }
.timeline .step:first-child::before { display: none; }
.timeline .step.done { color: var(--ink); font-weight: 600; }
.timeline .step.done .dot { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.timeline .step.done::before { background: var(--brand); }
.timeline .step.current .dot { box-shadow: 0 0 0 5px color-mix(in srgb, var(--brand) 22%, transparent); }
@media (max-width: 480px) {
  .timeline { margin-left: -5px; margin-right: -5px; }
  .timeline .step { min-width: 0; font-size: 9px; line-height: 1.15; overflow-wrap: anywhere; }
  .timeline .step .dot { width: 22px; height: 22px; margin-bottom: 5px; font-size: 11px; }
  .timeline .step::before { top: 10px; height: 2px; }
  .timeline .step .tiny { font-size: 9px; line-height: 1.1; white-space: nowrap; }
}

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 100; box-shadow: var(--shadow); font-weight: 600; max-width: calc(100% - 32px); }
.toast.err { background: var(--danger); color: #fff; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 26px; }
.auth .brand { justify-content: center; font-size: 24px; margin-bottom: 4px; }

.pin-box { font-family: ui-monospace, Menlo, monospace; font-size: 30px; letter-spacing: .25em; font-weight: 700; text-align: center; padding: 14px; background: var(--surface-2); border-radius: 12px; }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.suggest { border: 1px solid var(--line); border-radius: 10px; margin-top: 4px; max-height: 220px; overflow-y: auto; background: var(--surface); }
.suggest button { display: flex; width: 100%; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; justify-content: space-between; font-weight: 500; }
.suggest button:last-child { border-bottom: 0; }
.selected-cust { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.customer-details-panel { margin: 20px 0; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); }
.customer-details-panel h3 { margin: 0 0 10px; }
.customer-selected-details { background: var(--surface); margin-bottom: 12px; }
.customer-address-field { margin: 12px 0 0; }
.customer-address-field textarea { min-height: 72px; }
table.simple { width: 100%; border-collapse: collapse; }
table.simple td, table.simple th { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
table.simple th { font-size: 12px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }

/* Packing */
.item-ed .qp { grid-template-columns: 70px 1fr 80px auto; }
@media (max-width: 480px) { .item-ed .qp { grid-template-columns: 1fr 1fr 1fr; } .item-ed .qp.no-box { grid-template-columns: 1fr 1fr; } .item-ed .qp [data-rm] { grid-column: 1 / -1; justify-self: start; } }
.box-tag { display: inline-block; padding: 0 6px; border-radius: 6px; background: var(--surface-2); color: var(--ink); font-weight: 700; }
.pack-box { overflow: hidden; }
.pack-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 14px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.pack-cust { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.pack-cust:last-child { border-bottom: 0; }
.pack-item { display: flex; gap: 12px; align-items: center; padding: 8px 0; }
.pack-item + .pack-item { border-top: 1px dashed var(--line); }
.pack-item .thumb { width: 44px; height: 44px; }
.pack-item .pi-name { font-weight: 600; }
.pack-item .qty { color: var(--accent); font-weight: 800; }
.pack-item.is-packed .pi-name { text-decoration: line-through; color: var(--ink-3); }
.pack-item.is-packed .thumb { opacity: .5; }
.pack-check input { width: 22px; height: 22px; accent-color: var(--ok); cursor: pointer; }
.box-edit { width: 70px; flex: none; }
.box-edit label { margin: 0 0 2px; }
.box-edit input { padding: 6px 8px; text-align: center; font-weight: 700; }
.box-edit .btn-sm { width: 100%; min-height: 30px; padding: 4px 6px; }
.pack-item .pill { font-size: 11px; padding: 1px 8px; }

@media print {
  .topbar, .tabs, #newOrder, .no-print, .toast, .modal-back { display: none !important; }
  body { background: #fff; color: #000; }
  .page { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #999; }
  body.printing .pack-box:not(.print-target) { display: none; }
  .pack-box { break-inside: avoid-page; margin-bottom: 12px; }
  .pack-cust { break-inside: avoid; }
  .pack-item.is-packed .pi-name { text-decoration: none; color: #000; }
}
@media (max-width: 480px) { .wide-only { display: none; } .tabs button { padding: 8px 11px; } }

/* Printable order list (Orders page) */
#printArea { display: none; }
#itemLabelPrintArea { display: none; }
#packingPrintArea { display: none; }
@media print {
  body.printing-list > *:not(#printArea) { display: none !important; }
  body.printing-list #printArea { display: block; color: #000; }
  #printArea .pl-head { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; }
  #printArea .pl-logo { height: 60px; }
  #printArea h2 { font-size: 22px; }
  #printArea .small, #printArea .tiny { color: #333; }
  .pl-table { width: 100%; border-collapse: collapse; font-size: 12px; }
  .pl-table th { text-align: left; border-bottom: 2px solid #000; padding: 6px; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
  .pl-table td { border-bottom: 1px solid #ccc; padding: 6px; vertical-align: top; }
  .pl-table tr.pl-new td { border-top: 1.5px solid #000; }
  .pl-table tr { break-inside: avoid; }
  .pl-chk { font-size: 16px; width: 24px; }
}
@media print {
  @page packing-list { margin: 12mm; }
  body.printing-packing { page: packing-list; background: #fff; }
  body.printing-packing > *:not(#packingPrintArea) { display: none !important; }
  body.printing-packing #packingPrintArea { display: block !important; color: #000; font: 12px Arial, sans-serif; }
  #packingPrintArea .packing-print-title { margin-bottom: 14px; }
  #packingPrintArea h1 { margin: 0; font-size: 21px; }
  #packingPrintArea .packing-print-box { break-inside: avoid-page; margin: 0 0 16px; }
  #packingPrintArea h2 { margin: 12px 0 5px; padding-bottom: 4px; border-bottom: 2px solid #000; font-size: 15px; }
  #packingPrintArea table { width: 100%; border-collapse: collapse; table-layout: fixed; }
  #packingPrintArea th { text-align: left; padding: 6px; border-bottom: 1.5px solid #000; font-size: 10px; text-transform: uppercase; }
  #packingPrintArea th:first-child { width: 42%; }
  #packingPrintArea td { padding: 7px 6px; border-bottom: 1px solid #ccc; vertical-align: top; overflow-wrap: anywhere; }
  #packingPrintArea tr { break-inside: avoid; }
  #packingPrintArea .packing-print-split { display: block; margin-top: 2px; font-size: 10px; font-weight: 700; }
}
@media print {
  @page item-label { size: 2in 1in; margin: 0; }
  body.printing-labels { page: item-label; margin: 0 !important; background: #fff; }
  body.printing-labels > *:not(#itemLabelPrintArea) { display: none !important; }
  body.printing-labels #itemLabelPrintArea { display: block; width: 2in; color: #000; }
  #itemLabelPrintArea .item-label {
    box-sizing: border-box;
    page: item-label;
    width: 2in;
    height: 1in;
    padding: .1in .12in;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: .025in;
    overflow: hidden;
    break-after: page;
    page-break-after: always;
    font-family: Arial, sans-serif;
    color: #000;
  }
  #itemLabelPrintArea .item-label:last-child { break-after: auto; page-break-after: auto; }
  #itemLabelPrintArea .item-label-name {
    max-height: .3in;
    overflow: hidden;
    font-size: 9.5pt;
    line-height: 1.03;
    overflow-wrap: anywhere;
  }
  #itemLabelPrintArea .item-label-phone { font-size: 8pt; line-height: 1.02; }
  #itemLabelPrintArea .item-label-item {
    max-height: .23in;
    overflow: hidden;
    font-size: 8pt;
    line-height: 1.02;
    overflow-wrap: anywhere;
  }
}

/* Highlight one customer's items in the same shipment when they span boxes. */
.pack-item.is-split { background: var(--st-arrived-bg); border-radius: 10px; padding-left: 8px; padding-right: 8px; margin: 2px -8px; border-top-color: transparent; }
.pack-item.is-saida { background: #fff3e4; box-shadow: inset 5px 0 0 #9b3d00; }
.pack-cust.split-group { box-shadow: inset 4px 0 0 var(--st-arrived); }
.split-note { color: var(--st-arrived); font-weight: 700; font-size: 12.5px; }
.box-tag.big-box { font-size: 12px; padding: 1px 8px; background: var(--ink); color: var(--bg); }
@media print {
  .pl-table tr.pl-split td { background: #fdf0d2 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pl-table tr.pl-saida td { background: #fff0dc !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pack-item.is-split { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pack-item.is-saida, .bc-item.is-saida, .bc-cust.is-saida, .order-row.saida-order, .saida-badge { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Shipment → Box packing layout */
.ship-head { background: var(--ink); color: var(--bg); border-bottom: 0; }
.ship-head .small { color: color-mix(in srgb, var(--bg) 75%, transparent); }
.ship-head .btn-sm { background: transparent; color: var(--bg); border-color: color-mix(in srgb, var(--bg) 40%, transparent); }
.ship-label { font-family: "Cormorant Garamond", Georgia, serif; font-size: 26px; letter-spacing: .02em; }
.box-section { border-top: 1px solid var(--line); }
.box-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.box-label { font-size: 16px; padding: 2px 10px; border-radius: 8px; background: var(--surface); border: 1.5px solid var(--ink); }
.box-section .pack-cust { padding-left: 28px; }
@media print {
  .ship-head { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pl-table tr.pl-ship td { background: #1c1a1b !important; color: #fff; font-weight: 800; font-size: 14px; letter-spacing: .08em; padding: 8px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pl-table tr.pl-box td { background: #eee !important; font-weight: 700; font-size: 13px; padding: 6px 8px 6px 18px; border-bottom: 1px solid #999; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pl-table tr.pl-ship span, .pl-table tr.pl-box span { font-weight: 400; letter-spacing: 0; }
}

/* Shipment board and packing accountability */
.missing-text { color: var(--danger); font-weight: 700; }
.packed-text { color: var(--ok); font-weight: 600; }
.pack-item.is-missing, .check-row.is-missing { background: color-mix(in srgb, var(--danger) 7%, var(--surface)); }
.pack-item .btn-missing, .pack-item .btn-missing-on { flex: 0 0 auto; }
.btn-missing { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn-missing-on { color: var(--bg); background: var(--danger); border-color: var(--danger); }
.check-row { grid-template-columns: 86px minmax(0, 1fr) auto; }
.check-row .pack-check { display: flex; align-items: center; gap: 8px; min-width: 0; cursor: pointer; }
.check-row .pack-check input { width: 18px; height: 18px; accent-color: var(--ok); flex: 0 0 18px; }
.check-row .pack-check img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; }
.check-row > div:nth-child(2) { min-width: 0; overflow-wrap: anywhere; }
.check-row .pi-name { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-weight: 600; }
.check-row .pi-item-title { min-width: 0; overflow-wrap: anywhere; }
.check-row .item-label-action { flex: 0 0 auto; white-space: nowrap; }
.check-row .amount { white-space: nowrap; }
.board-sum { border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin: 8px 0 14px; background: var(--surface); }
.board-title { font-size: 22px; font-weight: 750; letter-spacing: -.02em; }
.board-stats { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.board-stats > div { min-width: 88px; display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); }
.board-stats b { font-size: 17px; }
.board-stats span { font-size: 11px; color: var(--ink-3); }
.board-stats .ok b { color: var(--ok); }
.board-stats .bad b { color: var(--danger); }
.board { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }
.box-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-sm); }
.box-card.all-packed { border-color: color-mix(in srgb, var(--ok) 55%, var(--line)); }
.box-card.has-missing { border-color: color-mix(in srgb, var(--danger) 55%, var(--line)); }
.box-card > header { padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.box-card.has-missing > header { background: color-mix(in srgb, var(--danger) 7%, var(--surface-2)); }
.box-num { font-weight: 750; font-size: 15px; }
.box-meta { color: var(--ink-3); font-size: 11px; margin-top: 3px; }
.box-card ul { list-style: none; margin: 0; padding: 6px 12px 10px; }
/* Box view: one card per customer */
.box-card ul.bc-groups { padding: 10px; display: grid; gap: 10px; }
.bc-group { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.bc-group.is-saida { border: 2px solid #9b3d00; border-left-width: 7px; }
.bc-cust { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.bc-group.is-saida .bc-cust { background: #fff3e4; }
.bc-who { min-width: 0; display: grid; gap: 3px; }
.bc-cname { font-size: 17px; font-weight: 750; line-height: 1.2; overflow-wrap: anywhere; color: var(--ink); }
.bc-sub { font-size: 12px; color: var(--ink-2); }
.bc-who .saida-badge { justify-self: start; }
.bc-lines { list-style: none; margin: 0; padding: 2px 0; }
.bc-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.bc-inv, .bc-package-label { flex: 0 0 auto; white-space: nowrap; }
@media (max-width: 560px) {
  .bc-cust { align-items: flex-start; flex-wrap: wrap; }
  .bc-actions { margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
}
.drop { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 28px 16px; border: 2px dashed var(--line); border-radius: var(--radius); cursor: pointer; text-align: center; color: var(--ink); background: var(--surface); margin: 0; }
.drop:hover, .drop.over, .drop:focus { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--surface)); outline: none; }
.map-grid { display: grid; grid-template-columns: minmax(110px, 160px) minmax(0, 1fr); gap: 8px 12px; align-items: center; margin-top: 12px; }
.map-grid label { margin: 0; }
.map-grid select { padding: 7px 10px; }
.imp-sum { display: flex; flex-wrap: wrap; gap: 18px; padding: 12px 16px; border-radius: 12px; background: var(--surface-2); }
.imp-sum div { display: flex; flex-direction: column; line-height: 1.15; }
.imp-sum b { font-size: 22px; }
.imp-sum span { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-2); }
.imp-sum .bad b, .imp-sum .bad span { color: var(--danger); }
.imp-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; box-shadow: none; }
.imp-row.is-missing { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.imp-row.is-skip { opacity: .6; }
.imp-done { font-size: 22px; font-weight: 700; color: var(--ok); }
.split-note { display: inline-block; margin-left: 4px; }
.bc-item { display: grid; grid-template-columns: 30px minmax(0, 1fr); grid-template-areas: "chk name" "chk meta"; column-gap: 10px; row-gap: 2px; align-items: center; padding: 9px 12px; cursor: pointer; border-top: 1px solid var(--line); }
.bc-lines .bc-item:first-child { border-top: 0; }
.bc-item:hover { background: var(--surface-2); }
.bc-item.is-packed .bc-name { color: var(--ink-2); }
.bc-item .bc-pack-control { grid-area: chk; }
.bc-item .bc-name { grid-area: name; font-size: 15px; font-weight: 600; line-height: 1.3; }
.bc-item .bc-meta { grid-area: meta; font-size: 12px; color: var(--ink-3); }
.bc-item.is-missing .bc-mark { color: var(--danger); }
.bc-item.is-packed .bc-mark { color: var(--ok); }
.bc-mark { font-weight: 800; }
.bc-pack-control { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; font-size: 10px; color: var(--ink-2); cursor: pointer; }
.bc-pack-control input { width: 24px; height: 24px; margin: 0; accent-color: var(--ok); flex: 0 0 24px; }
.bc-name { min-width: 0; overflow-wrap: anywhere; }
.bc-name small { display: block; color: var(--ink-3); font-size: 10px; }
.bc-qty, .bc-ord { white-space: nowrap; font-size: 11px; color: var(--ink-3); }
.bc-box-display { white-space: nowrap; font-size: 11px; }
.bc-box-meta { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
@media (max-width: 700px) {
  .board { grid-template-columns: 1fr; }
  .check-row { grid-template-columns: 66px minmax(0, 1fr) auto; gap: 8px; }
  .check-row .pack-check img { width: 36px; height: 36px; }
  .check-row .pack-check .thumb { width: 36px; height: 36px; }
  .pack-item { gap: 8px; }
  .bc-cname { font-size: 18px; }
}
@media print {
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .box-card { break-inside: avoid-page; box-shadow: none; }
  .board-sum, .box-card > header { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .bc-item { cursor: default; padding: 4px 8px; grid-template-columns: minmax(0, 1fr); grid-template-areas: "name" "meta"; }
  .bc-cname { font-size: 13px; }
  .bc-item .bc-name { font-size: 12px; }
  .bc-item .bc-meta { font-size: 10px; }
  .bc-group { break-inside: avoid; }
}

.req { color: var(--danger); }
input[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent); }

/* ---------- Items in stock ---------- */
.stock-row .title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.stock-row.is-out .thumb { opacity: .55; }
.stock-qty-view { display: flex; flex-direction: column; align-items: center; flex: none; min-width: 52px; }
.stock-num { min-width: 34px; text-align: center; font-weight: 700; font-size: 20px; font-variant-numeric: tabular-nums; }
.stock-stepper { display: flex; align-items: center; gap: 6px; }
.stock-stepper { min-width: 0; }
.stock-stepper input { text-align: center; min-width: 0; width: 100%; flex: 1 1 0; font-variant-numeric: tabular-nums; }
/* never let a pop-up be wider than the phone screen */
.modal, .modal-body { max-width: 100%; min-width: 0; }
.modal-body .field, .modal-body .row > .field { min-width: 0; }
.modal-body input, .modal-body textarea, .modal-body select { max-width: 100%; }
.stock-stepper .btn-sm { min-width: 40px; justify-content: center; font-size: 17px; flex: none; }
.stock-hist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.stock-hist li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; padding: 6px 0; border-bottom: 1px solid var(--line); color: var(--ink-2); }
.hist-up { color: var(--ok); font-weight: 700; }
.hist-down { color: var(--danger); font-weight: 700; }
.stock-badge { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; }
.stock-badge.is-out { color: var(--st-cancelled); background: var(--st-cancelled-bg); }
.stock-badge.is-low { color: var(--st-out-for-delivery); background: var(--st-out-for-delivery-bg); }
.thumb.stock-photo { width: 84px; height: 84px; font-size: 28px; }

.sell-results { display: grid; gap: 4px; margin-top: 6px; }
.sell-cust { justify-content: flex-start; width: 100%; font-weight: 400; white-space: normal; text-align: left; }
.sell-picked { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.sell-total { box-shadow: none; background: var(--surface-2); display: grid; gap: 4px; }

[hidden] { display: none !important; }

/* Stock sizes */
.size-rows { display: grid; gap: 8px; }
.size-row { display: grid; grid-template-columns: minmax(48px, 72px) minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.size-row .size-label { text-align: center; font-weight: 700; padding: 8px 4px; border-radius: 10px; background: var(--surface-2); }
.size-row .size-name { min-width: 0; text-align: center; font-weight: 600; }
.size-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.size-chip { font-size: 12px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.size-chip.is-zero { opacity: .5; text-decoration: line-through; }
.size-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.stock-view-qty { font-size: 18px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.stock-view-qty strong { font-size: 26px; font-variant-numeric: tabular-nums; }
.size-table { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.size-cell { display: flex; flex-direction: column; align-items: center; padding: 6px 4px; border: 1px solid var(--line); border-radius: 10px; font-variant-numeric: tabular-nums; }
.size-cell span { font-size: 12px; color: var(--ink-2); }
.size-cell.is-zero { opacity: .5; }
.cat-tag { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .03em; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
/* compact size rows */
.size-rows { gap: 6px; }
.size-row .btn-sm { padding: 4px 8px; min-width: 34px; }
.size-row input { padding-top: 6px; padding-bottom: 6px; }
.size-pick .chip { min-width: 44px; justify-content: center; }
.req { color: var(--danger); font-weight: 700; }
.sku-result { box-shadow: none; background: var(--surface-2); }
.sku-name { font-size: 18px; font-weight: 750; margin-top: 4px; overflow-wrap: anywhere; }
.scan-view { position: relative; border-radius: 10px; overflow: hidden; background: #111; }
.scan-view video { display: block; width: 100%; max-height: 50vh; object-fit: cover; }
.scan-aim { position: absolute; left: 12%; right: 12%; top: 32%; bottom: 32%; border: 3px solid rgba(255,255,255,.9); border-radius: 10px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); pointer-events: none; }
/* Shipment picker cards */
.ship-list { display: flex; gap: 10px; overflow-x: auto; padding: 14px 2px 10px; scroll-snap-type: x proximity; }
.ship-card { flex: 0 0 auto; min-width: 170px; display: grid; gap: 6px; justify-items: start; text-align: left; padding: 12px 14px; border-radius: 14px; white-space: normal; font-weight: 400; scroll-snap-align: start; }
.ship-card[aria-pressed="true"] { border: 2px solid var(--ink); background: var(--surface); box-shadow: var(--shadow); }
.ship-num { font-size: 20px; font-weight: 800; }
.ship-meta { font-size: 12px; color: var(--ink-2); }
.ship-done { margin: 0 0 10px; }
.ship-done summary { cursor: pointer; font-weight: 700; padding: 8px 2px; }
.ship-done-list { display: grid; gap: 6px; margin-top: 6px; }
.ship-row { display: flex; align-items: center; gap: 10px; width: 100%; justify-content: flex-start; font-weight: 400; padding: 10px 12px; border-radius: 12px; }
.ship-row strong { font-size: 16px; }
.ship-row[aria-pressed="true"] { border: 2px solid var(--ink); }
