:root {
  --orange: #f26a1b;
  --orange-soft: #fff1e8;
  --navy: #111827;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f6f7f9;
  --card: #ffffff;
  --green: #15803d;
  --red: #b91c1c;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
h2 { margin: 0 0 12px; font-size: 20px; }
h3 { margin: 18px 0 8px; font-size: 15px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--navy); color: #fff; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: .5px; }
.brand img { width: 34px; height: 34px; border-radius: 50%; background: #fff; }
.brand span { font-weight: 400; color: #fbbf8a; }
#tabs { display: flex; gap: 4px; flex-wrap: wrap; }
#tabs button { background: transparent; color: #d1d5db; border: 0; padding: 8px 12px; border-radius: 6px; cursor: pointer; font: inherit; }
#tabs button.active { background: var(--orange); color: #fff; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.row-between h2 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

button, .btn { font: inherit; padding: 7px 12px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; display: inline-block; }
button:hover, .btn:hover { border-color: var(--orange); }
button.primary { background: var(--orange); border-color: var(--orange); color: #fff; font-weight: 600; }
button.danger { color: var(--red); }
button.sm { padding: 3px 8px; font-size: 12px; }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 6px; background: #fff; width: 100%; color: inherit; }
.actions input, .actions select { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--orange-soft); border-color: var(--orange); }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
label.chk { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); }
label.chk input { width: auto; }
.actions label { flex-direction: row; align-items: center; gap: 6px; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; white-space: nowrap; }
th { background: #f9fafb; font-size: 12px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 160px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--orange-soft); }
tfoot td { font-weight: 700; background: #f9fafb; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: #eef2ff; color: #3730a3; }
.badge.s0 { background: #f3f4f6; color: #374151; }
.badge.s1 { background: #fef3c7; color: #92400e; }
.badge.s2 { background: #dcfce7; color: #166534; }
.badge.s3 { background: #dbeafe; color: #1e40af; }
.badge.s4 { background: #e0e7ff; color: #3730a3; }
.badge.s5 { background: #fae8ff; color: #86198f; }
.badge.s6 { background: #d1fae5; color: #065f46; }
.badge.s7 { background: #fee2e2; color: #991b1b; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.card .k { font-size: 12px; color: var(--muted); }
.card .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.card .s { font-size: 12px; color: var(--muted); }
.card.accent { border-top: 3px solid var(--orange); }

dialog { border: 0; border-radius: 10px; padding: 0; width: min(920px, 96vw); max-height: 94vh; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(17,24,39,.5); }
#orderForm { padding: 18px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin: 10px 0; }
.span2 { grid-column: span 2; }
@media (max-width: 520px) { .span2 { grid-column: span 1; } }
table.cartons input { min-width: 60px; }
table.cartons td { padding: 3px; border: 0; }
.calc { background: var(--orange-soft); border: 1px solid #fed7aa; border-radius: 8px; padding: 10px 14px; margin-top: 12px; }
.calc table td { border: 0; padding: 2px 6px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 16px; position: sticky; bottom: 0; background: #fff; padding-top: 8px; }
.spacer { flex: 1; }

.settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.settings h4 { grid-column: 1 / -1; margin: 8px 0 0; color: var(--navy); }
.settings .full { grid-column: 1 / -1; }

.sync { margin-left: auto; font-size: 12px; padding: 3px 10px; border-radius: 99px; background: rgba(255,255,255,.1); color: #d1d5db; }
.sync.ok { color: #86efac; }
.sync.busy { color: #fde68a; }
.sync.err { background: #7f1d1d; color: #fff; }
.sync:empty { display: none; }
dialog.pin { width: min(340px, 92vw); text-align: center; }
dialog.pin form { padding: 24px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
dialog.pin h2 { margin: 0; }
dialog.pin input { text-align: center; font-size: 20px; letter-spacing: 6px; }
.err { color: var(--red); min-height: 1em; margin: 0; }

/* ---------- Printable document ---------- */
.doc-view { position: fixed; inset: 0; z-index: 20; overflow: auto; background: #e5e7eb; }
.doc-toolbar { position: sticky; top: 0; display: flex; gap: 8px; padding: 10px 16px; background: var(--navy); }
.doc-page { width: 210mm; min-height: 297mm; margin: 16px auto; background: #fff; padding: 14mm 14mm; color: #111; font-size: 12px; box-shadow: 0 4px 20px rgba(0,0,0,.15); }
.doc-head { display: flex; justify-content: space-between; gap: 16px; border-bottom: 3px solid var(--orange); padding-bottom: 10px; }
.doc-co { display: flex; gap: 12px; align-items: flex-start; }
.doc-co img { width: 78px; height: 78px; }
.doc-co .name { font-size: 17px; font-weight: 800; color: var(--navy); }
.doc-co div { line-height: 1.4; }
.doc-title { text-align: right; }
.doc-title h1 { margin: 0 0 6px; font-size: 26px; color: var(--orange); letter-spacing: 2px; }
.doc-title table td { padding: 1px 0 1px 10px; border: 0; white-space: nowrap; }
.doc-title table td:first-child { color: #555; }
.doc-sec { margin-top: 14px; }
.doc-sec h5 { margin: 0 0 4px; font-size: 11px; letter-spacing: 1px; color: var(--orange); border-bottom: 1px solid #ddd; padding-bottom: 2px; }
.doc-two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.doc-items th { background: var(--navy); color: #fff; font-size: 11px; }
.doc-items td, .doc-items th { padding: 6px 8px; white-space: normal; }
.doc-totals { width: 46%; margin-left: auto; margin-top: 6px; }
.doc-totals td { padding: 4px 8px; border: 0; }
.doc-totals tr.grand td { background: var(--orange); color: #fff; font-weight: 800; font-size: 13px; }
.doc-terms ol { margin: 4px 0; padding-left: 18px; }
.doc-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-top: 22px; }
.doc-sign .line { margin-top: 36px; border-top: 1px solid #333; padding-top: 3px; }
.doc-foot { margin-top: 18px; text-align: center; color: #555; font-style: italic; }

@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  .no-print, .no-print * { display: none !important; }
  .doc-view { position: static; overflow: visible; background: #fff; }
  .doc-page { margin: 0; box-shadow: none; width: auto; min-height: auto; }
  .doc-items th, .doc-totals tr.grand td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body.print-kom main.no-print, body.print-kom main.no-print * { display: revert !important; }
  body.print-kom .tab:not(#tab-komisen), body.print-kom #tab-komisen .actions { display: none !important; }
  body.print-kom main { padding: 10mm; }
}
