*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #273548;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --success: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  background: #0a0f1e;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── Обёртка ── */
#app {
  position: relative;
  width: 100%;
  max-width: 375px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Экраны ── */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  width: 100%;
}
.screen.active { display: flex; }

/* ── Нижнее меню ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 375px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  min-height: 56px;
  transition: color .2s;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn.active { color: var(--accent); }
.nav-btn span { font-size: 22px; line-height: 1; }

/* ── Кнопки ── */
.btn {
  display: flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 12px 20px;
  border-radius: var(--radius-sm); border: none;
  font-size: 16px; font-weight: 600;
  cursor: pointer; width: 100%;
  transition: background .15s, opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: #334155; color: var(--text-muted); cursor: not-allowed; transform: none; }
.btn-secondary { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-secondary:hover { color: var(--text); border-color: var(--text-muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); border: none; }

/* ── Inputs ── */
.input {
  width: 100%; padding: 13px 16px;
  background: var(--surface2); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 16px; outline: none;
  transition: border-color .2s;
  -webkit-appearance: none;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-muted); }
textarea.input { resize: none; -webkit-overflow-scrolling: touch; }

/* ── Чипы ── */
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 16px; border-radius: 50px;
  border: 1.5px solid var(--border);
  background: transparent; color: var(--text);
  font-size: 15px; cursor: pointer;
  min-height: 44px; transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.chip.selected { border-color: var(--accent); background: rgba(99,102,241,.15); color: var(--accent); }
.chip:active { transform: scale(0.96); }

/* ── Card ── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}

/* ── Labels ── */
.label { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; display: block; }
.hint { font-size: 13px; color: var(--warn); margin-top: 8px; }
.char-count { font-size: 12px; color: var(--text-muted); text-align: right; margin-top: 4px; }

/* ── Прогресс онбординга ── */
.progress-dots { display: flex; gap: 6px; justify-content: center; padding: 16px 0 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); transition: background .2s; }
.dot.active { background: var(--accent); }

/* ── Screen header ── */
.screen-header { display: flex; align-items: center; gap: 12px; padding: 16px 20px 0; }
.back-icon {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; cursor: pointer; flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.screen-title { font-size: 17px; font-weight: 600; }

/* ── Оверлей / Попап ── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 200; display: none;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.overlay.active { display: flex; }
.popup {
  background: var(--surface); border-radius: 20px 20px 0 0;
  width: 100%; max-width: 375px;
  padding: 0 20px 32px; max-height: 92dvh;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.popup-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 12px auto 20px; }
.popup-close {
  position: absolute; top: 16px; right: 20px;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface2); border: none;
  color: var(--text-muted); font-size: 16px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* ── Табы ── */
.tabs { display: flex; background: var(--surface2); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 20px; }
.tab-btn {
  flex: 1; padding: 10px; border: none; border-radius: 6px;
  background: transparent; color: var(--text-muted);
  font-size: 15px; font-weight: 500; cursor: pointer; transition: all .2s;
}
.tab-btn.active { background: var(--surface); color: var(--text); font-weight: 600; }

/* ── Cookie banner ── */
#cookie-banner {
  position: fixed; bottom: 56px; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 375px;
  background: var(--surface2); border-top: 1px solid var(--border);
  padding: 12px 20px; display: flex; align-items: center; gap: 12px;
  z-index: 150; font-size: 13px; color: var(--text-muted);
}
#cookie-banner button { flex-shrink: 0; padding: 8px 16px; min-height: 36px; font-size: 14px; }

/* ── AI Чат ── */
.chat-area {
  flex: 1; overflow-y: auto;
  padding: 16px 16px calc(120px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
  -webkit-overflow-scrolling: touch;
}
.msg { max-width: 85%; animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity:0; transform: translateY(6px); } to { opacity:1; transform: none; } }
.msg-user { align-self: flex-end; background: var(--accent); color: #fff; padding: 12px 16px; border-radius: 18px 18px 4px 18px; font-size: 15px; line-height: 1.5; }
.msg-system { align-self: flex-start; background: var(--surface); color: var(--text); padding: 12px 16px; border-radius: 18px 18px 18px 4px; font-size: 15px; line-height: 1.5; border: 1px solid var(--border); }
.msg-variant { align-self: flex-start; background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); padding: 14px 16px; width: 100%; max-width: 100%; }
.variant-label { font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 6px; letter-spacing: .05em; }
.variant-text { font-size: 15px; line-height: 1.5; margin-bottom: 10px; }
.copy-btn { display: flex; align-items: center; gap: 6px; background: rgba(99,102,241,.15); color: var(--accent); border: none; border-radius: 6px; padding: 8px 12px; font-size: 14px; cursor: pointer; min-height: 36px; }

.action-btns { display: flex; flex-wrap: wrap; gap: 8px; align-self: flex-start; }
.action-btn {
  padding: 10px 14px; border-radius: 50px; border: 1.5px solid var(--border);
  background: transparent; color: var(--text); font-size: 14px;
  cursor: pointer; min-height: 44px; transition: all .15s;
  white-space: nowrap;
}
.action-btn.yes { border-color: var(--success); color: var(--success); }
.action-btn.no { border-color: var(--danger); color: var(--danger); }
.action-btn.highlight { border-color: var(--accent); color: var(--accent); background: rgba(99,102,241,.1); }
.action-btn:active { transform: scale(0.96); }

.typing { display: flex; gap: 5px; align-items: center; padding: 4px 0; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); animation: pulse 1.2s ease infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes pulse { 0%,80%,100% { transform: scale(0.7); opacity:.5; } 40% { transform: scale(1); opacity:1; } }

/* ── Ввод сообщения ── */
.chat-input-bar {
  position: fixed;
  bottom: calc(56px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 375px;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 10px 12px; display: flex; gap: 10px; align-items: flex-end;
  z-index: 100;
}
.chat-input-bar textarea {
  flex: 1; min-height: 44px; max-height: 120px;
  background: var(--surface2); border: 1.5px solid var(--border);
  border-radius: 22px; padding: 11px 16px;
  font-size: 16px; color: var(--text); resize: none; outline: none;
  -webkit-overflow-scrolling: touch; font-family: inherit;
}
.chat-input-bar textarea:focus { border-color: var(--accent); }
.send-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); border: none; color: #fff;
  font-size: 18px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.send-btn:disabled { background: var(--border); cursor: not-allowed; }

/* ── Карточка диалога ── */
.dialog-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.dialog-card:active { background: var(--surface2); }
.dialog-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.dialog-info { flex: 1; min-width: 0; }
.dialog-name { font-size: 16px; font-weight: 600; margin-bottom: 3px; }
.dialog-meta { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.delete-btn { width: 40px; height: 40px; border-radius: 50%; background: transparent; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.delete-btn:hover { color: var(--danger); }

/* ── Профиль ── */
.profile-avatar { width: 80px; height: 80px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 700; margin: 0 auto 12px; }
.profile-row { display: flex; justify-content: space-between; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--border); }
.profile-row:last-child { border-bottom: none; }
.profile-key { font-size: 14px; color: var(--text-muted); }
.profile-val { font-size: 15px; font-weight: 500; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.stat-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 10px; text-align: center; }
.stat-num { font-size: 24px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Premium ── */
.plan-card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; align-items: center; justify-content: space-between; transition: border-color .2s; cursor: pointer; margin-bottom: 10px; }
.plan-card.selected { border-color: var(--accent); }
.plan-card.best { border-color: var(--warn); }
.best-badge { font-size: 11px; font-weight: 700; color: var(--warn); background: rgba(245,158,11,.15); padding: 3px 8px; border-radius: 50px; }

/* ── Скролл-контейнер ── */
.scroll-content { flex: 1; overflow-y: auto; padding: 20px; -webkit-overflow-scrolling: touch; padding-bottom: 80px; }

/* ── Чекбоксы ── */
.check-row { display: flex; align-items: flex-start; gap: 12px; padding: 8px 0; }
.check-row input[type=checkbox] { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; accent-color: var(--accent); }
.check-row label { font-size: 12px; color: var(--text-muted); line-height: 1.5; cursor: pointer; }
.check-row label a { color: var(--accent); }

/* ── Toast ── */
#toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: var(--success); color: #fff; padding: 10px 20px;
  border-radius: 50px; font-size: 14px; font-weight: 600;
  z-index: 9999; opacity: 0; pointer-events: none;
  transition: opacity .25s; white-space: nowrap;
}
#toast.show { opacity: 1; }

/* ── Confirm ── */
#confirm-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  z-index: 500; display: none; align-items: center; justify-content: center;
  padding: 20px;
}
#confirm-overlay.active { display: flex; }
.confirm-box { background: var(--surface); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 320px; }
.confirm-title { font-size: 17px; font-weight: 600; margin-bottom: 8px; }
.confirm-text { font-size: 14px; color: var(--text-muted); margin-bottom: 20px; }
.confirm-btns { display: flex; gap: 10px; }
.confirm-btns button { flex: 1; }

/* ── Welcome ── */
.welcome-top {
  flex: 1; background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative; min-height: 50dvh; padding: 40px 20px 60px;
}
.welcome-bottom { background: var(--bg); padding: 32px 24px 48px; display: flex; flex-direction: column; gap: 16px; }
.chat-bubble {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 14px; font-size: 13px;
  color: var(--text); max-width: 240px;
}
.chat-bubble.partner { align-self: flex-start; margin-left: 8px; }
.chat-bubble.ai { align-self: flex-end; margin-right: 8px; border-color: var(--accent); background: rgba(99,102,241,.1); }
.chat-bubbles { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.welcome-logo { font-size: 26px; font-weight: 800; color: var(--text); margin-top: 20px; letter-spacing: -.5px; }
.welcome-logo span { color: var(--accent); }
.welcome-divider { height: 40px; background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%); margin: -1px 0; }

/* ── Онбординг оверлей ── */
.onb-overlay {
  position: fixed;
  top: 0; bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 375px;
  background: var(--bg);
  z-index: 300;
  display: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.onb-overlay.active { display: block; }
.onb-topbar {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex; align-items: center; gap: 12px;
}
.onb-content { padding: 24px 20px 8px; }
.onb-title { font-size: 22px; font-weight: 700; margin-bottom: 6px; line-height: 1.3; }
.onb-subtitle { font-size: 15px; color: var(--text-muted); margin-bottom: 24px; }
.onb-footer { padding: 16px 20px 40px; display: flex; flex-direction: column; gap: 10px; }

/* ── Center screen ── */
.center-screen { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 24px; text-align: center; gap: 16px; }
.big-icon { font-size: 64px; line-height: 1; }

/* ── Skeleton ── */
.skeleton { background: linear-gradient(90deg, var(--surface) 0%, var(--surface2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

/* ── More variants btn ── */
.more-variants-btn {
  align-self: flex-start;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 50px; padding: 10px 18px; font-size: 15px;
  color: var(--text); cursor: pointer; min-height: 44px;
  transition: border-color .15s;
}
.more-variants-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Scrollbar */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Exit guard modal ── */
#exit-guard-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  z-index: 600; display: none; align-items: center; justify-content: center;
  padding: 20px;
}
#exit-guard-overlay.active { display: flex; }
