/**
 * mod_maxbutton v2.1.0 (ЮБ Эгида)
 * Плавающие кнопки связи (Телефон, MAX, Telegram, WhatsApp)
 * Обновление: оригинальные SVG, карусельная выразительная анимация по кругу,
 * идеальное выравнивание слева и справа, всплывающие подсказки при hover на ПК,
 * поддержка prefers-reduced-motion и WCAG 2.1
 */

.max-wrap {
  position: fixed;
  bottom: var(--max-bottom, 20px);
  z-index: var(--max-zindex, 99999);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

.max-wrap * {
  box-sizing: border-box;
}

/* Расположение справа (по умолчанию) */
.max-wrap.pos-right {
  right: var(--max-side, 20px);
  left: auto;
  align-items: flex-end;
}

/* Расположение слева: кнопки строго привязаны к левому краю, подсказки выезжают вправо */
.max-wrap.pos-left {
  left: var(--max-side, 20px);
  right: auto;
  align-items: flex-start;
}

/* Контейнер списка кнопок */
.max-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Элемент кнопки: служит якорем для абсолютного позиционирования подсказки */
.max-item {
  position: relative;
  display: flex;
  align-items: center;
}

.max-wrap.pos-right .max-item {
  justify-content: flex-end;
}

.max-wrap.pos-left .max-item {
  justify-content: flex-start;
}

/* Круглая кнопка связи (Оригинальные параметры 42px / 45px на тач) */
.max-btn {
  position: relative;
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.18);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
  text-decoration: none;
  box-sizing: border-box;
  flex-shrink: 0;
  cursor: pointer;
  outline: none;
}

.max-btn:focus-visible {
  outline: 3px solid #6366f1;
  outline-offset: 3px;
}

.max-btn:hover {
  transform: scale(1.10) !important;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.30);
}

.max-btn:active {
  transform: scale(0.95) !important;
}

.max-btn svg {
  display: block;
}

/* Стили отдельных кнопок (1-в-1 оригиналы) */
.max-btn.btn-phone {
  background: #25d366;
}
.max-btn.btn-phone svg {
  width: 65%;
  height: 65%;
}

.max-btn.btn-max {
  background: linear-gradient(135deg, #00d2ff 0%, #5533ee 65%, #9933dd 100%);
  padding: 0;
  overflow: hidden;
}
.max-btn.btn-max svg {
  width: 100%;
  height: 100%;
}

.max-btn.btn-tg {
  background: #229ed9;
}
.max-btn.btn-tg svg {
  width: 66%;
  height: 66%;
  margin-right: 2px;
  margin-top: 1px;
}

.max-btn.btn-wa {
  background: #25d366;
}
.max-btn.btn-wa svg {
  width: 64%;
  height: 64%;
}

/* Белая плашка-подпись (Tooltip) */
.max-label {
  background: #ffffff;
  padding: 8px 18px;
  border-radius: 40px;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.14), 0 1px 4px rgba(0, 0, 0, 0.06);
  font: 500 14px/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #222e3a;
  white-space: nowrap;
  pointer-events: none;
  border: 1px solid rgba(226, 232, 240, 0.85);
  user-select: none;
  z-index: 10;
  will-change: transform, opacity;
}

/* Позиционирование плашки справа и слева (якорное, исключает смещение кнопок) */
.max-wrap.pos-right .max-label {
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
}

.max-wrap.pos-left .max-label {
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
}

/* ==============================================================
   Анимация: последовательная карусель по кругу по всем кнопкам
   ============================================================== */
.max-wrap.anim-expressive .max-carousel-0 { animation: expressiveCarousel 9s infinite 0s ease-in-out; }
.max-wrap.anim-expressive .max-carousel-1 { animation: expressiveCarousel 9s infinite 1.5s ease-in-out; }
.max-wrap.anim-expressive .max-carousel-2 { animation: expressiveCarousel 9s infinite 3.0s ease-in-out; }
.max-wrap.anim-expressive .max-carousel-3 { animation: expressiveCarousel 9s infinite 4.5s ease-in-out; }

@keyframes expressiveCarousel {
  0%, 14%, 100% {
    transform: rotate(0deg) scale(1);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.18);
  }
  3% {
    transform: rotate(-8.5deg) scale(1.07);
    box-shadow: 0 5px 18px rgba(0, 0, 0, 0.26);
  }
  6% {
    transform: rotate(7.5deg) scale(1.09);
    box-shadow: 0 7px 22px rgba(0, 0, 0, 0.30);
  }
  9% {
    transform: rotate(-3.5deg) scale(1.03);
    box-shadow: 0 5px 16px rgba(0, 0, 0, 0.22);
  }
  12% {
    transform: rotate(0deg) scale(1);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.18);
  }
}

/* Классическая оригинальная карусель (масштаб 1.04) */
.max-wrap.anim-classic .max-carousel-0 { animation: gentleCarousel 9s infinite 0s ease-in-out; }
.max-wrap.anim-classic .max-carousel-1 { animation: gentleCarousel 9s infinite 1.5s ease-in-out; }
.max-wrap.anim-classic .max-carousel-2 { animation: gentleCarousel 9s infinite 3.0s ease-in-out; }
.max-wrap.anim-classic .max-carousel-3 { animation: gentleCarousel 9s infinite 4.5s ease-in-out; }

@keyframes gentleCarousel {
  0%, 14%, 100% { transform: rotate(0deg) scale(1); }
  3% { transform: rotate(-7deg) scale(1.04); }
  6% { transform: rotate(6deg) scale(1.04); }
  9% { transform: rotate(-3deg) scale(1.02); }
  12% { transform: rotate(0deg) scale(1); }
}

/* Пауза анимации при наведении на блок для спокойного взаимодействия */
.max-wrap:hover .max-btn {
  animation-play-state: paused;
}

/* ==============================================================
   Режимы отображения на десктопе (экраны от 769px)
   ============================================================== */
@media (min-width: 769px) {
  /* Режим 1: Подписи только при наведении (hover) — РЕКОМЕНДУЕМЫЙ */
  .max-wrap.desktop-hover.pos-right .max-label {
    opacity: 0;
    visibility: hidden;
    transform: translateY(-50%) translateX(10px);
    transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.22s;
  }

  .max-wrap.desktop-hover.pos-left .max-label {
    opacity: 0;
    visibility: hidden;
    transform: translateY(-50%) translateX(-10px);
    transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.22s;
  }

  .max-wrap.desktop-hover .max-item:hover .max-label,
  .max-wrap.desktop-hover .max-btn:focus-visible ~ .max-label,
  .max-wrap.desktop-hover .max-item:focus-within .max-label {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(-50%) translateX(0);
  }

  /* Режим 2: Показывать всегда (классика) */
  .max-wrap.desktop-always .max-label {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(-50%) translateX(0);
  }

  /* Режим 3: Только иконки */
  .max-wrap.desktop-hidden .max-label {
    display: none !important;
  }
}

/* ==============================================================
   Поддержка prefers-reduced-motion (доступность для пользователей)
   ============================================================== */
@media (prefers-reduced-motion: reduce) {
  .max-btn,
  .max-btn[class*="max-carousel-"] {
    animation: none !important;
    transition: none !important;
  }

  .max-wrap.desktop-hover .max-label {
    transform: translateY(-50%) !important;
    transition: opacity 0.12s ease !important;
  }
}

/* ==============================================================
   Мобильные экраны (до 768px включительно)
   Минимальный отступ от края (4px), чтобы кнопки не «съедали» текст сайта
   ============================================================== */
@media (max-width: 768px) {
  .max-wrap.pos-right {
    right: calc(var(--max-side-mob, 4px) + env(safe-area-inset-right, 0px)) !important;
    bottom: calc(var(--max-bottom-mob, 14px) + env(safe-area-inset-bottom, 0px)) !important;
  }

  .max-wrap.pos-left {
    left: calc(var(--max-side-mob, 4px) + env(safe-area-inset-left, 0px)) !important;
    bottom: calc(var(--max-bottom-mob, 14px) + env(safe-area-inset-bottom, 0px)) !important;
  }

  .max-label {
    display: none !important;
  }

  .max-list {
    gap: 6px !important;
  }

  .max-btn {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.16) !important;
  }

  /* Режим FAB (кнопка-раскладушка на смартфонах) */
  .max-wrap.mobile-fab .max-list {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(16px) scale(0.92);
    transform-origin: bottom center;
    transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.22s;
  }

  .max-wrap.mobile-fab.is-open .max-list {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
  }

  .max-fab-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #ffffff;
    border: none;
    box-shadow: 0 4px 18px rgba(79, 70, 229, 0.4);
    cursor: pointer;
    margin-top: 6px;
    transition: transform 0.2s ease, background 0.2s ease;
  }

  .max-fab-trigger:active {
    transform: scale(0.93);
  }

  .max-fab-icon-close {
    display: none;
  }

  .max-wrap.mobile-fab.is-open .max-fab-icon-chat {
    display: none;
  }

  .max-wrap.mobile-fab.is-open .max-fab-icon-close {
    display: block;
  }
}

@media (min-width: 769px) {
  .max-fab-trigger {
    display: none !important;
  }
}
