/* Young AI - чат: контент и инпут по центру, классический AI-чат */
/* Переопределяем только нужное для чата, отступ от сайдбара берётся из ArticleSidebar.css */

/* Чтобы не было отступа снизу: html/body на всю высоту вьюпорта */
html.young-ai-page,
body.young-ai-page {
  min-height: 100vh;
}

/* body - flex-контейнер, чтобы main мог растянуться до низа */
body.young-ai-page {
  display: flex;
  flex-direction: column;
}

/* main на всю ширину, чат не схлопывается */
html body.young-ai-page .main-content,
body.young-ai-page .main-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
  align-items: center;
  justify-content: flex-start;
  padding-bottom: 0 !important;
}

/* Баннер «запусти netlify dev»: показывается, пока бэкенд недоступен */
.young-ai-dev-banner {
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  line-height: 1.4;
  background: #000000;
  color: #fff;
  border-radius: 12px;
}
.young-ai-dev-banner code { font-family: inherit; background: rgba(255,255,255,.15); padding: 2px 6px; border-radius: 4px; }
.young-ai-dev-banner a { color: #fff; text-decoration: underline; }

/* Баннер ошибок — над карточкой чата, текст + кнопка «Повторить» */
.young-ai-error-banner {
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  line-height: 1.4;
  background: #000000;
  color: #fff;
  border-radius: 12px;
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.young-ai-error-banner:not([hidden]) {
  display: flex;
}
.young-ai-error-banner[hidden] {
  display: none !important;
}
.young-ai-error-banner .young-ai-error-text { flex: 1 1 auto; min-width: 0; }
.young-ai-error-banner code { font-family: inherit; background: rgba(255,255,255,.15); padding: 2px 6px; border-radius: 4px; }
.young-ai-error-banner a { color: #fff; text-decoration: underline; }

.young-ai-error-retry {
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-family: inherit;
  color: #000;
  background: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
}
.young-ai-error-retry:hover {
  background: #eee;
}

/* Инфо-баннер (например «Используем предыдущий ответ»), скрывается через 2.5 с */
.young-ai-info-banner {
  padding: 8px 14px;
  margin-bottom: 12px;
  font-size: 0.85rem;
  line-height: 1.4;
  background: rgba(0, 0, 0, 0.06);
  color: var(--color-text-secondary, #666);
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}
.young-ai-info-banner[hidden] {
  display: none !important;
}

[data-theme="dark"] .young-ai-info-banner {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.7);
  border-color: rgba(255, 255, 255, 0.1);
}

/* Обёртка чата: фиксированная ширина 720px по центру, не зависит от контента */
.young-ai-chat-wrap {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-self: stretch;
  width: 100%;
  max-width: 720px;
  min-width: 720px;
  margin: 0 auto;
  min-height: 200px;
  padding: 24px 20px 20px;
  box-sizing: border-box;
}

@media (max-width: 760px) {
  .young-ai-chat-wrap {
    min-width: 0;
  }
}

/* Большие экраны: чат и пузыри шире, текст чуть крупнее */
@media (min-width: 1200px) {
  .young-ai-chat-wrap {
    max-width: 860px;
    min-width: 860px;
    padding: 28px 24px 24px;
  }

  .young-ai-messages {
    padding: 28px;
    padding-bottom: 150px;
  }

  .young-ai-message-bubble {
    max-width: 88%;
    padding: 14px 18px;
    font-size: 17px;
    line-height: 1.55;
  }

  .young-ai-message.assistant .young-ai-message-bubble {
    max-width: min(88%, 620px);
  }

  .young-ai-input {
    font-size: 17px;
  }

  .young-ai-welcome-title {
    font-size: clamp(32px, 4vw, 52px) !important;
  }

  .young-ai-welcome-desc {
    font-size: 17px;
    line-height: 1.6;
  }

  .young-ai-scroll-to-bottom {
    width: 40px;
    height: 40px;
  }

  .young-ai-scroll-to-bottom i {
    width: 18px;
    height: 18px;
  }
}

/* Карточка: верхняя часть с фоном, нижняя (под инпутом) — без фона, контент виден */
/* filter: blur(0) нужен для backdrop-filter (баг Chrome) */
.young-ai-chat-card {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 320px;
  min-width: 100%;
  width: 100%;
  max-width: 100%;
  background: linear-gradient(
    to bottom,
    var(--color-bg-secondary, #f5f5f5) 0%,
    var(--color-bg-secondary, #f5f5f5) 60%,
    transparent 100%
  );
  border-radius: 32px;
  overflow: hidden;
  filter: blur(0);
  box-sizing: border-box;
}

/* Тёмная тема: больше стопов + явные цвета вместо transparent — меньше banding в Chrome */
[data-theme="dark"] .young-ai-chat-card {
  background: linear-gradient(
    to bottom,
    #1a1a1a 0%,
    #1a1a1a 50%,
    #181818 70%,
    #151515 85%,
    #111111 100%
  );
}

/* Закругление верхних углов скролл-области — совпадает с контейнером (32px) */
.young-ai-messages {
  flex: 1 1 0;
  min-height: 120px;
  min-width: 0;
  width: 100%;
  overflow-y: auto;
  overflow-x: visible;
  -webkit-overflow-scrolling: touch;
  padding: 24px;
  padding-bottom: 140px; /* место под инпут-оверлей, контент не скрыт */
  box-sizing: border-box;
  text-align: left;
  border-top-left-radius: 32px;
  border-top-right-radius: 32px;
}

/* Плавное появление сообщений и индикатора «печатает» */
@keyframes young-ai-message-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.young-ai-message {
  margin-bottom: 20px;
  display: flex;
  gap: 0;
  align-items: flex-start;
  animation: young-ai-message-in 0.35s ease-out forwards;
}

.young-ai-message.user {
  flex-direction: row-reverse;
}

/* Аватарки отключены - только переписка */
.young-ai-message-avatar {
  display: none !important;
}

.young-ai-message-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.5;
  word-break: break-word;
  border: none;
  overflow: visible;
}

/* Светлая тема: пузырь ассистента - контрастный, текст чёрный */
.young-ai-message.assistant .young-ai-message-bubble {
  max-width: min(85%, 520px);
  background: #e5e5e5;
  color: #111;
  border-bottom-left-radius: 4px;
}

.young-ai-message.assistant .young-ai-message-bubble p,
.young-ai-message.assistant .young-ai-message-bubble strong,
.young-ai-message.assistant .young-ai-message-bubble li {
  color: #111;
}

.young-ai-message.assistant .young-ai-message-bubble a {
  color: #0A72C2;
}

.young-ai-message.assistant .young-ai-message-bubble a:hover {
  color: #084d8a;
}

/* Тёмная тема: пузырь ассистента - основной текст #D6D6D6, закрывающая фраза (последний абзац) #A0A0A0 */
[data-theme="dark"] .young-ai-message.assistant .young-ai-message-bubble {
  background: #3d3d3d;
  color: #D6D6D6;
}

[data-theme="dark"] .young-ai-message.assistant .young-ai-message-bubble p,
[data-theme="dark"] .young-ai-message.assistant .young-ai-message-bubble strong,
[data-theme="dark"] .young-ai-message.assistant .young-ai-message-bubble li {
  color: #D6D6D6;
}

[data-theme="dark"] .young-ai-message.assistant .young-ai-message-bubble p:last-child {
  color: #A0A0A0;
}

[data-theme="dark"] .young-ai-message.assistant .young-ai-message-bubble a {
  color: #7eb8ff;
}

[data-theme="dark"] .young-ai-message.assistant .young-ai-message-bubble a:hover {
  color: #a8d0ff;
}

/* Сообщения пользователя (вопрос): светлая тема — тёмный фон, белый текст */
.young-ai-message.user .young-ai-message-bubble {
  background: #1a1a1a;
  color: #fff !important;
  border-bottom-right-radius: 4px;
}

.young-ai-message.user .young-ai-message-bubble p,
.young-ai-message.user .young-ai-message-bubble strong,
.young-ai-message.user .young-ai-message-bubble span {
  color: #fff !important;
}

.young-ai-message.user .young-ai-message-bubble a {
  color: #7eb8ff !important;
}

.young-ai-message.user .young-ai-message-bubble a:hover {
  color: #a8d0ff !important;
}

/* Тёмная тема: вопрос — белый фон, текст тёмным (#111 как на сайте) */
[data-theme="dark"] .young-ai-message.user .young-ai-message-bubble {
  background: #fff;
}

[data-theme="dark"] .young-ai-message.user .young-ai-message-bubble,
[data-theme="dark"] .young-ai-message.user .young-ai-message-bubble p,
[data-theme="dark"] .young-ai-message.user .young-ai-message-bubble strong,
[data-theme="dark"] .young-ai-message.user .young-ai-message-bubble span {
  color: #111 !important;
}

[data-theme="dark"] .young-ai-message.user .young-ai-message-bubble a {
  color: #0A72C2 !important;
}

[data-theme="dark"] .young-ai-message.user .young-ai-message-bubble a:hover {
  color: #084d8a !important;
}

.young-ai-message-bubble p {
  margin: 0 0 0.5em;
}

.young-ai-message-bubble p:last-child {
  margin-bottom: 0;
}

.young-ai-message-bubble a {
  color: inherit;
  text-decoration: none;
}

.young-ai-message-bubble a:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.young-ai-message-bubble img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 8px 0;
  display: block;
}

/* Превью кейса: картинка перед ссылкой на проект */
.young-ai-case-card {
  margin: 10px 0;
}
.young-ai-case-card-link {
  display: inline-block;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.08);
}
.young-ai-case-thumb {
  display: block;
  max-width: 280px;
  width: 100%;
  height: auto;
  margin: 0 !important;
  border-radius: 0;
  vertical-align: top;
}
[data-theme="dark"] .young-ai-case-card-link {
  border-color: rgba(255, 255, 255, 0.12);
}

/* Компактный индикатор «печатает»: узкий пузырь по контенту */
.young-ai-message-bubble:has(.young-ai-typing) {
  max-width: fit-content;
}

.young-ai-typing {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  align-items: center;
}

.young-ai-typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-text-muted, #888);
  animation: young-ai-dot 1.2s ease-in-out infinite both;
}

[data-theme="dark"] .young-ai-typing span {
  background: rgba(255, 255, 255, 0.5);
}

.young-ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.young-ai-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes young-ai-dot {
  0%, 70%, 100% { transform: scale(0.85); opacity: 0.5; }
  35% { transform: scale(1.15); opacity: 1; }
}

/* Кнопка «доскроллить вниз»: над инпутом с зазором, выше по стеку — не перекрывается input-wrap */
.young-ai-scroll-to-bottom {
  position: absolute;
  bottom: calc(24px + 52px + 24px + 16px); /* высота input-wrap + 16px зазор */
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.95);
  color: #111;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
  transition: opacity 0.2s, transform 0.2s, background 0.2s;
}

.young-ai-scroll-to-bottom i {
  width: 14px;
  height: 14px;
}

.young-ai-scroll-to-bottom:hover {
  background: #fff;
  transform: translateX(-50%) scale(1.05);
}

.young-ai-scroll-to-bottom[hidden] {
  display: none !important;
}

/* Тёмная тема: светлая кнопка и тёмная стрелка — стрелка хорошо видна, кнопка не залезает под инпут */
[data-theme="dark"] .young-ai-scroll-to-bottom {
  background: rgba(255, 255, 255, 0.92);
  color: #111;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .young-ai-scroll-to-bottom:hover {
  background: #fff;
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.6);
}

/* Инпут — оверлей поверх сообщений, под кнопкой «доскроллить вниз» (z-index ниже) */
.young-ai-input-wrap {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 2;
  padding: 24px;
  background: transparent !important;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  overflow: hidden;
}

/* Блок под инпутом: без фона, только blur для размытия контента под собой */
.young-ai-input-blur {
  position: absolute;
  inset: 0;
  background: transparent !important;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  pointer-events: none;
  z-index: 0;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
}

/* Инпут (поле ввода) — чуть темнее белого для контраста */
.young-ai-input-inner {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0;
  max-width: 100%;
  min-height: 52px;
  padding: 10px 10px 10px 20px;
  background: #f0f0f0;
  border: 1px solid transparent;
  border-radius: 26px;
  transition: border-color 0.2s, background 0.2s;
}

.young-ai-input-inner:hover {
  border-color: #e8e8e8;
}

[data-theme="dark"] .young-ai-input-inner {
  background: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .young-ai-input-inner:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

/* Не меньше 16px — иначе iOS/Android зумируют при фокусе в поле */
.young-ai-input {
  flex: 1;
  min-height: 32px;
  max-height: 160px;
  padding: 10px 12px 10px 0;
  border: none;
  border-radius: 0;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.4;
  resize: none;
  background: transparent;
  color: var(--color-text);
  transition: none;
  align-self: center;
  box-sizing: border-box;
}

/* Ротация плейсхолдера: оверлей поверх инпута, 3 фразы по кругу с плавным появлением */
.young-ai-placeholder-rotator {
  position: absolute;
  left: 30px;
  right: 50px;
  top: 10px;
  bottom: 10px;
  display: flex;
  align-items: center;
  pointer-events: none;
  z-index: 0;
  color: var(--color-text-muted, #888);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.4;
}

.young-ai-placeholder-rotator-text {
  transition: opacity 0.4s ease;
}

.young-ai-placeholder-rotator.rotator-hidden .young-ai-placeholder-rotator-text {
  opacity: 0;
  pointer-events: none;
}

.young-ai-placeholder-rotator-text.rotator-fade-out {
  opacity: 0;
}

[data-theme="dark"] .young-ai-placeholder-rotator {
  color: rgba(255, 255, 255, 0.45);
}

.young-ai-input::placeholder {
  color: var(--color-text-muted, #888);
}

[data-theme="dark"] .young-ai-input::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

.young-ai-input:focus {
  outline: none;
}

.young-ai-input:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* Кнопка отправить - чёрная, белая иконка */
.young-ai-send {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #000;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s, background 0.2s;
  align-self: center;
}

/* Ховер: фон кнопки темнее фона чата */
.young-ai-send:hover:not(:disabled) {
  background: #e0e0e0;
  color: #111;
}

.young-ai-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

[data-theme="dark"] .young-ai-send {
  background: #fff;
  color: #000;
}

[data-theme="dark"] .young-ai-send:hover:not(:disabled) {
  background: #111;
  color: #fff;
}

/* Приветственный блок: по умолчанию по левому краю (когда есть переписка) */
.young-ai-welcome {
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  padding: 0;
  margin-top: 24px;
  margin-bottom: 24px;
}

/* Начальное состояние (нет сообщений): заголовок, текст и чипы по центру */
.young-ai-messages:not(:has(.young-ai-message)) .young-ai-welcome {
  text-align: center;
}

.young-ai-messages:not(:has(.young-ai-message)) .young-ai-welcome-title {
  text-align: center !important;
}

.young-ai-messages:not(:has(.young-ai-message)) .young-ai-welcome-desc {
  text-align: center !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

.young-ai-messages:not(:has(.young-ai-message)) .young-ai-chips {
  justify-content: center;
  text-align: center;
}

/* Заголовок приветствия — обычный начертание, не курсив */
.young-ai-welcome-title {
  display: block;
  width: 100%;
  font-family: var(--font-editorial) !important;
  font-style: normal !important;
  font-weight: 500 !important;
  font-size: clamp(28px, 4vw, 48px) !important;
  line-height: 1.1 !important;
  letter-spacing: -0.02em !important;
  color: var(--color-text) !important;
  margin: 0 0 16px 0 !important;
  padding: 0 !important;
  text-align: left !important;
}

.young-ai-welcome-desc {
  display: block;
  width: 100%;
  max-width: 624px; /* +40 от 584px */
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text-secondary, #777);
  margin: 0 !important;
  padding: 0 !important;
  text-align: left !important;
  white-space: pre-line; /* перенос по \n в i18n (en/es) */
}

[data-theme="dark"] .young-ai-welcome-desc {
  color: rgba(255, 255, 255, 0.7);
}

/* Подсказка после первого ответа: один раз, нейтральный тон */
.young-ai-first-hint {
  font-size: 13px;
  line-height: 1.4;
  color: var(--color-text-muted, #888);
  margin: -8px 0 16px 0;
  padding: 0;
  animation: young-ai-hint-in 0.4s ease-out;
}

[data-theme="dark"] .young-ai-first-hint {
  color: rgba(255, 255, 255, 0.5);
}

@keyframes young-ai-hint-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Starter chips: по левому краю при переписке; в начале — по центру (см. выше) */
.young-ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-start;
  align-items: center;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 0 0 20px 0;
  margin-top: 0;
  margin-left: 0;
  text-align: left;
}

.young-ai-chips.young-ai-chips-loading {
  pointer-events: none;
  opacity: 0.6;
}

.young-ai-messages .young-ai-chips:not(:first-child):not(:nth-child(2)) {
  margin-top: 16px;
}

.young-ai-chips.hidden {
  display: none;
}

.young-ai-chip.young-ai-chip-used {
  display: none;
}

.young-ai-chip {
  padding: 8px 14px;
  border-radius: 20px;
  border: none;
  background: var(--color-bg, #fff);
  color: var(--color-text);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

.young-ai-chip:hover {
  background: #e8e8e8;
}

[data-theme="dark"] .young-ai-chip {
  background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .young-ai-chip:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* ========== Адаптив и мобильный интерфейс ========== */
@media (max-width: 768px) {
  .young-ai-chat-wrap {
    padding: 16px 12px 16px;
    min-height: 180px;
  }

  .young-ai-chat-card {
    border-radius: 20px;
    min-height: 280px;
  }

  .young-ai-messages {
    padding: 16px;
    padding-bottom: 120px;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
  }

  .young-ai-message {
    margin-bottom: 14px;
  }

  .young-ai-message.assistant .young-ai-message-bubble {
    max-width: min(95%, 100%);
  }

  .young-ai-message-bubble {
    padding: 10px 12px;
  }

  .young-ai-case-thumb {
    max-width: 100%;
  }

  .young-ai-scroll-to-bottom {
    bottom: calc(16px + 48px + 16px + 16px); /* мобильная высота input-wrap + 16px зазор */
  }

  .young-ai-placeholder-rotator {
    left: 24px;
    right: 48px;
  }

  .young-ai-input-wrap {
    padding: 16px 12px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
  }

  .young-ai-input-blur {
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
  }

  .young-ai-input-inner {
    min-height: 48px;
    padding: 8px 8px 8px 16px;
    border-radius: 24px;
  }

  .young-ai-input {
    font-size: 16px; /* не меньше 16px, чтобы iOS не зумил при фокусе */
  }

  .young-ai-send {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  .young-ai-welcome-title {
    font-size: clamp(22px, 5vw, 32px) !important;
    margin-bottom: 12px !important;
  }

  .young-ai-welcome-desc {
    font-size: 14px;
    line-height: 1.5;
  }

  .young-ai-chips {
    gap: 6px;
    padding-bottom: 16px;
  }

  .young-ai-chip {
    padding: 10px 14px;
    font-size: 13px;
  }

  .young-ai-dev-banner {
    padding: 10px 12px;
    font-size: 0.85rem;
    margin-bottom: 10px;
  }

  .young-ai-error-banner {
    padding: 10px 12px;
    font-size: 0.85rem;
    margin-bottom: 10px;
  }
}

/* Очень узкие экраны (например портрет телефона) */
@media (max-width: 380px) {
  .young-ai-chat-wrap {
    padding: 12px 10px 12px;
  }

  .young-ai-messages {
    padding: 12px;
    padding-bottom: 110px;
  }

  .young-ai-scroll-to-bottom {
    bottom: calc(12px + 48px + 12px + 16px);
  }

  .young-ai-input-wrap {
    padding: 12px 10px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .young-ai-input {
    font-size: 16px; /* минимум для iOS/Android — без зума при фокусе */
  }

  .young-ai-welcome-title {
    font-size: clamp(20px, 6vw, 28px) !important;
  }
}
