:root {
    --pl-primary: #1750d7;
    --pl-secondary: #c54963;
    --pl-white: #ffffff;
    --pl-gray-light: #f3f4f6;
    --pl-gray: #e5e7eb;
    --pl-text-dark: #1f2937;
    --pl-text-muted: #6b7280;
    --pl-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --pl-glass: rgba(255, 255, 255, 0.95);
}

/* Container & Reset */
#primelane-chat-widget {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 2147483647;
    /* Max z-index to stay on top */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    box-sizing: border-box;
    width: auto;
    height: auto;
    pointer-events: none;
    /* Let clicks pass through container */
}

#primelane-chat-widget * {
    box-sizing: border-box;
}

/* Toggle Button */
@keyframes slowPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(23, 80, 215, 0.7);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(23, 80, 215, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(23, 80, 215, 0);
    }
}

#pl-chat-toggle {
    background-color: var(--pl-primary);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    box-shadow: var(--pl-shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    bottom: 0;
    right: 0;
    pointer-events: auto;
    /* Re-enable pointer events for button */
    touch-action: manipulation;
    /* Optimise touch */
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.2s;
    z-index: 20;
}

/* Only animate pulse when not interacting */
#pl-chat-toggle:not(:active) {
    animation: slowPulse 3s infinite;
}

/* Hover only on devices that support it to avoid sticky hover on mobile */
@media (hover: hover) {
    #pl-chat-toggle:hover {
        animation: none;
        transform: scale(1.1);
    }
}

#pl-chat-toggle.hidden-btn {
    display: none;
    /* Direct hide instead of transform to avoid stacking issues */
}

/* Window Styling */
#pl-chat-window {
    width: 380px;
    height: 650px;
    max-height: 80vh;
    background: var(--pl-white);
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    position: absolute;
    bottom: 80px;
    right: 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
    pointer-events: auto;
    z-index: 10;
}

#pl-chat-window.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Header */
.pl-chat-header {
    background: var(--pl-primary);
    color: var(--pl-white);
    padding: 1.5rem 1.5rem 3.5rem;
    /* Adjusted padding */
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom-left-radius: 24px;
    border-bottom-right-radius: 24px;
    flex-shrink: 0;
    /* Prevent shrinking */
}

.pl-header-content {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.pl-logo-icon {
    background: rgba(255, 255, 255, 0.2);
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pl-header-text h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
}

.pl-header-text p {
    margin: 0.25rem 0 0;
    font-size: 0.9rem;
    opacity: 0.95;
}

#pl-chat-close {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    opacity: 0.9;
    color: white;
    touch-action: manipulation;
}

/* Body */
.pl-chat-body {
    flex: 1;
    padding: 0 1rem 1rem;
    margin-top: -2.5rem;
    /* Overlap header */
    position: relative;
    z-index: 20;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Smooth scroll on iOS */
    scrollbar-width: thin;
}

.pl-tab-content {
    background: var(--pl-white);
    border-radius: 16px;
    padding: 1.25rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    min-height: 300px;
    animation: fadeIn 0.1s ease-out;
    /* Simple fade in for tabs */
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.pl-tab-content.hidden {
    display: none;
}

/* Form Elements */
.pl-booking-form input,
.pl-booking-form select {
    width: 100%;
    padding: 12px;
    /* Larger tap targets */
    margin-bottom: 12px;
    border: 1px solid var(--pl-gray);
    border-radius: 10px;
    outline: none;
    background: white;
    font-size: 16px;
    /* Prevent zoom on iOS */
}

.pl-btn-secondary {
    background: var(--pl-secondary);
    color: white;
    padding: 12px;
    border-radius: 10px;
    font-weight: 600;
    width: 100%;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    touch-action: manipulation;
}

/* List Items */
.pl-list-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 0.5rem;
    /* Larger tap area */
    border-bottom: 1px solid var(--pl-gray-light);
}

.pl-xs-btn {
    background: var(--pl-primary);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
}

/* Accordion */
.pl-faq-question {
    width: 100%;
    background: none;
    border: none;
    text-align: left;
    padding: 1rem 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--pl-text-dark);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    touch-action: manipulation;
}

.pl-faq-answer {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    color: var(--pl-text-muted);
    font-size: 0.85rem;
    line-height: 1.5;
}

/* Bottom Nav */
.pl-bottom-nav {
    background: var(--pl-white);
    border-top: 1px solid var(--pl-gray);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 0.5rem 0;
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
    flex-shrink: 0;
}

.pl-nav-item {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--pl-text-muted);
    font-size: 0.7rem;
    cursor: pointer;
    padding: 8px 0;
    touch-action: manipulation;
}

.pl-nav-item.active {
    color: var(--pl-secondary);
}

/* Mobile Specific Overrides */
@media (max-width: 480px) {
    #primelane-chat-widget {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 0;
        /* Min height when closed */
        overflow: visible;
        z-index: 2147483647;
    }

    /* Toggle Button Mobile Position */
    #pl-chat-toggle {
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 2147483647;
    }

    #pl-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 100dvh;
        /* Dynamic Viewport Height */
        max-height: none;
        border-radius: 0;
        transform: none;
        /* Disable transform to avoid blurry text/stacking issues */
        opacity: 1;
        display: none;
        /* Use simple display toggle for mobile reliability */
        box-shadow: none;
        flex-direction: column;
        z-index: 2147483646;
        /* Behind toggle but top of everything else */
    }

    #pl-chat-window.visible {
        display: flex;
        /* Flex instead of block */
        animation: slideUp 0.25s ease-out forwards;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }

        to {
            transform: translateY(0);
        }
    }

    .pl-chat-header {
        padding-top: max(20px, env(safe-area-inset-top));
        /* Safe area for notch */
        border-radius: 0;
    }

    .pl-bottom-nav {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        /* Safe area for home bar */
        border-radius: 0;
    }
}