/* ==========================================================================
   Sunme Contact Widget — G5T (plugin riêng, không phụ thuộc theme).
   Nút chính tròn góc phải dưới, đỏ Sunme #C00511 (đổi được trong cài
   đặt qua --scw-main / --scw-main-rgb in từ PHP), vòng sáng lan tỏa
   2 lớp lệch pha. Bấm mở: tối đa 6 nút kênh xếp dọc phía trên
   (Fanpage, Zalo, Telegram, TikTok, Messenger, Hotline — G5T-B)
   xuất hiện so le theo vị trí; nút chính đổi icon bong bóng
   thành X (chính nó là nút đóng, đúng mẫu khokhoahoc).
   Kích thước: desktop nút chính 56px / kênh 52px; mobile (<=767px)
   52px / 48px, sát mép 12px (cùng quy ước nút nổi của theme).
   Nút back-to-top của theme xếp chồng PHÍA TRÊN widget này (xem
   theme components/floating.css); khi widget mở, theme ẩn tạm
   back-to-top (html.scw-open) để kênh không đè lên nút đó.
   ========================================================================== */

.scw-widget {
  --scw-main-size: 56px;
  --scw-btn-size: 52px;
  --scw-gap: 12px;
  --scw-edge: 16px;
  --scw-bottom: 24px;
  position: fixed;
  right: var(--scw-edge);
  bottom: var(--scw-bottom);
  z-index: 1200; /* = --z-to-top của theme (cụm nút nổi cũ). */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--scw-gap);
  transition: opacity 300ms ease, visibility 300ms ease;
  /* G5T (C11): khung bao cao ~312px, phủ cả vị trí nút back-to-top
     của theme — KHÔNG được chặn click. Chỉ nút thật nhận click:
     .scw-main luôn auto, .scw-channels auto chỉ khi mở. Nút con
     pointer-events:auto vẫn nhận click dù cha none (chuẩn CSS). */
  pointer-events: none;
}

/* G5Q (theme): ẩn widget khi menu mobile mở — cùng luật với cụm nút
   nổi cũ (html.sunme-nav-open do modules/mobile-menu.js gắn). */
html.sunme-nav-open .scw-widget {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* G5 (theme): mờ widget khi dòng bản quyền footer vào tầm nhìn —
   back-to-top.js gắn .is-footer-hidden (đã đổi selector sang
   .scw-widget ở G5T). */
.scw-widget.is-footer-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* --- Cụm nút kênh (ẩn khi đóng, hiện so le khi mở) --- */

.scw-channels {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--scw-gap);
  /* G5T: khi ĐÓNG, container trong suốt (nút con visibility:hidden
     vẫn chiếm layout ~180-360px) KHÔNG được chặn click nút
     back-to-top của theme nằm ngay phía trên — lỗi bắt được ở
     g5t-verify (Playwright: #scwChannels intercepts pointer events).
     Nút con vẫn tự toggle pointer-events như cũ. */
  pointer-events: none;
}

.scw-widget.is-open .scw-channels {
  pointer-events: auto;
}

.scw-btn {
  width: var(--scw-btn-size);
  height: var(--scw-btn-size);
  border-radius: 50%;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 8px 20px rgba(20, 0, 2, 0.22);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.8);
  pointer-events: none;
  transition: opacity 300ms ease, transform 300ms ease, visibility 300ms ease;
}

/* Màu kênh (G5T-B, theo chỉ định của Lobe 23:32): Messenger ĐỎ
   #C00511 thay gradient thương hiệu; Hotline đỏ đặc #C00511. */
.scw-btn--fanpage {
  background-color: #1877f2;
}

.scw-btn--zalo {
  background-color: #0068ff; /* = --zalo-blue của theme. */
}

.scw-btn--telegram {
  background-color: #229ed9;
}

.scw-btn--tiktok {
  background-color: #000000;
}

.scw-btn--messenger {
  background-color: #c00511;
}

.scw-btn--hotline {
  background-color: #c00511;
}

.scw-widget.is-open .scw-btn {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* So le theo VỊ TRÍ trong cụm (nth-child), không theo kênh — đúng
   với mọi thứ tự hiển thị (channel_order) và mọi số kênh (tối đa 6).
   Khi ĐÓNG: gấp từ trên xuống (nút trên cùng trước). */
.scw-channels .scw-btn:nth-child(1) { transition-delay: 0ms; }
.scw-channels .scw-btn:nth-child(2) { transition-delay: 60ms; }
.scw-channels .scw-btn:nth-child(3) { transition-delay: 120ms; }
.scw-channels .scw-btn:nth-child(4) { transition-delay: 180ms; }
.scw-channels .scw-btn:nth-child(5) { transition-delay: 240ms; }
.scw-channels .scw-btn:nth-child(6) { transition-delay: 300ms; }

/* Khi MỞ: bung từ dưới lên (nút sát nút chính trước). */
.scw-widget.is-open .scw-channels .scw-btn:nth-last-child(1) { transition-delay: 0ms; }
.scw-widget.is-open .scw-channels .scw-btn:nth-last-child(2) { transition-delay: 60ms; }
.scw-widget.is-open .scw-channels .scw-btn:nth-last-child(3) { transition-delay: 120ms; }
.scw-widget.is-open .scw-channels .scw-btn:nth-last-child(4) { transition-delay: 180ms; }
.scw-widget.is-open .scw-channels .scw-btn:nth-last-child(5) { transition-delay: 240ms; }
.scw-widget.is-open .scw-channels .scw-btn:nth-last-child(6) { transition-delay: 300ms; }

.scw-btn:hover {
  transform: translateY(-2px);
  color: #ffffff;
  text-decoration: none;
}

.scw-btn--fanpage:hover {
  background-color: #0e62d6;
}

.scw-btn--zalo:hover {
  background-color: #0052cc; /* = --zalo-blue-dark. */
}

.scw-btn--telegram:hover {
  background-color: #1b87bb;
}

.scw-btn--tiktok:hover {
  background-color: #262626;
}

.scw-btn--messenger:hover,
.scw-btn--hotline:hover {
  background-color: #9e0410;
}

.scw-btn .scw-icon {
  width: 26px;
  height: 26px;
}

/* Zalo dùng chữ (đúng mark của Zalo, đọc rõ ở cỡ nhỏ). */
.scw-zalo-text {
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
}

/* --- Nút chính --- */

.scw-main {
  position: relative;
  width: var(--scw-main-size);
  height: var(--scw-main-size);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background-color: var(--scw-main, #c00511);
  color: #ffffff;
  box-shadow: 0 10px 30px rgba(var(--scw-main-rgb, 192, 5, 17), 0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  /* G5T (C11): cha .scw-widget pointer-events:none nên nút chính
     phải tự bật lại — nếu không nút chính cũng không bấm được. */
  pointer-events: auto;
}

.scw-main:hover {
  filter: brightness(1.08);
}

/* Vòng sáng lan tỏa: 2 vòng lệch pha nửa chu kỳ (2.4s, vòng sau chậm
   1.2s) — hiệu ứng hào quang như mẫu khokhoahoc. Chỉ chạy khi widget
   ĐÓNG (mở rồi thì không cần thu hút nữa).
   Dùng box-shadow spread (KHÔNG dùng transform scale): bóng không
   tạo overflow — vòng scale 1.9 sẽ tràn 11px ra ngoài viewport ở
   390px vì nút chỉ cách mép 12px, gây thanh cuộn ngang. */
.scw-main::before,
.scw-main::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(var(--scw-main-rgb, 192, 5, 17), 0.45);
  pointer-events: none;
  animation: scw-pulse 2.4s ease-out infinite;
}

.scw-main::after {
  animation-delay: 1.2s;
}

@keyframes scw-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(var(--scw-main-rgb, 192, 5, 17), 0.45);
  }

  100% {
    box-shadow: 0 0 0 18px rgba(var(--scw-main-rgb, 192, 5, 17), 0);
  }
}

.scw-widget.is-open .scw-main::before,
.scw-widget.is-open .scw-main::after {
  animation: none;
  opacity: 0;
}

/* Tắt hiệu ứng phát sáng trong cài đặt: ẩn hẳn 2 vòng. */
.scw-widget--no-glow .scw-main::before,
.scw-widget--no-glow .scw-main::after {
  display: none;
}

/* Tạm dừng vòng sáng khi tab bị ẩn (tiết kiệm CPU; widget fixed nên
   không bao giờ ra ngoài màn hình — không dùng IntersectionObserver). */
.scw-widget.scw-paused .scw-main::before,
.scw-widget.scw-paused .scw-main::after {
  animation-play-state: paused;
}

/* Đổi icon bong bóng <-> X: xoay + mờ dần 300ms. */
.scw-main__icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 300ms ease, transform 300ms ease;
}

.scw-main__icon .scw-icon {
  width: 26px;
  height: 26px;
}

.scw-main__icon--close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
}

.scw-widget.is-open .scw-main__icon--chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.6);
}

.scw-widget.is-open .scw-main__icon--close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

/* Focus rõ ràng cho bàn phím (vòng trắng + vòng đỏ Sunme). */
.scw-main:focus-visible,
.scw-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px #ffffff, 0 0 0 6px rgba(var(--scw-main-rgb, 192, 5, 17), 0.55);
}

/* --- Mobile (<= 767px): nút gọn lại, sát mép 12px --- */

@media (max-width: 767px) {
  .scw-widget {
    --scw-main-size: 52px;
    --scw-btn-size: 48px;
    --scw-gap: 10px;
    --scw-edge: 12px;
    --scw-bottom: 12px;
  }

  .scw-btn .scw-icon,
  .scw-main__icon .scw-icon {
    width: 24px;
    height: 24px;
  }

  .scw-zalo-text {
    font-size: 12px;
  }
}

/* --- Tôn trọng prefers-reduced-motion: tắt vòng sáng, mở/thu tức thì.
   (Theme cũng có kill-switch toàn cục; luật riêng này để plugin tự
   đứng vững khi chạy ngoài theme Sunme.) --- */

@media (prefers-reduced-motion: reduce) {
  .scw-main::before,
  .scw-main::after {
    animation: none;
    display: none;
  }

  .scw-btn,
  .scw-main__icon,
  .scw-widget {
    transition: none;
  }
}
