:root {
  --primary: #1f4e79;
  --primary-2: #2e75b6;
  --bg: #f2f4f7;
  --card: #fff;
  --text: #1d2733;
  --muted: #6b7785;
  --line: #e2e6ea;
  --ok: #1e8e3e;
  --warn: #c77700;
  --err: #c62828;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
a { color: var(--primary-2); text-decoration: none; }
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
}
.brand { color: #fff; font-weight: 700; font-size: 17px; }
.net { background: var(--err); padding: 2px 8px; border-radius: 10px; font-size: 12px; }
main { max-width: 900px; margin: 0 auto; padding: 14px; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; background: #fff; border-top: 1px solid var(--line);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { flex: 1; text-align: center; padding: 8px 0; color: var(--muted); font-size: 12px; }
.tabbar a span { display: block; font-size: 20px; }
.tabbar a.active { color: var(--primary); font-weight: 600; }

h2 { margin: 4px 0 12px; font-size: 20px; }
h3 { margin: 16px 0 8px; font-size: 16px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: Consolas, "SF Mono", monospace; word-break: break-all; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.stat b { display: block; font-size: 26px; color: var(--primary); }
.stat span { color: var(--muted); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 10px; padding: 10px 14px; font-size: 15px; font-weight: 600; cursor: pointer;
  background: var(--primary); color: #fff; text-decoration: none; font-family: inherit;
}
.btn.secondary { background: #e8eef5; color: var(--primary); }
.btn.danger { background: #fdecea; color: var(--err); }
.btn.ok { background: var(--ok); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.actions .btn { padding: 16px 10px; }

input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 15px; font-family: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-2); border-color: transparent; }
label.f { display: block; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
label.f input, label.f select, label.f textarea { margin-top: 4px; color: var(--text); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li.click { cursor: pointer; }
.list .ico { font-size: 22px; width: 32px; text-align: center; flex: none; }
.list li.flash { animation: flash 1.2s; }
@keyframes flash { from { background: #d9f2df; } to { background: transparent; } }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: #e8eef5; color: var(--primary); white-space: nowrap; }
.badge.open { background: #fff4e0; color: var(--warn); }
.badge.sealed { background: #e3f4e7; color: var(--ok); }
.badge.none { background: #f0f0f0; color: var(--muted); }
.badge.err { background: #fdecea; color: var(--err); }

.crumbs { font-size: 13px; color: var(--muted); }
.crumbs a { font-weight: 600; }

/* Scanner */
.scanner { margin-bottom: 12px; }
.scanner .cam { width: 100%; border-radius: var(--radius); overflow: hidden; background: #000; margin-bottom: 8px; }
.scanner .cam:empty { display: none; }
.scanner .cam video { width: 100% !important; display: block; }
.scanner form { display: flex; gap: 8px; }
.scanner form input { font-family: Consolas, monospace; flex: 1; min-width: 0; }
.scan-result { padding: 10px 12px; border-radius: 10px; margin-top: 8px; font-weight: 600; }
.scan-result.ok { background: #e3f4e7; color: var(--ok); }
.scan-result.warn { background: #fff4e0; color: var(--warn); }
.scan-result.err { background: #fdecea; color: var(--err); }

.tabs { display: flex; gap: 6px; margin-bottom: 10px; overflow-x: auto; }
.tabs button { border: 0; background: #e8eef5; color: var(--primary); padding: 7px 12px; border-radius: 16px; font-weight: 600; cursor: pointer; white-space: nowrap; font-family: inherit; }
.tabs button.active { background: var(--primary); color: #fff; }

.verify { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; margin-bottom: 10px; }
.verify div { background: #f6f8fa; border-radius: 10px; padding: 10px 4px; }
.verify b { display: block; font-size: 22px; }

.toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 30; max-width: 90vw; text-align: center;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--err); }
.toast.warn { background: var(--warn); }

dialog { border: 0; border-radius: var(--radius); padding: 18px; width: min(460px, 92vw); max-height: 90vh; }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h3 { margin-top: 0; }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.hide-sm { }
@media (max-width: 600px) { .hide-sm { display: none; } }

/* Cek paket: sub-paket bertingkat */
details.sub { border: 1px solid var(--line); border-radius: 10px; margin: 8px 0; background: #fafbfc; }
details.sub > summary { list-style: none; cursor: pointer; padding: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
details.sub > summary::-webkit-details-marker { display: none; }
details.sub > summary::before { content: '▸'; color: var(--muted); margin-right: 4px; }
details.sub[open] > summary::before { content: '▾'; }
details.sub > summary > span:first-child { flex: 1; min-width: 0; }
.sub-body { padding: 0 10px 6px 14px; border-top: 1px solid var(--line); }

/* Banner update aplikasi */
.update-bar {
  position: fixed; left: 10px; right: 10px; top: calc(56px + env(safe-area-inset-top)); z-index: 40;
  max-width: 880px; margin: 0 auto; background: #fff8e1; border: 1px solid #f0c36d; color: #5c4400;
  border-radius: 12px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; justify-content: space-between;
  box-shadow: 0 4px 14px rgba(0,0,0,.15); flex-wrap: wrap; animation: slideDown .3s ease-out;
}
@keyframes slideDown { from { transform: translateY(-20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Komponen v2: login, form, pengiriman, penerimaan ---------- */
body.logged-out .tabbar, body.logged-out .who, body.logged-out #queueBadge { display: none !important; }
body.logged-out { padding-bottom: 0; }
.login { max-width: 380px; margin: 40px auto; }
.who { font-size: 12px; opacity: .85; max-width: 45vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.net.queue { background: var(--warn); color: #fff; text-decoration: none; }
.net.fail { background: var(--err); color: #fff; text-decoration: none; }
.center { text-align: center; }
.row.end { justify-content: flex-end; }
.btn.danger-solid { background: var(--err); color: #fff; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; color: var(--text); }
.checks label, .seg label { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.checks input, .seg input, label.small input { width: auto; }
.seg { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.seg label { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; cursor: pointer; min-width: 130px; }
.seg label:has(input:checked) { border-color: var(--primary-2); background: #eef4fb; font-weight: 600; }
.seg.col { flex-direction: column; }
.kv { margin-top: 10px; font-size: 14px; display: grid; gap: 4px; }
.kv > div { display: flex; gap: 8px; }
.kv > div > span:first-child { color: var(--muted); min-width: 92px; flex: none; font-size: 13px; }
.warn-text { color: var(--warn); }
.err-text { color: var(--err); }
.badge.info { background: #e3effc; color: #1a5fb4; }
a.stat { color: inherit; text-decoration: none; display: block; }
a.stat.hl { outline: 2px solid var(--primary-2); }
a.stat.bad b { color: var(--err); }
.warn-card { border-left: 4px solid var(--warn); }
.incoming { border-left: 4px solid var(--primary-2); }
.route { margin: 8px 0 2px; font-size: 16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.route .arrow { color: var(--muted); }
.koli-no { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: #fff; font-weight: 700; flex: none; padding: 0 6px; }
.print-grid { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.gallery figure { margin: 0; cursor: pointer; position: relative; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; background: #eee; }
.gallery figcaption { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.add-photo { aspect-ratio: 1; border: 2px dashed var(--line); border-radius: 8px; background: #fafbfc; font-size: 24px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); }
.add-photo span { font-size: 11px; margin-top: 4px; }
.sigpad { width: 100%; height: 160px; border: 1px solid var(--line); border-radius: 10px; background: #fff; touch-action: none; display: block; margin-top: 4px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.timeline li:last-child { border-bottom: 0; }
.timeline .dot { width: 26px; text-align: center; flex: none; }
tr.click { cursor: pointer; }
.tabbar a span { font-size: 19px; }
.who.switchable { cursor: pointer; text-decoration: underline dotted; }
.item-form fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 2px; margin: 0 0 10px; }
.item-form legend { font-size: 13px; font-weight: 700; color: var(--primary); padding: 0 4px; }
.item-form .unit-row + .unit-row { border-top: 1px dashed var(--line); padding-top: 6px; }
dialog { width: min(560px, 94vw); }
.scanner .btn.kbd.active { background: var(--primary); color: #fff; }
/* Pilih banyak barang */
table.t th.chk, table.t td.chk { width: 34px; text-align: center; cursor: pointer; }
table.t td.chk input, table.t th.chk input { width: 18px; height: 18px; cursor: pointer; }
table.t tr.sel td { background: #eef4fb; }
.bulk-bar {
  position: fixed; left: 10px; right: 10px; bottom: calc(70px + env(safe-area-inset-bottom)); z-index: 20;
  max-width: 880px; margin: 0 auto; background: var(--primary); color: #fff; border-radius: 12px;
  padding: 10px 12px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.bulk-bar .btn.secondary { background: rgba(255,255,255,.18); color: #fff; }
.bulk-bar .btn:not(.secondary) { background: #fff; color: var(--primary); }
