/* ================= Themes ================= */
:root, [data-theme="dark"] {
  --bg: #0f1115;
  --bg-raised: #171a21;
  --bg-input: #1d212b;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --text-dim: #9aa3b2;
  --accent: #6c7cff;
  --accent-hover: #8491ff;
  --code-bg: #232835;
  --user-bubble: #2b3a6e;
  --glass-bg: rgba(255, 255, 255, .06);
  --glass-border: rgba(255, 255, 255, .16);
  --glass-shadow: rgba(0, 0, 0, .25);
  --radius: 12px;
  --danger: #ff8f8f;
}

[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-raised: #ffffff;
  --bg-input: #ffffff;
  --border: #dde3ef;
  --text: #1c2333;
  --text-dim: #67718a;
  --accent: #4f63e6;
  --accent-hover: #3d51d4;
  --code-bg: #f0f2f8;
  --user-bubble: #dbe4ff;
  --glass-bg: rgba(255, 255, 255, .65);
  --glass-border: rgba(255, 255, 255, .85);
  --glass-shadow: rgba(31, 45, 90, .12);
  --danger: #d64545;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  transition: background .25s ease, color .25s ease;
}

/* ================= Экран приветствия ================= */
.welcome-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(900px 600px at 50% -20%, rgba(0, 119, 255, .22), transparent 70%),
    radial-gradient(600px 400px at 10% 110%, rgba(108, 124, 255, .14), transparent 70%),
    radial-gradient(500px 380px at 95% 100%, rgba(27, 140, 255, .10), transparent 70%),
    var(--bg);
  animation: auth-bg 8s ease-in-out infinite alternate;
  padding: 20px;
}

.welcome-card {
  width: 440px;
  max-width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 42px 34px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55), 0 0 60px rgba(0, 119, 255, .12);
  animation: auth-in .45s ease;
  text-align: center;
}

[data-theme="light"] .welcome-card {
  box-shadow: 0 30px 80px rgba(31, 45, 90, .2), 0 0 60px rgba(0, 119, 255, .1);
}

.welcome-logo {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  animation: logo-pulse 3s ease-in-out infinite;
}

.welcome-title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.25;
  background: linear-gradient(90deg, #7ab8ff, #6c7cff, #9d7bff);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 3s linear infinite;
}

.welcome-sub {
  margin: 0;
  color: var(--text-dim);
  font-size: 14.5px;
  line-height: 1.5;
}

.welcome-features {
  list-style: none;
  margin: 6px 0 8px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  text-align: left;
}

.welcome-features li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--text);
}

.welcome-features li::before {
  content: '✦';
  color: var(--accent-hover);
  flex-shrink: 0;
  font-size: 13px;
  margin-top: 1px;
}

.welcome-start {
  width: 100%;
  background: linear-gradient(135deg, #1b8cff, #6c7cff);
  border: none;
  color: #fff;
  padding: 14px;
  border-radius: 14px;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  box-shadow: 0 8px 28px rgba(27, 140, 255, .35);
  transition: transform .15s ease, box-shadow .15s ease;
}

.welcome-start:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 36px rgba(27, 140, 255, .5);
}

/* ================= Верификация ================= */
.verify-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  text-align: center;
}

.verify-title {
  font-size: 16px;
  font-weight: 600;
}

.verify-text {
  margin: 0;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.5;
}

.verify-code {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 10px;
  padding: 12px 18px;
  border: 1px dashed var(--accent);
  border-radius: 12px;
  background: var(--bg-input);
  color: var(--accent-hover);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  margin: 2px 0;
}

.verify-bot-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: #2aabee;
  color: #fff;
  text-decoration: none;
  padding: 12px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  transition: filter .15s ease, transform .15s ease;
}

.verify-bot-link:hover {
  filter: brightness(1.12);
  transform: translateY(-1px);
}

.verify-status {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
}

.ghost-btn.center-block {
  width: 100%;
  text-align: center;
}

/* ---------- Квота изображений ---------- */
.quota-badge {
  color: var(--text-dim);
  font-size: 12px;
  margin-left: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px 9px;
}

.quota-badge.exhausted {
  color: #ffb35c;
  border-color: rgba(255, 179, 92, .4);
  background: rgba(255, 179, 92, .1);
}

/* ================= Экран входа ================= */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(700px 460px at 50% -10%, rgba(0, 119, 255, .16), transparent 70%),
    radial-gradient(500px 320px at 85% 110%, rgba(108, 124, 255, .10), transparent 70%),
    var(--bg);
  animation: auth-bg 6s ease-in-out infinite alternate;
}

@keyframes auth-bg {
  from { background-position: 0 0, 0 0, 0 0; }
  to { background-position: 40px 20px, -40px -20px, 0 0; }
}

.auth-card {
  width: 344px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
  animation: auth-in .35s ease;
}

[data-theme="light"] .auth-card {
  box-shadow: 0 24px 60px rgba(31, 45, 90, .18);
}

@keyframes auth-in {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.auth-logo {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0 auto;
  animation: logo-pulse 3s ease-in-out infinite;
}

@keyframes logo-pulse {
  0%, 100% { box-shadow: 0 0 22px rgba(0, 119, 255, .45); }
  50% { box-shadow: 0 0 44px rgba(0, 119, 255, .8); }
}

.auth-title {
  text-align: center;
  margin: 0;
  font-size: 24px;
  font-weight: 600;
}

.auth-tabs {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.auth-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  transition: all .15s ease;
}

.auth-tab.active {
  background: var(--accent);
  color: #fff;
}

.auth-card input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 13px;
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color .15s ease;
  margin-bottom: 10px;
}

.auth-card input:focus { border-color: var(--accent); }

.auth-submit {
  width: 100%;
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 11px;
  border-radius: 10px;
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease;
}

.auth-submit:hover { background: var(--accent-hover); }
.auth-submit:disabled { opacity: .6; cursor: wait; }

.auth-error {
  color: var(--danger);
  background: rgba(255, 80, 80, .08);
  border: 1px solid rgba(255, 80, 80, .3);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
}

/* ================= Layout ================= */
.app {
  display: flex;
  width: 100%;
  height: 100vh;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.side-head {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 2px;
}

.logo-img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(108, 124, 255, .45);
}

.side-title {
  font-weight: 600;
  font-size: 16px;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13.5px;
  transition: all .15s ease;
}

.new-chat-btn:hover {
  border-color: var(--accent);
  color: #fff;
}

[data-theme="light"] .new-chat-btn:hover { color: var(--text); }

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s ease;
}

.chat-item:hover { background: var(--bg-input); }
.chat-item.active { background: rgba(108, 124, 255, .14); }

.chat-item-main { flex: 1; min-width: 0; }

.chat-item-title {
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-meta {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 2px;
}

.chat-del {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 7px;
  border-radius: 6px;
  transition: all .12s ease;
}

.chat-item:hover .chat-del { opacity: 1; }
.chat-del:hover { color: var(--danger); background: rgba(255, 80, 80, .1); }

.chat-empty {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 26px 8px;
  line-height: 1.6;
}

.side-foot {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.foot-btns { display: flex; gap: 6px; align-items: center; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1b8cff, #6c7cff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: 14px;
  flex-shrink: 0;
}

.user-name {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ghost-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12.5px;
  flex-shrink: 0;
  transition: all .15s ease;
}

.ghost-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.ghost-btn.icon-only { padding: 6px 7px; display: flex; align-items: center; }
.ghost-btn.small { font-size: 12px; padding: 4px 10px; }

/* ================= Main ================= */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-dim);
  padding: 0 20px;
  text-align: center;
}

.empty-logo {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 32px rgba(0, 119, 255, .45);
  margin-bottom: 6px;
  animation: logo-pulse 4s ease-in-out infinite;
}

.empty-state h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
}

.empty-sub {
  margin: 0;
  font-size: 14px;
  max-width: 420px;
  line-height: 1.5;
}

.messages {
  max-width: 820px;
  margin: 0 auto;
  padding: 24px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.msg {
  display: flex;
  gap: 14px;
  animation: msg-in .3s cubic-bezier(.2, .8, .3, 1);
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px) scale(.99); filter: blur(2px); }
  to { opacity: 1; transform: none; filter: none; }
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  margin-top: 2px;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.bubble { min-width: 0; flex: 1; }

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

.msg.user .bubble {
  background: var(--user-bubble);
  padding: 10px 14px;
  border-radius: var(--radius);
  border-top-right-radius: 4px;
  max-width: 78%;
  white-space: pre-wrap;
  word-break: break-word;
}

[data-theme="light"] .msg.user .bubble { color: #1c2333; }

.msg.assistant .bubble {
  padding: 2px 0;
  line-height: 1.65;
  font-size: 15px;
}

.bubble-img {
  display: block;
  max-width: 260px;
  max-height: 200px;
  border-radius: 10px;
  margin-top: 8px;
  border: 1px solid var(--border);
}

/* Streaming caret */
.caret {
  display: inline-block;
  width: 8px;
  height: 16px;
  background: var(--accent);
  vertical-align: text-bottom;
  margin-left: 2px;
  border-radius: 1px;
  animation: blink 1s steps(2) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* Анимация 1: точки «печатает…» */
.typing-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 7px 2px;
}

.typing-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7ab8ff, #6c7cff);
  animation: dot-bounce 1.2s ease-in-out infinite;
}

.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }

@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0) scale(1); opacity: .35; }
  30% { transform: translateY(-6px) scale(1.15); opacity: 1; }
}

/* Анимация 2: мягкое «дыхание» пузыря во время ответа */
.msg.assistant.streaming .bubble {
  animation: breathe 2.2s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(108, 124, 255, 0); }
  50% { box-shadow: 0 0 20px 2px rgba(108, 124, 255, .14); }
}

/* ================= Markdown ================= */
.bubble h1, .bubble h2, .bubble h3, .bubble h4, .bubble h5 {
  margin: 14px 0 8px;
  line-height: 1.3;
}
.bubble h1 { font-size: 20px; }
.bubble h2 { font-size: 18px; }
.bubble h3 { font-size: 16px; }
.bubble h4 { font-size: 15px; }
.bubble h5 { font-size: 14px; }

.bubble p { margin: 8px 0; }
.bubble ul, .bubble ol { margin: 8px 0; padding-left: 22px; }
.bubble li { margin: 3px 0; }

.bubble code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: .9em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 5px;
}

.bubble blockquote {
  margin: 10px 0;
  padding: 2px 14px;
  border-left: 3px solid var(--accent);
  color: var(--text-dim);
}

.bubble a { color: var(--accent-hover); }

/* ================= Code blocks ================= */
.code-block {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 10px 0;
  overflow: hidden;
}

.code-block pre {
  margin: 0;
  border: none;
  border-radius: 0;
  padding: 12px 14px;
  overflow-x: auto;
}

.code-block pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.55;
  display: block;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px 6px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-input);
}

.code-lang {
  font-size: 12px;
  color: var(--text-dim);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}

.code-actions { display: flex; gap: 6px; }

.code-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s ease;
}

.code-btn:hover { color: var(--text); border-color: var(--accent); }
.code-btn.done { color: #6fd38f; border-color: #6fd38f; }

/* ================= Thinking ================= */
.thinking {
  margin: 0 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-input);
  font-size: 13px;
}

.thinking summary {
  cursor: pointer;
  padding: 8px 12px;
  color: var(--text-dim);
  user-select: none;
  list-style: none;
}

.thinking summary::-webkit-details-marker { display: none; }
.thinking summary::before { content: '▸ '; }
.thinking[open] summary::before { content: '▾ '; }

.thinking-body {
  padding: 0 12px 10px;
  color: var(--text-dim);
  white-space: pre-wrap;
  line-height: 1.55;
  max-height: 260px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}

.dim { color: var(--text-dim); font-size: 13px; }

/* ================= Composer ================= */
.composer-wrap {
  flex-shrink: 0;
  padding: 12px 20px 10px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.composer {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 10px 8px 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 124, 255, .15);
}

.composer textarea {
  flex: 1;
  resize: none;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  max-height: 180px;
  padding: 6px 0;
}

.composer textarea::placeholder { color: var(--text-dim); }

.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  transition: color .15s ease, background .15s ease;
  flex-shrink: 0;
}

.icon-btn:hover { color: var(--text); background: rgba(127, 140, 180, .12); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ================= Стеклянные кнопки (liquid glass) ================= */
.glass-group {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.glass-btn {
  position: relative;
  overflow: hidden;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--text-dim);
  font-size: 12.5px;
  padding: 7px 12px;
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  box-shadow: 0 2px 10px var(--glass-shadow), inset 0 1px 0 rgba(255, 255, 255, .18);
  transition: all .2s ease;
}

[data-theme="light"] .glass-btn {
  box-shadow: 0 2px 10px var(--glass-shadow), inset 0 1px 0 rgba(255, 255, 255, .7);
}

.glass-btn::after {
  content: '';
  position: absolute;
  top: 0;
  left: -80%;
  width: 60%;
  height: 100%;
  background: linear-gradient(105deg, transparent, rgba(255, 255, 255, .35), transparent);
  transform: skewX(-20deg);
  transition: left .5s ease;
  pointer-events: none;
}

.glass-btn:hover::after { left: 120%; }
.glass-btn:hover { color: var(--text); border-color: var(--accent); }

.glass-btn.active {
  color: var(--accent-hover);
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(108, 124, 255, .22), rgba(27, 140, 255, .14));
  box-shadow: 0 0 18px rgba(108, 124, 255, .35), inset 0 1px 0 rgba(255, 255, 255, .2);
}

[data-theme="light"] .glass-btn.active {
  color: #3d51d4;
  background: linear-gradient(135deg, rgba(79, 99, 230, .18), rgba(27, 140, 255, .12));
}

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, opacity .15s ease, transform .1s ease;
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) { background: var(--accent-hover); transform: translateY(-1px); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ================= Прикреплённое фото ================= */
.attach-preview {
  max-width: 820px;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
}

.attach-preview img {
  height: 44px;
  width: 44px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.attach-name {
  flex: 1;
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
  transition: color .15s ease;
}

.remove-btn:hover { color: var(--danger); }

.hint {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  margin: 8px 0 0;
}

/* ================= Сгенерированное фото в чате ================= */
.gen-photo img {
  display: block;
  max-width: 100%;
  max-height: 480px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.gen-caption {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 8px;
}

.link-btn {
  display: inline-block;
  margin-top: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 6px;
  text-decoration: none;
  transition: all .15s ease;
}

.link-btn:hover { color: var(--text); border-color: var(--accent); }

/* ================= Инлайн-карточка генерации ================= */
.gen-card {
  max-width: 380px;
  background: var(--bg-raised);
  border: 1px solid rgba(108, 124, 255, .35);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .4), 0 0 34px rgba(0, 119, 255, .14);
  animation: gen-pop .35s cubic-bezier(.2, .9, .3, 1.15);
}

[data-theme="light"] .gen-card {
  box-shadow: 0 14px 40px rgba(31, 45, 90, .2), 0 0 34px rgba(0, 119, 255, .12);
}

@keyframes gen-pop {
  from { opacity: 0; transform: translateY(14px) scale(.96); }
  to { opacity: 1; transform: none; }
}

.gen-anim {
  position: relative;
  width: 56px;
  height: 56px;
  margin: 2px 0;
}

.gen-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0%, rgba(0, 119, 255, 0) 30%, #1b8cff 60%, #6c7cff 80%, transparent 100%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
  animation: spin 1.1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.gen-orb {
  position: absolute;
  inset: 11px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4db3ff, #0d5fd6 70%);
  animation: orb-breathe 1.6s ease-in-out infinite;
}

@keyframes orb-breathe {
  0%, 100% { transform: scale(1); box-shadow: 0 0 16px rgba(0, 119, 255, .7); }
  50% { transform: scale(1.12); box-shadow: 0 0 30px rgba(0, 119, 255, .95); }
}

.gen-title {
  font-size: 14px;
  font-weight: 600;
  background: linear-gradient(90deg, #7ab8ff, #6c7cff, #7ab8ff);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 2s linear infinite;
}

@keyframes shimmer { to { background-position: -200% 0; } }

.gen-prompt {
  font-size: 12.5px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.45;
  word-break: break-word;
  max-height: 48px;
  overflow-y: auto;
  max-width: 100%;
}

.gen-stage {
  font-size: 12.5px;
  color: var(--accent-hover);
  min-height: 17px;
  animation: stage-fade .3s ease;
}

@keyframes stage-fade {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: none; }
}

.gen-track {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-input);
  overflow: hidden;
}

.gen-bar {
  height: 100%;
  width: 40%;
  border-radius: 2px;
  background: linear-gradient(90deg, #1b8cff, #6c7cff);
  animation: gen-slide 1.2s ease-in-out infinite;
}

@keyframes gen-slide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(280%); }
}

/* ================= Звонок Deep (голосовой режим) ================= */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 98;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse at 50% 35%, rgba(27, 140, 255, .18), rgba(8, 10, 14, .92) 70%);
  backdrop-filter: blur(8px);
  animation: gen-fade .25s ease;
}

[data-theme="light"] .call-overlay {
  background: radial-gradient(ellipse at 50% 35%, rgba(27, 140, 255, .22), rgba(31, 45, 90, .9) 70%);
}

.call-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: min(420px, 100%);
}

.call-avatar {
  width: 108px;
  height: 108px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(27, 140, 255, .5);
  box-shadow: 0 0 45px rgba(27, 140, 255, .35), inset 0 0 30px rgba(27, 140, 255, .15);
  animation: call-breathe 2.6s ease-in-out infinite;
}

.call-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

@keyframes call-breathe {
  0%, 100% { transform: scale(1); box-shadow: 0 0 35px rgba(27, 140, 255, .25), inset 0 0 30px rgba(27, 140, 255, .1); }
  50% { transform: scale(1.045); box-shadow: 0 0 60px rgba(27, 140, 255, .5), inset 0 0 30px rgba(27, 140, 255, .2); }
}

.call-status {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: .2px;
}

.call-wave {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 34px;
}

.call-wave i {
  width: 5px;
  height: 10px;
  border-radius: 3px;
  background: var(--accent);
  opacity: .45;
}

.call-wave.talking i { animation: call-bar 1s ease-in-out infinite; }
.call-wave.talking i:nth-child(2) { animation-delay: .12s; }
.call-wave.talking i:nth-child(3) { animation-delay: .24s; }
.call-wave.talking i:nth-child(4) { animation-delay: .36s; }
.call-wave.talking i:nth-child(5) { animation-delay: .48s; }

@keyframes call-bar {
  0%, 100% { height: 10px; opacity: .4; }
  50% { height: 32px; opacity: 1; }
}

.call-caption {
  min-height: 22px;
  max-height: 120px;
  overflow-y: auto;
  font-size: 14px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
  word-break: break-word;
}

.call-controls {
  display: flex;
  align-items: center;
  gap: 26px;
  margin-top: 8px;
}

.call-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: rgba(27, 140, 255, .15);
  color: var(--text);
  border: 1px solid rgba(27, 140, 255, .35);
  transition: background .15s ease, transform .1s ease;
}

.call-btn:hover { background: rgba(27, 140, 255, .28); }
.call-btn:active { transform: scale(.94); }

.call-btn.muted {
  background: rgba(243, 156, 18, .18);
  border-color: rgba(243, 156, 18, .5);
  color: #f39c12;
}

.call-btn.end {
  width: 76px;
  height: 76px;
  background: rgba(231, 76, 60, .85);
  border-color: rgba(255, 100, 100, .6);
  color: #fff;
  flex-direction: column;
  font-size: 12px;
  font-weight: 600;
  border-radius: 40px;
  box-shadow: 0 6px 24px rgba(231, 76, 60, .35);
}

.call-btn.end:hover { background: #e74c3c; }

/* ================= Настройки ================= */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  background: rgba(8, 10, 14, .4);
  backdrop-filter: blur(3px);
  animation: gen-fade .2s ease;
}

[data-theme="light"] .settings-overlay { background: rgba(31, 45, 90, .25); }

@keyframes gen-fade { from { opacity: 0; } to { opacity: 1; } }

.settings-panel {
  width: 340px;
  height: 100%;
  background: var(--bg-raised);
  border-left: 1px solid var(--border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  animation: panel-in .25s ease;
}

@keyframes panel-in {
  from { transform: translateX(30px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 600;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.settings-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-row label {
  font-size: 13px;
  color: var(--text-dim);
}

.settings-row select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 11px;
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  outline: none;
  cursor: pointer;
}

.settings-row select:focus { border-color: var(--accent); }

.memory-controls { display: flex; justify-content: space-between; align-items: center; }

.memory-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.memory-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  line-height: 1.5;
}

.memory-empty {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 20px 8px;
}

.settings-note {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ================= Админ-панель ================= */
.admin-overlay {
  position: fixed;
  inset: 0;
  z-index: 96;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 10, 14, .55);
  backdrop-filter: blur(4px);
  animation: gen-fade .2s ease;
}

[data-theme="light"] .admin-overlay { background: rgba(31, 45, 90, .3); }

.admin-panel {
  width: min(720px, 100%);
  max-height: 85vh;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
  animation: panel-in .25s ease;
}

.admin-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.admin-toolbar input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  font: inherit;
  font-size: 13.5px;
  outline: none;
}

.admin-toolbar input:focus { border-color: var(--accent); }

.admin-stats {
  font-size: 13px;
  color: var(--text-dim);
  padding: 4px 2px;
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding-right: 4px;
}

.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}

.admin-row-main { min-width: 0; }

.admin-row-name {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.admin-row-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.admin-date { font-size: 12px; color: var(--text-dim); }

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

.badge.ok {
  color: #2ecc71;
  background: rgba(46, 204, 113, .12);
  border: 1px solid rgba(46, 204, 113, .35);
}

.badge.warn {
  color: #f39c12;
  background: rgba(243, 156, 18, .12);
  border: 1px solid rgba(243, 156, 18, .35);
}

.badge.accent {
  color: var(--accent);
  background: rgba(27, 140, 255, .12);
  border: 1px solid rgba(27, 140, 255, .35);
}

.admin-row-stats {
  display: flex;
  gap: 14px;
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
}

.admin-row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

/* Детальный просмотр пользователя (история чатов + память) */
.admin-detail {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-right: 4px;
}

.admin-detail-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.admin-detail-title {
  font-size: 14px;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-detail-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  padding-right: 4px;
}

.admin-sec { display: flex; flex-direction: column; gap: 8px; }

.admin-sec-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.admin-chat {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.admin-chat summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
}

.admin-chat summary::-webkit-details-marker { display: none; }

.admin-chat[open] summary { border-bottom: 1px solid var(--border); }

.admin-chat-title {
  font-size: 13.5px;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-chat-meta {
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: nowrap;
}

.admin-chat-msgs {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px 12px;
  max-height: 340px;
  overflow-y: auto;
}

.admin-msg { display: flex; flex-direction: column; gap: 3px; }

.admin-msg-role {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.admin-msg-role.user { color: var(--accent); }
.admin-msg-role.ai { color: var(--text-dim); }

.admin-msg-text {
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.admin-img-tag {
  font-size: 12px;
  color: var(--text-dim);
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 0 6px;
}

.admin-mem-list { display: flex; flex-direction: column; gap: 6px; }

.admin-mem-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

.admin-mem-text {
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}

.ghost-btn.small.danger {
  color: #e74c3c;
  border-color: rgba(231, 76, 60, .35);
}

/* ================= Голос Deep (озвучка ответов) ================= */
.msg-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  margin-left: 44px;
}

.msg-speak {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background .15s ease, opacity .2s ease;
}

.msg-speak:hover {
  color: var(--accent);
  border-color: rgba(27, 140, 255, .45);
  background: rgba(27, 140, 255, .08);
}

.msg-speak.playing {
  color: var(--accent);
  border-color: rgba(27, 140, 255, .55);
  background: rgba(27, 140, 255, .14);
  animation: speak-pulse 1.4s ease-in-out infinite;
}

.msg-speak:disabled { opacity: .55; cursor: wait; }

@keyframes speak-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(27, 140, 255, .25); }
  50% { box-shadow: 0 0 0 5px rgba(27, 140, 255, 0); }
}

/* ================= Ошибка ================= */
.msg.error .bubble {
  color: var(--danger);
  background: rgba(255, 80, 80, .08);
  border: 1px solid rgba(255, 80, 80, .3);
  border-radius: var(--radius);
  padding: 10px 14px;
  white-space: pre-wrap;
}

/* ================= Режим «Код» ================= */
body.code-mode .composer { border-color: rgba(108, 124, 255, .55); }
body.code-mode .glass-btn.active { border-color: #4fd6a0; }
body.code-mode .code-head { background: linear-gradient(90deg, rgba(79, 214, 160, .12), transparent); }

/* ================= Мобильная адаптация ================= */
.mobile-bar { display: none; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 89;
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(2px);
}

@media (max-width: 820px) {
  .app { height: 100dvh; }

  /* Верхняя панель с гамбургером */
  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top));
    border-bottom: 1px solid var(--border);
    background: var(--bg-raised);
    flex-shrink: 0;
  }

  /* Сайдбар превращается в выдвижную шторку */
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 280px;
    max-width: 84vw;
    z-index: 90;
    transform: translateX(-105%);
    visibility: hidden;
    pointer-events: none;
    transition: transform .25s ease, visibility .25s;
    box-shadow: 0 0 50px rgba(0, 0, 0, .5);
  }

  .sidebar.open {
    transform: none;
    visibility: visible;
    pointer-events: auto;
  }

  /* Поле ввода: текст+кнопки в один ряд, стеклянные кнопки снизу */
  .composer-wrap {
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  }

  .composer { flex-wrap: wrap; padding: 8px; }
  .composer textarea { order: 0; min-width: 0; }
  #attachBtn { order: 1; }
  #sendBtn { order: 2; }

  .glass-group {
    order: 3;
    width: 100%;
    justify-content: stretch;
  }

  .glass-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 6px;
    font-size: 12.5px;
  }

  /* Панели и карточки на всю ширину */
  .settings-panel { width: 100%; }

  .admin-overlay { padding: 10px; }
  .admin-panel { max-height: 92dvh; padding: 14px; }

  .admin-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .admin-row-actions { width: 100%; }
  .admin-row-actions .ghost-btn { flex: 1; text-align: center; }

  .welcome-card { padding: 30px 22px 26px; }
  .welcome-title { font-size: 22px; }

  .hint { font-size: 11px; }

  .msg.user .bubble, .msg.assistant .bubble { max-width: 92%; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a4150; }
