/* Global Styles */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --text-primary: #eeeeee;
  --text-secondary: #e6e6e6;
  --accent-primary: #0f3460;
  --accent-secondary: #e94560;
  --success: #4ade80;
  --warning: #fbbf24;
  --error: #f87171;
  --border-radius: 8px;
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  --border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="light"] {
  --bg-primary: #f8f9fa;
  --bg-secondary: #ffffff;
  --text-primary: #333333;
  --text-secondary: #555555;
  --accent-primary: #e3f2fd;
}

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

html,
body {
  height: 100%;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  /* вместо min-height: 100vh фиксируем высоту через html/body */
  padding: 2px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}

/* Header Styles */
header {
  text-align: center;
  margin-bottom: 2px;
  padding: 4px 10px;
  background-color: var(--bg-secondary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 960px;
  margin-left: auto;
  margin-right: auto;
  flex: 0 0 auto; /* фиксированная высота в flex-колонке */
}

header h1 {
  color: var(--accent-secondary);
  margin-bottom: 4px;
  font-size: 1.2rem; /* ещё чуть меньше заголовок, экономим высоту */
}

header p {
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-size: 0.7rem;
}

.model-label {
  display: inline-block;
  margin-right: 10px;
  font-weight: bold;
}

#model-select {
  padding: 8px 12px;
  border-radius: var(--border-radius);
  border: 2px solid var(--accent-primary);
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  margin-right: 10px;
}

.model-status {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 15px;
  vertical-align: middle;
}

.model-status.available {
  background-color: var(--success);
}

.model-status.unavailable {
  background-color: var(--error);
}

#theme-toggle {
  background-color: var(--accent-primary);
  color: var(--text-primary);
  border: none;
  padding: 8px 12px;
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: 1.2rem;
}

#theme-toggle:hover {
  background-color: var(--accent-secondary);
}

/* Контейнер для выпадающего меню */
.models-dropdown-container {
  position: relative;
  display: inline-block;
  margin-right: 25px !important;
}

/* Стили для ссылки "О моделях" */
header .models-link {
  color: #ffffff !important;
  text-decoration: none !important;
  font-weight: bold !important;
  font-size: 0.9rem !important;
  padding: 2px 6px !important;
  border-radius: 4px !important;
  transition: all 0.3s ease !important;
  box-shadow: 20px 20px 40px rgba(0, 0, 0, 0.9) !important, -10px -10px 20px rgba(255, 255, 255, 0.5) !important;
  display: inline-block !important;
  position: relative !important;
  z-index: 10 !important;
  background: linear-gradient(145deg, var(--accent-secondary), #c73650) !important;
  border: 1px solid rgba(233, 69, 96, 0.5) !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3) !important;
  outline: 3px solid red !important;
}

header .models-link:hover {
  color: #ffffff !important;
  background: linear-gradient(145deg, #c73650, var(--accent-secondary)) !important;
  box-shadow: 25px 25px 50px rgba(0, 0, 0, 0.95) !important, -12px -12px 25px rgba(255, 255, 255, 0.6) !important;
  transform: translateY(-2px) !important;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4) !important;
  outline: 3px solid blue !important;
}

/* Выпадающее меню */
header .models-dropdown {
  position: absolute !important;
  top: 100% !important;
  right: 0 !important;
  background: var(--bg-primary) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 8px !important;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.5) !important, 0 6px 15px rgba(0, 0, 0, 0.3) !important;
  min-width: 180px !important;
  opacity: 0 !important;
  visibility: hidden !important;
  transform: translateY(-10px) !important;
  transition: all 0.3s ease !important;
  z-index: 1000 !important;
  margin-top: 5px !important;
}

header .models-dropdown.show {
  opacity: 1 !important;
  visibility: visible !important;
  transform: translateY(0) !important;
}

header .dropdown-item {
  display: block;
  padding: 10px 15px;
  color: var(--text-primary);
  text-decoration: none;
  transition: background 0.2s ease;
  border-radius: 6px;
  margin: 4px;
}

header .dropdown-item:hover {
  background: var(--bg-secondary);
  color: var(--accent-primary);
}

header .dropdown-item:first-child {
  margin-top: 8px;
}

header .dropdown-item:last-child {
  margin-bottom: 8px;
}

/* Scroll Buttons INSIDE chat container */
.scroll-to-top,
.scroll-to-bottom {
  position: absolute;
  right: 16px;
  background-color: var(--accent-secondary);
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: none;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  opacity: 0.9;
  z-index: 10;
}

.scroll-to-top {
  top: 16px;
}

.scroll-to-bottom {
  bottom: 120px;
}

.scroll-to-top.show,
.scroll-to-bottom.show {
  display: flex;
}

/* Chat Container */
.chat-container {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  background-color: var(--bg-secondary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
  flex: 1 1 auto; /* занимает всё доступное пространство между header и footer */
  display: flex;
  flex-direction: column;
}

.chat-messages {
  padding: 12px; /* ещё чуть уменьшаем внутренний отступ */
  flex: 1 1 auto;
  min-height: 0; /* важно, чтобы flex корректно считал высоту и позволял скролл */
  overflow-y: auto; /* единственное место со скроллом */
}

/* Message Styles */
.message {
  margin-bottom: 8px;  /* ещё компактнее вертикальный разрыв между сообщениями */
  padding: 10px;       /* уменьшаем внутренний отступ */
  border-radius: var(--border-radius);
  position: relative;
  font-size: 0.9rem;   /* уменьшаем шрифт в сообщениях */
  line-height: 1.4;    /* чуть плотнее строки для экономии места */
}

.user-message {
  background-color: var(--accent-primary);
  margin-left: 0;
  margin-right: 0;
  border-left: 4px solid var(--accent-secondary);
}

.assistant-message {
  background-color: var(--bg-primary);
  margin-left: 0;
  margin-right: 0;
  border-left: 4px solid var(--success);
}

.message h1, .message h2, .message h3 {
  margin: 8px 0 6px 0; /* меньше отступы вокруг заголовков */
  color: var(--accent-secondary);
}

.message h1 {
  font-size: 1.4rem;
  border-bottom: 1px solid var(--accent-secondary);
  padding-bottom: 3px;
}

.message h2 {
  font-size: 1.2rem;
  color: var(--warning);
}

.message h3 {
  font-size: 1.05rem;
  color: var(--success);
}

.message strong {
  color: var(--accent-secondary);
}

.message em {
  color: var(--warning);
}

.message ul {
  margin: 4px 0;      /* меньше вертикальный отступ вокруг списков */
  padding-left: 18px; /* чуть компактнее отступ слева */
}

.message li {
  margin: 2px 0;      /* плотнее элементы списка */
}

.message hr {
  border: none;
  border-top: 2px solid var(--accent-primary);
  margin: 10px 0; /* меньше вертикальный зазор для разделителей */
}

.message blockquote {
  border-left: 4px solid var(--accent-secondary);
  padding-left: 15px;
  margin: 8px 0;  /* меньше отступы вокруг цитат */
  color: var(--text-secondary);
  font-style: italic;
}

.message pre {
  background-color: var(--accent-primary);
  padding: 10px;   /* компактнее блоки кода */
  border-radius: var(--border-radius);
  overflow-x: auto;
  margin: 8px 0;  /* меньше отступы вокруг блоков кода */
}

.message code {
  font-family: 'Courier New', monospace;
  background-color: var(--accent-primary);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Размышление модели (сворачиваемый блок) */
.reasoning-block {
  margin-bottom: 6px;
  padding: 4px 8px;
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  font-size: 0.85rem;
}

.reasoning-block > summary {
  cursor: pointer;
  list-style: none;
  outline: none;
}

.reasoning-block > summary::-webkit-details-marker {
  display: none;
}

.reasoning-block > summary::before {
  content: "🤔 ";
}

.reasoning-content {
  margin-top: 4px;
}

/* File Preview in Messages */
.file-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  margin: 10px 0;
}

.file-preview img {
  max-width: 100px;
  max-height: 100px;
  border-radius: 4px;
}

.file-preview .file-info {
  flex: 1;
}

.file-preview .file-name {
  font-weight: bold;
  color: var(--accent-secondary);
}

.file-preview .file-size {
  font-size: 0.9em;
  color: var(--text-secondary);
}

/* Message Controls */
.message-controls {
  display: flex;
  gap: 8px;
  margin-top: 15px;
  opacity: 0.7;
  transition: opacity 0.3s ease;
}

.message:hover .message-controls {
  opacity: 1;
}

.message-controls button {
  background-color: var(--accent-primary);
  color: var(--text-primary);
  border: none;
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.message-controls button:hover {
  background-color: var(--accent-secondary);
  transform: translateY(-1px);
}

.message-controls button.copy-btn {
  background-color: #3b82f6;
}

.message-controls button.export-btn {
  background-color: #10b981;
}

.message-controls button.copy-btn:hover {
  background-color: #2563eb;
}

.message-controls button.export-btn:hover {
  background-color: #059669;
}

/* Message Input Panel (CONTAINS EVERYTHING) */
.message-input-panel {
  padding: 10px 16px; /* ужимаем панель ввода по высоте */
  background-color: var(--bg-primary);
  border-top: 2px solid var(--accent-primary);
}

/* Main Input Row */
.input-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  align-items: flex-end;
}

.input-row #user-input {
  flex: 1;
  padding: 12px;
  border: 2px solid var(--accent-primary);
  border-radius: var(--border-radius);
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  resize: none;
  min-height: 60px;
  max-height: 150px;
  font-size: 16px;
}

#user-input:focus {
  outline: none;
  border-color: var(--accent-secondary);
}

.input-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#send-button {
  padding: 10px 18px;
  background: linear-gradient(145deg, var(--accent-secondary), #c73650) !important;
  color: #ffffff !important;
  border: 1px solid rgba(233, 69, 96, 0.5) !important;
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  transition: all 0.3s ease;
  white-space: nowrap;
  box-shadow: 25px 25px 50px rgba(0, 0, 0, 0.95) !important, -12px -12px 25px rgba(255, 255, 255, 0.6) !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3) !important;
  outline: 3px solid red !important;
}

#send-button:hover:not(:disabled) {
  background: linear-gradient(145deg, #c73650, var(--accent-secondary)) !important;
  box-shadow: 30px 30px 60px rgba(0, 0, 0, 0.98) !important, -15px -15px 30px rgba(255, 255, 255, 0.7) !important;
  transform: translateY(-3px) !important;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4) !important;
  outline: 3px solid blue !important;
}

#send-button:disabled {
  background: linear-gradient(145deg, #666, #555) !important;
  color: #999 !important;
  cursor: not-allowed;
  box-shadow: 15px 15px 30px rgba(0, 0, 0, 0.8) !important, -8px -8px 15px rgba(255, 255, 255, 0.5) !important;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2) !important;
  outline: 3px solid gray !important;
}

/* Мобильная версия кнопки "Отправить" */
@media (max-width: 768px) {
  #send-button {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    width: 60px !important;
    height: 60px !important;
    padding: 0 !important;
    border-radius: 50% !important;
    font-size: 20px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 1000 !important;
    background: linear-gradient(145deg, var(--accent-secondary), #c73650) !important;
    box-shadow: 12px 12px 24px rgba(0, 0, 0, 0.9) !important, -6px -6px 12px rgba(255, 255, 255, 0.5) !important;
  }
  
  #send-button:hover:not(:disabled) {
    transform: scale(1.1) !important;
    box-shadow: 15px 15px 30px rgba(0, 0, 0, 0.95) !important, -8px -8px 15px rgba(255, 255, 255, 0.6) !important;
  }
  
  /* Кнопки загрузки файлов - в один ряд */
  .file-buttons {
    flex-direction: row !important;
    gap: 8px !important;
    margin-bottom: 80px !important; /* Место для кнопки Отправить */
  }
  
  .file-btn {
    flex: 1 !important;
    min-width: 0 !important;
    padding: 8px 12px !important;
    font-size: 12px !important;
  }
  
  /* Уменьшаем отступы для экономии места */
  .message-input-panel {
    padding: 15px !important;
  }
  
  /* Увеличиваем место для чата */
  .chat-container {
    height: calc(100vh - 180px) !important; /* Меньше места для панели ввода */
  }
}

/* File Upload Section (INSIDE the panel) */
.file-upload-section {
  border-top: 1px solid var(--accent-primary);
  padding-top: 15px;
}

.file-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.file-btn {
  background-color: var(--accent-primary);
  color: var(--text-primary);
  border: none;
  border-radius: 4px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s ease;
}

.file-btn:hover {
  background-color: var(--accent-secondary);
  transform: translateY(-1px);
}

.file-input-hidden {
  display: none;
}

/* Uploaded Files Container */
.uploaded-files-container {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.uploaded-file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: rgba(255, 255, 255, 0.1);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 13px;
}

.uploaded-file-item img {
  max-width: 25px;
  max-height: 25px;
  border-radius: 3px;
}

.remove-file-btn {
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  margin: 0;
}

.remove-file-btn:hover {
  color: #ff6b81;
}

/* Typing Indicator */
.typing-indicator {
  text-align: center;
  padding: 15px;
  color: var(--text-secondary);
  font-style: italic;
  display: none;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius);
  margin: 10px 0;
  border-left: 4px solid var(--warning);
}

.typing-indicator.visible {
  display: block;
  animation: pulse 1.5s ease-in-out infinite;
}

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

/* Footer */
footer {
  text-align: center;
  margin-top: 2px;
  padding: 4px 10px;
  color: var(--text-secondary);
  font-size: 0.75rem;
  width: 100%;
  max-width: 960px;
  margin-left: auto;
  margin-right: auto;
  flex: 0 0 auto; /* фиксированная высота внизу экрана */
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
  width: 10px;
}

.chat-messages::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--accent-primary);
  border-radius: 5px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--accent-secondary);
}

/* Responsive Design */
@media (max-width: 1200px) {
  .chat-container {
    max-width: 95%;
  }
}

@media (max-width: 768px) {
  body {
    padding: 10px;
  }
  
  header h1 {
    font-size: 1.5rem;
  }
  
  .chat-messages {
    min-height: 300px;
    padding: 15px;
  }
  
  .message {
    padding: 15px;
  }
  
  .input-row {
    flex-direction: column;
  }
  
  #user-input {
    border-radius: var(--border-radius);
    margin-bottom: 10px;
  }
  
  #send-button {
    width: 100%;
    border-radius: var(--border-radius);
  }
  
  .message-input-panel {
    padding: 15px;
  }
  
  .user-message {
    margin-left: 5%;
  }
  
  .assistant-message {
    margin-right: 5%;
  }
  
  .scroll-to-top {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
  
  .scroll-to-bottom {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
  
  .file-buttons {
    flex-direction: column;
  }
  
  .message-controls {
    flex-direction: column;
  }
  
  .message-controls button {
    width: 100%;
    justify-content: center;
  }
}