/* ─────────────────────────────────────────────────────────
   iBoto AI Chat Widget — Character Launcher
   ───────────────────────────────────────────────────────── */

:root {
  --saa-purple:    #9B8FE0;
  --saa-purple-dk: #6B5CE7;
  --saa-purple-2:  #7B9FD4;
  --saa-yellow:    #FFD000;
  --saa-yellow-dk: #E6BA00;
  --saa-bg:        #F3F1FF;
  --saa-white:     #ffffff;
  --saa-text:      #2D2060;
  --saa-muted:     #7B7AAD;
  --saa-border:    #DDD8F8;
  --saa-font:      'Nunito', 'Segoe UI', system-ui, Arial, sans-serif;
}

#saa-widget {
  position: fixed;
  left: 24px;
  bottom: 20px;
  z-index: 999999;
  font-family: var(--saa-font);
}

#saa-widget * {
  box-sizing: border-box;
}

/* ─── LAUNCHER (персонаж) ─── */

.saa-launcher {
  position: relative;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  filter: drop-shadow(0 8px 24px rgba(107,92,231,0.30));
  transition: filter 0.3s ease;
}

.saa-launcher:hover {
  filter: drop-shadow(0 12px 32px rgba(107,92,231,0.50));
}

/* Персонаж (PNG) */
.saa-char {
  width: 90px;
  height: 106px;
  display: block;
  object-fit: contain;
  animation: saaCharFloat 3s ease-in-out infinite;
  transform-origin: bottom center;
}

@keyframes saaCharFloat {
  0%,100% { transform: translateY(0);    }
  50%      { transform: translateY(-6px); }
}

/* Анимация машущей руки — убрана (используется PNG-персонаж) */

/* ─── ОБЛАЧКО "Нужна помощь?" ─── */

.saa-bubble-hint {
  position: absolute;
  bottom: 108px;
  left: 72px;
  background: var(--saa-white);
  color: var(--saa-text);
  font-size: 13px;
  font-weight: 700;
  font-family: var(--saa-font);
  white-space: nowrap;
  padding: 8px 14px;
  border-radius: 18px 18px 18px 4px;
  box-shadow:
    0 4px 16px rgba(107,92,231,0.18),
    0 1px 4px rgba(107,92,231,0.10);
  border: 1.5px solid rgba(107,92,231,0.14);
  pointer-events: none;

  /* Анимация появления */
  animation: saoBubbleIn 0.5s cubic-bezier(0.22,1,0.36,1) both,
             saoBubblePulse 4s ease-in-out 1s infinite;
  transform-origin: left bottom;
}

/* Хвостик облачка */
.saa-bubble-hint::before {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 14px;
  width: 14px;
  height: 10px;
  background: var(--saa-white);
  clip-path: polygon(0 0, 100% 0, 0 100%);
  border-left: 1.5px solid rgba(107,92,231,0.14);
  border-bottom: 1.5px solid rgba(107,92,231,0.14);
}

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

@keyframes saoBubblePulse {
  0%,90%,100% { transform: scale(1); }
  95%          { transform: scale(1.04); }
}

/* Скрываем облачко когда панель открыта */
.saa-launcher[aria-expanded="true"] .saa-bubble-hint {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s, visibility 0.2s;
}

/* ─── ПАНЕЛЬ ЧАТА ─── */

.saa-panel {
  position: fixed;
  left: 125px;
  bottom: 148px;
  width: 420px;
  min-width: 300px;
  max-width: calc(100vw - 40px);
  height: 600px;
  min-height: 360px;
  max-height: calc(100vh - 170px);
  background: var(--saa-white);
  border-radius: 24px;
  box-shadow:
    0 2px 6px rgba(107,92,231,0.06),
    0 10px 30px rgba(107,92,231,0.14),
    0 36px 72px rgba(107,92,231,0.14),
    0 72px 110px rgba(60,40,140,0.10);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 1000000;
  animation: saaPanelIn 0.32s cubic-bezier(0.22,1,0.36,1) both;
  border: 1px solid rgba(155,143,224,0.20);
  resize: both;
  /* Переопределяем overflow чтобы resize работал */
  overflow: auto;
}

/* Ручка ресайза — кастомный уголок */
.saa-panel::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 18px;
  height: 18px;
  cursor: se-resize;
  background:
    linear-gradient(
      135deg,
      transparent 0%,
      transparent 40%,
      rgba(155,143,224,0.35) 40%,
      rgba(155,143,224,0.35) 50%,
      transparent 50%,
      transparent 60%,
      rgba(155,143,224,0.35) 60%,
      rgba(155,143,224,0.35) 70%,
      transparent 70%
    );
  border-radius: 0 0 24px 0;
  pointer-events: none;
  z-index: 10;
}

/* Внутренние элементы панели не должны вылезать */
.saa-panel[hidden] {
  display: none;
}

.saa-panel .saa-panel__header,
.saa-panel .saa-contacts,
.saa-panel .saa-form {
  flex-shrink: 0;
  overflow: hidden;
}

.saa-panel .saa-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

@keyframes saaPanelIn {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

/* ─── HEADER ─── */

.saa-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(130deg, #6B5CE7 0%, #9B8FE0 55%, #7B9FD4 100%);
  color: #fff;
  padding: 16px 18px;
  gap: 12px;
  flex: 0 0 auto;
  position: relative;
  overflow: hidden;
}

.saa-panel__header::before {
  content: '';
  position: absolute;
  top: -50px; right: -30px;
  width: 160px; height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.12) 0%, transparent 70%);
  pointer-events: none;
}

.saa-panel__header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.18), transparent);
}

.saa-panel__person {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 auto;
  position: relative;
  z-index: 1;
}

.saa-panel__avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 40px;
  border: 2px solid rgba(255,255,255,0.35);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.10), 0 4px 10px rgba(0,0,0,0.16);
}

.saa-panel__avatar--fallback {
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.18);
  color: #fff; font-weight: 800; font-size: 16px;
}

.saa-panel__meta  { min-width: 0; }

.saa-panel__title {
  font-size: 14px; font-weight: 800; line-height: 1.2;
}

.saa-panel__subtitle {
  font-size: 12px; font-weight: 600; opacity: 0.85;
  margin-top: 2px;
  display: flex; align-items: center; gap: 5px;
}

.saa-panel__subtitle::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #7AFF8B;
  box-shadow: 0 0 0 2px rgba(122,255,139,0.22), 0 0 9px rgba(122,255,139,0.6);
  flex-shrink: 0;
  animation: saaPulse 2.5s ease-in-out infinite;
}

@keyframes saaPulse {
  0%,100% { box-shadow: 0 0 0 2px rgba(122,255,139,0.22), 0 0 9px rgba(122,255,139,0.6); }
  50%     { box-shadow: 0 0 0 4px rgba(122,255,139,0.10), 0 0 15px rgba(122,255,139,0.4); }
}

.saa-panel__header-actions {
  display: flex; align-items: center; gap: 7px;
  flex: 0 0 auto; position: relative; z-index: 1;
}

.saa-panel__support-btn {
  background: rgba(255,255,255,0.16);
  border: 1px solid rgba(255,255,255,0.30);
  color: #fff;
  padding: 6px 11px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 12px; font-weight: 700; font-family: var(--saa-font);
  line-height: 1; min-height: 30px;
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 5px;
  white-space: nowrap;
  transition: background 0.2s, border-color 0.2s;
}

.saa-panel__support-btn:hover {
  background: rgba(255,255,255,0.26);
  border-color: rgba(255,255,255,0.45);
}

.saa-panel__close {
  background: transparent; border: 0;
  color: rgba(255,255,255,0.75);
  line-height: 1; cursor: pointer; padding: 0;
  border-radius: 8px;
  transition: color 0.2s, background 0.2s;
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; font-size: 15px;
}

.saa-panel__close:hover {
  color: #fff; background: rgba(255,255,255,0.15);
}

/* ─── MESSAGES ─── */

.saa-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 14px 8px;
  background: var(--saa-bg);
  scroll-behavior: smooth;
}

.saa-messages::-webkit-scrollbar { width: 4px; }
.saa-messages::-webkit-scrollbar-track { background: transparent; }
.saa-messages::-webkit-scrollbar-thumb {
  background: rgba(155,143,224,0.28); border-radius: 4px;
}

.saa-message {
  display: flex; gap: 8px;
  margin-bottom: 12px;
  align-items: flex-end;
  animation: saaMsgIn 0.28s cubic-bezier(0.22,1,0.36,1) both;
}

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

.saa-message--user { justify-content: flex-end; }
.saa-message--user .saa-message__avatar-wrap { display: none; }
.saa-message__avatar-wrap { flex: 0 0 30px; }

.saa-message__avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  object-fit: cover;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 30px;
  border: 2px solid rgba(155,143,224,0.22);
}

.saa-message__avatar--fallback {
  background: linear-gradient(135deg, var(--saa-purple-dk), var(--saa-purple));
  color: #fff; font-weight: 800; font-size: 12px;
}

.saa-bubble {
  max-width: 82%;
  padding: 11px 14px;
  border-radius: 16px 16px 16px 4px;
  background: var(--saa-white);
  color: var(--saa-text);
  box-shadow: 0 1px 3px rgba(107,92,231,0.07), 0 4px 12px rgba(107,92,231,0.08);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.56;
  font-size: 13.5px;
  border: 1px solid rgba(155,143,224,0.16);
}

.saa-message--user .saa-bubble {
  background: linear-gradient(135deg, #6B5CE7 0%, #9B8FE0 100%);
  color: #fff;
  box-shadow: 0 4px 16px rgba(107,92,231,0.34);
  border: 0;
  border-radius: 16px 16px 4px 16px;
}

/* ─── TYPING ─── */

.saa-typing {
  display: inline-flex; gap: 5px;
  align-items: center; padding: 3px 0;
}

.saa-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--saa-purple); opacity: 0.35;
  animation: saaTypingBlink 1.3s infinite ease-in-out;
}
.saa-typing span:nth-child(2) { animation-delay: 0.16s; }
.saa-typing span:nth-child(3) { animation-delay: 0.32s; }

@keyframes saaTypingBlink {
  0%,80%,100% { opacity: 0.30; transform: translateY(0); }
  40%         { opacity: 1;    transform: translateY(-4px); }
}

/* ─── CONTACTS ─── */

.saa-contacts {
  padding: 9px 16px;
  border-top: 1px solid var(--saa-border);
  background: #FAF8FF;
  font-size: 12px;
  flex: 0 0 auto;
  color: var(--saa-muted);
}

.saa-contacts__item {
  display: flex; align-items: center; gap: 7px;
}
.saa-contacts__item + .saa-contacts__item { margin-top: 4px; }
.saa-contacts__item i { color: var(--saa-purple); width: 13px; text-align: center; font-size: 12px; flex-shrink: 0; }
.saa-contacts a { color: var(--saa-purple-dk); text-decoration: none; font-weight: 700; }
.saa-contacts a:hover { text-decoration: underline; }

/* ─── FORM ─── */

.saa-form {
  border-top: 1px solid var(--saa-border);
  padding: 10px 12px;
  background: var(--saa-white);
  flex: 0 0 auto;
}

.saa-input {
  width: 100%; display: block;
  resize: none; min-height: 42px; max-height: 160px;
  height: 42px;
  border: 1.5px solid var(--saa-border);
  border-radius: 12px;
  padding: 10px 13px;
  outline: none;
  font: inherit; font-size: 13.5px;
  background: #F9F7FF;
  color: var(--saa-text);
  transition: border-color 0.25s, background 0.25s, box-shadow 0.25s;
  line-height: 1.5;
  overflow-y: hidden;
}

.saa-input:focus {
  border-color: var(--saa-purple);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(155,143,224,0.18);
}

.saa-input::placeholder { color: #B2ABDA; }

.saa-actions {
  margin-top: 8px;
  display: flex; justify-content: flex-end;
}

.saa-send {
  background: var(--saa-yellow);
  color: #2D2060;
  border: 0; border-radius: 11px;
  padding: 10px 20px;
  cursor: pointer;
  font: inherit; font-weight: 800; font-size: 13px;
  display: inline-flex; align-items: center; gap: 7px;
  box-shadow: 0 4px 14px rgba(255,208,0,0.38);
  transition: background 0.2s, box-shadow 0.2s, transform 0.15s;
}

.saa-send:hover {
  background: var(--saa-yellow-dk);
  box-shadow: 0 6px 20px rgba(255,208,0,0.52);
  transform: translateY(-1px);
}

.saa-send:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(255,208,0,0.30);
}

/* ─── RICH TEXT ─── */

.saa-rich-p            { margin: 0 0 8px; }
.saa-rich-p:last-child { margin-bottom: 0; }
.saa-rich-h            { margin: 8px 0 5px; font-size: 13.5px; font-weight: 800; color: var(--saa-purple-dk); }
.saa-rich-list         { margin: 0 0 8px 16px; padding: 0; }
.saa-rich-ol           { margin: 0 0 8px 18px; padding: 0; }
.saa-rich-list li,
.saa-rich-ol li        { margin: 0 0 4px; line-height: 1.5; }
.saa-rich-space        { height: 5px; }
.saa-bubble strong     { font-weight: 800; }
.saa-bubble em         { font-style: italic; }

/* ─── SUPPORT CARD ─── */

.saa-support-card {
  background: var(--saa-white);
  border: 1.5px solid var(--saa-border);
  border-radius: 16px;
  padding: 14px 16px;
  margin: 4px 0 12px;
  box-shadow: 0 4px 16px rgba(107,92,231,0.10);
  animation: saaMsgIn 0.28s cubic-bezier(0.22,1,0.36,1) both;
}

.saa-support-card__title {
  font-weight: 800; font-size: 13.5px; color: var(--saa-purple-dk);
  margin-bottom: 5px;
  display: flex; align-items: center; gap: 6px;
}
.saa-support-card__title i { font-size: 15px; color: var(--saa-purple); }
.saa-support-card__text { font-size: 12px; color: var(--saa-muted); margin: 0 0 10px; }
.saa-support-card__btns { display: flex; flex-direction: column; gap: 7px; }

.saa-support-btn {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 14px; border-radius: 11px;
  text-decoration: none;
  font-size: 13px; font-weight: 600; font-family: var(--saa-font);
  transition: transform 0.15s, box-shadow 0.2s;
}
.saa-support-btn:hover { transform: translateY(-1px); }

.saa-support-btn--tg {
  background: #229ED9; color: #fff;
  box-shadow: 0 4px 12px rgba(34,158,217,0.32);
}
.saa-support-btn--tg:hover { box-shadow: 0 6px 18px rgba(34,158,217,0.48); }
.saa-support-btn--tg i { font-size: 18px; }

.saa-support-btn--max {
  background: linear-gradient(135deg, var(--saa-purple-dk) 0%, var(--saa-purple) 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(107,92,231,0.32);
}
.saa-support-btn--max:hover { box-shadow: 0 6px 18px rgba(107,92,231,0.48); }
.saa-support-btn--max i { font-size: 16px; }
.saa-support-btn span   { line-height: 1.3; }
.saa-support-btn strong { font-weight: 800; }

/* ─── MOBILE ─── */

@media (max-width: 600px) {
  #saa-widget {
    left: 12px;
    bottom: 14px;
  }

  .saa-char {
    width: 74px; height: 87px;
  }

  .saa-bubble-hint {
    font-size: 12px;
    padding: 7px 11px;
    bottom: 90px;
    left: 60px;
  }

  .saa-panel {
    left: 10px;
    right: 10px;
    bottom: 110px;
    width: auto;
    min-width: 0;
    max-width: none;
    height: 72vh;
    min-height: 380px;
    max-height: 72vh;
    border-radius: 20px;
    animation: saaPanelIn 0.28s cubic-bezier(0.22,1,0.36,1) both;
  }

  .saa-bubble { max-width: 88%; }
  .saa-send   { padding: 10px 16px; }
}

:is(.btn,.button,button,[type=submit],[type=button]) {background-color: transparent !important;}

:root textarea { min-height: 60px !important;}