:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #7d8a9c;
  --line: #e2e8f0;
  --brand: #14532d;
  --brand-2: #166534;
  --accent: #0f766e;
  --info: #1d4ed8;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --r: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font: 15px/1.45 "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  padding-bottom: calc(86px + var(--safe-b));
  overflow-wrap: anywhere;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--info); }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--brand); color: #fff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .1);
}
.topbar .brand { flex: 1; min-width: 0; }
.topbar h1 { font-size: 14px; font-weight: 700; letter-spacing: .4px; }
.topbar .sub { font-size: 12px; opacity: .82; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .pill {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: rgba(255, 255, 255, .18); white-space: nowrap;
}
.topbar .pill.admin { background: #facc15; color: #422006; font-weight: 700; }

/* ---------- layout ---------- */
main { padding: 12px 12px 4px; max-width: 780px; margin: 0 auto; }
.judul { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 6px 2px 10px; }
.judul h2 { font-size: 17px; }
.judul .ket { font-size: 12px; color: var(--ink-3); }

/* ---------- search ---------- */
.cari { position: relative; margin-bottom: 10px; }
.cari input {
  width: 100%; padding: 11px 12px 11px 36px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  outline: none;
}
.cari input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 118, 110, .12); }
.cari .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }

/* ---------- chips ---------- */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--ink-2);
  padding: 6px 11px; border-radius: 999px; font-size: 13px; white-space: nowrap; cursor: pointer;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 6px; white-space: nowrap;
}
.b-terbuka { background: var(--warn-bg); color: var(--warn); }
.b-terima { background: var(--ok-bg); color: var(--ok); }
.b-tidak { background: var(--bad-bg); color: var(--bad); }
.b-baru { background: #e0e7ff; color: #3730a3; }
.b-netral { background: #eef2f6; color: var(--ink-2); }

/* ---------- kartu dokumen ---------- */
.kartu {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px; margin-bottom: 10px; box-shadow: var(--shadow); cursor: pointer;
}
.kartu:active { transform: scale(.995); }
.kartu .atas { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.kartu .no { font-weight: 700; font-size: 15px; letter-spacing: .2px; }
.kartu .meta { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.kartu .angka { display: flex; gap: 16px; margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--line); }
.kartu .angka div { font-size: 11px; color: var(--ink-3); }
.kartu .angka b { display: block; font-size: 14px; color: var(--ink); }

/* ---------- baris item ---------- */
.baris {
  display: flex; gap: 10px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 10px; margin-bottom: 8px; cursor: pointer;
}
.baris .isi { flex: 1; min-width: 0; }
.baris .nama { font-size: 13.5px; font-weight: 600; line-height: 1.3; }
.baris .sku { font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.baris .qty { text-align: right; font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.baris .qty b { font-size: 15px; color: var(--ink); }
.baris.lebih { border-color: #fca5a5; background: #fff5f5; }
.baris.beres { border-color: #bbf7d0; background: #f6fef9; }

.thumb {
  border-radius: 9px; background: #eef2f6; overflow: hidden; flex: 0 0 auto;
  display: grid; place-items: center; border: 1px solid var(--line);
}
.thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.thumb-x { font-size: 15px; opacity: .38; filter: grayscale(1); }

/* ---------- tombol ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 11px 14px; border-radius: 11px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 11px; font-size: 13px; border-radius: 9px; }
.icon-btn {
  border: 0; background: transparent; color: inherit; font-size: 22px; line-height: 1;
  padding: 4px 6px; cursor: pointer; border-radius: 8px;
}

/* ---------- form ---------- */
.field { margin-bottom: 13px; }
.field > label { display: block; font-size: 12px; font-weight: 700; color: var(--ink-2); margin-bottom: 5px; letter-spacing: .2px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 11px; background: #fff; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 118, 110, .12);
}
.field .hint { font-size: 11.5px; color: var(--ink-3); margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.qty-row { display: flex; gap: 8px; align-items: center; }
.qty-row input { text-align: center; font-size: 20px; font-weight: 700; }
.qty-row .btn { min-width: 52px; font-size: 20px; padding: 9px 0; }
.pilih { display: flex; flex-wrap: wrap; gap: 7px; }
.pilih .chip { font-size: 13px; }

/* ---------- foto input ---------- */
.foto-box { display: flex; gap: 10px; align-items: center; }
.foto-prev {
  width: 74px; height: 74px; border-radius: 10px; border: 1px dashed var(--line);
  background: #fff; display: grid; place-items: center; overflow: hidden; flex: 0 0 auto;
}
.foto-prev img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; }
.sheet-bg { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); opacity: 0; transition: opacity .18s; }
.sheet {
  position: relative; width: 100%; max-width: 780px; margin: 0 auto;
  background: var(--card); border-radius: 18px 18px 0 0;
  max-height: 92vh; display: flex; flex-direction: column;
  transform: translateY(18px); opacity: 0; transition: transform .2s, opacity .2s;
}
.sheet-wrap.in .sheet { transform: none; opacity: 1; }
.sheet-wrap.in .sheet-bg { opacity: 1; }
.sheet-wrap.out { opacity: 0; transition: opacity .18s; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 13px 14px 9px; border-bottom: 1px solid var(--line); }
.sheet-head h3 { flex: 1; font-size: 15.5px; }
.sheet-body { padding: 14px; overflow: auto; }
.sheet-foot { display: flex; gap: 8px; padding: 11px 14px calc(11px + var(--safe-b)); border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1; }

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: #fff;
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
  box-shadow: 0 -6px 16px rgba(15, 23, 42, .05);
}
.tabbar a {
  display: grid; place-items: center; gap: 2px; padding: 8px 2px 7px;
  color: var(--ink-3); text-decoration: none; font-size: 10.5px; font-weight: 600;
}
.tabbar a .ic { font-size: 19px; line-height: 1; }
.tabbar a.on { color: var(--brand-2); }
.tabbar a.on .ic { filter: none; }

/* ---------- detail ---------- */
.hero {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 13px; margin-bottom: 11px; box-shadow: var(--shadow);
}
.hero .no { font-size: 18px; font-weight: 800; letter-spacing: .2px; }
.hero .asal { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; }
.stat { display: flex; gap: 18px; margin-top: 11px; }
.stat div { font-size: 11px; color: var(--ink-3); }
.stat b { display: block; font-size: 16px; color: var(--ink); }
.progress { height: 7px; background: #e8eef3; border-radius: 999px; overflow: hidden; margin-top: 11px; }
.progress > i { display: block; height: 100%; background: var(--ok); border-radius: 999px; transition: width .3s; }

.bottombar {
  position: fixed; bottom: calc(0px + var(--safe-b)); left: 0; right: 0; z-index: 40;
  display: flex; gap: 8px; padding: 10px 12px;
  background: #fff; border-top: 1px solid var(--line);
  box-shadow: 0 -6px 16px rgba(15, 23, 42, .06);
}
.bottombar .btn { flex: 1; }
body.detail { padding-bottom: calc(140px + var(--safe-b)); }
body.detail .tabbar { display: none; }

/* ---------- misc ---------- */
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 34px 0; color: var(--ink-3); font-size: 13px; }
.spin { width: 17px; height: 17px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.kosong { text-align: center; padding: 40px 18px; color: var(--ink-3); }
.kosong-ic { font-size: 34px; margin-bottom: 8px; }
.kosong h3 { font-size: 15px; color: var(--ink-2); margin-bottom: 4px; }
.kosong p { font-size: 13px; margin: 0; }

#toast { position: fixed; left: 0; right: 0; bottom: calc(84px + var(--safe-b)); z-index: 90; display: grid; justify-items: center; gap: 8px; pointer-events: none; }
.toast {
  max-width: 92vw; padding: 10px 14px; border-radius: 11px; font-size: 13.5px; font-weight: 600;
  background: #1f2937; color: #fff; box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  animation: tin .18s ease-out;
}
.toast-ok { background: var(--ok); }
.toast-err { background: var(--bad); }
.toast-warn { background: var(--warn); }
.toast.out { opacity: 0; transform: translateY(6px); transition: .25s; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

.teks { font-size: 14px; color: var(--ink-2); margin: 0 0 10px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 13px; margin-bottom: 11px; }
.panel h4 { font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 4px 0; }
.kv span:first-child { color: var(--ink-3); }
.sep { height: 1px; background: var(--line); margin: 9px 0; }
.warnbox { background: var(--warn-bg); color: #7c2d12; border-radius: 10px; padding: 10px 11px; font-size: 12.5px; font-weight: 600; }
.errbox { background: var(--bad-bg); color: #7f1d1d; border-radius: 10px; padding: 10px 11px; font-size: 12.5px; font-weight: 600; }
.okbox { background: var(--ok-bg); color: #14532d; border-radius: 10px; padding: 10px 11px; font-size: 12.5px; font-weight: 600; }
.fab {
  position: fixed; right: 14px; bottom: calc(88px + var(--safe-b)); z-index: 35;
  width: 54px; height: 54px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--brand); color: #fff; font-size: 26px; line-height: 1;
  box-shadow: 0 10px 24px rgba(20, 83, 45, .35);
}
