/* ===== Independent Fixed Widgets — !important overrides builder CSS ===== */
.chatgvt-phone-widget,
.chatgvt-wa-widget {
    position: fixed !important;
    z-index: 99999 !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    pointer-events: auto !important;
    transform: none !important;
    float: none !important;
    display: block !important;
    /* NO contain or isolation — prevents stacking context issues */
    overflow: visible !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-sizing: border-box !important;
}

/* ===== Positioning: Both on RIGHT side, Phone UP, WhatsApp DOWN ===== */
.chatgvt-phone-widget.chatgvt-pos-left,
.chatgvt-phone-widget.chatgvt-pos-right {
    right: 24px !important;
    bottom: 96px !important;
    left: auto !important;
    top: auto !important;
}
.chatgvt-wa-widget.chatgvt-pos-right,
.chatgvt-wa-widget.chatgvt-pos-left {
    right: 24px !important;
    bottom: 24px !important;
    left: auto !important;
    top: auto !important;
}

/* ===== FAB Button — Transparent, No Boundary ===== */
.chatgvt-fab {
    width: var(--chatgvt-size, 68px);
    height: var(--chatgvt-size, 68px);
    cursor: pointer !important;
    position: relative !important;
    background: transparent !important;
    border: none !important;
    border-radius: 50% !important;
    box-shadow: none !important;
    outline: none;
    transition: transform 0.2s ease;
    display: flex !important;
    align-items: center;
    justify-content: center;
    pointer-events: auto !important;
    z-index: 10 !important;
}
.chatgvt-fab:hover {
    transform: scale(1.1);
    box-shadow: none !important;
}
.chatgvt-fab:active {
    transform: scale(0.95);
}
.chatgvt-fab:focus-visible {
    outline: 3px solid #25D366;
    outline-offset: 4px;
}
.chatgvt-fab-icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    border-radius: 50%;
    pointer-events: none;
}
.chatgvt-fab-close {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

/* ===== Phone FAB — No Glow, Clean ===== */
.chatgvt-fab-phone {
    position: relative !important;
}
.chatgvt-fab-phone:focus-visible {
    outline-color: #3b82f6;
}

/* Phone animation variants */
.chatgvt-anim-phone-pulse {
    animation: chatgvt-phone-pulse 2s ease-in-out infinite;
}
@keyframes chatgvt-phone-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ===== WhatsApp Animations ===== */
.chatgvt-anim-pulse {
    animation: chatgvt-pulse 2s ease-in-out infinite;
}
@keyframes chatgvt-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}
.chatgvt-anim-bounce {
    animation: chatgvt-bounce 2s ease-in-out infinite;
}
@keyframes chatgvt-bounce {
    0%, 100% { transform: translateY(0); }
    25% { transform: translateY(-8px); }
    50% { transform: translateY(0); }
    75% { transform: translateY(-4px); }
}
.chatgvt-anim-slide {
    animation: chatgvt-slide 3s ease-in-out infinite;
}
@keyframes chatgvt-slide {
    0% { transform: translateX(0); opacity: 1; }
    15% { transform: translateX(-10px); opacity: 0.8; }
    30% { transform: translateX(0); opacity: 1; }
    100% { transform: translateX(0); opacity: 1; }
}
.chatgvt-wa-widget.chatgvt-pos-left .chatgvt-anim-slide {
    animation-name: chatgvt-slide-left;
}
@keyframes chatgvt-slide-left {
    0% { transform: translateX(0); opacity: 1; }
    15% { transform: translateX(10px); opacity: 0.8; }
    30% { transform: translateX(0); opacity: 1; }
    100% { transform: translateX(0); opacity: 1; }
}

/* ===== Badge ===== */
.chatgvt-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    background: #ef4444;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
    animation: chatgvt-badge-pop 0.3s ease-out;
}
@keyframes chatgvt-badge-pop {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* ===== Popup Panels — FIXED position, above FABs ===== */
.chatgvt-popup,
.chatgvt-phone-popup {
    position: fixed !important;
    width: 360px;
    max-height: 480px;
    background: #ffffff !important;
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.24), 0 4px 12px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    display: none;
    flex-direction: column;
    z-index: 100000 !important;
    touch-action: manipulation;
    -webkit-overflow-scrolling: touch;
    max-width: calc(100vw - 48px);
}

/* WhatsApp popup: bottom-right, above WhatsApp FAB */
.chatgvt-popup {
    right: 24px !important;
    bottom: calc(24px + 68px + 16px) !important;
    left: auto !important;
}

/* Phone popup: bottom-right, above phone FAB */
.chatgvt-phone-popup {
    right: 24px !important;
    bottom: calc(96px + 68px + 16px) !important;
    left: auto !important;
}

/* Animation in */
.chatgvt-popup.chatgvt-popup-anim,
.chatgvt-phone-popup.chatgvt-popup-anim {
    animation: chatgvt-popup-in 0.25s ease-out;
}

@keyframes chatgvt-popup-in {
    0% { opacity: 0; transform: translateY(12px) scale(0.96); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* ===== Mobile Backdrop Overlay ===== */
.chatgvt-mobile-backdrop {
    display: none;
}

/* ===== Popup Header — SOLID, opaque ===== */
.chatgvt-popup-header {
    background: #075e54 !important;
    color: #fff;
    padding: 16px 44px 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
}
.chatgvt-popup-header-phone {
    background: #1e40af !important;
}
.chatgvt-popup-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 600;
    min-width: 0;
}

/* ===== Close Button — INSIDE header, right edge ===== */
.chatgvt-popup-close {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    font-size: 18px;
    font-weight: 400;
    cursor: pointer !important;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    line-height: 1;
    opacity: 0.9;
    transition: opacity 0.15s, background 0.15s;
    flex-shrink: 0;
    pointer-events: auto !important;
    z-index: 10 !important;
}
.chatgvt-popup-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.25);
}
.chatgvt-popup-close:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
    opacity: 1;
}

/* ===== Agents List ===== */
.chatgvt-agents-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
    background: #ffffff !important;
    max-height: 320px;
}

/* ===== WhatsApp Agent Row ===== */
.chatgvt-agent-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    text-decoration: none;
    color: inherit;
    cursor: pointer !important;
    transition: background 0.15s;
    border-bottom: 1px solid #f0f0f0;
    pointer-events: auto !important;
}
.chatgvt-agent-item:last-child { border-bottom: none; }
.chatgvt-agent-item:hover { background: #f5f5f5; }
.chatgvt-agent-item:focus-visible {
    outline: 2px solid #075e54;
    outline-offset: -2px;
    background: #f5f5f5;
}

/* ===== Phone Agent Row ===== */
.chatgvt-phone-agent-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    cursor: pointer !important;
    transition: background 0.15s;
    border-bottom: 1px solid #f0f0f0;
    background: #ffffff !important;
    pointer-events: auto !important;
}
.chatgvt-phone-agent-item:last-child { border-bottom: none; }
.chatgvt-phone-agent-item:hover { background: #f5f5f5; }
.chatgvt-phone-agent-item:focus-visible {
    outline: 2px solid #1e40af;
    outline-offset: -2px;
    background: #f5f5f5;
}

/* ===== Agent Photo & Info ===== */
.chatgvt-agent-photo {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: #e0e0e0;
}
.chatgvt-agent-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.chatgvt-agent-initial {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #075e54;
    color: #fff;
    font-size: 20px;
    font-weight: 600;
}
.chatgvt-agent-initial-phone {
    background: #1e40af;
}

.chatgvt-agent-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.chatgvt-agent-name {
    font-size: 15px;
    font-weight: 600;
    color: #111;
}
.chatgvt-agent-role {
    font-size: 12px;
    color: #888;
}
.chatgvt-agent-msg {
    font-size: 12px;
    color: #999;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== Phone Number (revealed on click) ===== */
.chatgvt-phone-number {
    margin-top: 6px;
}
.chatgvt-phone-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    color: #1e40af;
    text-decoration: none;
    padding: 6px 12px;
    background: #eff6ff;
    border-radius: 8px;
    transition: background 0.15s;
    border: 1px solid #bfdbfe;
    pointer-events: auto !important;
    cursor: pointer !important;
}
.chatgvt-phone-link:hover {
    background: #dbeafe;
    text-decoration: none;
}

/* ===== Action Buttons ===== */
.chatgvt-agent-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.chatgvt-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer !important;
    transition: background 0.15s, transform 0.15s;
    pointer-events: auto !important;
}
.chatgvt-action-btn:hover { transform: scale(1.1); }
.chatgvt-call-btn {
    background: #3b82f6;
    color: #fff;
}
.chatgvt-call-btn:hover { background: #2563eb; }
.chatgvt-call-btn:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}
.chatgvt-call-btn.revealed {
    background: #1e40af;
}
.chatgvt-wa-icon {
    background: transparent;
    padding: 0;
    border-radius: 6px;
}
.chatgvt-wa-icon img {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    display: block;
}

/* ===== Popup Footer ===== */
.chatgvt-popup-footer {
    padding: 10px 18px;
    text-align: center;
    font-size: 11px;
    color: #aaa;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
    background: #ffffff !important;
}
.chatgvt-popup-footer a {
    color: #888;
    text-decoration: none;
}
.chatgvt-popup-footer a:hover {
    color: #555;
    text-decoration: underline;
}

/* ===== Offline State ===== */
.chatgvt-offline {
    padding: 40px 20px;
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #ffffff !important;
}
.chatgvt-offline-icon {
    margin-bottom: 16px;
    opacity: 0.5;
}
.chatgvt-offline-msg {
    font-size: 14px;
    color: #666;
    margin: 0;
    line-height: 1.5;
}

/* ===== Sheet Handle (hidden on desktop, shown on mobile) ===== */
.chatgvt-sheet-handle {
    display: none;
    width: 36px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 8px auto 4px;
    flex-shrink: 0;
    cursor: grab;
}
.chatgvt-sheet-handle:active {
    cursor: grabbing;
}

/* ========================================
   TABLET BREAKPOINT (768px and below)
   Both icons on right side, stacked
   ======================================== */
@media (max-width: 768px) {
    /* Both on right side */
    .chatgvt-phone-widget.chatgvt-pos-left,
    .chatgvt-phone-widget.chatgvt-pos-right {
        right: 16px !important;
        left: auto !important;
        bottom: 88px !important;
    }
    .chatgvt-wa-widget.chatgvt-pos-right,
    .chatgvt-wa-widget.chatgvt-pos-left {
        right: 16px !important;
        left: auto !important;
        bottom: 16px !important;
    }

    /* Slightly smaller FABs on tablet */
    .chatgvt-fab {
        width: 60px !important;
        height: 60px !important;
    }
    .chatgvt-fab-icon {
        width: 60px !important;
        height: 60px !important;
    }

    /* Popup: fixed position, above FABs */
    .chatgvt-popup {
        right: 16px !important;
        bottom: calc(16px + 60px + 12px) !important;
        left: auto !important;
        width: 340px !important;
        max-width: calc(100vw - 32px) !important;
    }
    .chatgvt-phone-popup {
        right: 16px !important;
        bottom: calc(88px + 60px + 12px) !important;
        left: auto !important;
        width: 340px !important;
        max-width: calc(100vw - 32px) !important;
    }
}

/* ========================================
   MOBILE BREAKPOINT (480px and below)
   Bottom sheet pattern
   ======================================== */
@media (max-width: 480px) {
    /* Stack both on right side */
    .chatgvt-phone-widget.chatgvt-pos-left,
    .chatgvt-phone-widget.chatgvt-pos-right {
        right: 12px !important;
        left: auto !important;
        bottom: 84px !important;
    }
    .chatgvt-wa-widget.chatgvt-pos-right,
    .chatgvt-wa-widget.chatgvt-pos-left {
        right: 12px !important;
        left: auto !important;
        bottom: 12px !important;
    }

    .chatgvt-fab {
        width: 56px !important;
        height: 56px !important;
    }
    .chatgvt-fab-icon {
        width: 56px !important;
        height: 56px !important;
    }

    /* Mobile backdrop overlay */
    .chatgvt-mobile-backdrop {
        display: none;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        background: rgba(0, 0, 0, 0.4) !important;
        z-index: 99998 !important;
        -webkit-tap-highlight-color: transparent;
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }
    .chatgvt-mobile-backdrop.chatgvt-backdrop-visible {
        display: block;
    }

    /* Popups become bottom sheets */
    .chatgvt-popup,
    .chatgvt-phone-popup {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        max-height: 75vh !important;
        border-radius: 20px 20px 0 0 !important;
        transform: translateY(100%) !important;
        transition: transform 0.3s ease-out !important;
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    }

    /* When popup is visible */
    .chatgvt-popup.chatgvt-popup-visible,
    .chatgvt-phone-popup.chatgvt-popup-visible {
        transform: translateY(0) !important;
    }

    /* Drag handle for bottom sheet */
    .chatgvt-sheet-handle {
        display: block !important;
    }

    /* Agents list scrollable in bottom sheet */
    .chatgvt-agents-list {
        max-height: calc(75vh - 140px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* Larger close button for touch (min 44px per Apple HIG) */
    .chatgvt-popup-close {
        width: 44px !important;
        height: 44px !important;
        font-size: 20px !important;
        right: 8px !important;
    }

    .chatgvt-phone-agent-item,
    .chatgvt-agent-item { padding: 14px 16px; }
    .chatgvt-agent-photo { width: 44px; height: 44px; }
}

/* ===== Print ===== */
@media print {
    .chatgvt-phone-widget,
    .chatgvt-wa-widget { display: none !important; }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    .chatgvt-anim-pulse,
    .chatgvt-anim-bounce,
    .chatgvt-anim-slide,
    .chatgvt-anim-phone-pulse {
        animation: none !important;
    }
    .chatgvt-popup,
    .chatgvt-phone-popup {
        animation: none !important;
        transition: none !important;
    }
    .chatgvt-badge {
        animation: none !important;
    }
    .chatgvt-fab {
        transition: none !important;
    }
}

/* ===== Dark Mode ===== */
@media (prefers-color-scheme: dark) {
    .chatgvt-popup,
    .chatgvt-phone-popup {
        background: #1e1e1e !important;
        box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5), 0 4px 12px rgba(0, 0, 0, 0.3);
    }
    .chatgvt-agents-list,
    .chatgvt-phone-agent-item,
    .chatgvt-offline,
    .chatgvt-popup-footer {
        background: #1e1e1e !important;
    }
    .chatgvt-popup-header { background: #064e3b !important; }
    .chatgvt-popup-header-phone { background: #1e3a5f !important; }
    .chatgvt-agent-item,
    .chatgvt-phone-agent-item { border-bottom-color: #333; color: #e0e0e0; }
    .chatgvt-agent-item:hover,
    .chatgvt-phone-agent-item:hover { background: #2a2a2a; }
    .chatgvt-agent-name { color: #f0f0f0; }
    .chatgvt-agent-role { color: #aaa; }
    .chatgvt-agent-msg { color: #888; }
    .chatgvt-popup-footer { border-top-color: #333; color: #666; }
    .chatgvt-offline-msg { color: #aaa; }
    .chatgvt-phone-link { background: #1e3a5f; color: #93c5fd; border-color: #2563eb; }
    .chatgvt-phone-link:hover { background: #1e40af; }
    .chatgvt-popup-close { background: rgba(255, 255, 255, 0.1); }
    .chatgvt-popup-close:hover { background: rgba(255, 255, 255, 0.2); }
    .chatgvt-mobile-backdrop { background: rgba(0, 0, 0, 0.6) !important; }
}
