/* CSS Переменные для тем - AI стиль (Gemini/Copilot) */
:root {
  /* Deep Paper Light Theme (Super low glare) */
  --bg-primary: #F4F3F0;
  --bg-secondary: #EAE9E4;
  --bg-tertiary: #DFDDDA;
  --text-primary: #333333;
  --text-secondary: #6B6B6B;
  --text-tertiary: #8A8A8A;
  --border-color: #D2D0C9;
  --accent-color: #9C7153;
  --accent-hover: #835B40;
  --accent-light: rgba(156, 113, 83, 0.12);
  --user-message-bg: transparent;
  --assistant-message-bg: transparent;
  --success-color: #34d399;
  --error-color: #D97757;
  --warning-color: #fbbf24;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.05);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
}

[data-theme="dark"] {
  /* Unified Theme Enforced */
  --bg-primary: #0A0B0D;
  --bg-secondary: #141619;
  --bg-tertiary: #1A1D21;
  --text-primary: #ECEDF0;
  --text-secondary: #7D8590;
  --text-tertiary: #5A6069;
  --border-color: #2A2D33;
  --accent-color: #E6C09C;
  --accent-hover: #D4AF8B;
  --accent-light: rgba(230, 192, 156, 0.1);
  --user-message-bg: transparent;
  --assistant-message-bg: transparent;
  --success-color: #34d399;
  --error-color: #D97757;
  --warning-color: #fbbf24;
  --shadow-sm: none;
  --shadow-md: none;
  --shadow-lg: none;
  --shadow-xl: none;
}

/* Сброс стилей */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.65;
  transition: background-color 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Навигация */
.navbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  box-shadow: none;
  padding: 1rem 0;
}

.nav-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: nowrap;
}

.nav-brand h1 {
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: visible;
  text-overflow: ellipsis;
  max-width: 250px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  letter-spacing: -0.01em;
}

.nav-brand h1 span.accent {
  color: var(--accent-color);
}

.beta-badge {
  font-size: 0.65rem;
  font-weight: 500;
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-sm);
  color: var(--accent-color);
  background-color: var(--accent-light);
  position: relative;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.nav-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}

/* Кнопки */
.btn {
  padding: 0.75rem 1.5rem;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background-color: var(--accent-color);
  color: white;
  background-color: var(--text-primary);
  color: var(--bg-primary);
}

.btn-primary:hover {
  background-color: var(--text-secondary);
  transform: none;
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background-color: transparent;
  color: var(--text-primary);
  border: 1px solid var(--text-secondary);
}

.btn-secondary:hover {
  background-color: var(--bg-tertiary);
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.icon-btn {
  background: none;
  border: none;
  padding: 0.625rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  cursor: pointer;
  color: var(--text-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease, background-color 0.2s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:hover {
  background-color: var(--bg-secondary);
}

.icon-btn:active {
}

.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  display: block;
}

svg.icon {
  width: 1.25rem !important;
  height: 1.25rem !important;
  max-width: 1.25rem;
  max-height: 1.25rem;
}

.icon-btn svg,
.icon-btn .icon {
  width: 1.25rem !important;
  height: 1.25rem !important;
  max-width: 1.25rem;
  max-height: 1.25rem;
}

/* Основной контент */
.main-content {
  min-height: calc(100vh - 80px);
}

.page {
  display: block;
}

/* Страница авторизации */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 80px);
  padding: 2rem 1rem;
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at 15% 50%, var(--accent-light), transparent 25%),
              radial-gradient(circle at 85% 30%, rgba(99, 102, 241, 0.08), transparent 25%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background-color: var(--bg-primary);
  border-radius: var(--radius-xl);
  padding: 2.5rem 2rem;
  box-shadow: none;
  border: 1px solid var(--border-color);
  position: relative;
  z-index: 1;
}

.auth-header {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 1.25rem;
  background: var(--bg-secondary);
  color: var(--accent-color);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-icon svg {
  width: 28px;
  height: 28px;
}

.auth-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.auth-subtitle {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  margin: 0;
}

.auth-tabs {
  display: flex;
  background-color: var(--bg-secondary);
  padding: 0.375rem;
  border-radius: var(--radius-lg);
  margin-bottom: 2rem;
  gap: 0.25rem;
}

.tab-btn {
  flex: 1;
  padding: 0.625rem 1rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 600;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: center;
  border-radius: var(--radius-md);
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  background-color: var(--bg-primary);
  color: var(--accent-color);
  box-shadow: var(--shadow-sm);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
}

.auth-form .form-group label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.auth-form .btn-primary {
  margin-top: 0.75rem;
  padding: 0.875rem 1.5rem;
  font-size: 1rem;
}

.auth-form a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s ease;
}
.auth-form a:hover {
  color: var(--accent-color);
}

.form-group label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-weight: 400;
}

.form-group input:not([type="checkbox"]),
.form-group select,
.form-group textarea {
  padding: 0.875rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9375rem;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.form-group input:not([type="checkbox"]):focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* Стили для checkbox */
.form-group input[type="checkbox"] {
  width: 1.125rem;
  height: 1.125rem;
  margin: 0;
  padding: 0;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: var(--bg-primary);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.form-group input[type="checkbox"]:hover {
  border-color: var(--accent-color);
  background-color: var(--bg-secondary);
}

.form-group input[type="checkbox"]:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.form-group input[type="checkbox"]:checked {
  background-color: var(--accent-color);
  border-color: var(--accent-color);
}

.form-group input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
  width: 0.375rem;
  height: 0.625rem;
  border: solid white;
  border-width: 0 2px 2px 0;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  line-height: 1.4;
}

.error-message {
  margin-top: 1rem;
  padding: 0.75rem;
  background-color: var(--error-color);
  color: white;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  text-align: center;
}

/* Страница чата */
.chat-layout {
  display: flex;
  height: calc(100vh - 80px);
  max-width: 100%;
  margin: 0;
}

.sidebar {
  width: 260px;
  min-width: 260px;
  background-color: var(--bg-secondary);
  border-right: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
  transition: margin-left 0.3s ease, transform 0.3s ease;
  margin-left: 0;
}

.sidebar.hidden {
  margin-left: -260px;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: none;
  flex-shrink: 0;
}

.sidebar-header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 0.5rem;
}

.sidebar-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.sidebar-close-btn {
  display: flex;
  cursor: pointer;
}


.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.conversation-item {
  padding: 0.625rem 0.875rem;
  margin: 0.25rem 0.75rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  background-color: transparent !important;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.conversation-item:hover {
  background-color: var(--bg-tertiary) !important;
}

.conversation-item:active {
}

.conversation-item.active {
  background-color: var(--bg-primary) !important;
  box-shadow: var(--shadow-sm);
  color: var(--text-primary);
}

.conversation-item-icon {
  color: var(--text-secondary);
  flex-shrink: 0;
}

.conversation-item-content {
  flex: 1;
  min-width: 0;
}

.conversation-item-title {
  font-weight: 500;
  margin-bottom: 0.25rem;
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.conversation-item-actions {
  display: flex;
  gap: 0.25rem;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 1rem;
  background-color: var(--bg-primary);
  min-height: 60px;
}

.chat-title-area {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.conversation-title {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
  padding-left: 1rem;
  border-left: 1px solid var(--border-color);
}

.model-selector {
  margin-top: 0;
  flex-shrink: 0;
}

/* Скрываем старые селекты */
.model-selector select,
select#conversationModelSelect {
  display: none !important;
}

/* Custom Select Component */
.custom-select-container {
  position: relative;
  width: 100%;
  max-width: 280px;
}

#newConversationModal .custom-select-container {
  max-width: 100%;
}

.custom-select-trigger {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0.5rem 0.875rem;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  user-select: none;
  white-space: nowrap;
}

.form-group .custom-select-trigger {
  border-radius: var(--radius-lg);
  padding: 0.875rem 1rem;
  background-color: var(--bg-primary);
  font-weight: normal;
}

.custom-select-trigger:hover, 
.custom-select-container.open .custom-select-trigger {
  background-color: var(--bg-tertiary);
  border-color: var(--accent-color);
  box-shadow: none;
  color: var(--accent-color);
  transform: none;
}

.custom-select-container.open .custom-select-trigger .icon {
  transform: rotate(180deg);
}

.custom-select-trigger .icon {
  width: 1rem;
  height: 1rem;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  color: var(--text-secondary);
  margin-left: 0.5rem;
  flex-shrink: 0;
}

.custom-select-value {
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-select-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  width: 100%;
  min-width: 240px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: none;
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.custom-select-container.open .custom-select-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.custom-select-options {
  max-height: 300px;
  overflow-y: auto;
  padding: 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-tertiary) transparent;
}

.custom-select-options::-webkit-scrollbar { width: 6px; }
.custom-select-options::-webkit-scrollbar-thumb { background-color: var(--bg-tertiary); border-radius: 3px; }

.custom-select-optgroup {
  padding: 0.75rem 0.75rem 0.25rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 0.25rem;
}

.custom-select-optgroup:first-child { padding-top: 0.25rem; }

.custom-select-option {
  padding: 0.625rem 0.75rem;
  font-size: 0.9375rem;
  color: var(--text-primary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.custom-select-option:hover {
  background-color: var(--bg-secondary);
  color: var(--accent-color);
}

.custom-select-option.selected {
  background-color: var(--accent-light);
  color: var(--accent-color);
  font-weight: 600;
}

.custom-select-option.selected::after {
  content: '';
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent-color);
}

.usage-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  padding: 0.5rem 1rem;
  background-color: var(--bg-secondary);
  border-radius: 2rem;
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
  cursor: default;
  flex-shrink: 0;
}

.usage-info:hover {
  background-color: var(--bg-tertiary);
  border-color: var(--accent-color);
}

.usage-icon {
  color: var(--warning-color);
  fill: rgba(245, 158, 11, 0.2);
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 0 1.5rem;
  background-color: var(--bg-primary);
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  padding: 2rem;
  max-width: 768px;
  margin: 0 auto;
}

.empty-state-title {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  text-align: center;
}

.empty-state-subtitle {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin-bottom: 2.5rem;
  text-align: center;
  font-weight: 500;
}

.example-suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  width: 100%;
  max-width: 800px;
}

.example-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background-color: var(--bg-secondary);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.example-item:hover {
  background-color: var(--bg-primary);
  border-color: var(--accent-color);
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.example-item:active {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.example-icon {
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
  color: var(--accent-color);
  background-color: var(--accent-light);
  padding: 0.625rem;
  border-radius: 50%;
  box-sizing: content-box;
}

.example-item span {
  color: var(--text-primary);
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.5;
  text-align: left;
}

.empty-icon {
  width: 4rem;
  height: 4rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.message {
  margin-bottom: 0;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 1.25rem;
  animation: fadeIn 0.4s ease;
  padding: 1.5rem 0;
  border-bottom: none;
  background-color: transparent !important;
  width: 100%;
  max-width: 850px;
  align-self: center;
}

.message.assistant {
  margin-left: 0;
  padding-left: 2.5rem;
  border-left: 1px solid var(--border-color);
}

.message-avatar {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 600;
  font-size: 0.875rem;
  letter-spacing: 0.05em;
  margin: 0;
  background-color: var(--bg-secondary) !important;
  border: 1px solid var(--border-color);
  text-transform: uppercase;
}

.message.user .message-avatar {
  color: var(--text-primary) !important;
}

.message.assistant .message-avatar {
  background-color: transparent !important;
  border-color: transparent;
  color: var(--accent-color) !important;
}

.message-content {
  flex: 1;
  max-width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow-x: auto; 
  margin-bottom: 0;
  padding-right: 0;
}

.message.assistant .message-content {
  padding-left: 0;
  border-left: none;
  margin-left: 0;
}

/* Основной стиль таблицы */
table {
  width: 100%;            /* Растягиваем на доступную ширину */
  border-collapse: collapse; /* Убираем двойные рамки */
  table-layout: auto;     /* КЛЮЧЕВОЙ МОМЕНТ: ширина колонок зависит от контента */
}

/* Стили ячеек */
th, 
td {
  padding: 8px 12px;      /* Воздух, чтобы текст не прилипал */
  border: 1px solid #ddd; /* Границы для наглядности */
  vertical-align: top;    /* Выравнивание по верху (удобно для длинных текстов) */
  text-align: left;
}

/* Защита от слишком длинных слов (например, URL или код) */
td {
  word-wrap: break-word;  /* Перенос длинных слов */
  overflow-wrap: break-word;
  max-width: 400px;       /* Опционально: не дает одной колонке занять вообще всё место */
}

/* Чтобы заголовки не ломались посередине слова и не были слишком узкими */
th {
  white-space: nowrap;    /* Заголовки в одну строку (если они короткие) */
  background-color: #f4f4f4;
  color: var(--accent-color);
}

.message-bubble {
  padding: 0;
  border-radius: 0;
  background-color: transparent;
  word-wrap: break-word;
  word-break: break-word;
  line-height: 1.75;
  overflow-wrap: break-word;
  max-width: 100%;
  box-sizing: border-box;
  display: block;
  width: 100%;
  min-width: 0;
  font-size: 16px;
  color: var(--text-primary);
}

.message-bubble p {
  margin: 0.5rem 0;
}

.message-bubble p:first-child {
  margin-top: 0;
}

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

/* Стили для кода */
.message-bubble code {
  background-color: rgba(0, 0, 0, 0.1);
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-sm);
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.875em;
  word-break: break-word;
}

[data-theme="dark"] .message-bubble code {
  background-color: rgba(255, 255, 255, 0.1);
}

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

/* Стили для highlight.js */
.message-bubble pre code.hljs {
  display: block;
  overflow-x: auto;
  padding: 1rem;
  background: transparent;
}

.message-bubble pre.hljs {
  background: var(--bg-tertiary);
  padding: 1rem;
  border-radius: var(--radius-md);
  overflow-x: auto;
}

.message.user .message-bubble pre.hljs {
  background: rgba(255, 255, 255, 0.15);
}

.message-bubble pre {
  background-color: var(--bg-tertiary);
  padding: 1rem;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 0.75rem 0;
  border: 1px solid var(--border-color);
  max-width: 100%;
  box-sizing: border-box;
  width: 100%;
}

.message-bubble pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  display: block;
  white-space: pre;
  overflow-x: auto;
  word-break: normal;
  overflow-wrap: normal;
}

.message.user .message-bubble pre {
  background-color: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.2);
}

.message-bubble pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  display: block;
  white-space: pre;
  overflow-x: auto;
}

.message-bubble ul,
.message-bubble ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.message-bubble li {
  margin: 0.25rem 0;
}

/* Стили для математических формул */
.message-bubble .math-formula {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  background-color: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-family: 'Times New Roman', serif;
  font-style: italic;
  margin: 0.25rem 0;
}

.message.user .message-bubble .math-formula {
  background-color: rgba(255, 255, 255, 0.15);
}

.message-bubble .math-block {
  display: block;
  padding: 0.75rem;
  background-color: var(--bg-tertiary);
  border-radius: var(--radius-md);
  text-align: center;
  margin: 0.75rem 0;
  font-family: 'Times New Roman', serif;
  font-style: italic;
  overflow-x: auto;
}

.message.user .message-bubble .math-block {
  background-color: rgba(255, 255, 255, 0.15);
}

.message.user .message-bubble {
  background-color: transparent;
  color: var(--text-primary);
}

.message.assistant .message-bubble.error-message {
  background-color: var(--error-color);
  color: white;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  opacity: 0.9;
}

.message.assistant .message-bubble.error-message:hover {
  opacity: 1;
}

.message.assistant .message-bubble {
  background-color: transparent;
  color: var(--text-primary);
}

.message-image {
  max-width: 100%;
  max-height: 400px;
  border-radius: var(--radius-md);
  margin-top: 0.5rem;
  object-fit: contain;
  display: block;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.message-image:hover {
  transform: scale(1.02);
}

.message-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

.message-actions {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.5rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}

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

.message-action-btn {
  background: none;
  border: none;
  padding: 0.5rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
  cursor: pointer;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.message-action-btn:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  transform: scale(1.1);
}

.message-action-btn:active {
  transform: scale(0.95);
}

.message.user .message-action-btn:hover {
  background-color: rgba(255, 255, 255, 0.2);
  color: white;
}

.message-action-btn .icon {
  width: 1rem;
  height: 1rem;
}

/* Индикатор печати и статусы */
.typing-indicator {
  opacity: 1;
  background-color: var(--assistant-message-bg);
  border-bottom: 1px solid var(--border-color);
}

.typing-bubble {
  padding: 0;
  min-height: 1.5rem;
  display: flex;
  align-items: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
  padding: 0.5rem 0;
}

.status-indicator-text {
  font-weight: 500;
}

.typing-dots {
  display: inline-flex;
  gap: 0.25rem;
  align-items: center;
  margin-left: 0.5rem;
}

.typing-dots span {
  width: 0.35rem;
  height: 0.35rem;
  border-radius: 50%;
  background-color: var(--text-secondary);
  animation: typingDot 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

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

.typing-cursor {
  display: inline-block;
  width: 0.6rem;
  height: 1.2rem;
  background-color: var(--text-primary);
  animation: blink 1s step-end infinite;
  margin-left: 0.25rem;
  vertical-align: text-bottom;
  border-radius: 1px;
}

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

.generative-shimmer {
  background: linear-gradient(90deg, var(--text-primary) 0%, var(--text-secondary) 50%, var(--text-primary) 100%);
  background-size: 200% auto;
  color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
  animation: shimmer 2s linear infinite;
}

.message-input-container {
  padding: 1.5rem 0;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-primary);
}

/* Блок рассуждений (Reasoning) */
.reasoning-block {
  border-left: 2px solid var(--border-color);
  margin: 0.5rem 0 1rem;
  background: var(--bg-secondary);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  overflow: hidden;
  transition: all 0.3s ease;
}
.reasoning-header {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  font-weight: 500;
  user-select: none;
  background: transparent;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.reasoning-header:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}
.reasoning-content {
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 0.5rem 1rem 1rem;
  border-top: 1px solid var(--border-color);
}

/* Переливающийся плейсхолдер при рисовании */
.image-gen-placeholder {
  width: 100%;
  max-width: 280px;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-lg);
  background: linear-gradient(90deg, var(--bg-secondary) 0%, var(--bg-tertiary) 50%, var(--bg-secondary) 100%);
  background-size: 200% 100%;
  animation: shimmerLoader 2s infinite linear;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  margin: 1rem 0;
  border: 1px solid var(--border-color);
}
.image-gen-placeholder svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  opacity: 0.6;
}
.image-gen-placeholder div {
  font-size: 0.9rem;
  font-weight: 500;
}

@keyframes shimmerLoader {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.message-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background-color: var(--bg-primary);
  border: 1px solid var(--text-secondary); /* Thin slate gray */
  border-radius: var(--radius-md); /* Anthropic-like minimal radius */
  padding: 0.75rem 1rem;
  box-shadow: none !important;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  transition: border-color 0.2s ease;
  box-sizing: border-box;
}

.input-wrapper:focus-within {
  border-color: var(--accent-color);
}

.input-wrapper textarea {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  color: var(--text-primary);
  font-size: 1rem;
  resize: none;
  max-height: 200px;
  min-height: 24px;
  padding: 0.625rem 0;
  font-family: inherit;
  line-height: 1.6;
  width: 0;
}

.input-wrapper textarea:focus {
  outline: none;
}

/* Убираем сильную заливку у иконок в поле ввода (скрепка, лупа, язык, кисть и т.д.) */
.input-wrapper button svg,
.input-wrapper .icon {
  fill: none !important;
  stroke: currentColor !important;
  stroke-width: 1.5 !important;
}

.web-search-toggle {
  padding: 0;
  width: 2.75rem;
  height: 2.75rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  border-radius: 50%;
  flex-shrink: 0;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  color: var(--accent-color) !important;
  box-shadow: none !important;
}

.web-search-toggle:hover, 
.web-search-toggle.active {
  background-color: transparent !important;
  color: var(--accent-hover) !important;
  transform: none !important;
}

.web-search-toggle .icon {
  width: 1.125rem;
  height: 1.125rem;
}

.web-search-label {
  display: none !important;
}

@media (max-width: 768px) {
  .web-search-toggle {
    min-width: 2.5rem;
    min-height: 2.5rem;
    width: 2.5rem;
    height: 2.5rem;
  }

  .web-search-toggle .icon {
    width: 1.125rem;
    height: 1.125rem;
  }
}

.send-btn {
  padding: 0;
  width: 2.75rem;
  height: 2.75rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  background: transparent !important;
  color: var(--accent-color) !important;
  border: none !important;
  box-shadow: none !important;
}

.send-btn .icon, .attach-btn .icon {
  width: 1.25rem !important;
  height: 1.25rem !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  color: var(--accent-color) !important;
}

.send-btn:hover, .attach-btn:hover {
  color: var(--accent-hover) !important;
  background: transparent !important;
  transform: none !important;
}

.attach-btn {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0;
  margin-right: 0.25rem;
  background: transparent !important;
  color: var(--accent-color) !important;
  border: none !important;
  box-shadow: none !important;
}

.image-preview {
  position: relative;
  display: inline-block;
  max-width: 200px;
  margin-top: 0.5rem;
}

.image-preview img {
  width: 100%;
  border-radius: var(--radius-md);
}

.remove-image {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background-color: var(--error-color);
  color: white;
  padding: 0.25rem;
}

/* Страница настроек - Redesign */
.settings-layout {
  display: flex;
  height: calc(100vh - 80px);
  background-color: var(--bg-primary);
}

.settings-sidebar {
  width: 280px;
  background-color: var(--bg-secondary);
  border-right: none;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.settings-sidebar-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.settings-sidebar-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
}

.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.settings-nav-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
}

.settings-nav-btn:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

.settings-nav-btn.active {
  background-color: var(--bg-primary);
  box-shadow: var(--shadow-sm);
  color: var(--text-primary);
  font-weight: 600;
}

.settings-content-area {
  flex: 1;
  padding: 2rem 3rem;
  overflow-y: auto;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.settings-section {
  display: none;
  animation: fadeIn 0.3s ease;
}

.settings-section.active {
  display: block;
}

.settings-section h3 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.settings-card {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: none;
}

.usage-display {
  margin-top: 1rem;
  padding: 1.25rem;
  background-color: var(--bg-secondary);
  border-radius: var(--radius-lg);
}

/* Тарифные планы в настройках */
.tariff-plans-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.tariff-plan-card {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  position: relative;
}

.tariff-plan-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent-color);
}

.tariff-plan-card.current-plan {
  border-color: var(--accent-color);
  background-color: var(--accent-light);
}

.plan-header {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.plan-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.plan-description {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 1rem;
  flex: 1;
}

/* Модальное окно */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 1rem;
}

.modal-content {
  background-color: var(--bg-primary);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 500px;
  box-shadow: var(--shadow-xl);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 1.5rem;
  font-weight: 600;
}

.modal-content form {
  padding: 1.5rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* Уведомления */
.notifications {
  position: fixed;
  top: 80px;
  right: 1rem;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 400px;
}

.notification {
  padding: 1rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

.notification.success {
  background-color: var(--success-color);
  color: white;
}

.notification.error {
  background-color: var(--error-color);
  color: white;
}

.notification.info {
  background-color: var(--accent-color);
  color: white;
}


@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* Загрузка */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4000;
}

.spinner {
  width: 3rem;
  height: 3rem;
  border: 4px solid var(--bg-secondary);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Мобильная адаптация */
@media (max-width: 768px) {
  .nav-brand h1 {
    font-size: 1.25rem;
  }

  .navbar {
    padding: 0.875rem 0;
  }

  .chat-layout {
    flex-direction: column;
    height: calc(100vh - 70px);
    height: calc(100dvh - 100px);
  }

  .sidebar {
    position: fixed;
    top: 70px;
    left: 0;
    bottom: 0;
    width: 85vw;
    max-width: 320px;
        min-width: 0;
    z-index: 1500;
        margin-left: 0 !important;
        transform: translateX(-100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-xl);
    border-radius: 0 var(--radius-xl) var(--radius-xl) 0;
  }

  .sidebar:not(.hidden) {
    transform: translateX(0);
  }
      .sidebar.hidden {
        transform: translateX(-100%);
      }

  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 1400;
    transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .sidebar-header-top .icon-btn:not(.sidebar-close-btn),
  .new-chat-btn, .new-chat-fab {
    position: fixed;
    bottom: 6rem;
    right: 1.5rem;
    background-color: var(--bg-secondary) !important;
    color: var(--accent-color) !important;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 3.5rem;
    height: 3.5rem;
    box-shadow: var(--shadow-md) !important;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .chat-main {
    width: 100%;
    margin-left: 0 !important;
  }

  .chat-header {
    padding: 0.75rem 1rem;
    min-height: 60px;
  }

  .conversation-title {
    display: none;
  }

  .message {
    flex-direction: row;
    gap: 0.75rem;
  }

  .message-content {
    max-width: 100%;
    min-width: 0;
    padding-right: 0;
  }

  .message.assistant {
    padding-left: 1.5rem;
    margin-left: 0;
  }

  .message-avatar {
    margin: 0;
  }

  .message-image {
    max-height: 300px;
  }

  .auth-card {
    padding: 2rem 1.5rem;
    border-radius: var(--radius-xl);
  }

  .settings-layout {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 80px);
  }
  .settings-sidebar {
    width: 100%;
    padding: 1rem;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
  }
  .settings-sidebar-header {
    margin-bottom: 1rem;
  }
  .settings-nav {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    -webkit-overflow-scrolling: touch;
  }
  .settings-nav-btn {
    white-space: nowrap;
    padding: 0.625rem 1rem;
  }
  .settings-content-area {
    padding: 1.5rem 1rem;
  }

  .modal-content {
    margin: 1rem;
    border-radius: var(--radius-xl);
  }

  .example-suggestions {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .empty-state {
    padding: 1.5rem;
  }

  .empty-state-title {
    font-size: 1.375rem;
    margin-bottom: 1.5rem;
  }

  .message-input-container {
    padding: 1.25rem 1rem;
  }

  .input-wrapper {
    padding: 0.375rem 0.375rem 0.375rem 1rem;
    width: 100%;
    max-width: 100%;
    margin: 0;
    flex-wrap: wrap;
    align-items: center;
  }

  .input-wrapper textarea {
    flex: 1 1 100%;
    min-width: 100%;
    width: 100%;
    order: -1;
    padding: 0.25rem 0.25rem 0.5rem 0.25rem;
  }

  .btn {
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
  }

  .icon-btn {
    min-width: 3rem;
    min-height: 3rem;
    padding: 0.75rem;
  }
}

@media (max-width: 480px) {
  .nav-container {
    padding: 0 0.75rem;
    gap: 0.375rem;
  }

  .nav-brand h1 {
    font-size: 1.125rem;
    max-width: 180px;
  }

  .beta-badge {
    font-size: 0.5625rem;
    padding: 0.125rem 0.25rem;
  }

  .nav-actions {
    gap: 0.25rem;
  }

  .navbar {
    padding: 0.75rem 0;
  }

  .messages-container {
    padding: 0 1rem;
  }

  .message {
    padding: 1rem 0;
  }

  .message-content {
    max-width: 100%;
    padding-right: 0;
  }

  .message-avatar {
    margin: 0;
    width: 1.75rem;
    height: 1.75rem;
    font-size: 0.75rem;
  }

  .message-input-container {
    padding: 0.75rem;
    background: transparent;
    overflow: visible;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px)) !important;
  }

  .input-wrapper {
    padding: 0.5rem;
    gap: 0.25rem;
    width: 100%;
    max-width: 100%;
    margin: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: none !important;
    background-color: var(--bg-primary);
    overflow: visible;
    box-sizing: border-box;
    flex-wrap: wrap;
    align-items: center;
  }

  .input-wrapper:focus-within {
    border-color: var(--border-color);
    box-shadow: none;
  }

  .input-wrapper textarea {
    flex: 1 1 100%;
    width: 100%;
    min-width: 100%;
    overflow: hidden;
    order: -1;
    padding: 0.25rem 0.25rem 0.5rem 0.5rem;
  }

  .web-search-toggle, .attach-btn, .send-btn {
    width: 2.25rem !important;
    height: 2.25rem !important;
    min-width: 2.25rem !important;
    min-height: 2.25rem !important;
    border-radius: 50% !important;
    flex-shrink: 0;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .send-btn {
    margin-left: auto;
  }

  .send-btn .icon {
    width: 1.125rem !important;
    height: 1.125rem !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    color: var(--accent-color) !important;
  }

  .attach-btn { margin-right: 0; }

  .web-search-toggle {
    flex-shrink: 0;
  }

  .chat-header {
    padding: 0.5rem 0.75rem;
    flex-wrap: nowrap;
    gap: 0.5rem;
  }

  .chat-title-area {
    flex: 1;
    min-width: 0;
  }

  .custom-select-trigger {
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
  }

  .sidebar {
    width: 90vw;
    max-width: 90vw;
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  }

  .sidebar-header {
    padding: 0.875rem;
  }

  .conversations-list {
    padding: 0.5rem 0.375rem;
  }

  .conversation-item {
    padding: 0.875rem 0.75rem;
    margin-bottom: 0.375rem;
  }

  .conversation-item-title {
    font-size: 0.875rem;
    line-height: 1.4;
  }

  .conversation-item-meta {
    font-size: 0.6875rem;
    margin-top: 0.25rem;
  }

  .example-item {
    padding: 1rem;
    gap: 0.75rem;
  }

  .example-item span {
    font-size: 0.875rem;
  }

  .auth-card {
    padding: 1.5rem 1.25rem;
    margin: 0.5rem;
  }

  .btn {
    padding: 0.875rem 1.25rem;
    font-size: 0.9375rem;
  }

  .icon-btn {
    min-width: 2.5rem;
    min-height: 2.5rem;
    padding: 0.5rem;
  }

  .empty-state-title {
    font-size: 1.25rem;
  }

  .message-bubble {
    font-size: 0.9375rem;
    line-height: 1.7;
  }

  .message-bubble pre {
    font-size: 0.8125rem;
    padding: 0.875rem;
  }

  .usage-info {
    font-size: 0.75rem;
    padding: 0.375rem 0.625rem;
    white-space: nowrap;
  }
}

/* Поддержка safe-area для iPhone */
@supports (padding: max(0px)) {
  .message-input-container {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  .navbar {
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  .sidebar {
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

/* Скроллбар */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* Плавный скролл */
html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Баннер лимита */
.limit-banner {
  background-color: var(--warning-color);
  color: #1f2937; /* Темный текст для контраста на желтом/оранжевом фоне */
  padding: 0.75rem 1.25rem;
  display: none; /* По умолчанию скрыт */
  justify-content: center;
  align-items: center;
  width: auto;
  max-width: calc(100vw - 2rem);
  position: fixed;
  top: 5.5rem;
  right: 1rem;
  left: auto;
  border-radius: var(--radius-md);
  z-index: 3000;
  box-shadow: var(--shadow-lg);
  animation: slideInBanner 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideInBanner {
  from { transform: translateX(120%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.limit-banner-content {
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: 1400px;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

.limit-banner span {
  font-weight: 600;
  font-size: 0.9375rem;
}

.limit-banner .btn {
  padding: 0.375rem 1rem;
  font-size: 0.875rem;
  background-color: rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: inherit;
  white-space: nowrap;
  min-height: auto;
}

.limit-banner .btn:hover {
  background-color: rgba(0, 0, 0, 0.2);
  transform: none;
  box-shadow: none;
}

/* Баннер установки PWA */
.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 2000;
  background-color: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  padding: 1rem;
  animation: slideUp 0.3s ease;
}

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

.install-banner-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.install-banner-info {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
}

.install-banner-icon {
  width: 2rem;
  height: 2rem;
  color: var(--accent-color);
  flex-shrink: 0;
}

.install-banner-title {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.install-banner-text {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin: 0;
}

.install-banner-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

@media (max-width: 768px) {
  .install-banner-content {
    flex-direction: column;
    align-items: flex-start;
  }

  .install-banner-info {
    width: 100%;
  }

  .install-banner-actions {
    width: 100%;
    justify-content: space-between;
  }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background-color: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  border: 1px solid var(--border-color);
  box-shadow: none;
  text-align: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent-color);
  margin-bottom: 0.5rem;
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.codes-list,
.users-list,
.tariff-plans-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

.code-item,
.user-item,
.tariff-plan-item {
  background-color: var(--bg-primary);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border-color);
  box-shadow: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.code-item:hover,
.user-item:hover,
.tariff-plan-item:hover {
  border-color: var(--accent-color);
  box-shadow: var(--shadow-sm);
}

.code-info,
.user-info,
.tariff-plan-info {
  flex: 1;
}

.code-value {
  font-family: monospace;
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--accent-color);
}

.code-meta,
.user-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.code-status {
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
}

.status-active {
  background-color: var(--success-color);
  color: white;
}

.status-used {
  background-color: var(--text-secondary);
  color: white;
}

.status-expired {
  background-color: var(--warning-color);
  color: white;
}

.status-inactive {
  background-color: var(--error-color);
  color: white;
}

.code-actions,
.user-actions,
.tariff-plan-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.user-name {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.user-email {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

.tariff-plan-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.tariff-plan-name {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.badge-default {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-sm);
  background-color: var(--accent-color);
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  margin-left: 0.5rem;
}

.tariff-plan-description {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.tariff-plan-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.tariff-plan-models {
  margin-top: 0.5rem;
}

.tariff-plan-models strong {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.875rem;
}

.tariff-plan-models .models-list {
  font-size: 0.875rem;
  color: var(--text-secondary);
  word-break: break-word;
}

.tariff-plan-models-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  padding: 0.75rem;
  background-color: var(--bg-secondary);
  border-radius: var(--radius-md);
  min-height: 3rem;
}

.tariff-plan-model-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem;
  background-color: var(--bg-primary);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.pagination {
  margin-top: 1rem;
}

.pagination-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
}

/* Прогресс-бары для лимитов */
.limit-progress-wrapper {
  width: 100%;
  height: 8px;
  background-color: var(--bg-tertiary);
  border-radius: var(--radius-xl);
  overflow: hidden;
  margin-top: 0.5rem;
}

.limit-progress-fill {
  height: 100%;
  background-color: var(--accent-color);
  border-radius: var(--radius-xl);
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.limit-progress-fill.warning { background-color: var(--warning-color); }
.limit-progress-fill.danger { background-color: var(--error-color); }

@media (max-width: 768px) {
  .admin-container {
    padding: 1rem;
  }

  .admin-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .code-item,
  .user-item,
  .tariff-plan-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .code-actions,
  .user-actions,
  .tariff-plan-actions {
    width: 100%;
    flex-direction: column;
  }

  .code-actions .btn,
  .user-actions .btn {
    width: 100%;
  }
}

/* Модальное окно просмотра изображений */
.image-viewer-modal {
  display: none;
  position: fixed;
  z-index: 5000;
  padding-top: 0;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: rgba(0, 0, 0, 0.9);
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.image-viewer-content {
  margin: auto;
  display: block;
  max-width: 90%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

.image-viewer-close {
  position: absolute;
  top: 20px;
  right: 35px;
  color: #f1f1f1;
  font-size: 40px;
  font-weight: bold;
  transition: 0.3s;
  cursor: pointer;
  z-index: 5001;
}

.image-viewer-close:hover,
.image-viewer-close:focus {
  color: #bbb;
  text-decoration: none;
  cursor: pointer;
}

.download-btn {
  margin-top: 20px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  z-index: 5001;
  background-color: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.download-btn:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

/* Выделение текста */
::selection {
  background-color: var(--accent-color);
  color: white;
}

/* API Key Management */
.create-key-form {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
}

.create-key-form .form-group {
  flex-grow: 1;
}

.generated-key-container {
  margin-top: 1rem;
  padding: 1rem;
  background-color: var(--bg-primary);
  border-radius: var(--radius-md);
  border: 1px solid var(--accent-color);
}

.generated-key {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.generated-key input {
  flex-grow: 1;
  background-color: var(--bg-secondary);
  font-family: monospace;
}

.api-keys-list ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.api-keys-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background-color: var(--bg-primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.key-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.key-name {
  font-weight: 600;
}

.key-partial {
  font-family: monospace;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.delete-key-btn {
  background-color: var(--error-color);
  color: white;
}
