/* === AI РОБОТ-ЮРИСТ === */
#ai-assistant {
  position: fixed;
  bottom: 28px; right: 28px;
  width: 66px; height: 66px;
  z-index: 9999;
  cursor: pointer;
  filter: drop-shadow(0 8px 25px rgba(0,0,0,0.4));
  transition: all 0.3s ease;
}
#ai-assistant:hover { transform: scale(1.15); }

.ai-robot { 
  width: 100%; height: 100%; 
  filter: drop-shadow(0 0 15px rgba(212,175,55,0.5)); 
}

.judge-hat {
  animation: hatWiggle 4s ease-in-out infinite;
}
@keyframes hatWiggle {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-1px) rotate(0.8deg); }
}

.ai-bubble {
  position: absolute;
  bottom: 80px; right: 0;
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.85rem;
  max-width: 200px;
  white-space: nowrap;
  box-shadow: 0 8px 25px rgba(0,0,0,0.3);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  z-index: 9998;
  animation: bubbleFade 0.4s ease-out forwards;
}
.ai-bubble::after {
  content: '';
  position: absolute;
  bottom: -8px; right: 18px;
  border: 8px solid transparent;
  border-top-color: rgba(255,255,255,0.12);
}
@keyframes bubbleFade { to { opacity: 1; transform: translateY(0); } }

/* === MACOS-СТИЛЬ ЧАТ === */
.ai-chat-modal {
  position: fixed;
  bottom: 110px; right: 28px;
  width: 360px; height: 480px;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(30px);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 24px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  display: none;
  flex-direction: column;
  z-index: 9999;
  overflow: hidden;

  /* Начальное состояние */
  opacity: 0;
  transform: scale(0.1) translateY(20px);
  transform-origin: bottom right;
  transition: 
      opacity 0.38s cubic-bezier(0.2, 0.8, 0.2, 1),
      transform 0.38s cubic-bezier(0.2, 0.8, 0.2, 1),
      border-radius 0.38s ease,
      box-shadow 0.38s ease;
}

.ai-chat-modal.show {
  opacity: 1;
  transform: scale(1) translateY(0);
  /* УМЕНЬШИЛ СВЕЧЕНИЕ — теперь мягкое золотисто-белое, почти незаметное */
  box-shadow: 
    0 35px 90px rgba(0,0,0,0.7),
    0 0 18px rgba(212,175,55,0.18),
    0 0 32px rgba(255,255,255,0.08);
}

.ai-chat-modal.closing {
  opacity: 0;
  transform: scale(0.1) translateY(20px);
  transition: 
      opacity 0.38s cubic-bezier(0.4, 0, 0.6, 1),
      transform 0.38s cubic-bezier(0.4, 0, 0.6, 1);
}

/* Полноэкранный режим — плавно */
.ai-chat-modal.fullscreen {
  top: 20px !important;
  left: 20px !important;
  right: 20px !important;
  bottom: 20px !important;
  width: auto !important;
  height: auto !important;
  border-radius: 16px !important;
  transform-origin: center !important;
  transition: 
      all 0.42s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Остальное без изменений */
.ai-chat-header {
  padding: 1rem 1.2rem;
  background: rgba(255,255,255,0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.ai-header-buttons { display: flex; gap: 8px; }

.ai-btn-minimize, .ai-btn-close {
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.3s;
}
.ai-btn-minimize:hover, .ai-btn-close:hover {
  background: rgba(255,255,255,0.25);
}

.ai-chat-body { 
  flex: 1; 
  display: flex; 
  flex-direction: column; 
  min-height: 0; /* ← ДОБАВЛЕНО: чтобы body могло сжиматься, если нужно */
}
.ai-chat-messages {
  flex: 1 1 0%; /* Главный фикс для скролла */
  min-height: 0; /* Критично для nested flex overflow */
  padding: 1rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  scroll-behavior: smooth;
}
.msg {
  max-width: 80%; padding: 0.75rem 1.1rem; border-radius: 18px;
  font-size: 0.94rem; line-height: 1.5; animation: msgFade 0.3s ease-out;
}
.msg.user { 
  align-self: flex-end; 
  background: linear-gradient(135deg, #d4af37, #b8975a); 
  color: #000; 
}
.msg.ai { 
  align-self: flex-start; 
  background: rgba(255,255,255,0.1); 
  color: #fff; 
  border: 1px solid rgba(255,255,255,0.1); 
}

.ai-chat-input {
  display: flex; padding: 0.8rem;
  background: rgba(255,255,255,0.05);
  border-top: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0; /* ← ДОБАВЛЕНО: чтобы input не сжимался и оставался видимым */
}
.ai-chat-input input {
  flex: 1; background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 20px; padding: 0.7rem 1rem;
  color: #fff; font-size: 0.95rem;
}
.ai-chat-input input::placeholder { color: #aaa; }
.ai-chat-input button {
  background: linear-gradient(135deg, #d4af37, #b8975a);
  border: none; width: 40px; height: 40px;
  border-radius: 50%; margin-left: 8px; color: #000;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}

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

/* ==================================================================
   AI РОБОТ-ЮРИСТ — СВЕТЛАЯ ТЕМА (2025) — macOS-стиль + премиум
================================================================== */
html[data-theme="light"] #ai-assistant {
  filter: drop-shadow(0 10px 30px rgba(0,0,0,0.22)) !important;
}

html[data-theme="light"] .ai-robot {
  filter: drop-shadow(0 0 16px rgba(212,175,55,0.35)) !important;
}

html[data-theme="light"] .ai-bubble {
  background: rgba(255,255,255,0.96) !important;
  backdrop-filter: blur(20px) !important;
  border: 1.6px solid rgba(15,15,15,0.18) !important;
  color: #000 !important;
  box-shadow: 0 12px 40px rgba(0,0,0,0.18) !important;
}

html[data-theme="light"] .ai-bubble::after {
  border-top-color: rgba(255,255,255,0.96) !important;
  border-width: 9px !important;
  bottom: -9px !important;
}

/* Основное окно чата */
html[data-theme="light"] .ai-chat-modal {
  background: rgba(255,255,255,0.98) !important;
  backdrop-filter: blur(32px) !important;
  border: 1.8px solid rgba(15,15,15,0.18) !important;
  box-shadow: 
    0 40px 100px rgba(0,0,0,0.22),
    0 15px 40px rgba(0,0,0,0.14),
    0 0 20px rgba(212,175,55,0.12) !important;
}

html[data-theme="light"] .ai-chat-modal.show {
  box-shadow: 
    0 45px 110px rgba(0,0,0,0.25),
    0 0 20px rgba(212,175,55,0.16),
    0 0 40px rgba(0,0,0,0.08) !important;
}

/* Хедер */
html[data-theme="light"] .ai-chat-header {
  background: rgba(15,15,15,0.07) !important;
  border-bottom: 1px solid rgba(15,15,15,0.12) !important;
}

html[data-theme="light"] .ai-btn-minimize,
html[data-theme="light"] .ai-btn-close {
  background: rgba(15,15,15,0.1) !important;
  color: #000 !important;
}
html[data-theme="light"] .ai-btn-minimize:hover,
html[data-theme="light"] .ai-btn-close:hover {
  background: rgba(15,15,15,0.22) !important;
  transform: scale(1.1);
}

/* Сообщения */
html[data-theme="light"] .msg.ai {
  background: rgba(15,15,15,0.08) !important;
  border: 1px solid rgba(15,15,15,0.18) !important;
  color: #000 !important;
}

html[data-theme="light"] .msg.user {
  background: #000 !important;
  color: #fff !important;
}

/* Инпут */
html[data-theme="light"] .ai-chat-input {
  background: rgba(15,15,15,0.05) !important;
  border-top: 1px solid rgba(15,15,15,0.12) !important;
}

html[data-theme="light"] .ai-chat-input input {
  background: rgba(15,15,15,0.08) !important;
  border: 1.6px solid rgba(15,15,15,0.28) !important;
  color: #000 !important;
}
html[data-theme="light"] .ai-chat-input input::placeholder {
  color: rgba(0,0,0,0.55) !important;
}
html[data-theme="light"] .ai-chat-input input:focus {
  outline: none !important;
  border-color: #ff9500 !important;
  background: rgba(15,15,15,0.12) !important;
  box-shadow: 0 0 0 5px rgba(255,149,0,0.14) !important;
}

/* Кнопка отправки — чёрная с белым текстом */
html[data-theme="light"] .ai-chat-input button {
  background: #000 !important;
  color: #fff !important;
}
html[data-theme="light"] .ai-chat-input button:hover {
  background: #333 !important;
  transform: scale(1.1);
}

/* Полноэкранный режим — тоже красиво */
html[data-theme="light"] .ai-chat-modal.fullscreen {
  box-shadow: 
    0 60px 160px rgba(0,0,0,0.28),
    0 0 30px rgba(212,175,55,0.14) !important;
}

/* Надпись "AI Юрист" — ЧЁРНАЯ в светлой теме */
html[data-theme="light"] .ai-bubble,
html[data-theme="light"] .ai-chat-modal {
  color: #000000 !important;
}

/* Если вдруг где-то текст отдельным классом (на всякий случай) */
html[data-theme="light"] .ai-bubble *,
html[data-theme="light"] .ai-chat-modal * {
  color: #000000 !important;
}

/* Специально для заголовка в чате, если там отдельный тег */
html[data-theme="light"] .ai-chat-header,
html[data-theme="light"] .ai-chat-header * {
  color: #000000 !important;
}


/* КНОПКА ОТПРАВКИ В ЧАТЕ AI — СВЕТЛАЯ ТЕМА: БЕЛЫЙ КРУГ + ЧЁРНАЯ СТРЕЛКА */
html[data-theme="light"] .ai-chat-input button {
  background: #ffffff !important;
  color: #000000 !important;
  border: 1.8px solid rgba(15, 15, 15, 0.25) !important;
  box-shadow: 
    0 6px 18px rgba(0, 0, 0, 0.14),
    0 0 0 1px rgba(15, 15, 15, 0.08) inset !important;
  transition: all 0.32s cubic-bezier(0.22, 1, 0.36, 1) !important;
}

html[data-theme="light"] .ai-chat-input button:hover {
  background: #f2f2f2 !important;
  border-color: rgba(15, 15, 15, 0.38) !important;
  transform: translateY(-2px) scale(1.08) !important;
  box-shadow: 
    0 12px 30px rgba(0, 0, 0, 0.22),
    0 0 0 1px rgba(15, 15, 15, 0.12) inset !important;
}

html[data-theme="light"] .ai-chat-input button:active {
  transform: translateY(0) scale(1.02) !important;
}

/* ============================================================= */
/* АДАПТАЦИЯ ЧАТА ПОД КЛАВИАТУРУ — РАБОТАЕТ ВЕЗДЕ (2025 ГОД)     */
/* ============================================================= */


/* ОТКЛЮЧАЕМ ВСЁ ЭТО НА МОБИЛЕ — ЭТО ГЛАВНОЕ! */

/* 100% ГАРАНТИЯ: AI-робот пробивает ВСЁ, даже мобильную корзину */
#ai-assistant,
.ai-bubble {
  z-index: 2147483647 !important;     /* максимальный возможный z-index */
  pointer-events: auto !important;
  touch-action: manipulation !important;
}

/* На всякий случай — если где-то есть overlay с pointer-events */
#mobileCartSheet,
#mobileCartSheet * {
  pointer-events: none !important;
}
#mobileCartSheet.active #mobileCartBackdrop,
#mobileCartSheet.active .sheet-container,
#mobileCartSheet.active .sheet-container * {
  pointer-events: auto !important;
}

/* ====================================================
   AI ЧАТ — МОБИЛЬНАЯ ВЕРСИЯ 2025 (КАК В ТЕЛЕГРАММЕ)
   iPhone + Android + iPad — 100% идеально
=================================================== */
@media (max-width: 1023px) {
  /* Запрещаем зум и двойной тап — ПОЛНОСТЬЮ убирает баг с масштабированием */
  .ai-chat-modal,
  .ai-chat-modal * {
    touch-action: pan-y pinch-zoom !important;
    -ms-touch-action: pan-y pinch-zoom !important;
  }

  /* Основной контейнер — как в Telegram */
  .ai-chat-modal {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    background: rgba(0,0,0,0.92) !important;
    backdrop-filter: blur(32px) !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
    overscroll-behavior: contain; /* важно! */

    /* Начально — скрыто снизу */
    transform: translateY(100dvh);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.54s cubic-bezier(0.22, 0.88, 0.36, 1),
                opacity 0.42s ease;
  }

  .ai-chat-modal.active {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
  }

  /* Полоска сверху — как в Telegram */
  .ai-chat-header {
    padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
    flex-shrink: 0;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
  }

  .ai-chat-header::before {
    content: '';
    position: absolute;
    top: calc(8px + env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 5px;
    background: rgba(255,255,255,0.32);
    border-radius: 3px;
    pointer-events: none;
  }

  html[data-theme="light"] .ai-chat-header::before {
    background: rgba(0,0,0,0.28) !important;
  }

  /* Сообщения — с правильным отступом снизу */
  .ai-chat-messages {
    flex: 1 1 0%;
    min-height: 0;
    padding: 12px 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }

  /* Инпут — фиксирован внизу, поднимается над клавиатурой */
  .ai-chat-input {
    padding: 12px 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    background: transparent !important;
    border-top: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
    transition: padding-bottom 0.3s ease;
  }

  html[data-theme="light"] .ai-chat-input {
    border-top-color: rgba(0,0,0,0.12) !important;
  }

  /* Когда клавиатура открыта — добавляем отступ снизу */
  .ai-chat-modal.keyboard-open .ai-chat-input {
    padding-bottom: calc(env(keyboard-inset-height, 280px) + 16px);
  }

  /* Убираем кнопку минимизации */
  .ai-btn-minimize { display: none !important; }

  /* Робот — чуть выше нижней панели */
  #ai-assistant {
    bottom: calc(92px + env(safe-area-inset-bottom) + 12px) !important;
    right: 16px !important;
    width: 72px !important;
    height: 72px !important;
  }
}


/* === КРИТИЧЕСКИ ВАЖНО: ПОДЪЁМ СТРОКИ ВВОДА НАД КЛАВИАТУРОЙ === */
@media (max-width: 1023px) {
  .ai-chat-input {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 2rem);
    max-width: 480px;
    box-sizing: border-box;
    z-index: 9999;
    background: var(--bg, rgba(0,0,0,0.92));
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 12px 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    transition: bottom 0.32s cubic-bezier(0.22, 0.88, 0.36, 1);
  }

  html[data-theme="light"] .ai-chat-input {
    background: rgba(255,255,255,0.98) !important;
    border-top-color: rgba(0,0,0,0.12) !important;
  }

  /* Когда клавиатура открыта — поднимаем строку ввода */
  .ai-chat-modal.keyboard-open .ai-chat-input {
    bottom: env(keyboard-inset-height, 280px) !important; /* магия 2025 */
  }

  /* По умолчанию — прижата к низу экрана */
  .ai-chat-input {
    bottom: 0 !important;
  }
}

.ai-chat-messages {
scrollbar-width: none; /* Firefox /
-ms-overflow-style: none; / IE/Edge */
}
.ai-chat-messages::-webkit-scrollbar {
display: none; /* Chrome/Safari/Opera */
}

body:has(.ai-chat-modal.fullscreen) #ai-assistant {
display: none !important;
}

