:root {
  --brand: #0b3d91;
  --brand-2: #1565ff;
  --accent: #19c37d;
  --wa: #25d366;
  --danger: #e5484d;
  --bg: #c51617;
  --card: #ffffff;
  --text: #0f1729;
  --muted: #64748b;
  --line: #e2e8f0;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(15, 23, 41, 0.08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); -webkit-tap-highlight-color: transparent; }
img, video { max-width: 100%; display: block; }
a { color: var(--brand-2); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p { margin: 0; }

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border: 0; border-radius: 12px;
  font: inherit; font-weight: 600; font-size: 16px; text-decoration: none; cursor: pointer;
  background: var(--brand-2); color: #fff; transition: transform .1s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 22px; height: 22px; flex: none; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: #e8eefc; color: var(--brand); }
.btn.ghost { background: transparent; color: var(--brand-2); min-height: 40px; padding: 0 8px; }
.btn.danger { background: #fdecec; color: var(--danger); }
.btn.wa { background: var(--wa); }
.btn.accent { background: var(--accent); }
.btn.block { width: 100%; }
.btn.big { min-height: 64px; font-size: 18px; border-radius: 16px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; display: grid; place-items: center;
  cursor: pointer; flex: none; text-decoration: none;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn.wa { background: var(--wa); color: #fff; }
.icon-btn.call { background: var(--brand-2); color: #fff; }
.icon-btn.plain { background: #eef2f8; color: var(--text); }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
input, textarea, select {
  font: inherit; font-size: 16px; color: var(--text); background: #fff;
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand-2); border-color: transparent; }
textarea { min-height: 96px; resize: vertical; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 52px; }
.eye-btn {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border: 0; background: transparent; color: var(--muted); cursor: pointer;
  display: grid; place-items: center; border-radius: 10px;
}
.eye-btn svg { width: 22px; height: 22px; }
.link-btn { background: none; border: 0; color: var(--brand-2); font: inherit; font-size: 15px; cursor: pointer; padding: 8px; align-self: center; }
.form { display: flex; flex-direction: column; gap: 14px; }
.error { color: var(--danger); font-size: 14px; min-height: 1em; }
.muted { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }

/* ---------- Шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px; background: var(--bg);
}
.topbar .title { flex: 1; min-width: 0; font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-bar { display: flex; align-items: center; gap: 10px; }
.contact-bar .phone { flex: 1; font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; white-space: nowrap; }
.logo { width: 40px; height: 40px; flex: none; }

/* ---------- Вход ---------- */
.auth { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; gap: 20px; padding: 24px 0; }
.auth-hero { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.auth-hero .logo { width: 88px; height: 88px; }
.auth-logo { width: 220px; max-width: 70%; height: auto; border-radius: 28px; box-shadow: var(--shadow); }
.auth-hero .muted { color: #fff; opacity: .9; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: #e8eefc; border-radius: 12px; padding: 4px; }
.tabs button { border: 0; background: transparent; padding: 10px; border-radius: 10px; font: inherit; font-weight: 600; color: var(--brand); cursor: pointer; }
.tabs button[aria-selected="true"] { background: #fff; box-shadow: var(--shadow); }

/* ---------- Окно ИИ ---------- */
.ai-card { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; }
.ai-card h2 { color: #fff; }
.ai-card p { opacity: .85; font-size: 14px; margin: 4px 0 12px; }
.search {
  display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 14px; padding: 4px 4px 4px 14px;
}
.search input { border: 0; padding: 10px 0; }
.search input:focus { outline: none; }
.search svg { width: 20px; height: 20px; color: var(--muted); flex: none; }

.ai-overlay {
  position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column;
  max-width: 520px; margin: 0 auto; animation: grow .18s ease-out;
}
@keyframes grow { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.ai-overlay header { display: flex; align-items: center; gap: 10px; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; background: var(--brand); color: #fff; }
.ai-overlay header h2 { flex: 1; color: #fff; }
.ai-overlay header > svg { width: 28px; height: 28px; flex: none; }
.ai-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.ai-input { display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); }

.bubble { max-width: 85%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.4; }
.bubble.me { align-self: flex-end; background: var(--brand-2); color: #fff; border-bottom-right-radius: 4px; }
.bubble.them { align-self: flex-start; background: #fff; box-shadow: var(--shadow); border-bottom-left-radius: 4px; }
.bubble .meta { font-size: 12px; opacity: .7; margin-bottom: 4px; display: flex; gap: 8px; align-items: center; }
.bubble .media { margin-top: 8px; display: grid; gap: 8px; }
.bubble .media img, .bubble .media video { border-radius: 10px; }
.badge { display: inline-block; align-self: flex-start; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #fff3cd; color: #8a5a00; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.bad { background: #fdecec; color: var(--danger); }
.badge.info { background: #e8eefc; color: var(--brand); }
.typing { align-self: flex-start; color: var(--muted); font-size: 14px; }

/* ---------- Реклама и меню ---------- */
.ad { padding: 0; overflow: hidden; text-decoration: none; color: inherit; display: block; }
.ad img { width: 100%; aspect-ratio: 16 / 7; object-fit: cover; }
.ad .ad-text { padding: 12px 16px; font-weight: 600; }
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
nav.menu .btn { flex-direction: column; min-height: 96px; gap: 6px; }
nav.menu .btn svg { width: 28px; height: 28px; }
.owner-menu { display: grid; gap: 10px; }

/* ---------- Групповой чат ---------- */
.chat-page { height: 100dvh; padding-bottom: 0; gap: 0; }
.chat-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 8px 0 12px; }
.chat-input { display: flex; gap: 8px; align-items: center; padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); background: var(--bg); }
.bubble.owner { border: 2px solid #ffd666; }

/* ---------- Каталог ---------- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.product { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.product .photo { aspect-ratio: 1; background: #e8eefc; display: grid; place-items: center; cursor: pointer; user-select: none; }
.product .photo img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.product .photo svg { width: 48px; height: 48px; color: var(--brand); opacity: .4; }
.product .body { padding: 10px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.product .name { font-weight: 600; font-size: 14px; flex: 1; }
.product .btn { min-height: 40px; font-size: 15px; }
.hint { text-align: center; font-size: 13px; color: var(--muted); }

.detail-photo { border-radius: var(--radius); overflow: hidden; background: #e8eefc; aspect-ratio: 1; }
.detail-photo img { width: 100%; height: 100%; object-fit: cover; }
.price { font-size: 22px; font-weight: 800; color: var(--brand); }

/* ---------- Лист закупки ---------- */
.promo { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.promo figure { margin: 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.promo figure .img { aspect-ratio: 1; background: #e8eefc; display: grid; place-items: center; }
.promo figure img { width: 100%; height: 100%; object-fit: cover; }
.promo figcaption { padding: 8px 10px; font-weight: 600; font-size: 14px; text-align: center; }
.pay-info { display: grid; gap: 8px; }
.pay-info .line { display: flex; justify-content: space-between; gap: 12px; }
.pay-info .line b { text-align: right; word-break: break-word; }
.buy-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.receipt-preview { border-radius: 12px; max-height: 220px; object-fit: contain; margin: 0 auto; }
.code-row { display: flex; gap: 8px; }
.code-row .grow, .chat-input .grow { flex: 1; min-width: 0; }
.code-row input { text-transform: uppercase; letter-spacing: 2px; font-weight: 700; }
.code-row input::placeholder { text-transform: none; letter-spacing: normal; font-weight: 400; }
.support { text-align: center; display: grid; gap: 10px; }
.support .phone { font-size: 20px; font-weight: 800; }
.result { border: 2px solid var(--accent); }

/* ---------- Владелец ---------- */
.list-item { display: flex; gap: 12px; align-items: flex-start; }
.list-item .thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: #e8eefc; flex: none; }
.list-item .grow { flex: 1; min-width: 0; display: grid; gap: 4px; }
.list-item .text { font-size: 14px; color: var(--muted); white-space: pre-wrap; max-height: 6.5em; overflow: hidden; }
.receipt { border-radius: 12px; max-height: 320px; object-fit: contain; background: #f1f5f9; width: 100%; }
.filter { display: flex; gap: 8px; overflow-x: auto; }
.filter button { flex: none; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px; font: inherit; cursor: pointer; }
.filter button[aria-pressed="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }

.modal-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(15, 23, 41, .5); display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--bg); width: 100%; max-width: 520px; max-height: 92dvh; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50;
  background: var(--text); color: #fff; padding: 12px 18px; border-radius: 12px; max-width: calc(100% - 32px); box-shadow: var(--shadow);
}
.toast.error { background: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 32px 0; }
.spinner { width: 28px; height: 28px; border: 3px solid #cbd5e1; border-top-color: var(--brand-2); border-radius: 50%; animation: spin 1s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
