/**
 * Cargoroll - Floating Action Buttons (FAB)
 *
 * Z-Index Hierarchy:
 * - Mobile Navigation: 9998-9999
 * - Back-to-top button: 9999 (bottom-right)
 * - Header: 1000
 * - FAB: 950 (bottom-left, clear of all conflicts)
 *
 * Position: Fixed, bottom-left corner
 * Visibility: Appears after 120px scroll
 * Footer avoidance: Shifts up when approaching footer
 */

/* =============================================
   FAB CONTAINER
   ============================================= */
.fab-container {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 950;
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-start;
    gap: 12px;

    /* Initial state - hidden */
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: opacity 0.3s ease,
                visibility 0.3s ease,
                transform 0.3s ease,
                bottom 0.3s ease;

    /* Safe area padding for iOS */
    padding-left: env(safe-area-inset-left, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Visible state */
.fab-container.fab-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Hide when mobile nav is open */
body.mobile-nav-open .fab-container {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Footer avoidance - dynamic via JS */
.fab-container.fab-near-footer {
    bottom: var(--fab-footer-offset, 24px);
}

/* =============================================
   FAB MAIN TOGGLE BUTTON
   ============================================= */
.fab-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 56px;
    height: 56px;
    padding: 0 20px;

    background: var(--color-primary, #664F9E);
    color: white;
    border: none;
    border-radius: 28px;
    cursor: pointer;

    font-family: var(--font-body, 'Inter', sans-serif);
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;

    box-shadow: 0 4px 16px rgba(102, 79, 158, 0.35),
                0 2px 6px rgba(0, 0, 0, 0.1);

    transition: background-color 0.2s ease,
                transform 0.2s ease,
                box-shadow 0.2s ease,
                border-radius 0.3s ease;
}

.fab-toggle:hover {
    background: #553d82;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 79, 158, 0.45),
                0 3px 8px rgba(0, 0, 0, 0.12);
}

.fab-toggle:active {
    transform: translateY(0);
}

.fab-toggle:focus {
    outline: 3px solid rgba(102, 79, 158, 0.4);
    outline-offset: 2px;
}

/* Toggle icon */
.fab-toggle-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.fab-toggle-icon svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* Toggle label (hidden on mobile) */
.fab-toggle-label {
    display: inline;
}

/* Rotate icon when expanded */
.fab-container.fab-expanded .fab-toggle-icon {
    transform: rotate(45deg);
}

/* =============================================
   FAB ACTION BUTTONS
   ============================================= */
.fab-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;

    /* Hidden by default */
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px) scale(0.95);
    transform-origin: bottom left;

    transition: opacity 0.25s ease,
                visibility 0.25s ease,
                transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Show actions when expanded */
.fab-container.fab-expanded .fab-actions {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Individual action button */
.fab-action {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    min-height: 48px;

    background: white;
    color: var(--color-text, #333);
    border: none;
    border-radius: 24px;
    cursor: pointer;
    text-decoration: none;

    font-family: var(--font-body, 'Inter', sans-serif);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;

    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12),
                0 1px 4px rgba(0, 0, 0, 0.08);

    transition: background-color 0.2s ease,
                transform 0.2s ease,
                box-shadow 0.2s ease,
                color 0.2s ease;
}

.fab-action:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15),
                0 2px 6px rgba(0, 0, 0, 0.1);
}

.fab-action:focus {
    outline: 3px solid rgba(102, 79, 158, 0.3);
    outline-offset: 2px;
}

/* Action icon container */
.fab-action-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.fab-action-icon svg {
    width: 18px;
    height: 18px;
}

.fab-action:hover .fab-action-icon {
    transform: scale(1.1);
}

/* Action label */
.fab-action-label {
    flex: 1;
}

/* =============================================
   ACTION BUTTON VARIANTS (Color-coded)
   ============================================= */

/* Primary CTA: Add Ad (Purple) */
.fab-action--add-ad {
    background: var(--color-primary, #664F9E);
    color: white;
}

.fab-action--add-ad:hover {
    background: #553d82;
    color: white;
}

.fab-action--add-ad .fab-action-icon {
    background: rgba(255, 255, 255, 0.2);
}

/* Secondary: Search Freight (Turquoise) */
.fab-action--freight {
    background: var(--color-secondary, #00BBA0);
    color: white;
}

.fab-action--freight:hover {
    background: #009582;
    color: white;
}

.fab-action--freight .fab-action-icon {
    background: rgba(255, 255, 255, 0.2);
}

/* Tertiary: Search Trucks (Light Purple) */
.fab-action--trucks {
    background: var(--color-accent, #A18DC2);
    color: white;
}

.fab-action--trucks:hover {
    background: #8a75b0;
    color: white;
}

.fab-action--trucks .fab-action-icon {
    background: rgba(255, 255, 255, 0.2);
}

/* =============================================
   STAGGERED ANIMATION FOR ACTIONS
   ============================================= */
.fab-action {
    opacity: 0;
    transform: translateY(10px) translateX(-10px);
}

.fab-container.fab-expanded .fab-action {
    opacity: 1;
    transform: translateY(0) translateX(0);
}

/* Stagger delays (bottom to top appearance) */
.fab-container.fab-expanded .fab-action:nth-child(1) {
    transition-delay: 0.05s;
}

.fab-container.fab-expanded .fab-action:nth-child(2) {
    transition-delay: 0.1s;
}

.fab-container.fab-expanded .fab-action:nth-child(3) {
    transition-delay: 0.15s;
}

/* Reset delays when collapsing */
.fab-container:not(.fab-expanded) .fab-action {
    transition-delay: 0s;
}

/* =============================================
   BACKDROP OVERLAY (Mobile)
   ============================================= */
.fab-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 949; /* Just below FAB */

    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.fab-container.fab-expanded ~ .fab-backdrop {
    opacity: 1;
    visibility: visible;
}

/* =============================================
   SCROLL BEHAVIOR - Reduce Visual Noise
   ============================================= */
.fab-container.fab-scrolling-down {
    opacity: 0.6;
    transform: scale(0.9);
}

.fab-container.fab-scrolling-down:hover {
    opacity: 1;
    transform: scale(1);
}

/* =============================================
   RESPONSIVE - TABLET (769px - 992px)
   ============================================= */
@media (max-width: 992px) {
    .fab-container {
        bottom: 20px;
        left: 20px;
    }

    .fab-toggle {
        height: 52px;
        min-width: 52px;
        padding: 0 16px;
        font-size: 14px;
    }

    .fab-toggle-icon {
        width: 22px;
        height: 22px;
    }
}

/* =============================================
   RESPONSIVE - MOBILE (< 769px)
   ============================================= */
@media (max-width: 768px) {
    .fab-container {
        bottom: 20px;
        left: 16px;
    }

    /* Icon-only toggle on mobile */
    .fab-toggle {
        width: 56px;
        height: 56px;
        min-width: 56px;
        padding: 0;
        border-radius: 50%;
    }

    .fab-toggle-label {
        display: none;
    }

    .fab-toggle-icon {
        width: 26px;
        height: 26px;
    }

    /* Actions remain full with labels */
    .fab-action {
        padding: 10px 16px;
        min-height: 44px; /* Minimum tap target */
        font-size: 13px;
    }

    .fab-action-icon {
        width: 28px;
        height: 28px;
    }

    .fab-action-icon svg {
        width: 16px;
        height: 16px;
    }
}

/* =============================================
   RESPONSIVE - SMALL MOBILE (< 480px)
   ============================================= */
@media (max-width: 479px) {
    .fab-container {
        left: 12px;
        bottom: 16px;
    }

    .fab-toggle {
        width: 52px;
        height: 52px;
        min-width: 52px;
    }

    .fab-action {
        padding: 8px 14px;
        font-size: 13px;
    }
}

/* =============================================
   PAGE-SPECIFIC HIDE ON MOBILE
   ============================================= */
@media (max-width: 768px) {
    .fab-container.fab-hide-mobile,
    .fab-container.fab-hide-mobile ~ .fab-backdrop {
        display: none !important;
    }
}

/* =============================================
   COOKIE CONSENT BANNER AVOIDANCE
   ============================================= */
.termsfeed-com---nb-simple ~ .fab-container {
    bottom: 100px;
}

@media (max-width: 768px) {
    .termsfeed-com---nb-simple ~ .fab-container {
        bottom: 140px;
    }
}

/* =============================================
   ACCESSIBILITY - REDUCED MOTION
   ============================================= */
@media (prefers-reduced-motion: reduce) {
    .fab-container,
    .fab-toggle,
    .fab-toggle-icon,
    .fab-actions,
    .fab-action,
    .fab-action-icon,
    .fab-backdrop {
        transition-duration: 0.01ms !important;
    }
}

/* =============================================
   ACCESSIBILITY - HIGH CONTRAST MODE
   ============================================= */
@media (prefers-contrast: high) {
    .fab-toggle {
        border: 2px solid white;
    }

    .fab-action {
        border: 2px solid currentColor;
    }
}

/* =============================================
   PRINT - HIDE FAB
   ============================================= */
@media print {
    .fab-container,
    .fab-backdrop {
        display: none !important;
    }
}
