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

:root {
  --sidebar-bg: #171717;
  --main-bg: #212121;
  --surface: #2f2f2f;
  --surface2: #3d3d3d;
  --accent: #10a37f;
  --accent-hover: #0d8a6b;
  --text: #ececec;
  --text-dim: #8e8ea0;
  --border: #3d3d3d;
  --user-bubble: #2f2f2f;
  --code-bg: #1a1a1a;
}

[data-theme="light"] {
  --sidebar-bg: #f0f0f0;
  --main-bg: #ffffff;
  --surface: #e8e8e8;
  --surface2: #d8d8d8;
  --accent: #10a37f;
  --accent-hover: #0d8a6b;
  --text: #0d0d0d;
  --text-dim: #6e6e80;
  --border: #d0d0d0;
  --user-bubble: #e8e8e8;
  --code-bg: #f4f4f4;
}
[data-theme="light"] .chat-ctx-menu { background: #fff; }
[data-theme="light"] .think-block { background: #f5f5ff; border-color: #ddd; }
[data-theme="light"] .think-content { color: #555; }
[data-theme="light"] .msg-content code:not(pre code) { background: #eee; color: #b45309; }
[data-theme="light"] .msg-content pre { background: #f4f4f4; border-color: #ddd; }
[data-theme="light"] .about-name span { background: linear-gradient(135deg, #10a37f, #7c3aed); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--main-bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* LAYOUT */
.layout {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* SIDEBAR */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  transition: transform 0.25s ease;
  z-index: 100;
}

.sidebar-top {
  padding: 12px 10px 8px;
}

.new-chat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.new-chat-btn:hover { background: var(--surface); }
.new-chat-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

/* CHAT LIST */
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px;
}

.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-group-label {
  font-size: 11px;
  color: var(--text-dim);
  padding: 10px 6px 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
  gap: 6px;
  margin-bottom: 2px;
}
.chat-item:hover { background: var(--surface); color: var(--text); }
.chat-item.active { background: var(--surface); color: var(--text); }

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

.chat-item-menu {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.chat-item:hover .chat-item-menu { opacity: 1; }
.chat-item-menu:hover { background: var(--surface2); color: var(--text); }

/* CONTEXT MENU */
.chat-ctx-menu {
  position: fixed;
  background: #222;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  min-width: 170px;
  z-index: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  animation: ctxIn 0.12s ease;
}
@keyframes ctxIn {
  from { opacity: 0; transform: scale(0.95) translateY(-4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.ctx-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  border-radius: 7px;
  text-align: left;
  transition: background 0.12s;
}
.ctx-item:hover { background: var(--surface); }
.ctx-danger { color: #ef4444; }
.ctx-danger:hover { background: rgba(239,68,68,0.12); }
.ctx-divider { height: 1px; background: var(--border); margin: 3px 6px; }

/* RENAME INPUT */
.chat-rename-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 5px;
  color: var(--text);
  font-size: 13.5px;
  padding: 2px 6px;
  outline: none;
  width: 100%;
  font-family: inherit;
}

/* ARCHIVED ITEM */
.archived-item .chat-item-title { opacity: 0.55; }

/* TOAST */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 600;
  animation: toastIn 0.2s ease;
  pointer-events: none;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.sidebar-bottom {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
}

.user-avatar { font-size: 22px; }
.user-name { font-size: 14px; color: var(--text-dim); }

/* MAIN */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--main-bg);
}

/* TOPBAR */
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 10px 16px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
/* выравниваем боковые кнопки по центру относительно заголовка */
.topbar > .menu-btn,
.topbar > div[style] {
  margin-top: 6px;
}
.topbar-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-bottom: 10px;
}

/* NEXUS LOGO POPUP */
.nexus-logo-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.nexus-logo-wrap .topbar-title {
  cursor: pointer;
  user-select: none;
}
.nexus-logo-wrap .topbar-title:hover { opacity: 0.85; }

.agent-pick-hint {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 7px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color 0.15s;
}
.agent-pick-hint:hover { color: var(--accent); }
.agent-pick-arrow {
  transition: transform 0.2s;
  flex-shrink: 0;
}
.agent-pick-hint.open .agent-pick-arrow {
  transform: rotate(180deg);
}

.nexus-info-popup {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: #13131f;
  border: 1px solid #2e2e45;
  border-radius: 14px;
  padding: 6px 0;
  min-width: 300px;
  max-width: 380px;
  z-index: 200;
  box-shadow: 0 12px 40px rgba(0,0,0,.6);
  animation: nipFadeIn .15s ease;
}
.nexus-info-popup.open { display: block; }
@keyframes nipFadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
/* стрелка вверх */
.nexus-info-popup::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid #2e2e45;
}
.nip-header {
  font-size: 11px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 8px 16px 6px;
  border-bottom: 1px solid #1e1e30;
}
.nip-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 16px;
  transition: background .15s;
  cursor: pointer;
  border-bottom: 1px solid #1a1a2a;
}
.nip-item:last-child { border-bottom: none; }
.nip-item:hover { background: #7c3aed18; }
.nip-item:hover .nip-dot { background: #a78bfa; }
.nip-item.nip-active { background: #7c3aed14; }
.nip-item.nip-active .nip-dot { background: #7c3aed; box-shadow: 0 0 6px #7c3aed88; }
.nip-dot {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #444;
  margin-top: 5px;
  transition: background .2s, box-shadow .2s;
}
.nip-item div { display: flex; flex-direction: column; gap: 2px; }
.nip-mode {
  font-size: 12px;
  font-weight: 700;
  color: #c4b5fd;
  line-height: 1.3;
}
.nip-desc {
  font-size: 11px;
  color: #888;
  line-height: 1.45;
}

/* ПК — agent bar чуть крупнее */
@media (min-width: 701px) {
  .agent-btn { font-size: 13px; padding: 5px 14px; }
  .agent-desc { font-size: 12px; }
  .nexus-info-popup { min-width: 340px; max-width: 420px; }
  .nip-mode { font-size: 13px; }
  .nip-desc { font-size: 12px; }
}

/* Мобилка — попап на всю ширину снизу */
@media (max-width: 700px) {
  .nexus-info-popup {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    border-radius: 16px 16px 0 0;
    max-width: 100%;
    min-width: unset;
    padding-bottom: env(safe-area-inset-bottom, 12px);
    animation: nipSlideUp .2s ease;
  }
  .nexus-info-popup::before { display: none; }
  @keyframes nipSlideUp {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
  }
  .nip-item { padding: 12px 18px; }
  .nip-mode { font-size: 13px; }
  .nip-desc { font-size: 12px; }
}

.menu-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}
.menu-btn:hover { background: var(--surface); color: var(--text); }
.menu-btn svg { width: 20px; height: 20px; }

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

/* CHAT BOX */
.chat-box {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.chat-box::-webkit-scrollbar { width: 6px; }
.chat-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* WELCOME */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 40px 20px;
  gap: 20px;
  color: var(--text-dim);
}
.welcome p { font-size: 15px; max-width: 400px; }

/* NEXUS LOGO IMAGES */
.nexus-logo-img {
  width: 110px;
  height: 110px;
  animation: logoPulse 3s ease-in-out infinite, titleIn 0.6s ease both;
  filter: drop-shadow(0 0 18px rgba(0, 212, 255, 0.35)) drop-shadow(0 0 8px rgba(139, 92, 246, 0.3));
}

.nexus-logo-sm {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  filter: drop-shadow(0 0 4px rgba(0, 212, 255, 0.4));
}

@keyframes logoPulse {
  0%, 100% { filter: drop-shadow(0 0 18px rgba(0,212,255,0.35)) drop-shadow(0 0 8px rgba(139,92,246,0.3)); }
  50%       { filter: drop-shadow(0 0 28px rgba(0,212,255,0.6)) drop-shadow(0 0 14px rgba(139,92,246,0.5)); }
}

/* NEXUS TITLE (welcome) */
.nexus-title {
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
  animation: titleIn 0.6s ease both;
}
.nexus-title span {
  background: linear-gradient(135deg, #7c3aed, #10a37f, #60a5fa);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: gradientShift 4s ease infinite;
}

@keyframes titleIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes gradientShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* NEXUS LOGO (topbar) */
.nexus-logo {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.nexus-logo span {
  background: linear-gradient(135deg, #7c3aed, #10a37f);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: gradientShift 4s ease infinite;
}

/* NEXUS SMALL (sidebar bottom) */
.nexus-small {
  font-size: 14px;
  font-weight: 600;
}
.nexus-small span {
  background: linear-gradient(135deg, #7c3aed, #10a37f);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* MESSAGES */
.message {
  animation: fadeIn 0.25s ease;
  width: 100%;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 24px;
}

.msg-avatar { display: none; }

/* USER MESSAGE — пузырь справа */
.user-message {
  padding: 20px 0 4px;
  display: flex;
  justify-content: flex-end;
}

.user-message .message-inner {
  display: flex;
  justify-content: flex-end;
  width: 100%;
}

.user-message .msg-content {
  background: #2f2f2f;
  border-radius: 20px;
  padding: 10px 18px;
  font-size: var(--msg-font, 15px);
  line-height: 1.6;
  color: var(--text);
  max-width: 560px;
  width: fit-content;
}

/* Compact mode */
.chat-box.compact .ai-message { padding: 8px 0 10px; }
.chat-box.compact .user-message { margin-bottom: 4px; }

/* AI MESSAGE — чистый текст без фона */
.ai-message {
  padding: 16px 0 20px;
}

.ai-message .message-inner {
  display: block;
}

.ai-message .msg-content {
  font-size: var(--msg-font, 15px);
  line-height: 1.75;
  color: var(--text);
}
.ai-message .msg-content > div {
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-message .msg-content > div[style*="opacity"] {
  display: block;
}
.msg-done {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 11px;
  color: #4a5568;
  user-select: none;
}
.msg-done-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent, #00d4ff);
  opacity: 0.7;
}

/* MARKDOWN */
.msg-content p { margin-bottom: 10px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content h1, .msg-content h2, .msg-content h3 {
  margin: 20px 0 8px;
  color: var(--text);
  font-weight: 700;
}
.msg-content h1 { font-size: 18px; }
.msg-content h2 { font-size: 16px; }
.msg-content h3 { font-size: 15px; }
.msg-content ul, .msg-content ol { padding-left: 22px; margin-bottom: 10px; }
.msg-content li { margin-bottom: 5px; }
.msg-content strong { color: #fff; }
.msg-content .katex-display { overflow-x: auto; margin: 6px 0; }
.msg-content li .katex-display { margin: 4px 0 2px; }
.msg-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}
.msg-content code:not(pre code) {
  background: var(--surface);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: #e2a85d;
  font-family: 'Consolas', monospace;
}
.msg-content pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  overflow-x: auto;
  margin: 10px 0;
}
.msg-content pre code { font-size: 13px; font-family: 'Consolas', monospace; }

.chat-image {
  max-width: 100%;
  max-height: 260px;
  border-radius: 10px;
  margin-bottom: 10px;
  display: block;
  object-fit: contain;
}

/* THINK BLOCK */
.think-block {
  background: #1a1a2e;
  border: 1px solid #2d2d4e;
  border-radius: 10px;
  margin-bottom: 14px;
  overflow: hidden;
}
.think-block summary {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s;
}
.think-block summary:hover { color: var(--text); }
.think-block[open] summary { color: #a855f7; border-bottom: 1px solid #2d2d4e; }
.think-content {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.65;
}
.think-content p { margin-bottom: 8px; }

/* EXPORT BUTTONS */
.export-btns {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.export-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.export-btn svg { width: 15px; height: 15px; }
.export-btn:hover { border-color: var(--accent); color: var(--text); background: var(--surface2); }
.pdf-btn:hover { border-color: #ef4444; color: #ef4444; }
.pptx-btn:hover { border-color: #f97316; color: #f97316; }

/* THINKING LABEL */
.thinking-label {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-style: italic;
}
.think-dots::after {
  content: '...';
  animation: thinkDots 1.2s steps(4, end) infinite;
}
@keyframes thinkDots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
  100% { content: ''; }
}

/* TYPING */
.typing-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 0;
}
.dot {
  width: 7px; height: 7px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* INPUT WRAPPER */
.input-wrapper {
  padding: 12px 16px 16px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  flex-shrink: 0;
}

/* IMAGE PREVIEW */
.image-preview-area { margin-bottom: 8px; }
.image-preview-inner { position: relative; display: inline-block; }
.image-preview-inner img {
  max-height: 100px;
  max-width: 180px;
  border-radius: 8px;
  border: 2px solid var(--accent);
  object-fit: cover;
  display: block;
}
.remove-image {
  position: absolute; top: -7px; right: -7px;
  width: 20px; height: 20px;
  border-radius: 50%; border: none;
  background: #ef4444; color: white;
  font-size: 10px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.remove-image:hover { background: #dc2626; }

/* AGENT BAR */
.agent-bar {
  display: none;
}
.agent-bar::-webkit-scrollbar { display: none; }
.agent-btn {
  flex-shrink: 0;
  padding: 4px 11px;
  border-radius: 20px;
  border: 1px solid #333;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
  line-height: 1.4;
}
.agent-btn:hover { border-color: #666; color: var(--text-main); background: #2a2a2a; }
.agent-btn.active {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(124,58,237,.35);
}
.agent-desc {
  display: none;
}

/* INPUT BOX */
.input-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 10px;
  transition: border-color 0.2s;
}
.input-box:focus-within { border-color: #555; }

.tool-btn {
  width: 36px; height: 36px;
  border: none; background: none;
  color: var(--text-dim); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px; flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.tool-btn:hover { background: var(--surface2); color: var(--text); }
.tool-btn.has-image { color: var(--accent); }
.tool-btn svg { width: 18px; height: 18px; }

textarea {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  padding: 6px 4px;
  resize: none;
  outline: none;
  max-height: 160px;
  overflow-y: auto;
  line-height: 1.5;
}
textarea::placeholder { color: var(--text-dim); }

button#sendBtn {
  width: 36px; height: 36px;
  border-radius: 8px; border: none;
  background: var(--accent); color: white;
  cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
button#sendBtn:hover { background: var(--accent-hover); }
button#sendBtn:active { transform: scale(0.93); }
button#sendBtn:disabled { opacity: 0.4; cursor: not-allowed; }
button#sendBtn svg { width: 16px; height: 16px; }

/* MIC BUTTON */
#micBtn { position: relative; }
#micBtn.recording {
  color: #ef4444;
  background: rgba(239,68,68,0.12);
  animation: micPulse 1.2s ease-in-out infinite;
}
#micBtn.recording svg {
  animation: micScale 1.2s ease-in-out infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.5); }
  50%       { box-shadow: 0 0 0 10px rgba(239,68,68,0); }
}
@keyframes micScale {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.15); }
}

button#stopBtn {
  width: 36px; height: 36px;
  border-radius: 8px; border: none;
  background: #ef4444; color: white;
  cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  animation: stopPulse 1.5s ease-in-out infinite;
}
button#stopBtn:hover { background: #dc2626; }
button#stopBtn:active { transform: scale(0.93); }
@keyframes stopPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50%       { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

.input-hint { font-size: 11px; color: var(--text-dim); text-align: center; margin-top: 6px; }

/* DRAG OVER */
.main.drag-over::after {
  content: '📎 Отпустите для загрузки';
  position: fixed;
  inset: 0;
  background: rgba(16, 163, 127, 0.12);
  border: 2px dashed var(--accent);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--accent);
  z-index: 50;
  pointer-events: none;
}
.main.drag-over { outline: none; }

/* OVERLAY */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* MOBILE */
@media (max-width: 700px) {
  /* ── Layout ── */
  .layout { height: 100dvh; }

  /* ── Sidebar ── */
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    height: 100dvh;
    transform: translateX(-100%);
    width: 82vw;
    max-width: 300px;
    z-index: 300;
    box-shadow: 4px 0 24px rgba(0,0,0,0.55);
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  }
  .sidebar.open { transform: translateX(0); }
  .overlay.show { display: block; }
  .menu-btn { display: flex; width: 44px; height: 44px; }

  /* Кнопка ... всегда видна на тач-устройствах */
  .chat-item-menu { opacity: 1; }
  .chat-item { padding: 11px 10px; min-height: 44px; }

  /* ── Topbar ── */
  .topbar {
    height: 54px;
    padding: 0 12px;
    padding-top: env(safe-area-inset-top, 0px);
  }
  .topbar-title { font-size: 15px; }

  /* ── Chat box ── */
  .chat-box {
    padding: 10px 0 6px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }
  .message-inner { padding: 0 14px; max-width: 100%; }

  /* User bubble */
  .user-message { padding: 10px 0 2px; }
  .user-message .msg-content {
    max-width: 83vw;
    font-size: var(--msg-font, 15px);
    padding: 10px 15px;
    border-radius: 18px;
  }

  /* AI text */
  .ai-message { padding: 10px 0 12px; }
  .ai-message .msg-content { font-size: var(--msg-font, 15px); line-height: 1.65; }

  /* Код горизонтально скроллится */
  .msg-content pre { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ── Input wrapper ── */
  .input-wrapper {
    padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    max-width: 100%;
    background: var(--main-bg);
  }
  .input-box { padding: 6px 8px; border-radius: 18px; gap: 4px; }
  textarea {
    font-size: 16px; /* 16px — iOS не зумит */
    max-height: 120px;
    padding: 5px 2px;
  }
  .input-hint { display: none; }

  /* Крупные тач-цели */
  button#sendBtn { width: 42px; height: 42px; border-radius: 10px; }
  button#sendBtn svg { width: 18px; height: 18px; }
  .tool-btn { width: 42px; height: 42px; }
  .tool-btn svg { width: 20px; height: 20px; }

  /* ── Превью фото ── */
  .image-preview-inner img { max-height: 80px; max-width: 140px; }

  /* ── Welcome ── */
  .welcome { padding: 28px 20px; gap: 14px; }
  .nexus-logo-img { width: 72px; height: 72px; }
  .nexus-title { font-size: 30px; }
  .welcome p { font-size: 14px; }

  /* ── Think block ── */
  .think-block { margin-bottom: 10px; }
  .think-content { font-size: 12px; }

  /* ── Export buttons ── */
  .export-btns { gap: 6px; margin-top: 10px; }
  .export-btn { padding: 7px 12px; font-size: 12px; }

  /* ── Context menu ── */
  .chat-ctx-menu { min-width: 190px; }
  .ctx-item { padding: 12px 12px; font-size: 14px; min-height: 44px; }

  /* ── Toast ── */
  .toast {
    bottom: calc(90px + env(safe-area-inset-bottom, 0px));
    font-size: 14px;
    padding: 10px 20px;
  }

  /* ── Settings — шторка снизу ── */
  .settings-modal {
    flex-direction: column;
    height: 92dvh;
    width: 100vw;
    border-radius: 18px 18px 0 0;
    position: fixed;
    bottom: 0;
  }
  .settings-backdrop { align-items: flex-end; }
  .settings-nav {
    width: 100%;
    flex-direction: row;
    padding: 10px 8px 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: #111;
    flex-shrink: 0;
  }
  .settings-nav::-webkit-scrollbar { display: none; }
  .settings-nav-title { display: none; }
  .settings-nav-item {
    flex-direction: column;
    gap: 3px;
    padding: 8px 12px;
    font-size: 11px;
    white-space: nowrap;
    border-radius: 8px;
    min-height: 44px;
    justify-content: center;
  }
  .settings-nav-item svg { width: 20px; height: 20px; }
  .settings-content { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .settings-close { top: 12px; right: 12px; width: 32px; height: 32px; }
}

/* AUTH MODAL */
.auth-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
}
.auth-backdrop.open { display: flex; }

.auth-modal {
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px 28px;
  width: 360px;
  max-width: 94vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  animation: authIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes authIn {
  from { opacity: 0; transform: scale(0.88) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.auth-logo { width: 60px; height: 60px; margin-bottom: 4px; }
.auth-title {
  font-size: 26px; font-weight: 800; color: var(--text);
  margin: 0;
}
.auth-title span {
  background: linear-gradient(135deg, #7c3aed, #10a37f);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.auth-sub { font-size: 13px; color: var(--text-dim); margin: 0 0 4px; }

.auth-tabs {
  display: flex; gap: 4px;
  background: var(--surface);
  border-radius: 10px;
  padding: 3px;
  width: 100%;
}
.auth-tab {
  flex: 1; padding: 7px;
  border: none; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  background: transparent; color: var(--text-dim);
  transition: all 0.2s;
}
.auth-tab.active { background: var(--surface2); color: var(--text); }

.auth-form { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.auth-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  padding: 11px 14px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
  box-sizing: border-box;
}
.auth-input:focus { border-color: var(--accent); }
.auth-input::placeholder { color: var(--text-dim); }

.auth-error {
  font-size: 12px; color: #ef4444;
  min-height: 16px; text-align: center;
}
.auth-submit {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: white;
  border: none; border-radius: 10px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.auth-submit:hover { background: var(--accent-hover); }
.auth-submit:active { transform: scale(0.98); }
.auth-submit:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-remember {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-dim); cursor: pointer; user-select: none;
}
.auth-remember input[type="checkbox"] {
  width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer;
}

.auth-skip {
  width: 100%; padding: 9px; background: none;
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-dim); font-size: 13px; cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.auth-skip:hover { color: var(--text); border-color: var(--text-dim); }

/* USER AVATAR */
.user-avatar-circle {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #10a37f);
  color: white; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; text-transform: uppercase;
}

/* SECURITY TAB */
.security-account-block { padding: 12px 0 4px; }
.sec-guest-msg, .sec-user-msg {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.sec-guest-msg .settings-btn { margin-left: auto; flex-shrink: 0; }
.change-pass-form {
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px 0 6px;
}
.sr-nav-link-btn {
  background: none; border: none;
  color: var(--text-dim); font-size: 13px;
  cursor: pointer; display: flex; align-items: center; gap: 2px;
  padding: 0; transition: color 0.15s;
}
.sr-nav-link-btn:hover { color: var(--accent); }

/* GUEST BANNER */
.guest-banner {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px;
  background: rgba(16,163,127,0.07);
  border: 1px solid rgba(16,163,127,0.2);
  border-radius: 10px;
  margin-bottom: 6px;
}
.guest-banner span {
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.4;
}
.guest-login-btn {
  width: 100%;
  padding: 7px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.guest-login-btn:hover { background: var(--accent-hover); }

/* ADMIN PANEL BTN */
.admin-panel-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 10px;
  border: 1px solid rgba(124,58,237,0.3); background: rgba(124,58,237,0.08);
  color: #a78bfa; font-size: 13px; font-weight: 600;
  cursor: pointer; border-radius: 8px;
  transition: background 0.15s, border-color 0.15s;
  margin-bottom: 4px;
}
.admin-panel-btn:hover { background: rgba(124,58,237,0.18); border-color: rgba(124,58,237,0.5); }

/* ADMIN MODAL */
.admin-backdrop {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
  align-items: center; justify-content: center; padding: 16px;
}
.admin-backdrop.open { display: flex; }
.admin-modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; width: 100%; max-width: 860px;
  max-height: 90vh; display: flex; flex-direction: column;
  overflow: hidden;
}
.admin-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.adm-badge-inline {
  background: #7c3aed; color: #fff; font-size: 10px;
  padding: 2px 7px; border-radius: 20px; font-weight: 700; letter-spacing: 0.5px;
}
.adm-last-upd { font-size: 11px; color: var(--text-dim); }
.adm-ref-btn {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 7px; padding: 5px 8px; cursor: pointer; transition: color 0.15s;
}
.adm-ref-btn:hover { color: var(--accent); }
.admin-modal-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 6px;
  transition: color 0.15s;
}
.admin-modal-close:hover { color: var(--text); }
.admin-modal-body { overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }

/* Cards */
.adm-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px,1fr)); gap: 10px; }
.adm-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 4px;
}
.adm-card::before { content:''; position:absolute; top:0; left:0; right:0; height:2px; background:var(--cc,var(--accent)); }
.adm-card-lbl { font-size:10px; color:var(--text-dim); text-transform:uppercase; letter-spacing:0.5px; }
.adm-card-val { font-size:26px; font-weight:700; line-height:1; }
.adm-card small { font-size:10px; color:var(--text-dim); }

/* Section */
.adm-section { background: var(--surface2); border:1px solid var(--border); border-radius:10px; overflow:hidden; }
.adm-sec-hdr { display:flex; align-items:center; justify-content:space-between; padding:10px 14px; border-bottom:1px solid var(--border); }
.adm-analyze-btn {
  background: linear-gradient(135deg,var(--accent),#7c3aed); color:#fff;
  border:none; border-radius:7px; padding:6px 14px; font-size:12px;
  font-weight:600; cursor:pointer; transition:opacity 0.2s;
}
.adm-analyze-btn:hover { opacity:0.85; }
.adm-analyze-btn:disabled { opacity:0.4; cursor:not-allowed; }
.adm-analysis { display:none; padding:14px; font-size:13px; line-height:1.7; border-top:1px solid var(--border); }
.adm-analysis h2 { font-size:13px; font-weight:700; color:var(--accent); margin:12px 0 6px; }
.adm-analysis h2:first-child { margin-top:0; }
.adm-analysis p, .adm-analysis li { color:var(--text-dim); margin-bottom:4px; }
.adm-cursor { display:inline-block; width:2px; height:1em; background:var(--accent); animation:blink 0.7s step-end infinite; vertical-align:text-bottom; }
@keyframes blink { 50%{ opacity:0; } }
.adm-search {
  background:var(--surface); border:1px solid var(--border); color:var(--text);
  border-radius:7px; padding:5px 10px; font-size:12px; outline:none; width:160px;
}
.adm-search:focus { border-color:var(--accent); }
.adm-table { width:100%; border-collapse:collapse; }
.adm-table th { text-align:left; padding:8px 12px; font-size:10px; color:var(--text-dim); text-transform:uppercase; letter-spacing:0.4px; border-bottom:1px solid var(--border); }
.adm-table td { padding:8px 12px; border-bottom:1px solid #1e1e1e; }
.adm-table tr:last-child td { border-bottom:none; }
.adm-table tr:hover td { background:rgba(255,255,255,0.02); }
.adm-online-badge { display:inline-flex; align-items:center; gap:4px; background:rgba(34,197,94,0.12); color:#22c55e; border-radius:20px; padding:2px 7px; font-size:11px; font-weight:600; }
.adm-online-dot { width:5px; height:5px; border-radius:50%; background:#22c55e; animation:onlinePulse 2s infinite; }
@keyframes onlinePulse { 0%,100%{opacity:1} 50%{opacity:0.3} }

/* LOGOUT BTN */
.logout-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 10px;
  border: none; background: none;
  color: var(--text-dim); font-size: 13px;
  cursor: pointer; border-radius: 8px;
  transition: background 0.15s, color 0.15s;
  margin-top: 2px;
}
.logout-btn:hover { background: rgba(239,68,68,0.1); color: #ef4444; }

/* SETTINGS ICON */
.user-info {
  cursor: pointer;
  transition: background 0.15s;
  border-radius: 8px;
  padding: 8px;
}
.user-info:hover { background: var(--surface); }
.settings-icon {
  width: 16px; height: 16px;
  margin-left: auto;
  color: var(--text-dim);
  flex-shrink: 0;
}

/* SETTINGS MODAL */
.settings-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.settings-backdrop.open { display: flex; }

.settings-modal {
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 680px;
  max-width: 96vw;
  height: 500px;
  max-height: 90vh;
  display: flex;
  position: relative;
  overflow: hidden;
  animation: modalIn 0.2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

.settings-close {
  position: absolute; top: 14px; right: 14px;
  width: 28px; height: 28px;
  border-radius: 50%; border: none;
  background: var(--surface); color: var(--text-dim);
  cursor: pointer; font-size: 13px; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.settings-close:hover { background: var(--surface2); color: var(--text); }

/* SETTINGS NAV */
.settings-nav {
  width: 200px;
  min-width: 200px;
  background: #111;
  border-right: 1px solid var(--border);
  padding: 20px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-nav-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  padding: 0 8px 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.settings-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  border: none; background: none;
  color: var(--text-dim);
  font-size: 14px; cursor: pointer;
  text-align: left; width: 100%;
  transition: background 0.15s, color 0.15s;
}
.settings-nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.settings-nav-item:hover { background: var(--surface); color: var(--text); }
.settings-nav-item.active { background: var(--surface); color: var(--text); }

/* SETTINGS CONTENT */
.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
}
.settings-content::-webkit-scrollbar { width: 4px; }
.settings-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.settings-tab { display: none; }
.settings-tab.active { display: block; }

.settings-section-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
}

.sr-label {
  display: block;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 3px;
}

.sr-hint {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
  max-width: 340px;
  line-height: 1.5;
}

.sr-section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  padding: 16px 0 4px;
}

.settings-nav-row { cursor: default; }
.sr-nav-link {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
}
.sr-arrow {
  font-size: 16px;
  color: var(--text-dim);
}

.settings-row-label span {
  display: block;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 3px;
}
.settings-row-label small {
  font-size: 12px;
  color: var(--text-dim);
}

.settings-divider {
  border: none;
  border-top: 1px solid var(--border);
}

.settings-select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  padding: 7px 10px;
  cursor: pointer;
  outline: none;
  min-width: 140px;
}
.settings-select:focus { border-color: var(--accent); }

.settings-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  font-family: 'Consolas', monospace;
  width: 100%;
}
.settings-input:focus { border-color: var(--accent); }

.api-key-row {
  display: flex; gap: 8px; width: 100%;
}

.settings-hint {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
}

.settings-btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.settings-btn:hover { background: var(--accent-hover); }

.settings-btn-danger {
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid #ef4444;
  background: transparent;
  color: #ef4444;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.settings-btn-danger:hover { background: rgba(239,68,68,0.1); }

/* COLOR PICKER */
.color-picker-row {
  display: flex; gap: 8px;
}
.color-dot {
  width: 26px; height: 26px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
}
.color-dot:hover { transform: scale(1.15); }
.color-dot.active { border-color: white; }

/* TOGGLE */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--surface2);
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ABOUT */
.about-block {
  display: flex; flex-direction: column;
  align-items: center; text-align: center;
  padding: 20px 0; gap: 8px;
}
.about-name {
  font-size: 22px; font-weight: 800;
}
.about-name span {
  background: linear-gradient(135deg, #00d4ff, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.about-version { font-size: 13px; color: var(--text-dim); }
.about-desc { font-size: 13px; color: var(--text-dim); max-width: 300px; margin-top: 8px; line-height: 1.6; }

@media (max-width: 600px) {
  .settings-nav { width: 160px; min-width: 160px; }
  .settings-nav-item span { display: none; }
  .settings-content { padding: 16px; }
}
