:root {
  --bg: #f3f5f9; --card: #fff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --primary: #1d4ed8; --primary-2: #1e40af; --primary-soft: #e0e7ff;
  --green: #15803d; --green-soft: #dcfce7; --red: #b91c1c; --red-soft: #fee2e2;
  --orange: #c2410c; --orange-soft: #ffedd5; --teal: #0f766e; --teal-soft: #ccfbf1;
  --blue: #1d4ed8; --blue-soft: #dbeafe; --gray-soft: #f1f5f9; --dark: #334155;
  --radius: 12px; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 1px 8px rgba(15,23,42,.04);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
body.noscroll { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h3 { font-size: 1.02rem; } h4 { font-size: .92rem; margin-top: 1rem; color: var(--dark); }
small, .muted { color: var(--muted); }
.hidden { display: none !important; }
.txt-red { color: var(--red); } .txt-teal { color: var(--teal); } .txt-green { color: var(--green); } .txt-orange { color: var(--orange); }
.right { text-align: right; } .nowrap { white-space: nowrap; }

/* layout */
#app { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 236px; background: #0f172a; color: #cbd5e1; padding: 16px 12px; overflow-y: auto; z-index: 40; transition: transform .2s; }
.sidebar .brand { color: #fff; font-weight: 700; font-size: 1.05rem; padding: 4px 10px 14px; display: flex; gap: 8px; align-items: center; }
.sidebar .brand span { font-size: 1.4rem; }
.sidebar a, .sidebar button.navlink { display: flex; align-items: center; gap: 10px; color: #cbd5e1; padding: 10px 12px; border-radius: 9px; margin: 2px 0; width: 100%; background: none; border: 0; font: inherit; cursor: pointer; text-align: left; }
.sidebar a:hover, .sidebar button.navlink:hover { background: #1e293b; color: #fff; }
.sidebar a.active { background: var(--primary); color: #fff; }
.sidebar .sep { height: 1px; background: #1e293b; margin: 10px 4px; }
.topbar { position: sticky; top: 0; z-index: 30; background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; align-items: center; gap: 10px; margin-left: 236px; }
.topbar h1 { font-size: 1.1rem; margin: 0; flex: 1; }
.topbar .menu-btn { display: none; }
main { margin-left: 236px; padding: 16px; max-width: 1180px; }
.bottomnav { display: none; }
.drawer-bg { display: none; }

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); width: 260px; }
  body.drawer .sidebar { transform: none; }
  body.drawer .drawer-bg { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 35; }
  .topbar, main { margin-left: 0; }
  .topbar .menu-btn { display: inline-flex; }
  main { padding: 12px 12px 88px; }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a, .bottomnav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px; font-size: .72rem; color: var(--muted); background: none; border: 0; font-family: inherit; cursor: pointer; }
  .bottomnav .ic { font-size: 1.25rem; line-height: 1; }
  .bottomnav a.active { color: var(--primary); font-weight: 600; }
}

/* komponen */
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 14px; }
.panel > h3 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; cursor: pointer; border: 1px solid transparent; display: block; color: inherit; }
.card:hover { border-color: var(--primary-soft); }
.card .lbl { font-size: .8rem; color: var(--muted); }
.card .val { font-size: 1.35rem; font-weight: 700; margin-top: 2px; }
.card .sub { font-size: .78rem; color: var(--muted); }
.card.warn .val { color: var(--orange); } .card.danger .val { color: var(--red); } .card.ok .val { color: var(--green); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; gap: 0; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; min-height: 40px; white-space: nowrap; }
.btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.danger:hover { background: var(--red-soft); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-icon { border: 0; background: none; font-size: 1.05rem; cursor: pointer; padding: 6px 9px; border-radius: 8px; color: var(--muted); font-family: inherit; }
.btn-icon:hover { background: var(--gray-soft); }
.btn-icon.danger:hover { color: var(--red); background: var(--red-soft); }
.actions, .quick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
@media (max-width: 560px) { .quick .btn { flex: 1 1 calc(50% - 8px); } }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; align-items: center; }
.toolbar input[type=search] { flex: 1 1 220px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; scrollbar-width: none; }
.tabs button { flex: none; border: 1px solid var(--line); background: var(--card); padding: 7px 13px; border-radius: 999px; font: inherit; font-size: .88rem; cursor: pointer; color: var(--dark); }
.tabs button.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.tabs button .n { background: rgba(0,0,0,.08); border-radius: 999px; padding: 0 7px; margin-left: 4px; font-size: .78rem; }

input, select, textarea { font: inherit; color: inherit; border: 1px solid #cbd5e1; border-radius: 9px; padding: 9px 11px; background: #fff; width: 100%; min-height: 40px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
label { display: block; font-size: .85rem; color: var(--dark); font-weight: 500; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
.form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 12px; }
.form .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form { grid-template-columns: 1fr; } }
.chk { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; font-size: .9rem; white-space: nowrap; }
.chk input { width: 18px; min-height: 18px; height: 18px; margin: 0; }
.radio-group { display: grid; gap: 6px; }
.radio { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; font-weight: 400; }
.radio input { width: 18px; min-height: 18px; height: 18px; margin: 2px 0 0; flex: none; }
.radio:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.hint { font-size: .8rem; color: var(--muted); margin: 2px 0 0; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
@media (max-width: 560px) { .form-actions .btn { flex: 1; } }

/* daftar */
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.item:last-child { border-bottom: 0; }
.item.click { cursor: pointer; } .item.click:hover { background: #f8fafc; }
.item-main { flex: 1; min-width: 0; }
.item-main > b { display: block; overflow-wrap: anywhere; }
.item-main small { display: block; }
.item-side { text-align: right; flex: none; max-width: 48%; }
.item-side b, .item-side small { display: block; }
.chips { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: .8rem; color: var(--dark); }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.loading { text-align: center; color: var(--muted); padding: 40px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; background: var(--gray-soft); color: var(--dark); }
.b-green { background: var(--green-soft); color: var(--green); } .b-red { background: var(--red-soft); color: var(--red); }
.b-orange { background: var(--orange-soft); color: var(--orange); } .b-blue { background: var(--blue-soft); color: var(--blue); }
.b-teal { background: var(--teal-soft); color: var(--teal); } .b-dark { background: #334155; color: #fff; }

table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th, .tbl td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: .78rem; color: var(--muted); font-weight: 600; }
.tbl td.num, .tbl th.num { text-align: right; white-space: nowrap; }
.tbl tfoot td { font-weight: 700; border-bottom: 0; }
.scroll-x { overflow-x: auto; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.plate { display: inline-block; font-weight: 800; letter-spacing: .5px; font-size: 1.25rem; background: #0f172a; color: #fff; padding: 3px 12px; border-radius: 7px; border: 2px solid #0f172a; box-shadow: inset 0 0 0 2px #fff; }
.plate.sm { font-size: .95rem; padding: 1px 8px; }

/* langkah status */
.steps { display: flex; gap: 4px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.steps::-webkit-scrollbar { display: none; }
.step { flex: 1 0 74px; text-align: center; font-size: .72rem; color: var(--muted); position: relative; }
.step .dot { width: 26px; height: 26px; border-radius: 50%; background: var(--gray-soft); border: 2px solid var(--line); margin: 0 auto 4px; display: flex; align-items: center; justify-content: center; font-size: .75rem; font-weight: 700; }
.step.done .dot { background: var(--green); border-color: var(--green); color: #fff; }
.step.now .dot { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 0 0 4px var(--primary-soft); }
.step.now { color: var(--text); font-weight: 600; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 0 0 10px 18px; border-left: 2px solid var(--line); margin-left: 6px; position: relative; font-size: .88rem; }
.timeline li::before { content: ''; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); }

/* editor baris barang */
.line { border: 1px solid var(--line); border-radius: 10px; padding: 9px; margin-bottom: 8px; background: #fbfcfe; display: grid; gap: 7px; }
.line-top { display: flex; gap: 7px; }
.line-top select { flex: 0 0 130px; }
.line-nums { display: flex; gap: 7px; align-items: flex-end; }
.line-nums label { flex: 1; font-size: .75rem; }
.line-nums label.qty { flex: 0 0 90px; }
.line .sub { font-size: .78rem; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
/* editor baris: satu baris per barang */
.le { --cols: minmax(240px, 1fr) 112px 48px 68px 116px 108px 32px; }
.le-servis { --cols: 122px minmax(240px, 1fr) 112px 48px 68px 116px 108px 32px; }
.le-transfer { --cols: minmax(240px, 1fr) 130px 56px 76px 32px; }
.le-head, .le-line { display: grid; grid-template-columns: var(--cols); gap: 8px; align-items: center; }
.le-head { font-size: .74rem; color: var(--muted); font-weight: 600; padding: 0 10px 4px; }
.le-head .r, .le-line .c-stk, .le-line .c-sub { text-align: right; }
.le-line { margin-bottom: 6px; padding: 7px 10px; }
.le-line .c-pn { font-size: .85rem; font-weight: 600; color: var(--dark); overflow-wrap: anywhere; }
.le-line .c-stk { font-size: .9rem; cursor: help; }
.le-line .c-sub { font-size: .9rem; white-space: nowrap; }
.le-line input, .le-line select { min-height: 38px; padding: 7px 9px; }
.le-line .c-qty, .le-line .c-price { text-align: right; }
.le-foot { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.le-foot .le-total { margin-top: 0; }
@media (max-width: 760px) {
  .le-head { display: none; }
  .le-line { grid-template-columns: 1fr 70px 96px 32px; grid-template-areas: "item item item item" "pn stk sub sub" "qty price price del"; }
  .le-servis .le-line { grid-template-areas: "kind kind kind kind" "item item item item" "pn stk sub sub" "qty price price del"; }
  .le-transfer .le-line { grid-template-areas: "item item item item" "pn pn stk stk" "qty qty qty del"; }
  .le-line .c-kind { grid-area: kind; } .le-line .c-item { grid-area: item; } .le-line .c-pn { grid-area: pn; }
  .le-line .c-stk { grid-area: stk; } .le-line .c-stk::before { content: 'Stok '; color: var(--muted); }
  .le-line .c-qty { grid-area: qty; } .le-line .c-price { grid-area: price; } .le-line .c-sub { grid-area: sub; } .le-line .c-del { grid-area: del; }
}
.le-total { text-align: right; margin-top: 8px; font-size: 1rem; }
.le-line.unmatched { background: #fff7ed; border-color: #fdba74; }
.le-line.check { background: #fefce8; border-color: #fde68a; }

/* draft / nota */
.status-banner { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--gray-soft); font-size: .92rem; }
.status-banner.draft { background: var(--orange-soft); color: #7c2d12; }
.status-banner.done { background: var(--green-soft); color: #14532d; }
.nota-preview { background: #e4e4e7; padding: 12px; border-radius: 10px; text-align: center; max-height: 70vh; overflow: auto; }
.nota-preview img { width: 100%; max-width: 560px; background: #fff; box-shadow: 0 4px 18px rgba(0,0,0,.15); }
@media print { @page { margin: 10mm; } }

.le-total div { margin-top: 2px; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 4vh 12px; overflow-y: auto; }
.modal { background: var(--card); border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 1040px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); border-radius: 14px 14px 0 0; z-index: 2; }
.modal-head h3 { margin: 0; }
.modal-body { padding: 14px 16px 16px; }
@media (max-width: 560px) {
  .overlay { padding: 0; align-items: stretch; }
  .modal, .modal.wide { border-radius: 0; min-height: 100%; max-width: none; }
  .modal-head { border-radius: 0; }
}

#toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; width: min(420px, calc(100% - 24px)); }
.toast { background: #0f172a; color: #fff; padding: 11px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-size: .92rem; }
.toast.err { background: var(--red); } .toast.ok { background: #14532d; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, #0f172a, #1e3a8a); }
.login-box { background: #fff; border-radius: 16px; padding: 26px 22px; width: 100%; max-width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-box h2 { margin-bottom: 4px; }
.login-box .btn { width: 100%; margin-top: 12px; }

/* cetak nota */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; color: #000; font-size: 12px; }
  #print-area table { width: 100%; border-collapse: collapse; }
  #print-area th, #print-area td { border-bottom: 1px solid #999; padding: 4px; text-align: left; }
  #print-area .num { text-align: right; }
}

/* ---------- absensi mekanik ---------- */
.absen-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.absen-head input[type=date] { flex: 1; min-width: 150px; max-width: 220px; }
.absen-sum { margin: 4px 0 12px; line-height: 1.5; }
.absen-count { font-size: 1.4rem; font-weight: 700; color: var(--green); }
.absen-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-bottom: 8px; }
.absen-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); cursor: pointer; user-select: none; box-shadow: var(--shadow); }
.absen-item input { position: absolute; opacity: 0; pointer-events: none; }
.absen-box { width: 30px; height: 30px; flex: none; border: 2px solid var(--muted); border-radius: 8px; display: grid; place-items: center; color: transparent; font-weight: 700; font-size: 1.1rem; }
.absen-name { flex: 1; font-weight: 600; font-size: 1.05rem; }
.absen-st { font-size: .8rem; color: var(--muted); }
.absen-item.on { border-color: var(--green); background: var(--green-soft); }
.absen-item.on .absen-box { background: var(--green); border-color: var(--green); color: #fff; }
.absen-item.on .absen-st { color: var(--green); font-weight: 600; }
.absen-item:has(input:focus-visible) { outline: 3px solid var(--primary-soft); }
.absen-rekap { display: flex; flex-direction: column; }
.absen-rrow { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.absen-rrow:last-child { border-bottom: 0; }
.absen-rrow > b { flex: 1; }
.absen-all { display: inline-flex; align-items: center; gap: 6px; margin: 0 0 10px; font-size: .9rem; cursor: pointer; user-select: none; }
.absen-all input { width: 16px; height: 16px; margin: 0; accent-color: var(--green); cursor: pointer; }

/* pencarian pembeli (ketik lalu pilih) */
.combo > input#so-q { margin-top: 4px; }
.combo-drop { margin-top: 4px; border: 1px solid #cbd5e1; border-radius: 9px; background: #fff; overflow: hidden; box-shadow: var(--shadow); }
.combo-drop button { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; font: inherit; cursor: pointer; min-height: 48px; }
.combo-drop button:last-child { border-bottom: 0; }
.combo-drop button:hover, .combo-drop button:focus { background: var(--primary-soft); }
.combo-drop button small { display: block; color: var(--muted); }
.combo-drop .combo-new { color: var(--primary); }
.combo-empty { padding: 10px 12px; color: var(--muted); font-size: .9rem; border-bottom: 1px solid var(--line); }

/* ringkasan pembayaran nota tempo */
.pay-sum { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.pay-sum > div { background: var(--bg); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.pay-sum b { font-size: 1.05rem; }
@media (max-width: 760px) { .pay-sum { grid-template-columns: 1fr 1fr; } }

/* tombol cepat jatuh tempo (Sabtu) */
.due-quick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.due-quick button { font: inherit; font-size: .85rem; border: 1px solid #cbd5e1; background: #fff; border-radius: 999px; padding: 6px 12px; cursor: pointer; min-height: 36px; }
.due-quick button.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.status-banner.batal { background: var(--red-soft); color: #7f1d1d; margin: 0 0 14px; }
.draft-box { border: 2px dashed var(--orange, #ea580c); }

.pay-method { display: block; max-width: 340px; margin-top: 10px; }

.ship-prev { background: var(--primary-soft); border-radius: 10px; padding: 10px 12px; font-size: .9rem; line-height: 1.6; }

.warnbox { background: var(--orange-soft); color: #7c2d12; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: .9rem; display: grid; gap: 4px; max-height: 240px; overflow: auto; }
.xl-tbl td { vertical-align: top; font-size: .88rem; }

/* merek Buana: logo & warna sidebar */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sidebar { background: #04263f; }
.sidebar a:hover, .sidebar button.navlink:hover { background: #0a3a60; }
.sidebar .sep { background: #0d4370; }
.sidebar .brand { padding: 2px 6px 10px; }
.sidebar .brand img { width: 100%; max-width: 190px; height: auto; display: block; }
.login { background: radial-gradient(900px 400px at 85% -10%, #0d5a9a 0%, transparent 60%), linear-gradient(160deg, #04263f, #06345a 60%, #0a4a7f); }
.login-logo { display: block; width: 100%; max-width: 250px; margin: 0 auto 6px; }
.topbar .top-ic { width: 28px; height: 28px; display: none; }
@media (max-width: 860px) { .topbar .top-ic { display: block; } }
