/* ==========================================================
   FILE SOURCE:
   static/css/pages/floating_support.css

   PURPOSE:
   - Global floating support buttons.
   - Desktop:
       WhatsApp / Messenger / Zalo show directly on the right.
       Scroll-up appears on the right after scrolling.
   - Mobile:
       Chat / Hỗ trợ button stays on the left.
       Scroll-up button stays on the right.
       Chat menu opens upward from the left button.
   - Product detail mobile:
       Floating buttons move above Add to Cart / Buy Now bar.
   - Mobile drawer:
       Floating buttons hide when hamburger menu is open.

   HTML:
   templates/includes/chat_buttons.html

   JS:
   static/js/pages/floating_support.js

   DEPENDS ON:
   static/css/pages/skeleton_base.css

   SKELETON VARIABLES USED:
   --color-primary
   --color-primary-soft
   --color-accent
   --color-accent-dark
   --color-bg
   --color-bg-soft
   --color-card
   --color-border
   --color-button
   --color-button-dark
   --color-button-text
   ========================================================== */


/* ==========================================================
   01. ACCESSIBILITY
   ========================================================== */

.floating-sr-only {
  position: absolute;

  width: 1px;
  height: 1px;

  padding: 0;
  margin: -1px;

  overflow: hidden;
  clip: rect(0, 0, 0, 0);

  white-space: nowrap;

  border: 0;
}


/* ==========================================================
   02. DESKTOP WRAPPER
   Desktop default:
   - Support group sits bottom-right.
   - Chat links are visible directly.
   - Scroll-up appears above/below naturally in same group.
   ========================================================== */

.floating-support {
  position: fixed;
  right: clamp(0.85rem, 2vw, 1.35rem);
  bottom: clamp(0.85rem, 2vw, 1.35rem);
  z-index: 1080;

  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.65rem;

  pointer-events: none;
}

.floating-support button,
.floating-support a {
  pointer-events: auto;
}


/* ==========================================================
   03. SHARED BUTTON STYLE
   ========================================================== */

.chat-toggle,
.chat-btn,
.floating-scroll-top {
  width: clamp(2.9rem, 4.5vw, 3.35rem);
  height: clamp(2.9rem, 4.5vw, 3.35rem);

  display: inline-flex;
  align-items: center;
  justify-content: center;

  padding: 0;

  border: 1px solid rgba(232, 222, 208, 0.82);
  border-radius: 999px;

  background:
    radial-gradient(circle at top right, rgba(185, 130, 47, 0.12), transparent 2.8rem),
    linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(250, 247, 241, 0.88));

  color: var(--color-primary);

  box-shadow: 0 0.55rem 1.25rem rgba(43, 33, 24, 0.14);

  text-decoration: none;
  cursor: pointer;

  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;

  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease,
    border-color 160ms ease,
    opacity 160ms ease,
    visibility 160ms ease;
}

.chat-toggle:hover,
.chat-btn:hover,
.floating-scroll-top:hover {
  transform: translateY(-2px);
  border-color: rgba(185, 130, 47, 0.45);
  box-shadow: 0 0.75rem 1.55rem rgba(43, 33, 24, 0.18);
}

.chat-toggle:focus-visible,
.chat-btn:focus-visible,
.floating-scroll-top:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
}

.chat-icon {
  display: block;

  width: 1.65rem;
  height: 1.65rem;

  object-fit: contain;
}


/* ==========================================================
   04. SCROLL TO TOP BUTTON
   Hidden by default.
   JS adds .is-visible after scrolling.
   ========================================================== */

.floating-scroll-top {
  opacity: 0;
  visibility: hidden;
  transform: translateY(0.45rem);
  pointer-events: none;

  background:
    radial-gradient(circle at top right, rgba(185, 130, 47, 0.16), transparent 3.2rem),
    linear-gradient(135deg, var(--color-primary), var(--color-primary-soft));

  color: #fff;
  border-color: rgba(185, 130, 47, 0.32);
}

.floating-scroll-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.floating-scroll-top i {
  font-size: 1rem;
  line-height: 1;
}


/* ==========================================================
   05. DESKTOP CHAT MENU
   Desktop:
   - chat-toggle hidden.
   - chat-menu shows all chat links directly.
   ========================================================== */

.floating-chat {
  position: relative;

  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.chat-toggle {
  display: none;
}

.chat-menu {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.58rem;
}

.chat-btn.whatsapp {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(238, 248, 235, 0.94));
}

.chat-btn.facebook {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(235, 243, 255, 0.94));
}

.chat-btn.zalo {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(232, 247, 255, 0.94));
}


/* ==========================================================
   06. MOBILE SPLIT POSITION
   Mobile:
   - wrapper becomes invisible full-width layer.
   - Chat button fixed on left.
   - Scroll-up fixed on right.
   ========================================================== */

@media (max-width: 767px) {
  .floating-support {
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1080;

    width: 100%;
    height: 0;

    display: block;

    pointer-events: none;
  }

  .floating-chat {
    position: fixed;
    left: 0.8rem;
    right: auto;
    bottom: calc(0.8rem + env(safe-area-inset-bottom));
    z-index: 1082;

    display: flex;
    flex-direction: column;
    align-items: flex-start;

    pointer-events: auto;
  }

  .floating-scroll-top {
    position: fixed;
    right: 0.8rem;
    left: auto;
    bottom: calc(0.8rem + env(safe-area-inset-bottom));
    z-index: 1081;

    width: 2.85rem;
    height: 2.85rem;

    pointer-events: none;
  }

  .floating-scroll-top.is-visible {
    pointer-events: auto;
  }
}


/* ==========================================================
   07. MOBILE CHAT TOGGLE
   Friendly pill button:
   - Closed: Hỗ trợ / Support
   - Open: Đóng / Close
   ========================================================== */

@media (max-width: 767px) {
  .chat-toggle {
    width: auto;
    min-width: 5.65rem;
    height: 2.85rem;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.42rem;

    padding: 0 0.82rem;

    border: 1px solid rgba(185, 130, 47, 0.32);
    border-radius: 999px;

    background:
      radial-gradient(circle at top right, rgba(185, 130, 47, 0.18), transparent 3.4rem),
      linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(250, 247, 241, 0.94));

    color: var(--color-primary);

    box-shadow:
      0 0.55rem 1.25rem rgba(43, 33, 24, 0.16),
      inset 0 0 0 1px rgba(255, 255, 255, 0.55);
  }

  .chat-toggle:hover {
    border-color: rgba(185, 130, 47, 0.52);
    background:
      radial-gradient(circle at top right, rgba(185, 130, 47, 0.22), transparent 3.4rem),
      linear-gradient(135deg, rgba(255, 255, 255, 1), rgba(243, 235, 221, 0.96));
  }

  .chat-toggle-icon {
    position: static;

    width: 1.45rem;
    height: 1.45rem;

    flex: 0 0 auto;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    opacity: 1;
    transform: none;
  }

  .chat-toggle .chat-icon {
    width: 1.42rem;
    height: 1.42rem;
  }

  .chat-toggle-close {
    display: none;

    color: var(--color-primary);
    font-size: 1.05rem;
  }

  .floating-chat.is-open .chat-toggle-open {
    display: none;
    opacity: 0;
    transform: none;
  }

  .floating-chat.is-open .chat-toggle-close {
    display: inline-flex;
    opacity: 1;
    transform: none;
  }

  html[lang="vi"] .chat-toggle::after {
    content: "Hỗ trợ";
  }

  html[lang="en"] .chat-toggle::after {
    content: "Support";
  }

  html[lang="vi"] .floating-chat.is-open .chat-toggle::after {
    content: "Đóng";
  }

  html[lang="en"] .floating-chat.is-open .chat-toggle::after {
    content: "Close";
  }

  .chat-toggle::after {
    display: inline-block;

    color: var(--color-primary);
    font-size: 0.86rem;
    font-weight: 900;
    line-height: 1;
    white-space: nowrap;
  }
}


/* ==========================================================
   08. MOBILE CHAT MENU
   Opens upward from the left chat button.
   ========================================================== */

@media (max-width: 767px) {
  .chat-menu {
    position: absolute;
    left: 0;
    right: auto;
    bottom: calc(100% + 0.65rem);
    z-index: 1083;

    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.58rem;

    opacity: 0;
    visibility: hidden;
    transform: translateY(0.45rem) scale(0.96);
    pointer-events: none;

    transition:
      opacity 160ms ease,
      visibility 160ms ease,
      transform 160ms ease;
  }

  .floating-chat.is-open .chat-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }

  .chat-menu::after {
    content: "";

    position: absolute;
    left: 1.05rem;
    right: auto;
    bottom: -0.42rem;

    width: 0.8rem;
    height: 0.8rem;

    background: rgba(255, 255, 255, 0.96);
    transform: rotate(45deg);

    box-shadow: 0.2rem 0.2rem 0.45rem rgba(43, 33, 24, 0.08);
  }
}


/* ==========================================================
   09. PRODUCT DETAIL MOBILE OFFSET
   Product pages have a fixed Add to Cart / Buy Now bar.
   Move support buttons above that bar.
   ========================================================== */

@media (max-width: 767px) {
  body.product-detail-body .floating-chat,
  body.product-detail-body .floating-scroll-top {
    bottom: calc(5.35rem + env(safe-area-inset-bottom));
  }
}

@media (max-width: 420px) {
  body.product-detail-body .floating-chat,
  body.product-detail-body .floating-scroll-top {
    bottom: calc(5.1rem + env(safe-area-inset-bottom));
  }
}


/* ==========================================================
   10. MOBILE DRAWER OPEN PATCH
   Header JS/CSS uses body.mobile-nav-open.
   Hide floating buttons while hamburger drawer is open.
   This prevents covering Contact / Liên hệ row in drawer.
   ========================================================== */

@media (max-width: 767px) {
  body.mobile-nav-open .floating-chat,
  body.mobile-nav-open .floating-scroll-top {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transform: translateY(0.45rem) !important;
  }
}


/* ==========================================================
   11. VERY SMALL MOBILE
   ========================================================== */

@media (max-width: 360px) {
  .floating-chat {
    left: 0.6rem;
  }

  .floating-scroll-top {
    right: 0.6rem;

    width: 2.72rem;
    height: 2.72rem;
  }

  .chat-toggle {
    min-width: 5.2rem;
    height: 2.72rem;
    padding: 0 0.68rem;
  }

  .chat-toggle::after {
    font-size: 0.8rem;
  }

  .chat-icon {
    width: 1.5rem;
    height: 1.5rem;
  }
}