:root {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --surface-2: #f7faf8;
  --border: #e0e8e4;
  --text: #1b2433;
  --muted: #64748b;
  --primary: #1e5e48;
  --primary-soft: #e4f1eb;
  --side: #123a2d;
  --side-text: #b5cec3;
  --side-active: #1c4a3a;
  --ok: #138a52;
  --ok-soft: #e3f5ec;
  --warn: #b26a00;
  --warn-soft: #fff3df;
  --bad: #c62f3c;
  --bad-soft: #fde8ea;
  --info: #0b7bb5;
  --info-soft: #e2f3fb;
  --violet: #6b46c1;
  --violet-soft: #efe9fb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 60px 1fr;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.mono { font-family: "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- Shell ---------- */
.sidebar {
  grid-row: 1 / 3;
  background: var(--side);
  color: var(--side-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  height: 60px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  color: #fff;
  font-weight: 700;
  letter-spacing: .3px;
  border-bottom: 1px solid #1d4637;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 8px;
  background: #fff;
  display: grid; place-items: center; overflow: hidden; flex: none;
}
.brand-mark img { width: 34px; height: 34px; object-fit: cover; object-position: top; }
.brand small { display: block; font-weight: 400; color: var(--side-text); font-size: 11px; }
.nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: #7fa696; padding: 14px 12px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 8px;
  color: var(--side-text); font-size: 13.5px;
}
.nav a:hover { background: var(--side-active); color: #fff; text-decoration: none; }
.nav a.active { background: #2f7a5f; color: #fff; }
.nav svg { width: 17px; height: 17px; flex: none; }
.side-foot { padding: 14px 20px; border-top: 1px solid #1d4637; font-size: 12px; }
.side-foot button { background: none; border: 0; color: var(--side-text); cursor: pointer; padding: 0; font-size: 12px; text-decoration: underline; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 20;
}
.track {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 0 10px; width: 380px; max-width: 45vw;
}
.track input { border: 0; background: transparent; padding: 9px 0; flex: 1; outline: none; font: inherit; }
.track svg { width: 16px; height: 16px; color: var(--muted); }
.topbar .spacer { flex: 1; }
.role-pick { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.role-pick select { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 600; font-size: 12px; }

main.content { padding: 24px 28px 48px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 6px; }

/* ---------- Cards / grid ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-body { padding: 18px; }
.card + .card, .stack > * + * { margin-top: 16px; }
.grid > .card, .split > .card, .split > .stack { margin-top: 0; }
h1 .mono, h2 .mono { font-size: inherit; }
.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)); }
.g6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; align-items: start; }

.kpi { padding: 16px 18px; display: block; color: inherit; }
.kpi:hover { text-decoration: none; border-color: #c7d2e5; }
.kpi .label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody tr:hover { background: #fafbfd; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.selected { background: var(--primary-soft) !important; }
td input, td select { width: 100%; min-width: 90px; }
td select[name=product] { min-width: 170px; }
td input[name=spec], td input[name=trade] { min-width: 130px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; background: #eef1f5; color: #475569; }
.b-approval { background: var(--warn-soft); color: var(--warn); }
.b-production { background: var(--violet-soft); color: var(--violet); }
.b-qc { background: var(--info-soft); color: var(--info); }
.b-logistics { background: #e5eef4; color: #2f5f80; }
.b-payment { background: #fff0e6; color: #c2410c; }
.b-completed, .b-ok { background: var(--ok-soft); color: var(--ok); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-info { background: var(--info-soft); color: var(--info); }

/* ---------- Buttons / forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-weight: 500; font-size: 13.5px;
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: #174a39; }
.btn-ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn-ok:hover { background: #0f7444; }
.btn-bad { background: var(--surface); color: var(--bad); border-color: #f2c4c8; }
.btn-bad:hover { background: var(--bad-soft); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; filter: grayscale(.6); }
.btn svg { width: 15px; height: 15px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text);
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input[readonly] { background: var(--surface-2); color: var(--muted); }
textarea { resize: vertical; min-height: 64px; }
.section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); margin: 22px 0 10px; padding-bottom: 6px; border-bottom: 1px dashed var(--border); }
.section-title:first-child { margin-top: 0; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; overflow-y: hidden; }
.tab { background: none; border: 0; font: inherit; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Progress / stepper ---------- */
.progress { height: 8px; background: #edf0f5; border-radius: 999px; overflow: hidden; position: relative; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s; }
.progress.ok > span { background: var(--ok); }
.progress .mark { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); left: 95%; }

.stepper { display: flex; align-items: flex-start; gap: 0; overflow-x: auto; padding: 4px 0; }
.step { flex: 1; min-width: 110px; text-align: center; position: relative; font-size: 12.5px; color: var(--muted); }
.step::before { content: ""; position: absolute; top: 15px; left: -50%; right: 50%; height: 2px; background: var(--border); z-index: 0; }
.step:first-child::before { display: none; }
.step .bubble { width: 32px; height: 32px; border-radius: 50%; margin: 0 auto 8px; display: grid; place-items: center; background: var(--surface); border: 2px solid var(--border); position: relative; z-index: 1; font-weight: 600; }
.step.done .bubble { background: var(--ok); border-color: var(--ok); color: #fff; }
.step.done::before, .step.current::before { background: var(--ok); }
.step.current .bubble { border-color: var(--primary); color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.step.current { color: var(--text); font-weight: 600; }
.step small { display: block; font-weight: 400; color: var(--muted); margin-top: 2px; }

.pipeline { display: flex; height: 14px; border-radius: 999px; overflow: hidden; gap: 2px; }
.pipeline span { display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Misc ---------- */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.note { padding: 12px 14px; border-radius: 8px; background: var(--info-soft); color: #075985; font-size: 13px; display: flex; gap: 10px; align-items: flex-start; }
.note.warn { background: var(--warn-soft); color: #7a4a00; }
.note.bad { background: var(--bad-soft); color: #8f1d27; }
.note.ok { background: var(--ok-soft); color: #0b5c37; }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.doc-chip { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: 8px; font-size: 13px; }
.doc-chip.done { border-style: solid; border-color: #b9e3cc; background: var(--ok-soft); }
.delivery { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: var(--surface-2); }
.mini-steps { display: flex; gap: 4px; margin-top: 10px; }
.mini-steps span { flex: 1; text-align: center; font-size: 11px; padding: 5px 2px; border-radius: 6px; background: #e9edf3; color: var(--muted); }
.mini-steps span.done { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.mini-steps span.current { background: var(--primary); color: #fff; font-weight: 600; }

/* ---------- Toast / modal ---------- */
.toast-host { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1b2433; color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); font-size: 13.5px; max-width: 360px; animation: pop .2s ease-out; }
.toast.ok { background: var(--ok); }
.toast.bad { background: var(--bad); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: none; align-items: center; justify-content: center; z-index: 90; padding: 20px; }
.modal-back.open { display: flex; }
.modal { background: var(--surface); border-radius: 12px; width: 640px; max-width: 100%; max-height: 90vh; overflow: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal .card-head { position: sticky; top: 0; background: var(--surface); }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.x { background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--muted); line-height: 1; }

/* ---------- Printable document ---------- */
.doc { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 28px 32px; font-size: 12.5px; color: #111; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #111; padding-bottom: 12px; margin-bottom: 14px; }
.doc-head h2 { font-size: 20px; letter-spacing: 1px; }
.doc { overflow-x: auto; }
.doc table { font-size: 11.5px; }
.doc table th { background: #f1f3f6; color: #111; font-size: 10.5px; }
.doc table th, .doc table td { border: 1px solid #d5dae1; padding: 6px 8px; }
.doc .sign { margin-top: 36px; display: flex; justify-content: space-between; align-items: flex-end; }
.doc .sign div { text-align: center; min-width: 180px; border-top: 1px solid #111; padding-top: 6px; }
.stamp { display: inline-block; border: 2px solid var(--ok); color: var(--ok); padding: 4px 10px; border-radius: 6px; font-weight: 700; transform: rotate(-6deg); font-size: 12px; letter-spacing: 1px; }
.stamp.pending { border-color: var(--warn); color: var(--warn); }

/* ---------- Login ---------- */
body.login-page { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: none; min-height: 100vh; }
.login-hero { background: linear-gradient(160deg, #123a2d 0%, #1e5e48 60%, #3f8f6f 100%); color: #e4f1eb; display: flex; flex-direction: column; justify-content: space-between; padding: 48px; }
.login-hero h1 { color: #fff; font-size: 30px; line-height: 1.25; margin-top: 28px; max-width: 460px; }
.login-hero p { max-width: 440px; line-height: 1.6; opacity: .85; }
.login-hero .logo { background: #fff; border-radius: 12px; padding: 10px; width: 120px; }
.login-hero .logo img { width: 100%; display: block; }
.login-hero ul { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 10px; font-size: 14px; }
.login-hero li::before { content: "✓"; color: #7ab39b; margin-right: 10px; font-weight: 700; }
.login-panel { display: grid; place-items: center; padding: 32px 16px; background: var(--bg); }
.login-card { width: 400px; max-width: 100%; padding: 32px; }
.login-card h2 { font-size: 22px; }
.login-card form { display: grid; gap: 14px; margin-top: 22px; }
.login-card .btn { justify-content: center; padding: 11px 14px; font-size: 15px; }

@media (max-width: 1100px) {
  .g4, .g6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3, .split, .g2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  body { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .track { width: auto; flex: 1; }
  .role-pick span { display: none; }
  main.content { padding: 16px; }
  .form-grid, .form-grid.cols-4 { grid-template-columns: 1fr; }
  body.login-page { grid-template-columns: 1fr; }
  .login-hero { padding: 24px 16px; }
  .span-2 { grid-column: auto; }
}

@media print {
  body { display: block; background: #fff; }
  .sidebar, .topbar, .no-print, .toast-host { display: none !important; }
  main.content { padding: 0; }
  .print-area { display: block !important; }
  .print-area .doc { border: 0; padding: 0; }
  body.printing main.content > *:not(.print-area) { display: none !important; }
}
