:root {
  --red: #BC2F2A;
  --red-dark: #9A231F;
  --red-soft: #FBECEB;
  --ink: #1F1F1F;
  --muted: #6B6B6B;
  --line: #E7E2E1;
  --bg: #F7F5F5;
  --ok: #1E7D45;
  --radius: 10px;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-size: 15px; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--red); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--ink); }
label.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 14px; }
label.check input { width: auto; }

.btn {
  text-decoration: none;
  border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 9px 16px; cursor: pointer;
  font-weight: 600; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--red); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); }
.btn.primary:disabled { background: #d9a4a1; border-color: #d9a4a1; cursor: not-allowed; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--red); }
.btn.big { padding: 14px 20px; font-size: 17px; width: 100%; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.err { color: var(--red); min-height: 20px; font-size: 14px; margin-bottom: 8px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; background: linear-gradient(135deg, #fff 0%, var(--red-soft) 100%); }
.login-card { background: #fff; padding: 36px; border-radius: 16px; width: 360px; box-shadow: 0 10px 40px rgba(188,47,42,.12); border-top: 6px solid var(--red); }
.login-logo { width: 100%; max-width: 260px; display: block; margin: 0 auto 26px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 20px; background: #fff; padding: 8px 18px;
  border-bottom: 4px solid var(--red); position: sticky; top: 0; z-index: 5;
}
.logo { height: 44px; }
#nav { display: flex; gap: 4px; flex: 1; align-items: center; }
#nav a {
  text-decoration: none; color: var(--ink); padding: 8px 14px; border-radius: 8px; font-weight: 600; font-size: 14px;
}
#nav a:hover { background: var(--red-soft); color: var(--red); }
#nav a.active { background: var(--red); color: #fff; }
.dd { position: relative; }
.dd-btn.active { background: var(--red) !important; color: #fff !important; }
.dd-menu { display: none; position: absolute; top: 100%; left: 0; margin-top: 6px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.1); padding: 6px; min-width: 180px; z-index: 10; }
.dd.open .dd-menu { display: grid; }
.dd-menu a { padding: 10px 12px !important; }
#acct { color: var(--ink); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.top-right { display: flex; gap: 10px; align-items: center; }
#branchSel { width: auto; min-width: 170px; font-weight: 600; border-color: var(--red); color: var(--red); }
.user-chip { font-size: 13px; color: var(--muted); white-space: nowrap; }
.user-chip b { color: var(--ink); }

main { padding: 18px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.right { text-align: right; }
.neg { color: var(--red); font-weight: 700; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; background: #eee; }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.green { background: #E6F4EC; color: var(--ok); }

table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #FBFAFA; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--red-soft); }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; background: #fff; }

/* POS */
.pos { display: grid; grid-template-columns: 1fr 400px; gap: 16px; height: calc(100vh - 100px); }
.pos-left { display: flex; flex-direction: column; min-height: 0; }
.cats { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.cat { padding: 8px 16px; border-radius: 99px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 600; }
.cat.active { background: var(--red); color: #fff; border-color: var(--red); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; overflow: auto; padding-bottom: 10px; align-content: start; }
.tile {
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px; cursor: pointer; min-height: 104px;
  display: flex; flex-direction: column; justify-content: space-between; user-select: none; transition: transform .08s, border-color .15s;
  border-left: 4px solid var(--red);
}
.tile:hover { border-color: var(--red); }
.tile:active { transform: scale(.97); }
.tile .nm { font-weight: 700; line-height: 1.25; }
.tile .pr { color: var(--red); font-weight: 800; font-size: 17px; }
.tile .sku { font-size: 11px; color: var(--muted); }

.cart { background: #fff; border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; min-height: 0; }
.cart-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.cart-head h2 { margin: 0; font-size: 17px; }
.cart-lines { flex: 1; overflow: auto; }
.cart-empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.cl { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.cl .n { font-weight: 600; }
.cl .p { font-size: 12px; color: var(--muted); }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 700; font-size: 16px; }
.qty button:hover { border-color: var(--red); color: var(--red); }
.qty span { min-width: 26px; text-align: center; font-weight: 700; }
.cl .lt { font-weight: 700; min-width: 70px; text-align: right; }
.totals { padding: 12px 16px; border-top: 1px solid var(--line); }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; color: var(--muted); }
.totals .grand { color: var(--ink); font-size: 24px; font-weight: 800; padding-top: 8px; }
.totals .grand span:last-child { color: var(--red); }
.cart-foot { padding: 12px 16px; display: grid; gap: 8px; }

/* Payment modal */
.modal { position: fixed; inset: 0; background: rgba(20,10,10,.45); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal-box { background: #fff; border-radius: 14px; width: min(560px, 100%); max-height: 92vh; overflow: auto; padding: 22px; border-top: 6px solid var(--red); }
.modal-box.wide { width: min(860px, 100%); }
.modal-box h2 { margin: 0 0 14px; font-size: 20px; }
.pay-total { text-align: center; padding: 6px 0 16px; }
.pay-total .lbl { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; }
.pay-total .amt { font-size: 40px; font-weight: 800; color: var(--red); }
.methods { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.method {
  border: 2px solid var(--line); border-radius: 12px; padding: 18px; text-align: center; cursor: pointer; font-weight: 800; font-size: 18px; background: #fff;
}
.method .ic { font-size: 28px; display: block; margin-bottom: 4px; }
.method.active { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.tender-input { font-size: 28px; font-weight: 700; text-align: right; padding: 12px 14px; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0 14px; }
.quick button { padding: 12px 0; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-weight: 700; cursor: pointer; }
.quick button:hover { border-color: var(--red); color: var(--red); }
.change { display: flex; justify-content: space-between; align-items: center; background: #E6F4EC; color: var(--ok); padding: 14px 16px; border-radius: 10px; font-weight: 800; font-size: 22px; margin-bottom: 14px; }
.change.short { background: var(--red-soft); color: var(--red); }
.done-change { text-align: center; padding: 10px 0 18px; }
.done-change .amt { font-size: 48px; font-weight: 800; color: var(--ok); }

/* Receiving */
.recv-lines td input { padding: 6px 8px; }

.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; border-top: 4px solid var(--red); }
.stat .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .v { font-size: 26px; font-weight: 800; margin-top: 4px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { margin: 0; border: 1px solid var(--line); border-radius: 99px; padding: 6px 12px; display: flex; gap: 6px; align-items: center; color: var(--ink); cursor: pointer; }
.chips input { width: auto; margin: 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 10px; z-index: 30; font-weight: 600; }
.toast.bad { background: var(--red); }

/* Receipt (80mm thermal) */
#printArea { display: none; }
.receipt { width: 72mm; font-family: "Courier New", monospace; font-size: 12px; color: #000; }
.receipt .c { text-align: center; }
.receipt hr { border: 0; border-top: 1px dashed #000; margin: 6px 0; }
.receipt table { background: none; }
.receipt td, .receipt th { padding: 2px 0; border: 0; font-size: 12px; color: #000; background: none; text-transform: none; letter-spacing: 0; }
.receipt .tot td { font-weight: 700; font-size: 14px; }
.receipt img { width: 52mm; filter: grayscale(1) contrast(1.4); }
.receipt-preview { border: 1px dashed var(--line); padding: 12px; display: flex; justify-content: center; background: #fff; margin-bottom: 14px; }

@media print {
  @page { size: 80mm auto; margin: 3mm; }
  body * { visibility: hidden; }
  #printArea, #printArea * { visibility: visible; }
  #printArea { display: block; position: absolute; left: 0; top: 0; }
}

@media (max-width: 1000px) {
  .pos { grid-template-columns: 1fr; height: auto; }
  .stats { grid-template-columns: 1fr 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr; }
}
