:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --ink: #1f2a27;
  --muted: #6b7773;
  --line: #e3ddd1;
  --brand: #1f5f55;
  --brand-ink: #ffffff;
  --brand-soft: #e3f0ec;
  --accent: #b5532f;
  --ok: #2f7d4f;
  --ok-soft: #e4f3ea;
  --warn: #9a6a00;
  --warn-soft: #fff3d6;
  --bad: #b3261e;
  --bad-soft: #fde8e6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(31, 42, 39, .06), 0 4px 14px rgba(31, 42, 39, .05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12181a; --surface: #1b2326; --ink: #e8eeec; --muted: #9aa8a4; --line: #2c3a3d;
    --brand: #3fa592; --brand-ink: #08201b; --brand-soft: #1d3a35;
    --ok-soft: #1c3527; --warn-soft: #3a2f10; --bad-soft: #3d1c19; --accent: #e08a62;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; font-size: 15px; }
.hidden { display: none !important; }
a { color: var(--brand); }
h1 { font-size: 1.35rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: 0 0 .4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* Kerangka */
.topbar { display: flex; align-items: center; gap: 1rem; padding: .55rem 1rem; background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; z-index: 20; }
.brand { color: inherit; text-decoration: none; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.brand span { font-weight: 400; opacity: .85; }
.nav { display: flex; gap: .15rem; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { color: inherit; text-decoration: none; padding: .4rem .7rem; border-radius: 8px; white-space: nowrap; opacity: .88; font-size: .93rem; }
.nav a:hover { background: rgba(255,255,255,.12); }
.nav a.active { background: rgba(255,255,255,.2); opacity: 1; font-weight: 600; }
.user { display: flex; align-items: center; gap: .5rem; font-size: .85rem; white-space: nowrap; }
.view { max-width: 1100px; margin: 0 auto; padding: 1rem 1rem 5rem; outline: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: .5rem; margin-bottom: 1rem; }
.page-head p { margin: 0; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: .4rem .8rem; }
  .nav { order: 3; flex-basis: 100%; }
  .user #whoami { display: none; }
}

/* Komponen */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); }
.stat .n { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .82rem; }
.stat.in .n { color: var(--ok); } .stat.out .n { color: var(--accent); }

.btn { appearance: none; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); padding: .55rem .95rem; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .4rem; min-height: 40px; }
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: transparent; color: var(--brand); }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.4); color: inherit; font-weight: 500; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { padding: .25rem .6rem; min-height: 32px; font-size: .85rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

label.f { display: flex; flex-direction: column; gap: .2rem; font-size: .82rem; color: var(--muted); font-weight: 600; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; min-height: 40px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
input[type=checkbox] { width: auto; min-height: 0; }
input.invalid { border-color: var(--bad); background: var(--bad-soft); }
.form-grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.form-grid .span2 { grid-column: span 2; }
@media (max-width: 480px) { .form-grid .span2 { grid-column: auto; } }
.check { display: flex; align-items: center; gap: .45rem; font-size: .92rem; color: var(--ink); font-weight: 500; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 700; font-size: .9rem; padding: 0 .4rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .5rem .55rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
@media (hover: hover) and (pointer: fine) { tr.click:hover td { background: var(--brand-soft); } }
td input { min-height: 36px; padding: .3rem .45rem; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .75rem; font-weight: 700; }
.badge.in_stock, .badge.IN { background: var(--ok-soft); color: var(--ok); }
.badge.depleted { background: var(--warn-soft); color: var(--warn); }
.badge.void, .badge.OUT { background: var(--bad-soft); color: var(--bad); }
.badge.ADJUST { background: var(--warn-soft); color: var(--warn); }
.badge.low { background: var(--warn-soft); color: var(--warn); }
.bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--brand); }

.scan-box { display: flex; gap: .5rem; }
.scan-box input { font-size: 1.1rem; min-height: 48px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.scan-box .btn { min-height: 48px; }
.notice { padding: .65rem .9rem; border-radius: 8px; background: var(--warn-soft); color: var(--warn); margin: 0 0 1rem; font-size: .9rem; }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
#banner .notice { border-radius: 0; margin: 0; text-align: center; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: .6rem .9rem; font: inherit; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 700; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .6rem 1rem; }
.kv dt { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kv dd { margin: 0; font-weight: 600; }
.big-code { font-size: 1.5rem; font-weight: 700; letter-spacing: .03em; }
.barcode-img { display: block; width: 100%; max-width: 360px; height: 80px; background: #fff; padding: 6px; border: 1px solid var(--line); border-radius: 6px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: auto 1fr auto; gap: .2rem .8rem; padding: .6rem 0; border-bottom: 1px solid var(--line); align-items: start; }
.timeline .delta { font-weight: 700; font-variant-numeric: tabular-nums; }
.timeline .delta.pos { color: var(--ok); } .timeline .delta.neg { color: var(--accent); }

/* Toast & modal */
.toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .5rem; z-index: 100; width: min(92vw, 420px); }
.toast { background: var(--ink); color: var(--bg); padding: .7rem 1rem; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: .92rem; }
.toast.err { background: var(--bad); color: #fff; } .toast.ok { background: var(--ok); color: #fff; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 1rem; z-index: 90; }
.modal { background: var(--surface); border-radius: 12px; width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 1.1rem; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal h2 { margin-bottom: .8rem; }
.modal .actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
pre.cmd { background: #11181a; color: #cfe8e1; padding: .8rem; border-radius: 8px; overflow: auto; font-size: .8rem; max-height: 50vh; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login .card { width: min(380px, 100%); }
.login h1 { text-align: center; color: var(--brand); }

/* Kamera scan */
.cam { position: fixed; inset: 0; background: #000; z-index: 120; display: grid; grid-template-rows: 1fr auto; }
.cam video { width: 100%; height: 100%; object-fit: cover; }
.cam .cam-bar { padding: 1rem; display: flex; gap: .5rem; justify-content: center; background: #000; color: #fff; }

/* Label (layar & cetak) */
/* align-items: flex-start penting: tanpa itu gambar barcode direnggangkan ke lebar label (ukuran fisik barcode harus tetap) */
.label-frame { background: #fff; color: #000; box-shadow: 0 0 0 1px #bbb; overflow: hidden; display: flex; flex-direction: column; align-items: flex-start; font-family: Arial, Helvetica, sans-serif; line-height: 1.15; }
.label-frame > * { flex: none; max-width: 100%; }
.label-frame .lb-bar { max-width: none; }
.label-frame .lb-mat.sm { font-size: 6pt; }
.label-frame .lb-title { font-size: 6.5pt; letter-spacing: .08em; font-weight: 700; }
.label-frame .lb-mat { font-size: 8.5pt; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: clip; }
.label-frame .lb-bar { display: block; margin: .6mm 0; }
.label-frame .lb-code { font-size: 6.5pt; font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: .04em; }
.label-frame .lb-info { font-size: 10pt; font-weight: 700; display: flex; gap: 3mm; white-space: nowrap; }
.label-frame .lb-sup { font-size: 6pt; white-space: nowrap; overflow: hidden; }
.preview-stage { background: repeating-conic-gradient(#e9e4d9 0 25%, #f4f0e7 0 50%) 0 0 / 16px 16px; border-radius: 10px; padding: 1rem; overflow: auto; display: grid; place-items: center; min-height: 160px; }

/* Foto roll */
.photo-btns { display: inline-flex; gap: .3rem; }
.photo-btns .btn { cursor: pointer; }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line, #d8d2c4); cursor: zoom-in; vertical-align: middle; background: #eee; }
.thumb.lg { width: 100%; max-width: 360px; height: auto; max-height: 360px; border-radius: 10px; }
.photo-cell { display: flex; align-items: center; gap: .4rem; min-width: 130px; }
.photo-cell .ph-state { font-size: .75rem; }
@media (max-width: 640px) { .photo-cell { min-width: 0; } .photo-btns .btn { padding: .4rem .55rem; } }

/* ===== Ramah HP & tablet ===== */
html { -webkit-text-size-adjust: 100%; }
a, button, label.btn, select, input, summary { touch-action: manipulation; }
.ni, .more-btn, .more-sheet { display: none; }   /* ikon & menu "Lainnya" hanya untuk HP */
.nav a .ni { display: none; }

/* Perangkat sentuh (HP & tablet, termasuk landscape): target sentuh >= 44px, font input 16px agar iOS tidak zoom */
@media (pointer: coarse) {
  input, select, textarea { font-size: 16px; min-height: 44px; }
  td input, td select { min-height: 44px; }
  .btn { min-height: 44px; }
  .btn.sm { min-height: 44px; padding: .35rem .8rem; }
  .nav a { min-height: 44px; display: inline-flex; align-items: center; }
  .brand { min-height: 44px; display: inline-flex; align-items: center; }
  .tabs button { min-height: 44px; }
  input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); }
  .check { min-height: 44px; }
  .photo-btns .btn { min-width: 44px; justify-content: center; }
  .thumb { width: 52px; height: 52px; }
}

/* Tablet portrait */
@media (min-width: 721px) and (max-width: 900px) {
  .view { padding-left: .8rem; padding-right: .8rem; }
  .grid.cols-2 { grid-template-columns: 1fr; }
}

/* HP */
@media (max-width: 720px) {
  body { font-size: 16px; }
  h1 { font-size: 1.3rem; }
  .topbar { flex-wrap: nowrap; padding: .4rem .8rem; padding-top: calc(.4rem + env(safe-area-inset-top)); justify-content: space-between; }
  .user { margin-left: auto; }
  .view { padding: .8rem .8rem calc(6rem + env(safe-area-inset-bottom)); }
  .card { padding: .85rem; }
  .page-head { align-items: stretch; }
  .page-head .btn-row { width: 100%; }
  .page-head .btn-row .btn { flex: 1 1 auto; justify-content: center; }
  .btn-row > .btn { flex: 1 1 auto; justify-content: center; }
  .scan-box .btn { flex: none; }
  .modal-bg { align-items: end; padding: 0; }
  .modal { width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; padding-bottom: calc(1.1rem + env(safe-area-inset-bottom)); }
  .modal .actions .btn { flex: 1 1 auto; justify-content: center; }
  .toasts { bottom: calc(4.8rem + env(safe-area-inset-bottom)); }

  /* Menu bawah ala aplikasi */
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; order: 0; flex-basis: auto; overflow: visible;
         display: grid; grid-template-columns: repeat(6, 1fr); gap: 0; padding: .2rem .2rem calc(.2rem + env(safe-area-inset-bottom));
         background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.08); }
  .nav > a.secondary { display: none; }
  .nav > a, .nav > .more-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem; min-height: 56px;
         padding: .25rem 0; border-radius: 10px; color: var(--muted); font-size: .68rem; opacity: 1; background: none; border: 0; font-family: inherit; cursor: pointer; text-align: center; white-space: nowrap; }
  .nav > a .ni, .nav > .more-btn .ni { display: block; font-style: normal; font-size: 1.35rem; line-height: 1; }
  .nav > a span, .nav > .more-btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .nav > a.active, .nav > .more-btn.active { color: var(--brand); background: var(--brand-soft); font-weight: 700; }
  .nav > a:hover { background: none; }
  .nav > a.active:hover { background: var(--brand-soft); }
  /* tampilkan nama ringkas */
  .nav > a[href="#/masuk"] span, .nav > a[href="#/keluar"] span { font-size: 0; }
  .nav > a[href="#/masuk"] span::after { content: 'Masuk'; font-size: .68rem; }
  .nav > a[href="#/keluar"] span::after { content: 'Keluar'; font-size: .68rem; }
  .more-sheet { display: block; position: absolute; right: .5rem; bottom: calc(100% + .5rem); min-width: 190px; background: var(--surface); border: 1px solid var(--line);
                border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.25); padding: .3rem; }
  .more-sheet[hidden] { display: none; }
  .more-sheet a { display: flex; align-items: center; gap: .6rem; min-height: 48px; padding: .4rem .8rem; border-radius: 10px; color: var(--ink); text-decoration: none; font-size: 1rem; }
  .more-sheet a.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
  .more-btn { display: flex; }
  .more-sheet a .ni { display: inline; font-size: 1.2rem; font-style: normal; }

  /* Tabel -> kartu */
  .table-wrap { overflow: visible; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.stack tr { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 .7rem; padding: .25rem .8rem; background: var(--surface); box-shadow: var(--shadow); }
  /* label di kiri lewat posisi absolut: isi sel yang berisi banyak elemen tetap mengalir normal */
  table.stack td { display: block; position: relative; min-height: 2.6rem; padding: .55rem 0 .55rem 38%; border: 0; border-bottom: 1px dashed var(--line); text-align: left; overflow-wrap: anywhere; }
  table.stack td:last-child { border-bottom: 0; }
  table.stack td::before { content: attr(data-label); position: absolute; left: 0; top: .7rem; width: 34%; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); line-height: 1.3; overflow-wrap: normal; }
  table.stack td[data-label=""] { padding-left: 0; min-height: 0; }
  table.stack td[data-label=""]::before { display: none; }
  table.stack td.num { text-align: left; }
  table.stack td .btn-row, table.stack td.nowrap { white-space: normal; }
  table.stack tr.click:active { background: var(--brand-soft); }
  table.stack td .bar { min-width: 0; }
  .label-frame { max-width: 100%; }
}
@media (max-width: 380px) { .nav > a, .nav > .more-btn { font-size: .62rem; } .nav > a .ni, .nav > .more-btn .ni { font-size: 1.2rem; } }
