:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --secondary: #f97316;
  --text: #1e293b;
  --text-light: #64748b;
  --background: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --success: #10b981;
  --danger: #ef4444;
  --info: #3b82f6;
  --nav-height: 70px; /* Базовая высота навигации */
  --nav-height-scrolled: 50px; /* Уменьшенная высота навигации */
  --nav-height-mobile: 60px; /* Уменьшенная высота навигации на мобильных */
  --nav-height-mobile-scrolled: 50px; /* Уменьшенная высота на мобильных */

  /* Add transition for smooth theme switching */
  transition: background-color 0.3s ease, color 0.3s ease;
}

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

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--background);
  color: var(--text);
  line-height: 1.6;
  transition: background-color 0.3s ease, color: 0.3s ease;
}

/* Заменяем nav на .main-nav */
.main-nav {
  background: var(--primary);
  color: white;
  padding: 1rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: fixed; /* Фиксированная позиция вместо sticky */
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: centerter;
  transition: padding 0.3s ease, font-size 0.3s ease, height 0.3s ease;
  width: 100%; /* Гарантирует полную ширину */
  box-sizing: border-box; /* Padding включается в размер элемента */
  margin: 0; /* Убираем любые наружные отступы */
  left: 0; /* Прижимаем к левому краю */
  right: 0; /* Прижимаем к правому краю */
  height: var(--nav-height); /* Фиксированная высота */
}

/* Стили при скроллинге */
.main-nav.nav-scrolled {
  padding: 0.5rem 1rem;
  height: var(--nav-height-scrolled);
}

.main-nav.nav-scrolled .nav-brand {
  font-size: 1.25rem;
}

.main-nav.nav-scrolled .nav-links a {
  font-size: 0.9rem;
  padding: 0.3rem 0.6rem;
}

.nav-brand {
  font-size: 1.5rem;
  font-weight: 700;
  color: white;
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 1.5rem;
}

.main-nav a {
  color: white;
  text-decoration: none;
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  transition: all 0.2s ease;
}

.main-nav a:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 1.5rem;
  background: var(--card);
  border-radius: 0.75rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  animation: fadeIn 0.5s ease;
  box-sizing: border-box; /* Padding включается в размер */
  margin-top: calc(var(--nav-height) + 1rem); /* Отступ сверху равен высоте навигации + 1rem */
  transition: margin-top 0.3s ease; /* Плавный переход */
}

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

h2 {
  color: var(--primary);
  margin-bottom: 1.5rem;
  font-weight: 700;
  position: relative;
  display: inline-block;
}

h2::after {
  content: "";
  position: absolute;
  bottom: -5px;
  left: 0;
  width: 40px;
  height: 3px;
  background: var(--secondary);
  border-radius: 3px;
}

.flash {
  padding: 1rem;
  margin: 1rem 0;
  border-radius: 0.5rem;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    transform: translateX(-20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.flash.success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
  border-left: 4px solid var(--success);
}

.flash.danger {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border-left: 4px solid var(--danger);
}

.flash.info {
  background: rgba(59, 130, 246, 0.1);
  color: var(--info);
  border-left: 4px solid var(--info);
}

.cookie-banner {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: var(--text);
  color: white;
  padding: 1rem;
  text-align: center;
  z-index: 1000;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  animation: slideUp 0.5s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.cookie-banner button {
  margin-left: 1rem;
  padding: 0.5rem 1rem;
  background: var(--secondary);
  color: white;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
}

.cookie-banner button:hover {
  background: #ea580c;
  transform: scale(1.05);
}

/* Чат-контейнер для оптимизации высоты */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--nav-height) - 120px); /* Учитываем высоту навигации */
  transition: height 0.3s ease; /* Плавная анимация при изменении высоты */
}

/* Chat styles */
.chat-section {
  border: 1px solid var(--border);
  flex-grow: 1; /* Заполнить доступное пространство */
  min-height: 0; /* Позволяет flex-grow работать правильно */
  overflow-y: auto;
  padding: 0.5rem; /* Уменьшенный отступ для сообщений */
  background: var(--card);
  border-radius: 0.75rem;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
  scroll-behavior: smooth;
  will-change: transform; /* Предотвращает дрожание при прокрутке */
  position: relative;
}

.chat-input {
  display: flex;
  margin-top: 1rem;
  gap: 0.5rem;
  width: 100%; /* Полная ширина */
}

.chat-input input,
.chat-input textarea {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 1rem;
  transition: all 0.2s ease;
  min-width: 0; /* Позволяет сжиматься при необходимости */
  background-color: var(--card);
  color: var(--text);
}

.chat-input input:focus,
.chat-input textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);
}

.chat-input button {
  padding: 0.75rem 1.25rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap; /* Предотвращает перенос текста кнопки */
}

.chat-input button:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
}

/* Оптимизируем анимацию сообщений, чтобы предотвратить дёргание */
.chat-section .user,
.chat-section .bot,
.chat-section .admin {
  padding: 0.75rem 1rem;
  margin: 0.5rem 0;
  word-break: break-word;
  display: block;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  /* Убираем анимацию, которая могла вызывать дёргание */
  opacity: 1;
  transform: none;
}

.chat-section .user {
  background: var(--primary);
  color: white;
  border-radius: 1rem 1rem 0 1rem;
  margin-left: auto;
  margin-right: 0.25rem;
  max-width: 85%;
}

.chat-section .bot,
.chat-section .admin {
  background: #f1f5f9;
  color: var(--text);
  border-radius: 1rem 1rem 1rem 0;
  margin-right: auto;
  margin-left: 0.25rem;
  max-width: 85%;
}

/* //Светлый желтый для сообщений администратора
.chat-section .admin {
background: #fef3c7;
}
*/

/* Bot selection */
.bot-list {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin: 2rem 0;
}

.bot-list > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 1.5rem;
  border-radius: 1rem;
  background: var(--card);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.bot-list > div:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
}

.bot-list img {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--primary);
  transition: all 0.3s ease;
}

.bot-list > div:hover img {
  transform: scale(1.05);
  border-color: var(--secondary);
}

.bot-list p {
  margin-top: 1rem;
  font-weight: 600;
  color: var(--text);
  font-size: 1.25rem;
}

/* Forms */
form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 400px;
  margin: 0 auto;
}

form label {
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.25rem;
  display: block;
}

form input {
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 1rem;
  width: 100%;
  transition: all 0.2s ease;
  background-color: var(--card);
  color: var(--text);
}

form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);
}

form input[type="submit"] {
  background: var(--primary);
  color: white;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

form input[type="submit"]:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
}

form a {
  color: var(--primary);
  text-decoration: none;
  transition: all 0.2s ease;
}

form a:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  border-radius: 0.5rem;
  overflow: hidden;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

table th,
table td {
  padding: 0.75rem 1rem;
  text-align: left;
}

table th {
  background: var(--primary);
  color: white;
  font-weight: 500;
}

table tr:nth-child(even) {
  background: #f1f5f9;
}

table tr {
  transition: all 0.2s ease;
}

table tr:hover {
  background: #e2e8f0;
}

table a {
  color: var(--primary);
  text-decoration: none;
  transition: all 0.2s ease;
}

table a:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

/* Стиль для иконки бота в заголовке чата */
.chat-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  object-fit: cover;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  width: 100%;
}

.clear-chat-btn {
  background-color: var(--danger);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 0.5rem;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  transition: all 0.2s ease;
}

.clear-chat-btn:hover {
  background-color: #c82333;
  transform: translateY(-2px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Специальный скролл для чата */
.chat-section::-webkit-scrollbar {
  width: 8px;
}

.chat-section::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 6px;
}

.chat-section::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 6px;
}

.chat-section::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Responsive */
@media (max-width: 768px) {
  .container {
    margin: 0; /* Убираем внешние отступы */
    margin-top: var(--nav-height-mobile); /* Отступ под высоту мобильной навигации */
    padding: 1rem;
    border-radius: 0; /* Убираем скругление углов */
    width: 100%; /* Полная ширина */
    max-width: 100%; /* Переопределяем максимальную ширину */
  }

  .chat-container {
    height: calc(100vh - var(--nav-height-mobile) - 80px); /* Корректируем под мобильную навигацию */
  }

  .bot-list {
    flex-direction: column;
    align-items: center;
  }

  .chat-input {
    flex-wrap: nowrap; /* Предотвращаем перенос на новую строку */
  }

  .chat-input button {
    padding: 0.75rem 0.75rem; /* Уменьшаем отступы кнопки */
    font-size: 0.9rem; /* Уменьшаем размер шрифта */
  }

  /* Настройки мобильной навигации */
  .main-nav {
    padding: 0.5rem;
    flex-direction: row; /* Изменено на row для размещения в одну линию */
    height: var(--nav-height-mobile);
  }

  .nav-links {
    width: auto; /* Ширина по содержимому */
    gap: 0.5rem; /* Уменьшаем расстояние между кнопками */
  }

  .nav-links a {
    padding: 0.3rem 0.5rem; /* Меньшие отступы для кнопок */
    font-size: 0.85rem; /* Меньший размер шрифта */
  }

  .main-nav.nav-scrolled {
    padding: 0.4rem 0.5rem;
    height: var(--nav-height-mobile-scrolled);
  }

  .main-nav.nav-scrolled .nav-brand {
    font-size: 1.1rem;
  }

  /* Корректируем высоту при скроллинге */
  .main-nav.nav-scrolled + .container {
    margin-top: var(--nav-height-mobile-scrolled);
  }

  .main-nav.nav-scrolled + .container .chat-container {
    height: calc(100vh - var(--nav-height-mobile-scrolled) - 80px);
  }
}

/* Для очень маленьких экранов */
@media (max-width: 380px) {
  .nav-brand {
    font-size: 1.25rem; /* Еще меньший размер для бренда */
  }

  .nav-links a {
    padding: 0.25rem 0.4rem; /* Минимальные отступы */
    font-size: 0.8rem; /* Еще меньший шрифт */
  }

  .main-nav {
    padding: 0.5rem 0.4rem; /* Меньше боковых отступов */
  }
}
