:root {
  --bg: #f4f5f7;
  --card: #fff;
  --text: #14171a;
  --muted: #6b7480;
  --line: #e4e7eb;
  --accent: #128c4a;
  --accent-ink: #fff;
  --wa: #25d366;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  padding-bottom: 96px;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }
picture { display: contents; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line); }
.bar { max-width: 1200px; margin: 0 auto; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 10px 12px; align-items: center; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: -.02em; }
.brand p { margin: 0; color: var(--muted); font-size: 12px; }
.lang { border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; font-size: 12px; font-weight: 600; }
.search { grid-column: 1 / -1; width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); outline: none; font-size: 16px; }
.search:focus { border-color: var(--accent); background: var(--card); }

/* layout */
.wrap { max-width: 1200px; margin: 0 auto; padding: 12px; }
.side { display: none; }
@media (min-width: 900px) {
  .bar { grid-template-columns: auto 1fr auto; gap: 20px; }
  .search { grid-column: 2; grid-row: 1; }
  .wrap { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 20px; align-items: start; }
  .side { display: block; position: sticky; top: 76px; background: var(--card); border-radius: var(--radius); padding: 6px; max-height: calc(100vh - 90px); overflow-y: auto; }
  .side a { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; font-size: 14px; font-weight: 500; }
  .side a:hover { background: var(--bg); }
  .side a.on { background: var(--bg); color: var(--accent); font-weight: 700; }
  .side .cv { width: 34px; border-radius: 8px; font-size: 14px; }
}

/* page transitions */
@keyframes in-fwd { from { opacity: 0; transform: translateX(14px); } }
@keyframes in-back { from { opacity: 0; transform: translateX(-14px); } }
@keyframes in-fade { from { opacity: 0; transform: translateY(6px); } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(24px); } }
@keyframes sheet-out { to { opacity: 0; transform: translateY(24px); } }
main.fwd { animation: in-fwd .22s ease-out; }
main.back { animation: in-back .22s ease-out; }
main.fade { animation: in-fade .18s ease-out; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* covers */
.cv { flex: none; aspect-ratio: 1; background: #e8ebef; display: grid; place-items: center; color: #9aa3ad; font-weight: 700; overflow: hidden; }
.cv img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* home: groups + subcategory tiles */
.grp { background: var(--card); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.grp-head { display: flex; align-items: center; gap: 12px; }
.grp-head .cv { width: 52px; border-radius: 12px; font-size: 20px; }
.grp-head .gt { flex: 1; min-width: 0; display: grid; }
.grp-head b { font-size: 17px; letter-spacing: -.01em; }
.grp-head small { color: var(--muted); font-size: 12px; }
.grp-head i { font-style: normal; font-size: 22px; color: var(--muted); padding: 0 4px; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 10px; margin-top: 12px; }
@media (min-width: 600px) { .tiles { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 900px) { .tiles { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.tile { display: grid; gap: 6px; align-content: start; font-size: 12px; line-height: 1.25; text-align: center; transition: transform .15s; }
.tile:active { transform: scale(.96); }
.tile .cv { width: 100%; border-radius: 12px; font-size: 26px; }
.tile span { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* category page */
.crumb { display: flex; align-items: center; gap: 4px; margin-bottom: 4px; }
.crumb:empty { display: none; }
.crumb a { width: 36px; height: 36px; flex: none; display: grid; place-items: center; font-size: 20px; border-radius: 50%; margin-left: -8px; }
.crumb h2 { margin: 0; font-size: 18px; letter-spacing: -.01em; min-width: 0; }
.crumb small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.cats { display: flex; gap: 8px; overflow-x: auto; padding: 6px 12px 12px; margin: 0 -12px; scrollbar-width: none; }
.cats:empty { display: none; }
.cats::-webkit-scrollbar { display: none; }
.chip { flex: none; display: flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 999px; background: var(--card); font-size: 13px; white-space: nowrap; max-width: 240px; }
.chip span { overflow: hidden; text-overflow: ellipsis; }
.chip .cv { width: 28px; border-radius: 50%; margin-left: -10px; font-size: 12px; }
.chip.on { background: var(--text); color: #fff; }

/* product grid */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.card { background: var(--card); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.ph { aspect-ratio: 1; background: #eceef1; }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.info { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nm { font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.7em; }
.pr { font-weight: 700; font-size: 15px; margin-top: auto; }
.pr small { font-weight: 400; color: var(--muted); font-size: 12px; }
.add { width: 100%; padding: 8px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 14px; transition: transform .12s; }
.add:active { transform: scale(.97); }
.add:disabled { background: var(--bg); color: var(--muted); }
.step { display: flex; align-items: center; border-radius: 10px; background: var(--bg); overflow: hidden; }
.step button { width: 34px; height: 36px; font-size: 20px; font-weight: 600; color: var(--accent); flex: none; }
.step input { flex: 1; min-width: 0; width: 100%; height: 36px; padding: 0; border: 0; background: none; text-align: center; font-weight: 700; font-size: 16px; outline: none; -moz-appearance: textfield; }
.step input::-webkit-inner-spin-button { display: none; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* cart bar */
.cartbar {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 6;
  max-width: 560px; margin: 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-radius: 16px; background: var(--accent); color: var(--accent-ink);
  font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); animation: in-fade .2s ease-out;
}
.cartbar[hidden] { display: none; }
.cartbar b { margin-left: auto; font-size: 16px; }
.badge { background: #fff; color: var(--accent); border-radius: 999px; min-width: 24px; padding: 2px 7px; font-size: 13px; text-align: center; }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 10; background: var(--bg); display: flex; flex-direction: column; animation: sheet-in .22s ease-out; }
.sheet.closing { animation: sheet-out .16s ease-in forwards; }
.sheet[hidden] { display: none; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 17px; flex: 1; text-align: center; }
.icon { width: 36px; height: 36px; border-radius: 50%; font-size: 18px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 12px; width: 100%; max-width: 720px; margin: 0 auto; }
.sheet-body.fwd { animation: in-fwd .2s ease-out; }
.sheet-body.back { animation: in-back .2s ease-out; }
.sheet-foot { background: var(--card); border-top: 1px solid var(--line); padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); }
.sheet-foot > div { max-width: 720px; margin: 0 auto; display: grid; gap: 8px; }
.tot { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; color: var(--muted); }
.tot b { font-size: 20px; color: var(--text); }
.btn { width: 100%; padding: 14px; border-radius: 12px; font-weight: 700; font-size: 16px; background: var(--accent); color: #fff; }
.btn.wa { background: var(--wa); color: #06310f; }
.btn.ghost { background: none; color: var(--muted); font-weight: 500; font-size: 14px; padding: 8px; }
.btn:disabled { opacity: .5; }
.warn { color: #b45309; font-size: 13px; text-align: center; margin: 0; }

.row { display: flex; gap: 10px; align-items: center; background: var(--card); border-radius: 12px; padding: 10px; margin-bottom: 8px; }
.row .ph { width: 56px; flex: none; border-radius: 8px; overflow: hidden; }
.row .mid { flex: 1; min-width: 0; }
.row .nm { min-height: 0; -webkit-line-clamp: 3; }
.row .sub { color: var(--muted); font-size: 12px; }
/* сан өрісі 6 таңбаға дейін сыяды */
.row .qty { width: 148px; flex: none; }
.row .sum { font-weight: 700; font-size: 13px; text-align: right; margin-top: 4px; white-space: nowrap; }

/* invoice */
.paper { background: var(--card); border-radius: 12px; padding: 14px; }
.paper h3 { margin: 0; font-size: 16px; }
.paper .meta { color: var(--muted); font-size: 12px; margin: 2px 0 10px; }
.fields { display: grid; gap: 8px; margin-bottom: 12px; }
.fields input, .fields textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; outline: none; font-size: 16px; background: var(--card); }
.fields input:focus, .fields textarea:focus { border-color: var(--accent); }
.fields .bad { border-color: #dc2626; }
.inv { width: 100%; border-collapse: collapse; font-size: 13px; }
.inv th, .inv td { border: 1px solid var(--line); padding: 6px; text-align: left; vertical-align: top; }
.inv th { background: var(--bg); font-weight: 600; font-size: 12px; }
.inv .n { text-align: right; white-space: nowrap; }
.inv tfoot td { font-weight: 700; }

@media print {
  body { background: #fff; padding: 0; }
  .top, .wrap, .cartbar, .sheet-head, .sheet-foot { display: none !important; }
  .sheet { position: static; background: #fff; animation: none; }
  .sheet-body { overflow: visible; max-width: none; padding: 0; }
  .fields input, .fields textarea { border: 0; padding: 2px 0; }
  .fields input:placeholder-shown, .fields textarea:placeholder-shown { display: none; }
}
