/* ============================================
   CHAT.CSS v3.3 - MOBILE Z-INDEX CORRECTED
   ✅ Fixed scroll behavior
   ✅ Better mobile positioning
   ✅ Improved notification system
   ✅ Z-index hierarchy: header (10001) > nav (10000) > chat (9997)
   ✅ Proper pointer-events handling
   ✅ Widget pointer-events ALWAYS none - only chat-window.active gets auto
   ============================================ */

/* Chat Widget Container */
.chat-widget {
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 999999 !important; /* High z-index for DESKTOP only */
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-end;
    gap: 20px;
    pointer-events: none;
}

/* Desktop-specific z-index */
@media (min-width: 769px) {
    .chat-widget {
        z-index: 999999 !important;
    }
}

/* Chat Toggle Button - Bottom Right (HIDDEN ON MOBILE) */
.chat-toggle {
    width: 60px;
    height: 60px;
    background: rgba(255, 107, 53, 0.1);
    border: none;
    border-radius: 0px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
    position: relative;
    overflow: visible;
    clip-path: polygon(0 0, calc(100% - 15px) 0, 100% 15px, 100% 100%, 15px 100%, 0 calc(100% - 15px));
    z-index: 100000;
    pointer-events: auto;
}

.chat-toggle::before {
    content: '';
    position: absolute;
    inset: 0;
    background: #ff6b35;
    opacity: 0;
    transition: opacity 0.4s;
    z-index: -1;
}

.chat-toggle:hover::before {
    opacity: 1;
}

.chat-toggle:hover {
    transform: scale(1.1);
}

.chat-toggle i {
    font-size: 24px;
    color: #ff6b35;
    transition: color 0.3s;
    z-index: 1;
}

.chat-toggle:hover i {
    color: #0a0a0a;
}

/* ============================================
   NOTIFICATION TEXT - ABOVE ICON
   ============================================ */

.chat-notification-text {
    position: absolute;
    bottom: 80px;
    right: 0;
    color: #ffffff;
    font-family: 'REG', sans-serif;
    font-size: 12px;
    padding: 12px 18px;
    white-space: nowrap;
    display: none;
    border: none;
    clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 10px 100%, 0 calc(100% - 10px));
    z-index: 99999;
    box-shadow: 0 4px 20px rgba(255, 107, 53, 0.3);
    pointer-events: auto;
    backdrop-filter: blur(10px);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    opacity: 0;
}

.chat-notification-text.show {
    display: block;
    animation: notificationSlideIn 0.5s ease forwards;
}

@keyframes notificationSlideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.chat-notification-text:hover {
    background: rgba(255, 107, 53, 0.05);
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(255, 107, 53, 0.4);
}

.chat-notification-text::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    background: rgba(255, 255, 255, 0.02);
}

/* ============================================
   CHAT WINDOW - POPUP NEXT TO ICON
   ============================================ */

.chat-window {
    position: absolute;
    bottom: 100px;
    right: 0;
    width: 400px;
    height: 600px;
    max-width: calc(100vw - 50px);
    max-height: calc(100vh - 150px);
    backdrop-filter: blur(30px);
    border: none;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
    clip-path: polygon(0 0, calc(100% - 20px) 0, 100% 20px, 100% 100%, 20px 100%, 0 calc(100% - 20px));
    z-index: 999998 !important; /* Must be below widget container but above everything else */
    pointer-events: none;
    overflow: hidden;
}

.chat-window::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 0;
    background: 
        radial-gradient(circle at 20% 30%, rgba(255,107,53, 0.08) 0%, transparent 45%),
        radial-gradient(circle at 80% 70%, rgba(255,107,53, 0.05) 0%, transparent 40%),
        linear-gradient(180deg, #0a0a0a 0%, #0f0f0f 50%, #0a0a0a 100%);
    animation: chatGradientPulse 8s ease-in-out infinite;
    pointer-events: none;
}

@keyframes chatGradientPulse {
    0%, 100% {
        opacity: 1;
        filter: brightness(1) blur(0px);
    }
    50% {
        opacity: 0.9;
        filter: brightness(1.2) blur(10px);
    }
}

.chat-window.active {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateY(0) scale(1) !important;
    pointer-events: auto !important;
    display: flex !important;
}

/* Chat Header */
.chat-header {
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.chat-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-avatar {
    display: none;
}

.chat-header-info h3 {
    font-family: 'EXTRA', sans-serif;
    font-size: 14px;
    color: var(--white, #fff);
    margin: 0 0 2px 0;
    text-transform: uppercase;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'REG', sans-serif;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
}

.chat-status-dot {
    width: 6px;
    height: 6px;
    background: #00ff88;
    border-radius: 0px;
    animation: statusPulse 2s infinite;
}

@keyframes statusPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chat-close {
    background: rgba(255, 107, 53, 0.1);
    border: none;
    color: #ff6b35;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
    clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 10px 100%, 0 calc(100% - 10px));
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.chat-close::before {
    content: '';
    position: absolute;
    inset: 0;
    background: #ff6b35;
    opacity: 0;
    transition: opacity 0.4s;
    z-index: -1;
}

.chat-close:hover::before {
    opacity: 1;
}

.chat-close:hover {
    color: #0a0a0a;
    transform: translateY(-2px);
}

/* ============================================
   CHAT MESSAGES CONTAINER - FIXED SCROLL
   ============================================ */

.chat-messages {
    flex: 1;
    overflow-y: auto !important;
    overflow-x: hidden;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
    z-index: 1;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 107, 53, 0.6) rgba(10, 10, 10, 0.5);
}

/* ✅ CRITICAL: Force scrollbar to always be visible */
.chat-messages::-webkit-scrollbar {
    width: 10px !important;
    display: block !important;
}

.chat-messages::-webkit-scrollbar-track {
    background: rgba(10, 10, 10, 0.8) !important;
    border-radius: 5px;
    display: block !important;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 107, 53, 0.7) !important;
    border-radius: 5px;
    border: 2px solid rgba(10, 10, 10, 0.8);
    display: block !important;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 107, 53, 1) !important;
}

/* Chat Message */
.chat-message {
    display: flex;
    gap: 12px;
    animation: messageSlideIn 0.3s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user {
    flex-direction: row-reverse;
}

.chat-message-content {
    max-width: 75%;
    word-wrap: break-word;
}

.chat-message-bubble {
    margin-bottom: 20px;
    padding: 12px 16px;
    font-family: 'REG', sans-serif;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px));
}

.chat-message.user .chat-message-bubble {
    background: rgba(255, 107, 53, 0.1);
    border: none;
    color: var(--white, #fff);
}

.chat-message.bot .chat-message-bubble {
    background: rgba(255, 255, 255, 0.02);
    border: none;
    color: rgba(255, 255, 255, 0.9);
}

/* Typing Indicator */
.chat-typing {
    display: none;
    padding: 0 24px 10px;
    position: relative;
    z-index: 1;
}

.chat-typing.active {
    display: block;
}

.chat-typing-dots {
    display: inline-flex;
    gap: 6px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.0);
    border: none;
    clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 10px 100%, 0 calc(100% - 10px));
}

.chat-typing-dot {
    width: 8px;
    height: 8px;
    background: rgba(255, 107, 53, 0.8);
    border-radius: 0px;
    animation: typingBounce 1.4s infinite;
}

.chat-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Chat Input Container */
.chat-input-container {
    padding: 20px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    gap: 12px;
    align-items: center;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.02);
    border: none;
    border-radius: 0px;
    padding: 12px 16px;
    font-family: 'REG', sans-serif;
    font-size: 13px;
    color: var(--white, #fff);
    outline: none;
    transition: all 0.3s;
    text-transform: none;
    clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px));
}

.chat-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
    text-transform: none;
}

.chat-input:focus {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 107, 53, 0.3);
}

.chat-send {
    width: 44px;
    height: 44px;
    background: rgba(255, 107, 53, 0.1);
    border: none;
    border-radius: 0px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px));
}

.chat-send::before {
    content: '';
    position: absolute;
    inset: 0;
    background: #ff6b35;
    opacity: 0;
    transition: opacity 0.4s;
    z-index: -1;
}

.chat-send:hover::before {
    opacity: 1;
}

.chat-send i {
    font-size: 16px;
    color: #ff6b35;
    transition: color 0.4s;
}

.chat-send:hover i {
    color: #0a0a0a;
}

.chat-send:hover {
    transform: translateY(-2px);
}

.chat-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ============================================
   HIDE CHAT WHEN AUTH MODAL IS OPEN
   ============================================ */

.auth-modal.active ~ .chat-widget,
body.auth-modal-open .chat-widget {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

body:has(.auth-modal.active) .chat-widget {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    /* ⚠️ CRITICAL: Mobile z-index MUST be BELOW header and nav! */
    .chat-widget,
    div.chat-widget {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        z-index: 9997 !important; /* BELOW header (10001) and nav (10000) */
        pointer-events: none !important; /* ALWAYS none - only window gets events */
    }
    
    /* Hide desktop toggle button on mobile */
    .chat-toggle {
        display: none !important;
    }
    
    /* Notification positioning for mobile - above mobile nav */
    .chat-notification-text {
        bottom: 110px !important; /* Above mobile nav bar */
        right: 50% !important;
        transform: translateX(50%) !important;
        left: auto !important;
        font-size: 11px !important;
        padding: 10px 16px !important;
        max-width: calc(90vw - 40px) !important;
        white-space: normal !important;
        text-align: center !important;
        z-index: 9996 !important;
    }
    
    .chat-notification-text.show {
        animation: notificationSlideUp 0.5s ease forwards;
    }
    
    @keyframes notificationSlideUp {
        from {
            opacity: 0;
            transform: translateX(50%) translateY(20px);
        }
        to {
            opacity: 1;
            transform: translateX(50%) translateY(0);
        }
    }
    
    .chat-notification-text:hover {
        transform: translateX(50%) translateY(-2px) !important;
    }
    
    /* ============================================
       MOBILE CHAT WINDOW - CENTERED POSITIONING
       CRITICAL: z-index MUST be below header and nav!
       ============================================ */
    .chat-window,
    div.chat-window {
        position: fixed !important;
        top: 70px !important; /* Directly below header */
        bottom: 80px !important; /* Directly above mobile nav */
        left: 12px !important;
        right: 12px !important;
        width: calc(100vw - 24px) !important;
        height: auto !important;
        max-width: calc(100vw - 24px) !important;
        max-height: none !important;
        border-radius: 20px !important;
        clip-path: polygon(0 0, calc(100% - 20px) 0, 100% 20px, 100% 100%, 20px 100%, 0 calc(100% - 20px)) !important;
        display: flex !important;
        flex-direction: column !important;
        z-index: 9995 !important; /* BELOW header and nav! */
    }
    
    .chat-window.active {
        transform: translateY(0) scale(1) !important;
        pointer-events: auto !important; /* Enable interactions only when chat is open */
    }
    
    .chat-header {
        padding: 16px 20px !important;
        flex-shrink: 0 !important;
    }
    
    /* ✅ CRITICAL: Messages container must be flexible */
    .chat-messages {
        padding: 16px 20px !important;
        padding-bottom: 20px !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: thin !important;
        flex: 1 !important;
        overflow-y: auto !important;
        min-height: 150px !important;
    }
    
    /* ✅ Input container stays at bottom of chat window */
    .chat-input-container {
        padding: 16px 20px !important;
        flex-shrink: 0 !important;
        border-top: 1px solid rgba(255, 255, 255, 0.05) !important;
    }
    
    /* ✅ Mobile input - prevent zoom on focus */
    .chat-input {
        font-size: 16px !important; /* iOS won't zoom if >= 16px */
    }
    
    .chat-input::placeholder {
        font-size: 14px !important;
    }
    
    /* ✅ Quick actions positioning */
    .chat-quick-actions {
        flex-shrink: 0 !important;
        padding: 12px 20px !important;
    }
    
    .chat-quick-actions.visible {
        padding: 14px 20px !important;
    }
    
    .chat-message-content {
        max-width: 85% !important;
    }
    
    /* ✅ Prevent body scroll when chat is open */
    body.chat-open {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
    }
}

@media (max-width: 400px) {
    .chat-window {
        top: 75px; /* Adjusted for smaller header */
        bottom: 90px; /* Adjusted for mobile nav */
        left: 15px;
        right: 15px;
        width: calc(100vw - 30px);
        max-height: calc(100vh - 165px);
        z-index: 9995 !important; /* BELOW header and nav */
    }
    
    .chat-header {
        padding: 14px 16px;
    }
    
    .chat-messages {
        padding: 14px 16px;
        padding-bottom: 16px;
    }
    
    .chat-input-container {
        padding: 14px 16px;
    }
    
    .chat-input {
        font-size: 16px !important;
    }
    
    .chat-notification-text {
        bottom: 100px;
        z-index: 9994 !important;
    }
}

/* ============================================
   ENSURE PROPER Z-INDEX STACKING
   ============================================ */

/* Make sure all interactive elements are properly layered */
.chat-window > * {
    position: relative;
}

/* Bot messages with embedded elements need proper width */
.chat-message.bot .chat-message-content {
    max-width: 90%;
}

.chat-message.bot .chat-message-content > *:not(.chat-message-bubble) {
    width: 100%;
}
/* ============================================
   CHAT PRICE TIMER
   ============================================ */
#chatPriceTimer {
    color: #ff6b35;
    font-family: 'EXTRA';
    letter-spacing: 0.5px;
}

.calculation-display {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}