/**
 * Hắc Kim Real Estate — Floating Action Cluster Styles
 * Unified Hierarchy: Level 1 (AI Chat) -> Level 2 (Contact) -> Level 3 (Scroll Top)
 * Brand Color Tone: #CA6743 (Terracotta / Orange-copper) & White Accents
 * PC Desktop: Fan-out quarter-circle arc (Xòe quạt)
 * Mobile: Vertical upward stack (Mở ra dạng dọc)
 */

:root {
    --hk-floating-brand: #CA6743;
    --hk-floating-brand-hover: #b85632;
    --hk-floating-right: 24px;
    --hk-floating-bottom: 24px;
    --hk-floating-gap: 12px;
    --hk-ai-launcher-height: 52px;
    --hk-contact-size: 48px;
    --hk-scroll-size: 44px;
    --hk-sticky-bottom-offset: 0px;

    /* Semantic Z-Index Hierarchy Contract */
    --hk-z-sticky: 90;
    --hk-z-floating: 990;
    --hk-z-popover: 992;
    --hk-z-chat: 995;
    --hk-z-modal: 1000;
}

/* ==========================================================================
   1. Unified Cluster Container
   ========================================================================== */
.hk-floating-cluster {
    position: fixed;
    right: var(--hk-floating-right);
    bottom: calc(var(--hk-floating-bottom) + var(--hk-sticky-bottom-offset) + env(safe-area-inset-bottom, 0px));
    z-index: var(--hk-z-floating);
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-end;
    gap: var(--hk-floating-gap);
    pointer-events: none;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    user-select: none;
    -webkit-font-smoothing: antialiased;
    opacity: 0;
    transform: translateY(14px) scale(0.96);
    transition: opacity 0.38s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.38s cubic-bezier(0.16, 1, 0.3, 1),
                bottom 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.hk-floating-cluster.is-ready {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.hk-floating-cluster button,
.hk-floating-cluster a {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Slot for AI Chat Launcher */
.hk-floating-ai-slot {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    pointer-events: auto;
}

/* ==========================================================================
   2. Level 2 (Secondary): Floating Contact Group
   ========================================================================== */
.hk-floating-contact {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

/* Contact Trigger Button (Classic #CA6743 Tone) */
.hk-floating-contact__trigger {
    position: relative;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--hk-contact-size);
    height: var(--hk-contact-size);
    min-width: 46px;
    min-height: 46px;
    padding: 0;
    color: #FFFFFF;
    background: var(--hk-floating-brand);
    border: 2px solid #FFFFFF;
    border-radius: 50%;
    box-shadow: 0 6px 20px rgba(202, 103, 67, 0.45), 0 2px 6px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    outline: none;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1),
                background-color 0.2s ease,
                border-color 0.2s ease,
                box-shadow 0.2s ease;
}

.hk-floating-contact__trigger:hover,
.hk-floating-contact__trigger:focus-visible {
    transform: scale(1.06);
    background: var(--hk-floating-brand-hover);
    border-color: #FFFFFF;
    box-shadow: 0 8px 24px rgba(202, 103, 67, 0.55), 0 0 12px rgba(202, 103, 67, 0.35);
}

.hk-floating-contact__trigger:active {
    transform: scale(0.96);
}

.hk-floating-contact__trigger:focus-visible,
.hk-floating-contact__channel:focus-visible,
.hk-floating-scroll-top:focus-visible {
    outline: 2px solid var(--hk-floating-brand);
    outline-offset: 3px;
}

/* Trigger Icons */
.hk-floating-contact__trigger-icon {
    position: absolute;
    font-size: 19px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFFFFF;
    transition: opacity 0.2s ease, transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.hk-floating-contact__trigger-icon--close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.6);
    color: #FFFFFF;
}

.hk-floating-contact.is-open .hk-floating-contact__trigger-icon--open {
    opacity: 0;
    transform: rotate(90deg) scale(0.6);
}

.hk-floating-contact.is-open .hk-floating-contact__trigger-icon--close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Pulse Waves */
.hk-floating-contact__pulse {
    position: absolute;
    inset: -6px;
    border: 2px solid rgba(202, 103, 67, 0.5);
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    animation: hkFloatingPulse 2.6s cubic-bezier(0.25, 1, 0.5, 1) infinite;
}

.hk-floating-contact__pulse--two {
    border-color: rgba(202, 103, 67, 0.3);
    animation-delay: 0.85s;
}

@keyframes hkFloatingPulse {
    0% { opacity: 0.85; transform: scale(0.9); }
    100% { opacity: 0; transform: scale(1.45); }
}

.hk-floating-contact.is-open .hk-floating-contact__pulse {
    animation: none;
    opacity: 0;
}

/* Tooltip (Hỗ trợ & Tư vấn) */
.hk-floating-contact__tooltip {
    position: absolute;
    top: 50%;
    right: calc(100% + 12px);
    padding: 6px 12px;
    color: #FFFFFF;
    background: var(--hk-floating-brand);
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 16px;
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.2;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%) translateX(6px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
    visibility: hidden;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.hk-floating-contact__trigger:hover .hk-floating-contact__tooltip,
.hk-floating-contact__trigger:focus-visible .hk-floating-contact__tooltip {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
    visibility: visible;
}

.hk-floating-contact.is-open .hk-floating-contact__tooltip {
    opacity: 0 !important;
    visibility: hidden !important;
}

/* ==========================================================================
   3. Contact Channel Icons & Labels Base Styles
   ========================================================================== */
.hk-floating-contact__channel {
    color: #FFFFFF;
    text-decoration: none;
    outline: none;
}

.hk-floating-contact__channel:hover,
.hk-floating-contact__channel:focus-visible {
    color: #FFFFFF;
    text-decoration: none;
    outline: none;
}

/* 46px Circle Icon with Crisp White Border */
.hk-floating-contact__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    color: #FFFFFF;
    border: 2px solid #FFFFFF;
    border-radius: 50%;
    box-shadow: 0 5px 16px rgba(0, 0, 0, 0.22);
    font-size: 20px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    flex-shrink: 0;
}

.hk-floating-contact__channel:hover .hk-floating-contact__icon,
.hk-floating-contact__channel:focus-visible .hk-floating-contact__icon {
    transform: scale(1.1);
    box-shadow: 0 7px 20px rgba(0, 0, 0, 0.32);
}

/* Channel Background Colors */
.hk-floating-contact__channel--hotline .hk-floating-contact__icon {
    background: #008c62;
}

.hk-floating-contact__channel--zalo .hk-floating-contact__icon {
    overflow: hidden;
    padding: 0;
    background: #0068ff;
    border-color: #FFFFFF;
}

.hk-floating-contact__zalo-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.hk-floating-contact__channel--facebook .hk-floating-contact__icon {
    background: #1877f2;
}

.hk-floating-contact__channel--tiktok .hk-floating-contact__icon {
    background: #010101;
    color: #FFFFFF;
}

.hk-floating-contact__channel--tiktok:hover .hk-floating-contact__icon {
    background: #000000;
    box-shadow: 0 4px 18px rgba(254, 44, 85, 0.4), 0 0 10px rgba(37, 244, 238, 0.3);
}

/* Classic Terracotta Pill Label (#CA6743 with White Border) */
.hk-floating-contact__label {
    padding: 6px 10px;
    color: #FFFFFF;
    background: var(--hk-floating-brand);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.96);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: opacity 0.2s ease, transform 0.2s ease, background-color 0.15s ease;
}

.hk-floating-contact__channel:hover .hk-floating-contact__label,
.hk-floating-contact__channel:focus-visible .hk-floating-contact__label {
    background: var(--hk-floating-brand-hover);
}

/* ==========================================================================
   4. DESKTOP ONLY (≥768px): Fan-Out Quarter-Circle Arc (Xòe Quạt)
   ========================================================================== */
@media (min-width: 768px) {
    .hk-floating-contact__menu {
        position: absolute;
        width: 48px;
        height: 48px;
        display: block;
        right: 0;
        bottom: 0;
        pointer-events: none;
        z-index: 10;
    }

    .hk-floating-contact__channel {
        position: absolute;
        right: 1px;
        bottom: 1px;
        width: 46px;
        height: 46px;
        display: flex;
        justify-content: center;
        align-items: center;
        opacity: 0;
        pointer-events: none;
        transform: scale(0.25);
        transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    }

    /* Fan-out Coordinates in Quarter-Circle Arc (Top-Left from trigger) */
    .hk-floating-contact.is-open .hk-floating-contact__channel--zalo {
        transform: translate3d(0, -108px, 0) scale(1);
        opacity: 1;
        pointer-events: auto;
    }

    .hk-floating-contact.is-open .hk-floating-contact__channel--facebook {
        transform: translate3d(-54px, -94px, 0) scale(1);
        opacity: 1;
        pointer-events: auto;
    }

    .hk-floating-contact.is-open .hk-floating-contact__channel--tiktok {
        transform: translate3d(-94px, -54px, 0) scale(1);
        opacity: 1;
        pointer-events: auto;
    }

    .hk-floating-contact.is-open .hk-floating-contact__channel--hotline {
        transform: translate3d(-108px, 0, 0) scale(1);
        opacity: 1;
        pointer-events: auto;
    }

    /* Desktop Labels: Pop out on hover over specific channel */
    .hk-floating-contact__label {
        position: absolute;
        right: calc(100% + 9px);
        top: 50%;
        opacity: 0;
        pointer-events: none;
        transform: translateY(-50%) translateX(6px);
        visibility: hidden;
    }

    .hk-floating-contact__channel:hover .hk-floating-contact__label,
    .hk-floating-contact__channel:focus-visible .hk-floating-contact__label {
        opacity: 1;
        transform: translateY(-50%) translateX(0);
        visibility: visible;
        z-index: 100;
    }

    /* Zalo is straight at the top -> label pops above icon */
    .hk-floating-contact__channel--zalo .hk-floating-contact__label {
        right: auto;
        bottom: calc(100% + 8px);
        left: 50%;
        top: auto;
        transform: translateY(4px) translateX(-50%);
    }

    .hk-floating-contact__channel--zalo:hover .hk-floating-contact__label,
    .hk-floating-contact__channel--zalo:focus-visible .hk-floating-contact__label {
        transform: translateY(0) translateX(-50%);
    }
}

/* ==========================================================================
   5. MOBILE ONLY (<768px): Vertical Upward Stack (Mở Ra Dạng Dọc)
   ========================================================================== */
@media (max-width: 767px) {
    :root {
        --hk-floating-right: 14px;
        --hk-floating-bottom: 14px;
        --hk-floating-gap: 10px;
        --hk-ai-launcher-height: 46px;
        --hk-contact-size: 46px;
        --hk-scroll-size: 44px;
    }

    .hk-floating-contact__tooltip {
        display: none !important;
    }

    .hk-floating-contact__menu {
        position: absolute;
        right: 0;
        bottom: calc(100% + 10px);
        display: flex;
        flex-direction: column-reverse;
        gap: 8px;
        pointer-events: none;
        z-index: 10;
    }

    .hk-floating-contact__channel {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 8px;
        padding: 0;
        color: #FFFFFF;
        text-decoration: none;
        opacity: 0;
        pointer-events: none;
        transform: translateY(14px) scale(0.8);
        transition: opacity 0.2s ease, transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .hk-floating-contact.is-open .hk-floating-contact__channel {
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0) scale(1);
    }

    .hk-floating-contact.is-open .hk-floating-contact__channel:nth-child(1) { transition-delay: 0.10s; }
    .hk-floating-contact.is-open .hk-floating-contact__channel:nth-child(2) { transition-delay: 0.07s; }
    .hk-floating-contact.is-open .hk-floating-contact__channel:nth-child(3) { transition-delay: 0.04s; }
    .hk-floating-contact.is-open .hk-floating-contact__channel:nth-child(4) { transition-delay: 0s; }

    .hk-floating-contact__icon {
        width: 44px;
        height: 44px;
    }

    .hk-floating-contact__label {
        display: block;
        opacity: 1;
        visibility: visible;
        position: static;
        transform: none;
    }
}

/* ==========================================================================
   6. Level 3 (Utility): Scroll to Top (Classic #CA6743 & White Style)
   ========================================================================== */
.hk-floating-scroll-top {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--hk-scroll-size);
    height: var(--hk-scroll-size);
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    color: var(--hk-floating-brand);
    background: #FFFFFF;
    border: 2px solid var(--hk-floating-brand);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    outline: none;
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px);
    transition: opacity 0.18s ease-out,
                transform 0.18s ease-out,
                background-color 0.15s ease,
                color 0.15s ease,
                border-color 0.15s ease;
}

.hk-floating-scroll-top.is-visible {
    opacity: 0.95;
    pointer-events: auto;
    transform: translateY(0);
}

.hk-floating-scroll-top:hover,
.hk-floating-scroll-top:focus-visible {
    opacity: 1;
    color: #FFFFFF;
    background: var(--hk-floating-brand);
    border-color: var(--hk-floating-brand);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(202, 103, 67, 0.35);
}

.hk-floating-scroll-top:active {
    transform: translateY(0) scale(0.96);
}

/* Suppress duplicate Houzez theme default scroll-to-top */
.back-to-top-wrap,
#scroll-top.btn-back-to-top,
.houzez-back-to-top {
    display: none !important;
}

/* ==========================================================================
   7. State Mutual Exclusion Rules (Chat > Contact > Welcome > Scroll)
   ========================================================================== */

/* When Contact Menu is Open -> Hide Scroll Top */
.hk-floating-contact.is-open ~ .hk-floating-scroll-top,
.hk-state-contact-open .hk-floating-scroll-top {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: translateY(6px) !important;
}

/* When Chat Panel is Open -> Hide Contact and Scroll Top */
body.hk-state-chat-open .hk-floating-contact,
body.hk-state-chat-open .hk-floating-scroll-top {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    transform: scale(0.8) !important;
}

/* ==========================================================================
   8. Small Mobile Devices (<= 360px)
   ========================================================================== */
@media (max-width: 360px) {
    :root {
        --hk-floating-right: 10px;
        --hk-floating-bottom: 10px;
        --hk-floating-gap: 8px;
        --hk-ai-launcher-height: 44px;
        --hk-contact-size: 42px;
        --hk-scroll-size: 40px;
    }

    .hk-floating-contact__trigger {
        width: 42px;
        height: 42px;
        min-width: 42px;
        min-height: 42px;
    }

    .hk-floating-contact__trigger-icon {
        font-size: 17px;
    }

    .hk-floating-contact__icon {
        width: 40px;
        height: 40px;
        font-size: 17px;
    }

    .hk-floating-contact__label {
        font-size: 11px;
        padding: 5px 8px;
        max-width: calc(100vw - 75px);
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .hk-floating-scroll-top {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }
}

/* ==========================================================================
   9. Ultra-Small Mobile Devices (< 320px) — Galaxy Fold Cover, iPhone 4/5/SE1
   ========================================================================== */
@media (max-width: 320px) {
    :root {
        --hk-floating-right: 8px;
        --hk-floating-bottom: 8px;
        --hk-floating-gap: 6px;
        --hk-ai-launcher-height: 40px;
        --hk-contact-size: 38px;
        --hk-scroll-size: 36px;
    }

    .hk-floating-contact__trigger {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
        border-width: 1.5px;
    }

    .hk-floating-contact__trigger-icon {
        font-size: 15px;
    }

    .hk-floating-contact__menu {
        gap: 6px;
        bottom: calc(100% + 8px);
    }

    .hk-floating-contact__channel {
        gap: 6px;
    }

    .hk-floating-contact__icon {
        width: 36px;
        height: 36px;
        font-size: 15px;
        border-width: 1.5px;
    }

    .hk-floating-contact__label {
        font-size: 10px;
        padding: 3.5px 7px;
        border-radius: 12px;
        max-width: calc(100vw - 64px);
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .hk-floating-scroll-top {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
        border-width: 1.5px;
        font-size: 14px;
    }

    .hk-floating-scroll-top svg {
        width: 14px;
        height: 14px;
    }
}

/* ==========================================================================
   10. Accessibility & Reduced Motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    .hk-floating-cluster *,
    .hk-floating-contact__trigger,
    .hk-floating-contact__channel,
    .hk-floating-scroll-top {
        animation: none !important;
        transition: none !important;
        transform: none !important;
    }

    .hk-floating-scroll-top.is-visible {
        opacity: 1 !important;
    }
}
