/* ═══════════════════════════════════════════════════
   chat.css — стили интерфейса приложения
   ═══════════════════════════════════════════════════ */

* {
  box-sizing: border-box;
}

body {
  margin: 0; padding: 0;
  height: 100dvh;
  overflow: hidden;
  background: var(--charcoal);
  font-family: 'Jost', sans-serif;
  color: var(--warm-white);
  width: 100%;
}

.screen {
  display: none;
  height: 100%;
  width: 100%;
}
.screen.visible { display: flex; }

#app-screen {
  position: relative;
}

/* ─── ЭКРАН АВТОРИЗАЦИИ ─── */
#auth-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(to bottom right, #1C1A18, #2a2520);
}
.auth-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(184, 149, 90, 0.2);
  padding: 48px;
  border-radius: 16px;
  text-align: center;
  max-width: 400px;
  width: 90%;
}
.auth-logo {
  font-family: 'Cormorant Garamond', serif;
  font-size: 32px; letter-spacing: 4px;
  text-transform: uppercase; margin-bottom: 24px;
}
.auth-logo span { color: var(--gold); }
.auth-title { font-size: 24px; margin-bottom: 12px; font-weight: 400; }
.auth-desc { font-size: 15px; color: rgba(255,255,255,0.6); margin-bottom: 32px; line-height: 1.6; }
.tg-widget-container { min-height: 40px; margin-bottom: 24px; }
.auth-back { display: block; font-size: 13px; color: var(--gold); text-decoration: none; text-transform: uppercase; letter-spacing: 1px; }

/* ─── САЙДБАР ─── */
.sidebar {
  width: 280px;
  background: #141311;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s ease;
  z-index: 100;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(184, 149, 90, 0.3) transparent;
}  
.sidebar-header {
  padding: 20px 24px;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.sidebar-logo {
  font-family: 'Cormorant Garamond', serif;
  font-size: 20px; letter-spacing: 2px; color: var(--warm-white); text-decoration: none;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(184, 149, 90, 0.3); border-radius: 4px; }

/* Модалка подтверждения */
.modal-btn.outline { background: transparent; border: 1px solid rgba(255,255,255,0.2); color: white; }
.modal-btn.danger { background: #ff4d6a; color: white; }

.sidebar-logo span { color: var(--gold); }
.close-sidebar-btn { display: none; background: none; border: none; color: white; font-size: 20px; cursor: pointer; }

.sidebar-section { padding: 20px 24px 0; }
.section-label { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--gold); margin-bottom: 12px; }

.role-btn, .cmd-btn {
  width: 100%; text-align: left; background: transparent; border: none;
  padding: 10px 12px; border-radius: 6px; color: rgba(255,255,255,0.7);
  font-family: 'Jost', sans-serif; font-size: 14px; cursor: pointer;
  transition: all 0.2s; margin-bottom: 4px;
}
.role-btn:hover, .cmd-btn:hover { background: rgba(255,255,255,0.05); color: white; }
.role-btn.active { background: rgba(184, 149, 90, 0.15); color: var(--gold); }
.cmd-btn.danger:hover { background: rgba(255, 50, 50, 0.15); color: #ff6b6b; }

.sidebar-spacer { flex: 1; }

.sidebar-profile { padding: 20px 24px; border-top: 1px solid rgba(255, 255, 255, 0.05); }
.profile-info { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.profile-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--gold); color: var(--charcoal); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 16px; }
.profile-name { font-weight: 500; font-size: 15px; }
.profile-plan { font-size: 12px; color: var(--gold); }

.limits-block { margin-bottom: 20px; }
.limit-item { margin-bottom: 12px; }
.limit-header { display: flex; justify-content: space-between; font-size: 11px; color: rgba(255,255,255,0.5); margin-bottom: 6px; }
.limit-bar { height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; overflow: hidden; }
.limit-fill { height: 100%; background: var(--gold); transition: width 0.3s; }

.profile-actions { display: flex; flex-direction: column; gap: 8px; }
.profile-btn.full-width { width: 100%; text-align: center; }
.profile-actions-row { display: flex; gap: 8px; }
.profile-actions-row .profile-btn { flex: 1; text-align: center; }
.profile-btn { flex: 1; padding: 8px; background: var(--gold); color: var(--charcoal); border: none; border-radius: 6px; font-weight: 500; font-size: 12px; cursor: pointer; text-transform: uppercase; }
.profile-btn.outline { background: transparent; border: 1px solid rgba(255,255,255,0.2); color: white; }


/* ─── ЧАТ (ОСНОВНАЯ ОБЛАСТЬ) ─── */
.chat-area {
  flex: 1; display: flex; flex-direction: column;
  background: var(--warm-white); color: var(--charcoal); position: relative;
  width: 100%;
  min-width: 0;
}
.chat-header {
  height: 60px; border-bottom: 1px solid rgba(0,0,0,0.05); display: flex;
  align-items: center; justify-content: space-between; padding: 0 20px;
  background: rgba(253, 250, 246, 0.9); backdrop-filter: blur(10px);
}
.burger-btn { background: none; border: none; font-size: 24px; cursor: pointer; display: none; color: var(--charcoal); }
.current-role-title { font-family: 'Cormorant Garamond', serif; font-size: 20px; font-weight: 600; color: var(--gold); }

.messages-container {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: 24px; display: flex; flex-direction: column; gap: 24px;
}
.msg { 
  display: flex; 
  gap: 16px; 
  max-width: 800px; /* Ограничиваем ширину на больших экранах */
  margin: 0 auto; 
  width: 100%; 
}
.msg.user { flex-direction: row-reverse; }
.msg-avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-weight: 600; }
.msg.assistant .msg-avatar { background: var(--gold); color: var(--charcoal); font-family: 'Cormorant Garamond', serif; font-size: 18px; }
.msg.user .msg-avatar { background: var(--charcoal); color: white; font-size: 14px; }

/* ИСПРАВЛЕННЫЙ ПУЗЫРЬ */
.msg-bubble { 
  background: white; 
  padding: 16px 20px; 
  border-radius: 12px; 
  box-shadow: 0 2px 10px rgba(0,0,0,0.02); 
  font-size: 15px; 
  line-height: 1.6; 
  word-wrap: break-word; 
  overflow-wrap: break-word; 
  max-width: 85%; /* Пузырь аккуратно облегает текст, но не более 85% ширины */
}
.msg.user .msg-bubble { background: var(--blush); }

.input-area { padding: 20px; background: var(--warm-white); border-top: 1px solid rgba(0,0,0,0.05); width: 100%; }
.input-wrapper { 
  max-width: 800px; 
  margin: 0 auto; position: relative; display: flex; align-items: flex-end; 
  background: white; border: 1px solid rgba(0,0,0,0.1); border-radius: 16px; 
  padding: 8px 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.03); 
  width: 100%; 
}
#chat-input { flex: 1; border: none; outline: none; resize: none; max-height: 200px; font-family: 'Jost', sans-serif; font-size: 15px; padding: 8px; line-height: 1.5; background: transparent; min-width: 0; width: 100%; }
.send-btn { background: var(--gold); border: none; width: 36px; height: 36px; border-radius: 10px; color: var(--charcoal); display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; transition: transform 0.2s; }
.send-btn:hover { transform: scale(1.05); }
.input-hint { text-align: center; font-size: 11px; color: var(--light); margin-top: 8px; }

/* ─── МОДАЛКА ─── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 200; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.modal-overlay.active { display: flex; }
.modal { background: var(--charcoal); width: 90%; max-width: 500px; border-radius: 12px; padding: 32px; border: 1px solid rgba(184, 149, 90, 0.3); position: relative; }
.modal-close { position: absolute; top: 16px; right: 16px; background: none; border: none; color: white; cursor: pointer; font-size: 20px; }
.modal-title { font-family: 'Cormorant Garamond', serif; font-size: 24px; color: var(--gold); margin-bottom: 20px; }
.modal-content { max-height: 300px; overflow-y: auto; margin-bottom: 20px; font-size: 14px; color: rgba(255,255,255,0.8); }
.fact-item { display: flex; justify-content: space-between; padding: 10px; background: rgba(255,255,255,0.05); margin-bottom: 8px; border-radius: 6px; }
.del-fact { background: none; border: none; color: #ff6b6b; cursor: pointer; }
.modal-input-group { display: flex; gap: 8px; }
.modal-input-group input { flex: 1; padding: 10px 16px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.1); background: transparent; color: white; font-family: 'Jost'; }
.modal-btn { background: var(--gold); border: none; padding: 0 20px; border-radius: 6px; font-weight: 500; cursor: pointer; }

/* ─── МOБИЛКИ (Медиа-запрос) ─── */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 90; }

@media (max-width: 768px) {
  .sidebar { position: absolute; height: 100%; width: 280px; transform: translateX(-100%); z-index: 100; background: #141311; transition: transform 0.3s ease; overflow-y: auto; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.active { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 90; }
  .burger-btn, .close-sidebar-btn { display: block; }
  
  /* ИСПРАВЛЕННАЯ АДАПТАЦИЯ ЧАТА ДЛЯ МОБИЛОК */
  .messages-container { padding: 16px; }
  .msg-bubble { max-width: calc(100% - 52px); /* Занимает всю ширину, оставляя место для аватарки */ }
}

/* Красивый Markdown внутри чата */
.msg-bubble strong { font-weight: 600; color: var(--gold-light); }
.msg-bubble p { margin: 0 0 10px 0; }
.msg-bubble p:last-child { margin: 0; }

/* Стили для системных заметок (инсайтов) */
.msg-bubble blockquote {
  margin: 12px 0 0 0; padding: 10px 14px;
  background: rgba(184, 149, 90, 0.08); border-left: 3px solid var(--gold); border-radius: 0 6px 6px 0;
}
.msg-bubble code { font-family: 'Courier New', monospace; font-size: 13px; color: var(--gold); }

/* Стили для плашки "Печатаю ответ..." */
.thinking-msg .msg-bubble { background: transparent; border: 1px solid rgba(0, 0, 0, 0.05); color: var(--mid); font-style: italic; padding: 10px 16px; }

/* Скрепка и файлы */
.attach-btn { background: none; border: none; color: var(--gold); font-size: 20px; cursor: pointer; padding: 6px 10px; margin-right: 4px; transition: transform 0.2s; flex-shrink: 0; }
.attach-btn:hover { transform: scale(1.1); }
#attachment-preview { font-size: 13px; color: var(--charcoal); background: var(--blush); padding: 8px 14px; border-radius: 8px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; width: fit-content; max-width: 100%; border: 1px solid rgba(184,149,90,0.3); }
#attachment-remove { background: none; border: none; color: red; font-size: 16px; cursor: pointer; font-weight: bold; margin-left: 12px; }

/* ─── АНИМАЦИЯ НАБОРА ТЕКСТА ─── */
.typing-indicator { display: inline-flex; align-items: center; gap: 4px; }
.typing-indicator span { width: 6px; height: 6px; background-color: var(--gold); border-radius: 50%; animation: typingBounce 1.4s infinite ease-in-out both; }
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
.typing-indicator span:nth-child(3) { animation-delay: 0s; }
@keyframes typingBounce { 0%, 80%, 100% { transform: scale(0); opacity: 0.3; } 40% { transform: scale(1); opacity: 1; } }
.thinking-text { margin-left: 10px; font-size: 14px; color: var(--mid); font-style: italic; }
.thinking-msg .msg-bubble { display: flex; align-items: center; background: transparent; border: 1px solid rgba(184, 149, 90, 0.2); padding: 12px 16px; }

/* ─── ПОДСВЕТКА СИНТАКСИСА И БЛОКИ КОДА ─── */
.code-block-wrapper {
    width: 100%;
    margin: 16px 0;
    border-radius: 8px;
    overflow: hidden; /* Блокирует вылезание за рамки */
    background: #0d1117;
    border: 1px solid rgba(184, 149, 90, 0.2);
}

.code-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 12px; background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(184, 149, 90, 0.2); font-size: 12px;
}

.code-language { color: var(--gold); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }

.copy-code-btn {
    background: rgba(184, 149, 90, 0.1); border: 1px solid var(--gold); color: var(--gold);
    padding: 4px 10px; border-radius: 4px; font-size: 11px; cursor: pointer; transition: all 0.2s; font-family: 'Jost', sans-serif;
}
.copy-code-btn:hover { background: var(--gold); color: var(--charcoal); transform: scale(1.05); }

/* ИСПРАВЛЕННЫЙ БЛОК КОДА */
.code-block-wrapper pre {
    margin: 0;
    padding: 16px;
    overflow-x: auto; /* Включает ГОРИЗОНТАЛЬНЫЙ СКРОЛЛ для длинных строк */
    white-space: pre; /* Железобетонно запрещает перенос строк (спасает Python) */
    background: #0d1117;
}

.code-block-wrapper code {
    font-family: 'Courier New', 'Monaco', 'Menlo', monospace;
    font-size: 13px;
    line-height: 1.5;
}

/* Стили для inline-кода */
.msg-bubble code:not(pre code) {
    background: rgba(184, 149, 90, 0.1); padding: 2px 6px; border-radius: 4px;
    font-family: 'Courier New', monospace; font-size: 0.9em; color: var(--gold);
}
.msg-bubble pre { margin: 16px 0; border-radius: 8px; overflow-x: auto; }
.msg-bubble blockquote code { background: transparent; color: inherit; }

/* --- АНИМАЦИЯ МИКРОФОНА (Push-to-Talk) --- */
#mic-btn {
  transition: all 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* Запрещаем системное меню на iOS при долгом тапе */
}

#mic-btn.recording {
  color: #ff4d6a !important;
  transform: scale(1.2);
  background: rgba(255, 77, 106, 0.15);
  border-radius: 50%;
  animation: pulseMic 1.5s infinite;
}

@keyframes pulseMic {
  0% { box-shadow: 0 0 0 0 rgba(255, 77, 106, 0.4); }
  70% { box-shadow: 0 0 0 12px rgba(255, 77, 106, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 77, 106, 0); }
}