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

:root, body.dark {
  --bg-primary: #0a0a0f; --bg-secondary: #14141c; --bg-tertiary: #1e1e2a;
  --bg-elevated: #252530; --accent: #3b82f6; --accent-hover: #2563eb;
  --accent-glow: rgba(59,130,246,0.3); --accent-secondary: #8b5cf6;
  --text-primary: #f1f5f9; --text-secondary: #94a3b8; --text-tertiary: #64748b;
  --border: #2d2d3a; --danger: #ef4444; --success: #10b981;
  --card-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
}
body.light {
  --bg-primary: #fff; --bg-secondary: #f8f9fa; --bg-tertiary: #f1f3f5;
  --bg-elevated: #e9ecef; --text-primary: #1a1a2e; --text-secondary: #4a4a6a;
  --border: #e2e8f0; --card-shadow: 0 25px 50px -12px rgba(0,0,0,0.15);
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', system-ui, sans-serif;
  background: var(--bg-primary); color: var(--text-primary);
  line-height: 1.5; transition: background 0.2s, color 0.2s;
}

/* ===== AUTH ===== */
.auth-container {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 30%, var(--accent-glow) 0%, transparent 70%);
  padding: 20px;
}
.auth-card {
  background: var(--bg-secondary); border-radius: 32px; padding: 48px 40px;
  width: 100%; max-width: 460px; border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
}
.logo { text-align: center; margin-bottom: 32px; }
.logo svg { width: 52px; height: 52px; }
.logo h1 {
  font-size: 28px; font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-top: 12px;
}
.auth-card h2 { font-size: 28px; font-weight: 600; text-align: center; margin-bottom: 8px; }
.auth-sub { text-align: center; color: var(--text-secondary); margin-bottom: 32px; }

.auth-methods { display: flex; gap: 12px; margin-bottom: 24px; }
.auth-method-btn {
  flex: 1; padding: 16px; border: 2px solid var(--border);
  background: var(--bg-tertiary); border-radius: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 15px; font-weight: 600; transition: 0.2s; color: var(--text-secondary);
}
.auth-method-btn:hover { border-color: var(--accent); background: var(--bg-elevated); color: var(--text-primary); }
.auth-method-btn.active { border-color: var(--accent); background: var(--accent-glow); color: var(--text-primary); }
.auth-method-btn svg { width: 22px; height: 22px; }

.auth-form { display: none; animation: fadeIn 0.3s ease; }
.auth-form.active { display: block; }
@keyframes fadeIn { from { opacity:0; transform:translateY(5px); } to { opacity:1; transform:translateY(0); } }

.input-group { margin-bottom: 20px; }
.input-group input, .input-group select {
  width: 100%; padding: 14px 16px; background: var(--bg-tertiary);
  border: 1px solid var(--border); border-radius: 16px;
  color: var(--text-primary); font-size: 15px; transition: 0.15s;
}
.input-group input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.btn-primary {
  width: 100%; padding: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  border: none; border-radius: 40px; color: #fff; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: 0.2s; margin-top: 8px;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 20px var(--accent-glow); }

.btn-secondary {
  width: 100%; padding: 12px; background: transparent; border: 1px solid var(--border);
  border-radius: 40px; color: var(--text-primary); font-size: 14px; font-weight: 500;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 12px;
  text-decoration: none; transition: 0.2s;
}
.btn-secondary:hover { background: var(--bg-tertiary); border-color: var(--accent); }

.divider {
  text-align: center; margin: 24px 0; position: relative;
  color: var(--text-tertiary); font-size: 12px;
}
.divider::before, .divider::after {
  content: ''; position: absolute; top: 50%;
  width: calc(50% - 40px); height: 1px; background: var(--border);
}
.divider::before { left: 0; } .divider::after { right: 0; }

.text-link { color: var(--accent); text-decoration: none; font-size: 14px; cursor: pointer; }
.text-link:hover { text-decoration: underline; }

.telegram-widget-box {
  margin: 24px 0; padding: 20px; background: var(--bg-tertiary);
  border-radius: 16px; text-align: center; border: 1px solid var(--border);
}

/* ===== CHAT LAYOUT ===== */
.chat-layout {
  display: flex;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  flex-shrink: 0;
  position: relative;
  transition: none;
  transition: width 0.25s ease-in-out;
}
.sidebar-expanded {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.sidebar.collapsed { width: 0; border-right: none; }

.sidebar-top {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 60px;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.logo-small {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
}
.logo-small svg { width: 28px; height: 28px; color: var(--accent); flex-shrink: 0; }
.logo-text {
  font-size: 18px; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  white-space: nowrap; transition: none;
}
.sidebar.collapsed .logo-text { opacity: 0; width: 0; transition: none;}

.toggle-sidebar-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.2s;
  width: 29px; 
  height: 29px;
}
.toggle-sidebar-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.toggle-sidebar-btn svg { width: 16px; height: 16px; }

.new-chat-btn {
  width: 100%; padding: 10px 14px; background: var(--bg-tertiary);
  border: 1px solid var(--border); border-radius: 12px;
  color: var(--text-primary); font-weight: 500; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background 0.2s, border-color 0.2s; font-size: 13px;
}
.new-chat-btn:hover { background: var(--bg-elevated); border-color: var(--accent); }
.new-chat-btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.sidebar-collapsed-header {
  display: none;
  position: absolute;
  left: 16px;
  top: 8px;
  align-items: center;
  gap: 12px;
  z-index: 100;
}
.sidebar.collapsed .sidebar-collapsed-header { display: flex; }
.sidebar.collapsed .sidebar-expanded { display: none; }

.sidebar-collapsed-logo {
  display: flex; align-items: center; justify-content: center;
  background: transparent; padding: 0; height: 32px;
}
.sidebar-collapsed-logo svg { width: 28px; height: 28px; color: var(--accent); }

.sidebar-collapsed-buttons {
  display: flex; gap: 6px; background: var(--bg-secondary);
  border: 1px solid var(--border); border-radius: 40px;
  padding: 6px 10px; box-shadow: var(--card-shadow);
  backdrop-filter: blur(10px); height: 41px; align-items: center;
}
.sidebar-collapsed-btn {
  background: transparent; border: 1px solid var(--border);
  border-radius: 8px; padding: 0; cursor: pointer;
  color: var(--text-secondary); display: flex; align-items: center;
  justify-content: center; transition: all 0.2s ease;
  flex-shrink: 0; width: 29px; height: 29px;
}
.sidebar-collapsed-btn:hover {
  background: var(--bg-tertiary); color: var(--text-primary);
  border-color: var(--border); transform: none;
}
.sidebar-collapsed-btn svg { width: 14px; height: 14px; transition: none; }
.sidebar-collapsed-btn:hover svg { transform: none; color: var(--text-primary); }

.history-list {
  flex: 1; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth;
  padding: 8px 12px 12px 12px; min-height: 0;
  max-height: calc(100vh - 175px); position: relative;
  scrollbar-width: thin; scrollbar-color: var(--bg-secondary) transparent; display: flex;
  flex-direction: column;
  gap: 4px;
}
.history-list-wrapper { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.sidebar.collapsed .history-list { display: none; }

.history-list::-webkit-scrollbar { width: 6px; }
.history-list::-webkit-scrollbar-track { background: transparent; margin: 4px 0 4px 0; }
.history-list::-webkit-scrollbar-thumb {
  background: var(--bg-secondary); border-radius: 3px; transition: background 0.2s;
}
.history-list::-webkit-scrollbar-thumb:hover { background: var(--bg-tertiary); }
.history-list:hover { scrollbar-color: var(--text-secondary) transparent; }
.history-list:hover::-webkit-scrollbar-track::before,
.history-list:hover::-webkit-scrollbar-track::after { opacity: 1; background: var(--accent); }
.sidebar:hover .history-list::-webkit-scrollbar-thumb { background: var(--bg-tertiary); }
.history-list:not(.overflowing)::after { display: none; }

.history-section-title {
  padding: 12px 12px 6px; font-size: 11px; font-weight: 600;
  color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.5px;
}
.history-item {
  padding: 10px 12px; border-radius: 12px; cursor: pointer;
  font-size: 14px; color: var(--text-secondary); transition: background 0.15s, color 0.15s;
  display: flex; align-items: center; gap: 8px; position: relative; margin:0;
}
.history-item-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: none;}
.history-item-title-input {
  width: 100%; border: 1px solid transparent; background: var(--bg-tertiary);
  color: var(--text-primary); border-radius: 10px; padding: 6px 10px;
  font-size: 14px; line-height: 1.2; outline: none; box-shadow: none;
  -webkit-appearance: none; appearance: none; box-sizing: border-box;
}
.history-item-title-input:focus {
  border-color: var(--accent); outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}
.history-item:hover, .history-item.active { background: var(--bg-tertiary); color: var(--text-primary); }

.chat-actions-btn {
  width: 24px; height: 24px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--text-secondary); display: flex;
  opacity: 0; pointer-events: none; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.history-item:hover .chat-actions-btn,
.history-item.active .chat-actions-btn,
.chat-actions-btn:focus-visible { opacity: 1; pointer-events: auto; }
.chat-actions-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }

.chat-actions-menu {
  position: absolute; right: 8px; min-width: 160px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg-elevated);
  box-shadow: var(--card-shadow); padding: 6px; display: none; z-index: 20;
}
.chat-actions-menu.show { display: block; }
.history-item.menu-down .chat-actions-menu { top: calc(100% - 6px); }
.history-item.menu-up .chat-actions-menu { bottom: calc(100% - 6px); }

.chat-actions-item {
  width: 100%; border: none; border-radius: 8px; background: transparent;
  color: var(--text-primary); text-align: left; padding: 8px 10px;
  cursor: pointer; font-size: 13px;
}
.chat-actions-item:hover { background: var(--bg-tertiary); }
.chat-actions-item.danger { color: var(--danger); }

.sidebar-footer {
  padding: 12px 16px; border-top: 1px solid var(--border);
  margin-top: auto; background: var(--bg-secondary); z-index: 10; flex-shrink: 0;
}
.user-info-sidebar {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px;
  border-radius: 12px; cursor: pointer; transition: 0.2s; position: relative;
}
.user-info-sidebar:hover { background: var(--bg-tertiary); }
.sidebar.collapsed .user-info-sidebar { justify-content: center; padding: 8px; }
.sidebar.collapsed .user-info-text { display: none; }

.user-avatar {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: #fff; flex-shrink: 0; font-size: 14px;
}
.user-info-text { flex: 1; min-width: 0; }
.user-info-text div:first-child {
  font-weight: 600; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.user-dropdown {
  position: absolute; bottom: 65px; left: 16px; width: 240px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 16px; padding: 8px; box-shadow: var(--card-shadow);
  opacity: 0; transform: translateY(10px) scale(0.95);
  pointer-events: none; transition: all 0.2s ease; z-index: 1000;
}
.user-dropdown.active { opacity: 1; transform: translateY(0) scale(1); pointer-events: all; }

.dropdown-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-radius: 10px; cursor: pointer; color: var(--text-primary);
  font-size: 14px; transition: 0.15s;
}
.dropdown-item:hover { background: var(--bg-tertiary); }
.dropdown-item svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--text-secondary); }

.dropdown-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.3);
  opacity: 0; pointer-events: none; transition: 0.2s; z-index: 999;
}
.dropdown-overlay.active { opacity: 1; pointer-events: all; }

/* ===== MAIN CHAT ===== */
.chat-main {
  flex: 1 1 0%; min-height: 0; display: flex;
  flex-direction: column; position: relative;
}

.messages-area {
  flex: 1 1 0%; min-height: 0; overflow-y: auto; overflow-x: hidden;
  padding: 0 32px; position: relative; display: flex;
  flex-direction: column; align-items: center;
  overscroll-behavior: contain; scrollbar-width: thin;
  scrollbar-color: #39445f transparent;
}
.messages-area::-webkit-scrollbar { width: 10px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #2f3a56, #3f4f75);
  border-radius: 10px; border: 2px solid transparent; background-clip: padding-box;
}
.messages-area::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #4a5f8f, #5c74ab); background-clip: padding-box;
}

.welcome-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; text-align: center; padding: 40px; max-width: 600px;
}

/* ===== MESSAGES CONTAINER & ALIGNMENT ===== */
.messages-container {
  width: 100%; max-width: 900px; display: flex; flex-direction: column; margin: 0 auto;
}

.message-group {
  display: flex; gap: 16px; width: 100%;
}

/* User messages - right aligned, no right margin */
.message-group.user-row {
  flex-direction: row; align-items: flex-start; align-self: flex-end;
  max-width: 100%; margin-left: auto; margin-right: 0; gap: 0;
}
.message-group.user-row:first-child{ margin-top: 15px; }
.message-group.user-row .message-content { flex: 1; min-width: 0; max-width: 100%; }

.message-content.user-bubble {
  background: transparent; border: none; padding: 0;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}

.user-message-stack {
  display: flex; flex-direction: column; align-items: flex-end;
  gap: 8px; max-width: 100%; width: auto; box-sizing: border-box;
}

.user-attachment-card {
  display: flex; align-items: center; gap: 8px;
  min-width: 0; max-width: 100%; width: auto;
  min-height: 52px; background: var(--bg-tertiary);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 8px 12px; box-sizing: border-box;
}

.user-text-bubble {
  width: auto; max-width: min(100%, 650px);
  text-align: left; line-height: 1.5; font-size: 15px;
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 18px; padding: 10px 14px; color: var(--text-primary);
  box-sizing: border-box; overflow: hidden; word-wrap: break-word;
}

/* Assistant messages - left aligned, no avatar */
.message-group:not(.user-row) {
  flex-direction: row; align-items: flex-start; align-self: flex-start;
  max-width: 100%; margin-right: auto; margin-left: 0; margin-top:8px; gap: 0;
}
.message-group:not(.user-row):first-child {
  margin-top: 0;
}
.message-group:last-child {
  margin-bottom: 8px; /* ← Меньший отступ для последнего */
}

.message-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg-tertiary); display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; font-size: 16px;
}
.message-avatar.user {
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary)); color: #fff;
}

.message-content {
  flex: 1; line-height: 1.6; font-size: 15px;
  background: var(--bg-secondary); padding: 12px 16px;
  border-radius: 16px; border: 1px solid var(--border);
  width: 100%; max-width: 100%; word-wrap: break-word; overflow-wrap: break-word;
}

.message-stack {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  align-items: flex-start; max-width: 100%; width: 100%;
}
.message-group.user-row .message-stack { align-items: flex-end; }

/* ===== ACTION BUTTONS - DeepSeek style ===== */
.message-actions {
  display: flex; align-items: center; gap: 4px;
  margin-top: 8px; margin-left: 0;
  opacity: 0; transition: opacity 0.2s ease; pointer-events: none;
}
.message-actions.user-actions {
  margin-left: 0; justify-content: flex-end;
  opacity: 0; transform: none; transition: opacity 0.2s ease; pointer-events: none;
}

/* Last message: buttons always visible */
.message-group.user-row:last-child .message-actions.user-actions,
.message-actions.user-actions.always-visible,
.message-group:not(.user-row):last-child .message-actions,
.message-actions:not(.user-actions).always-visible {
  opacity: 1; transform: none; pointer-events: auto;
}
/* Hover: show buttons */
.message-group.user-row:hover .message-actions.user-actions,
.message-group:not(.user-row):hover .message-actions {
  opacity: 1; pointer-events: auto;
}

.message-action-btn {
  border: none; background: transparent; color: var(--text-tertiary);
  width: 28px; height: 28px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0; transition: all 0.15s ease;
}
.message-action-icon { width: 14px; height: 14px; stroke: currentColor; }
.message-action-btn:hover {
  color: var(--text-primary); background: var(--bg-tertiary); border-color: transparent;
}
.message-action-btn.done { color: var(--success); }

.message-content.user-bubble.editing {
  background: transparent; border: none; padding: 0;
}

.inline-edit-card {
  width: min(100%, 860px); border: 2px solid var(--accent);
  border-radius: 22px; background: #2a2b30; padding: 12px 16px 10px;
  box-shadow: 0 0 0 1px rgba(99,132,255,0.2) inset;
}
.inline-edit-input {
  width: 100%; min-height: 48px; max-height: 180px; resize: none;
  background: transparent; border: none; outline: none;
  color: var(--text-primary); font-size: 15px; line-height: 1.45; font-family: inherit;
}
.inline-edit-actions { margin-top: 10px; display: flex; justify-content: flex-end; gap: 10px; }
.inline-edit-btn {
  border-radius: 999px; border: 1px solid var(--border);
  background: transparent; color: var(--text-primary);
  padding: 9px 18px; font-size: 15px; cursor: pointer;
}
.inline-edit-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.inline-edit-btn.primary:hover { background: var(--accent-hover); }
.inline-edit-btn.ghost:hover { background: var(--bg-tertiary); }

.continue-btn {
  border: 1px solid var(--border); border-radius: 999px;
  background: transparent; color: var(--text-primary);
  padding: 6px 14px; font-size: 13px; cursor: pointer;
}
.continue-btn:hover { border-color: var(--accent); color: var(--accent); }

.message-content pre {
  background: var(--bg-tertiary); padding: 16px; border-radius: 12px; overflow-x: auto;
}

.message-content:has(.chat-error-box) { border-left: 3px solid var(--danger); }
.chat-error-box { border-radius: 10px; padding: 2px 0 0 0; }
.chat-error-title { color: var(--danger); font-size: 14px; line-height: 1.5; font-weight: 600; }
.chat-error-details {
  margin-top: 8px; font-size: 12px; font-family: ui-monospace, Consolas, 'Courier New', monospace;
  color: var(--text-secondary); white-space: pre-wrap; word-break: break-word; opacity: 0.95;
}

/* ===== INPUT BAR ===== */
.chat-input-wrapper {
  width: 100%; padding: 20px 32px 24px; display: flex;
  justify-content: center; background: var(--bg-primary);
  flex-shrink: 0; position: relative; z-index: 20; overflow: visible;
}
.input-bar {
  display: flex; flex-direction: column; background: var(--bg-secondary);
  border: 1px solid var(--border); border-radius: 24px;
  width: 100%; max-width: 900px; transition: 0.2s; overflow: visible;
}

.input-btn {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 16px; padding: 8px 12px; color: var(--text-secondary);
  font-size: 13px; cursor: pointer; transition: 0.2s;
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.input-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }
.input-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.input-btn.icon-only { padding: 8px; border-radius: 50%; width: 36px; height: 36px; justify-content: center; }
.input-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.input-textarea {
  width: 100%; background: transparent; border: none; padding: 0;
  color: var(--text-primary); font-size: 15px; resize: none;
  font-family: inherit; line-height: 1.5; min-height: 24px; max-height: 200px;
  overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--bg-tertiary) transparent;
}
.input-textarea-wrapper { width: 100%; padding: 10px 12px 0 12px; }

.attachments-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.attachments-viewport { flex: 1; display: flex; gap: 6px; min-width: 0; overflow: hidden; }

.attachments-nav {
  display: none; width: 0; min-width: 0; height: 32px; padding: 0;
  box-sizing: border-box; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-tertiary); color: var(--text-secondary); cursor: pointer;
  line-height: 0; flex-shrink: 0; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; overflow: hidden;
  transition: opacity 0.18s ease, width 0.18s ease, min-width 0.18s ease,
              background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}
.attachments-nav-icon { display: block; width: 18px; height: 18px; flex-shrink: 0; stroke: currentColor; }
.attachments-row.has-overflow .attachments-nav {
  display: flex; width: 32px; min-width: 32px; opacity: 1; pointer-events: auto;
}
.attachments-row.has-overflow .attachments-nav:hover:not(:disabled) {
  background: var(--bg-elevated); border-color: var(--text-tertiary); color: var(--text-primary);
}
.attachments-row.has-overflow .attachments-nav:active:not(:disabled) { transform: scale(0.96); }
.attachments-row.has-overflow .attachments-nav:disabled {
  opacity: 0.35; cursor: not-allowed; color: var(--text-tertiary);
}

.attachment-chip {
  display: flex; align-items: center; gap: 8px;
  width: calc((100% - 12px) / 3); min-width: calc((100% - 12px) / 3);
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px 10px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.attachment-chip:hover { border-color: var(--accent); background: var(--bg-elevated); }

.attachment-icon {
  width: 24px; height: 24px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; letter-spacing: 0.2px; color: #fff; flex-shrink: 0;
}
.attachment-icon.pdf { background: linear-gradient(180deg, #ef4444, #dc2626); }
.attachment-icon.doc { background: linear-gradient(180deg, #3b82f6, #1d4ed8); }
.attachment-icon.text { background: linear-gradient(180deg, #10b981, #047857); }
.attachment-icon.default { background: linear-gradient(180deg, #64748b, #475569); }
.attachment-icon.image { background: linear-gradient(180deg, #8b5cf6, #6d28d9); }

.attachment-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.attachment-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px; color: var(--text-primary); font-weight: 600; flex: 1; min-width: 0;
}
.attachment-size {
  font-size: 11px; color: var(--text-secondary); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 100%; min-width: 0;
}
.attachment-size.error { color: #fca5a5; }

.attachment-remove {
  border: none; background: transparent; color: var(--text-secondary);
  cursor: pointer; font-size: 16px; line-height: 1; opacity: 0;
  transform: translateX(4px); transition: opacity 0.15s ease, transform 0.15s ease, color 0.15s ease;
}
.attachment-chip:hover .attachment-remove { opacity: 1; transform: translateX(0); }
.attachment-remove:hover { color: var(--text-primary); }

.input-textarea:focus { outline: none; }
.input-textarea::placeholder { color: var(--text-tertiary); }
.input-textarea::-webkit-scrollbar { width: 10px; height: 10px; }
.input-textarea::-webkit-scrollbar-track { background: transparent; border-radius: 5px; }
.input-textarea::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 5px; min-height: 50px; }
.input-textarea::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }
.input-textarea::-webkit-scrollbar-button {
  display: none !important; height: 0 !important; width: 0 !important;
  background: transparent !important; -webkit-appearance: none !important;
}
.input-textarea::-webkit-scrollbar-corner { background: transparent; }
@-moz-document url-prefix() { .input-textarea { scrollbar-width: auto; } }
.input-textarea { -ms-overflow-style: none; scrollbar-width: thin; }

.input-buttons {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  flex-shrink: 0; overflow: visible; position: relative; z-index: 2;
}

.send-btn {
  background: var(--accent); border: none; border-radius: 50%;
  width: 36px; height: 36px; color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: 0.2s; flex-shrink: 0; margin-left: auto; position: relative;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn.is-stop { background: #ef4444; transition: background 0.15s ease; }
.send-btn.is-stop:hover { background: #dc2626; }
.send-btn.is-stop.retry-mode { transition: background 0.1s ease; }
.send-btn.is-stop.retry-mode:hover { transition: background 0.08s ease; }
.stop-square { width: 12px; height: 12px; border-radius: 2px; background: #fff; display: inline-block; }

.send-btn.disabled, .send-btn:disabled {
  opacity: 1; cursor: not-allowed; background: #5b8dff; pointer-events: none;
}
.send-btn.disabled[data-tooltip]:not([data-tooltip=""]):hover::after,
.send-btn:disabled[data-tooltip]:not([data-tooltip=""]):hover::after,
.send-btn.is-stop[data-tooltip]:not([data-tooltip=""]):hover::after {
  content: attr(data-tooltip); position: absolute; right: calc(100% + 10px); left: auto; top: 50%;
  bottom: auto; transform: translateY(-50%); display: block; width: max-content;
  max-width: min(300px, 85vw); white-space: normal; word-wrap: break-word;
  word-break: normal; overflow-wrap: break-word; writing-mode: horizontal-tb; direction: ltr;
  unicode-bidi: plaintext; overflow: visible; text-overflow: clip; text-align: left;
  line-height: 1.35; background: var(--bg-elevated); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px;
  font-size: 12px; box-shadow: var(--card-shadow); z-index: 50; pointer-events: none;
}
.send-btn svg { width: 18px; height: 18px; }

/* ===== LOADING MESSAGE - FIXED WIDTH ===== */
.loading-message {
  width: 100%; max-width: 900px; margin: 0 auto;
}
.loading-message .message-content {
  background: var(--bg-secondary); border: 1px solid var(--border);
  padding: 12px 16px; border-radius: 16px; display: flex;
  align-items: center; gap: 12px; min-height: auto;
  width: 100%; max-width: 100%;
}
.generating-text { display: flex; gap: 4px; align-items: center; }
.generating-text .dot {
  width: 8px; height: 8px; background: var(--accent); border-radius: 50%;
  display: inline-block; animation: pulse 1.4s infinite ease-in-out both;
}
.generating-text .dot:nth-child(1) { animation-delay: -0.32s; }
.generating-text .dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes pulse {
  0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}
.generating-label {
  color: var(--text-secondary); font-size: 14px; font-weight: 500;
  animation: fadeInOut 2s infinite ease-in-out;
}
@keyframes fadeInOut {
  0%, 100% { opacity: 0.6; } 50% { opacity: 1; }
}

/* ===== SETTINGS MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px); display: flex; align-items: center;
  justify-content: center; z-index: 1000; opacity: 0;
  pointer-events: none; transition: 0.2s;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal-container {
  width: 760px; height: 500px; background: var(--bg-secondary);
  border-radius: 24px; border: 1px solid var(--border);
  box-shadow: var(--card-shadow); display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-header h2 { font-size: 20px; font-weight: 600; }
.close-modal { background: none; border: none; color: var(--text-secondary); font-size: 24px; cursor: pointer; }
.modal-body { flex: 1; display: flex; overflow: hidden; }
.modal-nav {
  width: 200px; padding: 16px; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
}
.modal-nav .nav-item {
  text-align: left; background: transparent; border: none;
  color: var(--text-secondary); padding: 12px; border-radius: 12px;
  cursor: pointer; font-size: 15px; transition: 0.2s;
}
.modal-nav .nav-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.modal-nav .nav-item.active { background: var(--accent); color: #fff; }
.modal-content { flex: 1; padding: 24px; overflow-y: auto; position: relative; }
.tab-content { display: none; } .tab-content.active { display: block; }
.setting-row { margin-bottom: 24px; }
.setting-label { font-weight: 600; margin-bottom: 12px; display: block; }

.theme-buttons { display: flex; gap: 10px; }
.theme-btn {
  width: 163px; height: 82px; border: 2px solid var(--border);
  border-radius: 16px; cursor: pointer; background: var(--bg-tertiary);
  color: var(--text-primary); font-size: 14px; font-weight: 500;
  transition: 0.2s; display: flex; align-items: center; justify-content: center;
}
.theme-btn.active { border-color: var(--accent); }
.theme-btn:hover { background: var(--bg-elevated); }

.language-container { width: 514px; height: 60px; margin-top: 8px; }
.dropdown { position: relative; }
.dropdown-btn {
  width: 100%; padding: 12px; background: var(--bg-tertiary);
  border: 1px solid var(--border); border-radius: 16px;
  color: var(--text-primary); cursor: pointer; text-align: left; font-size: 14px;
}
.dropdown-menu {
  position: absolute; left: 0; right: 0; background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; display: none; z-index: 10;
}
.dropdown-menu.show { display: block; }
.dropdown-menu li {
  padding: 12px 16px; cursor: pointer; transition: 0.2s; color: var(--text-primary);
}
.dropdown-menu li:hover { background: var(--bg-tertiary); }
.dropdown-menu li.active { background: var(--accent-glow); color: var(--accent); }

.profile-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 0; border-bottom: 1px solid var(--border);
}
.profile-row:last-child { border-bottom: none; }
.profile-label { color: var(--text-secondary); }
.profile-value { color: var(--text-primary); font-weight: 500; }
.profile-btn {
  background: transparent; border: 1px solid var(--border);
  padding: 6px 16px; border-radius: 20px; cursor: pointer;
  color: var(--text-primary); font-size: 13px; transition: 0.2s;
}
.profile-btn:hover { background: var(--bg-tertiary); border-color: var(--accent); }
.profile-btn.danger { border-color: var(--danger); color: var(--danger); }
.profile-btn.danger:hover { background: rgba(239,68,68,0.1); }

.data-section, .about-section {
  color: var(--text-tertiary); font-size: 14px; text-align: center; padding: 40px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .auth-card { padding: 32px 24px; }
  .logo h1 { font-size: 24px; }
  .auth-card h2 { font-size: 24px; }
  .sidebar {
    position: fixed; left: -100%; top: 0; bottom: 0; z-index: 200; width: 280px;
  }
  .sidebar.mobile-open { left: 0; }
  .sidebar.collapsed { left: -100%; width: 0; }
  .modal-container { width: 100%; height: 100%; max-width: 100%; border-radius: 0; }
  .modal-nav { width: 70px; }
  .modal-nav .nav-item span { display: none; }
  .input-btn span { display: none; }
  .input-btn { padding: 8px; border-radius: 50%; width: 36px; height: 36px; justify-content: center; }
  .logo-text { display: none; }
  .user-dropdown { left: 12px; right: 12px; width: auto; bottom: 70px; }
  .messages-area { padding: 16px; }
  .chat-input-wrapper { padding: 12px 16px 20px; }
  .welcome-content { padding: 20px 10px; }
  .theme-btn { width: 100px; height: 70px; font-size: 12px; }
  .language-container { width: 100%; height: auto; }
  
  .message-actions { opacity: 1; }
}

/* ===== AUTO-FILL FIX ===== */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 1000px var(--bg-tertiary) inset !important;
  -webkit-text-fill-color: var(--text-primary) !important;
  transition: background-color 5000s ease-in-out 0s;
  caret-color: var(--text-primary);
}