/* GunCen — Design System v1.0 (DESIGN.md): тёплый тёмный фон, янтарный акцент */

:root {
  /* Поверхности — тёплый тёмный, НЕ серо-синий */
  --bg: #1a1815;            /* основной фон — тёплый глубокий */
  --bg-elevated: #211e1a;   /* сайдбар, модалки */
  --surface: #262320;       /* карточки, композер */
  --surface-2: #2f2b26;     /* hover, вторичные элементы */
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);

  /* Текст */
  --text: #ede8e0;          /* тёплый белый */
  --text-dim: #a89f94;      /* вторичный */
  --text-faint: #7a736a;    /* третичный (не использовать < 12px) */

  /* Акцент — янтарь, только для действий и статуса (≤ 5% поверхности) */
  --accent: #f5a623;
  --accent-soft: rgba(245, 166, 35, 0.14);
  --accent-glow: rgba(245, 166, 35, 0.25);

  /* Семантика */
  --ok: #4ade80;
  --danger: #ef4444;
  --warn: #facc15;

  /* Код */
  --code-bg: #282c34;
  --code-header: rgba(255, 255, 255, 0.04);

  /* Spring-кривые — единые для всего */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);  /* появление, пружина */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);        /* движение, таяние */
  --ease-fast: cubic-bezier(0.22, 1, 0.36, 1);       /* hover-кривая (алиас ease-out) */
  --dur-fast: 160ms;  /* hover, кнопки */
  --dur-base: 280ms;  /* модалки, карточки */
  --dur-slow: 420ms;  /* панели, лента */

  /* Тени и глубина */
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-modal: 0 8px 40px rgba(0, 0, 0, 0.5);
  --glow-accent: 0 0 12px var(--accent-glow);

  /* Радиусы */
  --r-sm: 8px;    /* чипы, кнопки-иконки */
  --r-md: 14px;   /* карточки, композер-внутри */
  --r-lg: 20px;   /* композер, модалки */

  /* Шрифты */
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Layout */
  --sidebar-w: 260px;

  /* Legacy-алиасы: компонентные секции ниже пока ссылаются на старые имена.
     Убрать, когда компоненты переведут на токены выше. */
  --sidebar-bg: var(--bg-elevated);
  --accent-hover: var(--accent);
  --accent-dim: var(--accent-soft);
  --radius-md: var(--r-md);
  --radius-lg: var(--r-lg);
}

* { box-sizing: border-box; }

/* Перебивает авторские display:flex у #login-screen/#app — иначе hidden не прячет. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

code, pre, kbd {
  font-family: var(--font-mono);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

textarea, input {
  font-family: inherit;
  color: var(--text);
}

/* Доступность: видимый фокус на всех интерактивных */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::selection {
  background: var(--accent-soft);
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.16); }
::-webkit-scrollbar-track { background: transparent; }
/* macOS overlay: ползунок тает, когда лента не под курсором */
#feed:not(:hover)::-webkit-scrollbar-thumb,
#chat-list:not(:hover)::-webkit-scrollbar-thumb { background: transparent; }

/* A11y: сокращённая анимация — всё схлопывается до мгновения */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }

/* ===== Экран входа ===== */

#login-screen {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 380px;
  max-width: 100%;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 32px 28px;
  text-align: center;
}

.brand {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--accent);
}

.brand-sub {
  margin: 8px 0 26px;
  font-size: 13px;
  color: var(--text-dim);
}

.key-row {
  position: relative;
  display: flex;
  align-items: center;
}

#key-input {
  width: 100%;
  padding: 12px 44px 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  outline: none;
}
#key-input:focus { border-color: var(--accent); }

.key-row .icon-btn {
  position: absolute;
  right: 6px;
  width: 32px;
  height: 32px;
}

.login-error {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--danger);
  text-align: left;
}

.login-btn {
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  background: var(--accent);
  color: #1a1a1a;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-md);
}
.login-btn:hover { background: var(--accent-hover); }
.login-btn:disabled { opacity: 0.6; cursor: default; }

.login-note {
  margin: 18px 0 0;
  font-size: 11px;
  color: var(--text-faint);
}

/* ===== Каркас приложения ===== */

#app {
  display: flex;
  height: 100dvh;
}

/* --- Сайдбар --- */

#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px;
}

.sb-top { flex-shrink: 0; }

/* ===== v2.1: плашка активного диалога (Notes-стиль) ===== */
/* Скрытие — атрибутом hidden (глобальное [hidden]{display:none!important} выше),
   поэтому состояния appear/disappear тут нет: автоплей один раз при показе.
   prefers-reduced-motion глушит анимацию глобальным блоком вверху файла. */
.dialog-pill {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 8px 10px 4px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  animation: pill-in 280ms var(--ease-out);
}
@keyframes pill-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.dp-model {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.dp-date {
  font-size: 10px;
  color: var(--text-faint);
}
.dp-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--text);
  transition: background var(--dur-fast) var(--ease-fast), border-color var(--dur-fast) var(--ease-fast), color var(--dur-fast) var(--ease-fast);
}
.new-chat:hover { background: var(--surface); border-color: var(--accent); color: var(--accent); }

#chat-list {
  flex: 1;
  overflow-y: auto;
  margin-top: 12px;
}

.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin: 4px 8px;
  padding: 9px 10px;
  border-left: 3px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13.5px;
  transition: background var(--dur-fast) var(--ease-fast), border-color var(--dur-fast) var(--ease-fast), color var(--dur-fast) var(--ease-fast);
}
.chat-item:hover { background: var(--surface-2); color: var(--text); }
.chat-item.active { background: var(--surface); border-left-color: var(--accent); color: var(--text); }

.chat-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-del {
  width: 26px;
  height: 26px;
  opacity: 0;
  color: var(--text-faint);
  transition: opacity var(--dur-fast) var(--ease-fast);
}
.chat-item:hover .chat-del { opacity: 1; }
.chat-del:hover { color: var(--danger); background: transparent; }
.chat-del svg { width: 15px; height: 15px; }

.chat-empty {
  padding: 24px 10px;
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
}

.sb-bottom {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 12px;
}

.usage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  padding: 0 4px 10px;
}
#tariff-name { color: var(--accent); font-weight: 600; }

.logout-btn {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text-dim);
  transition: background var(--dur-fast) var(--ease-fast), color var(--dur-fast) var(--ease-fast);
}
.logout-btn:hover { background: var(--surface); color: var(--text); }

.sb-disclaimer {
  margin: 10px 0 0;
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
}

/* --- Основная колонка --- */

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 16px;
  flex-shrink: 0;
  background: rgba(26, 24, 21, 0.85); /* fallback для FF<113 / Safari<16.2 */
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.burger { display: none; }

.model-switch { position: relative; }

.model-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--surface);
  font-size: 14px;
  color: var(--text);
  transition: background var(--dur-fast) var(--ease-fast);
}
.model-btn:hover { background: var(--surface-2); }

.model-menu {
  position: absolute;
  top: 42px;
  left: 0;
  min-width: 300px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  z-index: 30;
}

.model-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  text-align: left;
  font-size: 14px;
  color: var(--text);
}
.model-item:hover { background: var(--surface); }
.model-item.active { color: var(--accent); }

.model-price {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 999px;
  padding: 3px 8px;
}

/* --- Лента сообщений --- */

#feed {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  scrollbar-gutter: stable; /* gutter постоянный: никакого сдвига ленты при появлении скроллбара */
}

#feed-inner {
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  padding: 24px 20px 32px;
}

.msg {
  margin-bottom: 16px;
  transition:
    background var(--dur-fast) var(--ease-fast),
    border-radius var(--dur-fast) var(--ease-fast);
}

/* ховер пары (v2.1), минимально: мягкая подсветка каждого сообщения отдельно */
@media (hover: hover) {
.msg:hover {
  background: rgba(255, 255, 255, 0.025);
  border-radius: 12px;
}
}

.msg.user {
  display: flex;
  justify-content: flex-end;
}

.bubble {
  max-width: 78%;
  background: var(--surface);
  border-radius: 18px 18px 6px 18px;
  padding: 10px 16px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}

/* голос ассистента (v2.1): flat слева, янтарная полоска-градиент */
.msg.assistant {
  position: relative;
  border-left: 2px solid transparent;
  padding-left: 14px;
}
.msg.assistant::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 2px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), transparent 90%);
  opacity: 0.5;
}

/* дыхание-точки ожидания (v2.1, iMessage): в начале ответа, пока ни одного чанка;
   .out — fade 300ms при первом чанке (content или reasoning) */
.generating-dots {
  display: inline-flex;
  gap: 5px;
  height: 14px;
  animation: dotsFadeIn 300ms var(--ease-out) both;
}
.generating-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotsWave 1.2s ease-in-out infinite;
}
.generating-dots i:nth-child(2) { animation-delay: 200ms; }
.generating-dots i:nth-child(3) { animation-delay: 400ms; }
.generating-dots.out {
  position: absolute;
  pointer-events: none;
  animation: dotsFadeOut 300ms var(--ease-out) forwards;
}
@keyframes dotsFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes dotsFadeOut { to { opacity: 0; } }
@keyframes dotsWave {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.msg.assistant .md {
  line-height: 1.7;
  word-break: break-word;
}

/* markdown-контент ответа */
.md p { margin: 0 0 12px; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 20px 0 10px; line-height: 1.3; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 24px; }
.md li { margin-bottom: 4px; }
.md blockquote {
  margin: 0 0 12px;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--accent);
  color: var(--text-dim);
}
.md a { color: var(--accent); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.md table { border-collapse: collapse; margin: 0 0 12px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; font-size: 14px; }
.md :not(pre) > code {
  background: var(--surface);
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 13px;
}

/* Тач: hover нет — удаление чата всегда видимо. */
@media (hover: none) {
  .chat-del { opacity: 1; }
}

/* курсор стрима: мягкий пульс, высота = line-height */
.cursor {
  display: inline-block;
  width: 9px;
  height: 1.5em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--text);
  border-radius: 2px;
  animation: cursorPulse 900ms ease-in-out infinite;
}
@keyframes cursorPulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

/* карточка ошибки API */
.msg-error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
  padding: 12px 16px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: var(--radius-md);
  color: #f87171;
  font-size: 14px;
  line-height: 1.5;
}

.retry-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  border: 1px solid rgba(239, 68, 68, 0.5);
  border-radius: 9px;
  color: #f87171;
  font-size: 13px;
}
.retry-btn:hover { background: rgba(239, 68, 68, 0.15); }

/* кнопка регенерации под последним ответом */
.msg-actions {
  margin: -12px 0 20px;
  display: flex;
  gap: 6px;
}
.msg-actions .icon-btn { width: 30px; height: 30px; color: var(--text-faint); }
.msg-actions .icon-btn:hover { color: var(--accent); background: transparent; }
.msg-actions svg { width: 16px; height: 16px; }

/* --- Приветственный экран --- */

.welcome {
  min-height: 60%;
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 8vh;
  text-align: center;
  animation: welcome-in 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes welcome-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.welcome-logo {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: var(--accent-dim);
  margin-bottom: 20px;
  animation: welcome-glow 3s ease-in-out infinite;
}
.welcome-logo svg { width: 34px; height: 34px; }

@keyframes welcome-glow {
  0%, 100% { box-shadow: 0 0 0 rgba(245, 158, 11, 0); }
  50% { box-shadow: 0 0 24px rgba(245, 158, 11, 0.25); }
}

.welcome h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}

.welcome-sub {
  font-size: 14px;
  color: var(--text-faint);
  margin: 0 0 28px;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  gap: 16px 20px;
  width: 100%;
}

.suggestion-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  text-align: left;
  transition:
    transform 160ms cubic-bezier(0.34, 1.56, 0.64, 1),
    border-color 160ms ease,
    background 160ms ease;
}
.suggestion-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-dim);
  background: var(--surface-2);
}
.suggestion-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.suggestion-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent-dim);
  color: var(--accent);
  margin-bottom: 5px;
}
.suggestion-icon svg { width: 16px; height: 16px; }

.suggestion-title { font-size: 13px; font-weight: 600; color: var(--text); }
.suggestion-desc { font-size: 12px; color: var(--text-faint); line-height: 1.5; }
.suggestion-prompt {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- Композер (ввод) --- */

.composer {
  flex-shrink: 0;
  /* Ось ленты: feed-inner паддинг 20px + скроллбар-гаттер 6px. Композер центрируется с ней */
  padding: 0 26px 14px;
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 800px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 14px 16px;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.composer-box:focus-within {
  border-color: rgba(245, 166, 35, 0.4);
  box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.12), var(--shadow-card);
}

#msg-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  font-size: 15px;
  line-height: 1.5;
  max-height: 200px;
  padding: 4px 0;
}
#msg-input::placeholder { color: var(--text-faint); }

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #1a1a1a;
  flex-shrink: 0;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn.stop { background: var(--text); }
.send-btn svg { width: 17px; height: 17px; }

.composer-hint {
  max-width: 768px;
  margin: 8px auto 0;
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
  transition: opacity var(--dur-fast) var(--ease-out);
}
.composer:has(.composer-box:focus-within) .composer-hint { opacity: 0; }

/* --- Мобильная адаптация --- */

#overlay { display: none; }

/* Единый mobile-блок 768px вынесен в конец файла —
   чтобы гарантированно перебивать базовые правила выше по каскаду. */


/* ===== Тариф-карточка (Apple-стиль: кольцо-индикатор лимита, тонкие линии) ===== */
.plan-card {
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 13px;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}
.plan-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
}
.plan-ring { width: 56px; height: 56px; flex-shrink: 0; }
.plan-ring-track { stroke: rgba(255,255,255,.08); stroke-width: 5; }
.plan-ring-fill {
  stroke: var(--accent);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 163.36; /* 2π·26 */
  stroke-dashoffset: 163.36;
  transition: stroke-dashoffset 600ms var(--ease-out, cubic-bezier(.22,1,.36,1));
}
/* Живое кольцо: мягкий янтарный glow при наведении на карточку */
.plan-card:hover .plan-ring-fill { filter: drop-shadow(0 0 5px rgba(245,158,11,.4)); }
.plan-ring.limit-hit .plan-ring-fill { stroke: var(--danger); }
.plan-ring.limit-hit .plan-percent { fill: var(--danger); }
.plan-percent {
  fill: var(--text);
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.plan-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  min-width: 0;
}
.plan-name {
  font-weight: 500;
  font-size: 13px;
  letter-spacing: .2px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plan-days {
  color: var(--text-dim);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
}

.upgrade-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--accent);
  color: #1a1a1a;
  font-weight: 600;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 8px;
  transition: transform 160ms var(--ease-out, cubic-bezier(.22,1,.36,1)), filter 160ms var(--ease-out, cubic-bezier(.22,1,.36,1));
}
.upgrade-btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.upgrade-btn:active { transform: translateY(0) scale(.98); }

.logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 12px;
  border-radius: 12px;
}
.logout-btn:hover { background: var(--surface); color: var(--text); }

/* ===== Витрина подписок (Apple: blur-подложка, тонкие карточки, SVG-иконки) ===== */
#plans-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(10px);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: plansFade var(--dur-base) var(--ease-out);
}
@keyframes plansFade { from { opacity: 0; } to { opacity: 1; } }
#plans-modal {
  background: rgba(28,28,30,.92);
  backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 20px;
  padding: 30px;
  max-width: 920px; width: 100%;
  max-height: 90dvh; overflow-y: auto;
  position: relative;
  animation: plansUp var(--dur-base) var(--ease-out);
  box-shadow: 0 24px 80px rgba(0,0,0,.5);
}
@keyframes plansUp { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
#plans-modal h2 { margin: 0 0 4px; font-size: 21px; font-weight: 600; letter-spacing: .2px; }
.plans-sub { margin: 0 0 20px; color: var(--text-faint); font-size: 13px; }
.plans-close {
  position: absolute; top: 16px; right: 16px;
  background: rgba(255,255,255,.06);
  border: none;
  width: 30px; height: 30px;
  border-radius: 999px;
  color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--dur-fast) var(--ease-fast), color var(--dur-fast) var(--ease-fast);
}
.plans-close:hover { background: var(--surface); color: var(--text); }
.plans-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.plan-tile {
  background: rgba(255,255,255,.045);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
  padding: 18px 16px;
  position: relative;
  transition: border-color var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out);
}
.plan-tile:hover { border-color: rgba(245,158,11,.4); transform: translateY(-2px); }
.plan-tile.popular { border-color: rgba(245,158,11,.65); }
.plan-pop {
  position: absolute; top: -9px; right: 14px;
  background: var(--accent); color: #1a1a1a;
  font-size: 10px; font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  padding: 3px 10px; border-radius: 999px;
}
.plan-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: rgba(245,158,11,.12);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
}
.plan-tile h3 { margin: 0 0 3px; font-size: 15px; font-weight: 600; }
.plan-tag { margin: 0 0 12px; color: var(--text-faint); font-size: 12px; }
.plan-tile ul { margin: 0; padding-left: 15px; color: var(--text-dim); font-size: 12px; display: flex; flex-direction: column; gap: 6px; }
.plan-tile ul b { color: var(--text); }
.plan-note { margin: 12px 0 0; color: var(--text-faint); font-size: 11px; font-style: italic; }
.plans-cta { margin: 20px 0 0; text-align: center; color: var(--text-dim); font-size: 13px; }
.plans-cta a { color: var(--accent); text-decoration: none; }
.plans-cta a:hover { text-decoration: underline; }

/* ===== v4: лайв-лимит в композере ===== */
/* ===== v4: мысли модели — стеклянная карточка с дыханием ===== */
.think-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 0 0 12px;
  overflow: hidden;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: border-color .28s cubic-bezier(.22,1,.36,1),
              background-color .28s cubic-bezier(.22,1,.36,1),
              box-shadow .28s cubic-bezier(.22,1,.36,1);
}
.think-card.empty { display: none; }

.think-head {
  width: 100%;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 500;
  padding: 0 12px;
  cursor: pointer;
  transition: color .28s cubic-bezier(.22,1,.36,1),
              background-color .28s cubic-bezier(.22,1,.36,1);
}
.think-head:hover { color: var(--text-dim); }
.think-head:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 12px; }
.think-spark { flex-shrink: 0; color: var(--accent); opacity: .85; }
.think-badge { color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* пульс-точки: только пока карточка открыта и reasoning ещё идёт */
.think-dots { display: none; flex-shrink: 0; gap: 3px; }
.think-card.open:not(.done) .think-dots { display: flex; }
.think-dots i {
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: var(--text-faint);
  animation: thinkWave 1.4s infinite;
}
.think-dots i:nth-child(2) { animation-delay: .2s; }
.think-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes thinkWave { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* дыхание: янтарная пульсация бордюра во время стрима мыслей */
.think-card.open:not(.done) {
  animation: thinkBreath 2s ease-in-out infinite;
}
@keyframes thinkBreath {
  0%, 100% { border-color: var(--border); box-shadow: none; }
  50% { border-color: rgba(245, 158, 11, .45); box-shadow: 0 0 12px rgba(245, 158, 11, .15); }
}

.think-chev {
  margin-left: auto;
  flex-shrink: 0;
  transition: transform .28s cubic-bezier(.22,1,.36,1);
}
.think-card.open .think-chev { transform: rotate(180deg); }

.think-body {
  display: none;
  padding: 2px 14px 12px;
  color: var(--text-faint);
  font-size: 12.5px;
  line-height: 1.55;
  font-style: italic;
  white-space: pre-wrap;
  max-height: 220px;
  overflow-y: auto;
  animation: thinkFade .28s cubic-bezier(.22,1,.36,1);
}
.think-card.open .think-body { display: block; }
@keyframes thinkFade { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }

.think-body::-webkit-scrollbar { width: 6px; }
.think-body::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .15); border-radius: 999px; }
.think-body::-webkit-scrollbar-track { background: transparent; }

/* свернутая карточка — компактный бейдж-полоска */
.think-card.done { background: rgba(255, 255, 255, .03); }
.think-card.done:hover { background: var(--surface-2); border-color: rgba(255, 255, 255, .12); }

@media (prefers-reduced-motion: reduce) {
  .think-card.open:not(.done) { animation: none; }
  .think-dots i { animation: none; opacity: .6; }
  .think-body { animation: none; }
}

/* ===== v4: код-блок с header ===== */
/* atom-one-dark локально (переменные живут на .code-block, не в :root).
   Переопределения селекторами .code-block .hljs-* (0,2,0) бьют CDN-тему (0,1,0),
   style.css подключён после CDN — не зависим от неё полностью. */
.code-block {
  --code-bg: #282c34;            /* DESIGN.md, тёплый тёмный */
  --code-fg: #abb2bf;
  --code-comment: #5c6370;
  --code-keyword: #c678dd;
  --code-string: #98c379;
  --code-function: #61afef;
  --code-number: #d19a66;
  --code-title: #e5c07b;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin: 20px 0; /* v2.1: воздух вокруг код-блоков в ленте */
  background: var(--code-bg);
}
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 36px;
  padding: 0 6px 0 14px;
  background: var(--code-header);
  border-bottom: 1px solid var(--border);
}
.code-lang {
  color: var(--text-faint);
  font-size: 11px;
  font-family: "JetBrains Mono", ui-monospace, Consolas, monospace;
  text-transform: lowercase;
  letter-spacing: .4px;
}
.code-tools { display: flex; gap: 4px; }
.code-tool {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 24px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-faint);
  cursor: pointer;
  transition: color .15s ease, background .15s ease;
}
.code-tool:hover { color: var(--text); background: rgba(255,255,255,.07); }
.code-tool.active { color: var(--accent); }
.code-tool:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* тост «Скопировано» на кнопке «в новый файл» (отдельного тост-слоя в проекте нет) */
.code-tool-file::after {
  content: attr(data-toast);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity .15s ease, transform .15s ease;
  pointer-events: none;
  z-index: 2;
}
.code-tool-file.copied::after { opacity: 1; transform: none; }

.code-body { position: relative; }
.code-block.is-collapsed .code-body::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 56px;
  background: linear-gradient(to bottom, transparent, var(--code-bg));
  pointer-events: none;
}

.code-block pre {
  margin: 0;
  padding: 12px 14px;
  max-height: 480px;
  overflow: auto;
  background: transparent;
}
/* свёрнут: первые 24 строки (20.8px строка при 13px/1.6) + padding сверху, без скролла */
.code-block.is-collapsed pre {
  max-height: calc(24 * 20.8px + 12px);
  overflow: hidden;
}
.code-block pre.wrap-on code { white-space: pre-wrap; word-break: break-word; }
.code-block code {
  display: block;
  font-family: "JetBrains Mono", ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  background: transparent;
  padding: 0;
}
/* токены atom-one-dark поверх CDN-темы */
.code-block .hljs { color: var(--code-fg); background: transparent; }
.code-block .hljs-comment, .code-block .hljs-quote { color: var(--code-comment); font-style: italic; }
.code-block .hljs-keyword, .code-block .hljs-doctag, .code-block .hljs-formula { color: var(--code-keyword); }
.code-block .hljs-string, .code-block .hljs-regexp, .code-block .hljs-addition { color: var(--code-string); }
.code-block .hljs-number { color: var(--code-number); }
.code-block .hljs-title, .code-block .hljs-title.class_, .code-block .hljs-class .hljs-title { color: var(--code-title); }
.code-block .hljs-title.function_, .code-block .hljs-function .hljs-title, .code-block .hljs-built_in { color: var(--code-function); }

/* футер свёрнутого блока: «Показать полностью (N строк)» */
.code-expand {
  display: block;
  width: 100%;
  padding: 8px 14px;
  background: rgba(255,255,255,.03);
  border: none;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: color .15s ease, background .15s ease;
}
.code-expand:hover { color: var(--text); background: rgba(255,255,255,.06); }
.code-expand:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.code-block:not(.is-collapsed) .code-expand { display: none; }
/* нумерация строк и подсветка строки по hover не делаем: требует оборачивать
   строки в div — ломает span-подсветку hljs (span может пересекать перевод строки) */

/* ===== v4: анимации сообщений ===== */
/* Появление только у хвоста ленты — при renderFeed старая история не мигает. */
#feed-inner > *:nth-last-child(-n+2) {
  animation: msgUp var(--dur-base) var(--ease-out);
}
@keyframes msgUp { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===== Мобильная адаптация: единый блок 768px ===== */
/* В конце файла: перебивает все базовые правила выше по каскаду (в т.ч. витрину планов). */
@media (max-width: 768px) {
  .burger { display: inline-flex; }

  /* Сайдбар off-canvas: только transform, без layout-thrash */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform var(--dur-base) var(--ease-out); /* --dur-base = 280ms */
  }
  body.sidebar-open #sidebar { transform: translateX(0); }

  #overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 35;
  }
  body.sidebar-open #overlay { display: block; }

  .chat-del { opacity: 1; }

  #feed-inner { padding: 16px; }
  .bubble { max-width: 88%; }

  .welcome { padding-top: 20vh; }
  .welcome h1 { font-size: 22px; }
  .suggestions { grid-template-columns: 1fr; }

  .model-menu { left: 0; min-width: 260px; }

  /* Композер: компактнее + safe-area, textarea 16px против iOS-зума, кнопка 44px под палец */
  .composer {
    padding: 0 12px 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .composer-box { padding: 12px; }
  #msg-input { font-size: 16px; }
  .send-btn { width: 44px; height: 44px; }
  .composer-hint { display: none; }

  /* Витрина подписок: одна колонка */
  #plans-modal { padding: 20px 14px; }
  .plans-grid { grid-template-columns: 1fr; }
}


/* ===== Sticky-scroll кнопка «к последнему сообщению» ===== */
.scroll-to-bottom {
  position: absolute;
  bottom: 130px;
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
  z-index: 5;
}
.scroll-to-bottom.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.scroll-to-bottom:hover { color: var(--text); border-color: rgba(245,166,35,.4); }

/* Запрет pinch-zoom на тач-устройствах (viewport уже user-scalable=no) */
@media (pointer: coarse) {
  html, body { touch-action: pan-x pan-y; }
  #feed { overscroll-behavior: contain; }
}

/* ===== Мобильная донастройка (v11) ===== */
@media (max-width: 768px) {
  .scroll-to-bottom { bottom: 120px; }
  #topbar { padding: 0 12px; }
  .model-btn { max-width: 240px; }
  #model-label { font-size: 13px; }
  .welcome-logo { width: 48px; height: 48px; }
  .welcome-logo svg { width: 28px; height: 28px; }
  .welcome h1 { font-size: 20px; }
  .welcome-sub { font-size: 13px; margin-bottom: 20px; }
  .msg { padding: 6px 2px; }
  .msg.assistant { padding-left: 14px; } /* полоска-голос не наезжает на текст */
  .bubble { font-size: 15px; }
  .md { font-size: 15px; }
  .code-block { margin: 10px 0; }
  .code-header { padding: 6px 8px; }
  .plan-card { padding: 9px 10px; }
  .upgrade-btn { padding: 9px 10px; font-size: 12px; }
}

/* ===== v5: индикатор соединения в топбаре ===== */
/* Янтарная = онлайн (DESIGN.md v2.1: точка статуса, не декора), серая = офлайн. */
.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  margin-left: auto;
  margin-right: 2px;
  flex-shrink: 0;
  transition: background var(--dur-base) var(--ease-out), box-shadow var(--dur-base);
}
.conn-dot.online {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  /* лёгкое дыхание: 1 → 1.15, мягкий subtitle-пульс */
  animation: connPulse 2s ease-in-out infinite alternate;
}
.conn-dot.offline { background: var(--text-faint); box-shadow: none; animation: none; }

@keyframes connPulse { from { transform: scale(1); } to { transform: scale(1.15); } }
