:root {
  --bg: #f2f4f8;
  --panel: #ffffff;
  --border: #e2e6ee;
  --text: #1b2430;
  --muted: #6b7686;
  --primary: #1f6feb;
  --primary-dark: #1559c9;
  --danger: #d64545;
  --green: #2f9e44;
  --amber: #e8a90c;
  --shadow: 0 2px 10px rgba(20, 30, 50, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #0e2a47, #1f6feb); }
.login-card { background: #fff; padding: 32px; border-radius: 14px; width: 340px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card p.sub { color: var(--muted); margin: 0 0 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 5px; font-weight: 600; color: var(--text); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fafbfc; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); background: #fff; }
.btn { border: none; border-radius: 8px; padding: 10px 16px; font-weight: 600; background: #e8ebf1; color: var(--text); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: #fbeaec; color: var(--danger); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.row-actions { display: flex; gap: 4px; flex-wrap: nowrap; align-items: center; white-space: nowrap; }
.row-actions .btn.sm { padding: 5px 7px; font-size: 13px; line-height: 1; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.err { color: var(--danger); min-height: 18px; font-size: 13px; margin-top: 6px; }

/* ---------- App shell ---------- */
.app { display: flex; height: 100vh; }
.sidebar { width: 210px; background: #0e1a29; color: #cbd6e4; display: flex; flex-direction: column; flex-shrink: 0; }
.brand { padding: 18px; font-size: 17px; font-weight: 700; color: #fff; border-bottom: 1px solid #1e3147; }
.brand small { display: block; color: #7f93ad; font-size: 11px; font-weight: 400; margin-top: 2px; }
.nav { flex: 1; padding: 10px; overflow-y: auto; }
.nav-group { margin-bottom: 6px; }
.nav-head { display: flex; width: 100%; align-items: center; gap: 8px; padding: 10px 12px 7px; margin-top: 4px; background: none; border: none; color: #e8eef7; border-bottom: 1px solid rgba(120, 150, 185, .25); border-radius: 0; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; }
.nav-head:hover { color: #fff; }
.nav-caret { margin-left: auto; font-size: 11px; opacity: .75; }
.nav-body { display: none; padding-top: 4px; }
.nav-body.open { display: block; }
.nav-item { display: flex; width: 100%; align-items: center; gap: 9px; text-align: left; padding: 8px 12px; margin-bottom: 2px; background: none; border: none; color: #9db0c8; border-radius: 8px; font-size: 13.5px; }
.nav-badge { margin-left: auto; background: #e64545; color: #fff; border-radius: 10px; font-size: 10px; font-weight: 700; line-height: 1; padding: 3px 6px; min-width: 16px; text-align: center; }.nav-item.active .nav-badge { background: rgba(255,255,255,.85); color: var(--primary); }
.memo-banner { display: flex; align-items: center; gap: 10px; padding: 9px 22px; font-size: 13px; background: #fff7e0; border-bottom: 1px solid #f0d98c; color: #6b4f00; }
.mock-banner { display: flex; align-items: center; gap: 10px; padding: 10px 22px; font-size: 13px; font-weight: 700; background: repeating-linear-gradient(45deg, #d64545, #d64545 14px, #b03535 14px, #b03535 28px); color: #fff; border-bottom: 2px solid #8f2020; }
.mock-banner-ico { font-size: 16px; }
.mock-banner-txt { flex: 1; letter-spacing: .3px; }
.mock-pill { display: inline-block; background: #d64545; color: #fff; font-size: 11px; font-weight: 800; letter-spacing: 1px; padding: 3px 10px; border-radius: 20px; margin-left: 8px; }
.memo-banner.bad { background: #fdeaea; border-bottom-color: #eeb9b9; color: #7a2020; }
.memo-banner-ico { font-size: 15px; }
.memo-banner-txt { font-weight: 600; }
.nav-item:hover { background: #16283d; color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-icon { width: 18px; text-align: center; flex-shrink: 0; font-size: 15px; }
.side-foot { padding: 14px; border-top: 1px solid #1e3147; }
.side-foot .who { font-size: 13px; }
.side-foot .who b { color: #fff; }
.side-foot .logout { margin-top: 8px; background: none; color: #f2b8b8; border: none; }

.lang-toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; margin-top: 0; font-size: 12px; color: #4a5568; }
.lang-toggle input { display: none; }
.lang-toggle .track { width: 44px; height: 22px; border-radius: 11px; background: #cbd5e0; position: relative; transition: background .15s; flex-shrink: 0; }
.lang-toggle input:checked + .track { background: #1f6feb; }
.lang-toggle .thumb { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; font-size: 10px; line-height: 18px; text-align: center; color: #1f6feb; font-weight: 700; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: left .15s; }
.lang-toggle input:checked + .track .thumb { left: 24px; color: #fff; background: #fff; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar { background: var(--panel); border-bottom: 1px solid var(--border); padding: 14px 22px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow); z-index: 2; }
.topbar h2 { margin: 0; font-size: 18px; }
.topbar .spacer { flex: 1; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { padding: 6px 14px; border: 1px solid var(--border); border-radius: 20px; background: #fff; color: var(--text); cursor: pointer; font-size: 13px; }
.tabs button:hover { border-color: var(--primary); }
.tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.content { flex: 1; overflow: auto; padding: 22px; }

/* ---------- Cards / tables ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.stat .lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat .val { font-size: 24px; font-weight: 700; margin-top: 6px; }
.stat .val.green { color: var(--green); }
.stat .val.red { color: var(--danger); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
tr:hover td { background: #f7f9fc; }
.money { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.right { text-align: right; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.pill.ok { background: #e6f6ea; color: var(--green); }
.pill.bad { background: #fdecec; color: var(--danger); }
.pill.warn { background: #fbf1da; color: #8a6d1a; }

/* ---------- POS ---------- */
.pos { display: grid; grid-template-columns: 1fr 340px; gap: 16px; height: 100%; }
.catbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.catbar button { background: #fff; border: 1px solid var(--border); border-radius: 20px; padding: 6px 14px; }
.catbar button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.searchbar { display: flex; gap: 8px; margin-bottom: 12px; }
.searchbar input { flex: 1; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.prod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.prod-tile { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 12px; text-align: left; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.prod-tile:hover { border-color: var(--primary); }
.prod-tile .name { font-weight: 600; }
.prod-tile .price { color: var(--primary); font-weight: 700; font-size: 16px; }
.prod-tile .stock { color: var(--muted); font-size: 12px; }
.prod-tile.out { opacity: .5; }
.prod-tile .tile-img { width: 100%; height: 80px; object-fit: cover; border-radius: 6px; margin-bottom: 4px; }
.prod-tile .unit-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.prod-tile .unit-chip { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; font-size: 11px; padding: 2px 8px; color: var(--primary); cursor: pointer; }
.prod-tile .unit-chip:hover { background: var(--primary); color: #fff; }
.cart { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.cart-head { padding: 14px; border-bottom: 1px solid var(--border); font-weight: 700; }
.cart-items { flex: 1; overflow: auto; padding: 8px; }
.cart-item { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; }
.cart-item:hover { background: #f7f9fc; }
.cart-item .ci-name { flex: 1; }
.cart-item .ci-name .u { color: var(--muted); font-size: 12px; }
.cart-item .qtybox { display: flex; align-items: center; gap: 6px; }
.cart-item .qtybox button { width: 26px; height: 26px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.cart-item .line { width: 88px; text-align: right; font-weight: 600; }
.cart-foot { border-top: 1px solid var(--border); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.cart-foot .row { display: flex; justify-content: space-between; }
.cart-foot .row.total { font-size: 18px; font-weight: 700; }
.cart-actions { display: flex; gap: 8px; }
.cart-actions .btn { flex: 1; }
.btn.checkout { background: var(--green); color: #fff; font-size: 16px; padding: 14px; }
.btn.checkout:hover { background: #2b8a3a; }
.member-box { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: #f7f9fc; font-size: 12px; }
.member-box-inner { display: flex; flex-direction: column; gap: 2px; }
.member-box input[type=number] { padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; }
.vat-sheet .field label { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.vat-sheet .field label .auto { font-size: 10px; color: var(--green); font-weight: 600; text-transform: uppercase; }
.vat-sheet input[readonly] { background: #f5f7fa; }
.grid { display: grid; gap: 10px; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input, .toolbar select { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(10,20,35,.5); display: grid; place-items: center; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: min(520px, 92vw); max-height: 90vh; overflow: auto; padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; position: relative; }
.modal-head h3 { margin: 0; flex: 1; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Receipt modal ---------- */
.receipt-sheet { font-size: 12px; line-height: 1.5; }
.receipt-sheet .r-head { text-align: center; }
.receipt-sheet .r-items td { padding: 2px 6px; }
.receipt-actions { display: flex; gap: 8px; }

/* ---------- Print ---------- */
#print-root { display: none; }
@media print {
  body * { visibility: hidden; }
  #print-root, #print-root * { visibility: visible; }
  #print-root { display: block; position: absolute; left: 0; top: 0; width: 100%; }
  .sheet.thermal { margin: 0 auto; }
  .sheet.thermal58 { width: 58mm; }
  .sheet.thermal80 { width: 80mm; }
  .sheet.a4 { width: 190mm; padding: 12mm; }
  .sheet a, .sheet button { display: none; }
}

/* ---------- Professional thermal receipt ---------- */
.t-receipt { font-family: 'Consolas', 'Menlo', monospace; color: #111; font-size: 11px; line-height: 1.35; }
.t-receipt .t-center { text-align: center; }
.t-receipt .t-name { font-size: 13px; font-weight: 700; letter-spacing: .3px; }
.t-receipt .t-shop { color: #333; font-size: 10px; }
.t-receipt .t-shop .t-phone { color: #555; }
.t-receipt .t-tax { font-size: 10px; }
.t-receipt .t-divider { border: none; border-top: 1px dashed #333; margin: 6px 0; }
.t-receipt .t-divider.solid { border-top-style: solid; }
.t-receipt .t-receipt-no { font-size: 12px; font-weight: 700; }
.t-receipt .t-meta { font-size: 10px; color: #222; }
.t-receipt table.t-items { width: 100%; border-collapse: collapse; font-size: 11px; }
.t-receipt table.t-items th { text-align: left; font-size: 9px; text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid #333; padding: 3px 2px; }
.t-receipt table.t-items td { padding: 2px 2px; vertical-align: top; }
.t-receipt table.t-items tr.t-sub td { border-top: 1px dashed #999; padding-top: 4px; }
.t-receipt .t-total { font-size: 13px; font-weight: 700; }
.t-receipt .t-total .t-amt { font-size: 15px; }
.t-receipt .t-paid { font-size: 11px; }
.t-receipt .t-fiscal { border: 1px solid #333; padding: 6px 5px; margin-top: 6px; font-size: 9px; line-height: 1.4; }
.t-receipt .t-fiscal .t-f-head { text-align: center; font-weight: 700; letter-spacing: .5px; border-bottom: 1px solid #333; padding-bottom: 3px; margin-bottom: 4px; }
.t-receipt .t-qr { text-align: center; margin: 6px 0 2px; }
.t-receipt .t-url { word-break: break-all; word-wrap: break-word; font-size: 8.5px; color: #333; }
.t-receipt .t-footer { text-align: center; font-size: 9px; color: #555; margin-top: 8px; border-top: 1px solid #999; padding-top: 4px; }
.t-receipt .t-row { display: flex; justify-content: space-between; padding: 1px 0; font-size: 10px; }
.t-receipt .right { text-align: right; }
.t-receipt .t-totals { margin-top: 4px; }
.t-receipt .t-total { border-top: 1px dashed #333; margin-top: 2px; padding-top: 3px; }
.t-receipt .t-total .t-amt { color: #000; }
.t-receipt .t-itemline { margin: 2px 0; }
.t-receipt .t-itemline .t-il-name { font-size: 10px; }
.t-receipt .t-itemline .t-il-line { display: flex; justify-content: space-between; font-size: 10px; }

/* ---------- Responsive (desktop default above) ---------- */
/* New structural helpers (desktop: mostly hidden / static) */
.menu-btn { display: none; }
.side-close { display: none; background: none; border: none; color: #9db0c8; font-size: 16px; padding: 4px 8px; }
.side-head { display: flex; align-items: center; justify-content: space-between; }
.nav-backdrop { display: none; }
.cart-open { display: none; }
.cart-close { display: none; }
.cart-backdrop { display: none; }
.pos-goods { display: flex; flex-direction: column; min-width: 0; }

/* ---------- Tablet (≤1024px) ---------- */
@media (max-width: 1024px) {
  .sidebar { width: 190px; }
  .content { padding: 16px; }
  .pos { grid-template-columns: 1fr 300px; }
  .prod-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

/* ---------- Mobile (≤768px) ---------- */
@media (max-width: 768px) {
  body.nav-open { overflow: hidden; }

  /* Sidebar becomes a slide-in drawer with a hamburger opener. */
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; background: none; border: none; font-size: 20px; color: var(--text); padding: 4px 8px; margin-right: 2px; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 78vw; max-width: 300px;
    z-index: 60; transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,.2);
  }
  .sidebar.open { transform: translateX(0); }
  .side-close { display: block; }
  .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(10,16,26,.5); z-index: 55; opacity: 0; pointer-events: none; transition: opacity .22s ease; }
  .nav-backdrop.show { opacity: 1; pointer-events: auto; }

  /* Topbar stays visible with hamburger. */
  .topbar { padding: 10px 14px; }
  .topbar h2 { font-size: 16px; }

  /* Content */
  .content { padding: 12px; }

  /* POS: goods on top; cart becomes a bottom drawer. */
  .pos { display: block; height: auto; }
  .pos-goods { padding-bottom: 12px; }
  .prod-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .prod-tile { padding: 10px; }
  .cart-open { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
  .cart {
    position: fixed; left: 0; right: 0; bottom: 0; max-height: 82vh;
    border-radius: 16px 16px 0 0; z-index: 65;
    transform: translateY(110%); transition: transform .25s ease;
    box-shadow: 0 -6px 24px rgba(0,0,0,.22);
  }
  .cart.open { transform: translateY(0); }
  .cart-close { display: block; }
  .cart-backdrop { display: block; position: fixed; inset: 0; background: rgba(10,16,26,.45); z-index: 62; opacity: 0; pointer-events: none; transition: opacity .25s ease; }
  .cart-backdrop.show { opacity: 1; pointer-events: auto; }
  .cart-head { position: sticky; top: 0; background: var(--panel); display: flex; align-items: center; justify-content: space-between; }
  .cart-foot { padding: 12px; }

  /* Tables: allow horizontal scroll on small screens. */
  .card { overflow-x: auto; }
  table { min-width: 560px; }
  .card table { min-width: 560px; }

  /* Toolbars wrap cleanly. */
  .toolbar { gap: 8px; }
  .toolbar input, .toolbar select { max-width: 100%; }
  .row-actions { flex-wrap: wrap; }

  /* Cards row stats */
  .cards-row { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }

  /* Modal fits small screens. */
  .modal { width: 92vw !important; max-height: 90vh; overflow-y: auto; }
  .login-card { width: 90vw; }
}

/* ---------- Small phones (≤480px) ---------- */
@media (max-width: 480px) {
  .prod-grid { grid-template-columns: repeat(2, 1fr); }
  .brand { font-size: 15px; }
  .memo-banner { flex-wrap: wrap; padding: 8px 12px; }
  .memo-banner .btn { padding: 4px 8px; font-size: 12px; }
}

/* ---------- Touch numeric keypad ---------- */
.numpad-backdrop { position: fixed; inset: 0; background: rgba(10,16,26,.5); z-index: 90; display: none; align-items: flex-end; justify-content: center; }
.numpad-backdrop.show { display: flex; }
.numpad { width: 100%; max-width: 520px; background: #1c2733; border-radius: 18px 18px 0 0; padding: 14px 16px 20px; box-shadow: 0 -8px 30px rgba(0,0,0,.35); }
.numpad-head { display: flex; align-items: center; justify-content: space-between; color: #e8eef7; padding: 4px 4px 12px; border-bottom: 1px solid rgba(255,255,255,.12); margin-bottom: 12px; }
.numpad-head .np-label { font-size: 15px; font-weight: 700; }
.numpad-head .np-value { font-size: 22px; font-weight: 800; color: #fff; font-variant-numeric: tabular-nums; }
.numpad-head .np-close { background: none; border: none; color: #9db0c8; font-size: 20px; cursor: pointer; }
.numpad-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.numpad-grid button { height: 62px; border: none; border-radius: 12px; font-size: 24px; font-weight: 700; background: #2b3a4c; color: #fff; cursor: pointer; touch-action: manipulation; }
.numpad-grid button:active { background: #3a4d63; }
.numpad-grid button.np-fn { background: #17222e; color: #8fb0d6; font-size: 16px; }
.numpad-grid button.np-ok { background: var(--primary); color: #fff; }
.numpad-grid button.np-ok:active { background: var(--primary-dark); }
.numpad-grid .np-zero { grid-column: span 2; }
@media (max-width: 480px) {
  .numpad-grid button { height: 56px; font-size: 22px; }
}