:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #17202b;
  --ink-2: #4a5565;
  --ink-3: #8a94a3;
  --line: #e3e6eb;
  --line-2: #eef0f3;
  --brand: #262673;
  --brand-ink: #ffffff;
  --brand-soft: #eef0fb;
  --gold: #f9ae00;
  --gold-ink: #8a5f00;
  --gold-soft: #fff4d6;
  --nav: #262673;
  --focus: #2563eb;

  --s-sent: #64748b;      --s-sent-bg: #eef1f5;
  --s-recv: #2563eb;      --s-recv-bg: #e7efff;
  --s-prod: #7c3aed;      --s-prod-bg: #f1eafe;
  --s-hold: #c2410c;      --s-hold-bg: #ffeddf;
  --s-done: #0f766e;      --s-done-bg: #dcf5f1;
  --s-deliv: #15803d;     --s-deliv-bg: #e2f6e8;
  --s-canc: #9ca3af;      --s-canc-bg: #f3f4f6;
  --danger: #c62828;      --danger-bg: #fdecec;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .18);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--focus); }
.boot { padding: 80px; text-align: center; color: var(--ink-3); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 550; white-space: nowrap; }
.btn:hover { background: #f8f9fb; border-color: #d3d8df; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: #1c1c5a; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.input, select.input, textarea.input { width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; outline: none; }
textarea.input { height: auto; padding: 8px 10px; resize: vertical; min-height: 70px; }
.input:focus { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
.input[readonly], .input:disabled { background: #f6f7f9; color: var(--ink-2); }
label.f { display: block; }
label.f > span { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
label.f > span i { color: var(--danger); font-style: normal; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 10% -10%, #e3e5f7 0%, transparent 60%), radial-gradient(800px 400px at 110% 110%, #fff1cc 0%, transparent 60%), var(--bg); }
.login-logo { height: 46px; display: block; margin-bottom: 6px; }
.login { width: 100%; max-width: 380px; background: var(--panel); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 32px; }
.login h1 { font-size: 20px; margin: 16px 0 4px; }
.login p { margin: 0 0 22px; color: var(--ink-2); }
.login form { display: grid; gap: 14px; }
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.logo .mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; color: #fff; font-weight: 800; }
.err { color: var(--danger); background: var(--danger-bg); border-radius: 8px; padding: 8px 10px; font-size: 13px; }

/* ---------- layout ---------- */
.topbar { position: sticky; top: 0; z-index: 20; height: 56px; background: var(--nav); color: #e7ebf0;
  display: flex; align-items: center; gap: 16px; padding: 0 20px; }
.topbar .logo { color: #fff; text-decoration: none; display: flex; align-items: center; gap: 12px; }
.topbar .logo img { height: 26px; display: block; }
.topbar .logo .app { font-weight: 600; color: #fff; padding-left: 12px; border-left: 1px solid rgba(255,255,255,.25); line-height: 22px; }
.topbar .logo small { font-weight: 500; color: #9aa6b5; margin-left: 4px; }
.topbar nav { display: flex; gap: 4px; margin-left: 12px; }
.topbar nav a { color: #c9cce8; text-decoration: none; padding: 7px 12px; border-radius: 7px; font-weight: 550; }
.topbar nav a.on, .topbar nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.topbar .sp { flex: 1; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #9aa6b5; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #6b7280; display: inline-block; }
.live.on i { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.2); }
.userchip { display: flex; align-items: center; gap: 10px; }
.userchip .who { text-align: right; line-height: 1.15; }
.userchip .who b { display: block; color: #fff; font-weight: 600; }
.userchip .who span { font-size: 11px; color: #9aa6b5; text-transform: uppercase; letter-spacing: .04em; }
.topbar .btn.ghost { color: #cbd3dd; }
.topbar .btn.ghost:hover { background: rgba(255,255,255,.08); }
main { padding: 20px; max-width: 1680px; margin: 0 auto; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  cursor: pointer; text-align: left; position: relative; transition: border-color .12s, box-shadow .12s; }
.kpi:hover { border-color: #cfd5dd; box-shadow: var(--shadow); }
.kpi.on { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.kpi .lab { font-size: 12px; color: var(--ink-2); font-weight: 550; display: flex; align-items: center; gap: 6px; }
.kpi .lab i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.kpi .val { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.kpi .sub { font-size: 11px; color: var(--ink-3); }
.kpi.alert .val { color: var(--danger); }

/* ---------- toolbar ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.toolbar { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; background: #f0f2f5; padding: 3px; border-radius: 9px; }
.tabs button { border: 0; background: transparent; height: 28px; padding: 0 12px; border-radius: 7px; cursor: pointer; font-weight: 550; color: var(--ink-2); }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.tabs button .c { font-size: 11px; color: var(--ink-3); margin-left: 4px; }
.search { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.search input { padding-left: 32px; }
.search svg { position: absolute; left: 10px; top: 10px; color: var(--ink-3); }
.toolbar .sp { flex: 1; }
.bulkbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--gold-soft); border-bottom: 1px solid #f3dc9c; }

/* ---------- table ---------- */
.tablewrap { overflow: auto; max-height: calc(100vh - 290px); }
table.orders { width: 100%; border-collapse: separate; border-spacing: 0; }
table.orders th { position: sticky; top: 0; background: #fafbfc; z-index: 1; text-align: left; font-size: 11.5px; font-weight: 650;
  color: var(--ink-2); text-transform: uppercase; letter-spacing: .03em; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.orders td { padding: 9px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; white-space: nowrap; }
table.orders tbody tr { cursor: pointer; }
table.orders tbody tr:hover td { background: #fafbfd; }
table.orders tbody tr.sel td { background: var(--brand-soft); }
table.orders tbody tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: #fff1c2; } to { background: transparent; } }
td.r, th.r { text-align: right; }
td.rem { max-width: 260px; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.ono { font-weight: 650; }
.so { color: var(--ink-2); font-size: 12px; }
.chip { display: inline-block; padding: 1px 7px; border-radius: 5px; font-size: 11.5px; font-weight: 600; background: #eef1f5; color: var(--ink-2); }
.chip.new { background: #e7efff; color: #1d4ed8; }
.chip.urgent { background: var(--danger-bg); color: var(--danger); }
.overdue { color: var(--danger); font-weight: 650; }
.cb { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
.empty { padding: 60px 20px; text-align: center; color: var(--ink-3); }
.prog { display: flex; align-items: center; gap: 6px; }
.prog .bar { width: 46px; height: 5px; border-radius: 3px; background: #edf0f3; overflow: hidden; }
.prog .bar i { display: block; height: 100%; background: var(--s-done); }

/* status pill */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 11px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-SENT { color: var(--s-sent); background: var(--s-sent-bg); }
.st-RECEIVED { color: var(--s-recv); background: var(--s-recv-bg); }
.st-IN_PRODUCTION { color: var(--s-prod); background: var(--s-prod-bg); }
.st-ON_HOLD { color: var(--s-hold); background: var(--s-hold-bg); }
.st-COMPLETED { color: var(--s-done); background: var(--s-done-bg); }
.st-DELIVERED { color: var(--s-deliv); background: var(--s-deliv-bg); }
.st-CANCELLED { color: var(--s-canc); background: var(--s-canc-bg); }

/* ---------- drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(15, 23, 32, .35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--panel); z-index: 41;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slidein .18s ease-out; }
@keyframes slidein { from { transform: translateX(30px); opacity: .5; } to { transform: none; opacity: 1; } }
.drawer header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; gap: 12px; }
.drawer header h2 { margin: 0; font-size: 18px; }
.drawer header .meta { color: var(--ink-2); font-size: 13px; margin-top: 3px; }
.drawer .body { flex: 1; overflow: auto; padding: 18px 20px 30px; }
.drawer h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); margin: 22px 0 10px; }
.drawer h3:first-child { margin-top: 0; }
.facts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.facts div { background: #fff; padding: 9px 11px; min-width: 0; }
.facts dt { font-size: 11px; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.facts dd { margin: 2px 0 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline { display: flex; gap: 0; margin: 4px 0 0; }
.timeline .stp { flex: 1; position: relative; padding-top: 18px; font-size: 11.5px; color: var(--ink-3); }
.timeline .stp::before { content: ""; position: absolute; top: 5px; left: 0; right: 0; height: 2px; background: var(--line); }
.timeline .stp::after { content: ""; position: absolute; top: 0; left: 0; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid #cfd5dd; }
.timeline .stp.done { color: var(--ink-2); }
.timeline .stp.done::before { background: var(--s-done); }
.timeline .stp.done::after { background: var(--s-done); border-color: var(--s-done); }
.timeline .stp b { display: block; color: var(--ink); font-weight: 600; }
.updatebox { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: #fcfcfd; }
.statusbtns { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.statusbtns button { border: 1px solid var(--line); background: #fff; border-radius: 8px; height: 32px; padding: 0 12px; cursor: pointer; font-weight: 600; font-size: 13px; }
.statusbtns button.on { border-color: currentColor; box-shadow: inset 0 0 0 1px currentColor; }
.statusbtns button:disabled { opacity: .4; cursor: not-allowed; }

/* remarks thread */
.thread { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 9px 12px; border-radius: 12px; background: #f1f3f6; align-self: flex-start; }
.msg.me { align-self: flex-end; background: var(--brand-soft); }
.msg .h { font-size: 11.5px; color: var(--ink-3); margin-bottom: 3px; }
.msg .h b { color: var(--ink-2); }
.msg .t { white-space: pre-wrap; word-break: break-word; }
.sys { align-self: center; font-size: 12px; color: var(--ink-3); text-align: center; }
.composer { display: flex; gap: 8px; margin-top: 12px; }
.composer textarea { min-height: 42px; height: 42px; }
.hist { width: 100%; border-collapse: collapse; font-size: 13px; }
.hist td { padding: 6px 8px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.hist .old { color: var(--ink-3); text-decoration: line-through; }

/* ---------- modal ---------- */
.modal { position: fixed; z-index: 50; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(15, 23, 32, .4); }
.modal .box { background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 640px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; }
.modal .box.wide { max-width: 1200px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal header h2 { font-size: 17px; margin: 0; flex: 1; }
.modal .body { padding: 18px 20px; overflow: auto; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.modal footer .sp { flex: 1; }
.preview { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.preview th, .preview td { padding: 6px 8px; border-bottom: 1px solid var(--line-2); text-align: left; white-space: nowrap; }
.preview th { background: #fafbfc; position: sticky; top: 0; }
.preview tr.bad td { background: var(--danger-bg); }
.preview tr.warn td { background: #fff8e6; }
.maprow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.note { background: #f6f8fb; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color: var(--ink-2); font-size: 13px; }

/* ---------- admin ---------- */
.admin-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.card > header { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.card > header h2 { font-size: 15px; margin: 0; flex: 1; }
.card .body { padding: 14px 16px; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 11.5px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .03em; padding: 8px 12px; border-bottom: 1px solid var(--line); }
table.list td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); }
table.list tr.off td { color: var(--ink-3); }
.rowline { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line-2); }
.rowline span { flex: 1; }

/* ---------- toast ---------- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60; background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 9px; box-shadow: var(--shadow-lg); font-weight: 550; max-width: 90vw; }
.toast.error { background: var(--danger); }

/* ---------- mobile ---------- */
.cards { display: none; }
@media (max-width: 1400px) { .kpis { grid-template-columns: repeat(5, 1fr); } }
@media (max-width: 860px) {
  main { padding: 12px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar .logo small, .userchip .who, .live span { display: none; }
  .topbar nav { margin-left: 0; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi .val { font-size: 22px; }
  .tablewrap { display: none; }
  .cards { display: block; }
  .ocard { padding: 12px; border-bottom: 1px solid var(--line-2); display: grid; gap: 6px; }
  .ocard .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
  .ocard .mid { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--ink-2); font-size: 13px; }
  .facts { grid-template-columns: repeat(2, 1fr); }
  .grid2, .grid3, .maprow { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: auto; }
  .admin-grid { grid-template-columns: 1fr; }
  .search { max-width: none; }
}

/* polish */
.kpi .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs button { white-space: nowrap; }
table.orders td { font-size: 13.5px; }
td.rem { max-width: 220px; }
@media (max-width: 860px) {
  .tabs { overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .toolbar > .tabs { flex: 1 1 100%; }
}

/* Alubond / warehouse additions */
.chip.gold { background: var(--gold-soft); color: var(--gold-ink); }
.facts .wide { grid-column: 1 / -1; }
.facts dd.wrap { white-space: normal; font-weight: 550; }
.drumbox { border-color: #f3dc9c; background: #fffcf3; }
@media (max-width: 860px) {
  .topbar .logo img { height: 20px; }
  .topbar .logo .app { display: none; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
.logochip { background: #fff; border-radius: 7px; padding: 5px 9px; display: inline-flex; align-items: center; }
.logochip img { height: 22px !important; }
.kpi .lab { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search { min-width: 170px; max-width: 280px; }
@media (max-width: 860px) { .logochip img { height: 18px !important; } .search { max-width: none; } }
