:root {
  --bg: #f4f6f8; --card: #fff; --text: #17202a; --muted: #6b7785; --line: #e3e8ee;
  --brand: #0f766e; --brand-2: #115e59; --brand-soft: #e6f4f2;
  --red: #c2410c; --red-soft: #fdece3; --amber: #b45309; --amber-soft: #fdf3e1;
  --blue: #1d4ed8; --blue-soft: #e8eefc; --green: #15803d; --green-soft: #e5f5ea;
  --kaspi: #f14635; --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: #0b2b29; color: #d6ebe8; padding: 16px 10px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.logo { font-weight: 800; font-size: 20px; color: #fff; padding: 6px 12px 18px; letter-spacing: -.3px; }
.logo span { color: #5eead4; }
.nav-btn { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; color: inherit; padding: 10px 12px; border-radius: 10px; cursor: pointer; font-weight: 500; }
.nav-btn:hover { background: rgba(255,255,255,.07); }
.nav-btn.active { background: #134e4a; color: #fff; }
.nav-btn .ico { width: 20px; text-align: center; }
.nav-btn .badge { margin-left: auto; }
.side .spacer { flex: 1; }
.main { padding: 22px 26px 90px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; margin: 0; letter-spacing: -.3px; }
.page-head .grow { flex: 1; }

/* elements */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: #c6cfd8; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--red); }
.btn.kaspi { background: var(--kaspi); border-color: var(--kaspi); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.lg { padding: 14px 18px; font-size: 16px; border-radius: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 9px 11px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); font-weight: 500; cursor: pointer; }
.check input { width: auto; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 160px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef1f4; color: #405060; }
.b-green { background: var(--green-soft); color: var(--green); }
.b-red { background: var(--red-soft); color: var(--red); }
.b-amber { background: var(--amber-soft); color: var(--amber); }
.b-blue { background: var(--blue-soft); color: var(--blue); }
.b-brand { background: var(--brand-soft); color: var(--brand); }
.b-kaspi { background: #fde8e6; color: var(--kaspi); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { border: 1px solid var(--line); background: #fff; padding: 6px 12px; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: 13px; }
.tab.active { background: var(--text); color: #fff; border-color: var(--text); }
.empty { text-align: center; color: var(--muted); padding: 36px 10px; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8fafb; }

/* KPI */
.kpi { padding: 14px 16px; }
.kpi .v { font-size: 22px; font-weight: 800; letter-spacing: -.4px; margin-top: 4px; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 600; }

/* POS */
.pos { display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start; }
.pos-search { position: sticky; top: 0; z-index: 2; background: var(--bg); padding-bottom: 10px; }
.pos-search input { font-size: 16px; padding: 12px 14px; }
.products-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.pcard { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 6px; min-height: 104px; }
.pcard:hover { border-color: var(--brand); }
.pcard .n { font-weight: 600; line-height: 1.25; flex: 1; }
.pcard .p { font-weight: 800; }
.pcard .s { font-size: 12px; }
.cart { position: sticky; top: 16px; display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.cart-items { overflow-y: auto; flex: 1; margin: 0 -16px; padding: 0 16px; min-height: 80px; }
.citem { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.citem .n { font-weight: 600; }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.qty button { border: 0; background: #f4f6f8; width: 32px; height: 30px; cursor: pointer; font-size: 16px; }
.qty input { border: 0; width: 48px; text-align: center; padding: 4px; border-radius: 0; }
.total-line { display: flex; justify-content: space-between; padding: 4px 0; }
.total-line.big { font-size: 22px; font-weight: 800; padding-top: 10px; }
.pay-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,32,.45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 12px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal.wide { max-width: 820px; }
.modal-h { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-h h2 { margin: 0; font-size: 17px; flex: 1; }
.modal-x { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-b { padding: 18px; }
.modal-f { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #17202a; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 90vw; }
.toast.err { background: var(--red); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #0b2b29, #134e4a); }
.login .card { width: 100%; max-width: 360px; padding: 26px; }
.login .logo { color: var(--text); padding: 0 0 6px; font-size: 26px; }
.login .logo span { color: var(--brand); }

/* chart */
.bars { display: flex; justify-content: center; align-items: flex-end; gap: 4px; height: 170px; padding-top: 10px; }
.bar { flex: 1; max-width: 56px; background: var(--brand); border-radius: 5px 5px 0 0; min-height: 2px; position: relative; }
.bar:hover { background: var(--brand-2); }
.bar-labels { display: flex; justify-content: center; gap: 4px; margin-top: 6px; }
.bar-labels span { flex: 1; max-width: 56px; text-align: center; font-size: 10px; color: var(--muted); overflow: hidden; white-space: nowrap; }

.steps { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 14px; }
.step { text-align: center; font-size: 12px; font-weight: 600; padding: 8px 4px; border-radius: 8px; background: #eef1f4; color: var(--muted); cursor: pointer; border: 0; }
.step.done { background: var(--brand-soft); color: var(--brand); }
.step.cur { background: var(--brand); color: #fff; }

#print-area { display: none; }

/* mobile */
.mobile-nav { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: 14px 12px 96px; }
  .mobile-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
  .mobile-nav button { flex: 1; border: 0; background: none; padding: 8px 2px 10px; font-size: 11px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; position: relative; }
  .mobile-nav button .ico { font-size: 19px; }
  .mobile-nav button.active { color: var(--brand); font-weight: 700; }
  .mobile-nav .badge { position: absolute; top: 2px; right: 18%; padding: 0 6px; font-size: 10px; }
  .pos { grid-template-columns: 1fr; }
  .cart { position: static; max-height: none; }
  .g2, .g3, .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .hide-m { display: none; }
  .steps { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 520px) { .g2.stack-m, .g3.stack-m { grid-template-columns: 1fr; } }

@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  @page { margin: 4mm; }
}
.receipt { width: 72mm; font: 12px/1.35 ui-monospace, Consolas, monospace; color: #000; }
.receipt h2 { text-align: center; margin: 0 0 4px; font-size: 16px; }
.receipt .c { text-align: center; }
.receipt .ln { display: flex; justify-content: space-between; gap: 6px; }
.receipt hr { border: 0; border-top: 1px dashed #000; margin: 6px 0; }
