/* ==========================================================================
   ИИ-помощник детского сада № 2 — оформление
   Подключается только если помощник включён: Внешний вид → Настроить → «ИИ-помощник».
   Цвета берутся из переменных, которые выводит inc/ai-assistant.php
   (по умолчанию — фирменный жёлтый).
   ========================================================================== */

.sad2-ai-widget {
  --sad2-accent: #FFE01B;
  --sad2-accent-rgb: 255, 224, 27;
  --sad2-accent-ink: #1F2937;
  --sad2-accent-dark: #EAB308;
  --sad2-accent-border: #F2C91D;
  --sad2-accent-soft: #FFF3A1;
  --sad2-accent-faint: #FFFBE0;
  --sad2-accent-hover: #F2CE00;
  --sad2-gap: 20px;
}

.sad2-ai-widget * {
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

.sad2-ai-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--sad2-accent);
  border: 2px solid #FFFFFF;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  z-index: 99998;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  padding: 0;
  animation: sad2-fab-pulse 2.4s ease-in-out infinite;
}

.sad2-ai-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  animation: none;
}

.sad2-ai-fab.is-open-fab {
  animation: none;
}

@keyframes sad2-fab-pulse {
  0%, 100% {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2), 0 0 0 0 rgba(var(--sad2-accent-rgb), 0.55);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2), 0 0 0 14px rgba(var(--sad2-accent-rgb), 0);
    transform: scale(1.04);
  }
}

.sad2-ai-fab svg {
  width: 34px;
  height: 34px;
}

.sad2-ai-window {
  position: fixed;
  right: 20px;
  bottom: 92px;
  width: 380px;
  max-width: calc(100vw - 24px);
  height: 560px;
  max-height: calc(100vh - 110px);
  background: #FFFFFF;
  border-radius: 18px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 99999;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.sad2-ai-window.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.sad2-ai-window.is-dragging {
  transition: none !important;
  user-select: none;
}

.sad2-ai-window.is-maximized {
  right: 0 !important;
  bottom: 0 !important;
  left: 0 !important;
  top: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  border-radius: 0 !important;
  transform: none !important;
}

.sad2-ai-header {
  cursor: grab;
}

.sad2-ai-header:active {
  cursor: grabbing;
}

.sad2-ai-window.is-maximized .sad2-ai-header {
  cursor: default;
}

.sad2-ai-header-actions {
  cursor: default;
}

.sad2-ai-header-actions * {
  cursor: pointer;
}

.sad2-ai-header {
  background: var(--sad2-accent);
  color: var(--sad2-accent-ink);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sad2-ai-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sad2-ai-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.sad2-ai-avatar svg {
  width: 26px;
  height: 26px;
}

.sad2-ai-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
}

.sad2-ai-status {
  font-size: 12px;
  color: var(--sad2-accent-ink);
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.sad2-ai-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #16A34A;
  display: inline-block;
  animation: sad2-pulse 2s infinite;
}

@keyframes sad2-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.sad2-ai-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sad2-ai-icon-btn {
  background: rgba(255, 255, 255, 0.55);
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sad2-accent-ink);
  font-size: 16px;
  transition: background 0.15s ease;
  padding: 0;
}

.sad2-ai-icon-btn .sad2-ai-max-icon {
  display: block;
  flex-shrink: 0;
}

.sad2-ai-icon-btn:hover {
  background: rgba(255, 255, 255, 0.9);
}

.sad2-ai-messages {
  flex: 1;
  padding: 14px;
  overflow-y: auto;
  background: #FFFFFF;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.sad2-ai-msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  color: #1F2937;
  word-wrap: break-word;
}

.sad2-ai-msg a {
  color: #B45309;
  font-weight: 600;
  text-decoration: underline;
}

.sad2-ai-msg code {
  background: #F3F4F6;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.sad2-ai-msg--bot {
  align-self: flex-start;
  background: #F2F3F5;
  border-bottom-left-radius: 4px;
}

.sad2-ai-msg--user {
  align-self: flex-end;
  background: var(--sad2-accent-soft);
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.sad2-ai-typing {
  align-self: flex-start;
  background: #F2F3F5;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 5px;
  max-width: 88%;
}

.sad2-ai-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9CA3AF;
  animation: sad2-typing 1.4s infinite ease-in-out both;
}

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

@keyframes sad2-typing {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.45; }
  40% { transform: scale(1); opacity: 1; }
}

.sad2-ai-typing-label {
  font-size: 12px;
  color: #6B7280;
  margin-left: 4px;
}

.sad2-ai-chips {
  padding: 8px 12px 10px;
  background: #FFFFFF;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
  border-top: 1px solid #F3F4F6;
  max-height: 110px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sad2-ai-chip {
  background: #FFFFFF;
  border: 1.5px solid var(--sad2-accent-border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  line-height: 1.3;
  color: #1F2937;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s;
  white-space: nowrap;
  flex: 0 1 auto;
  max-width: 100%;
}

.sad2-ai-chip:hover {
  background: var(--sad2-accent-faint);
  border-color: var(--sad2-accent-dark);
}

.sad2-ai-chip:active {
  transform: scale(0.97);
}

@media (max-width: 400px) {
  .sad2-ai-chip {
    font-size: 11.5px;
    padding: 5px 10px;
  }
  .sad2-ai-chips {
    max-height: 120px;
    gap: 5px;
  }
}

.sad2-ai-input-area {
  padding: 10px 12px;
  border-top: 1px solid #E5E7EB;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.sad2-ai-input {
  flex: 1;
  border: 1px solid #D1D5DB;
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 14px;
  outline: none;
  color: #1F2937;
  transition: border-color 0.15s ease;
}

.sad2-ai-input:focus {
  border-color: var(--sad2-accent-dark);
}

.sad2-ai-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--sad2-accent);
  color: var(--sad2-accent-ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, opacity 0.15s;
  padding: 0;
}

.sad2-ai-send:hover {
  background: var(--sad2-accent-hover);
}

.sad2-ai-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sad2-ai-send svg {
  width: 18px;
  height: 18px;
}

.sad2-ai-footer-hint {
  font-size: 10px;
  color: #9CA3AF;
  text-align: center;
  padding: 4px 10px 6px;
  background: #FAFAFA;
  border-top: 1px solid #F3F4F6;
}

@media (max-width: 480px) {
  .sad2-ai-fab {
    right: 14px;
    bottom: 14px;
    width: 54px;
    height: 54px;
  }
  .sad2-ai-window {
    right: 12px;
    bottom: 78px;
    width: calc(100vw - 24px);
    height: 76vh;
  }
}

/* ==========================================================================
   ИНТЕГРАЦИЯ С ТЕМОЙ
   ========================================================================== */

/* Слои: ниже cookie-плашки (9999) и панели для слабовидящих (99999),
   выше обычного содержимого и кнопки «Наверх» (1000). */
.sad2-ai-fab    { z-index: 9990; }
.sad2-ai-window { z-index: 9991; }

/* Глобальные правила темы (a:hover{transform}, p{color,font-size}) не должны
   «протекать» в виджет. */
.sad2-ai-widget a,
.sad2-ai-widget a:hover { transform: none; transition: none; }
.sad2-ai-widget .sad2-ai-msg a:hover { color: #92400E; }
.sad2-ai-widget p { margin: 0; font-size: inherit; color: inherit; }
.sad2-ai-widget button { font-family: inherit; }
.sad2-ai-widget .sad2-ai-title { color: var(--sad2-accent-ink); }

/* Окно: учитываем адресную строку мобильных браузеров и «чёлку» */
.sad2-ai-window {
  max-height: calc(100vh - 110px);
  max-height: calc(100dvh - 110px);
}
.sad2-ai-window.is-maximized {
  height: 100vh !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
}
.sad2-ai-fab    { bottom: calc(var(--sad2-gap) + env(safe-area-inset-bottom, 0px)); }
.sad2-ai-window { bottom: calc(var(--sad2-gap) + 72px + env(safe-area-inset-bottom, 0px)); }

/* Фокус с клавиатуры */
.sad2-ai-widget button:focus-visible,
.sad2-ai-widget .sad2-ai-input:focus-visible {
  outline: 3px solid var(--sad2-accent-dark);
  outline-offset: 2px;
}

/* Позиция: справа (по умолчанию) или слева */
.sad2-ai-widget.is-left .sad2-ai-fab    { right: auto; left: var(--sad2-gap); }
.sad2-ai-widget.is-left .sad2-ai-window { right: auto; left: var(--sad2-gap); }

/* Кнопка «Наверх» темы лежит в том же углу — поднимаем её над кнопкой помощника */
body.sad2-ai-right .scroll-top { bottom: 92px; }

/* Телефоны */
@media (max-width: 480px) {
  .sad2-ai-widget { --sad2-gap: 14px; }
  .sad2-ai-window {
    width: calc(100vw - 24px);
    height: 76vh;
    height: 76dvh;
    right: 12px;
    bottom: calc(var(--sad2-gap) + 66px + env(safe-area-inset-bottom, 0px));
  }
  .sad2-ai-widget.is-left .sad2-ai-window { left: 12px; right: auto; }
  /* 16px — иначе iOS увеличивает страницу при фокусе в поле ввода */
  .sad2-ai-input { font-size: 16px; }
  body.sad2-ai-right .scroll-top { bottom: 80px; }
}

/* Настройка «Не показывать на телефонах» */
@media (max-width: 768px) {
  .sad2-ai-widget.is-hidden-mobile { display: none !important; }
  body.sad2-ai-hide-mobile .scroll-top { bottom: 20px; }
}

/* Пользователям, которым неприятна анимация */
@media (prefers-reduced-motion: reduce) {
  .sad2-ai-fab,
  .sad2-ai-status-dot { animation: none !important; }
  .sad2-ai-window { transition: none; }
  .sad2-ai-messages { scroll-behavior: auto; }
}

/* При печати чат не нужен */
@media print { .sad2-ai-widget { display: none !important; } }
