:root {
  --bg-page: #EEF0F3;
  --bg-surface: #FFFFFF;
  --bg-surface-2: #F6F7F9;
  --text-primary: #1A2233;
  --text-secondary: #5B6478;
  --text-muted: #8A93A6;
  --border: #E2E5EB;
  --navy: #0B2D5C;
  --navy-tint: #E8EEF6;
  --gold: #F5A623;
  --gold-tint: #FDF3E1;
  --success: #1D9E75;
  --success-tint: #E1F5EE;
  --danger: #D64545;
  --danger-tint: #FBE7E7;
}
:root[data-theme="dark"] {
  --bg-page: #0D1117;
  --bg-surface: #171C24;
  --bg-surface-2: #1D232C;
  --text-primary: #EDEFF3;
  --text-secondary: #9AA3B5;
  --text-muted: #6B7385;
  --border: #2A3140;
  --navy: #6C93CC;
  --navy-tint: #1B2635;
  --gold: #F5A623;
  --gold-tint: #2E2411;
  --success: #4FCBA0;
  --success-tint: #123227;
  --danger: #E77373;
  --danger-tint: #341717;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-page: #0D1117;
    --bg-surface: #171C24;
    --bg-surface-2: #1D232C;
    --text-primary: #EDEFF3;
    --text-secondary: #9AA3B5;
    --text-muted: #6B7385;
    --border: #2A3140;
    --navy: #6C93CC;
    --navy-tint: #1B2635;
    --gold: #F5A623;
    --gold-tint: #2E2411;
    --success: #4FCBA0;
    --success-tint: #123227;
    --danger: #E77373;
    --danger-tint: #341717;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Login ---------- */
#screen-login {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px calc(32px + env(safe-area-inset-bottom));
}
.login-wrap { display: flex; flex-direction: column; align-items: center; width: 100%; max-width: 320px; }
.login-logo { width: 188px; height: auto; display: block; margin-bottom: 18px; }
.login-sub { font-size: 12.5px; color: var(--text-muted); margin: 0 0 32px; text-align: center; }
.login-form { width: 100%; }
.login-footer { text-align: center; font-size: 11px; color: var(--text-muted); margin-top: 26px; }
.login-error {
  background: var(--danger-tint); color: var(--danger); font-size: 12.5px;
  border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; display: none;
}
.login-error.show { display: block; }

/* ---------- App shell ---------- */
#app { display: none; min-height: 100vh; flex-direction: column; }
#app.show { display: flex; }
#app-main {
  flex: 1; width: 100%; max-width: 480px; margin: 0 auto;
  padding: 18px 18px calc(88px + env(safe-area-inset-bottom));
}
.screen { display: none; }
.screen.active { display: block; }

.topbar { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 4px; }
.topbar h1 { font-size: 20px; font-weight: 500; margin: 0; }
.topbar .sub { font-size: 12px; color: var(--text-muted); }
.greeting { font-size: 12.5px; color: var(--text-secondary); margin: 2px 0 0; }
.logout-btn {
  background: var(--bg-surface-2); border: 1px solid var(--border); color: var(--text-secondary);
  font-size: 11.5px; padding: 7px 12px; border-radius: 10px; cursor: pointer; font-family: inherit;
}

.section-label {
  font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-muted); margin: 14px 0 6px;
}

.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.kpi-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.kpi-label { font-size: 12px; color: var(--text-secondary); margin: 0 0 6px; }
.kpi-value { font-size: 19px; font-weight: 500; margin: 0; font-variant-numeric: tabular-nums; }
.kpi-value.small { font-size: 16px; }
.kpi-value.placeholder { color: var(--text-muted); }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 500; padding: 2px 8px; border-radius: 100px;
}
.pill.success { background: var(--success-tint); color: var(--success); }
.pill.danger { background: var(--danger-tint); color: var(--danger); }
.pill.gold { background: var(--gold-tint); color: #9A6300; }
:root[data-theme="dark"] .pill.gold { color: var(--gold); }

.seg { display: flex; background: var(--bg-surface-2); border-radius: 11px; padding: 3px; margin-top: 14px; }
.seg button {
  flex: 1; border: none; background: transparent; padding: 7px 4px; font-size: 11.5px;
  color: var(--text-secondary); border-radius: 8px; cursor: pointer; font-family: inherit;
}
.seg button.active { background: var(--bg-surface); color: var(--text-primary); font-weight: 500; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

.row-list { display: flex; flex-direction: column; margin-bottom: 18px; }
.row-item { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); }
.row-item:last-child { border-bottom: none; }
.row-item.row-bold .row-title { font-weight: 700; }
.row-item.row-bold .row-amount { font-weight: 700; }
.row-main { display: flex; flex-direction: column; gap: 1px; }
.row-title { font-size: 12.5px; font-weight: 500; margin: 0; }
.row-sub { font-size: 10.5px; color: var(--text-muted); margin: 0; }
.row-end { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.row-amount { font-size: 12.5px; font-weight: 500; font-variant-numeric: tabular-nums; margin: 0; }
.row-left { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--navy-tint); color: var(--navy);
  display: flex; align-items: center; justify-content: center; font-size: 10.5px; font-weight: 500; flex-shrink: 0;
}
.stock-qty { font-size: 12.5px; font-weight: 500; font-variant-numeric: tabular-nums; margin: 0; }
.stock-unit { font-size: 10px; color: var(--text-muted); margin: 0; }

select, input[type="text"], input[type="number"], input[type="password"], input[type="search"], input[type="date"] {
  width: 100%; height: 40px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-surface-2); color: var(--text-primary); padding: 0 12px; font-size: 14px;
  font-family: inherit;
}
label { font-size: 12px; color: var(--text-secondary); display: block; margin: 0 0 5px; }
.field { margin-bottom: 14px; }

.btn { width: 100%; height: 42px; border-radius: 11px; border: none; font-size: 14px; font-weight: 500; cursor: pointer; font-family: inherit; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-gold { background: var(--gold); color: #402D06; }
.btn-ghost { background: var(--bg-surface-2); color: var(--text-primary); border: 1px solid var(--border); }

.empty-card {
  background: var(--bg-surface); border: 1px dashed var(--border); border-radius: 14px;
  padding: 28px 18px; text-align: center; margin-top: 18px;
}
.empty-card .empty-title { font-size: 14px; font-weight: 500; margin: 0 0 6px; }
.empty-card .empty-sub { font-size: 12.5px; color: var(--text-muted); margin: 0; line-height: 1.5; }

.navbar {
  position: fixed; bottom: 0; left: 0; right: 0; height: 66px;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg-surface); border-top: 1px solid var(--border);
  display: flex; z-index: 20;
}
.navbtn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: none; color: var(--text-muted); font-size: 10.5px; cursor: pointer; font-family: inherit;
}
.navbtn.active { color: var(--navy); }
.navbtn i { font-size: 20px; }

.item-card { background: var(--bg-surface-2); border-radius: 14px; padding: 12px; margin-bottom: 10px; }
.item-card .item-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px; }
.item-card .item-title { font-size: 13.5px; font-weight: 500; }
.produk-picker { position: relative; margin-bottom: 8px; }
.pj-produk-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: 10px;
  max-height: 220px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,0.16); display: none;
}
.pj-produk-results.show { display: block; }
.pj-produk-result-item { padding: 9px 12px; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--border); }
.pj-produk-result-item:last-child { border-bottom: none; }
.pj-produk-result-item:hover { background: var(--bg-surface-2); }
.pj-produk-result-empty { padding: 12px; font-size: 12.5px; color: var(--text-muted); text-align: center; }
.pj-produk-result-kategori { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; padding: 6px 12px 2px; }
.item-card .remove { color: var(--text-muted); font-size: 11px; cursor: pointer; background: none; border: none; font-family: inherit; padding: 0; flex-shrink: 0; }
.item-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.item-row-2 label { margin: 0 0 3px; }
.item-subtotal { font-size: 11.5px; color: var(--text-muted); text-align: right; margin: 8px 0 0; }
.total-strip {
  display: flex; justify-content: space-between; align-items: baseline;
  background: var(--navy-tint); border-radius: 14px; padding: 14px 16px; margin: 14px 0 18px;
}
.total-strip .label { font-size: 12px; color: var(--navy); }
:root[data-theme="dark"] .total-strip .label { color: var(--text-secondary); }
.total-strip .value { font-size: 20px; font-weight: 500; color: var(--navy); font-variant-numeric: tabular-nums; }
:root[data-theme="dark"] .total-strip .value { color: var(--text-primary); }
.total-strip.negative { background: var(--danger-tint); }
.total-strip.negative .label, .total-strip.negative .value { color: var(--danger); }
.cashback-item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.cashback-item:last-child { border-bottom: none; }
.cashback-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.cashback-amounts { font-size: 10.5px; color: var(--text-muted); margin: 1px 0 0; font-variant-numeric: tabular-nums; }
.progress-track { background: var(--bg-surface-2); border-radius: 100px; height: 6px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--navy); border-radius: 100px; }
.progress-fill.tercapai { background: var(--success); }
.cashback-estimasi { font-size: 11px; color: var(--success); margin: 5px 0 0; }

.opname-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.opname-row:last-child { border-bottom: none; }
.opname-top { display: flex; justify-content: space-between; margin-bottom: 8px; gap: 8px; }
.opname-input-wrap { display: flex; align-items: center; gap: 10px; }
.opname-input-wrap input { width: 84px; text-align: center; flex-shrink: 0; }
.opname-diff { font-size: 12px; font-variant-numeric: tabular-nums; }

.form-msg { font-size: 12.5px; border-radius: 10px; padding: 10px 12px; margin: 12px 0; display: none; }
.form-msg.show { display: block; }
.form-msg.error { background: var(--danger-tint); color: var(--danger); }
.form-msg.success { background: var(--success-tint); color: var(--success); }
.form-msg a { color: inherit; text-decoration: underline; font-weight: 500; }

.detail-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
.detail-overlay.show { opacity: 1; pointer-events: auto; }
.detail-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  background: var(--bg-surface); border-radius: 18px 18px 0 0;
  max-height: 78vh; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform 0.22s ease;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.2);
  max-width: 480px; margin: 0 auto;
}
.detail-sheet.show { transform: translateY(0); }
.detail-sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.detail-sheet-title { font-size: 15px; font-weight: 500; margin: 0; }
.detail-sheet-close {
  background: var(--bg-surface-2); border: none; border-radius: 100px; width: 28px; height: 28px;
  font-size: 18px; line-height: 1; color: var(--text-secondary); cursor: pointer;
}
.detail-sheet-body { padding: 8px 18px 24px; overflow-y: auto; }
.detail-kv { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.detail-kv:last-child { border-bottom: none; }
.detail-kv .k { color: var(--text-muted); }
.detail-kv .v { font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; }
.detail-loading { text-align: center; padding: 32px 0; color: var(--text-muted); font-size: 12.5px; }
.detail-clickable { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.detail-clickable:active { opacity: 0.7; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text-primary); color: var(--bg-surface); font-size: 12.5px;
  padding: 10px 16px; border-radius: 10px; z-index: 40; opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }
