/* ==========================================================================
   1. ПЕРЕМЕННЫЕ ЦВЕТОВОЙ ПАЛИТРЫ (Светлая и Темная темы)
   ========================================================================== */
:root {
  /* Основные цвета */
  --primary-color: #3390ec;
  --primary-hover: #297bc9;
  --purple-color: #8c52ff;
  --purple-hover: #733dec;

  /* Светлая тема */
  --bg-color: #f4f4f5;
  --surface-color: #ffffff;
  --chat-bg: #e4eaf0;
  --text-primary: #000000;
  --text-secondary: #707579;
  --border-color: #e0e0e0;
  --message-out: #eeffde;
  --message-in: #ffffff;
  --badge-bg: var(--purple-color);
  --badge-text: #ffffff;
  --shadow-color: rgba(0, 0, 0, 0.08);

  /* Цвета неба (День) */
  --sky-gradient: linear-gradient(180deg, #6ec6ff 0%, #b3e5fc 60%, #e1f5fe 100%);
  --cloud-opacity: 0.95;
  --cloud-color: #ffffff;
}

body.dark-theme {
  /* Темная тема */
  --bg-color: #1c1d22;
  --surface-color: #24252b;
  --chat-bg: #0f1013;
  --text-primary: #ffffff;
  --text-secondary: #9aa0a6;
  --border-color: #34363f;
  --message-out: #2b5278;
  --message-in: #2a2b31;
  --shadow-color: rgba(0, 0, 0, 0.35);

  /* Цвета неба (Ночь) */
  --sky-gradient: linear-gradient(180deg, #090a10 0%, #141726 60%, #1d2136 100%);
  --cloud-opacity: 0.25;
  --cloud-color: #444b6e;
}

/* ==========================================================================
   2. БАЗОВЫЕ СТИЛИ
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  transition: background-color 0.4s ease, color 0.4s ease;
}

.hidden {
  display: none !important;
}

svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

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

input {
  font-family: inherit;
  color: var(--text-primary);
}

.screen {
  height: 100%;
  width: 100%;
  position: relative;
}

/* ==========================================================================
   4. ЭКРАН АВТОРИЗАЦИИ
   ========================================================================== */

.auth-header img,
.logo-icon-image {
  width: 96px !important; /* Увеличено на 50% */
  height: 96px !important;
  object-fit: contain;
  margin: 0 auto 12px auto;
  display: block;
}

.auth-title {
  text-align: center; /* Центрируем */
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 20px;
}

.auth-card {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 400px;
  padding: 40px 32px;
  border-radius: 24px;
  
  /* Эффект Liquid Glass (Светлая тема) */
  background: rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.1);
  transition: all 0.4s ease;
}

body.dark-theme .auth-card {
  /* Эффект Liquid Glass (Темная тема) */
  background: rgba(36, 37, 43, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
}

.input-wrapper {
  position: relative;
  width: 100%;
}

#auth-form input {
  width: 100%;
  padding: 14px 16px;
  margin-bottom: 14px;
  border: 1px solid var(--border-color);
  background: var(--surface-color);
  border-radius: 12px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px; /* Отделяем кнопки друг от друга */
  margin-top: 12px;
}

/* Стили для кнопок Войти и Регистрация */
.auth-buttons button {
  width: 100%;
  padding: 14px 28px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.2s, transform 0.2s;
}

#btn-login {
  background: var(--purple-color);
  color: #ffffff;
}

#btn-login:hover {
  background: var(--purple-hover);
}

#btn-register {
  background: transparent;
  color: var(--text-primary);
  border: 2px solid var(--purple-color);
  margin-top: 4px;
}

#btn-register:hover {
  background: rgba(140, 82, 255, 0.1);
}

/* Переключатель темы (В правом нижнем углу) */
.auth-theme-switch {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 100;
}

.btn-theme-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  box-shadow: 0 8px 20px var(--shadow-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: transform 0.2s, box-shadow 0.2s;
}
.btn-theme-icon:hover { transform: scale(1.08); }


/* === ДИАЛОГОВОЕ ОБЛАКО (Тултип логина) === */
.thought-bubble {
  position: absolute;
  bottom: calc(100% + 25px);
  left: -20px;
  background: var(--surface-color);
  border-radius: 20px 20px 20px 8px; /* Форма облака-диалога */
  padding: 14px 18px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-primary);
  width: 260px;
  box-shadow: 0 8px 24px var(--shadow-color);
  border: 2px solid var(--border-color);
  z-index: 20;
  
  /* Анимация появления */
  opacity: 0;
  transform: translateY(15px) scale(0.9);
  pointer-events: none;
  transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.thought-bubble.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Кружочки облака (хвостик) */
.bubble-circle-1, .bubble-circle-2 {
  position: absolute;
  background: var(--surface-color);
  border: 2px solid var(--border-color);
  border-radius: 50%;
}
.bubble-circle-1 {
  width: 14px; height: 14px;
  bottom: -18px; left: 24px;
}
.bubble-circle-2 {
  width: 8px; height: 8px;
  bottom: -32px; left: 16px;
}

/* Скрываем бордеры пересечения кружков (имитация вылетания из инпута) */
.bubble-circle-1::after {
  content: ''; position: absolute;
  top: -4px; left: -2px; width: 16px; height: 8px;
  background: var(--surface-color);
}

/* ==========================================================================
   5. ОСНОВНОЙ ИНТЕРФЕЙС ПРИЛОЖЕНИЯ
   ========================================================================== */
#app-screen {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
  background: var(--bg-color);
  z-index: 10;
}

/* ЛЕВАЯ ПАНЕЛЬ (Сайдбар) */
.layout-sidebar {
  width: 100%;
  height: 100%;
  background: var(--surface-color);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-color);
  position: relative;
  z-index: 15;
  transition: background-color 0.3s;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  height: 60px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-color);
  position: relative;
}

.sidebar-header h3 {
  font-size: 20px;
  font-weight: 700;
}

.header-actions {
  position: relative;
}

/* Кнопка смены темы в шапке (заменяет нерабочие "три точки") */
.theme-toggle-btn {
  width: 40px;
  height: 40px;
  position: relative;
}

.theme-toggle-btn .theme-icon-sun,
.theme-toggle-btn .theme-icon-moon {
  position: absolute;
  top: 50%;
  left: 50%;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

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

/* ПОИСК С ВОЛНОВОЙ АНИМАЦИЕЙ */
.search-bar-container {
  padding: 10px 16px;
  position: relative;
  overflow: hidden;
  /* Убрали border-bottom: вместе с border-bottom у .sidebar-header
     это давало эффект "двойной полоски". Теперь единственная граница —
     у заголовка сверху. */
}

/* Скрываем строку поиска целиком во вкладках "Настройки" и "Профиль" —
   там она не нужна. Работает через :has(), поэтому не требует JS. */
#sidebar-screen:has(#view-settings:not(.hidden)) #search-container,
#sidebar-screen:has(#view-profile:not(.hidden)) #search-container {
  display: none;
}

.search-wave {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  background: radial-gradient(circle, rgba(140, 82, 255, 0.35) 0%, rgba(140, 82, 255, 0.14) 55%, rgba(140, 82, 255, 0) 100%);
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.5s ease;
  z-index: 0;
}

/* Класс wave-active навешивается через JS по фокусу/клику на поиск —
   волна расходится из центра строки поиска во все стороны */
.search-bar-container.wave-active .search-wave {
  transform: translate(-50%, -50%) scale(38);
  opacity: 1;
}

.search-bar {
  position: relative;
  z-index: 1;
}

.search-bar input {
  width: 100%;
  padding: 10px 16px;
  border: 1px solid transparent;
  background: var(--bg-color);
  border-radius: 20px;
  outline: none;
  font-size: 14px;
  transition: all 0.2s;
}

.search-bar input:focus {
  background: var(--surface-color);
  border-color: var(--purple-color);
  box-shadow: 0 0 0 3px rgba(140, 82, 255, 0.15);
}

/* ОБЛАСТЬ КОНТЕНТА САЙДБАРА */
.sidebar-content-area {
  flex: 1;
  overflow-y: auto;
  position: relative;
}

.sidebar-view {
  width: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* СПИСОК ЧАТОВ И ПОИСКА */
.chat-list {
  list-style: none;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.chat-item:hover {
  background: var(--bg-color);
}

.chat-item-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-color), var(--purple-color));
  margin-right: 14px;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}

.chat-item-info {
  flex: 1;
  min-width: 0;
}

.chat-item-name {
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.chat-item-preview {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Фиолетовый кружок с количеством непрочитанных */
.unread-badge {
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 12px;
  font-weight: 700;
  height: 20px;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 10px;
  flex-shrink: 0;
}

.empty-msg-list, .search-placeholder {
  text-align: center;
  color: var(--text-secondary);
  font-size: 15px;
  padding: 40px 20px;
  margin: auto;
}

/* ПРОФИЛЬ ПОЛЬЗОВАТЕЛЯ (В сайдбаре) */
.profile-header-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 30px 20px;
  gap: 16px;
}

.profile-avatar-wrapper {
  position: relative;
  width: 120px;
  height: 120px;
}

.profile-avatar-circle {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--purple-color);
  background: var(--bg-color);
  background-size: cover;
  background-position: center;
  cursor: pointer;
  transition: transform 0.2s;
}

.profile-avatar-circle:hover {
  transform: scale(1.03);
}

.avatar-upload-btn {
  position: absolute;
  bottom: 0;
  right: 0;
  background: var(--purple-color);
  color: #ffffff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid var(--surface-color);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--shadow-color);
  transition: background 0.2s, transform 0.2s;
}

.avatar-upload-btn:hover {
  background: var(--purple-hover);
  transform: scale(1.08);
}

.profile-name-edit {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 260px;
  position: relative;
}

.profile-name-edit input {
  width: 100%;
  padding: 10px 36px 10px 14px;
  border: 1px solid transparent;
  background: var(--bg-color);
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  outline: none;
  transition: all 0.2s;
}

.profile-name-edit input:focus {
  border-color: var(--purple-color);
  background: var(--surface-color);
}

.check-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
}

/* Фиолетовый бейдж @username под отображаемым именем в профиле */
.profile-username-badge {
  background: rgba(140, 82, 255, 0.14);
  color: var(--purple-color);
  font-size: 14px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 20px;
  letter-spacing: 0.2px;
  user-select: text;
}

/* НАСТРОЙКИ (В сайдбаре) */
.settings-list {
  list-style: none;
  padding: 10px 0;
}

.settings-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  transition: background 0.15s;
}

.settings-item:hover {
  background: var(--bg-color);
}

.settings-icon {
  color: var(--purple-color);
}

/* Строка настройки с переключателем (например, "Крупный текст") */
.settings-item-toggle {
  cursor: default;
}

/* Тумблер вкл/выкл */
.switch-toggle {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  margin-left: auto;
  flex-shrink: 0;
}

.switch-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: var(--border-color);
  border-radius: 34px;
  transition: background 0.3s ease;
}

.switch-slider::before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.switch-toggle input:checked + .switch-slider {
  background: var(--purple-color);
}

.switch-toggle input:checked + .switch-slider::before {
  transform: translateX(20px);
}

.switch-toggle input:focus-visible + .switch-slider {
  box-shadow: 0 0 0 3px rgba(140, 82, 255, 0.25);
}

/* Режим "Крупный текст" — включается добавлением класса на <body> */
body.large-text-mode {
  font-size: 17px;
}

body.large-text-mode .chat-item-name,
body.large-text-mode .chat-title,
body.large-text-mode .sidebar-header h3,
body.large-text-mode .message,
body.large-text-mode #message-input,
body.large-text-mode .settings-item span,
body.large-text-mode .empty-state-text {
  font-size: 1.15em;
}

body.large-text-mode .chat-item-preview,
body.large-text-mode .message-time,
body.large-text-mode .chat-subtitle {
  font-size: 1.08em;
}

.settings-footer {
  margin-top: auto;
  padding: 20px;
  border-top: 1px solid var(--border-color);
}

.logout-btn {
  width: 100%;
  padding: 14px;
  background: rgba(255, 59, 48, 0.1);
  color: #ff3b30;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.logout-btn:hover {
  background: rgba(255, 59, 48, 0.18);
}

/* ==========================================================================
   6. НИЖНЯЯ ПАНЕЛЬ С КНОПКАМИ (Чаты, Настройки, Профиль)
   ========================================================================== */
.bottom-nav {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 64px;
  background: var(--surface-color);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 20;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s;
  padding: 6px 0;
}

.nav-btn.active {
  color: var(--purple-color);
}

.nav-btn span {
  font-size: 11px;
  font-weight: 600;
}

.nav-avatar-mini {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--border-color);
  background-size: cover;
  background-position: center;
  border: 1.5px solid currentColor;
}

/* ==========================================================================
   7. ПРАВАЯ ПАНЕЛЬ (Окно чата и Пустое состояние)
   ========================================================================== */
.layout-main {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  position: relative;
  overflow: hidden;
}

/* ПУСТОЕ СОСТОЯНИЕ (Только на ПК) */
.empty-state-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 16px;
  text-align: center;
  padding: 20px;
}

.logo-icon-large {
  width: 240px; /* увеличено на 250% от исходных 96px */
  height: 240px;
  object-fit: contain;
  opacity: 0.85;
  border-radius: 55px;
}

.empty-state-text {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* АКТИВНЫЙ ЧАТ */
.active-chat-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

.chat-header {
  height: 60px;
  background: var(--surface-color);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-color);
  z-index: 10;
}

.back-btn {
  margin-right: 12px;
}

.chat-info {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--purple-color);
  background-size: cover;
  background-position: center;
  position: relative;
}

/* Индикатор "в сети" */
.online-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 12px;
  height: 12px;
  background: #4caf50;
  border: 2px solid var(--surface-color);
  border-radius: 50%;
}

.chat-title {
  font-weight: 700;
  font-size: 16px;
}

/* СПИСОК СООБЩЕНИЙ */
.messages-container {
  flex: 1;
  padding: 20px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-msg-bottom {
  text-align: center;
  color: var(--text-secondary);
  font-size: 15px;
  margin-top: auto;
  margin-bottom: 20px;
}

.message {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.45;
  position: relative;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.message.in {
  align-self: flex-start;
  background: var(--message-in);
  border-bottom-left-radius: 4px;
}

.message.out {
  align-self: flex-end;
  background: var(--message-out);
  border-bottom-right-radius: 4px;
}

/* Время и Галочки прочтения */
.message-meta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  float: right;
  margin: 6px 0 -4px 12px;
}

.message-time {
  font-size: 11px;
  color: var(--text-secondary);
}

.message-status {
  display: inline-flex;
  align-items: center;
  color: #4caf50; /* Зеленый цвет для галочек */
}

.message-status svg {
  width: 16px;
  height: 16px;
}

/* ПАНЕЛЬ ОТВЕТА НА СООБЩЕНИЕ (Reply/Quote) */
.reply-preview-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface-color);
  border-top: 1px solid var(--border-color);
  animation: replySlideIn 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

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

.reply-preview-line {
  width: 3px;
  align-self: stretch;
  min-height: 32px;
  border-radius: 3px;
  background: var(--purple-color);
  flex-shrink: 0;
}

.reply-preview-content {
  flex: 1;
  min-width: 0;
}

.reply-preview-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--purple-color);
  margin-bottom: 2px;
}

.reply-preview-text {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-cancel-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
}

.reply-cancel-btn svg {
  width: 18px;
  height: 18px;
}

/* ПАНЕЛЬ ВВОДА СООБЩЕНИЯ */
.message-input-area {
  background: var(--surface-color);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--border-color);
}

#message-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 12px 16px;
  font-size: 15px;
  background: var(--bg-color);
  border-radius: 22px;
  min-height: 44px;
}

.send-btn {
  color: var(--purple-color);
}

/* ==========================================================================
   8. МОДАЛЬНЫЕ ОКНА (Профиль, Просмотр аватарки, Кадрирование)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-box {
  background: var(--surface-color);
  width: 90%;
  max-width: 400px;
  border-radius: 24px;
  padding: 30px 24px;
  position: relative;
  box-shadow: 0 20px 40px rgba(0,0,0,0.4);
  text-align: center;
}

.close-btn-corner {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(0,0,0,0.1);
  border: none;
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.close-btn-corner:hover {
  background: rgba(0,0,0,0.2);
}

/* 1. Модалка профиля собеседника */
.modal-content-profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.modal-avatar-large {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  border: 4px solid var(--purple-color);
  background-size: cover;
  background-position: center;
  margin-bottom: 8px;
}

#modal-profile-name {
  font-size: 22px;
  font-weight: 700;
}

#modal-profile-username {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.btn-purple-rounded {
  background: var(--purple-color);
  color: #ffffff;
  border: none;
  padding: 14px 28px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  width: 100%;
}

.btn-purple-rounded:hover {
  background: var(--purple-hover);
}

/* 2. Полноразмерный просмотр аватарки (Квадрат + крестик справа вверху) */
.modal-full-image {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.full-avatar-wrapper {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

#full-avatar-img {
  display: block;
  max-width: 85vw;
  max-height: 85vh;
  object-fit: contain;
  aspect-ratio: 1 / 1;
}

/* Крестик справа от верхнего правого угла аватарки */
.modal-full-image .close-btn-corner {
  top: -15px;
  right: -50px;
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

/* 3. Окно кадрирования аватарки (Квадратная рамка + круглая маска внутри) */
.crop-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
}

.crop-container {
  position: relative;
  width: 280px;
  height: 280px;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  background: #000000;
  border-radius: 16px;
  overflow: hidden;
  margin: 0 auto 20px auto;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Квадратная рамка кадрирования: Cropper.js рисует свой квадратный
     view-box поверх #crop-image-target внутри этого квадрата,
     а .crop-circle-overlay поверх — накладывает круглую маску-превью,
     чтобы было видно, как аватар будет выглядеть на сайте. */
}

#crop-image-target {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

/* Круглая маска, показывающая, как аватарка будет выглядеть для всех */
.crop-circle-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 240px;
  height: 240px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.65);
  border: 2px solid #ffffff;
  pointer-events: none;
}

.modal-footer-right {
  display: flex;
  justify-content: flex-end;
}

.modal-footer-right .btn-purple-rounded {
  width: auto;
  padding: 12px 32px;
}

/* ==========================================================================
   9. АДАПТИВНОСТЬ (DESKTOP & MOBILE)
   ========================================================================== */

/* ПК и планшеты (Ширина от 768px) */
@media (min-width: 768px) {
  .layout-sidebar {
    width: 340px;
    flex-shrink: 0;
  }

  .layout-main {
    flex: 1;
  }

  .back-btn {
    display: none;
  }

  .hidden-mobile {
    display: flex !important;
  }
}

/* Смартфоны (Ширина до 767px) */
@media (max-width: 767px) {
  .layout-sidebar {
    width: 100%;
  }

  .hidden-mobile {
    display: none;
  }

  /* Полноэкранный чат на мобильном устройстве */
  .layout-main.active {
    display: flex;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 50;
    background: var(--chat-bg);
  }

  .empty-state-main {
    display: none !important;
  }

  .modal-full-image .close-btn-corner {
    top: 10px;
    right: 10px;
  }
}

/* ==========================================
   АТМОСФЕРНЫЙ ЭКРАН ВХОДА (ДЕНЬ / НОЧЬ)
========================================== */
.auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: background 1s ease;
}

/* Фон дня и ночи (чистые цвета как на референсе) */
body.light-theme .auth-screen {
  background: #7bd3f7; /* Голубое мультяшное небо */
}

body.dark-theme .auth-screen {
  background: linear-gradient(180deg, #091024 0%, #15224a 65%, #1e3368 100%);
}

/* ==========================================
   ЗВЕЗДНОЕ НЕБО (+50% звезд)
========================================== */
.night-stars {
  position: absolute;
  inset: 0;
  /* Увеличенная плотность звезд */
  background-image: 
    radial-gradient(2px 2px at 15% 25%, #ffffff 100%, transparent),
    radial-gradient(3px 3px at 75% 15%, #ffffff 100%, transparent),
    radial-gradient(2px 2px at 85% 45%, #ffffff 80%, transparent),
    radial-gradient(1px 1px at 30% 60%, #ffffff 100%, transparent),
    radial-gradient(2px 2px at 50% 10%, #ffffff 90%, transparent),
    radial-gradient(1px 1px at 10% 80%, #ffffff 100%, transparent),
    radial-gradient(2.5px 2.5px at 90% 80%, #ffffff 100%, transparent),
    radial-gradient(1.5px 1.5px at 60% 70%, #ffffff 100%, transparent),
    /* Новые звезды */
    radial-gradient(1.5px 1.5px at 20% 45%, #ffffff 90%, transparent),
    radial-gradient(2px 2px at 45% 85%, #ffffff 80%, transparent),
    radial-gradient(1px 1px at 80% 25%, #ffffff 100%, transparent),
    radial-gradient(2.5px 2.5px at 35% 15%, #ffffff 85%, transparent);
  opacity: 0;
  transition: opacity 1.2s ease;
  z-index: 0;
}
body.dark-theme .night-stars { opacity: 1; }

/* ==========================================
   НЕБЕСНЫЕ СВЕТИЛА (Подняты выше)
========================================== */
.celestial-container {
  position: absolute;
  top: 50%;
  left: 50%;
  /* Подняли еще чуть выше */
  transform: translate(-50%, -370px); 
  width: 120px;
  height: 120px;
  z-index: 1;
  pointer-events: none;
}

/* --- СОЛНЦЕ --- */
.sun-wrapper {
  position: absolute;
  width: 100px;
  height: 100px;
  top: 10px;
  left: 10px;
  transform: translate(0, 0); /* Солнце статично */
  opacity: 1;
  transition: transform 1s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.8s ease;
}

body.dark-theme .sun-wrapper {
  transform: translate(300px, 150px); /* Улетает без вращения */
  opacity: 0;
}

.sun-disc {
  position: absolute;
  inset: 0;
  background: #ffdf73;
  border-radius: 50%;
  z-index: 2;
  /* Свечение солнца */
  box-shadow: 0 0 50px 15px rgba(255, 223, 115, 0.7);
}

.sun-rays {
  position: absolute;
  inset: -30px;
  z-index: 1;
  animation: spinCCW 20s linear infinite; /* Вращение лучей */
}

/* Отделенные от солнца лучи */
.ray-line {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 180px;
  height: 6px;
  /* Прозрачность в центре создает визуальный отрыв лучей от солнца */
  background: linear-gradient(90deg, #ffdf73 0%, #ffdf73 18%, transparent 18%, transparent 82%, #ffdf73 82%, #ffdf73 100%);
  transform: translate(-50%, -50%);
  border-radius: 6px;
  /* Легкое свечение самим лучам */
  filter: drop-shadow(0 0 8px rgba(255, 223, 115, 0.8));
}
.ray-line:nth-child(2) { transform: translate(-50%, -50%) rotate(45deg); }
.ray-line:nth-child(3) { transform: translate(-50%, -50%) rotate(90deg); }
.ray-line:nth-child(4) { transform: translate(-50%, -50%) rotate(135deg); }

@keyframes spinCCW { 100% { transform: rotate(-360deg); } }

/* --- ЛУНА --- */
.moon-crescent {
  position: absolute;
  width: 90px;
  height: 90px;
  top: 15px;
  left: 15px;
  border-radius: 50%;
  background: transparent;
  box-shadow: -18px 12px 0 0 #fff; 
  transform: translate(-300px, 150px) rotate(-45deg);
  opacity: 0;
  transition: transform 1s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.8s ease;
}

body.dark-theme .moon-crescent {
  transform: translate(12px, -8px) rotate(0);
  opacity: 1;
}

/* ==========================================
   МУЛЬТЯШНЫЕ ВЕКТОРНЫЕ ОБЛАКА
========================================== */
.cartoon-cloud {
  position: absolute;
  background: #ffffff;
  border-radius: 50px;
  transition: background 1s ease, opacity 1s ease, transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  cursor: default; /* Делаем интерактивными */
  pointer-events: auto; /* Включаем кликабельность */
}

/* Класс для анимации "лопания" */
.cartoon-cloud.popping {
  transform: scale(0) !important;
  opacity: 0 !important;
  pointer-events: none;
}

body.dark-theme .cartoon-cloud {
  background: #1c2d5a;
  opacity: 0.6;
}

.cartoon-cloud::before,
.cartoon-cloud::after {
  content: '';
  position: absolute;
  background: inherit;
  border-radius: 50%;
}

/* Анимация метаморфозы облаков (бугорки "переливаются") */
@keyframes morph-cw {
  0%   { border-radius: 50%; transform: scale(1) translate(0, 0); }
  33%  { border-radius: 60% 40% 50% 50%; transform: scale(1.05) translate(3px, -2px); }
  66%  { border-radius: 40% 60% 55% 45%; transform: scale(0.95) translate(-2px, 3px); }
  100% { border-radius: 50%; transform: scale(1) translate(0, 0); }
}

@keyframes morph-ccw {
  0%   { border-radius: 50%; transform: scale(1) translate(0, 0); }
  33%  { border-radius: 45% 55% 40% 60%; transform: scale(0.95) translate(-3px, -2px); }
  66%  { border-radius: 55% 45% 60% 40%; transform: scale(1.05) translate(2px, 3px); }
  100% { border-radius: 50%; transform: scale(1) translate(0, 0); }
}

/* Применяем анимацию "переливания" только к верхним бугоркам. Нижняя база (сам .cartoon-cloud) остается статично-ровной */
.cartoon-cloud::before { animation: morph-cw 8s ease-in-out infinite; }
.cartoon-cloud::after { animation: morph-ccw 10s ease-in-out infinite; }


/* Базовые позиции и размеры */
.cloud-1 { top: 20%; left: 15%; width: 160px; height: 50px; --base-scale: 1; transform: scale(var(--base-scale)); }
.cloud-1::before { width: 70px; height: 70px; top: -30px; left: 20px; }
.cloud-1::after { width: 90px; height: 90px; top: -45px; right: 25px; }

.cloud-2 { top: 15%; right: 10%; width: 200px; height: 60px; --base-scale: 0.8; transform: scale(var(--base-scale)); }
.cloud-2::before { width: 80px; height: 80px; top: -40px; left: 30px; }
.cloud-2::after { width: 100px; height: 100px; top: -50px; right: 30px; }

.cloud-3 { bottom: 25%; left: 5%; width: 220px; height: 70px; --base-scale: 0.9; transform: scale(var(--base-scale)); }
.cloud-3::before { width: 90px; height: 90px; top: -45px; left: 40px; }
.cloud-3::after { width: 110px; height: 110px; top: -55px; right: 40px; }

.cloud-4 { bottom: 20%; right: 15%; width: 180px; height: 55px; --base-scale: 1; transform: scale(var(--base-scale)); }
.cloud-4::before { width: 80px; height: 80px; top: -35px; left: 25px; }
.cloud-4::after { width: 90px; height: 90px; top: -45px; right: 25px; }

.cloud-5 { top: 45%; left: 25%; width: 120px; height: 40px; --base-scale: 0.7; transform: scale(var(--base-scale)); }
.cloud-5::before { width: 50px; height: 50px; top: -25px; left: 15px; }
.cloud-5::after { width: 60px; height: 60px; top: -30px; right: 20px; }

/* ==========================================
   КАРТОЧКА АВТОРИЗАЦИИ (Оставляем как было, убрали прозрачность бордеров для четкости)
========================================== */
.auth-card {
  position: relative;
  z-index: 2; /* Между задними (1) и передними (3) облаками */
  width: 100%;
  max-width: 400px;
  padding: 40px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.1);
  border: 1px solid #ffffff;
  transition: background 0.5s ease, border-color 0.5s ease, box-shadow 0.5s ease;
}

body.dark-theme .auth-card {
  background: rgba(36, 37, 43, 0.9);
  border-color: #34363f;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}
/* Остальные стили .auth-theme-switch и .btn-theme-icon остаются как есть... */

/* Кнопка смены темы в правом нижнем углу карточки */
.auth-theme-switch {
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 20;
}

.btn-theme-icon {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: transform 0.3s ease;
}

.btn-theme-icon:hover {
  transform: scale(1.15) rotate(15deg);
}

/* Плавная анимированная смена иконок солнце <-> полумесяц.
   Работает и для кнопки на экране входа, и для кнопки в шапке чатов. */
.theme-icon-sun,
.theme-icon-moon {
  transform-origin: center;
  transition: opacity 0.35s ease, transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.btn-theme-icon .theme-icon-sun,
.btn-theme-icon .theme-icon-moon {
  position: relative;
}

.theme-toggle-btn .theme-icon-sun,
.theme-toggle-btn .theme-icon-moon {
  transform: translate(-50%, -50%);
}

.btn-theme-icon .theme-icon-sun,
.btn-theme-icon .theme-icon-moon {
  transform: none;
}

body.light-theme .theme-icon-sun,
body.dark-theme .theme-icon-moon {
  color: #ffb300;
  opacity: 1;
}

body.dark-theme .theme-icon-sun,
body.light-theme .theme-icon-moon {
  color: var(--purple-color);
  opacity: 1;
}

/* Скрываем неактуальную иконку темы (свёрнута и провёрнута) */
body.light-theme .theme-icon-moon {
  opacity: 0;
  pointer-events: none;
}
body.light-theme .theme-toggle-btn .theme-icon-moon {
  transform: translate(-50%, -50%) scale(0.4) rotate(-90deg);
}
body.light-theme .btn-theme-icon .theme-icon-moon {
  transform: scale(0.4) rotate(-90deg);
  position: absolute;
  inset: 0;
}

body.dark-theme .theme-icon-sun {
  opacity: 0;
  pointer-events: none;
}
body.dark-theme .theme-toggle-btn .theme-icon-sun {
  transform: translate(-50%, -50%) scale(0.4) rotate(90deg);
}
body.dark-theme .btn-theme-icon .theme-icon-sun {
  transform: scale(0.4) rotate(90deg);
  position: absolute;
  inset: 0;
}

/* Полноэкранная кратковременная вспышка при смене темы (день/ночь) —
   элемент .celestial-animation создаётся и удаляется через JS (applyTheme) */
.celestial-animation {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, rgba(255, 223, 115, 0.55) 0%, rgba(255, 223, 115, 0) 70%);
  opacity: 0;
  animation: themeFlash 1.1s ease forwards;
}

.celestial-animation.dark {
  background: radial-gradient(circle at 50% 50%, rgba(90, 70, 200, 0.5) 0%, rgba(20, 23, 38, 0) 70%);
}

@keyframes themeFlash {
  0%   { opacity: 0; transform: scale(0.3); }
  35%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.5); }
}
