:root {
  --bg: #eef1ef;
  --bg-glow-1: rgba(16, 185, 129, 0.09);
  --bg-glow-2: rgba(59, 130, 246, 0.07);
  --sidebar-bg: rgba(249, 250, 251, 0.88);
  --card-bg: #f8f9fa;
  --header-bg: rgba(248, 249, 250, 0.82);
  --input-bg: #fafbfc;
  --accent: #059669;
  --accent-2: #22c55e;
  --accent-grad: linear-gradient(135deg, #059669, #22c55e);
  --accent-glow: rgba(16, 185, 129, 0.45);
  --text-primary: #131a21;
  --text-secondary: #5d6b7a;
  --muted: #8fa0ad;
  --border: rgba(22, 32, 42, 0.1);
  --border-strong: rgba(22, 32, 42, 0.16);
  --shadow-sm: 0 1px 2px rgba(22, 32, 42, 0.05), 0 1px 3px rgba(22, 32, 42, 0.07);
  --shadow-md: 0 8px 24px rgba(22, 32, 42, 0.1), 0 2px 6px rgba(22, 32, 42, 0.05);
  --shadow-lg: 0 24px 60px rgba(22, 32, 42, 0.2);
  --bot-bubble-bg: #fbfcfd;
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
}

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

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 12% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(1000px 520px at 112% 115%, var(--bg-glow-2), transparent 60%),
    var(--bg);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

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

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

@media (min-width: 768px) {
  body {
    flex-direction: row;
  }

  #sidebar {
    width: 288px;
    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(246, 248, 247, 0.95);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-left: 6px solid var(--danger);
  border-radius: 16px;
  padding: 18px 20px 18px 16px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  z-index: 9999;
  color: var(--text-primary);
  opacity: 0;
  transform: translateY(80px) scale(0.92);
  transition: all 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

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

.rf-warning svg {
  width: 36px;
  height: 36px;
  fill: var(--danger);
  flex-shrink: 0;
  margin-top: 2px;
}

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

.rf-warning .close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--danger);
  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: var(--danger-soft);
}

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

/* Сайдбар */
#sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

#sidebar-header {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 6px;
}

.logo-text {
  font-size: 28px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #34d399);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

#new-chat-btn {
  padding: 10px 16px;
  background: var(--accent-grad);
  color: white;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 6px 16px var(--accent-glow);
  transition: all 0.25s ease;
  white-space: nowrap;
}

#new-chat-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px var(--accent-glow);
}

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

.chat-item {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  border-radius: 14px;
  background: var(--card-bg);
  transition: all 0.2s;
  margin: 4px 12px;
  min-height: 56px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.chat-item:hover {
  transform: translateY(-1px);
  border-color: rgba(16, 185, 129, 0.4);
  box-shadow: var(--shadow-md);
}

.chat-item.active {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.12), rgba(34, 197, 94, 0.08));
  border-left: 4px solid var(--accent);
  border-color: rgba(16, 185, 129, 0.35);
}

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

.chat-item-content i {
  color: var(--accent);
  font-size: 14px;
}

.chat-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
}

.chat-delete-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--danger-soft);
  color: var(--danger);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  opacity: 0;
}

.chat-item:hover .chat-delete-btn {
  opacity: 1;
}

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

/* Основная область */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

header {
  background: var(--header-bg);
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 5;
}

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

.header-logo-text {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.header-logo-text::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent-2);
  margin-right: 8px;
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.18);
  animation: pulse 2s infinite;
}

.mode-switcher {
  display: flex;
  background: rgba(15, 23, 42, 0.06);
  border-radius: 999px;
  padding: 4px;
  border: 1px solid var(--border);
}

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

.mode-btn.active {
  background: var(--accent-grad);
  color: white;
  box-shadow: 0 4px 14px var(--accent-glow);
}

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

/* Чат */
#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 26px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.message {
  display: flex;
  gap: 12px;
  max-width: 100%;
  animation: fadeIn 0.3s ease-out;
}

.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: #f1f4f2;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25), var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.3s;
}

.avatar:hover {
  transform: scale(1.08);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.45), var(--shadow-md);
}

.user .avatar {
  background: linear-gradient(135deg, #0f172a, #1e293b);
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.15), var(--shadow-sm);
  border: none;
}

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

.message-bubble {
  background: var(--bot-bubble-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 14px 18px;
  flex: 1;
  box-shadow: var(--shadow-sm);
  max-width: 82%;
  width: fit-content;
  min-width: 0;
  word-break: normal;
  overflow-wrap: break-word;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  hyphens: auto;
  white-space: normal;
  box-sizing: border-box;
  transition: box-shadow 0.25s;
}

.message-bubble:hover {
  box-shadow: var(--shadow-md);
}

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

.user .message-bubble {
  max-width: 82%;
  background: var(--accent-grad);
  color: white;
  border-bottom-right-radius: 6px;
  border: none;
  box-shadow: 0 8px 20px rgba(5, 150, 105, 0.28);
}

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

.message-bubble p:last-child {
  margin-bottom: 0;
}

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

/* Блок размышлений */
.thinking-box {
  background: rgba(16, 185, 129, 0.06);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-left: 5px solid var(--accent);
  border-radius: 16px;
  padding: 14px 18px;
  margin: 6px 0 16px;
}

.thinking-title {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

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

.thinking-box p {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Контекст-меню */
#ctx-menu {
  position: fixed;
  z-index: 999999;
  min-width: 220px;
  background: rgba(247, 249, 248, 0.97);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 8px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  animation: ctxIn 0.14s ease-out;
  user-select: none;
}

.ctx-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  padding: 6px 10px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
  font-weight: 700;
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  transition: background 0.15s;
}

.ctx-item i {
  width: 18px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 15px;
}

.ctx-item:hover {
  background: rgba(16, 185, 129, 0.1);
}

.ctx-item:hover i {
  color: var(--accent);
}

.ctx-item.danger {
  color: var(--danger);
}

.ctx-item.danger i {
  color: var(--danger);
}

.ctx-item.danger:hover {
  background: var(--danger-soft);
}

.ctx-item.ok i {
  color: var(--accent);
}

.ctx-item.on {
  color: var(--accent);
}

.ctx-item.on i {
  color: var(--accent);
}

.ctx-sep {
  height: 1px;
  background: var(--border);
  margin: 6px 4px;
}

@keyframes ctxIn {
  from { opacity: 0; transform: scale(0.94) translateY(4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.message.swiping .message-bubble {
  opacity: 0.6;
  transform: translateX(-18px);
  transition: transform 0.2s, opacity 0.2s;
}

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

/* Реакции */
.reaction-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 30px;
  height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  margin-top: 10px;
  font-size: 12px;
  background: rgba(15, 23, 42, 0.05);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  user-select: none;
}

.reaction-badge.liked {
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent);
  border-color: rgba(16, 185, 129, 0.4);
}

.reaction-badge.disliked {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.4);
}

/* Индикатор печати */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 2px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Ввод */
#input-area {
  padding: 14px 18px 18px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: nowrap;
  position: sticky;
  bottom: 0;
  z-index: 10;
  background: linear-gradient(to top, var(--bg) 82%, transparent);
}

.attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-secondary);
  font-size: 18px;
  width: 46px;
  height: 52px;
  flex-shrink: 0;
}

.attach-btn:hover {
  color: var(--accent);
  transform: scale(1.12);
}

.input-shell {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 4px 6px 4px 18px;
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.2s, border-color 0.2s;
}

.input-shell:focus-within {
  border-color: rgba(16, 185, 129, 0.6);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.12), var(--shadow-md);
}

#user-input {
  flex: 1;
  padding: 12px 10px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  min-height: 30px;
  max-height: 120px;
  line-height: 1.4;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: normal;
  max-width: 100%;
}

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

#send-btn {
  width: 46px;
  height: 46px;
  min-width: 46px;
  background: var(--accent-grad);
  color: white;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px var(--accent-glow);
  transition: all 0.25s;
  flex-shrink: 0;
}

#send-btn:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 10px 24px var(--accent-glow);
}

#send-btn:disabled {
  background: rgba(15, 23, 42, 0.14);
  color: rgba(255, 255, 255, 0.7);
  box-shadow: none;
  cursor: not-allowed;
}

button {
  outline: none;
  font-family: inherit;
}

/* Кнопка "вниз" */
.scroll-btn {
  position: absolute;
  bottom: 96px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #f5f7f6;
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  z-index: 20;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: all 0.25s;
}

.scroll-btn.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.scroll-btn:hover {
  color: var(--accent);
  transform: translateY(-2px);
}

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

/* Превы-просмотр изображения */
#preview-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

#remove-preview {
  background: var(--danger);
  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);
}

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

/* Приветствие */
.welcome-message {
  text-align: center;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 14px;
  animation: fadeIn 0.5s ease-out;
}

.welcome-icon {
  width: 84px;
  height: 84px;
  border-radius: 26px;
  background: var(--accent-grad);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 38px;
  box-shadow: 0 18px 44px var(--accent-glow);
  animation: float 4s ease-in-out infinite;
  margin-bottom: 6px;
}

.welcome-message h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.welcome-message p {
  color: var(--text-secondary);
  font-size: 15px;
  margin: 0;
}

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 640px;
  margin-top: 14px;
}

.prompt-chip {
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.prompt-chip:hover {
  border-color: rgba(16, 185, 129, 0.5);
  color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

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

.message.new-message {
  animation: slideIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

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

/* Markdown-стили */
.message-bubble pre {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 12px;
  padding: 16px;
  overflow-x: auto;
  border: 1px solid rgba(255, 255, 255, 0.08);
  margin: 10px 0;
}

.message-bubble pre code {
  background: transparent;
  padding: 0;
}

.message-bubble code {
  background: rgba(15, 23, 42, 0.07);
  padding: 2px 6px;
  border-radius: 6px;
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
  font-size: 13px;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
  margin-top: 14px;
  margin-bottom: 8px;
  color: var(--text-primary);
  font-weight: 700;
}

.message-bubble h1 { font-size: 20px; }
.message-bubble h2 { font-size: 18px; }
.message-bubble h3 { font-size: 16px; }

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

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

.message-bubble blockquote {
  border-left: 4px solid var(--accent-2);
  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-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
}

.message-bubble th,
.message-bubble td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

.message-bubble th {
  background: rgba(16, 185, 129, 0.08);
  font-weight: 600;
}

.message-content {
  white-space: pre-wrap !important;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  max-width: 100%;
}

.message.user .message-bubble p {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
}

.message.user .message-bubble code {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.message.user .message-bubble pre {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.message.user .message-bubble a {
  color: #fff;
  border-bottom-color: rgba(255, 255, 255, 0.6);
}

.glow-effect {
  position: relative;
}

::selection {
  background: rgba(16, 185, 129, 0.28);
  color: var(--text-primary);
}