:root {
  --bg: #f3f1ec; --surface: #ffffff; --surface-2: #f8f7f4; --ink: #1c232b; --muted: #5d6874;
  --border: #dcd7ce; --accent: #0d7a6f; --accent-ink: #ffffff; --accent-soft: #dff1ee;
  --ok: #1d8a57; --ok-soft: #e1f4ea; --bad: #c0392b; --bad-soft: #fbe6e3; --warn: #b7791f;
  --line-3d: #6b7783; --viewer: #e9e6df; --shadow: 0 1px 2px rgba(20,25,30,.06), 0 4px 16px rgba(20,25,30,.05);
  --mono: 'JetBrains Mono', ui-monospace, monospace; --sans: 'Manrope', system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151a; --surface: #192027; --surface-2: #1e262e; --ink: #e7ebee; --muted: #93a0ac;
    --border: #2b353f; --accent: #3cc2b0; --accent-ink: #0b1513; --accent-soft: #163a36;
    --ok: #4cc38a; --ok-soft: #173327; --bad: #f07167; --bad-soft: #3a1f1d; --warn: #e3b341;
    --line-3d: #8a98a6; --viewer: #141a20; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11151a; --surface: #192027; --surface-2: #1e262e; --ink: #e7ebee; --muted: #93a0ac;
  --border: #2b353f; --accent: #3cc2b0; --accent-ink: #0b1513; --accent-soft: #163a36;
  --ok: #4cc38a; --ok-soft: #173327; --bad: #f07167; --bad-soft: #3a1f1d; --warn: #e3b341;
  --line-3d: #8a98a6; --viewer: #141a20; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h2 { font-size: 1.5rem; font-weight: 800; letter-spacing: -.01em; }
h3 { font-size: 1.02rem; font-weight: 700; }
.muted { color: var(--muted); }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 60px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 800; font-size: 1.35rem; letter-spacing: .14em; }
.brand svg { width: 30px; height: 30px; fill: #fff; }
.brand .brand-bg { fill: var(--accent); }
.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tabs a { white-space: nowrap; padding: 8px 14px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .93rem; }
.tabs a:hover { background: var(--surface-2); color: var(--ink); }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }
.icon-btn { border: 1px solid var(--border); background: var(--surface); color: var(--ink); width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; }

/* Layout */
.layout { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 20px; padding: 20px; max-width: 1600px; margin: 0 auto; align-items: start; }
.shipment { position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.module { min-width: 0; display: grid; gap: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card > h3:first-child { margin-bottom: 12px; }
.lead { color: var(--muted); margin: 0 0 4px; max-width: 70ch; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.foot { max-width: 1600px; margin: 0 auto; padding: 8px 20px 40px; color: var(--muted); font-size: .82rem; }

/* Shipment panel */
.ship-head { display: flex; justify-content: space-between; align-items: baseline; padding: 16px 16px 8px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.ship-head h3 { margin: 0; font-size: 1.1rem; }
.pieces { padding: 12px; display: grid; gap: 10px; }
.piece { border: 1px solid var(--border); border-left: 4px solid var(--c, var(--accent)); border-radius: 10px; padding: 10px; background: var(--surface-2); display: grid; gap: 8px; }
.piece .top { display: flex; gap: 8px; }
.piece .top input { flex: 1; }
.piece .dims { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.piece .dims label { grid-column: span 2; }
.piece .dims label:nth-child(n+4) { grid-column: span 3; }
.piece .flags { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; font-size: .82rem; color: var(--muted); }
.piece .flags .spacer { flex: 1; }
.ship-add, .ship-tools { padding: 0 12px 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.totals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 0 12px 12px; }
.totals div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; }
.totals b { display: block; font-family: var(--mono); font-size: .95rem; }
.totals span { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* Forms */
label.f { display: grid; gap: 3px; font-size: .74rem; color: var(--muted); font-weight: 600; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; min-width: 0; width: 100%; }
input[type=number], .mono-in { font-family: var(--mono); font-size: .9rem; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.chk { display: inline-flex; gap: 5px; align-items: center; cursor: pointer; white-space: nowrap; }
.btn { font: inherit; font-weight: 700; font-size: .9rem; border: 1px solid var(--border); background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small { padding: 4px 9px; font-size: .78rem; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.x { border: none; background: none; color: var(--bad); font-size: 1.1rem; cursor: pointer; padding: 0 6px; }

/* Results */
.verdict { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 10px; font-weight: 700; }
.verdict.ok { background: var(--ok-soft); color: var(--ok); }
.verdict.bad { background: var(--bad-soft); color: var(--bad); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 12px 0; }
.kpi { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.kpi span { font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; }
.kpi b { display: block; font: 600 1.25rem var(--mono); }
.specs { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px 16px; margin: 12px 0; font-size: .88rem; }
.specs div span { display: block; color: var(--muted); font-size: .74rem; }
.specs div b { font-family: var(--mono); font-weight: 600; }
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr.best td { background: var(--accent-soft); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* 3D */
.viewer { position: relative; height: 460px; border-radius: 12px; background: var(--viewer); overflow: hidden; border: 1px solid var(--border); }
.viewer canvas { display: block; width: 100%; height: 100%; }
.viewer .tag { position: absolute; font-size: .72rem; font-weight: 700; color: var(--muted); letter-spacing: .05em; bottom: 10px; }
.viewer .tag.l { left: 12px; } .viewer .tag.r { right: 12px; }
.viewer-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.viewer-bar input[type=range] { flex: 1; min-width: 120px; padding: 0; }

.steps { display: grid; gap: 18px; }
.step-n { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: .85rem; margin-right: 8px; }
.hero { background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%); }
.hero h2 { font-size: 2rem; }
details summary { cursor: pointer; font-weight: 700; color: var(--accent); margin: 10px 0; }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--border); border-radius: 10px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(10,14,18,.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--surface); border-radius: 14px; padding: 20px; width: min(620px, 100%); max-height: 90vh; overflow: auto; display: grid; gap: 12px; }

/* AWB */
.awb-sec { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 14px; }
.awb-sec h3 { font-size: .95rem; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.fgrid .wide { grid-column: 1 / -1; }
.lock { display: flex; gap: 10px; align-items: center; padding: 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
table.edit td { padding: 4px; }
table.edit input, table.edit select { padding: 5px 6px; }

#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; color: #000; background: #fff; font: 11pt/1.4 var(--sans); }
  #print-area img { max-width: 100%; border: 1px solid #ccc; }
  #print-area table { font-size: 9pt; }
  #print-area th, #print-area td { border-bottom: 1px solid #bbb; color: #000; }
  .pbreak { page-break-before: always; }
  .awb-print { border: 2px solid #000; display: grid; grid-template-columns: 1fr 1fr; font-size: 8.5pt; }
  .awb-print > div { border: 1px solid #000; padding: 4px 6px; min-height: 34px; white-space: pre-wrap; }
  .awb-print .lbl { display: block; font-size: 6.5pt; text-transform: uppercase; color: #333; }
  .awb-print .full { grid-column: 1 / -1; }
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .shipment { position: static; max-height: none; }
  .topbar { gap: 10px; padding: 0 16px; }
  .brand span { display: none; }
  .viewer { height: 340px; }
  .hero h2 { font-size: 1.5rem; }
}
