@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/instrument-sans-latin-wght-normal.woff2") format("woff2-variations"),
       url("../fonts/instrument-sans-latin-wght-normal.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --paper: #f4f5f7;
  --surface: #ffffff;
  --ink: #1b2129;
  --ink-2: #4d5764;
  --ink-3: #808a96;
  --line: #d9dde3;
  --line-2: #eaedf1;
  --accent: #2b5c8a;
  --accent-2: #224a70;
  --accent-tint: #e6eef6;
  --accent-soft: #9dbad6;
  --ok: #2f7d4f;
  --ok-tint: #e3f2e8;
  --warn: #a8620a;
  --warn-tint: #fcf0dc;
  --bad: #b8371d;
  --bad-tint: #fbe7e2;
  --side: #1e252e;
  --side-ink: #c8cfd8;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(20, 26, 34, .06), 0 4px 16px rgba(20, 26, 34, .06);
  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.125rem; font-weight: 620; }
h3 { font-size: 1rem; font-weight: 620; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.num { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 32px 28px; box-shadow: var(--shadow); }
.login-card h1 { margin: 18px 0 4px; }
.login-card p { margin: 0 0 22px; color: var(--ink-2); }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 6px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100%; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; text-decoration: none; }
.brand img { width: 32px; height: 32px; object-fit: contain; border-radius: 6px; background: #fff; }
.mono { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 7px; background: var(--accent); color: #fff; font-weight: 650; font-size: .9rem; letter-spacing: .02em; flex: none; }
.mono.lg { width: 48px; height: 48px; font-size: 1.15rem; border-radius: 10px; }
.login-card .brandmark { display: flex; align-items: center; gap: 12px; }
.login-card .brandmark img { width: 48px; height: 48px; object-fit: contain; }
.login-card .brandmark strong { font-size: 1.02rem; }
.brand strong { font-size: .98rem; font-weight: 620; line-height: 1.2; }
.nav { padding: 4px 10px 18px; flex: 1; }
.nav-group { margin-top: 14px; }
.nav-group > span { display: block; padding: 0 10px 4px; font-size: .78rem; color: #8a95a3; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 5px; color: var(--side-ink); text-decoration: none; font-size: .93rem; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--accent); color: #fff; }
.nav a .badge { margin-left: auto; background: rgba(255,255,255,.14); color: #fff; font-size: .72rem; padding: 0 7px; border-radius: 9px; }
.me { border-top: 1px solid rgba(255,255,255,.08); padding: 12px 18px; font-size: .85rem; }
.me strong { color: #fff; display: block; font-weight: 560; }
.me button { background: none; border: 0; color: var(--accent-soft); padding: 0; cursor: pointer; font-size: .85rem; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.page { padding: 26px 32px 60px; max-width: 1320px; width: 100%; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--ink-2); margin-top: 3px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { font-size: .88rem; margin-bottom: 6px; }
.crumb a { text-decoration: none; }

/* ---------- Buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 7px 14px; border-radius: var(--radius); cursor: pointer; font-weight: 540; font-size: .92rem; white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); padding: 5px 8px; }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 4px 6px; color: var(--ink-3); border-radius: 4px; font-size: 1rem; line-height: 1; }
.icon-btn:hover { color: var(--bad); background: var(--bad-tint); }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label { font-size: .85rem; color: var(--ink-2); font-weight: 520; }
.field .hint { font-size: .8rem; color: var(--ink-3); }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=password], input[type=month], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 7px 10px; min-height: 36px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 2px solid var(--accent-tint); outline-offset: 0; }
input[readonly] { background: var(--paper); }
input.num { text-align: right; }
textarea { min-height: 64px; resize: vertical; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .93rem; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.grid { display: grid; gap: 14px 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

/* ---------- Panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.panel + .panel, .panel + .block, .block + .panel { margin-top: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.panel-body { padding: 18px; }
.panel-body.flush { padding: 0; }
.block { margin-top: 18px; }

/* ---------- Toolbar & filters ---------- */
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; padding: 12px 18px; border-bottom: 1px solid var(--line-2); }
.toolbar .field { min-width: 140px; }
.toolbar .grow { flex: 1; min-width: 200px; }
.toolbar .exports { margin-left: auto; display: flex; gap: 6px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 14px; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 540; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th { text-align: left; font-weight: 560; color: var(--ink-2); font-size: .82rem; padding: 9px 12px; border-bottom: 1px solid var(--line); background: #f8f9fb; white-space: nowrap; }
table.t td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.t tbody tr.click { cursor: pointer; }
table.t tbody tr.click:hover td { background: var(--accent-tint); }
table.t tfoot td { font-weight: 620; border-top: 1px solid var(--line); background: #f8f9fb; }
table.t .sub-row td { background: #fafbfc; font-size: .86rem; color: var(--ink-2); }
table.t th.num, table.t td.num { text-align: right; }
.empty { padding: 36px 18px; text-align: center; color: var(--ink-2); }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; }
table.lines td { padding: 6px 8px; vertical-align: middle; }
table.lines input, table.lines select { min-height: 34px; }
table.lines .w-qty { width: 110px; }
table.lines .w-price { width: 150px; }

/* ---------- Status pills ---------- */
.pill { display: inline-block; font-size: .78rem; padding: 1px 9px; border-radius: 10px; font-weight: 560; white-space: nowrap; background: var(--line-2); color: var(--ink-2); }
.pill.draft { background: #eef0f0; color: var(--ink-2); }
.pill.ok, .pill.posted, .pill.lunas, .pill.completed, .pill.sudah_ditagih { background: var(--ok-tint); color: var(--ok); }
.pill.warn, .pill.sebagian, .pill.partial, .pill.sebagian_ditagih, .pill.issued { background: var(--warn-tint); color: var(--warn); }
.pill.bad, .pill.cancelled, .pill.overdue { background: var(--bad-tint); color: var(--bad); }
.pill.info, .pill.belum_bayar, .pill.belum_ditagih { background: var(--accent-tint); color: var(--accent-2); }

/* ---------- Summary figures ---------- */
.figures { display: flex; flex-wrap: wrap; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.figure { background: var(--surface); padding: 14px 18px; flex: 1 1 190px; }
.figure .label { font-size: .85rem; color: var(--ink-2); }
.figure .value { font-size: 1.3rem; font-weight: 640; margin-top: 2px; letter-spacing: -.01em; }
.figure .note { font-size: .82rem; color: var(--ink-3); margin-top: 2px; }
.figure .value.bad { color: var(--bad); }
.figure a { color: inherit; text-decoration: none; }

/* ---------- Stock tiles (ringkasan & galon kosong) ---------- */
.gauges { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.gauge { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px 14px; display: block; }
.gauge .g-name { font-size: .86rem; color: var(--ink-2); line-height: 1.3; min-height: 2.6em; }
.gauge .g-qty { font-size: 1.5rem; font-weight: 660; line-height: 1.1; margin-top: 6px; }
.gauge .g-unit { font-size: .8rem; color: var(--ink-3); }
.gauge .g-bar { height: 6px; background: var(--line-2); border-radius: 3px; margin-top: 10px; overflow: hidden; }
.gauge .g-bar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.gauge.low .g-qty { color: var(--bad); }
.gauge.low .g-bar span { background: var(--bad); }
a.gauge:hover { border-color: var(--accent); }

/* ---------- Document view ---------- */
.doc-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px 20px; }
.doc-meta > div > span:first-child { display: block; font-size: .82rem; color: var(--ink-2); }
.doc-meta div strong { font-weight: 560; }
.totals { margin-left: auto; width: min(360px, 100%); padding: 12px 18px; }
.totals .row { display: flex; justify-content: space-between; padding: 3px 0; }
.totals .row.grand { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; font-weight: 660; font-size: 1.05rem; }
.callout { border-left: 3px solid var(--warn); background: var(--warn-tint); padding: 10px 14px; border-radius: 0 6px 6px 0; font-size: .92rem; margin-bottom: 14px; }
.callout.info { border-color: var(--accent); background: var(--accent-tint); }
.callout.bad { border-color: var(--bad); background: var(--bad-tint); }
.callout p { margin: 0; }
.callout p + p { margin-top: 4px; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 26, 34, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 10px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 860px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line-2); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 12px 20px 16px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line-2); flex-wrap: wrap; }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 7px; box-shadow: var(--shadow); font-size: .92rem; }
.toast.error { background: var(--bad); }
.toast.ok { background: var(--ok); }

.loading { padding: 40px; text-align: center; color: var(--ink-3); }
.perm-grid td, .perm-grid th { text-align: center; }
.perm-grid td:first-child, .perm-grid th:first-child { text-align: left; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; font-size: .92rem; }
.kv span { color: var(--ink-2); }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.split > * + * { margin-top: 0 !important; }
.stack > * + * { margin-top: 18px; }
.right { text-align: right; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 60; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--side); color: #fff; position: sticky; top: 0; z-index: 40; }
  .topbar button { background: none; border: 1px solid rgba(255,255,255,.25); color: #fff; border-radius: 5px; padding: 4px 10px; cursor: pointer; }
  .topbar strong { font-weight: 600; font-size: .95rem; }
  .page { padding: 18px 16px 50px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .split { grid-template-columns: 1fr; }
  .toolbar .exports { margin-left: 0; }
  table.lines .w-qty, table.lines .w-price { width: auto; min-width: 90px; }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }
.gauges > .empty { grid-column: 1 / -1; text-align: left; padding: 6px 0 4px; }
.figures + .panel, .figures + .block, .figures + .split { margin-top: 18px; }
.bar-track { height: 8px; background: var(--line-2); border-radius: 4px; min-width: 120px; overflow: hidden; margin-top: 6px; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--bad); }
.bar-fill.in { background: var(--ok); }
table.t tr.void td { color: var(--ink-3); }
table.t.book { min-width: 1080px; }
table.t.book td:nth-child(3) { min-width: 200px; }
.btn.ghost.danger { color: var(--bad); }
.me-link { color: #fff; opacity: .8; font-size: .85rem; }
.me button { color: #fff; opacity: .8; }
.me-link:hover, .me button:hover { opacity: 1; }
