:root {
  --bg: #f4f1ff; --card: #ffffff; --ink: #0f172a; --muted: #64748b;
  --primary: #7c3aed; --primary-dark: #5b21b6; --secondary: #0ea5e9;
  --accent: #10b981; --pink: #ec4899; --orange: #f97316; --sun: #f59e0b;
  --danger: #ef4444; --warn: #f59e0b; --line: #e5e0ff;
  --sidebar: #2e1065; --sidebar-ink: #ddd6fe;
  --radius: 12px;
  --tap: 48px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif; color: var(--ink); font-size: 17px; line-height: 1.55;
  background: linear-gradient(160deg, #ede9fe 0%, #fdf4ff 45%, #ecfeff 100%); background-attachment: fixed; }
a { color: #6d28d9; text-decoration: none; font-weight: 600; }
a:hover { text-decoration: underline; }
button, .pay-opt, .prod-card, .qty-btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(135deg, #4c1d95 0%, #7c3aed 35%, #db2777 70%, #0ea5e9 100%); }
.auth-card { background: #fff; border-radius: 18px; padding: 32px; width: 100%; max-width: 460px;
  box-shadow: 0 24px 70px rgba(76,29,149,.5); border-top: 8px solid; border-image: linear-gradient(90deg, #8b5cf6, #ec4899, #0ea5e9) 1; border-top-width: 8px; }
.auth-card h1 { margin: 0 0 4px; font-size: 28px; background: linear-gradient(90deg, #6d28d9, #db2777); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-card p.sub { margin: 0 0 20px; color: var(--muted); font-size: 16px; }

/* ---------- Form ---------- */
label.lbl { display: block; font-size: 15px; font-weight: 600; margin: 12px 0 6px; color: #4c1d95; }
input[type=text], input[type=password], input[type=number], input[type=email], input[type=date], input[type=tel], input[type=file], select, textarea {
  width: 100%; padding: 12px 14px; border: 2px solid var(--line); border-radius: 10px; font-size: 16px; background: #fff; color: var(--ink); min-height: var(--tap);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124,58,237,.2); }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > div { flex: 1; min-width: 160px; }
.btn { display: inline-block; border: 0; border-radius: 10px; padding: 12px 20px; font-size: 16px; font-weight: 700; cursor: pointer; color: #fff; min-height: 44px;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9); box-shadow: 0 4px 12px rgba(124,58,237,.35); transition: transform .08s ease, box-shadow .08s ease; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(124,58,237,.45); text-decoration: none; color: #fff; }
.btn.success { background: linear-gradient(135deg, #34d399, #059669); box-shadow: 0 4px 12px rgba(16,185,129,.35); }
.btn.danger { background: linear-gradient(135deg, #f87171, #dc2626); box-shadow: 0 4px 12px rgba(239,68,68,.35); }
.btn.warn { background: linear-gradient(135deg, #fbbf24, #d97706); box-shadow: 0 4px 12px rgba(245,158,11,.35); }
.btn.ghost { background: #ede9fe; color: #5b21b6; box-shadow: none; }
.btn.ghost:hover { background: #ddd6fe; }
.btn.big { font-size: 22px; padding: 18px 24px; border-radius: 12px; width: 100%; min-height: 60px; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ---------- Layout owner ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 260px; padding: 20px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; flex-shrink: 0; z-index: 40;
  background: linear-gradient(180deg, #1e1b4b 0%, #4c1d95 55%, #7c3aed 100%); color: var(--sidebar-ink); }
.sidebar .brand { color: #fff; font-weight: 800; font-size: 21px; padding: 0 12px 16px; text-shadow: 0 2px 8px rgba(0,0,0,.4); }
.sidebar .brand::after { content: ""; display: block; height: 4px; border-radius: 4px; margin-top: 8px;
  background: linear-gradient(90deg, #f0abfc, #ec4899, #0ea5e9); }
.sidebar a.nav { display: block; color: var(--sidebar-ink); padding: 13px 14px; border-radius: 10px; margin: 3px 0; font-size: 16px; font-weight: 600; }
.sidebar a.nav:hover { background: rgba(255,255,255,.14); color: #fff; text-decoration: none; }
.sidebar a.nav.active { background: linear-gradient(90deg, #8b5cf6, #ec4899); color: #fff; text-decoration: none; box-shadow: 0 4px 12px rgba(0,0,0,.3); }
.sidebar .nav-sec { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: #c4b5fd; padding: 14px 12px 4px; }
.main { flex: 1; min-width: 0; }
.topbar { background: #fff; padding: 12px 24px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 30; border-bottom: 4px solid; border-image: linear-gradient(90deg, #8b5cf6, #ec4899, #0ea5e9, #10b981) 1; border-bottom-width: 4px; }
.topbar strong { color: #5b21b6; font-size: 18px; }
.topbar .who { font-size: 15px; color: var(--muted); }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.content { padding: 24px; max-width: 1200px; }
.content h2.page-title { margin: 0 0 16px; font-size: 27px; font-weight: 800;
  background: linear-gradient(90deg, #6d28d9, #db2777 60%, #0ea5e9); -webkit-background-clip: text; background-clip: text; color: transparent; }
.menu-btn { display: none; border: 2px solid #c4b5fd; background: #f5f3ff; color: #6d28d9; border-radius: 10px; width: var(--tap); height: var(--tap); font-size: 22px; cursor: pointer; flex-shrink: 0; }
.scrim { display: none; }

/* ---------- Cards / stats ---------- */
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.card { background: var(--card); border: 1px solid #e5e0ff; border-radius: var(--radius); padding: 20px;
  box-shadow: 0 4px 14px rgba(124,58,237,.1); font-size: 16px; }
.card h3 { margin: 0 0 12px; font-size: 19px; color: #5b21b6; border-left: 5px solid #ec4899; padding-left: 10px; }
.stat { color: #fff; border: none; position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; right: -40px; top: -40px; width: 130px; height: 130px; border-radius: 50%; background: rgba(255,255,255,.16); }
.stat .num { font-size: 30px; font-weight: 800; }
.stat .lbl2 { font-size: 15px; color: rgba(255,255,255,.88); }
.stat .delta-up { color: #d1fae5; font-size: 14px; font-weight: 700; }
.stat .delta-dn { color: #fecaca; font-size: 14px; font-weight: 700; }
.grid.stats .stat:nth-child(4n+1) { background: linear-gradient(135deg, #8b5cf6, #6d28d9); box-shadow: 0 6px 16px rgba(124,58,237,.4); }
.grid.stats .stat:nth-child(4n+2) { background: linear-gradient(135deg, #38bdf8, #2563eb); box-shadow: 0 6px 16px rgba(37,99,235,.4); }
.grid.stats .stat:nth-child(4n+3) { background: linear-gradient(135deg, #34d399, #059669); box-shadow: 0 6px 16px rgba(16,185,129,.4); }
.grid.stats .stat:nth-child(4n+4) { background: linear-gradient(135deg, #fbbf24, #f97316); box-shadow: 0 6px 16px rgba(249,115,22,.4); }

/* ---------- Table ---------- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 15.5px; }
table.tbl th, table.tbl td { padding: 12px 14px; border-bottom: 1px solid #ede9fe; text-align: left; }
table.tbl th { background: linear-gradient(180deg, #ede9fe, #e0e7ff); font-size: 13.5px; text-transform: uppercase; letter-spacing: .04em; color: #5b21b6; white-space: nowrap; }
table.tbl tbody tr:nth-child(even) td { background: #faf8ff; }
table.tbl tr:hover td { background: #f1eaff; }
.badge { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 13.5px; font-weight: 700; white-space: nowrap; }
.badge.green { background: #a7f3d0; color: #065f46; }
.badge.red { background: #fecaca; color: #991b1b; }
.badge.gray { background: #e2e8f0; color: #475569; }
.badge.blue { background: #bae6fd; color: #0c4a6e; }
.badge.yellow { background: #fde68a; color: #92400e; }

/* ---------- Alert / flash ---------- */
.alert { padding: 14px 18px; border-radius: 10px; margin-bottom: 16px; font-size: 16px; border-left: 6px solid; }
.alert.ok { background: #d1fae5; color: #065f46; border-left-color: #10b981; }
.alert.err { background: #fee2e2; color: #991b1b; border-left-color: #ef4444; }

/* ---------- Kasir POS ---------- */
.pos-top { color: #fff; padding: 12px 20px; display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: linear-gradient(120deg, #4c1d95 0%, #7c3aed 55%, #db2777 100%); }
.pos-top .store { font-weight: 800; font-size: 21px; text-shadow: 0 2px 6px rgba(0,0,0,.3); }
.pos-top .meta { font-size: 14.5px; color: #f5d0fe; }
.pos-top .btn.ghost { background: rgba(255,255,255,.18); color: #fff; box-shadow: none; }
.pos-top .btn.ghost:hover { background: rgba(255,255,255,.3); }
.pos-nav { background: #2e1065; padding: 8px 16px; display: flex; gap: 8px; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.pos-nav a { color: #ddd6fe; padding: 10px 18px; border-radius: 10px; font-size: 16px; font-weight: 600; white-space: nowrap; }
.pos-nav a:hover { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.pos-nav a.active { background: linear-gradient(90deg, #8b5cf6, #ec4899); color: #fff; text-decoration: none; box-shadow: 0 3px 10px rgba(0,0,0,.35); }
.pos-wrap { display: grid; grid-template-columns: 1fr 400px; gap: 16px; padding: 16px 20px; max-width: 1400px; margin: 0 auto; }
.scan-input { font-size: 20px !important; padding: 16px 18px !important; border: 2px solid #8b5cf6 !important; min-height: 60px;
  box-shadow: 0 0 0 3px rgba(139,92,246,.15); background: #fbfaff !important; }
.scan-row { display: flex; gap: 10px; align-items: stretch; }
.scan-row .scan-input { flex: 1; min-width: 0; }
.scan-row .btn { flex-shrink: 0; min-width: 76px; font-size: 20px; }
#scan-qty { max-width: 84px; flex-shrink: 0; text-align: center; font-size: 20px; font-weight: 800; color: #6d28d9; }
.qty-input { width: 66px; text-align: center; padding: 6px 4px !important; font-size: 17px; font-weight: 800; min-height: 44px; color: #6d28d9; }
.prod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(175px, 1fr)); gap: 12px; margin-top: 12px; }
.prod-card { background: #fff; border: 2px solid #e9e4ff; border-top: 5px solid #c4b5fd; border-radius: 12px; padding: 14px; cursor: pointer; transition: transform .08s ease, box-shadow .08s ease; }
.prod-card:nth-child(4n+1) { border-top-color: #8b5cf6; }
.prod-card:nth-child(4n+2) { border-top-color: #ec4899; }
.prod-card:nth-child(4n+3) { border-top-color: #0ea5e9; }
.prod-card:nth-child(4n+4) { border-top-color: #10b981; }
.prod-card:hover { border-color: #8b5cf6; box-shadow: 0 6px 16px rgba(139,92,246,.3); transform: translateY(-2px); }
.prod-card .nm { font-weight: 700; font-size: 16.5px; }
.prod-card .pr { font-weight: 800; font-size: 18px; background: linear-gradient(90deg, #6d28d9, #db2777); -webkit-background-clip: text; background-clip: text; color: transparent; }
.prod-card .st { font-size: 14px; color: var(--muted); }
.cart { background: #fff; border: 2px solid #c4b5fd; border-radius: 14px; padding: 18px; position: sticky; top: 16px; align-self: start; font-size: 16px;
  box-shadow: 0 6px 20px rgba(124,58,237,.18); }
.cart h3 { font-size: 20px; color: #5b21b6; border-left: 5px solid #0ea5e9; padding-left: 10px; }
.cart-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 2px dashed #e9d5e1; font-size: 16px; }
.cart-item .qty { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.qty-btn { min-width: 44px; min-height: 44px; border-radius: 10px; border: 2px solid #ddd6fe; background: #f5f3ff; color: #6d28d9; font-size: 20px; font-weight: 800; cursor: pointer; }
.qty-btn:hover { background: #ede9fe; border-color: #8b5cf6; }
.total-big { font-size: 40px; font-weight: 800; background: linear-gradient(90deg, #6d28d9, #db2777); -webkit-background-clip: text; background-clip: text; color: transparent; }
.pay-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); gap: 10px; margin: 12px 0; }
.pay-opt { border: 2px solid #e9e4ff; border-radius: 12px; padding: 14px 8px; text-align: center; cursor: pointer; font-weight: 700; font-size: 16px;
  min-height: 56px; display: flex; align-items: center; justify-content: center; background: #fbfaff; transition: transform .08s ease; }
.pay-opt:hover { border-color: #a78bfa; transform: translateY(-1px); }
.pay-opt.sel { border-color: #10b981; background: linear-gradient(180deg, #ecfdf5, #a7f3d0); box-shadow: 0 0 0 3px rgba(16,185,129,.25); }
.change-big { font-size: 32px; font-weight: 800; background: linear-gradient(90deg, #059669, #0d9488); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(46,16,101,.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 16px; padding: 24px; max-width: 520px; width: 100%; max-height: 90vh; overflow-y: auto; font-size: 16px;
  border-top: 8px solid #8b5cf6; box-shadow: 0 20px 60px rgba(76,29,149,.4); }
.modal h3 { color: #5b21b6; }

/* ---------- Toolbar / pagination ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.toolbar > div { min-width: 150px; }
.pagination { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.pagination a, .pagination span { padding: 10px 16px; border: 2px solid #e9e4ff; border-radius: 8px; background: #fff; color: #6d28d9; font-size: 16px; min-height: 44px; display: inline-flex; align-items: center; }
.pagination span.cur { background: linear-gradient(135deg, #8b5cf6, #ec4899); color: #fff; border-color: transparent; }
canvas.chart { width: 100%; height: 260px; }

/* ---------- Dokumen cetak: thermal 58/80mm & A4 (tetap hitam-putih agar hemat tinta printer) ---------- */
/* Preview di layar */
#doc-thermal .print-doc, #doc-a4 .print-doc { display: none; }
.preview-box { background: #fff; border: 2px solid #c4b5fd; border-radius: 10px; padding: 16px; margin-bottom: 12px; overflow-x: auto; }
.preview-box .struk { display: block; margin: 0 auto; font-family: "Courier New", monospace; font-size: 12px; color: #000; }
.preview-58 .struk { width: 48mm; }
.preview-80 .struk { width: 72mm; }
.preview-a4 .invoice-a4 { max-width: 100%; }
/* Struk thermal (dipakai di preview & cetak) */
.struk img.logo { max-width: 60mm; max-height: 25mm; display: block; margin: 0 auto; }
.struk .c { text-align: center; }
.struk hr { border: 0; border-top: 1px dashed #000; margin: 6px 0; }
.struk table { width: 100%; border-collapse: collapse; font-size: 12px; }
/* Invoice A4 (dipakai di preview & cetak) */
.invoice-a4 { font-family: Arial, Helvetica, sans-serif; color: #000; background: #fff; max-width: 700px; margin: 0 auto; }
.invoice-a4 .kop { display: flex; gap: 14px; align-items: center; border-bottom: 3px double #000; padding-bottom: 10px; }
.invoice-a4 .kop img { max-height: 64px; max-width: 140px; }
.invoice-a4 .kop-name { font-size: 22px; font-weight: 800; }
.invoice-a4 .kop-addr { font-size: 13px; }
.invoice-a4 .inv-title { text-align: center; font-size: 20px; font-weight: 800; margin: 12px 0 4px; letter-spacing: 2px; }
.invoice-a4 .inv-title span { font-size: 15px; letter-spacing: 0; }
.invoice-a4 table.meta { width: 100%; font-size: 13.5px; margin: 8px 0; }
.invoice-a4 table.meta td { padding: 2px 4px; }
.invoice-a4 table.items { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-top: 6px; }
.invoice-a4 table.items th, .invoice-a4 table.items td { border: 1px solid #000; padding: 6px 8px; }
.invoice-a4 table.items th { background: #eee; }
.invoice-a4 table.sum { margin-left: auto; margin-top: 8px; font-size: 14px; border-collapse: collapse; width: 260px; }
.invoice-a4 table.sum td { padding: 3px 6px; }
.invoice-a4 table.sum td:last-child { text-align: right; }
.invoice-a4 table.sum tr.grand td { font-weight: 800; font-size: 16px; border-top: 2px solid #000; }
.invoice-a4 .foot { text-align: center; font-size: 13px; margin-top: 14px; }
.invoice-a4 .ttd { display: flex; justify-content: space-between; margin-top: 26px; font-size: 13.5px; text-align: center; }

@media print {
  body[class*="print-"] > *:not([id^="doc-"]) { display: none !important; }
  body[class*="print-"] { background: #fff; }
  .no-print, #print-preview, #size-pick { display: none !important; }
  /* Thermal 58mm */
  body.print-58 #doc-thermal .print-doc { display: block !important; width: 48mm; margin: 0 auto; font-family: "Courier New", monospace; font-size: 11px; color: #000; }
  body.print-58 #doc-a4, body.print-80 #doc-a4, body.print-a4 #doc-thermal { display: none !important; }
  /* Thermal 80mm */
  body.print-80 #doc-thermal .print-doc { display: block !important; width: 72mm; margin: 0 auto; font-family: "Courier New", monospace; font-size: 12px; color: #000; }
  /* Kertas A4 */
  body.print-a4 #doc-a4 .print-doc { display: block !important; }
  @page { margin: 10mm; }
}

/* ==================================================
   RESPONSIVE
   ================================================== */

/* Tablet landscape / laptop kecil */
@media (max-width: 1100px) {
  .pos-wrap { grid-template-columns: 1fr 340px; padding: 12px; }
}

/* Sticky bottom bar (khusus layar kecil, diisi via JS) */
.pos-stickybar { display: none; }

/* Tablet portrait: sidebar jadi drawer, POS 1 kolom */
@media (max-width: 900px) {
  body { font-size: 16.5px; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-105%); transition: transform .25s ease; width: 280px; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .sidebar.open { transform: translateX(0); }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 35; }
  .scrim.show { display: block; }
  .content { padding: 16px; }
  .content h2.page-title { font-size: 23px; }
  .topbar { padding: 10px 16px; }
  .pos-wrap { grid-template-columns: 1fr; padding-bottom: 96px; }
  .cart { position: static; }
  .pos-stickybar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; color: #fff;
    background: linear-gradient(90deg, #4c1d95, #7c3aed 60%, #db2777);
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); align-items: center; gap: 10px; box-shadow: 0 -2px 12px rgba(0,0,0,.3); }
  .pos-stickybar .sb-total { font-size: 21px; font-weight: 800; }
  .pos-stickybar .btn { min-height: 50px; }
  .grid.two { grid-template-columns: 1fr; }
  .toolbar > div { flex: 1 1 45%; min-width: 140px; }
  .toolbar .btn, .toolbar button { width: 100%; }
}

/* HP */
@media (max-width: 600px) {
  body { font-size: 16px; }
  .auth-wrap { padding: 16px; }
  .auth-card { padding: 24px 20px; }
  .auth-card h1 { font-size: 25px; }
  .content { padding: 12px; }
  .card { padding: 16px; }
  .grid { gap: 12px; }
  .grid.stats { grid-template-columns: repeat(2, 1fr); }
  .stat .num { font-size: 22px; }
  .stat .lbl2 { font-size: 13.5px; }
  .content h2.page-title { font-size: 21px; }
  table.tbl { font-size: 14.5px; }
  table.tbl th, table.tbl td { padding: 10px 10px; }
  .prod-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .prod-card { padding: 12px; }
  .prod-card .nm { font-size: 15px; }
  .prod-card .pr { font-size: 17px; }
  .total-big { font-size: 34px; }
  .change-big { font-size: 28px; }
  .pay-grid { grid-template-columns: repeat(3, 1fr); }
  .pay-opt { font-size: 15px; min-height: 52px; padding: 12px 4px; }
  .pos-top { padding: 10px 14px; }
  .pos-top .store { font-size: 19px; }
  .pos-wrap { padding: 10px; }
  .form-row > div { min-width: 100%; }
  .modal { padding: 20px 16px; border-radius: 12px; }
  .btn.big { font-size: 20px; }
  .topbar .actions .btn { padding: 10px 14px; font-size: 15px; }
  canvas.chart { height: 220px; }
}

/* HP kecil */
@media (max-width: 380px) {
  .grid.stats { grid-template-columns: 1fr 1fr; }
  .stat .num { font-size: 19px; }
  .pay-grid { grid-template-columns: repeat(2, 1fr); }
}
