/* ═══════════════════════════════════════════════════════════
   AI Мессенджер — стили
   Тёмная тема, адаптивный дизайн, mobile-first
   Два ассистента: Гарри (фиолетовый) и Боря (зелёный/медицинский)
   ═══════════════════════════════════════════════════════════ */

/* ─── Переменные ─────────────────────────────────────────── */
:root {
  --bg-primary:    #0f0f13;
  --bg-secondary:  #1a1a24;
  --bg-tertiary:   #22222f;
  --bg-input:      #2a2a3a;

  /* Акцент меняется через JS в зависимости от ассистента */
  --accent:        #6c63ff;
  --accent-hover:  #8075ff;
  --accent-dim:    rgba(108, 99, 255, 0.15);

  --text-primary:   #f0f0f8;
  --text-secondary: #9090aa;
  --text-muted:     #60607a;

  --bubble-user:      var(--accent);
  --bubble-assistant: #22222f;

  --border:   rgba(255, 255, 255, 0.07);
  --shadow:   0 4px 24px rgba(0, 0, 0, 0.4);

  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition: 0.2s ease;
}

/* Тема Гарри — фиолетовая */
body.theme-harry {
  --accent:       #6c63ff;
  --accent-hover: #8075ff;
  --accent-dim:   rgba(108, 99, 255, 0.15);
}

/* Тема Бори — медицинский зелёный */
body.theme-borya {
  --accent:       #2ecc8e;
  --accent-hover: #3ddfa0;
  --accent-dim:   rgba(46, 204, 142, 0.15);
}

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

html { height: 100%; font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}

/* ─── Экран авторизации ───────────────────────────────────── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px 32px;
  box-shadow: var(--shadow);
  animation: fadeInUp 0.4s ease;
}

.auth-logo {
  font-size: 56px;
  text-align: center;
  margin-bottom: 8px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-6px); }
}

.auth-title {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: 14px;
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-form label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  display: block;
}

.auth-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.auth-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.auth-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.auth-btn:hover  { background: var(--accent-hover); }
.auth-btn:active { transform: scale(0.98); }

.auth-error {
  font-size: 13px;
  color: #ff6b6b;
  text-align: center;
  min-height: 20px;
}

/* ─── Экран чата ─────────────────────────────────────────── */
#chat-screen {
  display: none;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

#chat-screen.visible { display: flex; }

/* ─── Шапка ──────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  transition: background var(--transition);
}

.header-avatar {
  width: 40px;
  height: 40px;
  background: var(--accent-dim);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  border: 2px solid var(--accent);
  transition: border-color var(--transition), background var(--transition);
}

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

.header-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.header-status {
  font-size: 12px;
  color: #4caf8d;
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-status::before {
  content: '';
  width: 6px;
  height: 6px;
  background: #4caf8d;
  border-radius: 50%;
  display: inline-block;
}

.header-status.typing { color: var(--text-secondary); }
.header-status.typing::before {
  background: var(--text-secondary);
  animation: pulse 1s infinite;
}

.header-status.offline { color: var(--text-muted); }
.header-status.offline::before { background: var(--text-muted); }

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

/* Кнопка выхода */
.logout-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
}

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

/* ─── Список сообщений ───────────────────────────────────── */
.messages-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

.messages-list::-webkit-scrollbar       { width: 4px; }
.messages-list::-webkit-scrollbar-track { background: transparent; }
.messages-list::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 2px; }

/* ─── Сообщение ──────────────────────────────────────────── */
.message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: messageIn 0.25s ease;
}

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

.message.user      { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; align-items: flex-start; }

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.message.user .message-bubble {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: var(--radius-sm);
}

.message.assistant .message-bubble {
  background: var(--bubble-assistant);
  color: var(--text-primary);
  border-bottom-left-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 4px;
}

/* ─── Индикатор "печатает" ───────────────────────────────── */
.typing-indicator {
  display: none;
  align-self: flex-start;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: var(--bubble-assistant);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: var(--radius-sm);
}

.typing-indicator.visible { display: flex; }

.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingDot 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* ─── Панель ввода ───────────────────────────────────────── */
.input-panel {
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 8px 8px 8px 16px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.message-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  max-height: 120px;
  min-height: 24px;
  overflow-y: auto;
}

.message-input::placeholder { color: var(--text-muted); }

/* ─── Кнопки ввода ───────────────────────────────────────── */
.input-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background var(--transition), transform var(--transition);
  flex-shrink: 0;
}

.input-btn:active { transform: scale(0.9); }

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

.mic-btn:hover  { background: var(--accent-dim); color: var(--accent); }
.mic-btn.active {
  background: #ff4d4d;
  color: white;
  animation: micPulse 1s ease-in-out infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0   rgba(255, 77, 77, 0.4); }
  50%       { box-shadow: 0 0 0 8px rgba(255, 77, 77, 0); }
}

.send-btn { background: var(--accent); color: white; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* ─── Toast ──────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: var(--radius-xl);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 100;
  white-space: nowrap;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Анимации ───────────────────────────────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Адаптив ────────────────────────────────────────────── */
@media (max-width: 480px) {
  .auth-card { padding: 32px 20px; }
  .message   { max-width: 90%; }
}

@media (min-width: 768px) {
  #chat-screen {
    max-width: 640px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
