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

:root {
  --bg: #0f1115;
  --bg-card: #161920;
  --bg-input: #1a1e27;
  --bg-hover: #1e2330;
  --bg-pre: #0d1117;
  --border: #2a2f3c;
  --text: #e5e7eb;
  --text-dim: #9ca3af;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --user-bubble: #2d333b;
  --user-bubble-text: #e5e7eb;
  --send-btn-bg: #2d333b;
  --send-btn-bg-hover: #3d444d;
  --send-btn-text: #e5e7eb;
  --radius: 12px;
  --font-size: 16px;
  --sidebar-font-size: calc(var(--font-size) * 0.875);
  --sidebar-font-size-sm: calc(var(--font-size) * 0.6875);
  --chat-max-width: 760px;

  /* Фоновые цвета для карточек вложений (адаптивны к теме) */
  --file-att-bg: rgba(0, 0, 0, 0.18);
  --file-att-header-bg: rgba(0, 0, 0, 0.12);

  /* Цвет футера сайдбара — чуть отличается от фона списка чатов */
  --sidebar-footer-bg: #0b0d11;
}

/* Light theme */
[data-theme="light"] {
  --bg: #f5f7fa;
  --bg-card: #ffffff;
  --bg-input: #f0f2f5;
  --bg-hover: #e8ebf0;
  --bg-pre: #f1f3f5;
  --border: #d1d5db;
  --text: #1f2937;
  --text-dim: #6b7280;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --success: #16a34a;
  --user-bubble: #d1d5db;
  --user-bubble-text: #1f2937;
  --send-btn-bg: #4b5563;
  --send-btn-bg-hover: #374151;
  --send-btn-text: #ffffff;

  /* В светлой теме — чуть светлее, чтобы не «грязнить» bubble */
  --file-att-bg: rgba(0, 0, 0, 0.06);
  --file-att-header-bg: rgba(0, 0, 0, 0.04);

  /* В светлой теме футер чуть темнее белого */
  --sidebar-footer-bg: #eef1f5;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: var(--font-size);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.screen { width: 100%; height: 100%; }
.hidden { display: none !important; }

/* ==================== LOADING SCREEN ==================== */
#loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 9999;
  position: fixed;
  inset: 0;
}
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.loading-spinner svg {
  animation: pulse 2s infinite ease-in-out;
  filter: drop-shadow(0 0 8px rgba(0, 229, 255, 0.3));
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(0.95); }
}
.loading-dots {
  display: flex;
  gap: 6px;
}
.loading-dots span {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}
.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ==================== LOGIN ==================== */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  width: 320px;
  text-align: center;
}
.login-logo {
  margin-bottom: 14px;
  display: flex;
  justify-content: center;
}
.login-logo svg {
  filter: drop-shadow(0 0 6px rgba(0, 229, 255, 0.25));
}
.login-box h1 { font-size: 24px; margin-bottom: 20px; }
.login-tabs {
  display: flex; gap: 4px; margin-bottom: 20px;
  background: var(--bg); border-radius: 8px; padding: 3px;
}
.login-tabs .tab {
  flex: 1; padding: 8px; border: none; border-radius: 6px;
  background: transparent; color: var(--text-dim);
  cursor: pointer; font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.login-tabs .tab:hover {
  color: var(--text);
  background: var(--send-btn-bg-hover);
}
.login-tabs .tab.active {
  background: var(--send-btn-bg);
  color: var(--send-btn-text);
}
.login-box input {
  width: 100%; padding: 12px 14px; margin-bottom: 10px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}
.login-box input:focus { border-color: var(--accent); }
.login-box button[type=submit] {
  width: 100%; padding: 12px; border: none; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 15px;
  cursor: pointer; margin-top: 4px;
  transition: background 0.15s, transform 0.1s;
}
.login-box button[type=submit]:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}
.login-box button[type=submit]:active {
  transform: translateY(0);
}
.auth-error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ==================== APP LAYOUT (flexbox) ==================== */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  position: relative;
}

/* Fallback для браузеров без dvh (Chrome < 108) */
@supports not (height: 100dvh) {
  #app { height: 100vh; }
}

/* ==================== HEADER ==================== */
#header {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 6px;
  height: 52px; padding: 0 10px;
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  z-index: 100;
}
.header-title {
  flex: 1; font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer;
  transition: opacity 0.15s;
}
.header-title:hover {
  opacity: 0.7;
}

/* ==================== CUSTOM MODEL SELECTOR ==================== */
.model-select-wrap {
  position: relative;
  flex-shrink: 0;
}
.model-select-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  max-width: 150px;
  transition: border-color 0.15s, background 0.15s;
}
/* Кружок-индикатор перед названием модели */
.model-select-btn::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}
.model-select-btn.dot-busy::before {
  background: #f59e0b;
}
.model-select-btn.dot-offline::before {
  background: var(--text-dim);
}
.model-select-btn:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}
.model-select-label {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 110px;
}
.model-select-caret {
  flex-shrink: 0;
  color: var(--text-dim);
  transition: transform 0.2s;
}
.model-select-wrap.open .model-select-caret {
  transform: rotate(180deg);
}

.model-select-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success); /* зелёный по умолчанию */
  flex-shrink: 0;
}
.model-select-dot.busy {
  background: #f59e0b; /* жёлтый */
}
.model-select-dot.offline {
  background: var(--text-dim); /* серый */
}


.model-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.4);
  padding: 6px;
  z-index: 300;
  animation: menuIn 0.15s ease;
}
@keyframes menuIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.model-menu-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.model-menu-item:hover {
  background: var(--bg-hover);
}
.model-menu-item.active {
  background: var(--accent);
  color: #fff;
}
.model-menu-item.offline {
  color: var(--text-dim);
  opacity: 0.55;
  cursor: not-allowed;
}
.model-menu-item .model-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}
.model-menu-item.offline .model-dot {
  background: var(--text-dim);
}
.model-menu-item .model-check {
  margin-left: auto;
  color: var(--text-dim);
}
.model-menu-item.active .model-check {
  color: #fff;
}

.icon-btn {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 6px;
  border-radius: 6px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.new-chat-header-btn {
  color: var(--accent);
}
.new-chat-header-btn:hover {
  background: var(--bg-hover);
  color: var(--accent);
}




/* ==================== SIDEBAR (overlay) ==================== */
#sidebar {
  position: fixed; top: 52px; left: 0;
  bottom: 0;
  z-index: 110;
  width: 280px; background: var(--bg-card);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  display: flex; flex-direction: column;
}
#sidebar.open { transform: translateX(0); }
#sidebar-overlay {
  position: fixed; inset: 0; z-index: 105;
  background: rgba(0,0,0,0.5);
  display: none;
}
#sidebar-overlay.show { display: block; }
.new-chat-btn {
  margin: 12px; padding: 10px; border: 1px dashed var(--border);
  border-radius: 8px; background: none; color: var(--text);
  font-size: var(--sidebar-font-size); cursor: pointer;
  display: flex; align-items: center; gap: 6px; justify-content: center;
  flex-shrink: 0;
}
.new-chat-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ==================== CHAT SEARCH (поиск по чатам) ==================== */
.chat-search-wrap {
  position: relative;
  margin: 0 12px 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.chat-search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-dim);
  pointer-events: none;
}
.chat-search-wrap input {
  width: 100%;
  padding: 8px 30px 8px 32px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
.chat-search-wrap input:focus { border-color: var(--accent); }
.chat-search-wrap input::placeholder { color: var(--text-dim); }
.chat-search-clear {
  position: absolute;
  right: 6px;
  width: 20px; height: 20px;
  border: none;
  border-radius: 50%;
  background: var(--bg-hover);
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.chat-search-clear:hover { color: var(--text); }

.chat-list-empty {
  padding: 16px 12px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* ==================== PULL-TO-REFRESH INDICATOR ==================== */
.ptr-indicator {
  position: relative;
  height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease;
  flex-shrink: 0;
}
.ptr-indicator.visible {
  opacity: 1;
}
.ptr-indicator.refreshing {
  height: 48px !important;
  opacity: 1;
}
.ptr-spinner {
  color: var(--accent);
  will-change: transform;
}
.ptr-indicator.refreshing .ptr-spinner {
  animation: ptrSpin 0.8s linear infinite;
}

@keyframes ptrSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Список чатов — «воздух» сверху и снизу, чтобы не прилипал к футеру */
#chat-list {
  flex: 1; overflow-y: auto;
  padding: 4px 8px 16px;              /* 4px сверху, 16px снизу */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  will-change: transform;
}
#chat-list.ptr-dragging {
  transition: none !important;
}

.chat-item {
  display: flex; flex-direction: column;
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  color: var(--text-dim);
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-hover); color: var(--text); }
.chat-item .chat-top {
  display: flex; align-items: center; gap: 6px;
}
.chat-item .chat-name {
  flex: 1; font-size: var(--sidebar-font-size);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item .chat-date {
  font-size: var(--sidebar-font-size-sm); color: var(--text-dim); margin-top: 2px;
}
.chat-item .chat-del {
  opacity: 0; font-size: 14px; color: var(--text-dim);
  flex-shrink: 0; cursor: pointer;
}
.chat-item:hover .chat-del { opacity: 1; }
.chat-item .chat-del:hover { color: var(--danger); }

/* ==================== CHAT LOADING OVERLAY ==================== */
#chat-loading-overlay {
  position: fixed;
  top: 52px;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}
#chat-loading-overlay.visible {
  opacity: 1;
}
.chat-loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 36px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}


/* ==================== SIDEBAR FOOTER — иерархия ==================== */
.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--sidebar-footer-bg);   /* цвет отличается от фона списка */
}

.sidebar-export,
.sidebar-settings {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 10px 12px;
  border: none; border-radius: 8px;
  background: none; color: var(--text-dim);
  font-size: var(--sidebar-font-size); cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.sidebar-export:hover {
  background: var(--bg-hover);
  color: var(--accent);
}
.sidebar-settings:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.sidebar-export svg,
.sidebar-settings svg { flex-shrink: 0; }

/* ==================== SCROLL-TO-BOTTOM BUTTON ==================== */
.scroll-bottom-btn {
  position: absolute;
  bottom: 80px;
  right: 16px;
  z-index: 150;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  transition: opacity 0.2s, transform 0.2s, color 0.15s, border-color 0.15s;
  animation: fadeIn 0.2s ease;
}
.scroll-bottom-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  transform: translateY(-2px);
}
.scroll-bottom-btn.hidden {
  display: none !important;
}

/* ==================== MESSAGES ==================== */
#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}

.messages-inner {
  max-width: var(--chat-max-width);
  margin: 0 auto;
  padding: 20px 16px 20px;
}

.msg {
  margin-bottom: 20px;
  animation: fadeIn 0.1s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.msg.user {
  display: flex; flex-direction: column; align-items: flex-end;
}
.msg.assistant {
  display: flex; flex-direction: column; align-items: flex-start;
}
.msg.tool {
  display: flex; justify-content: center;
}

/* User message */
.msg.user .msg-content {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  padding: 10px 14px;
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  max-width: 85%;
  font-size: var(--font-size); line-height: 1.5;
  word-wrap: break-word; white-space: pre-wrap;
}
.msg.user .msg-content img {
  max-width: 100%; max-height: 300px;
  border-radius: 8px; margin-top: 6px; display: block;
}

/* Assistant message */
.msg.assistant .msg-content {
  max-width: 100%;
  font-size: var(--font-size); line-height: 1.7;
  color: var(--text);
  word-wrap: break-word;
}

/* ==================== ERROR MESSAGE (role='error') ==================== */
.msg.error {
  display: flex; flex-direction: column; align-items: flex-start;
}
.msg.error .msg-content.error-content {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 100%;
  margin: 4px 0;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-left: 3px solid var(--danger);
  border-radius: 8px;
}
.msg.error .error-icon {
  flex-shrink: 0;
  font-size: 14px;
  line-height: 1.4;
}
.msg.error .error-text {
  margin: 0;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--danger);
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 100%;
}

/* ==================== INLINE TOOL CALL ==================== */
.tool-call-inline {
  margin: 10px 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.tool-call-inline.pending {
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.15);
}

.tool-call-inline .tool-call-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.tool-call-inline .tool-call-header:hover {
  background: var(--bg-hover);
}

.tool-call-icon {
  font-size: 14px;
  flex-shrink: 0;
}

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

.tool-call-status {
  font-size: 12px;
  color: var(--success);
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.tool-call-status.running {
  color: var(--accent);
}

.tool-spinner {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}
.tool-spinner span {
  width: 5px;
  height: 5px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}
.tool-spinner span:nth-child(1) { animation-delay: 0s; }
.tool-spinner span:nth-child(2) { animation-delay: 0.2s; }
.tool-spinner span:nth-child(3) { animation-delay: 0.4s; }

.tool-call-toggle {
  font-size: 10px;
  color: var(--text-dim);
  transition: transform 0.2s;
  flex-shrink: 0;
}
.tool-call-toggle.expanded {
  transform: rotate(180deg);
}

.tool-call-body {
  display: none;
  padding: 0 12px 10px;
  border-top: 1px solid var(--border);
}
.tool-call-body.expanded {
  display: block;
}

.tool-call-section {
  margin-top: 10px;
}

.tool-call-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.tool-call-pre {
  background: var(--bg-pre);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 300px;
  overflow-y: auto;
}

.tool-call-result {
  color: var(--text-dim);
}

.tool-call-running {
  padding: 4px 0;
}
.tool-running-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}
.tool-running-dots span {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}
.tool-running-dots span:nth-child(1) { animation-delay: 0s; }
.tool-running-dots span:nth-child(2) { animation-delay: 0.2s; }
.tool-running-dots span:nth-child(3) { animation-delay: 0.4s; }

/* Inline thinking */
.inline-thinking {
  padding: 6px 0;
}
.inline-thinking .thinking {
  padding: 0;
}
.thinking-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-left: 4px;
}

/* text-stream */
.msg.assistant .msg-content .text-stream {
}

/* ==================== WELCOME SCREEN ==================== */
.welcome-screen {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: calc(100dvh - 220px);
  text-align: center;
  gap: 12px;
}
@supports not (height: 100dvh) {
  .welcome-screen { min-height: calc(100vh - 220px); }
}
.welcome-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}
.welcome-icon svg {
  width: calc(var(--font-size) * 3.5);
  height: calc(var(--font-size) * 4);
  display: block;
}
.welcome-screen h2 {
  font-size: calc(var(--font-size) * 1.5);
  font-weight: 600;
}
.welcome-screen p {
  color: var(--text-dim);
  font-size: calc(var(--font-size) * 0.94);
}
.welcome-new-chat {
  margin-top: 8px;
  padding: 10px 20px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font-size: calc(var(--font-size) * 0.94);
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
.welcome-new-chat:hover { background: var(--accent); color: #fff; }

/* ==================== THINKING INDICATOR ==================== */
.thinking {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-dim); font-size: 14px;
  padding: 4px 0;
}
.thinking-dots {
  display: flex; gap: 4px;
}
.thinking-dots span {
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}
.thinking-dots span:nth-child(1) { animation-delay: 0s; }
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ==================== MARKDOWN (assistant) ==================== */
.msg.assistant .msg-content h1,
.msg.assistant .msg-content h2,
.msg.assistant .msg-content h3,
.msg.assistant .msg-content h4 {
  margin: 16px 0 8px;
  font-weight: 600;
}
.msg.assistant .msg-content h1 { font-size: 1.4em; }
.msg.assistant .msg-content h2 { font-size: 1.25em; }
.msg.assistant .msg-content h3 { font-size: 1.1em; }

.msg.assistant .msg-content p {
  margin: 8px 0;
}

.msg.assistant .msg-content ul,
.msg.assistant .msg-content ol {
  margin: 8px 0; padding-left: 24px;
}
.msg.assistant .msg-content li { margin: 4px 0; }

.msg.assistant .msg-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 12px; margin: 8px 0;
  color: var(--text-dim);
  background: var(--bg-hover);
  border-radius: 0 6px 6px 0;
}

.msg.assistant .msg-content code {
  background: var(--bg-pre);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.9em;
}

.msg.assistant .msg-content pre {
  background: var(--bg-pre);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin: 12px 0;
  overflow-x: auto;
}
.msg.assistant .msg-content pre code {
  background: none; padding: 0;
  font-size: 13px; line-height: 1.2;
}

.msg.assistant .msg-content table {
  border-collapse: collapse;
  margin: 12px 0;
  width: 100%;
}
.msg.assistant .msg-content th,
.msg.assistant .msg-content td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.msg.assistant .msg-content th {
  background: var(--bg-hover);
  font-weight: 600;
}

.msg.assistant .msg-content a {
  color: var(--accent);
  text-decoration: none;
}
.msg.assistant .msg-content a:hover { text-decoration: underline; }

.msg.assistant .msg-content img {
  max-width: 100%;
  border-radius: 8px;
  margin: 8px 0;
}

/* ==================== INPUT ==================== */
#input-area {
  flex-shrink: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  overscroll-behavior: contain;
  position: relative;
  z-index: 100;
}

.input-inner {
  max-width: var(--chat-max-width);
  margin: 0 auto;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

#img-previews {
  display: flex; gap: 6px; margin-bottom: 6px;
  flex-wrap: wrap;
}
#img-previews:empty { display: none; }
.img-preview {
  position: relative; width: 56px; height: 56px;
  border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border);
}
.img-preview img { width: 100%; height: 100%; object-fit: cover; }
.img-preview .remove {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0,0,0,0.7); color: #fff;
  border: none; font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* Input row */
.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-btn {
  width: 40px; height: 40px;
  min-width: 40px; min-height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-dim);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.input-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Attach button disabled state */
.attach-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed !important;
  border-color: var(--border) !important;
  color: var(--text-dim) !important;
}
.attach-btn:disabled:hover {
  background: none;
  border-color: var(--border);
  color: var(--text-dim);
}

.input-row textarea {
  flex: 1;
  resize: none;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-size: var(--font-size);
  line-height: 1.4;
  height: 40px;
  max-height: 120px;
  outline: none;
  font-family: inherit;
  min-width: 0;
  overflow: hidden;
}

.input-row textarea:focus { border-color: var(--accent); }

.send-btn {
  width: 40px; height: 40px;
  min-width: 40px; min-height: 40px;
  border-radius: 50%;
  background: var(--send-btn-bg);
  border: none;
  color: var(--send-btn-text);
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed !important;
  background: var(--bg-input) !important;
  color: var(--text-dim) !important;
}
.send-btn:disabled:hover {
  background: var(--bg-input) !important;
  transform: none;
}
.send-btn:hover:not(:disabled) { background: var(--send-btn-bg-hover); }
.send-btn.stop-mode { background: var(--danger); color: #fff; }
.send-btn.stop-mode:hover { background: #dc2626; }

/* ==================== MESSAGE ACTIONS ==================== */
.msg-actions {
  display: flex; gap: 2px; margin-top: 4px;
  opacity: 0; transition: opacity 0.15s;
}
.msg:hover .msg-actions { opacity: 1; }
@media (hover: none) {
  .msg-actions { opacity: 1; }
}
.msg-action-btn {
  background: none; border: none;
  color: var(--text-dim); font-size: 13px;
  cursor: pointer; padding: 3px 7px;
  border-radius: 4px;
  display: flex; align-items: center; gap: 3px;
}
.msg-action-btn:hover { background: var(--bg-hover); color: var(--text); }
.msg-action-btn svg { width: 14px; height: 14px; }
.msg-action-delete:hover { color: var(--danger); }

/* ==================== EDIT MODE ==================== */
/* В режиме правки контейнер сообщения расширяется на всю колонку —
   так textarea удобнее, чем в тесном пузыре 85% */
.msg.user.editing .msg-content {
  width: 100%;
  max-width: 100%;
  align-self: stretch;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  white-space: normal;
}

/* Чипы вложений внутри редактора (те же стили, что у превью во вводе) */
.edit-attachments {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.edit-attachments:empty { display: none; }

.edit-area {
  width: 100%;
  max-width: none;
  background: var(--bg-input); border: 1px solid var(--accent);
  border-radius: 10px; padding: 10px 14px;
  color: var(--text); font-size: var(--font-size); line-height: 1.4;
  font-family: inherit; resize: vertical; min-height: 60px;
  outline: none;
}
.edit-actions {
  display: flex; gap: 8px; margin-top: 0;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
}
.edit-actions button {
  padding: 6px 14px; border-radius: 6px;
  border: none; font-size: 13px; cursor: pointer;
}
.edit-actions .edit-add-file {
  margin-right: auto;   /* «＋ Вложение» — слева, действия — справа */
  background: var(--bg);
  border: 1px dashed var(--border);
  color: var(--text-dim);
}
.edit-actions .edit-add-file:hover { border-color: var(--accent); color: var(--accent); }
.edit-actions .edit-save { background: var(--accent); color: #fff; }
.edit-actions .edit-cancel { background: var(--bg-hover); color: var(--text); }
.edit-actions .edit-save:disabled { opacity: 0.5; cursor: wait; }

/* ==================== TOAST — уведомления и диалоги ==================== */
#toast-container {
  position: fixed;
  top: 60px;
  right: 16px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: min(360px, calc(100vw - 32px));
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  opacity: 0;
  transform: translateX(16px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast.hide { opacity: 0; transform: translateX(16px); }

.toast-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  margin-top: 1px;
}
.toast-msg {
  flex: 1;
  white-space: pre-wrap;
  word-break: break-word;
}
.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
}
.toast-close:hover { color: var(--text); background: var(--bg-hover); }

.toast-info .toast-icon { color: var(--accent); }
.toast-success .toast-icon { color: var(--success); }
.toast-warning .toast-icon { color: #f59e0b; }
.toast-error .toast-icon { color: var(--danger); }
.toast-error { border-color: rgba(239, 68, 68, 0.4); }
.toast-success { border-color: rgba(34, 197, 94, 0.3); }

/* Dialog confirm */
.toast-confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 600;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  transition: opacity 0.18s ease;
}
.toast-confirm-overlay.show { opacity: 1; }

.toast-confirm {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  width: 320px;
  max-width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  transform: translateY(8px) scale(0.98);
  transition: transform 0.18s ease;
}
.toast-confirm-overlay.show .toast-confirm { transform: translateY(0) scale(1); }

.toast-confirm-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}
.toast-confirm-msg {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 18px;
}
.toast-confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.toast-confirm-btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.toast-confirm-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.toast-confirm-btn.ok {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.toast-confirm-btn.ok:hover {
  background: var(--accent-hover);
  color: #fff;
}
.toast-confirm-btn.ok.danger {
  background: var(--danger);
  border-color: var(--danger);
}
.toast-confirm-btn.ok.danger:hover {
  background: #dc2626;
  border-color: #dc2626;
}

/* ==================== SETTINGS MODAL — фикс скругления ==================== */
.settings-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.settings-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 360px;
  max-width: 100%;
  max-height: 85vh;
  overflow: hidden;                    /* было auto — из-за него скроллбар «пробивал» скругление справа */
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
}
.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
  flex-shrink: 0;                      /* шапка не сжимается при скролле */
}
.settings-header h3 { font-size: 17px; font-weight: 600; }
.settings-body {
  padding: 20px;
  display: flex; flex-direction: column; gap: 20px;
  overflow-y: auto;                    /* скролл перенесён сюда */
  flex: 1;
  min-height: 0;                       /* критично для flex + overflow */
}
.settings-row {
  display: flex; align-items: center; justify-content: space-between; padding-bottom: 6px;
}
.settings-row label { font-size: 15px; color: var(--text); }
.font-size-control {
  display: flex; align-items: center; gap: 10px;
}
.font-size-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.font-size-btn:hover { border-color: var(--accent); color: var(--accent); }
#font-size-value {
  font-size: 14px; color: var(--text-dim);
  min-width: 40px; text-align: center;
}
#font-size-slider {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}
.theme-toggle {
  display: flex; gap: 4px;
  background: var(--bg); border-radius: 8px; padding: 3px;
}
.theme-btn {
  padding: 6px 12px; border: none; border-radius: 6px;
  background: transparent; color: var(--text-dim);
  cursor: pointer; font-size: 13px;
}
.theme-btn.active { background: var(--accent); color: #fff; }

/* ==================== CUSTOM COLORS ==================== */
.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.color-row:last-child { margin-bottom: 0; }
.color-row label {
  font-size: 14px;
  color: var(--text);
  flex: 1;
}
.color-row input[type="color"] {
  width: 48px; height: 32px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  flex-shrink: 0;
}
.color-row input[type="color"]:hover {
  border-color: var(--accent);
}

.hex-input {
  width: 80px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  outline: none;
  flex-shrink: 0;
  transition: border-color 0.15s;
}
.hex-input:focus {
  border-color: var(--accent);
}
.hex-input::placeholder {
  color: var(--text-dim);
  opacity: 0.6;
}

.settings-section-note {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.settings-section-note span {
  color: var(--accent);
  font-weight: 500;
}

/* ==================== MCP SERVERS SECTION ==================== */
.settings-section {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.settings-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.settings-section-header h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.mcp-add-btn {
  width: 28px; height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--accent);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.mcp-add-btn:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.mcp-subsection {
  margin-bottom: 12px;
}

.mcp-subsection-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

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

.mcp-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  gap: 8px;
}

.mcp-item.disabled {
  opacity: 0.6;
}

.mcp-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.mcp-item-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mcp-item-meta {
  font-size: 11px;
  color: var(--text-dim);
}

.mcp-item-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  flex-shrink: 0;
}

.mcp-item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.mcp-item-btn {
  width: 26px; height: 26px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.mcp-item-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.mcp-item-delete:hover {
  color: var(--danger);
}

.mcp-empty {
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px 10px;
  text-align: center;
}

/* Toggle switch */
.mcp-toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
  cursor: pointer;
}
.mcp-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}
.mcp-toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 20px;
  transition: background 0.2s;
}
.mcp-toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.mcp-toggle input:checked + .mcp-toggle-slider {
  background: var(--accent);
}
.mcp-toggle input:checked + .mcp-toggle-slider::before {
  transform: translateX(16px);
}

/* MCP Form */
.mcp-form {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mcp-form.hidden {
  display: none;
}

.mcp-form-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.mcp-form input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.mcp-form input[type="text"]:focus {
  border-color: var(--accent);
}

.mcp-form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

.mcp-form-cancel {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
}
.mcp-form-cancel:hover {
  background: var(--bg-hover);
}

.mcp-form-save {
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}
.mcp-form-save:hover {
  background: var(--accent-hover);
}

/* ==================== SCROLLBAR (desktop) ==================== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

* {
  scrollbar-width: thin;                       /* Firefox */
  scrollbar-color: var(--border) transparent;  /* цвет thumb и track */
}

/* ==================== MOBILE — скрыть скроллбары, оставить скролл ==================== */
@media (max-width: 800px) {
  /* Скрываем сами полосы прокрутки (вертикальные И горизонтальные),
     но scroll по-прежнему работает пальцами / колесом */
  * {
    scrollbar-width: none;       /* Firefox — полностью скрыть */
    -ms-overflow-style: none;    /* IE / old Edge */
  }
  *::-webkit-scrollbar {         /* Chrome, Safari, Edge — полностью скрыть */
    display: none;
    width: 0;
    height: 0;
  }

  .messages-inner {
    max-width: 100%;
    padding: 16px 16px 16px;
  }
  .input-inner {
    max-width: 100%;
    padding: 8px 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}


@media (max-width: 600px) {
  .msg.user .msg-content { max-width: 92%; }
  .model-select-btn { max-width: 110px; font-size: 12px; }
  .model-select-label { max-width: 70px; }
  .model-menu { min-width: 150px; }
  #header { gap: 4px; padding: 0 8px; }
  .input-row { gap: 6px; }
  .input-btn { width: 38px; height: 38px; min-width: 38px; min-height: 38px; }
  .send-btn { width: 38px; height: 38px; min-width: 38px; min-height: 38px; }
  .input-row textarea { height: 38px; padding: 8px 12px; }
  .tool-call-pre { max-height: 200px; font-size: 11px; }
  .settings-modal { width: 100%; max-height: 90vh; }
  .hex-input { width: 70px; font-size: 11px; }
  .color-row input[type="color"] { width: 42px; height: 30px; }
  .scroll-bottom-btn { bottom: 72px; right: 10px; width: 32px; height: 32px; }
  #toast-container { top: 56px; right: 10px; left: 10px; max-width: none; }
}

/* ==================== COPY CODE BUTTON ==================== */
.msg.assistant .msg-content pre {
  position: relative;
}
.copy-code-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s, background 0.15s;
  z-index: 2;
}
/* Нижняя кнопка (для длинных блоков) */
.copy-code-btn.copy-code-bottom {
  top: auto;
  bottom: 6px;
}
/* Inline-кнопка (без текста, только иконка) */
.copy-code-btn.copy-code-inline {
  position: static;
  display: inline-flex;
  padding: 1px 4px;
  margin-left: 4px;
  border: none;
  background: none;
  border-radius: 4px;
  opacity: 0;
}
.copy-code-btn.copy-code-inline:hover {
  background: var(--bg-hover);
  opacity: 1;
}
.msg.assistant .msg-content pre:hover .copy-code-btn:not(.copy-code-inline) {
  opacity: 1;
}
@media (hover: none) {
  .copy-code-btn:not(.copy-code-inline) { opacity: 1; }
  .copy-code-btn.copy-code-inline { opacity: 0.6; }
  .copy-code-btn.copy-code-inline:active { opacity: 1; }
}
.copy-code-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--bg-hover);
}
.copy-code-btn.copied {
  color: var(--success);
  border-color: var(--success);
  opacity: 1;
}
.copy-code-btn svg {
  width: 12px;
  height: 12px;
}


/* ==================== MIC BUTTON (smooth rings) ==================== */

.mic-btn-wrap {
  position: relative;
  width: 40px;
  height: 40px;
  min-width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Кнопка микрофона */
.mic-btn {
  position: relative;
  z-index: 1;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--bg-input);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  /*transition: border-color 0.2s, color 0.2s, background 0.2s; */
  transition: border-color 0.2s, color 0.2s, background 0.2s, transform 0.15s ease;
}

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

/* Удержание пальцем — сильное увеличение (walkie-talkie) */
.mic-btn-wrap.pressing { z-index: 5; }
.mic-btn-wrap.pressing .mic-btn {
  transform: scale(1.5);
}

/* Запись */
.mic-btn-wrap.recording .mic-btn {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

/* Распознавание */
.mic-btn-wrap.transcribing .mic-btn {
  color: var(--accent);
  border-color: var(--accent);
  pointer-events: none;
}

/* Спиннер */
.mic-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ==================== MIC RINGS (smooth pulse around button) ==================== */
.mic-rings-container {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 2;
}

.mic-ring-pulse {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  transform: translate(-50%, -50%) scale(1);
  opacity: 0;
  width: 48px;
  height: 48px;
}

.mic-ring-pulse:nth-child(2) {
  border-width: 1.5px;
  width: 56px;
  height: 56px;
}

.mic-ring-pulse:nth-child(3) {
  border-width: 1px;
  width: 64px;
  height: 64px;
}

/* Mobile mic */
@media (max-width: 600px) {
  .mic-btn-wrap { width: 38px; height: 38px; min-width: 38px; }
  .mic-btn-wrap .mic-btn { width: 38px; height: 38px; min-width: 38px; min-height: 38px; }
  .mic-ring-pulse {
    width: 46px;
    height: 46px;
  }
  .mic-ring-pulse:nth-child(2) {
    width: 54px;
    height: 54px;
  }
  .mic-ring-pulse:nth-child(3) {
    width: 62px;
    height: 62px;
  }
}

.katex { font-size: 1.05em; }
.katex-display { margin: 12px 0; overflow-x: auto; overflow-y: hidden; padding: 8px 0; }
.msg.assistant .msg-content .katex,
.msg.assistant .msg-content .katex-display { color: var(--text); }

.model-menu-item .model-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success); /* зелёный */
  flex-shrink: 0;
}
.model-menu-item .model-dot.busy {
  background: #f59e0b; /* жёлтый */
}
.model-menu-item.offline .model-dot {
  background: var(--text-dim); /* серый */
}

/* Индикатор стрима в sidebar */
.chat-item.streaming .chat-stream-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 1.5s infinite;
  flex-shrink: 0;
}


/* ==================== CHAT META (даты + токены + full-ctx) ==================== */
.chat-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}
.chat-meta .chat-date {
  font-size: var(--sidebar-font-size-sm);
  color: var(--text-dim);
  margin-top: 0;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-tokens {
  font-size: 10px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  flex-shrink: 0;
  cursor: default;
}
.chat-tokens.warn { color: #f59e0b; border-color: rgba(245, 158, 11, 0.4); }
.chat-tokens.over { color: var(--danger); border-color: rgba(239, 68, 68, 0.4); }

/* Мини-тумблер "полный контекст" в списке чатов */
.chat-fullctx {
  position: relative;
  display: inline-block;
  width: 26px;
  height: 15px;
  flex-shrink: 0;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s;
}
.chat-item:hover .chat-fullctx,
.chat-fullctx:has(input:checked) { opacity: 1; }
.chat-fullctx input { opacity: 0; width: 0; height: 0; }
.chat-fullctx .mcp-toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 15px;
  transition: background 0.2s;
}
.chat-fullctx .mcp-toggle-slider::before {
  content: '';
  position: absolute;
  width: 11px; height: 11px;
  left: 2px; top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.chat-fullctx input:checked + .mcp-toggle-slider { background: var(--accent); }
.chat-fullctx input:checked + .mcp-toggle-slider::before { transform: translateX(11px); }

/* ==================== FILE CHIPS (превью вложений) ==================== */
.img-preview.file-chip {
  width: auto;
  max-width: 180px;
  min-width: 120px;
  height: 44px;                   /* компактнее, чем у квадратной картинки */
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 6px 6px 8px;       /* симметричные вертикальные отступы */
}
.file-chip-body {
  display: flex;
  align-items: center;
  gap: 8px;                       /* чуть больше воздуха между иконкой и текстом */
  min-width: 0;
  flex: 1;
}
.file-chip-icon {
  font-size: 18px;                /* крупнее — лучше читается на компактном чипе */
  line-height: 1;                 /* чтобы иконка была по центру без «съезда» */
  flex-shrink: 0;
}
.file-chip-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.file-chip-name {
  font-size: 12px;                /* чуть крупнее для читаемости */
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-chip-size {
  font-size: 10px;
  color: var(--text-dim);
}

/* Скроллбар внутри file-chip — не нужен, но на всякий случай тонкий */
.img-preview.file-chip::-webkit-scrollbar { width: 4px; }

/* ==================== FILE ATTACHMENT (в user-сообщении) ==================== */
.msg.user .msg-content .file-attachment {
  background: var(--file-att-bg);          /* адаптивно к теме через переменную */
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 6px;
  overflow: hidden;
}
.file-att-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--file-att-header-bg);   /* адаптивно к теме */
  border-bottom: 1px solid var(--border);
}
.file-att-icon {
  font-size: 13px;
  color: var(--accent);                   /* иконка читается в обеих темах */
}
.file-att-name {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-att-size {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.file-att-pre {
  margin: 0;
  padding: 8px 10px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow-y: auto;
  color: var(--user-bubble-text);
}

/* Тонкий скроллбар внутри pre-блоков (и в file-attachment, и в tool-call) */
.file-att-pre::-webkit-scrollbar { width: 4px; }
.file-att-pre::-webkit-scrollbar-track { background: transparent; }
.file-att-pre::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
.file-att-pre { scrollbar-width: thin; }

.tool-call-pre::-webkit-scrollbar { width: 4px; }
.tool-call-pre::-webkit-scrollbar-track { background: transparent; }
.tool-call-pre::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
.tool-call-pre { scrollbar-width: thin; }


/* ==================== LOGOUT BUTTON (в модалке настроек) ==================== */
.logout-section {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 4px;
}

.logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--danger);
  border-radius: 10px;
  background: transparent;
  color: var(--danger);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.logout-btn:hover {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25);
}

.logout-btn:active {
  transform: translateY(1px);
}

.logout-btn svg {
  flex-shrink: 0;
}

/* ==================== PERSONA ==================== */
.persona-preview {
  font-size: 12px; color: var(--text-dim);
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; max-height: 140px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word; line-height: 1.5;
}
.persona-preview.empty { opacity: 0.6; font-style: italic; }
.persona-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.persona-btn {
  flex: 1; padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 13px; cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.persona-btn:hover { border-color: var(--accent); color: var(--accent); }
.persona-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.persona-btn.primary:hover { background: var(--accent-hover); }
.persona-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.persona-editor-overlay {
  position: fixed; inset: 0; z-index: 400;
  background: var(--bg); display: flex; flex-direction: column;
}
.persona-editor {
  display: flex; flex-direction: column; height: 100%;
  width: 100%; max-width: 760px; margin: 0 auto;
}
.persona-editor-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border); background: var(--bg-card);
}
.persona-editor-header h3 { font-size: 16px; font-weight: 600; }
.persona-editor-note { padding: 12px 16px 0; font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.persona-textarea {
  flex: 1; margin: 12px 16px; padding: 12px 14px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 14px; line-height: 1.6;
  font-family: inherit; resize: none; outline: none;
}
.persona-textarea:focus { border-color: var(--accent); }
.persona-editor-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--bg-card);
}
.persona-tokens { font-size: 12px; color: var(--text-dim); font-family: monospace; }
.persona-editor-btns { display: flex; gap: 8px; }


/* ==================== DRAG AND DROP OVERLAY ==================== */
.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 140;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 17, 21, 0.72);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

[data-theme="light"] .drop-overlay {
  background: rgba(255, 255, 255, 0.6);
}

.drop-overlay.visible {
  opacity: 1;
}

.drop-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-width: 260px;
  max-width: min(360px, calc(100vw - 48px));
  padding: 28px 32px;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: var(--bg-card);
  color: var(--text);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28);
}

.drop-overlay-inner svg {
  filter: drop-shadow(0 0 10px rgba(0, 229, 255, 0.3));
}

.drop-overlay-inner p {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
  text-align: center;
}
