/* 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;
}
.young-ai-error-banner:not([hidden]) {
  display: block;
}
.young-ai-error-banner[hidden] {
  display: none !important;
}
.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; }

/* Обёртка чата: фиксированная ширина 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;
  }
}

/* Карточка: верхняя часть с фоном, нижняя (под инпутом) — без фона, контент виден */
/* 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; }
}

/* Инпут — оверлей поверх сообщений, контейнер и blur без фона */
.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);
}

.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;
}

.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-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;
}

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

/* Заголовок приветствия — обычный начертание, не курсив */
.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: 560px;
  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;
}

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

/* Starter chips: всегда по левому краю (переопределяем возможный text-align: center у предков) */
.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-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-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-input-wrap {
    padding: 12px 10px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

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