:root {
  --brand: #C4122E;
  --brand-dark: #9c0e24;
  --ink: #1a1a1a;
  --ink-soft: #6b6b6b;
  --border: #e4e4e4;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --success: #1a7a4c;
  --success-strong: #0f5c37;
  --danger: #c4122e;
  --warning-surface: #fff4d6;
  --warning-ink: #7a5b00;
  --r: 12px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px;
  --tap: 48px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--ink);
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; }

.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.screen[hidden] { display: none; }

/* ---- Login ---- */
#screen-login { align-items: center; justify-content: center; background: var(--brand); padding: var(--s4); }
.login-card { background: var(--surface); border-radius: var(--r); padding: var(--s5); width: 100%; max-width: 360px; }
.brand { margin: 0; font-size: 26px; color: var(--brand); text-align: center; }
.brand-sub { margin: 0 0 var(--s4); text-align: center; color: var(--ink-soft); }
.field { display: block; margin-bottom: var(--s3); }
.field span { display: block; font-size: 13px; font-weight: 600; margin-bottom: var(--s1); color: var(--ink-soft); }
.field input, .field select {
  width: 100%; min-height: var(--tap); padding: 0 var(--s3);
  border: 1px solid var(--border); border-radius: var(--r); font-size: 16px; background: var(--surface);
}
.err {
  background: #ffe6e6; color: var(--danger); border-radius: var(--r);
  padding: var(--s2) var(--s3); font-size: 13px; margin-bottom: var(--s3);
}

/* ---- Buttons ---- */
.btn { min-height: var(--tap); border-radius: var(--r); border: none; font-size: 16px; font-weight: 700; cursor: pointer; }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 17px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-dark); }
.btn-primary:disabled { background: #d8b6bc; cursor: not-allowed; }
.btn-white { background: #fff; color: var(--success-strong); }
.btn-ghost-white { background: transparent; color: #fff; border: 1px solid #fff; }
.icon-btn { min-width: var(--tap); min-height: var(--tap); background: none; border: none; font-size: 20px; cursor: pointer; }

/* ---- Topbar (grid) ---- */
.topbar {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s2) var(--s3); background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-title { flex: 1; display: flex; align-items: center; gap: var(--s2); }
.sync-dot { color: var(--success); font-size: 10px; }
.sync-dot.is-pending { color: var(--warning-ink); }

.appbar {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s2) var(--s3); background: var(--surface); border-bottom: 1px solid var(--border);
}

/* ---- Category tabs ---- */
.tabs { display: flex; gap: var(--s2); padding: var(--s2) var(--s3); overflow-x: auto; background: var(--surface); }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  flex: none; min-height: 36px; padding: 0 var(--s3); border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: 14px; font-weight: 600; cursor: pointer;
}
.tab-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---- Product grid ---- */
.product-grid {
  flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(2, 1fr);
  gap: var(--s2); padding: var(--s3); padding-bottom: 90px;
  align-content: start;
}
@media (min-width: 480px) { .product-grid { grid-template-columns: repeat(3, 1fr); } }
.tile {
  background: var(--surface); border-radius: var(--r); border: 1px solid var(--border);
  padding: var(--s3); text-align: left; cursor: pointer; min-height: 72px;
  display: flex; flex-direction: column; justify-content: space-between; gap: var(--s2);
}
.tile:active { background: #fdf0f1; border-color: var(--brand); }
.tile-name { font-size: 14px; font-weight: 600; line-height: 1.25; }
.tile-price { font-size: 13px; color: var(--ink-soft); font-weight: 700; }

.cart-bar {
  position: fixed; left: var(--s3); right: var(--s3); bottom: calc(var(--s3) + env(safe-area-inset-bottom));
  min-height: 56px; border-radius: var(--r); background: var(--brand); color: #fff; border: none;
  display: flex; align-items: center; padding: 0 var(--s4); gap: var(--s3); cursor: pointer;
}
.cart-bar[hidden] { display: none; }
.cart-bar span:first-child { font-size: 13px; opacity: .9; }
.cart-bar-total { flex: 1; text-align: left; font-weight: 700; }
.cart-bar-cta { font-weight: 700; }

/* ---- Sheets (cart / pay / riwayat) ---- */
.sheet { background: var(--surface); }
.cart-lines { flex: 1; overflow-y: auto; padding: var(--s3); }
.cart-line { display: flex; justify-content: space-between; align-items: center; padding: var(--s3) 0; border-bottom: 1px solid var(--border); gap: var(--s2); }
.cart-line-name { font-weight: 600; font-size: 14px; }
.cart-line-sub { font-size: 12px; color: var(--ink-soft); }
.qty-ctl { display: flex; align-items: center; gap: var(--s2); }
.qty-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); font-size: 18px; font-weight: 700; cursor: pointer; }

.pay-footer { padding: var(--s3); border-top: 1px solid var(--border); background: var(--surface); }
.pay-total-row { display: flex; justify-content: space-between; align-items: baseline; padding: var(--s3); }
.pay-total-row .cap { color: var(--ink-soft); font-size: 13px; }
#cart-total { font-size: 22px; }

.pay-body { flex: 1; overflow-y: auto; padding: var(--s3); }
.num-lg { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.num-lg.is-empty { color: var(--ink-soft); }

.seg { display: flex; border-radius: var(--r); overflow: hidden; border: 1px solid var(--border); margin-bottom: var(--s3); }
.seg-btn { flex: 1; min-height: var(--tap); border: none; background: var(--surface); font-weight: 700; cursor: pointer; }
.seg-btn.active { background: var(--brand); color: #fff; }

.tendered-row, .change-row { display: flex; justify-content: space-between; align-items: baseline; padding: var(--s2) 0; }
.change-row.is-short #pay-change-val { color: var(--danger); }
.change-row #pay-change-val { font-size: 18px; font-weight: 700; }

.quick-amounts { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s2); margin: var(--s3) 0; }
.quick-amounts button { min-height: 44px; border-radius: var(--r); border: 1px solid var(--border); background: var(--surface); font-weight: 700; cursor: pointer; }
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); }
.numpad button { min-height: 52px; border-radius: var(--r); border: 1px solid var(--border); background: var(--surface); font-size: 20px; font-weight: 700; cursor: pointer; }
.numpad button:active { background: #f0f0f0; }

.qris-img { display: block; width: 100%; max-width: 280px; margin: 0 auto var(--s4); border-radius: var(--r); border: 1px solid var(--border); }
.qris-hint { text-align: center; color: var(--ink-soft); font-size: 13px; margin-bottom: var(--s4); }

/* ---- Success ---- */
.success-screen {
  align-items: center; justify-content: center; text-align: center; gap: var(--s3);
  background: var(--success-strong); color: #fff; padding: var(--s5);
}
.success-lbl { font-size: 16px; font-weight: 700; letter-spacing: .04em; opacity: .9; }
.success-val { font-size: 44px; font-weight: 700; font-variant-numeric: tabular-nums; }
.success-doc { font-size: 13px; opacity: .85; }
.success-hold { font-size: 13px; opacity: .8; margin-bottom: var(--s2); }
#success-done, #success-print { width: 100%; max-width: 320px; }

/* ---- Riwayat ---- */
.riwayat-list { flex: 1; overflow-y: auto; padding: var(--s3); }
.riwayat-empty { text-align: center; color: var(--ink-soft); padding: var(--s5); }
.riwayat-row { display: flex; justify-content: space-between; align-items: center; padding: var(--s3); border-bottom: 1px solid var(--border); }
.riwayat-receipt { font-weight: 600; font-size: 14px; }
.riwayat-meta { font-size: 12px; color: var(--ink-soft); }
.riwayat-total { font-weight: 700; }
.riwayat-tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.riwayat-tag.done { background: #e2f5e9; color: var(--success-strong); }
.riwayat-tag.voided { background: #f2f2f2; color: var(--ink-soft); }

/* ---- Toast ---- */
.toast {
  position: fixed; left: var(--s3); right: var(--s3); bottom: calc(var(--s5) + env(safe-area-inset-bottom));
  background: #262626; color: #fff; padding: var(--s3) var(--s4); border-radius: var(--r);
  font-size: 14px; text-align: center; z-index: 999;
}
.toast[hidden] { display: none; }
.toast.is-error { background: var(--danger); }
