/* =========================================================
   NeoQ AI — style.css (единый файл: layout + sidebar + chat +
   composer + messages + attachments + animations + mobile + theme)
   Palette: Navy #0f2240 · Gold #b8882e
   Fonts: Cinzel (display) + DM Sans (body)
   ========================================================= */

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

/* ─── VARIABLES (dark по умолчанию) ─────────────────────── */
:root {
  --gold:        #b8882e;
  --gold-light:  #d4a84e;
  --gold-faint:  rgba(184,136,46,.08);
  --navy:        #0f2240;
  --navy-mid:    #1a3660;

  --bg-app:       #0f1117;
  --bg-sidebar:   #171923;
  --bg-chat:      #0f1117;
  --bg-bubble-ai: #1e2130;
  --bg-input:     #1e2130;
  --bg-topbar:    rgba(15,17,23,.92);
  --bg-hover:     rgba(255,255,255,.06);
  --bg-active:    rgba(255,255,255,.09);

  --text-main:  #e8eaf0;
  --text-soft:  #8b95aa;
  --text-faint: #4a5568;

  --border:      rgba(255,255,255,.08);
  --border-gold: rgba(184,136,46,.28);
  --danger:      #ff6b6b;
  --success:     #2fa87e;

  --sh-sm:   0 2px 8px rgba(0,0,0,.3);
  --sh-md:   0 6px 24px rgba(0,0,0,.4);
  --sh-lg:   0 16px 48px rgba(0,0,0,.55);
  --sh-gold: 0 4px 20px rgba(184,136,46,.22);

  --sidebar-w:  270px;
  --radius-msg: 16px;
  --transition: all .22s cubic-bezier(.4,0,.2,1);

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

[data-theme="light"] {
  --bg-app:       #f5f5f0;
  --bg-sidebar:   #ffffff;
  --bg-chat:      #f5f5f0;
  --bg-bubble-ai: #ffffff;
  --bg-input:     #ffffff;
  --bg-topbar:    rgba(245,245,240,.92);
  --bg-hover:     rgba(0,0,0,.04);
  --bg-active:    rgba(0,0,0,.07);
  --text-main:    #111318;
  --text-soft:    #5a6478;
  --text-faint:   #9aa3b2;
  --border:       rgba(0,0,0,.08);
  --border-gold:  rgba(184,136,46,.25);
  --sh-sm: 0 2px 8px rgba(0,0,0,.07);
  --sh-md: 0 6px 24px rgba(0,0,0,.1);
  --sh-lg: 0 16px 48px rgba(0,0,0,.14);
}

/* ─── BASE ──────────────────────────────────────────────── */
html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg-app);
  color: var(--text-main);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  transition: background .3s, color .3s;
}

body.modal-open {
  overflow: hidden;
}

.dev-warning-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 10, 17, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity .2s ease, visibility .2s ease;
}

.dev-warning-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.dev-warning-modal {
  width: min(420px, calc(100vw - 28px));
  background: rgba(22, 26, 36, 0.96);
  border: 1px solid rgba(184, 136, 46, 0.4);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  border-radius: 18px;
  padding: 22px 22px 18px;
  text-align: center;
  color: var(--text-main);
}

.dev-warning-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: rgba(184, 136, 46, 0.12);
  font-size: 24px;
}

.dev-warning-modal h2 {
  font-family: 'Cinzel', serif;
  font-size: 26px;
  margin-bottom: 10px;
  color: #f9d98d;
}

.dev-warning-modal p {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-soft);
  margin-bottom: 18px;
}

.dev-warning-actions {
  display: flex;
  justify-content: center;
}

.dev-warning-btn {
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  color: #1a1205;
  font-weight: 700;
  font-size: 14px;
  padding: 11px 22px;
  cursor: pointer;
  box-shadow: var(--sh-gold);
  transition: transform .15s ease, filter .15s ease;
}

.dev-warning-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

.shell { display: flex; height: 100dvh; overflow: hidden; position: relative; }

/* ═══════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 20;
  overflow: hidden;
  transition: width .3s cubic-bezier(.4,0,.2,1), transform .3s cubic-bezier(.4,0,.2,1);
}
.shell.sidebar-hidden .sidebar { width: 0; border-right-color: transparent; }

.sidebar-inner {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  padding: 12px 8px 8px;
  overflow-y: auto; overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar-inner::-webkit-scrollbar { width: 4px; }
.sidebar-inner::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 4px 14px;
}
.sidebar-logo-wrap { display: flex; align-items: center; gap: 9px; min-width: 0; }
.sidebar-logo {
  width: 32px; height: 32px; border-radius: 8px; overflow: hidden;
  background: #fff; border: 1px solid var(--border-gold); flex-shrink: 0;
}
.sidebar-logo img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-brand {
  font-family: 'Cinzel', serif; font-size: 15px; font-weight: 700;
  letter-spacing: .04em; white-space: nowrap;
}
.sidebar-collapse-btn {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  background: none; border: none; color: var(--text-soft);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .18s, color .18s;
}
.sidebar-collapse-btn:hover { background: var(--bg-hover); color: var(--text-main); }

.new-chat-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; min-height: 42px; padding: 10px 12px; margin-bottom: 10px;
  border-radius: 12px; text-align: left; cursor: pointer;
  background: linear-gradient(135deg, rgba(184,136,46,.18), rgba(184,136,46,.07));
  border: 1px solid var(--border-gold);
  color: var(--gold-light);
  font-family: 'DM Sans', sans-serif; font-size: 13.5px;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.new-chat-btn:hover {
  background: linear-gradient(135deg, rgba(184,136,46,.3), rgba(184,136,46,.12));
  box-shadow: var(--sh-gold); transform: translateY(-1px);
}
.new-chat-btn svg { flex-shrink: 0; }

/* ── история чатов ── */
.chat-history-search-wrap { padding: 0 2px 10px; }
.chat-history-search {
  width: 100%; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text-main); font: inherit; font-size: 13px; outline: none;
  transition: border-color .18s;
}
.chat-history-search:focus { border-color: var(--gold); }
.chat-history-search:disabled { opacity: .5; cursor: not-allowed; }

.chat-history-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.chat-history-empty { font-size: 12.5px; color: var(--text-faint); padding: 6px 12px 10px; }

.chat-history-item {
  position: relative;
  display: flex; align-items: center; gap: 9px;
  min-height: 40px; padding: 9px 10px; border-radius: 12px;
  color: var(--text-soft); font-size: 13.5px; cursor: pointer;
  transition: background .18s, color .18s;
  -webkit-tap-highlight-color: transparent;
}
.chat-history-item:hover { background: var(--bg-hover); color: var(--text-main); }
.chat-history-item.active { background: var(--bg-active); color: var(--text-main); }
.chat-history-item .dot {
  width: 5px; height: 5px; border-radius: 1px; flex-shrink: 0;
  background: var(--gold); transform: rotate(45deg); opacity: .7;
}
.chat-history-title {
  flex: 1; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.chat-history-delete {
  border: none; background: transparent; color: var(--text-faint);
  cursor: pointer; font-size: 18px; line-height: 1; padding: 0 3px;
  border-radius: 6px; opacity: 0; transition: opacity .15s, color .15s;
}
.chat-history-item:hover .chat-history-delete { opacity: 1; }
.chat-history-delete:hover { color: var(--danger); background: var(--bg-hover); }

/* подтверждение удаления (long-press) */
.history-confirm {
  position: absolute; inset: 0; z-index: 5;
  background: var(--bg-sidebar); border-radius: 12px;
  display: flex; align-items: center; padding: 0 8px;
  animation: fadeUp .15s ease;
}
.history-confirm__card {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; width: 100%;
}
.history-confirm__card strong { font-size: 12.5px; color: var(--text-main); }
.history-confirm__actions { display: flex; gap: 6px; }
.history-confirm__cancel, .history-confirm__ok {
  border: 1px solid var(--border); background: var(--bg-hover);
  color: var(--text-soft); font: inherit; font-size: 11.5px;
  padding: 5px 9px; border-radius: 8px; cursor: pointer;
}
.history-confirm__ok { border-color: rgba(255,107,107,.5); color: var(--danger); }

/* ── FAQ ── */
.history-label {
  font-size: 11px; font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text-faint); padding: 8px 12px 6px;
}
#faqList { list-style: none; display: flex; flex-direction: column; gap: 1px; }
.faq-item { border-radius: 10px; overflow: hidden; }
.faq-q {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 40px; padding: 9px 12px; border-radius: 10px; cursor: pointer;
  color: var(--text-soft); font-size: 13.5px; user-select: none;
  transition: background .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.faq-q:hover { background: var(--bg-hover); color: var(--text-main); }
.faq-item.open .faq-q { background: var(--bg-active); color: var(--text-main); }
.faq-q-left { display: flex; align-items: center; gap: 9px; min-width: 0; }
.faq-q-left span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.faq-icon { font-size: 14px; flex-shrink: 0; }
.faq-arrow { flex-shrink: 0; color: var(--text-faint); opacity: .6; transition: transform .22s ease; }
.faq-item.open .faq-arrow { transform: rotate(180deg); opacity: 1; }
.faq-a {
  display: grid; grid-template-rows: 0fr; padding: 0 12px;
  color: var(--text-soft); font-size: 12.5px; line-height: 1.68;
  transition: grid-template-rows .22s ease;
}
.faq-item.open .faq-a { grid-template-rows: 1fr; padding-bottom: 10px; }
.faq-a-inner { overflow: hidden; padding-top: 8px; border-top: 1px solid var(--border); }

/* ── контакты ── */
.contact-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; margin-bottom: 6px; border-radius: 10px;
  background: var(--bg-hover); border: 1px solid var(--border);
  text-decoration: none; transition: background .18s, border-color .18s;
}
.contact-link:hover { background: rgba(184,136,46,.1); border-color: var(--border-gold); }
.contact-link__icon {
  width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.contact-link__icon--tg { background: rgba(40,160,240,.15); color: #29A8EB; }
.contact-link__icon--ig { background: rgba(220,80,150,.15); color: #E1306C; }
.contact-link__info { flex: 1; min-width: 0; }
.contact-link__label { font-size: 10.5px; color: var(--text-faint); }
.contact-link__handle {
  font-size: 12.5px; color: var(--text-main);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.contact-link__arrow { color: var(--text-faint); flex-shrink: 0; }

/* ── низ сайдбара: карточка юзера + dropdown ── */
.sidebar-bottom {
  flex-shrink: 0; padding: 8px; position: relative;
  border-top: 1px solid var(--border);
}

.nq-dropdown {
  position: absolute; bottom: calc(100% + 6px); left: 8px; right: 8px;
  background: var(--bg-sidebar); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--sh-lg); z-index: 400; overflow: hidden;
  opacity: 0; transform: translateY(10px) scale(.98); pointer-events: none;
  transition: opacity .2s cubic-bezier(.4,0,.2,1), transform .2s cubic-bezier(.4,0,.2,1);
}
.nq-dropdown.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.nq-dropdown__header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 16px 12px; border-bottom: 1px solid var(--border);
}
.nq-dropdown__avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600; color: var(--navy);
  box-shadow: var(--sh-gold);
}
.nq-dropdown__header-info { flex: 1; min-width: 0; }
.nq-dropdown__name {
  font-size: 13px; font-weight: 500; color: var(--text-main);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nq-dropdown__email {
  font-size: 11px; color: var(--text-faint); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nq-dropdown__plan-badge {
  display: inline-flex; align-items: center; gap: 3px; margin-top: 4px;
  padding: 2px 7px; border-radius: 5px; font-size: 10px; font-weight: 500;
  background: var(--bg-hover); border: 1px solid var(--border); color: var(--text-faint);
}
.nq-dropdown__list { list-style: none; padding: 4px; display: flex; flex-direction: column; gap: 1px; }
.nq-dropdown__item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  color: var(--text-soft); font: inherit; font-size: 13px;
  background: transparent; border: none; text-decoration: none; outline: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .18s, color .18s;
  -webkit-tap-highlight-color: transparent;
}
.nq-dropdown__item:hover { background: var(--bg-hover); color: var(--text-main); }
.nq-dropdown__item:focus-visible { background: var(--bg-hover); box-shadow: inset 0 0 0 1.5px rgba(184,136,46,.35); }
.nq-dropdown__icon {
  width: 26px; height: 26px; border-radius: 8px; flex-shrink: 0;
  background: var(--bg-hover); display: flex; align-items: center; justify-content: center;
  font-size: 12px; transition: background .15s;
}
.nq-dropdown__item:hover .nq-dropdown__icon { background: rgba(184,136,46,.12); }
.nq-dropdown__logout {
  display: flex; align-items: center; gap: 11px;
  width: calc(100% - 12px); margin: 3px 6px 6px; padding: 9px 10px;
  border-radius: 10px; background: none; border: none; cursor: pointer;
  color: rgba(255,100,100,.75); font: inherit; font-size: 13.5px;
  transition: background .15s, color .15s;
}
.nq-dropdown__logout:hover { background: rgba(220,60,60,.1); color: #ff6666; }
[data-theme="light"] .nq-dropdown__logout { color: #cc4444; }
.nq-dropdown__logout-icon {
  width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;
  background: rgba(220,60,60,.1);
  display: flex; align-items: center; justify-content: center;
}

.nq-user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 9px; border-radius: 12px; cursor: pointer;
  user-select: none; outline: none; transition: background .18s;
  -webkit-tap-highlight-color: transparent;
}
.nq-user-card:hover { background: var(--bg-hover); }
.nq-user-card.active { background: var(--bg-active); }
.nq-user-card:focus-visible { box-shadow: 0 0 0 2px rgba(184,136,46,.4); }
.nq-user-card__avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: var(--navy);
}
.nq-user-card__info { flex: 1; min-width: 0; }
.nq-user-card__name {
  font-size: 13px; font-weight: 500; color: var(--text-main);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nq-user-card__plan { font-size: 11px; color: var(--text-faint); }
.nq-user-card__dots { color: var(--text-faint); flex-shrink: 0; transition: color .18s; }
.nq-user-card:hover .nq-user-card__dots { color: var(--text-soft); }

/* backdrop (mobile) */
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.6); opacity: 0; pointer-events: none;
  transition: opacity .3s ease;
}

/* ═══════════════════════════════════════════════════════
   CHAT PANEL
   ═══════════════════════════════════════════════════════ */
.chat-panel {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  overflow: hidden; background: var(--bg-chat);
  position: relative; transition: background .3s;
}

.topbar {
  height: 56px; padding: 0 16px; flex-shrink: 0; z-index: 10;
  background: var(--bg-topbar);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.topbar-left  { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.topbar-title {
  font-family: 'Cinzel', serif; font-size: 16px; font-weight: 600;
  letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-logo {
  width: 28px; height: 28px; border-radius: 7px; overflow: hidden; flex-shrink: 0;
  background: #fff; border: 1px solid var(--border-gold);
}
.topbar-logo img { width: 100%; height: 100%; object-fit: cover; }

.sidebar-toggle {
  width: 36px; height: 36px; border-radius: 8px; padding: 6px;
  background: none; border: none; cursor: pointer; color: var(--text-soft);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  transition: background .18s, color .18s;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-toggle:hover { background: var(--bg-hover); color: var(--text-main); }
.sidebar-toggle span { display: block; width: 18px; height: 1.5px; border-radius: 2px; background: currentColor; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 8px;
  background: none; border: none; color: var(--text-soft); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .18s, color .18s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-main); }
.icon-btn .icon-moon { display: block; }
.icon-btn .icon-sun  { display: none; }
[data-theme="light"] .icon-btn .icon-moon { display: none; }
[data-theme="light"] .icon-btn .icon-sun  { display: block; }

/* ─── MESSAGES ─────────────────────────────────────────── */
.messages {
  flex: 1; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  padding: 24px 0 16px;
  display: flex; flex-direction: column;
  scroll-behavior: smooth;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* welcome */
.welcome {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: 14px; padding: 48px 20px 20px;
  animation: fadeUp .5s cubic-bezier(.25,.46,.45,.94) both;
}
.welcome.hidden { display: none; }
.welcome-logo {
  width: 72px; height: 72px; border-radius: 22px; overflow: hidden;
  background: #fff; border: 1.5px solid var(--border-gold);
  box-shadow: var(--sh-gold), var(--sh-lg);
}
.welcome-logo img { width: 100%; height: 100%; object-fit: cover; }
.welcome-kicker {
  font-family: 'Cinzel', serif; font-size: 11px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--gold);
}
.welcome-heading {
  font-family: 'Cinzel', serif; font-size: 22px; font-weight: 700; letter-spacing: .03em;
}
.welcome-sub {
  font-size: 14.5px; color: var(--text-soft);
  max-width: 380px; line-height: 1.65; font-weight: 300;
}
.suggestion-grid {
  display: grid; gap: 8px; margin-top: 6px;
  width: 100%; max-width: 520px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.suggestion {
  display: flex; align-items: center; gap: 9px;
  min-height: 44px; padding: 12px 14px; border-radius: 14px;
  background: var(--bg-bubble-ai); border: 1px solid var(--border);
  color: var(--text-soft); font: inherit; font-size: 13px;
  cursor: pointer; text-align: left; transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.suggestion:hover {
  border-color: var(--border-gold); background: var(--bg-hover);
  color: var(--text-main); transform: translateY(-1px); box-shadow: var(--sh-sm);
}
.sug-icon { font-size: 16px; flex-shrink: 0; }

/* rows + bubbles */
.msg-row {
  display: flex; width: 100%; padding: 6px 0;
  animation: fadeUp .3s cubic-bezier(.25,.46,.45,.94) both;
}
.msg-row--user { justify-content: flex-end;   padding-right: 16px; padding-left: 48px; }
.msg-row--ai   { justify-content: flex-start; padding-left: 16px;  padding-right: 48px; }

.bubble--user {
  position: relative; max-width: 680px;
  padding: 12px 18px;
  border-radius: var(--radius-msg) var(--radius-msg) 4px var(--radius-msg);
  background: var(--bg-bubble-ai); border: 1px solid var(--border);
  color: var(--text-main); font-size: 15px; line-height: 1.68;
  word-break: break-word; overflow-wrap: anywhere; user-select: text;
}
[data-theme="dark"] .bubble--user { background: rgba(255,255,255,.05); }

.bubble--ai {
  max-width: 760px; width: 100%;
  color: var(--text-main); font-size: 15px; line-height: 1.75;
  word-break: break-word; overflow-wrap: anywhere; user-select: text;
}
.bubble-content { position: relative; }
.msg-row--ai.is-error .bubble-content { color: #ff8a8a; }

/* typing dots */
.dots-loader { display: flex; align-items: center; gap: 5px; padding: 4px 0; min-height: 28px; }
.dots-loader span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--gold);
  opacity: .3; animation: dotPulse 1.4s ease-in-out infinite;
}
.dots-loader span:nth-child(2) { animation-delay: .2s; }
.dots-loader span:nth-child(3) { animation-delay: .4s; }

/* actions под сообщением */
.msg-actions {
  display: flex; align-items: center; gap: 4px; margin-top: 8px;
  opacity: 0; transition: opacity .18s;
}
.msg-row--ai:hover .msg-actions { opacity: 1; }
.copy-btn {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  border: 1px solid var(--border); background: var(--bg-bubble-ai);
  color: var(--text-faint); cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.copy-btn:hover { border-color: var(--border-gold); color: var(--gold); background: var(--bg-hover); }
.copy-btn.copied { border-color: var(--success); color: var(--success); }
.copy-btn svg { pointer-events: none; }
.regen-btn svg { transition: transform .4s ease; }
.regen-btn:hover svg { transform: rotate(-180deg); }

.bubble--user .copy-btn {
  position: absolute; bottom: -10px; right: 0;
  opacity: 0; transition: opacity .18s;
}
.bubble--user:hover .copy-btn { opacity: 1; }

/* источники */
.source-cards { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.source-card {
  display: flex; flex-direction: column; max-width: 220px;
  padding: 8px 10px; border-radius: 12px;
  border: 1px solid var(--border); text-decoration: none;
  font-size: 12px; color: var(--text-soft);
  transition: border-color .18s;
}
.source-card:hover { border-color: var(--border-gold); }
.source-card strong { font-size: 13px; color: var(--text-main); }
.source-card span { opacity: .6; margin-top: 2px; }

/* вложения внутри пузыря */
.bubble-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.image-preview {
  max-width: 240px; max-height: 200px; border-radius: 12px;
  display: block; cursor: zoom-in;
}
.video-preview { max-width: 100%; border-radius: 12px; display: block; }
.file-tag {
  font-size: 12px; color: var(--text-soft);
  background: var(--bg-hover); border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 12px;
}

/* ─── MARKDOWN ─────────────────────────────────────────── */
.markdown p { margin: 0 0 .7em; line-height: 1.75; }
.markdown p:last-child { margin-bottom: 0; }
.markdown h1, .markdown h2, .markdown h3 {
  font-family: 'Cinzel', serif; margin: 1.1em 0 .5em; letter-spacing: .02em;
}
.markdown h1:first-child, .markdown h2:first-child, .markdown h3:first-child { margin-top: 0; }
.markdown h1 { font-size: 18px; } .markdown h2 { font-size: 16px; } .markdown h3 { font-size: 15px; }
.markdown ul, .markdown ol { margin: .5em 0 .75em 1.4em; display: flex; flex-direction: column; gap: 3px; }
.markdown li { line-height: 1.68; }
.markdown strong { font-weight: 600; }
.markdown em { font-style: italic; color: var(--text-soft); }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
.markdown a { color: var(--gold); text-decoration: underline; text-underline-offset: 2px; }
.markdown a:hover { color: var(--gold-light); }
.markdown blockquote {
  border-left: 3px solid var(--gold); margin: .75em 0; padding: 8px 16px;
  background: var(--gold-faint); border-radius: 0 8px 8px 0; color: var(--text-soft);
}
.markdown code {
  font-family: 'JetBrains Mono','Fira Code',monospace; font-size: 13px;
  background: var(--bg-hover); color: var(--gold-light);
  padding: 2px 6px; border-radius: 5px; border: 1px solid var(--border);
}
[data-theme="light"] .markdown code { color: var(--navy); background: rgba(0,0,0,.04); }
.markdown pre {
  position: relative; margin: .75em 0; padding: 16px 18px 14px;
  background: var(--bg-sidebar); border: 1px solid var(--border);
  border-radius: 10px; overflow-x: auto;
}
[data-theme="dark"] .markdown pre { background: rgba(0,0,0,.32); }
.markdown pre code {
  background: none; border: none; padding: 0;
  font-size: 13px; color: var(--text-main);
}
.code-lang {
  position: absolute; top: 7px; right: 10px; pointer-events: none;
  font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-faint);
}
.table-scroll { overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); margin: .6em 0; }
.markdown-table { width: 100%; border-collapse: collapse; min-width: 460px; }
.markdown-table th, .markdown-table td {
  padding: 10px 12px; border: 1px solid var(--border); text-align: left;
}
.markdown-table th { background: var(--bg-hover); font-weight: 600; }

/* оверлей картинки */
.image-preview-overlay {
  position: fixed; inset: 0; z-index: 999;
  display: grid; place-items: center; padding: 18px;
  background: rgba(0,0,0,.78); cursor: zoom-out;
  animation: fadeUp .2s ease;
}
.image-preview-overlay img {
  max-width: min(1000px, 100%); max-height: 92vh; object-fit: contain;
  border-radius: 16px; border: 1px solid rgba(255,255,255,.14); box-shadow: var(--sh-md);
}

/* ═══════════════════════════════════════════════════════
   COMPOSER
   ═══════════════════════════════════════════════════════ */
.input-area {
  flex-shrink: 0;
  padding: 8px 16px calc(14px + var(--safe-bottom));
  background: var(--bg-chat); border-top: 1px solid var(--border);
}
.input-wrap {
  max-width: 780px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: stretch;
  background: var(--bg-input); border: 1.5px solid var(--border);
  border-radius: 26px; padding: 6px; box-shadow: var(--sh-sm);
  transition: border-color .22s, box-shadow .22s;
}
.input-wrap:focus-within {
  border-color: rgba(184,136,46,.45);
  box-shadow: 0 0 0 3px rgba(184,136,46,.08);
}
.input-wrap.is-dragover { animation: pulseGlow .9s ease-in-out infinite; border-color: var(--gold); }

.attachment-stack { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; padding: 4px 6px 6px; }
.attachment-stack:empty { display: none; padding: 0; }
.attachment-chip {
  display: flex; align-items: center; gap: 6px; max-width: 200px;
  padding: 5px 10px; border-radius: 14px;
  background: var(--bg-hover); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-soft);
}
.attachment-chip--preview {
  flex-direction: column; align-items: flex-start;
  max-width: 160px; padding: 6px; border-radius: 14px;
}
.attachment-preview-image {
  width: 100%; max-height: 120px; object-fit: cover;
  border-radius: 10px; display: block; cursor: zoom-in;
  background: rgba(0,0,0,.2);
}
[data-theme="light"] .attachment-preview-image { background: #f0f0ea; }
.attachment-chip .name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px;
}
.attachment-chip .remove {
  border: none; background: transparent; color: var(--text-faint);
  cursor: pointer; font-size: 15px; line-height: 1; flex-shrink: 0;
}
.attachment-chip .remove:hover { color: var(--danger); }

.composer-row { display: flex; align-items: flex-end; gap: 4px; }
.chat-textarea {
  flex: 1; min-height: 24px; max-height: 200px;
  padding: 8px 6px; background: none; border: none; outline: none; resize: none;
  font-family: 'DM Sans', sans-serif; font-size: 15px; line-height: 1.5;
  color: var(--text-main); overflow-y: auto; scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.chat-textarea::placeholder { color: var(--text-faint); }

.send-btn, .stop-btn, .voice-btn, .attach-btn {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.voice-btn, .attach-btn { background: transparent; color: var(--text-soft); }
.voice-btn:hover, .attach-btn:hover { background: var(--bg-hover); color: var(--text-main); }
.voice-btn .icon-rec-stop { display: none; }
.voice-btn.recording { color: #ff5a5a; background: rgba(255,90,90,.12); }
.voice-btn.recording .icon-mic { display: none; }
.voice-btn.recording .icon-rec-stop { display: block; }
.attach-btn:disabled, .voice-btn:disabled { opacity: .45; cursor: not-allowed; }

.send-btn {
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  color: #1a1200; box-shadow: var(--sh-gold);
}
.send-btn:hover:not(:disabled) { transform: scale(1.06); box-shadow: 0 6px 22px rgba(184,136,46,.45); }
.send-btn:disabled { background: var(--bg-hover); color: var(--text-faint); box-shadow: none; cursor: not-allowed; }

.stop-btn {
  background: linear-gradient(135deg, #d05252, #e07070);
  color: #fff; box-shadow: 0 4px 18px rgba(220,60,60,.35);
  animation: stopPulse 1.1s ease-in-out infinite;
}

.regenerate-btn {
  display: none; align-items: center; gap: 6px; flex-shrink: 0;
  height: 38px; padding: 0 14px; border-radius: 19px;
  background: var(--bg-hover); border: 1px solid var(--border);
  color: var(--text-soft); font: inherit; font-size: 12.5px; cursor: pointer;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.regenerate-btn:hover { background: rgba(184,136,46,.1); border-color: var(--border-gold); color: var(--text-main); }

.composer-status {
  max-width: 780px; margin: 6px auto 0;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.upload-status { font-size: 11.5px; color: var(--text-faint); min-height: 15px; }
.upload-status.error { color: var(--danger); }
.voice-status { font-size: 11.5px; color: var(--text-soft); opacity: 0; transition: opacity .15s; }
.voice-status.visible { opacity: 1; }
.input-hint {
  max-width: 780px; margin: 6px auto 0;
  font-size: 11px; color: var(--text-faint); text-align: center;
}

/* ═══════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px) scale(.995); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes dotPulse {
  0%, 60%, 100% { opacity: .2; transform: scale(.8); }
  30%           { opacity: 1;  transform: scale(1.1); }
}
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 rgba(184,136,46,0); }
  50%      { box-shadow: 0 0 18px rgba(184,136,46,.26); }
}
@keyframes stopPulse {
  0%, 100% { transform: scale(1);    box-shadow: 0 4px 18px rgba(220,60,60,.35); }
  50%      { transform: scale(1.04); box-shadow: 0 6px 24px rgba(220,60,60,.55); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════ */
@media (max-width: 900px) { :root { --sidebar-w: 250px; } }

@media (max-width: 720px) {
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 100;
    width: min(84vw, 300px) !important;
    transform: translateX(-100%); box-shadow: var(--sh-lg);
    padding-top: var(--safe-top);
  }
  .shell.sidebar-open .sidebar { transform: translateX(0); }
  .shell.sidebar-hidden .sidebar { transform: translateX(-100%); width: min(84vw,300px) !important; }
  .shell.sidebar-hidden.sidebar-open .sidebar { transform: translateX(0); }

  .sidebar-backdrop { display: block; }
  .shell.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }

  .chat-panel { width: 100% !important; flex: 1 !important; }

  .topbar { height: 52px; padding: 0 12px; }
  .topbar-title { font-size: 15px; }

  .messages { padding: 16px 0 12px; }
  .msg-row--user { padding-right: 12px; padding-left: 24px; }
  .msg-row--ai   { padding-left: 12px;  padding-right: 24px; }
  .bubble--user, .bubble--ai { max-width: 100%; font-size: 14px; }

  .welcome { padding: 24px 16px 16px; }
  .welcome-logo { width: 64px; height: 64px; border-radius: 18px; }
  .welcome-heading { font-size: 20px; }
  .suggestion-grid { grid-template-columns: 1fr; }

  .input-area { padding: 8px 10px calc(10px + var(--safe-bottom)); }
  .input-wrap { border-radius: 24px; padding: 5px; }
  .composer-row { gap: 2px; }
  .chat-textarea { font-size: 16px; padding: 7px 6px; } /* без zoom на iOS */
  .send-btn, .stop-btn, .voice-btn, .attach-btn { width: 36px; height: 36px; }
  .regenerate-btn { height: 36px; padding: 0 10px; font-size: 12px; }
  .attachment-chip--preview { max-width: 130px; }

  .msg-actions { opacity: 1; }
  .bubble--user .copy-btn { opacity: .6; }
  .chat-history-delete { opacity: 1; }
}

@media (max-width: 390px) {
  .topbar-title { font-size: 13px; }
  .input-hint { display: none; }
  .bubble--user, .bubble--ai { font-size: 13.5px; }
}

@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .welcome { padding: 12px 16px 8px; gap: 8px; }
  .welcome-logo { width: 44px; height: 44px; }
  .welcome-heading { font-size: 16px; }
  .welcome-sub { display: none; }
  .suggestion-grid { grid-template-columns: 1fr 1fr; }
}