:root {
  --primary: #1a56db;
  --danger: #dc2626;
  --green: #16a34a;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ===== Topbar ===== */
.topbar {
  background: var(--primary);
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  height: 58px;
}
.topbar h1 { font-size: 1.3rem; }
.topbar .sub { font-size: 0.8rem; opacity: .8; font-weight: normal; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.demo-badge { font-size: .72rem; opacity: .9; }
.clock { font-variant-numeric: tabular-nums; font-size: .95rem; }

/* ===== Layout ===== */
.layout {
  display: grid;
  grid-template-columns: 1fr 460px;
  gap: 14px;
  padding: 14px;
  height: calc(100vh - 58px);
}
.left-panel { overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.right-panel { overflow-y: auto; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.card h2 { font-size: 1.05rem; margin-bottom: 10px; }
.card h2 small { color: var(--muted); font-weight: normal; }

/* ===== Buttons ===== */
.btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: .9rem;
  transition: .15s;
}
.btn:hover { background: #f1f5f9; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { opacity: .9; }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; color: inherit; border-color: rgba(255,255,255,.4); }
.card .btn.ghost { color: var(--muted); border-color: var(--border); }
.btn.checkout {
  width: 100%;
  background: var(--green);
  color: #fff;
  font-size: 1.1rem;
  padding: 12px;
  margin-top: 8px;
}
.btn.checkout:disabled { background: #9ca3af; cursor: not-allowed; }
.btn.cash { font-size: .8rem; padding: 6px 10px; }

/* ===== Scanner ===== */
.reader { width: 100%; border-radius: 8px; overflow: hidden; background: #000; min-height: 60px; }
.reader video { border-radius: 8px; }
.scanner-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.manual-input { display: flex; gap: 8px; margin-top: 10px; }
.manual-input input {
  flex: 1; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
}
.scan-status { margin-top: 8px; font-size: .85rem; color: var(--muted); min-height: 20px; }
.scan-status.ok { color: var(--green); font-weight: 600; }
.scan-status.err { color: var(--danger); font-weight: 600; }

/* ===== Produk ===== */
.search {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 6px; margin-bottom: 10px;
}
.product-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.product-item {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px;
  cursor: pointer; transition: .15s;
}
.product-item:hover { border-color: var(--primary); background: #eff6ff; }
.product-item .name { font-size: .85rem; font-weight: 600; margin-bottom: 4px; }
.product-item .cat { font-size: .7rem; color: var(--muted); }
.product-item .price { color: var(--primary); font-weight: 700; font-size: .9rem; margin-top: 4px; }
.product-item .stock { font-size: .7rem; color: var(--muted); }
.product-item.out { opacity: .45; cursor: not-allowed; }

/* ===== Keranjang ===== */
.cart-card { display: flex; flex-direction: column; }
.cart-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.cart-table th {
  text-align: left; padding: 6px; border-bottom: 2px solid var(--border);
  font-size: .75rem; color: var(--muted);
}
.cart-table td { padding: 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.cart-table .empty { text-align: center; color: var(--muted); padding: 20px; }
.qty-btn {
  width: 22px; height: 22px; border: 1px solid var(--border); background: #fff;
  border-radius: 4px; cursor: pointer; margin: 0 2px;
}
.qty-input { width: 44px; text-align: center; border: 1px solid var(--border); border-radius: 4px; padding: 2px; }
.del-btn { color: var(--danger); cursor: pointer; border: none; background: none; font-size: 1rem; }

.totals { margin-top: 12px; border-top: 2px solid var(--border); padding-top: 10px; }
.totals .row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0; font-size: .95rem;
}
.totals .row.total { font-size: 1.25rem; color: var(--primary); }
.discount-input, .paid-input {
  width: 120px; padding: 5px 8px; border: 1px solid var(--border);
  border-radius: 6px; text-align: right;
}
.payment { margin-top: 12px; border-top: 2px dashed var(--border); padding-top: 10px; }
.payment .row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.payment select, .payment input {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
}
.quick-cash { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.change-row { font-size: 1.15rem; color: var(--green); margin-top: 4px; }

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal.hidden { display: none; }
.modal-box {
  background: #fff; border-radius: 12px; padding: 18px;
  width: min(560px, 92vw); max-height: 85vh; overflow-y: auto;
}
.modal-box.wide { width: min(760px, 94vw); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

.history-item {
  border: 1px solid var(--border); border-radius: 8px; padding: 10px;
  margin-bottom: 8px; cursor: pointer;
}
.history-item:hover { border-color: var(--primary); }
.history-item .inv { font-weight: 700; }
.history-item .meta { font-size: .8rem; color: var(--muted); }

.product-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.product-form input {
  flex: 1; min-width: 120px; padding: 8px; border: 1px solid var(--border); border-radius: 6px;
}
.manage-list { max-height: 55vh; overflow-y: auto; }
.manage-row {
  display: grid; grid-template-columns: 130px 1fr 100px 100px 70px 40px;
  gap: 8px; align-items: center; padding: 6px 4px;
  border-bottom: 1px solid var(--border); font-size: .82rem;
}
.manage-row input { padding: 4px 6px; border: 1px solid var(--border); border-radius: 4px; width: 100%; }

/* ===== Modal Pembayaran QRIS / Debit ===== */
.payment-box { text-align: center; }
.payment-amount { font-size: 1.15rem; margin-bottom: 12px; color: var(--primary); }
.demo-payment-note { margin: -4px 0 12px; color: var(--muted); font-size: .82rem; }
.qris-frame {
  border: 2px solid var(--primary); border-radius: 10px;
  padding: 12px; width: 280px; margin: 0 auto;
}
.qris-brand { font-weight: 700; color: var(--primary); font-size: 1.1rem; }
.qris-brand span { font-size: .75rem; color: var(--muted); font-weight: normal; }
#qrImage { margin: 8px 0; }
#qrImage svg { background: #fff; }
.qris-merchant { font-size: .72rem; color: var(--muted); }
.pay-status { margin-top: 12px; font-size: .9rem; color: var(--muted); min-height: 22px; }
.pay-status.ok { color: var(--green); font-weight: 700; }
.pay-status.err { color: var(--danger); font-weight: 700; }
.pay-actions { margin-top: 10px; }
.edc-frame {
  border: 2px solid var(--border); border-radius: 10px;
  padding: 14px; width: 300px; margin: 0 auto; background: #0f172a; color: #4ade80;
}
.edc-screen {
  font-family: 'Courier New', monospace; font-size: .95rem; line-height: 1.6;
  border: 1px solid #334155; border-radius: 6px; padding: 10px; margin-bottom: 10px;
}
.edc-row { display: flex; gap: 8px; }
.edc-row input, .edc-row select {
  flex: 1; padding: 8px; border-radius: 6px; border: 1px solid var(--border);
}

/* ===== Struk (thermal 58mm style) ===== */
.receipt-area { display: none; }
.receipt {
  width: 300px; margin: 0 auto; font-family: 'Courier New', monospace;
  font-size: 12px; color: #000; line-height: 1.35;
}
.receipt .center { text-align: center; }
.receipt .bold { font-weight: bold; }
.receipt hr { border: none; border-top: 1px dashed #000; margin: 6px 0; }
.receipt table { width: 100%; border-collapse: collapse; }
.receipt table td { padding: 1px 0; vertical-align: top; }
.receipt .right { text-align: right; white-space: nowrap; }

@media print {
  body * { visibility: hidden; }
  .receipt-area { display: block !important; position: absolute; top: 0; left: 0; width: 100%; }
  .receipt-area, .receipt-area * { visibility: visible; }
  .receipt { width: 100%; }
}

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: .9rem; z-index: 200; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.toast.hidden { display: none; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--green); }

@media (max-width: 900px) {
  body { height: auto; min-height: 100vh; overflow-x: hidden; overflow-y: auto; }
  .topbar { height: auto; min-height: 58px; flex-wrap: wrap; gap: 8px; }
  .topbar-right { flex-wrap: wrap; gap: 6px; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .left-panel, .right-panel { overflow: visible; }
}

@media (max-width: 520px) {
  .topbar { align-items: flex-start; padding: 10px 12px; }
  .topbar h1 { font-size: 1.05rem; }
  .topbar-right { width: 100%; }
  .demo-badge { width: 100%; }
  .topbar-right .btn { padding: 7px 9px; font-size: .78rem; }
  .layout { padding: 8px; gap: 8px; }
  .card { padding: 10px; }
  .cart-table { font-size: .72rem; }
  .cart-table th, .cart-table td { padding: 4px 2px; }
  .cart-table th:nth-child(2), .cart-table td:nth-child(2) { display: none; }
  .qty-input { width: 34px; }
  .qty-btn { margin: 0; }
  .discount-input, .paid-input { width: 90px; }
}