:root {
  --bg: #fdf2f6;
  --surface: #ffffff;
  --ink: #21283a;
  --muted: #8a8597;
  --line: #ecdfe6;
  --accent: #14306b;
  --accent-soft: #fbdde9;
  --green: #2e7d50;
  --green-soft: #e2f1e8;
  --amber: #b87514;
  --amber-soft: #f9ecd5;
  --blue: #2d6ea3;
  --blue-soft: #e1edf6;
  --red: #b3402f;
  --red-soft: #f7e2dd;
  --gray-soft: #ece6df;
  --radius: 14px;
  --shadow: 0 6px 22px rgba(60, 40, 25, 0.10);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;            /* tidak ada scroll samping di HP */
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--red); font-size: 14px; }

button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit; width: 100%; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  color: var(--ink); margin-top: 4px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { font-size: 13px; font-weight: 600; color: var(--muted); display: block; margin-top: 12px; }

.btn-primary {
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  padding: 12px 16px; font-weight: 600; width: 100%; margin-top: 16px;
}
.btn-primary:active { transform: translateY(1px); }
.btn-secondary {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; font-weight: 600;
}
.btn-ghost { background: none; border: none; color: var(--accent); font-weight: 600; padding: 8px; }
.btn-danger { background: var(--red-soft); color: var(--red); border: none; border-radius: 8px; padding: 8px 12px; font-weight: 600; }
.btn-sm { padding: 7px 11px; font-size: 14px; border-radius: 8px; }

/* ===== Login ===== */
.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { background: var(--surface); padding: 28px; border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 360px; }
.brand { font-size: 22px; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.brand span { color: var(--accent); }
.brand.small { font-size: 17px; padding: 6px 4px 14px; }
.logo-img { width: 40px; height: 40px; border-radius: 10px; display: block; }
.brand.small .logo-img { width: 30px; height: 30px; border-radius: 8px; }
.login-card { text-align: center; }
.login-card .brand { justify-content: center; }
.login-card label, .login-card input { text-align: left; }

/* ===== Layout ===== */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
}
.topbar-title { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user { display: flex; align-items: center; gap: 8px; min-width: 0; }
#eventChip { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who { font-size: 13px; color: var(--muted); }
.icon-btn { background: none; border: none; font-size: 20px; padding: 6px 8px; border-radius: 8px; color: var(--ink); }
.icon-btn:active { background: var(--gray-soft); }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 240px; z-index: 50;
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 16px 12px; transform: translateX(-100%); transition: transform .22s ease;
  display: flex; flex-direction: column; padding-top: max(16px, env(safe-area-inset-top));
}
.sidebar.open { transform: translateX(0); }
.nav-item {
  display: block; padding: 12px 12px; border-radius: 10px; color: var(--ink);
  text-decoration: none; font-weight: 600; margin-bottom: 2px; cursor: pointer;
}
.nav-item:active { background: var(--gray-soft); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-spacer { flex: 1; }
.backdrop { position: fixed; inset: 0; background: rgba(30,20,12,.4); z-index: 40; }

.main { padding: 16px; max-width: 880px; margin: 0 auto; padding-bottom: 60px; }

/* ===== Cards & sections ===== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card h2 { margin: 0 0 12px; font-size: 17px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.section-title { font-size: 14px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 4px 8px; }

/* ===== Stat tiles ===== */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 22px; font-weight: 800; margin-top: 4px; }
.stat .value.rp { color: var(--accent); }

/* ===== Item builder ===== */
.item-line { display: grid; grid-template-columns: 1fr 64px 96px 32px; gap: 8px; align-items: end; margin-bottom: 8px; }
.item-line.bonus { background: var(--amber-soft); padding: 8px; border-radius: 10px; }
.item-line .x { background: none; border: none; color: var(--red); font-size: 18px; padding: 8px 0; }
.line-sub { font-size: 12px; color: var(--muted); text-align: right; }
@media (max-width: 520px) {
  .item-line { grid-template-columns: 1fr 52px 84px 28px; gap: 6px; }
  .item-line input, .item-line select { padding: 9px 8px; font-size: 15px; }
}

/* ===== Transaction list ===== */
.txn { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.txn-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.txn-code { font-weight: 800; font-family: ui-monospace, monospace; }
.txn-meta { font-size: 13px; color: var(--muted); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 8px; }
.txn-items { margin: 10px 0; font-size: 14px; }
.txn-items .li { display: flex; justify-content: space-between; padding: 2px 0; }
.txn-total { display: flex; justify-content: space-between; border-top: 1px dashed var(--line); padding-top: 8px; font-weight: 700; }
.txn-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.badge { font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 999px; white-space: nowrap; }
.b-gray { background: var(--gray-soft); color: var(--muted); }
.b-amber { background: var(--amber-soft); color: var(--amber); }
.b-blue { background: var(--blue-soft); color: var(--blue); }
.b-green { background: var(--green-soft); color: var(--green); }
.b-red { background: var(--red-soft); color: var(--red); }
.chip { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); }
.chip.bonus { background: var(--amber-soft); color: var(--amber); }

/* ===== Filters ===== */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.filters .full { grid-column: 1 / -1; }

/* ===== Table (products/users) ===== */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
.tbl th { color: var(--muted); font-size: 12px; text-transform: uppercase; }

/* Di HP: tabel jadi kartu bertumpuk supaya muat portrait (tanpa scroll samping) */
@media (max-width: 560px) {
  .tbl thead { display: none; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl tr { border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; margin-bottom: 10px; background: var(--surface); }
  .tbl td { border: none; padding: 7px 0; display: flex; justify-content: space-between; align-items: center; gap: 14px; text-align: right; }
  .tbl td:not(:last-child) { border-bottom: 1px dashed var(--line); }
  .tbl td::before { content: attr(data-label); font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; text-align: left; flex: 0 0 auto; }
  .tbl td[data-label=""]::before { content: ""; }
  .tbl td select, .tbl td input { width: auto; max-width: 62%; margin: 0; }
  .tbl td:last-child { justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
  .tbl td .vcell { text-align: right; line-height: 1.45; }
}
.tbl td .vcell { min-width: 0; }

/* ===== Proof thumbs ===== */
.proof { display: inline-flex; align-items: center; gap: 6px; }
.thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); cursor: pointer; }

/* ===== Photo modal ===== */
.photo-modal { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 80; display: grid; place-items: center; padding: 20px; }
.photo-modal img { max-width: 100%; max-height: 100%; border-radius: 10px; }

/* ===== Scan modal ===== */
.scan-modal { position: fixed; inset: 0; background: rgba(20,15,25,.92); z-index: 85; display: grid; place-items: center; padding: 16px; }
.scan-box { background: var(--surface); border-radius: var(--radius); padding: 14px; width: 100%; max-width: 420px; }
.scan-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; margin-bottom: 10px; }
.scan-region { width: 100%; border-radius: 10px; overflow: hidden; background: #000; min-height: 240px; }
.scan-region video { width: 100% !important; border-radius: 10px; }

/* Barcode input row di transaksi */
.scan-row { display: flex; gap: 8px; align-items: stretch; }
.scan-row input { flex: 1; }
.scan-row button { white-space: nowrap; }

/* ===== Toast ===== */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 90; box-shadow: var(--shadow); font-weight: 600; max-width: 90vw; }
.toast.err { background: var(--red); }

/* ===== Desktop ===== */
@media (min-width: 860px) {
  .sidebar { transform: translateX(0); }
  .backdrop { display: none !important; }
  #menuBtn { display: none; }
  .main { margin-left: 240px; }
  .topbar { padding-left: 256px; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
