/* ============================================
   FirstWeb Chat — базовая тема
   ============================================ */

/* ==== Сброс ==== */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

/* ==== Переменные ==== */
:root {
  /* Акцент */
  --accent: #fece1a;
  --accent-hover: #e5b800;
  --accent-soft: rgba(254, 206, 26, 0.15);
  --accent-text: #111111;

  /* Фоны */
  --bg-app: #f0f2f5;
  --bg-white: #ffffff;
  --bg-dark: #2a2a2a;

  /* Текст */
  --text: #111b21;
  --text-secondary: #667781;
  --text-muted: #8696a0;
  --text-on-dark: #ffffff;
  --text-on-dark-muted: rgba(255, 255, 255, 0.7);

  /* Пузыри сообщений */
  --bubble-in: #ffffff;
  --bubble-in-text: #111b21;
  --bubble-out: #fece1a;
  --bubble-out-text: #111111;

  /* Границы и статусы */
  --border: #e9edef;
  --danger: #dc2626;
  --success: #16a34a;
  --check-read: #2196f3;

  /* Тени */
  --shadow-sm: 0 1px 0.5px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);

  /* Размеры */
  --header-h: 56px;
  --max-width: 768px;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;
}

/* ============= Тёмная тема ============= */
[data-theme="dark"] {
  color-scheme: dark;

  /* Акцент — тот же жёлтый, но чуть приглушённый для тёмного фона */
  --accent: #f5c518;
  --accent-hover: #e0b000;
  --accent-soft: rgba(245, 197, 24, 0.14);
  --accent-text: #111111;

  /* Фоны */
  --bg-app: #0f1115;
  --bg-white: #1c1f24;
  --bg-dark: #2a2e34;

  /* Текст */
  --text: #e8e9ea;
  --text-secondary: #9aa1a8;
  --text-muted: #6b7278;
  --text-on-dark: #ffffff;
  --text-on-dark-muted: rgba(255, 255, 255, 0.65);

  /* Пузыри */
  --bubble-in: #262a30;
  --bubble-in-text: #e8e9ea;
  --bubble-out: #f5c518;
  --bubble-out-text: #111111;

  /* Границы */
  --border: #2e333a;

  /* Статусы */
  --danger: #f87171;
  --success: #4ade80;
  --check-read: #60a5fa;

  /* Тени — в тёмной теме почти не видны, но пусть будут мягче */
  --shadow-sm: 0 1px 0.5px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.6);
}

/* Некоторые захардкоженные цвета в base.css — фиксим точечно */
[data-theme="dark"] body {
  background: var(--bg-app);
}

[data-theme="dark"] .screen-auth {
  background: var(--bg-white);
}

[data-theme="dark"] .auth-form input {
  background: var(--bg-white);
  color: var(--text);
}

[data-theme="dark"] .auth-form input::placeholder {
  color: var(--text-muted);
}

[data-theme="dark"] .modal-content {
  background: var(--bg-white);
}

[data-theme="dark"] .modal input {
  background: var(--bg-white);
  color: var(--text);
}

[data-theme="dark"] .modal input:focus {
  background: #232730;
  border-bottom-color: var(--accent);
}

[data-theme="dark"] .btn-secondary {
  color: var(--text);
  border-color: var(--border);
}

[data-theme="dark"] .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .icon-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .icon-btn:active {
  background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .toast {
  background: rgba(240, 240, 240, 0.95);
  color: #111;
}

[data-theme="dark"] .toast.success {
  background: var(--accent);
  color: var(--accent-text);
}

/* ==== Основа ==== */
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;

  touch-action: pan-x pan-y;   /* разрешаем скролл, запрещаем pinch-zoom */
  -webkit-text-size-adjust: 100%;   /* iOS: не увеличивать текст при повороте */
  -ms-text-size-adjust: 100%;

  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

input, textarea {
  font: inherit;
  color: inherit;
  outline: none;
  border: none;
  background: none;
}

a { color: var(--accent-hover); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ==== Аватары ==== */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 600;
  text-transform: uppercase;
  user-select: none;
  flex-shrink: 0;
  overflow: hidden;
  letter-spacing: 0.5px;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 50%;
}

.avatar-sm { width: 40px; height: 40px; font-size: 15px; }
.avatar-md { width: 48px; height: 48px; font-size: 17px; }
.avatar-lg { width: 64px; height: 64px; font-size: 22px; }
.avatar-xl { width: 96px; height: 96px; font-size: 36px; }

/* ==== Экраны ==== */
.screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-app);
}

@media (min-width: 769px) {
  .screen {
    position: static;
    max-width: var(--max-width);
    margin: 0 auto;
    height: 100vh;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.08);
  }
}

/* ==== Экран загрузки ==== */
.screen-loading {
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-secondary);
  background: var(--bg-white);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==== Кнопки ==== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  transition: background 0.15s, transform 0.05s;
}
.btn-primary svg { display: block; flex-shrink: 0; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-secondary svg { display: block; flex-shrink: 0; }
.btn-secondary:hover { background: var(--bg-app); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--text-secondary);
  transition: background 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(0, 0, 0, 0.05); }
.icon-btn:active { background: rgba(0, 0, 0, 0.1); }

/* ==== Тосты ==== */
.toasts {
  position: fixed;
  bottom: calc(100px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}

.toast {
  background: rgba(17, 27, 33, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  animation: toast-in 0.2s ease-out;
  pointer-events: auto;
  max-width: 100%;
  word-break: break-word;
}
.toast.error { background: var(--danger); }
.toast.success {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 500;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ==== Модалки ==== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  animation: fade-in 0.15s ease-out;
}

.modal-content {
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-in 0.2s ease-out;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

.modal input {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  width: 100%;
  background: var(--bg-white);
}
.modal input:focus {
  background: #fafbfc;
  border-bottom-color: var(--accent);
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}