:root {
  --bg-main: #0a0a0a;
  --bg-sidebar: #111111;
  --bg-header: #141414;
  --bg-input: #1a1a1a;
  --accent: #16a34a;
  --accent-hover: #22c55e;
  --accent-glow: rgba(22,163,74,0.5);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --border: #333333;
  --thinking-bg: rgba(30,41,59,0.92);
  --btn-shadow: 0 4px 12px rgba(0,0,0,0.4);
  --btn-hover-shadow: 0 8px 24px rgba(22,163,74,0.3);
  --bg-message-bot: #1a1a1a;
  --avatar-border: rgba(255,255,255,0.1);
  --accent-light: rgba(22,163,74,0.2);
  --action-btn-bg: rgba(255,255,255,0.1);
  --action-btn-hover: rgba(255,255,255,0.2);
  --user-message-bg: #1e40af;
  --user-message-gradient: linear-gradient(135deg, #1e40af, #3b82f6);
}

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

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

*::-webkit-scrollbar {
  display: none;
}

* {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

@media (min-width: 768px) {
  body { flex-direction: row; }
  #sidebar { width: 300px; height: 100%; border-right: 1px solid var(--border);}
  #main { flex: 1; }
}

@media (max-width: 767px) {
  #sidebar { width: 100%; height: auto; border-bottom: 1px solid var(--border); order: -1; }
  #sidebar-header { padding: 12px; justify-content: space-between; }
  #chats-list { display: flex; overflow-x: auto; padding: 12px; gap: 12px; }
  .chat-item { min-width: 140px; padding: 12px 16px; font-size: 14px; }
}

.rf-warning {
  position: fixed;
  bottom: 32px;
  left: 32px;
  width: 380px;
  max-width: calc(100% - 64px);
  background: rgba(15, 15, 15, 0.10);
  border: 1px solid #7f1d1d;
  border-left: 6px solid #ef4444;
  border-radius: 14px;
  padding: 18px 20px 18px 16px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  z-index: 9999;
  color: white;
  opacity: 0;
  transform: translateY(80px) scale(0.92);
  transition: all 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
  backdrop-filter: blur(10px);
}

.rf-warning.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.rf-warning svg {
  width: 36px;
  height: 36px;
  fill: #ef4444;
  flex-shrink: 0;
  margin-top: 2px;
}

.rf-warning .text {
  flex: 1;
  font-size: 15px;
  line-height: 1.48;
}

.rf-warning .text strong {
  color: white;
}

.rf-warning .close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: #ef4444;
  font-size: 24px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.rf-warning .close:hover {
  background: rgba(239, 68, 68, 0.18);
}

@media (max-width: 500px) {
  .rf-warning {
    left: 16px;
    right: 16px;
    width: auto;
  }
}

#sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
}

#sidebar-header { 
  padding: 14.3px; 
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
}
.logo-container { 
  display: flex; 
  align-items: center; 
}
.logo-text { 
  font-size: 30px; 
  font-weight: 600; 
  background: linear-gradient(135deg, var(--accent), #86efac);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#new-chat-btn {
  padding: 12px 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--btn-shadow);
  transition: all 0.25s ease;
}

#new-chat-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--btn-hover-shadow);
}

#chats-list { 
  flex: 1; 
  padding: 8px 0; 
  overflow-y: auto; 
}

.chat-item {
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  border-radius: 16px;
  background: rgba(255,255,255,0.03);
  transition: all 0.2s;
  margin: 4px 12px;
  min-height: 60px;
  border: 1px solid transparent;
}

.chat-item:hover { 
  background: rgba(255,255,255,0.08); 
  border-color: rgba(22,163,74,0.3);
}
.chat-item.active { 
  background: rgba(22,163,74,0.15); 
  border-left: 4px solid var(--accent);
  border-color: rgba(22,163,74,0.4);
}

.chat-item-content {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  cursor: pointer;
  overflow: hidden;
  min-width: 0;
}

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

.chat-delete-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(239,68,68,0.15);
  color: #ef4444;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.chat-delete-btn:hover {
  background: #ef4444;
  color: white;
  transform: scale(1.1);
}

#main { 
  flex: 1; 
  display: flex; 
  flex-direction: column; 
  min-height: 0; 
  background: var(--bg-main);
}

header {
  background: var(--bg-header);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.header-left { 
  display: flex; 
  align-items: center; 
  gap: 10px; 
}

.header-logo-text {
  font-size: 18px;
  font-weight: 600;
  background: #ffffff;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.mode-switcher {
  display: flex;
  background: #1e1e1e;
  border-radius: 999px;
  padding: 4px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.5);
  border: 1px solid var(--border);
}

.mode-btn {
  padding: 10px 18px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.25s;
}

.mode-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white;
  box-shadow: 0 4px 12px rgba(22,163,74,0.4);
}

.mode-btn:hover:not(.active) {
  background: rgba(255,255,255,0.05);
}

#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg-main);
}

.message { 
  display: flex; 
  gap: 12px; 
  max-width: 90%; 
  animation: fadeIn 0.3s ease-out;
}
.user { 
  align-self: flex-end; 
  flex-direction: row-reverse; 
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 3px var(--avatar-border), 0 0 12px var(--accent-glow);
  transition: transform 0.2s, box-shadow 0.3s;
  border: 2px solid rgba(22,163,74,0.3);
}

.avatar:hover { 
  transform: scale(1.1); 
  box-shadow: 0 0 0 4px var(--accent), 0 0 20px var(--accent-glow); 
}

.user .avatar {
  background: linear-gradient(135deg, #3b82f6, #1e40af);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.4), 0 0 12px rgba(59,130,246,0.5);
  border-color: rgba(59,130,246,0.3);
}

.user .avatar i { 
  color: white; 
  font-size: 26px; 
}

.message-bubble {
  background: var(--bg-message-bot);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 14px 18px;
  flex: 1;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
}

.message-bubble {
  max-width: 80%;           
  width: fit-content;       
  min-width: 0;             
  word-break: normal;       
  overflow-wrap: break-word;
  hyphens: auto;            
  white-space: normal;    
}

.message-bubble * {
  overflow-wrap: break-word;
  word-break: normal;
}

.message {
  max-width: 100%;
}

.user .message-bubble {
  max-width: 82%;
}

#user-input {
  overflow-wrap: break-word;
  word-break: normal;
  white-space: pre-wrap;
  max-width: 100%;
}

.user .message-bubble {
  background: var(--user-message-gradient);
  color: white;
  border-bottom-right-radius: 6px;
  border: none;
  box-shadow: 0 4px 6px -1px rgba(30,64,175,0.3), 0 2px 4px -1px rgba(30,64,175,0.2);
}

.bot .message-bubble { 
  border-bottom-left-radius: 6px; 
}

.thinking-box {
  background: var(--thinking-bg);
  border: 1px solid var(--accent);
  border-left: 5px solid var(--accent);
  border-radius: 16px;
  padding: 16px 20px;
  margin: 16px 0;
  box-shadow: 0 4px 16px rgba(22,163,74,0.2);
  backdrop-filter: blur(10px);
}

.thinking-title {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
}

.thinking-title i {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

#input-area {
  padding: 12px 16px;
  background: var(--bg-header);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  position: sticky;
  bottom: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
}

.attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.attach-btn:hover { 
  color: white; 
  transform: scale(1.1);
}

#user-input {
  flex: 1;
  padding: 14px 20px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 16px;
  font-family: system-ui, sans-serif;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.5);
  resize: none;
  min-height: 52px;
  max-height: 120px;
  line-height: 1.4;
  overflow-y: auto;
  outline: none;
  transition: all 0.2s;
}

#user-input:focus {
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.5), 0 0 0 2px var(--accent);
  border-color: var(--accent);
}

#user-input::placeholder {
  color: var(--text-secondary);
}

/* Убираем ВСЕ ползунки */
#user-input::-webkit-scrollbar,
#chat-container::-webkit-scrollbar,
#chats-list::-webkit-scrollbar,
*::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
  background: transparent;
}

#send-btn {
  padding: 14px 28px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--btn-shadow);
  transition: all 0.25s;
  min-width: 110px;
  justify-content: center;
  border: 1px solid rgba(22,163,74,0.3);
}

#send-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--btn-hover-shadow);
}

#send-btn:disabled { 
  background: #444; 
  cursor: not-allowed; 
  border-color: var(--border);
}

/* Красивые кнопки действий */
.bot-actions {
  display: flex;
  gap: 20px;
  margin-top: 7px;
  margin-bottom: 6px;
  justify-content: end;
}

.action-btn {
  width: 5px;
  height: 5px;
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
}

.action-btn:hover {
  transform: scale(1.15);
}

.action-btn.active {
  color: white;
  transform: scale(1.1);
}

/* Кнопки удаления сообщений */
.message-bubble .delete-msg-btn {
  color: #ef4444 !important;
}

.message-bubble .delete-msg-btn:hover {
  color: white !important;
}

/* Кнопка перегенерации */
.message-bubble .regen-btn {
  color: #3b82f6 !important;
}

.message-bubble .regen-btn:hover {
  color: white !important;
}

.message-bubble .copy-btn.active {
  color: white !important;
}

button {
  outline: none;
}

.user-avatar {
  background: linear-gradient(135deg, #3b82f6, #1e40af);
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-avatar i {
  font-size: 20px;
  color: white;
}

#preview-container { 
  display: flex; 
  align-items: center; 
  gap: 8px; 
}

#image-preview { 
  max-height: 48px; 
  border-radius: 10px; 
  border: 2px solid var(--accent);
}

#remove-preview {
  background: #ef4444; 
  color: white; 
  border: none; 
  border-radius: 50%; 
  width: 28px; 
  height: 28px; 
  font-size: 18px; 
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#remove-preview:hover {
  background: #dc2626;
  transform: scale(1.1);
}

.welcome-message {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
  font-size: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 20px;
}

.welcome-message i {
  font-size: 48px;
  color: var(--accent);
  margin-bottom: 20px;
}

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

.message-bubble pre {
  background: #1e1e1e;
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  border: 1px solid var(--border);
}

.message-bubble code {
  background: rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 14px;
}

.message-bubble h1, 
.message-bubble h2, 
.message-bubble h3 {
  margin-top: 16px;
  margin-bottom: 8px;
  color: var(--accent);
}

.message-bubble p {
  margin-bottom: 12px;
  line-height: 1.6;
}

.message-bubble ul, 
.message-bubble ol {
  margin-left: 20px;
  margin-bottom: 12px;
}

.message-bubble li {
  margin-bottom: 4px;
}

.message-bubble blockquote {
  border-left: 4px solid var(--accent);
  padding-left: 16px;
  margin: 12px 0;
  color: var(--text-secondary);
  font-style: italic;
}

.message-bubble a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}

.message-bubble a:hover {
  border-bottom-style: solid;
}

.message.new-message {
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.glow-effect {
  position: relative;
}

.glow-effect::before {
  content: '';
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  background: linear-gradient(45deg, var(--accent), transparent, var(--accent));
  border-radius: inherit;
  z-index: -1;
  opacity: 0;
  transition: opacity 0.3s;
}

.glow-effect:hover::before {
  opacity: 0.5;
}

::selection {
  background: #365470;
  color: white;
}

/* Основное правило для всех пузырей сообщений */
.message-bubble {
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  hyphens: auto;                    /* автоматический перенос по слогам (где возможно) */
  max-width: 85vw;                  /* или 90% — подбери под свой дизайн */
  box-sizing: border-box;
}

/* Особенно важно для кода и длинных строк */
.message-bubble pre,
.message-bubble code,
.message-bubble p,
.message-content {
  white-space: pre-wrap !important;
  word-break: break-all !important;   /* break-all — агрессивный перенос даже посередине слова */
  overflow-wrap: break-word !important;
  overflow-x: auto;                   /* на всякий случай горизонтальный скролл, если очень длинно */
  max-width: 100%;
}

/* Для пользовательских сообщений тоже */
.message.user .message-bubble p {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
}

.message-bubble {

  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 85%;           /* или 90vw */
  box-sizing: border-box;
}

.message-content,
.message-bubble p {
  white-space: pre-wrap !important;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
}

/* Для кода внутри сообщений */
.message-bubble pre,
.message-bubble code {
  white-space: pre-wrap;
  word-break: break-all;
  overflow-x: auto;
  max-width: 100%;
}