:root {
  --ink: #222222;
  --ink-2: #3d3d3d;
  --muted: #6e6a7c;
  --line: #e4e1ec;
  --line-2: #efedf5;
  --bg: #f6f5fa;
  --card: #ffffff;
  --brand: #4b2d8b;
  --brand-dark: #341d66;
  --grey: #c4c4c4;
  --dark-grey: #3d3d3d;
  --tint: #f2f0fa;
  --accent: #4b2d8b;
  --accent-soft: #f2f0fa;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --good: #1f7a4f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(52, 29, 102, .06), 0 1px 3px rgba(52, 29, 102, .05);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.boot { padding: 40px; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%); color: #ddd5ef; padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.logo { padding: 6px 8px 22px; }
.logo img { display: block; height: 34px; width: auto; }
.logo .app { color: #fff; font-weight: 650; font-size: 13px; margin-top: 10px; letter-spacing: .02em; }
.logo .app small { display: block; font-weight: 400; color: #cbbfe8; font-size: 11px; letter-spacing: 0; }
.tagline { font-size: 10.5px; letter-spacing: .05em; text-transform: uppercase; color: #cbbfe8; padding: 10px 10px 0; line-height: 1.4; }
.nav a { display: flex; align-items: center; gap: 10px; color: #ddd5ef; padding: 9px 10px; border-radius: 8px; font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; color: #fff; }
.nav a.on { background: rgba(255, 255, 255, .14); color: #fff; box-shadow: inset 3px 0 0 var(--grey); }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.side .me { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255, 255, 255, .14); font-size: 12px; }
.side .me b { color: #fff; display: block; font-weight: 600; }
.side .me a { color: #e6dcff; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.main { padding: 24px 28px 60px; min-width: 0; max-width: 1280px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head .sub { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.topbar { display: none; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 18px 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi { padding: 16px 18px; }
.kpi .l { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi .v { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .s { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--dark-grey); font-weight: 650; background: var(--tint); position: sticky; top: 0; }
tbody tr:hover { background: #faf9fd; }
tr.click { cursor: pointer; }
td.item-name { max-width: 420px; }
tfoot td { font-weight: 650; border-top: 1px solid var(--line); background: var(--tint); }

/* chips */
.chip { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.chip.up { background: var(--bad-soft); color: var(--bad); }
.chip.down { background: #e6f4ec; color: var(--good); }
.chip.pdr { background: var(--brand); color: #fff; font-size: 10px; letter-spacing: .04em; padding: 1px 6px; }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.ok { background: #e6f4ec; color: var(--good); }

/* forms */
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
label .hint { font-weight: 400; color: var(--muted); }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); border: 1px solid #d4d0de; border-radius: 8px; padding: 8px 10px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(75, 45, 139, .16); }
input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }
.field { margin-bottom: 12px; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 14px; }
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; border-radius: 8px; padding: 8px 14px; border: 1px solid #d4d0de; background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--tint); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.search { position: relative; max-width: 520px; }
.search input { padding-left: 34px; height: 40px; }
.search svg { position: absolute; left: 11px; top: 11px; width: 18px; height: 18px; color: var(--muted); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; }

/* shipment form */
.lines-tbl input { padding: 6px 8px; }
.lines-tbl td { padding: 6px 6px; vertical-align: middle; }
.lines-tbl th { padding: 8px 6px; }
.lines-tbl .calc { color: var(--ink-2); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; font-size: 13px; }
.lines-tbl .calc b { color: var(--ink); }
.del { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; padding: 2px 6px; border-radius: 6px; }
.del:hover { color: var(--bad); background: var(--bad-soft); }
.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.summary { position: sticky; top: 16px; }
.summary .row { display: flex; justify-content: space-between; padding: 5px 0; font-variant-numeric: tabular-nums; }
.summary .row.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-weight: 700; font-size: 15px; }
.note { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: #7a3d06; font-size: 12.5px; margin-top: 10px; }
.note.info { background: var(--tint); color: var(--brand-dark); }
.note.bad { background: var(--bad-soft); color: var(--bad); }
.err { white-space: pre-line; }

/* breakdown */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1100px 600px at 15% -10%, #6a4bb0 0%, var(--brand) 45%, var(--brand-dark) 100%); }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login .card { border-top: 4px solid var(--brand); }
.login .logo { padding: 0 0 18px; }
.login .logo img { height: 40px; }
.login .logo .app { color: var(--ink); font-size: 15px; }
.login .logo .app small { color: var(--muted); }
.login .foot { margin: 18px -28px -28px; padding: 10px 16px; background: var(--dark-grey); color: var(--grey); font-size: 10px; font-weight: 700; letter-spacing: .03em; text-align: center; border-radius: 0 0 var(--radius) var(--radius); }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--brand-dark); color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; font-weight: 500; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--ink); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.chart-box { position: relative; height: 260px; }
.modal-bg { position: fixed; inset: 0; background: rgba(52, 29, 102, .45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { background: #fff; border-radius: 12px; padding: 22px; width: 100%; max-width: 440px; box-shadow: 0 20px 50px rgba(0, 0, 0, .2); }
.pw { font-family: var(--mono); font-size: 16px; background: var(--line-2); padding: 8px 12px; border-radius: 8px; display: inline-block; user-select: all; }

@media (max-width: 1000px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-layout { grid-template-columns: 1fr; }
  .summary { position: static; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .side.open { display: flex; position: fixed; inset: 0 30% 0 0; z-index: 30; height: 100%; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .topbar { display: flex; align-items: center; justify-content: space-between; background: var(--brand); color: #fff; padding: 10px 14px; position: sticky; top: 0; z-index: 20; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .topbar img { height: 22px; display: block; }
  .main { padding: 16px 14px 60px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  h1 { font-size: 19px; }
  th, td { padding: 8px 9px; }
  .hide-sm { display: none; }
  .lines-tbl, .lines-tbl tbody, .lines-tbl tr, .lines-tbl td { display: block; width: 100%; }
  .lines-tbl thead { display: none; }
  .lines-tbl tr { border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .lines-tbl td { border: 0; padding: 0; }
  .lines-tbl td[data-l]::before { content: attr(data-l); display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
  .lines-tbl td.wide { grid-column: 1 / -1; }
}
@media print {
  .side, .topbar, .actions, .btn { display: none !important; }
  .shell { display: block; }
  .card { box-shadow: none; break-inside: avoid; }
}


/* ---------- factory additions ---------- */
.chip.urgent { background: var(--bad); color: #fff; }
.chip.late { background: var(--bad-soft); color: var(--bad); }
.chip.soon { background: var(--warn-soft); color: var(--warn); }
.chip.st-open { background: var(--warn-soft); color: var(--warn); }
.chip.st-accepted { background: var(--tint); color: var(--brand); }
.chip.st-completed { background: #e6f4ec; color: var(--good); }
.chip.st-cancelled { background: var(--line-2); color: var(--muted); text-decoration: line-through; }
.chip.mr-open { background: var(--warn-soft); color: var(--warn); }
.chip.mr-ordered { background: var(--tint); color: var(--brand); }
.chip.mr-received { background: #e6f4ec; color: var(--good); }
.chip.mr-cancelled { background: var(--line-2); color: var(--muted); }
.bar { height: 8px; background: var(--line-2); border-radius: 99px; overflow: hidden; min-width: 70px; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.bar.done > i { background: var(--good); }
.prog { display: flex; align-items: center; gap: 8px; }
.prog .bar { flex: 1; }
.prog span { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.seg { display: inline-flex; border: 1px solid #d4d0de; border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-weight: 700; font-size: 12.5px; border: 0; border-right: 1px solid #d4d0de; background: #fff; padding: 7px 0; width: 40px; cursor: pointer; color: var(--muted); }
.seg button:last-child { border-right: 0; }
.seg button.on[data-v=P] { background: var(--good); color: #fff; }
.seg button.on[data-v=H] { background: #6d9b3a; color: #fff; }
.seg button.on[data-v=A] { background: var(--bad); color: #fff; }
.seg button.on[data-v=L] { background: var(--warn); color: #fff; }
.seg button.on[data-v=OD] { background: var(--brand); color: #fff; }
.att-row { display: grid; grid-template-columns: minmax(140px, 1fr) auto 80px minmax(160px, 1.2fr); gap: 10px; align-items: center; padding: 9px 14px; border-bottom: 1px solid var(--line-2); }
.att-row input { padding: 6px 8px; }
.att-row .nm b { display: block; }
.att-head { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--dark-grey); font-weight: 650; background: var(--tint); }
.datebar { display: flex; gap: 6px; align-items: center; }
.datebar input { width: auto; }
.alerts .note { margin: 0 0 10px; display: flex; gap: 8px; align-items: center; }
.grid-steps td, .grid-steps th { padding: 6px 10px; }
.grid-steps td.z { color: var(--line); }
.hbar { display: grid; grid-template-columns: minmax(120px, 210px) 1fr 50px; gap: 10px; align-items: center; padding: 4px 0; font-size: 13px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 4px 14px; }
.checks label { display: flex; gap: 8px; align-items: center; font-weight: 500; font-size: 13px; color: var(--ink); margin: 0; padding: 4px 0; }
.checks input { width: auto; }
.kpi.red { border-left: 4px solid var(--bad); }
.kpi.amber { border-left: 4px solid var(--warn); }
@media (max-width: 760px) {
  .att-row { grid-template-columns: 1fr auto; }
  .att-row .ot, .att-row .nt { grid-column: span 1; }
  .att-head { display: none; }
  .hbar { grid-template-columns: 110px 1fr 40px; }
}
.field { min-width: 0; }
.seg { justify-self: start; }
.show-sm { display: none; }
@media (max-width: 760px) {
  .fgrid { grid-template-columns: 1fr 1fr; }
  .fgrid .field[style*="span 2"] { grid-column: 1 / -1 !important; }
  .show-sm { display: block; }
  .datebar input { max-width: 150px; }
}
.spec-row { display: flex; gap: 6px; margin-top: 6px; }
.spec-row select { flex: 1.4; } .spec-row input { flex: 1; }
.lines-tbl select { min-width: 74px; }
@media print { .side, .topbar, .datebar, .actions { display: none !important; } .main { padding: 0; } .card { box-shadow: none; break-inside: avoid; } }
