:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f6f8;
  --border: #e5e9ef;
  --text: #111827;
  --text-dim: #6b7280;
  --primary: #16a34a;
  --primary-dark: #15803d;
  --primary-contrast: #ffffff;
  --danger: #dc2626;
  --warn: #d97706;
  --shadow: 0 1px 3px rgba(17,24,39,.06), 0 1px 2px rgba(17,24,39,.04);
  --radius: 12px;
  --nav-h: 64px;
  --topbar-h: 52px;
}

* { box-sizing: border-box; }

.icon { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }
.icon svg { width: 1.3em; height: 1.3em; display: block; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  background: transparent;
  border-bottom: none;
  box-shadow: none;
  pointer-events: none;
  display: flex; align-items: center; padding: 0 16px;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
}
.topbar-title { font-size: 17px; font-weight: 700; }
.demo-badge {
  margin-left: 10px; font-size: 10.5px; font-weight: 800; letter-spacing: .03em;
  color: var(--warn); background: #fef3c7; padding: 3px 8px; border-radius: 20px;
}

#app-root {
  padding-top: calc(var(--topbar-h) + env(safe-area-inset-top) + 10px);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px);
  min-height: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding-left: 12px;
  padding-right: 12px;
}

.bottom-nav {
  position: fixed; left: 12px; right: 12px; height: var(--nav-h);
  bottom: calc(14px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .78);
  backdrop-filter: blur(14px) saturate(180%);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
  border: 1px solid rgba(17, 24, 39, .06);
  border-radius: 20px;
  box-shadow: 0 8px 28px rgba(17, 24, 39, .14);
  display: flex;
  z-index: 20;
  max-width: 536px;
  margin: 0 auto;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-dim); text-decoration: none; font-size: 11px; gap: 2px;
}
.nav-icon { font-size: 22px; }
.nav-icon .icon svg { width: 1em; height: 1em; }
.nav-item.active { color: var(--primary); }

input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  margin-bottom: 10px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
input[type="file"] { padding: 8px; }

.field-label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 4px; margin-top: 2px; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 0 16px; cursor: pointer; }
.toggle-row-title { display: block; font-size: 14px; font-weight: 600; }
.toggle-row-hint { display: block; font-size: 12px; color: var(--text-dim); margin-top: 3px; line-height: 1.45; }
.toggle-row input[type="checkbox"] { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-switch {
  position: relative; flex-shrink: 0; width: 44px; height: 26px;
  background: var(--border); border-radius: 20px; transition: background .2s;
}
.toggle-switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-row input:checked + .toggle-switch { background: var(--primary); }
.toggle-row input:checked + .toggle-switch::after { transform: translateX(18px); }

.btn {
  border: none; border-radius: 10px; padding: 11px 16px; font-size: 15px; font-weight: 600;
  cursor: pointer; color: var(--text); background: var(--surface-2);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.btn .icon svg { width: 19px; height: 19px; }
.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-secondary { background: var(--surface-2); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-block { width: 100%; margin-bottom: 10px; }
.btn-icon { width: 46px; flex-shrink: 0; padding: 0; font-size: 18px; }

.search-row { display: flex; gap: 8px; align-items: stretch; }
.search-row input { flex: 1; min-width: 0; margin-bottom: 0; }

.search-box { position: relative; }
.search-box input { margin-bottom: 0; padding-right: 44px; }
.search-box-scan {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 38px; height: 38px; border: none; background: transparent; color: var(--primary);
  display: flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 8px;
}
.search-box-scan:active { background: var(--surface-2); }

.suggestions {
  display: none; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  margin-top: 8px; max-height: 260px; overflow-y: auto; box-shadow: var(--shadow);
}
.suggestions.open { display: block; }
.sugg-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.sugg-item:last-child { border-bottom: none; }
.sugg-name { font-weight: 600; font-size: 14px; }
.sugg-sub { font-size: 12px; color: var(--text-dim); }
.sugg-price { font-weight: 700; color: var(--primary); font-size: 14px; }
.sugg-empty { padding: 14px; text-align: center; color: var(--text-dim); font-size: 14px; }

.empty-state { text-align: center; color: var(--text-dim); padding: 40px 16px; font-size: 14px; line-height: 1.6; }

.cart-list { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.cart-item {
  display: grid; grid-template-columns: 1fr auto auto auto; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px;
  box-shadow: var(--shadow);
}
.cart-item-name { font-size: 14px; font-weight: 600; }
.cart-item-price { font-size: 12px; color: var(--text-dim); }
.qty-control { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 8px; padding: 4px 8px; }
.qty-btn { background: none; border: none; color: var(--text); width: 24px; height: 24px; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.qty-btn .icon svg { width: 16px; height: 16px; }
.cart-item-subtotal { font-weight: 700; font-size: 14px; min-width: 74px; text-align: right; }
.cart-remove { background: none; border: none; color: var(--danger); cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.cart-remove .icon svg { width: 17px; height: 17px; }

.pos-summary { position: sticky; bottom: 0; background: var(--bg); padding-top: 14px; margin-top: 14px; }
.summary-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 2px; font-size: 14px; }
.summary-row input { width: 130px; margin-bottom: 0; text-align: right; }
.summary-total { font-size: 18px; font-weight: 800; border-top: 1px dashed var(--border); margin-top: 4px; padding-top: 10px; }

.product-list, .trx-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.product-row, .trx-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; cursor: pointer;
  box-shadow: var(--shadow);
}
.product-name, .trx-invoice { font-weight: 700; font-size: 14px; }
.product-sub, .trx-date { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.product-meta { text-align: right; }
.product-price { font-weight: 700; font-size: 14px; color: var(--primary); }
.product-stock { font-size: 12px; color: var(--text-dim); }
.product-stock.low-stock { color: var(--warn); font-weight: 700; }
.product-stock.negative-stock { color: var(--danger); font-weight: 700; }
.trx-total { font-weight: 800; color: var(--primary); }

.filter-row { margin-bottom: 4px; }
.filter-row-flex { display: flex; gap: 8px; margin-bottom: 4px; align-items: stretch; }
.filter-row-flex select { flex: 1; margin-bottom: 0; }

.segmented { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 14px; }
.seg-btn {
  flex: 1; border: none; background: transparent; padding: 9px 4px; border-radius: 9px;
  font-size: 12.5px; font-weight: 700; color: var(--text-dim); cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 5px; white-space: nowrap;
}
.seg-btn .icon svg { width: 15px; height: 15px; }
.seg-btn.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }

.picker-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.picker-row { background: var(--surface-2); border-radius: 10px; padding: 9px 10px; }
.picker-row-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 7px; }
.picker-row-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-remove { background: none; border: none; color: var(--danger); cursor: pointer; display: flex; flex-shrink: 0; padding: 0; }
.picker-remove .icon svg { width: 16px; height: 16px; }
.picker-row-bottom { display: flex; align-items: center; gap: 6px; }
.picker-qty, .picker-cost { margin-bottom: 0; padding: 6px; font-size: 13px; text-align: center; width: 64px; flex: none; }
.picker-x { color: var(--text-dim); font-size: 12px; }
.picker-subtotal { margin-left: auto; font-size: 13px; font-weight: 700; white-space: nowrap; }
.empty-state-sm { text-align: center; color: var(--text-dim); font-size: 13px; padding: 16px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 10.5px; font-weight: 700; }
.badge-penjualan { background: #dcfce7; color: #15803d; }
.badge-pembelian { background: #dbeafe; color: #1d4ed8; }

.section-title { font-size: 14px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; margin: 22px 0 10px; }

.report-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.report-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 10px; text-align: center; box-shadow: var(--shadow); }
.report-card-label { font-size: 11px; color: var(--text-dim); }
.report-card-value { font-size: 15px; font-weight: 800; margin-top: 4px; word-break: break-word; }

.bar-chart { display: flex; align-items: flex-end; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 10px 10px; min-height: 160px; overflow-x: auto; box-shadow: var(--shadow); }
.bar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; flex: 1; min-width: 44px; }
.bar-val { font-size: 9px; color: var(--text-dim); margin-bottom: 4px; white-space: nowrap; }
.bar { width: 22px; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 4px; }
.bar-label { font-size: 10px; color: var(--text-dim); margin-top: 6px; }

.top-products { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.top-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.top-row:last-child { border-bottom: none; }
.top-rank { width: 20px; height: 20px; border-radius: 50%; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.top-name { flex: 1; font-weight: 600; }
.top-qty { color: var(--text-dim); font-size: 12px; }

.hint-text { font-size: 12px; color: var(--text-dim); line-height: 1.5; margin: 6px 0 4px; }
.app-version { text-align: center; font-size: 11px; color: var(--text-dim); margin-top: 26px; }

.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { margin-bottom: 10px; }

/* Activation gate */
body.pre-activation .topbar,
body.pre-activation .bottom-nav { display: none; }
body.pre-activation #app-root { padding: 0; max-width: none; }

.activation-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.activation-card { max-width: 380px; width: 100%; text-align: center; }
.activation-icon {
  width: 60px; height: 60px; border-radius: 18px; background: var(--primary); color: var(--primary-contrast);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 18px;
}
.activation-icon .icon svg { width: 30px; height: 30px; }
.activation-card h2 { margin: 0 0 8px; font-size: 20px; }
.activation-card p { color: var(--text-dim); font-size: 13.5px; margin: 0 0 20px; line-height: 1.55; }
#lic-input { text-align: center; letter-spacing: 2px; font-weight: 700; text-transform: uppercase; font-size: 16px; }
.lic-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: -4px 0 12px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 100;
}
.modal-box {
  background: var(--surface); border-radius: 16px; padding: 18px 16px;
  width: 100%; max-width: 480px; max-height: min(85vh, 720px); overflow-y: auto;
  box-shadow: 0 12px 40px rgba(17,24,39,.18);
  margin: auto;
}
.modal-box h3 { margin: 0 0 14px; font-size: 17px; }
.modal-msg { font-size: 14px; line-height: 1.6; margin: 0 0 16px; }
.modal-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; }
.modal-actions > div { display: flex; gap: 8px; }
.modal-actions-col { flex-direction: column; }
.modal-actions-col .btn { width: 100%; }

.scanner-box { text-align: center; }
.scanner-box video { width: 100%; border-radius: 10px; background: #000; max-height: 60vh; object-fit: cover; }
.scanner-hint { color: var(--text-dim); font-size: 13px; margin: 10px 0; }

.receipt-preview .receipt-html {
  background: #fff; color: #000; font-family: 'Courier New', monospace; font-size: 12px;
  padding: 14px; border-radius: 8px; margin-bottom: 14px;
}
.receipt-html .center { text-align: center; }
.receipt-html .line { border-top: 1px dashed #000; margin: 6px 0; }
.receipt-html table { width: 100%; border-collapse: collapse; }
.receipt-html td { padding: 1px 0; font-size: 12px; }
.receipt-html .r { text-align: right; }

/* Toasts */
#toast-holder { position: fixed; top: calc(var(--topbar-h) + 10px); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 200; pointer-events: none; }
.toast {
  background: var(--text); border: 1px solid var(--border); color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 13px; opacity: 0; transform: translateY(-8px);
  transition: all .25s ease; max-width: 90%; text-align: center; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-color: var(--primary); }
.toast-error { border-color: var(--danger); }

