:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #ccfbf1;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --warn-soft: #fef3c7;
  --ok-soft: #dcfce7;
  --radius: 14px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #151e2e;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --line: #243044;
    --primary: #14b8a6;
    --primary-ink: #042f2e;
    --primary-soft: #134e4a;
    --ok: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
    --bad-soft: #3f1d1d;
    --warn-soft: #3a2a0c;
    --ok-soft: #12301f;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); margin: 0; }

/* ---------- tugmalar ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 600;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.danger { color: var(--bad); }
.btn.big { width: 100%; padding: 14px; font-size: 17px; }
.btn:disabled { opacity: .5; }
.icon-btn {
  border: 0; background: transparent; width: 44px; height: 44px;
  display: grid; place-items: center; border-radius: 12px; color: var(--muted);
}
.icon-btn:active { background: var(--line); }
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- kirish ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: 20px;
  padding: 28px 22px; display: grid; gap: 14px; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.08);
}
.login-card img { margin: 0 auto; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 6px; text-align: left; font-size: 14px; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); font-size: 16px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

/* ---------- sarlavha ---------- */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px;
  padding: 8px 8px 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.who {
  flex: 1; min-width: 0; display: grid; text-align: left; border: 0; background: transparent;
  padding: 2px 0; line-height: 1.25;
}
.who b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 17px; }
.who b.unset { color: var(--bad); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 5px; vertical-align: 1px; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.seller-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.seller-grid button {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius);
  padding: 18px 10px; font-size: 17px; font-weight: 600;
}
.seller-grid button.active { border: 2px solid var(--primary); color: var(--primary); }
.chips.filter { padding-bottom: 4px; }
.status-line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.banner { padding: 8px 16px; font-size: 14px; background: var(--warn-soft); color: var(--warn); }
.banner.demo { background: var(--primary-soft); color: var(--primary); }

main { padding: 12px 12px calc(var(--tabs-h) + 90px + var(--safe-b)); max-width: 720px; margin: 0 auto; }

/* ---------- mijoz tanlash ---------- */
.client-pick {
  width: 100%; text-align: left; border: 2px dashed var(--line); background: var(--surface);
  border-radius: var(--radius); padding: 12px 14px; display: flex; align-items: center; gap: 10px;
}
.client-pick.set { border: 2px solid var(--primary); }
.client-pick .grow { flex: 1; min-width: 0; }
.client-pick b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.search { margin: 12px 0 8px; }
.search input { border-radius: 999px; padding-left: 16px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; white-space: nowrap;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

/* ---------- ro'yxatlar ---------- */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.list > li {
  background: var(--surface); border-radius: var(--radius); padding: 12px 14px;
  display: flex; gap: 12px; align-items: center;
}
.list > li.in-cart { box-shadow: inset 3px 0 0 var(--primary); }
.list .info { flex: 1; min-width: 0; }
.list .name { font-weight: 600; }
.list .meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.list .price { font-weight: 700; margin-top: 4px; }
.list .empty { justify-content: center; color: var(--muted); text-align: center; padding: 28px 16px; }
.list .section-title { background: transparent; padding: 10px 4px 0; font-weight: 700; color: var(--muted); font-size: 14px; }
.stock-ok { color: var(--ok); }
.stock-low { color: var(--warn); }
.stock-none { color: var(--bad); }
.debt { font-weight: 700; }
.debt.pos { color: var(--bad); }
.debt.neg { color: var(--ok); }
a.tel { color: var(--primary); text-decoration: none; }

/* ---------- miqdor tanlagich ---------- */
.stepper { display: flex; align-items: center; flex: none; }
.stepper button {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-size: 22px; line-height: 1; font-weight: 600;
}
.stepper .plus { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.stepper input {
  width: 56px; height: 40px; text-align: center; padding: 0 4px; margin: 0 4px;
  border-radius: 10px; font-weight: 700;
}
.stepper input.over { color: var(--bad); border-color: var(--bad); }

/* ---------- savat paneli ---------- */
.cart-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + var(--safe-b)); z-index: 6;
  padding: 10px 12px; background: linear-gradient(transparent, var(--bg) 30%);
}
.cart-bar .btn { max-width: 696px; margin: 0 auto; display: flex; justify-content: space-between; box-shadow: 0 6px 20px rgba(15,118,110,.35); }

/* ---------- pastki menyu ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; display: flex;
  background: var(--surface); border-top: 1px solid var(--line);
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
}
.tabs button {
  flex: 1; border: 0; background: transparent; color: var(--muted); font-size: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; position: relative;
}
.tabs svg { width: 24px; height: 24px; }
.tabs button.active { color: var(--primary); font-weight: 600; }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; font-weight: 700;
}

/* ---------- holat belgilari ---------- */
.status { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.status.sent { background: var(--ok-soft); color: var(--ok); }
.status.pending, .status.local { background: var(--warn-soft); color: var(--warn); }
.status.error { background: var(--bad-soft); color: var(--bad); }

/* ---------- pastdan oyna ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(2,6,23,.5); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 90dvh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 20px 20px 0 0; max-width: 720px; margin: 0 auto;
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; padding: 12px 8px 4px 16px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 19px; }
.sheet-body { overflow-y: auto; padding: 8px 12px calc(16px + var(--safe-b)); display: grid; gap: 12px; }
.field { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.totals {
  background: var(--surface); border-radius: var(--radius); padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-weight: 700;
}
.totals .sum { font-size: 20px; text-align: right; }
.kv { background: var(--surface); border-radius: var(--radius); padding: 4px 14px; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv div:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { text-align: right; }
.row-actions { display: flex; gap: 8px; }
.row-actions .btn { flex: 1; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(var(--tabs-h) + 90px + var(--safe-b)); max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
