/*
  Стили приложения-чата.
  Сделаны под телефон (это Telegram Mini App) и подстраиваются под тему телеги:
  светлую или тёмную — через переменные --tg-* (их подставляет Telegram),
  с аккуратными запасными цветами, если переменных нет.
*/

:root {
  /* Цвета берём из темы Telegram, с запасными значениями для светлой темы */
  --bg:        var(--tg-theme-bg-color, #f4f6fb);
  --surface:   var(--tg-theme-secondary-bg-color, #ffffff);
  --text:      var(--tg-theme-text-color, #1c1c1e);
  --hint:      var(--tg-theme-hint-color, #8a8d96);
  --accent:    var(--tg-theme-button-color, #3b82f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);

  /* Фирменный градиент шапки и кнопки */
  --brand-grad: linear-gradient(135deg, #5b8cff 0%, #6d5bff 100%);
  --bubble-bot: var(--tg-theme-bg-color, #ffffff);
  --shadow: 0 6px 24px rgba(40, 50, 90, 0.10);
  --radius: 20px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

/* Контейнер на всю высоту экрана: шапка сверху, ввод снизу, чат тянется */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* корректная высота на мобильных с учётом панелей */
  max-width: 720px;
  margin: 0 auto;
}

/* ─── Шапка ─── */
.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--brand-grad);
  color: #fff;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  flex-shrink: 0;
}

.header-info { min-width: 0; }

.header-title {
  font-weight: 600;
  font-size: 16px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-subtitle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  opacity: 0.9;
  margin-top: 2px;
}

.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3ddc84;
  box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.6);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.6); }
  70%  { box-shadow: 0 0 0 7px rgba(61, 220, 132, 0); }
  100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0); }
}

/* ─── Лента сообщений ─── */
.chat {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Пузырь сообщения */
.bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
  box-shadow: var(--shadow);
  animation: appear 0.22s ease-out;
}

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

/* Ответ бота — слева, светлый пузырь */
.bubble.bot {
  align-self: flex-start;
  background: var(--bubble-bot);
  color: var(--text);
  border-bottom-left-radius: 6px;
}

/* Сообщение клиента — справа, фирменный градиент */
.bubble.user {
  align-self: flex-end;
  background: var(--brand-grad);
  color: #fff;
  border-bottom-right-radius: 6px;
}

/* Индикатор «печатает…» — три прыгающие точки */
.typing {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 14px 16px;
  background: var(--bubble-bot);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow);
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hint);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ─── Поле ввода ─── */
.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.composer-input {
  flex: 1;
  border: none;
  outline: none;
  background: var(--bg);
  color: var(--text);
  font-size: 16px; /* 16px — чтобы iOS не зумил поле при фокусе */
  padding: 12px 16px;
  border-radius: 22px;
}

.composer-input::placeholder { color: var(--hint); }

.composer-send {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--brand-grad);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.composer-send:active { transform: scale(0.9); }
.composer-send:disabled { opacity: 0.5; cursor: default; }
