/* Mobile-visible class for JavaScript fallback */
.fab-container.mobile-visible {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    z-index: 9999 !important;
}

/* Ensure FABs are always visible on mobile/tablet devices by default */
.fab-container {
    position: fixed;
    left: 20px; /* Left side for RTL layout */
    bottom: 20px;
    z-index: 9999; /* Higher z-index to ensure visibility above other elements */
    display: flex; /* Always show by default for mobile-first approach */
    flex-direction: column;
    gap: 15px;
    /* Ensure the FABs are always visible on mobile */
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    /* Add transition for smooth appearance */
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* Hide on desktop/large screens */
@media (min-width: 769px) {
    .fab-container {
        display: none !important;
    }
}

.fab-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.fab-container .fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #17a2b8, #138496);
    box-shadow: 0 4px 16px rgba(23, 162, 184, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    outline: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    text-align: center;
    position: relative;
    /* Enhanced mobile touch support */
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
}

.fab-container .fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(23, 162, 184, 0.6);
}

.fab-container .fab:active {
    transform: scale(0.95);
}

.fab-container .fab-icon {
    font-size: 24px;
    color: white;
    display: inline-block;
    line-height: 1;
    vertical-align: middle;
    text-align: center;
    margin: 0;
    padding: 0;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* WhatsApp icon specific centering - Fixed with flexbox (override the absolute positioning) */
.fab-container .fab-whatsapp .fab-icon {
    position: relative;
    top: 0;
    left: 0;
    transform: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.fab-tooltip {
    position: absolute;
    left: 70px; /* Moved to left side for left-positioned buttons */
    background-color: #333;
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 14px;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    direction: rtl;
    text-align: right;
    font-family: 'Arial', sans-serif;
}

.fab-wrapper:hover .fab-tooltip {
    opacity: 1;
    transform: translateY(0);
}

.fab-container .fab-call {
    background: linear-gradient(135deg, #28a745, #20892c);
    box-shadow: 0 4px 16px rgba(40, 167, 69, 0.4);
    animation: pulse-call 2s infinite;
}

.fab-container .fab-call:hover {
    box-shadow: 0 6px 20px rgba(40, 167, 69, 0.6);
    animation: glow-call 1.5s infinite alternate;
}

.fab-container .fab-whatsapp {
    background: linear-gradient(135deg, #25d366, #1da851);
    box-shadow: 0 4px 16px rgba(37, 211, 102, 0.4);
    animation: pulse-whatsapp 2s infinite;
}

.fab-container .fab-whatsapp:hover {
    box-shadow: 0 6px 20px rgba(37, 211, 102, 0.6);
    animation: glow-whatsapp 1.5s infinite alternate;
}

/* Show FABs on all mobile and small screen devices */
@media (max-width: 768px) {
    .fab-container {
        display: flex !important; /* Force display with !important */
        left: 20px; /* Keep on left side */
        right: unset;
        flex-direction: column-reverse; /* WhatsApp on top */
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }
    
    .fab-tooltip {
        left: 70px; /* Tooltip to the right of buttons */
        right: unset;
    }
    
    /* Mobile-specific tooltip behavior */
    .fab-wrapper:active .fab-tooltip {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Additional coverage for any screen smaller than tablet */
@media screen and (max-width: 768px),
       screen and (max-device-width: 768px),
       (max-width: 768px) and (max-height: 1024px),
       (hover: none) and (pointer: coarse) {
    .fab-container {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        z-index: 9999 !important;
    }
}

/* Ensure FABs are visible on specific mobile screen sizes */
@media screen and (max-width: 767px) {
    .fab-container {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
}

/* Specific rules for very small screens - Enhanced coverage */
@media screen and (max-width: 414px) {
    .fab-container {
        display: flex !important;
        left: 15px;
        bottom: 15px;
        visibility: visible !important;
        opacity: 1 !important;
    }
}

@media screen and (max-width: 375px) {
    .fab-container {
        display: flex !important;
        left: 12px;
        bottom: 12px;
        visibility: visible !important;
        opacity: 1 !important;
    }
}

@media screen and (max-width: 360px) {
    .fab-container {
        display: flex !important;
        left: 10px;
        bottom: 10px;
        gap: 10px;
        visibility: visible !important;
        opacity: 1 !important;
    }
}

@media screen and (max-width: 320px) {
    .fab-container {
        display: flex !important;
        left: 8px;
        bottom: 8px;
        gap: 8px;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    .fab {
        width: 50px !important;
        height: 50px !important;
    }
    
    .fab-icon {
        font-size: 20px !important;
    }
}

/* Catch-all for any small screen that might be missed */
@media screen and (max-width: 480px) {
    .fab-container {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        z-index: 9999 !important;
    }
}

@media screen and (max-width: 320px) {
    .fab-container {
        display: flex !important;
        left: 8px;
        bottom: 8px;
        gap: 8px;
    }
    
    .fab {
        width: 50px !important;
        height: 50px !important;
    }
    
    .fab-icon {
        font-size: 20px !important;
    }
}

/* Additional mobile device detection using hover and pointer media queries */
@media (hover: none) and (pointer: coarse) {
    /* This targets touch devices specifically */
    .fab-container {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }
}

/* Fallback for any device with max-width 768px */
@media (max-device-width: 768px) {
    .fab-container {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
}

/* Mobile landscape orientation */
@media screen and (max-width: 768px) and (orientation: landscape) {
    .fab-container {
        display: flex !important;
        bottom: max(15px, env(safe-area-inset-bottom, 15px));
        left: max(15px, env(safe-area-inset-left, 15px));
        right: unset;
        gap: 12px;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    .fab {
        width: 48px;
        height: 48px;
    }
    
    .fab-icon {
        font-size: 20px;
    }
}

/* Additional spacing for devices with safe areas (iOS) */
@media (max-width: 768px) and (orientation: portrait) {
    .fab-container {
        display: flex !important;
        bottom: max(20px, env(safe-area-inset-bottom, 20px));
        left: max(20px, env(safe-area-inset-left, 20px));
        right: unset;
        visibility: visible !important;
        opacity: 1 !important;
    }
}

/* Enhanced responsive adjustments for very small screens */
@media (max-width: 480px) {
    .fab-container {
        display: flex !important;
        left: 15px;
        bottom: 15px;
        right: unset;
        gap: 12px;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }
}

/* Animation for better UX */
@keyframes fabSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Pulse animations for FABs */
@keyframes pulse-call {
    0% {
        transform: scale(1);
        box-shadow: 0 4px 16px rgba(40, 167, 69, 0.4), 0 0 0 0 rgba(40, 167, 69, 0.7);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 6px 20px rgba(40, 167, 69, 0.6), 0 0 0 8px rgba(40, 167, 69, 0.3);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 4px 16px rgba(40, 167, 69, 0.4), 0 0 0 0 rgba(40, 167, 69, 0);
    }
}

@keyframes pulse-whatsapp {
    0% {
        transform: scale(1);
        box-shadow: 0 4px 16px rgba(37, 211, 102, 0.4), 0 0 0 0 rgba(37, 211, 102, 0.7);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 6px 20px rgba(37, 211, 102, 0.6), 0 0 0 8px rgba(37, 211, 102, 0.3);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 4px 16px rgba(37, 211, 102, 0.4), 0 0 0 0 rgba(37, 211, 102, 0);
    }
}

/* Glow animations on hover */
@keyframes glow-call {
    from {
        transform: scale(1.05);
        box-shadow: 0 6px 20px rgba(40, 167, 69, 0.6), 0 0 15px rgba(40, 167, 69, 0.4);
    }
    to {
        transform: scale(1.15);
        box-shadow: 0 8px 25px rgba(40, 167, 69, 0.8), 0 0 25px rgba(40, 167, 69, 0.6);
    }
}

@keyframes glow-whatsapp {
    from {
        transform: scale(1.05);
        box-shadow: 0 6px 20px rgba(37, 211, 102, 0.6), 0 0 15px rgba(37, 211, 102, 0.4);
    }
    to {
        transform: scale(1.15);
        box-shadow: 0 8px 25px rgba(37, 211, 102, 0.8), 0 0 25px rgba(37, 211, 102, 0.6);
    }
}

.fab-container .fab {
    animation: fabSlideIn 0.3s ease-out;
}

.fab-container .fab-wrapper:nth-child(1) .fab {
    animation-delay: 0.2s;
}

.fab-container .fab-wrapper:nth-child(2) .fab {
    animation-delay: 0.4s;
}

/* Accessibility improvements */
.fab-container .fab:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .fab-container .fab {
        border: 2px solid #000;
    }

    .fab-container .fab-icon {
        filter: none;
    }

    .fab-tooltip {
        border: 1px solid #fff;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .fab-tooltip {
        background-color: #f8f9fa;
        color: #212529;
        border: 1px solid #dee2e6;
    }
}

/* Comprehensive mobile device targeting - covers all scenarios */
@media screen and (max-width: 768px),
       screen and (max-device-width: 768px),
       (hover: none) and (pointer: coarse),
       only screen and (-webkit-min-device-pixel-ratio: 1),
       only screen and (min-device-pixel-ratio: 1) {
    .fab-container {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        z-index: 9999 !important;
    }
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .fab-container .fab {
        transition: none;
        animation: none;
    }

    .fab-container .fab:hover {
        transform: none;
        animation: none;
    }

    .fab-container .fab:active {
        transform: none;
    }

    .fab-tooltip {
        transition: none;
    }

    .fab-container .fab-call {
        animation: none;
    }

    .fab-container .fab-whatsapp {
        animation: none;
    }

    .fab-container .fab-call:hover {
        animation: none;
    }

    .fab-container .fab-whatsapp:hover {
        animation: none;
    }
}

/* Ultimate fallback - Ensure FABs are ALWAYS visible on screens 768px and below */
/* This rule has highest specificity and should override any conflicts */
@media screen and (max-width: 768px) {
    .fab-container,
    div.fab-container,
    .fab-container.mobile-visible {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        position: fixed !important;
        left: 20px !important;
        bottom: 20px !important;
        z-index: 9999 !important;
        flex-direction: column-reverse !important;
        gap: 15px !important;
    }
}
