:root {
  --bg: #f3f6f8; --surface: #ffffff; --text: #14212b; --muted: #5d6b76; --line: #dbe3e8;
  --primary: #0b5c7a; --primary-2: #0e7aa1; --primary-soft: #e3f1f6;
  --ok: #1f7a4d; --ok-soft: #e2f4ea; --warn: #9a6100; --warn-soft: #fff3d6; --err: #b3261e; --err-soft: #fde7e5;
  --company: #0b5c7a; --deposit: #7a3e9d; --deposit-soft: #f2e8f8;
  --radius: 12px; --shadow: 0 1px 2px rgba(20, 33, 43, .06), 0 2px 8px rgba(20, 33, 43, .05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f171d; --surface: #17222a; --text: #e5edf2; --muted: #95a6b2; --line: #2a3943;
    --primary: #4fb3d9; --primary-2: #6cc5e6; --primary-soft: #16303c;
    --ok: #63c48f; --ok-soft: #173327; --warn: #f0b54a; --warn-soft: #3a2e14; --err: #ff8a80; --err-soft: #3d1c1a;
    --company: #6cc5e6; --deposit: #c99be6; --deposit-soft: #2c2135; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.3rem; } h3 { font-size: 1.05rem; } h4 { font-size: .95rem; margin-top: 1rem; }
p { margin: .4rem 0; }
.muted, small { color: var(--muted); }
.neg { color: var(--err); } .pos { color: var(--ok); }
.warn { background: var(--warn-soft); color: var(--warn); padding: .6rem .8rem; border-radius: 8px; }
.empty { color: var(--muted); padding: 1rem 0; text-align: center; }
.loading { padding: 3rem; text-align: center; color: var(--muted); }

/* Topbar */
#topbar { position: sticky; top: 0; z-index: 20; background: var(--primary); color: #fff; display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; padding: .5rem 1rem; padding-top: max(.5rem, env(safe-area-inset-top)); }
#topbar:empty { display: none; }
#topbar a, #topbar .link { color: #fff; }
.brand a { font-weight: 700; }
.mainnav { display: flex; gap: .25rem; overflow-x: auto; flex: 1 1 auto; order: 3; width: 100%; scrollbar-width: none; }
.mainnav a { padding: .4rem .7rem; border-radius: 999px; white-space: nowrap; opacity: .85; font-size: .95rem; }
.mainnav a.on { background: rgba(255,255,255,.2); opacity: 1; font-weight: 600; }
.user { margin-left: auto; display: flex; gap: .75rem; font-size: .85rem; align-items: center; }
@media (min-width: 900px) { .mainnav { order: 0; width: auto; } }

main { max-width: 1100px; margin: 0 auto; padding: 1rem 16px 6rem; }
.page-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .8rem; flex-wrap: wrap; }
.page-head h2 { margin: 0; flex: 1 1 auto; }
.page-head .actions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.back { font-size: 1.8rem; line-height: 1; padding: 0 .4rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.grid2 { display: grid; gap: 1rem; } @media (min-width: 800px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
@media (min-width: 800px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tiles.small { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.tile { position: relative; display: flex; flex-direction: column; gap: .2rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; color: var(--text); box-shadow: var(--shadow); min-height: 110px; transition: border-color .15s, transform .15s; }
.tile:hover, .tile:focus-visible { border-color: var(--primary); }
.tile:active { transform: scale(.98); }
.tile .ic { font-size: 1.6rem; }
.tile strong { font-size: 1.05rem; }
.tile small { font-size: .82rem; }
.tile em { position: absolute; top: .6rem; right: .6rem; background: var(--err); color: #fff; font-style: normal; font-size: .8rem; border-radius: 999px; padding: 0 .5rem; font-weight: 700; }
.tiles.small .tile { min-height: 0; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; margin: .5rem 0 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; display: flex; flex-direction: column; color: var(--text); }
.stat span { font-size: .8rem; color: var(--muted); }
.stat strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.stat.neg strong { color: var(--err); } .stat.warn { background: var(--warn-soft); }
.alerts { margin: 0; padding-left: 1.2rem; } .alerts li { margin: .25rem 0; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .3rem; min-height: 44px; padding: .55rem 1rem; border: 1px solid var(--primary); background: var(--primary); color: #fff; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; text-align: center; }
.btn:hover { background: var(--primary-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.danger, .btn.ghost.danger { color: var(--err); border-color: var(--err); }
.btn:not(.ghost).danger { background: var(--err); color: #fff; }
.btn.sm { min-height: 34px; padding: .3rem .7rem; font-size: .88rem; }
.link, button.link { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: .2rem; text-decoration: underline; }
.link.danger { color: var(--err); }
.icon { background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: var(--muted); min-width: 40px; min-height: 40px; }
.row { display: flex; gap: .5rem; align-items: center; margin: .5rem 0; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.sticky-actions { position: sticky; bottom: 0; z-index: 10; display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; padding: .75rem 0 calc(.75rem + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }

/* Forms */
.form { display: grid; gap: .7rem; }
.field { display: grid; gap: .25rem; }
.field > span { font-size: .88rem; font-weight: 600; } .field b { color: var(--err); }
.field small { font-size: .78rem; }
.field.check { display: flex; align-items: center; gap: .6rem; } .field.check input { width: 22px; height: 22px; }
input, select, textarea { font: inherit; width: 100%; min-height: 44px; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-2); outline-offset: 0; border-color: transparent; }
input.small { width: 90px; } input.big { font-size: 1.5rem; font-weight: 700; max-width: 200px; text-align: right; }
.inline { display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap; }
.segment { display: flex; flex-wrap: wrap; gap: .4rem; }
.segment button { flex: 1 1 auto; min-height: 46px; padding: .4rem .8rem; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 10px; font: inherit; cursor: pointer; }
.segment button.on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .7rem; }
.filters input, .filters select { flex: 1 1 160px; width: auto; }

/* Tables → cards on mobile */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
td { font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--primary-soft); }
@media (max-width: 700px) {
  table, thead, tbody, tr, td { display: block; } thead { display: none; }
  tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: .5rem; padding: .3rem .6rem; background: var(--surface); }
  td { border: 0; padding: .25rem 0; display: flex; gap: .6rem; justify-content: space-between; }
  td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; flex: 0 0 auto; }
  td[data-label=""]::before { content: none; }
}

/* Badges */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: var(--primary-soft); color: var(--primary); white-space: nowrap; vertical-align: middle; }
.b-posted, .b-confirmed, .b-done, .b-active, .b-available, .b-lunas { background: var(--ok-soft); color: var(--ok); }
.b-draft, .b-pending, .b-loading, .b-partial, .b-pending_approval, .b-inspection { background: var(--warn-soft); color: var(--warn); }
.b-cancelled, .b-rejected, .b-overdue, .b-void, .b-expired { background: var(--err-soft); color: var(--err); }
.b-company { background: var(--primary-soft); color: var(--company); }
.b-deposit { background: var(--deposit-soft); color: var(--deposit); }
.b-closed { background: var(--line); color: var(--muted); }

/* Lines (kelompok barang) */
.line { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--company); border-radius: 10px; padding: .8rem; margin-bottom: .7rem; }
.line.deposit { border-left-color: var(--deposit); }
.line.removed { opacity: .55; }
.line-head { margin-bottom: .3rem; }
.big-num { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.weighpad { margin-top: .4rem; }
.weighs { display: flex; flex-wrap: wrap; gap: .35rem; margin: .4rem 0; }
.chip { display: inline-flex; align-items: center; gap: .2rem; background: var(--primary-soft); color: var(--text); border-radius: 999px; padding: .2rem .4rem .2rem .7rem; font-size: .9rem; font-variant-numeric: tabular-nums; }
.chip .x { border: 0; background: none; color: var(--err); font-size: 1.1rem; cursor: pointer; min-width: 28px; min-height: 28px; }
.total { font-weight: 700; }
.progress { position: relative; height: 26px; background: var(--line); border-radius: 999px; overflow: hidden; margin: .5rem 0; }
.progress div { height: 100%; background: var(--ok); }
.progress span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: .85rem; font-weight: 600; }

/* Tabs (multi-pembeli) */
.tabs { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .5rem; margin-bottom: .5rem; }
.tabs button { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-start; min-width: 150px; padding: .55rem .8rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer; text-align: left; }
.tabs button small { font-size: .78rem; }
.tabs button.on { border-color: var(--primary); box-shadow: inset 0 -3px 0 var(--primary); }
.tabs button.add { justify-content: center; align-items: center; border-style: dashed; color: var(--primary); font-weight: 600; }
.tabs.simple a { padding: .5rem .9rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); white-space: nowrap; }
.tabs.simple a.on { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Lokasi */
.loc { border-left: 2px solid var(--line); padding: .4rem 0 .4rem .7rem; margin: .3rem 0; }
.loc.special { border-left-color: var(--warn); background: var(--warn-soft); border-radius: 0 8px 8px 0; }
.loc .unit { padding: .3rem 0 .3rem .5rem; border-bottom: 1px dashed var(--line); }

/* KV */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: .5rem 0; }
.kv dt { color: var(--muted); font-size: .9rem; } .kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.kvline { color: var(--muted); margin-bottom: .5rem; }
@media (max-width: 500px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: .4rem; } }

/* Modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(10, 20, 28, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 700px) { .modal-back { align-items: center; } }
.modal { background: var(--surface); width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 1rem 16px calc(1rem + env(safe-area-inset-bottom)); }
.modal.wide { max-width: 860px; }
@media (min-width: 700px) { .modal { border-radius: 16px; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.modal-head h3 { margin: 0; }
.toast { position: fixed; left: 50%; bottom: 20px; width: max-content; transform: translate(-50%, 30px); opacity: 0; transition: .25s; z-index: 100; background: var(--ok); color: #fff; padding: .7rem 1rem; border-radius: 10px; max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.toast.err { background: var(--err); } .toast.warn { background: var(--warn); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.auth { max-width: 420px; margin: 8vh auto; }
.sync { font-size: .85rem; color: var(--muted); } .sync.offline { color: var(--warn); font-weight: 600; }
pre.json { white-space: pre-wrap; font-size: .8rem; background: var(--bg); padding: .7rem; border-radius: 8px; max-height: 60vh; overflow: auto; }
code.small { font-size: .75rem; color: var(--muted); word-break: break-all; }

/* Dokumen cetak */
.doc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; margin-bottom: 1rem; }
.doc-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 2px solid var(--text); padding-bottom: .6rem; margin-bottom: .8rem; flex-wrap: wrap; }
.doc-total { text-align: right; font-size: 1.15rem; font-weight: 700; margin: .7rem 0; }
.signs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 2.5rem; text-align: center; }
.signs div { border-top: 1px solid var(--text); padding-top: .3rem; margin-top: 3rem; font-size: .85rem; }
@media print {
  #topbar, .page-head .actions, .back, .row, .sticky-actions, .toast { display: none !important; }
  body { background: #fff; color: #000; } main { padding: 0; max-width: none; }
  .doc { border: 0; padding: 0; }
  table, thead, tbody, tr, td { display: revert !important; } td::before { content: none !important; }
}

/* Foto bukti */
.ev-input .row { gap: 8px; flex-wrap: nowrap; }
.ev-input .row input[type=text] { flex: 1; min-width: 0; }
.ev-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { border: 1px solid var(--line, #ccd); background: transparent; color: inherit; border-radius: 999px; padding: 2px 10px; font-size: 0.85em; cursor: pointer; }
.ev-view .chip { margin: 2px 4px 2px 0; }
.ev-img { max-width: 100%; max-height: 75vh; display: block; margin: 0 auto; border-radius: 8px; }
