:root {
  --bg: #f3f5f4;
  --card: #ffffff;
  --text: #17201d;
  --muted: #66736e;
  --line: #e2e7e5;
  --accent: #0e7c66;
  --accent-2: #0b6555;
  --accent-soft: #e3f3ee;
  --danger: #c8372d;
  --danger-soft: #fdecea;
  --warn: #b26a00;
  --warn-soft: #fff4e0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 2px 8px rgba(16, 24, 20, .04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.neg { color: var(--danger); }
.pos-c { color: var(--accent); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
kbd { font: 600 11px/1 ui-monospace, monospace; padding: 2px 5px; border-radius: 4px; background: rgba(0,0,0,.12); margin-left: 6px; }

/* ---------- buttons & fields */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { border-color: #c5cfcb; background: #fafbfb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: rgba(0,0,0,.04); }
.btn.big { padding: 14px; font-size: 18px; width: 100%; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 22px; line-height: 1; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: rgba(0,0,0,.06); color: var(--text); }
input, select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
.fld { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.fld > input, .fld > select, .fld > textarea { color: var(--text); font-size: 15px; }
.chk { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.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; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #e3f3ee, #f3f5f4 60%); }
.login form { width: 100%; max-width: 360px; background: var(--card); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.login h1 { margin: 0 0 4px; font-size: 26px; }
.brand b { color: var(--accent); }
.err-box { background: var(--danger-soft); color: var(--danger); padding: 8px 12px; border-radius: 8px; font-size: 14px; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: #12201c; color: #d6e2de; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side .brand { font-size: 22px; font-weight: 700; padding: 20px 18px 2px; color: #fff; }
.side .brand b { color: #4fd1ae; }
.side .store { padding: 0 18px 14px; font-size: 13px; color: #8fa39c; }
.side nav { display: flex; flex-direction: column; padding: 4px 8px; gap: 2px; overflow: auto; flex: 1; }
.side nav a { color: #c5d3ce; text-decoration: none; padding: 9px 12px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
.side nav a svg { width: 18px; height: 18px; flex: none; opacity: .8; }
.side nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side nav a.active { background: var(--accent); color: #fff; }
.side-foot { padding: 12px 18px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.side-foot .who { color: #fff; font-weight: 600; }
.side-foot .btn { color: #c5d3ce; padding: 4px 0; margin-right: 12px; }
.side-foot .btn:hover { color: #fff; background: none; }
.topbar { display: none; }
.main-col { min-width: 0; }
.view { padding: 20px 24px 40px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h2 { margin: 0; font-size: 22px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px; }
.card h3 { margin: 0 0 12px; font-size: 16px; }

/* ---------- tables */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfb; position: sticky; top: 0; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #f7faf9; }
.tbl tfoot td { font-weight: 700; border-bottom: 0; }
.tbl .sub { font-size: 12px; color: var(--muted); }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent-2); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.gray { background: #eef1f0; color: var(--muted); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

/* ---------- POS */
.view-pos { padding: 14px; }
.pos { display: grid; grid-template-columns: 1fr 340px; gap: 14px; height: calc(100vh - 28px); }
.pos-main { display: flex; flex-direction: column; min-height: 0; padding: 12px; }
.pos-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.pos-tab { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 0 2px 0 12px; cursor: pointer; height: 34px; }
.pos-tab.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.pos-tab .x { border: 0; background: none; color: inherit; opacity: .6; cursor: pointer; font-size: 16px; padding: 0 8px; }
.pos-tab .cnt { font-size: 12px; opacity: .75; margin-left: 6px; }
.scan-wrap { position: relative; }
.scan { font-size: 18px; padding: 12px 14px; border-width: 2px; }
.suggest { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.12); max-height: 380px; overflow: auto; }
.sg { display: grid; grid-template-columns: 1fr auto auto auto; gap: 14px; align-items: center; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--line); }
.sg:last-child { border-bottom: 0; }
.sg.on, .sg:hover { background: var(--accent-soft); }
.sg small { color: var(--muted); }
.cart-wrap { flex: 1; overflow: auto; margin-top: 10px; }
.cart td { padding: 6px 10px; }
.cart .q, .cart .p { width: 96px; text-align: right; padding: 6px 8px; }
.pos-main, .pos-side { min-width: 0; }
.cart .p[readonly] { border-color: transparent; background: transparent; }
.cart tr.flash td { animation: flash .6s; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
.pos-side { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.cust-box { border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; }
.cust-box .nm { font-weight: 600; }
.totals > div { display: flex; justify-content: space-between; padding: 4px 0; color: var(--muted); }
.totals b { color: var(--text); font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; color: var(--text); font-size: 18px; }
.totals .grand b { font-size: 30px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.6; margin-top: auto; }

/* pay */
.pay-total { text-align: center; padding: 6px 0 14px; }
.pay-total b { font-size: 36px; display: block; font-variant-numeric: tabular-nums; }
.pay-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.pay-row { display: grid; grid-template-columns: 150px 1fr auto; gap: 8px; align-items: center; }
.pay-row label { font-weight: 500; }
.pay-row input { text-align: right; font-size: 17px; }
.pay-row.off { opacity: .45; }
.pay-sum { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.pay-sum div { background: #f6f8f7; border-radius: 8px; padding: 10px; }
.pay-sum b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.done-big { text-align: center; padding: 10px 0 18px; }
.done-big b { font-size: 44px; display: block; color: var(--accent); }

/* ---------- modal */
.overlay { position: fixed; inset: 0; background: rgba(10, 20, 16, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; z-index: 100; overflow: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 860px; }
.modal.xwide { max-width: 1100px; }
.m-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.m-head h3 { margin: 0; font-size: 18px; }
.m-body { padding: 18px; }
.list { max-height: 50vh; overflow: auto; margin-top: 8px; }
.list-item { display: flex; justify-content: space-between; gap: 12px; padding: 10px 8px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 6px; }
.list-item:hover { background: var(--accent-soft); }
details summary { cursor: pointer; color: var(--accent); margin: 10px 0; }

/* ---------- toasts */
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: calc(100vw - 32px); }
.toast { background: #12201c; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); animation: tin .2s; max-width: 420px; }
.toast.err { background: var(--danger); }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* ---------- KPI / reports */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.kpi span { font-size: 13px; color: var(--muted); }
.kpi b { display: block; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bar { height: 8px; background: var(--accent); border-radius: 4px; min-width: 2px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: 7px 12px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }
.seg button + button { border-left: 1px solid var(--line); }

/* ---------- labels */
.ean { width: 100%; height: 40px; display: block; }

/* ---------- responsive */
@media (max-width: 1100px) {
  .pos { grid-template-columns: 1fr 290px; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 90; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 50; }
  .topbar .tb-title { font-weight: 600; }
  .view { padding: 14px 16px 32px; }
  .view-pos { padding: 10px; }
  .pos { grid-template-columns: 1fr; height: auto; }
  .pos-main { min-height: 50vh; }
  .two-col, .grid3 { grid-template-columns: 1fr; }
  .pay-row { grid-template-columns: 110px 1fr auto; }
  .sg { grid-template-columns: 1fr auto; }
  .sg small { display: none; }
  .hide-m { display: none; }
}
@media (max-width: 480px) {
  .grid2 { grid-template-columns: 1fr; }
}
