:root {
  --bg: #f1f3f8;
  --card: #ffffff;
  --text: #14161f;
  --muted: #8a92a6;
  --line: #eceff5;
  --accent: #3d6dff;
  --accent-dark: #2f56d9;
  --accent-soft: #eaf0ff;
  --grad: linear-gradient(135deg, #3d6dff 0%, #7a4dff 100%);
  --green: #16b364;
  --green-soft: #e7f8f0;
  --red: #f04438;
  --red-soft: #fdeceb;
  --amber: #f79009;
  --radius: 16px;
  --nav-h: 62px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  overscroll-behavior: none;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

button { font-family: inherit; border: none; cursor: pointer; background: none; color: inherit; }
input, textarea, select {
  font-family: inherit; font-size: 15px; color: var(--text);
  border: 1.5px solid var(--line); border-radius: 12px;
  padding: 11px 14px; width: 100%; background: var(--card); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }

/* ---------- служебные экраны ---------- */
.screen-center {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  padding: 24px; background: var(--bg); z-index: 50;
}
.big-emoji { font-size: 56px; margin-bottom: 12px; }
.screen-center h2 { margin-bottom: 8px; }

.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- шапка ---------- */
#header {
  background: var(--grad);
  padding: 12px 14px 14px;
  border-radius: 0 0 20px 20px;
  position: sticky; top: 0; z-index: 10;
}
.header-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.logo { color: #fff; font-weight: 800; font-size: 19px; letter-spacing: 0.4px; }
.balance-pill {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, 0.18); color: #fff;
  border-radius: 100px; padding: 7px 8px 7px 14px;
  font-weight: 700; font-size: 14px; backdrop-filter: blur(4px);
}
.balance-plus {
  background: #fff; color: var(--accent); width: 22px; height: 22px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px;
}
.search-wrap {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border-radius: 12px; padding: 0 12px; color: var(--muted);
}
.search-wrap input { border: none; padding: 11px 0; background: transparent; }

/* ---------- основной контент ---------- */
#main { padding: 14px 14px calc(var(--nav-h) + 20px); max-width: 560px; margin: 0 auto; }

.section-title { font-size: 17px; font-weight: 800; margin: 4px 0 10px; }

/* категории */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; background: var(--card); border-radius: 100px;
  padding: 8px 15px; font-size: 13.5px; font-weight: 600; color: var(--text);
  border: 1.5px solid transparent; white-space: nowrap;
}
.chip.active { background: var(--accent); color: #fff; }
.chip.chip-del { border: 1.5px dashed var(--line); color: var(--muted); }

/* сетка товаров */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.p-card {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column; cursor: pointer;
  box-shadow: 0 1px 3px rgba(20, 22, 31, 0.05);
}
.p-img {
  aspect-ratio: 1; width: 100%; object-fit: cover; display: flex;
  align-items: center; justify-content: center; font-size: 44px;
  background: linear-gradient(160deg, #e8edfb, #f0eafc);
}
img.p-img { background: #f4f6fb; }
.p-body { padding: 10px 11px 11px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.p-price { font-weight: 800; font-size: 16.5px; }
.p-price small { color: var(--muted); font-weight: 600; font-size: 11px; }
.p-name {
  font-size: 13px; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 34px;
}
.p-stock { font-size: 11.5px; font-weight: 600; }
.p-stock.ok { color: var(--green); }
.p-stock.out { color: var(--red); }
.p-buy {
  margin-top: 6px; background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 13.5px; border-radius: 10px; padding: 9px 0;
}
.p-buy:disabled { opacity: 0.45; }

.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty .big-emoji { font-size: 44px; }

/* ---------- нижняя навигация ---------- */
#navbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; color: var(--muted); font-size: 10.5px; font-weight: 600;
}
.nav-btn svg { width: 23px; height: 23px; }
.nav-btn.active { color: var(--accent); }

/* ---------- карточки ---------- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  margin-bottom: 10px; box-shadow: 0 1px 3px rgba(20, 22, 31, 0.05);
}
.card-grad { background: var(--grad); color: #fff; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 2px; border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: none; }

.badge { font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 100px; white-space: nowrap; }
.badge.ok { background: var(--green-soft); color: var(--green); }
.badge.warn { background: #fef4e6; color: var(--amber); }
.badge.err { background: var(--red-soft); color: var(--red); }
.badge.info { background: var(--accent-soft); color: var(--accent); }

/* ---------- кнопки ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 14px; border-radius: 13px;
  font-weight: 700; font-size: 15.5px; transition: transform 0.05s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--grad); color: #fff; }
.btn-soft { background: var(--accent-soft); color: var(--accent); }
.btn-ghost { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-sm { width: auto; padding: 8px 14px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: 0.5; }

/* ---------- шторка ---------- */
#sheet-overlay {
  position: fixed; inset: 0; background: rgba(10, 12, 20, 0.5); z-index: 30;
  animation: fade 0.2s;
}
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--card); border-radius: 22px 22px 0 0;
  max-height: 90vh; overflow-y: auto;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  animation: slide-up 0.25s ease;
  max-width: 560px; margin: 0 auto;
}
@keyframes slide-up { from { transform: translateY(60px); opacity: 0.5; } }
@keyframes fade { from { opacity: 0; } }

.sheet-handle { width: 40px; height: 4px; background: var(--line); border-radius: 4px; margin: 4px auto 14px; }
.sheet-title { font-size: 18px; font-weight: 800; margin-bottom: 12px; }

.sheet-img {
  width: 100%; aspect-ratio: 1.6; object-fit: cover; border-radius: 14px;
  display: flex; align-items: center; justify-content: center; font-size: 64px;
  background: linear-gradient(160deg, #e8edfb, #f0eafc); margin-bottom: 12px;
}
.price-line { display: flex; align-items: baseline; gap: 8px; margin: 8px 0 2px; }
.price-big { font-size: 26px; font-weight: 800; }
.desc { color: #4a5065; font-size: 14px; white-space: pre-wrap; margin: 10px 0 4px; }

/* степпер количества */
.qty-row { display: flex; align-items: center; justify-content: space-between; margin: 14px 0; }
.stepper { display: flex; align-items: center; gap: 4px; background: var(--bg); border-radius: 12px; padding: 4px; }
.stepper button {
  width: 38px; height: 38px; border-radius: 9px; background: var(--card);
  font-size: 19px; font-weight: 700; color: var(--accent);
  box-shadow: 0 1px 2px rgba(20, 22, 31, 0.08);
}
.stepper button:disabled { color: var(--muted); opacity: 0.5; }
.stepper span { min-width: 42px; text-align: center; font-weight: 800; font-size: 17px; }

/* способы оплаты */
.pay-method {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 13px 14px; border-radius: 13px; background: var(--bg);
  margin-bottom: 8px; font-weight: 600; font-size: 14.5px; text-align: left;
}
.pay-method:active { background: var(--accent-soft); }
.pay-method:disabled { opacity: 0.45; }
.pay-icon {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 19px;
  background: var(--card); box-shadow: 0 1px 2px rgba(20, 22, 31, 0.08);
}
.pay-sub { font-size: 12px; color: var(--muted); font-weight: 500; }

/* выданный товар */
.item-line {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border-radius: 10px; padding: 10px 12px; margin-bottom: 6px;
}
.item-line code {
  flex: 1; font-size: 13px; word-break: break-all;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
}
.copy-btn { color: var(--accent); font-size: 17px; padding: 4px; }

/* формы */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.form-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 4px 0 12px; font-weight: 600; }
.switch-row input { width: 20px; height: 20px; accent-color: var(--accent); }

/* быстрые суммы */
.quick-amounts { display: flex; gap: 8px; margin: 10px 0 14px; }
.quick-amounts button {
  flex: 1; background: var(--bg); border-radius: 10px; padding: 10px 0;
  font-weight: 700; font-size: 13.5px;
}
.quick-amounts button.active { background: var(--accent); color: #fff; }

/* ---------- профиль ---------- */
.profile-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.avatar {
  width: 52px; height: 52px; border-radius: 50%; background: var(--grad);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800; flex-shrink: 0;
}
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.stat-card { background: var(--card); border-radius: var(--radius); padding: 13px 14px; box-shadow: 0 1px 3px rgba(20,22,31,0.05); }
.stat-card .v { font-size: 20px; font-weight: 800; }
.stat-card .l { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 2px; }

.ref-link {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, 0.16); border-radius: 10px;
  padding: 10px 12px; margin-top: 10px;
}
.ref-link code { flex: 1; font-size: 12px; color: #fff; word-break: break-all; }
.ref-link button { color: #fff; font-size: 17px; }

.info-link {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 13px 2px; border-bottom: 1px solid var(--line);
  font-size: 14.5px; font-weight: 600; text-align: left;
}
.info-link:last-child { border-bottom: none; }
.info-link .arr { margin-left: auto; color: var(--muted); }

/* ---------- админка ---------- */
.subtabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 12px; scrollbar-width: none; }
.subtabs::-webkit-scrollbar { display: none; }
.subtab {
  flex-shrink: 0; padding: 8px 14px; border-radius: 100px; font-size: 13px;
  font-weight: 700; background: var(--card); color: var(--muted); white-space: nowrap;
}
.subtab.active { background: var(--text); color: #fff; }

.admin-p-row { display: flex; gap: 10px; align-items: center; }
.admin-p-thumb {
  width: 46px; height: 46px; border-radius: 10px; object-fit: cover; flex-shrink: 0;
  background: linear-gradient(160deg, #e8edfb, #f0eafc);
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.admin-p-actions { display: flex; gap: 6px; margin-left: auto; flex-shrink: 0; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; background: var(--bg);
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}

/* ---------- тост ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px);
  transform: translateX(-50%); z-index: 60;
  background: rgba(20, 22, 31, 0.92); color: #fff;
  padding: 11px 18px; border-radius: 100px; font-size: 13.5px; font-weight: 600;
  max-width: 86vw; text-align: center; animation: toast-in 0.25s;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

.center { text-align: center; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; }
