:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --border-strong: #cfd7e3;
  --text: #0b0d24;
  --text-2: #475569;
  --muted: #8592a6;
  --accent: #008a63;
  --accent-soft: #e1f5ee;
  --accent-text: #ffffff;
  --good: #00865f;
  --good-soft: #e3f6f0;
  --warn: #a16207;
  --warn-soft: #fdf4dc;
  --danger: #c2334a;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .04);
  --radius: 14px;
  --c-product: #00b682;
  --c-bank: #f7ba2f;
  --c-leg1: #8b5cf6;
  --c-freight: #1e88e5;
  --c-last: #f0743e;
  --c-duty: #ee0000;
  --c-port: #8b5cf6;
  --c-vat: #64748b;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020;
    --surface: #131a2c;
    --surface-2: #182036;
    --border: #232d45;
    --border-strong: #33405e;
    --text: #e8edf7;
    --text-2: #a9b4c9;
    --muted: #7685a0;
    --accent: #2fd39f;
    --accent-soft: #0f3328;
    --accent-text: #0b1020;
    --good: #3ccfa5;
    --good-soft: #10342c;
    --warn: #f0c060;
    --warn-soft: #3a2f14;
    --danger: #ff7a8c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --c-product: #2fd39f;
    --c-bank: #f0c060;
    --c-leg1: #a98bfa;
    --c-freight: #5aa9f0;
    --c-last: #ff9566;
    --c-duty: #ff5a5a;
    --c-port: #a98bfa;
    --c-vat: #94a3b8;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1020; --surface: #131a2c; --surface-2: #182036; --border: #232d45; --border-strong: #33405e;
  --text: #e8edf7; --text-2: #a9b4c9; --muted: #7685a0; --accent: #2fd39f; --accent-soft: #0f3328; --accent-text: #0b1020;
  --good: #3ccfa5; --good-soft: #10342c; --warn: #f0c060; --warn-soft: #3a2f14; --danger: #ff7a8c; --shadow: 0 1px 2px rgba(0,0,0,.3);
  --c-product: #2fd39f; --c-bank: #f0c060; --c-leg1: #a98bfa; --c-freight: #5aa9f0; --c-last: #ff9566; --c-duty: #ff5a5a; --c-port: #a98bfa; --c-vat: #94a3b8;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "tnum" 1, "cv11" 1;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 42px; height: 42px; border-radius: 50%; display: block; flex: 0 0 auto; }
.brand h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.tagline { margin: 0; color: var(--muted); font-size: 12.5px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: 9px;
  background: var(--surface); color: var(--text);
  font-weight: 500; font-size: 13px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { color: var(--danger); background: var(--surface-2); }
.btn-sm { height: 30px; padding: 0 11px; font-size: 12.5px; }
.btn-dashed {
  width: 100%; justify-content: center; margin-top: 8px;
  border-style: dashed; background: transparent; color: var(--accent);
}
.btn-dashed:hover { background: var(--accent-soft); }
.btn:focus-visible, .mode-opt:focus-visible, .seg button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr);
  gap: 24px;
  max-width: 1480px; margin: 0 auto; padding: 24px;
  align-items: start;
}
.inputs { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.results {
  position: sticky; top: 84px;
  max-height: calc(100vh - 100px); overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px; min-width: 0;
  padding-bottom: 8px;
  scrollbar-width: thin;
}

/* ---------- Mode toggle ---------- */
.mode-toggle {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  padding: 6px; border-radius: calc(var(--radius) + 4px);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.mode-opt {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left;
  padding: 14px 16px; border-radius: var(--radius);
  border: 1.5px solid transparent; background: transparent; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.mode-opt:hover { background: var(--surface-2); }
.mode-opt[aria-checked="true"] { background: var(--accent-soft); border-color: var(--accent); }
.mode-tag { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.mode-opt[aria-checked="true"] .mode-tag { color: var(--accent); }
.mode-title { font-weight: 700; font-size: 15px; }
.mode-desc { color: var(--text-2); font-size: 12.5px; line-height: 1.4; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; font-weight: 600; font-size: 14.5px;
  border-radius: var(--radius);
}
.card > summary::-webkit-details-marker { display: none; }
.card > summary::after {
  content: ""; margin-left: auto; width: 8px; height: 8px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translateY(-3px); transition: transform .2s;
}
.card[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }
.card-hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.card-num {
  min-width: 26px; height: 26px; padding: 0 6px; border-radius: 7px;
  display: inline-grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700;
}
.card-body { padding: 2px 18px 18px; display: flex; flex-direction: column; gap: 14px; }
.card-body.grid-3 { display: grid; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); gap: 12px 14px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.field > span i { font-style: normal; color: var(--muted); font-weight: 400; }
.field.narrow { max-width: calc(50% - 7px); }
.help { color: var(--muted); font-size: 11.5px; line-height: 1.4; }
.help b { color: var(--text-2); font-weight: 600; }
.sub-label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 4px; }

input[type="text"], input[type="number"], select {
  width: 100%; height: 38px; padding: 0 11px;
  border: 1px solid var(--border-strong); border-radius: 9px;
  background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  min-width: 0;
}
input[type="number"] { font-variant-numeric: tabular-nums; }
input:hover, select:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--border-strong)); }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
select { appearance: none; padding-right: 28px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 16px, calc(100% - 10px) 16px; background-size: 5px 5px; background-repeat: no-repeat;
}

.affix, .money {
  display: flex; align-items: stretch;
  border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface);
  overflow: hidden; transition: border-color .15s, box-shadow .15s;
}
.affix:focus-within, .money:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.affix input, .money input, .money select { border: 0; border-radius: 0; box-shadow: none !important; }
.affix .pre, .affix .post {
  display: flex; align-items: center; padding: 0 10px; white-space: nowrap;
  background: var(--surface-2); color: var(--muted); font-size: 12.5px;
}
.affix .pre { border-right: 1px solid var(--border); }
.affix .post { border-left: 1px solid var(--border); }
.affix .pre b { color: var(--text-2); margin: 0 3px; }
.money select { width: auto; flex: 0 0 auto; min-width: 84px; border-left: 1px solid var(--border); background-color: var(--surface-2); font-weight: 500; font-size: 13px; }

/* Segmented */
.seg { display: inline-flex; padding: 3px; gap: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; flex-wrap: wrap; }
.seg button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 7px;
  font-size: 13px; font-weight: 500; color: var(--text-2); cursor: pointer;
}
.seg button[aria-checked="true"] { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgba(15,23,42,.12); font-weight: 600; }

/* Legs */
.leg { padding: 14px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2); display: flex; flex-direction: column; gap: 12px; }
.leg-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-weight: 600; font-size: 13.5px; }
.leg-head em { font-style: normal; font-weight: 400; color: var(--muted); font-size: 12px; }
.leg-dot { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--text); color: var(--surface); font-size: 11.5px; font-weight: 700; align-self: center; }
.leg input, .leg select, .leg .affix, .leg .money { background-color: var(--surface); }
.leg .affix .pre, .leg .affix .post { background: var(--surface-2); }

.mini-calc { border: 1px dashed var(--border-strong); border-radius: 10px; padding: 0 12px; background: var(--surface); }
.mini-calc > summary { cursor: pointer; padding: 10px 0; font-size: 12.5px; font-weight: 600; color: var(--accent); }
.mini-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.mini-out { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.mini-out b { color: var(--text); }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; font-size: inherit; }
.link-btn:hover { text-decoration: underline; }

/* Switch */
.switch { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2); cursor: pointer; }
.switch.compact { align-self: start; margin-top: 21px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { flex: 0 0 auto; width: 36px; height: 20px; border-radius: 20px; background: var(--border-strong); position: relative; transition: background .2s; margin-top: 1px; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch b { display: block; font-weight: 600; font-size: 13px; }
.switch small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }

/* Items */
.items-head, .item-row {
  display: grid; grid-template-columns: minmax(0, 2.4fr) minmax(0, .8fr) minmax(0, 1.1fr) minmax(0, 1fr) 32px 32px; gap: 8px; align-items: center;
}
.items-head { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: -6px; }
.items-head .src-code { text-transform: none; }
#items { display: flex; flex-direction: column; gap: 8px; }
.item-row input { height: 36px; }
.icon-btn { width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.icon-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; }
.alloc { padding-top: 6px; border-top: 1px solid var(--border); }

/* ---------- Results ---------- */
.kpis { display: grid; grid-template-columns: 1.25fr 1fr 1fr; gap: 10px; }
.kpi {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.kpi-main { background: linear-gradient(140deg, #01021b, #0a3a2e 55%, #00865f); border-color: transparent; color: #fff; }
.kpi-label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kpi-main .kpi-label, .kpi-main .kpi-sub { color: rgba(255,255,255,.78); }
.kpi-value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub { font-size: 12px; color: var(--muted); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 14.5px; font-weight: 600; }
.pill { font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); }
.muted { color: var(--muted); font-size: 12px; }

.breakdown { display: grid; grid-template-columns: 170px 1fr; gap: 20px; align-items: center; }
.donut-wrap { width: 170px; height: 170px; }
#donut { width: 100%; height: 100%; display: block; }
#donut .c-lbl { font-size: 7px; fill: var(--muted); font-weight: 500; }
#donut .c-val { font-size: 12px; fill: var(--text); font-weight: 700; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.legend li { display: grid; grid-template-columns: 10px 1fr auto 52px; align-items: center; gap: 9px; font-size: 13px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }
.legend .lb { color: var(--text-2); min-width: 0; }
.legend .am { font-weight: 600; text-align: right; white-space: nowrap; }
.legend .pc { text-align: right; color: var(--muted); font-size: 12px; }
.legend li.zero { opacity: .45; }

.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
.sku-table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 640px; }
.sku-table th { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); text-align: right; padding: 0 8px 8px; border-bottom: 1px solid var(--border); line-height: 1.35; vertical-align: bottom; }
.sku-table th .src-code, .sku-table th span { text-transform: none; }
.sku-table th.l, .sku-table td.l { text-align: left; padding-left: 0; }
.sku-table td { padding: 9px 8px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.sku-table td.l { white-space: normal; font-weight: 500; max-width: 170px; }
.sku-table td.hl { font-weight: 700; color: var(--text); }
.sku-table td.hl2 { font-weight: 700; color: var(--good); }
.sku-table td .sub { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }
.sku-table tfoot td { font-weight: 600; border-bottom: 0; color: var(--text-2); }
.sku-table .margin-in { width: 66px; height: 30px; padding: 0 6px; text-align: right; font-size: 12.5px; }
.sku-table .margin-cell { display: inline-flex; align-items: center; gap: 3px; color: var(--muted); }
.sku-table .empty { text-align: center; color: var(--muted); padding: 24px 0; white-space: normal; }

#notes { display: flex; flex-direction: column; gap: 8px; }
#notes:empty { display: none; }
.note { padding: 10px 12px; border-radius: 10px; font-size: 12.5px; line-height: 1.45; background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 22%, transparent); }
.note.info { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 22%, transparent); }

/* Saved quotes */
.saved-list { display: flex; flex-direction: column; gap: 8px; }
.saved-item { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2); }
.saved-item.best { border-color: color-mix(in srgb, var(--good) 45%, var(--border)); }
.saved-item .t { font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.saved-item .m { font-size: 11.5px; color: var(--muted); }
.saved-item .n { text-align: right; white-space: nowrap; }
.saved-item .n b { display: block; font-size: 13.5px; }
.saved-item .n span { font-size: 11.5px; color: var(--muted); }
.saved-item .b { display: flex; gap: 4px; }
.tag { font-size: 10.5px; font-weight: 600; padding: 1px 7px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); }
.tag.good { background: var(--good-soft); color: var(--good); }
.empty-state { color: var(--muted); font-size: 12.5px; padding: 10px 0 4px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px;
  font-size: 13px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .results { position: static; max-height: none; overflow: visible; }
}
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; position: static; }
  .actions { width: 100%; }
  .actions .btn { flex: 1 1 auto; justify-content: center; }
  .layout { padding: 16px; gap: 16px; }
  .mode-toggle, .grid-2, .grid-3, .kpis { grid-template-columns: 1fr; }
  .field.narrow { max-width: none; }
  .mini-grid { grid-template-columns: 1fr 1fr; }
  .switch.compact { margin-top: 0; }
  .breakdown { grid-template-columns: 1fr; justify-items: center; }
  .legend { width: 100%; }
  .items-head { display: none; }
  .item-row {
    grid-template-columns: 1fr 1fr 32px; grid-auto-rows: auto; padding: 10px; border: 1px solid var(--border); border-radius: 10px;
  }
  .item-row .in-name { grid-column: 1 / 3; }
  .item-row .in-qty { grid-column: 1; }
  .item-row .in-price { grid-column: 2; }
  .item-row .in-size { grid-column: 1 / 3; grid-row: 3; }
  .item-row .calc-btn { grid-column: 3; grid-row: 3; }
  .dim-grid { grid-template-columns: 1fr 1fr; }
  .item-row .del-btn { grid-column: 3; grid-row: 1; }
  .saved-item { grid-template-columns: 1fr auto; }
  .saved-item .b { grid-column: 1 / -1; }
}

/* ---------- Per-SKU carton CBM calculator ---------- */
.calc-btn:hover { background: var(--accent-soft); color: var(--accent); }
.calc-btn.on { color: var(--accent); }
.calc-btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); }
.in-size.auto { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, var(--border-strong)); color: var(--accent); font-weight: 600; cursor: default; }
.dim-calc {
  grid-column: 1 / -1;
  padding: 12px; margin-bottom: 4px;
  border: 1px dashed color-mix(in srgb, var(--accent) 40%, var(--border-strong)); border-radius: 10px;
  background: var(--surface-2); display: flex; flex-direction: column; gap: 10px;
}
.dim-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.dim-grid input { height: 34px; }
.dim-out { font-size: 12.5px; color: var(--text-2); line-height: 1.6; }
.dim-out b { color: var(--text); }
.dim-out .dim-res { color: var(--accent); }
.dim-out .link-btn { margin-left: 6px; }
.dim-grid { align-items: end; }
@media (max-width: 640px) { .dim-grid { grid-template-columns: 1fr 1fr; } }

/* Auto-totalled shipment volume */
.inline-check { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 500; color: var(--text-2); cursor: pointer; }
.inline-check input { width: 15px; height: 15px; accent-color: var(--accent); margin: 0; }
.affix.auto { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, var(--border-strong)); }
.affix.auto input { background: transparent; color: var(--accent); font-weight: 600; cursor: default; }

.brand h1 .h1-sub { font-weight: 500; color: var(--text-2); }

/* ---------- Packing list: cartons + paste ---------- */
.items-head, .item-row {
  grid-template-columns: minmax(0, 2.2fr) minmax(0, .9fr) minmax(0, .7fr) minmax(0, 1fr) minmax(0, 1fr) 32px 32px;
}
.in-pkg.bad { border-color: var(--warn); color: var(--warn); }
.pack { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2); }
.pack-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.pack-title { display: flex; flex-direction: column; gap: 2px; font-size: 13.5px; min-width: 0; }
.pack-title b { font-weight: 600; }
.pack input { background-color: var(--surface); }
.paste-box { display: flex; flex-direction: column; gap: 10px; }
.paste-box textarea {
  width: 100%; min-height: 140px; resize: vertical; padding: 10px 11px;
  border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface); color: var(--text);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.paste-box textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.paste-preview { display: flex; flex-direction: column; gap: 8px; }
.paste-stats { font-size: 12.5px; color: var(--text-2); }
.paste-stats b { color: var(--text); }
.paste-list { max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.paste-list table { width: 100%; border-collapse: collapse; font-size: 12px; }
.paste-list th { position: sticky; top: 0; background: var(--surface-2); font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; text-align: right; padding: 6px 10px; }
.paste-list td { padding: 5px 10px; border-top: 1px solid var(--border); text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.paste-list .l { text-align: left; }
.paste-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.cartons-head, .carton-row {
  display: grid; gap: 6px; align-items: center;
  grid-template-columns: minmax(0, 1.1fr) repeat(3, minmax(0, .65fr)) minmax(0, .8fr) minmax(0, 1.25fr) 32px;
}
.cartons-head { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 4px; }
.cartons-head[hidden] { display: none; }
#cartons { display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow-y: auto; }
#cartons:empty { display: none; }
.carton-row input { height: 32px; padding: 0 8px; font-size: 13px; }
.c-out { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-out b { color: var(--text); }
.carton-row.unlinked .c-pkg { border-color: var(--warn); }
.add-carton { align-self: flex-start; font-size: 12.5px; }
@media (max-width: 640px) {
  .item-row { grid-template-columns: 1fr 1fr 32px; }
  .item-row .in-pkg { grid-column: 1; grid-row: 3; }
  .item-row .in-size { grid-column: 2; grid-row: 3; }
  .cartons-head { display: none; }
  .carton-row { grid-template-columns: 1fr 1fr 1fr 32px; padding: 8px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
  .carton-row .c-pkg { grid-column: 1 / 4; }
  .carton-row [data-cdel] { grid-column: 4; grid-row: 1; }
  .carton-row [data-cf="kg"] { grid-column: 1; }
  .carton-row .c-out { grid-column: 2 / 5; }
}
.pack-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.pack.drop { outline: 2px dashed var(--accent); outline-offset: 2px; }
.inv-opts { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.inv-opts .inline-check { align-items: flex-start; line-height: 1.4; }
.inv-opts .inline-check input { margin-top: 2px; flex: 0 0 auto; }
.paste-list tr.charge td { color: var(--text-2); font-style: italic; }
.tag-ok { color: var(--good); font-weight: 700; }
.tag-new { color: var(--accent); font-weight: 600; }
.tag-warn { color: var(--warn); font-weight: 600; }
