﻿* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #080821;
    color: #fff;
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

.main-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    position: relative;
    overflow: hidden;
}

/* Hide the old top header bar completely */
.header {
    display: none !important
}

/* === AVATAR NOT CONNECTED STYLES === */
#avatar-not-connected {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.avatar-error-container {
    text-align: center;
    color: white;
    max-width: 400px;
    padding: 40px 20px;
}

.avatar-error-logo {
    width: 150px;
    height: auto;
    margin-bottom: 20px;
    opacity: 0.9;
}

.avatar-error-message {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 10px;
    color: #ff6b6b;
}

.avatar-error-description {
    font-size: 16px;
    margin-bottom: 30px;
    opacity: 0.9;
    line-height: 1.4;
}

.reconnect-button {
    padding: 12px 24px !important;
    font-size: 16px !important;
    font-weight: bold;
    border-radius: 8px;
    transition: all 0.3s ease;
    min-width: 140px;
}

.reconnect-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 123, 255, 0.3);
}

.reconnect-button i {
    margin-right: 8px;
}

.reconnect-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.reconnect-button:disabled:hover {
    transform: none;
    box-shadow: none;
}

/* Animation for reconnect button */
.reconnect-button.reconnecting i {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Mobile responsive styles for avatar error */
@media (max-width: 768px) {
    .avatar-error-container {
        padding: 30px 15px;
        max-width: 320px;
    }
    
    .avatar-error-logo {
        width: 120px;
        margin-bottom: 15px;
    }
    
    .avatar-error-message {
        font-size: 20px;
        margin-bottom: 8px;
    }
    
    .avatar-error-description {
        font-size: 14px;
        margin-bottom: 25px;
    }
    
    .reconnect-button {
        padding: 10px 20px !important;
        font-size: 14px !important;
        min-width: 120px;
    }
}

/* === STEP 1: INITIAL LOADING STYLES === */
#avatar-loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #080821 0%, #1a1a3e 100%);
    background-image: url('/image/avatar_gulfair_background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    display: none; /* Initially hidden, shown by JS */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.5s ease;
}

#avatar-loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1;
}

/* Gulf Air Logo Container */
.logo-container {
    position: absolute;
    top: 40px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.gulf-air-logo {
    width: auto;
    max-width: 400px;
    object-fit: contain;
}

@media (max-width: 768px) {
    .logo-container {
        top: 30px;
    }
    
    .gulf-air-logo {
        height: 50px;
        max-width: 200px;
    }
    
    /* Mobile background images */
    #avatar-loading {
        background-image: url('/image/avatar_gulfair_background_mobile.png') !important;
    }
    
    #tap-overlay {
        background-image: url('/image/avatar_gulfair_background_mobile.png') !important;
    }
}

    #avatar-loading.show {
        display: flex;
        opacity: 1;
    }

.loading-spinner {
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top: 4px solid #ffffff;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
    margin-bottom: 30px;
    position: relative;
    z-index: 10;
}

.loading-text {
    font-size: 18px;
    font-weight: 300;
    letter-spacing: 0.5px;
    color: #ffffff;
    text-align: center;
    margin-bottom: 20px;
    position: relative;
    z-index: 10;
}

/* Loading progress indicator */
.loading-progress {
    width: 200px;
    height: 4px;
    background: rgba(40, 40, 70, 0.3);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 20px;
    position: relative;
    z-index: 10;
}

.loading-progress-bar {
    height: 100%;
    background: rgba(40, 40, 70, 0.3);
    border-radius: 2px;
    width: 0%;
    animation: loadingProgress 3s ease-in-out;
}

@keyframes loadingProgress {
    0% {
        width: 0%;
    }

    50% {
        width: 60%;
    }

    100% {
        width: 100%;
    }
}

/* === STEP 2: TAP/CLICK OVERLAY STYLES === */
#tap-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #080821 0%, #1a1a3e 100%);
    background-image: url('/image/avatar_gulfair_background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    display: none; /* Initially hidden, shown by JS */
    justify-content: center;
    align-items: center;
    z-index: 500;
/*    cursor: pointer;*/
    opacity: 0;
    transition: opacity 0.5s ease;
}

#tap-overlay::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1;
    pointer-events: none;
}

    #tap-overlay:not(.hidden) { /* :not(.hidden) to control visibility via JS */
        display: flex;
        opacity: 1;
    }

    #tap-overlay.hidden {
        display: none;
    }

.tap-content {
    text-align: center;
    max-width: 90%;
    padding: 20px;
    margin-top: 50px; /* Add space for logo above */
    position: relative;
    z-index: 10;
}

.avatar-preview {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    margin: 0 auto 30px;
    background: url('/image/saqer.png') center/cover;
    background-color: #333;
    border: 4px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    animation: avatarFloat 3s ease-in-out infinite;
}

@keyframes avatarFloat {
    0%, 100% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-10px);
    }
}

.tap-message {
    font-size: 28px;
    font-weight: 300;
    margin-bottom: 15px;
    color: #ffffff;
    animation: fadeInUp 0.8s ease-out;
}

.tap-instruction {
    font-size: 18px;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 40px;
    animation: fadeInUp 0.8s ease-out 0.2s both;
}

.tap-indicator {
    display: inline-flex;
    align-items: center;
    gap: 15px;
    padding: 20px 35px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    animation: pulse 2s infinite, fadeInUp 0.8s ease-out 0.4s both;
    transition: all 0.3s ease;
}

    .tap-indicator:hover {
        background: rgba(255, 255, 255, 0.15);
        border-color: rgba(255, 255, 255, 0.5);
        transform: scale(1.05);
    }

.hand-icon {
    font-size: 28px;
    animation: tap 1.5s infinite;
    color: #ffffff;
}

/* === STEP 3: FLOATING CONTROL BUTTONS === */
.corner-controls {
    position: fixed;
    top: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 200;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

    .corner-controls.show {
        opacity: 1;
        transform: translateY(0);
        transition-delay: 0.1s; /* Stagger appearance */
    }

    .corner-controls button {
        width: 60px;
        height: 60px;
        border-radius: 50%;
        background: #1b1b36; /* Darker, distinct background */
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.3s ease;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

        .corner-controls button:hover {
            background: #2a2a4a; /* Lighter on hover */
            transform: scale(1.05);
        }

    .corner-controls i {
        font-size: 20px;
        color: #fff;
    }

    /* Special styling for close/rate button in corner controls */
    .corner-controls #closeRate {
        background: #dc3545; /* Red background for close button */
    }

    .corner-controls #closeRate:hover {
        background: #c82333; /* Darker red on hover */
        transform: scale(1.05);
    }

/* === BOTTOM MICROPHONE BUTTON === */
.bottom-controls {
    position: fixed;
    bottom: 20px; /* Match the chat history button */
    right: 20px; /* Match the padding */
    z-index: 150;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
    pointer-events: auto; /* Change from none to auto */
    display: flex;
    justify-content: center; /* Center the single microphone button */
}

    .bottom-controls.show {
        opacity: 1;
        transform: translateY(0);
        transition-delay: 0.2s; /* Stagger appearance */
    }

#microphone {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    z-index: 200;
}

    #microphone:hover {
        transform: scale(1.05);
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    }

    #microphone:disabled {
        opacity: 0.6;
        cursor: not-allowed;
    }

    #microphone i {
        font-size: 24px;
        color: #080821; /* Dark icon on white background */
        transition: all 0.3s ease;
    }

/* Audio wave animation circles */
.audio-wave {
    position: absolute;
    border-radius: 50%;
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.5); /* Semi-transparent white */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    display: none; /* Hidden by default, shown by JS */
}

/* Multiple rings with different sizes and animations */
.wave-circle-1 {
    width: 80px;
    height: 80px;
    animation: wave 2s infinite ease-out;
    animation-delay: 0s;
}

.wave-circle-2 {
    width: 80px;
    height: 80px;
    animation: wave 2s infinite ease-out;
    animation-delay: 0.5s;
}

.wave-circle-3 {
    width: 80px;
    height: 80px;
    animation: wave 2s infinite ease-out;
    animation-delay: 1s;
}

/* Wave animation keyframes */
@keyframes wave {
    0% {
        opacity: 0.8;
        width: 64px; /* Start from mic button size */
        height: 64px;
    }

    100% {
        opacity: 0;
        width: 150px; /* Expand outwards */
        height: 150px;
    }
}

/* State when recording */
#microphone.recording {
    background-color: #e53935; /* Red for recording */
}

    #microphone.recording i {
        color: #fff; /* White icon on red background */
    }

/* State when AI is speaking */
#microphone.speaking {
    background-color: #ffffff; /* Back to white when AI speaks */
}

    #microphone.speaking i {
        color: #080821; /* Original icon color */
    }

/* === AVATAR CONTAINER - ENHANCED MOBILE SUPPORT === */
.avatar-container {
    position: relative;
    flex: 1;
    overflow: hidden;
    background-color: #080821;
    background-image: url('https://airportwayfinding.blob.core.windows.net/appimages/avatar_gulfair_background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    width: 100%;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.6s ease, visibility 0.6s ease;
    /* Ensure proper aspect ratio handling */
    min-height: 100vh;
}

    .avatar-container.show {
        opacity: 1;
        visibility: visible;
    }

#remoteVideo {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #080821;
    background-image: url('https://airportwayfinding.blob.core.windows.net/appimages/avatar_gulfair_background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding-bottom: 0;
    z-index: 20;
}

/* Canvas styling - most specific styles are now applied by JavaScript's applyCanvasSizing */
.avatar-canvas { /* This class is added to the canvas in JS */
    display: block; /* Removes extra space below inline elements */
    user-select: none;
    /* Width, height, object-fit, object-position are set by JS (applyCanvasSizing) */
    /* For initial state before JS, or if JS fails: */
    max-width: 100%;
    max-height: 100%;
    opacity: 0; /* JS will fade it in */
    visibility: visible; /* Ensure visibility is not hidden */
    transition: opacity 0.3s ease; /* Smooth fade in by JS */
}

/* Force canvas to be visible when JS sets opacity to 1 */
.avatar-canvas[style*="opacity: 1"],
#transparentCanvas[style*="opacity: 1"],
canvas[style*="opacity: 1"] {
    opacity: 1 !important;
    visibility: visible !important;
    display: block !important;
    z-index: 100 !important;
}


#transparentCanvas { /* ID of the canvas, specific styles in JS if needed */
    /* Ensure the transparent canvas is properly handled */
    z-index: inherit;
}


#canvas { /* Hidden if not used or managed by JS */
    display: none;
}

#tmpCanvas { /* Hidden if not used or managed by JS */
    display: none;
}

/* Fix hidden video but keep playing */
#videoPlayer { /* The source <video> element that is drawn onto the canvas */
    position: absolute;
    width: 0.1px; /* Keep it minimal and out of sight */
    height: 0.1px;
    opacity: 0;
    left: -9999px; /* Move it off-screen */
    top: -9999px;
}


.chat-container {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 120px; /* Space for microphone button + margin */
    height: calc(100% - 150px); /* Take most of the screen except for top bar and bottom controls */
    overflow-y: auto; /* Use auto for scrolling */
    overflow-x: hidden;
    display: flex; /* This is required for the solution */
    flex-direction: column; /* This is required for the solution */
    z-index: 50;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
    scrollbar-width: thin;
    padding: 0 0 25px 0;
}

/* When typing indicator present, keep it anchored at bottom without shifting */
.chat-container.has-typing > #typingIndicator-main:first-child {
    margin-top: auto !important;
}

/* Force visibility of main typing indicator structure */
/* Standalone main typing indicator container */
#typingIndicator-main {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

    /* This new rule makes the content stick to the bottom */
    .chat-container > .message-wrapper:first-child {
        margin-top: auto;
    }

    .chat-container::-webkit-scrollbar {
        width: 6px;
        display: block;
    }

    .chat-container::-webkit-scrollbar-thumb {
        background-color: rgba(255, 255, 255, 0.3);
        border-radius: 3px;
    }

    .chat-container::-webkit-scrollbar-track {
        background-color: rgba(255, 255, 255, 0.1);
    }

    .chat-container.show {
        opacity: 1;
        transform: translateY(0);
        transition-delay: 0.3s; /* Stagger appearance */
    }
.message-wrapper {
    width: 100%;
    margin-bottom: 15px; /* Increased bottom margin between message wrappers */
    animation: fadeIn 0.3s ease forwards;
    transition: opacity 0.3s ease;
    display: flex;
}/* Fade effect only for the previous message when a new message is added */
    .message-wrapper.fade-message {
        opacity: 0.5; /* 50% opacity for the previous message */
        animation: fadeMessage 0.3s ease forwards;
    }

    /* Keep the newest message fully visible */
    .message-wrapper:not(.fade-message) {
        opacity: 1; /* 100% opacity for the current message */
    }

    /* When a message is unfaded */
    .message-wrapper.fade-message.unfade {
        animation: unfadeMessage 0.3s ease forwards;
    }

.user-message-wrapper {
    align-self: flex-end; /* Align to right side */
    justify-content: flex-end;
    padding: 0 20px; /* Increased horizontal padding */
    box-sizing: border-box;
    margin: 10px 0; /* Added vertical margin for better spacing between messages */
}

.ai-message-wrapper {
    align-self: flex-start; /* Align to left side */
    justify-content: flex-start;
    padding: 0 20px; /* Increased horizontal padding */
    box-sizing: border-box;
    margin: 10px 0; /* Added vertical margin for better spacing between messages */
    display: flex;
    flex-direction: column;
}

.typing-indicator-wrapper {
    align-self: flex-start;
    justify-content: flex-start;
    padding: 0 20px; /* Match the ai-message-wrapper padding of 0 20px */
    box-sizing: border-box;
    animation: fadeIn 0.3s ease forwards;
    width: 100%;
    margin: 10px 0; /* Match the ai-message-wrapper margin */
}

.message {
    padding: 16px 20px; /* Increased padding for better text spacing */
    border-radius: 18px;
    word-break: break-word;
    line-height: 1.6; /* Better line height for readability */
    position: relative;
    font-size: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px); /* Add subtle backdrop blur */
    min-width: 120px; /* Minimum width for consistency */
    max-width: 75%; /* Consistent max width for all messages */
    margin: 8px 0; /* Add vertical margin between messages */
    unicode-bidi: plaintext;
    word-wrap: break-word;
    white-space: normal; /* Changed from pre-wrap to normal to handle whitespace better */
    text-align: left; /* Ensure consistent text alignment */
    box-sizing: border-box; /* Include padding in width calculation */
}

/* RTL Text Support for Arabic */
.message[lang="ar"] {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif, 'Arial Unicode MS', sans-serif;
    text-align: right;
    direction: rtl;
}

/* Ensure mixed content (Arabic and English) is displayed properly */
.message .ar-text {
    direction: rtl;
    text-align: right;
    unicode-bidi: embed;
}

.user-message {
    background-color: rgba(30, 136, 229, 0.9); /* Slightly transparent */
    color: white;
    border-radius: 18px;
    border-bottom-right-radius: 6px; /* Pointed corner on bottom right for user messages */
    margin-left: auto; /* Push to right side */
}

.ai-message {
    background-color: rgba(51, 51, 72, 0.9); /* Slightly transparent */
    color: white;
    border-radius: 18px;
    border-bottom-left-radius: 6px; /* Pointed corner on bottom left for AI messages */
    margin-right: auto; /* Push to left side */
    margin-left: 12px; /* Add left margin */
    letter-spacing: 0.02em; /* Slight letter spacing for better readability */
    max-width: 75%; /* Match general message setting for consistency */
    min-height: 20px; /* Minimum height to prevent tiny bubbles */
}

/* Additional text formatting for better message display */

/* Improve text rendering and prevent layout shifts */
.ai-message * {
    max-width: 100%;
    box-sizing: border-box;
}

.ai-message p, .ai-message div {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Prevent unwanted line breaks in the middle of words */
.ai-message {
    text-rendering: optimizeLegibility;
    font-kerning: auto;
    font-variant-ligatures: common-ligatures;
}

/* Ensure consistent spacing for streamed content */
.ai-message.streaming {
    min-height: 20px;
    transition: none; /* Disable transitions during streaming for smoother updates */
}

/* Handle code blocks within messages */
.ai-message code {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
}

.ai-message pre {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 10px;
    border-radius: 5px;
    overflow-x: auto;
    margin: 8px 0;
}

.ai-message pre code {
    background: none;
    padding: 0;
}

/* Add styles for paragraph text within AI messages */
.ai-message p {
    margin: 0 0 10px 0; /* Add bottom margin to paragraphs for spacing */
    line-height: 1.5; /* Consistent line height */
}

.ai-message p:last-child {
    margin-bottom: 0; /* Remove margin from last paragraph */
}

/* Eliminate spacing between paragraphs and button containers */
.ai-message p + .button-scroll-container,
.chat-history-message .content p + .button-scroll-container,
.content p + .button-scroll-container {
    margin-top: 0 !important; /* Force no margin on button container */
}

/* Remove bottom margin from paragraphs when followed by button containers */
.ai-message p:has(+ .button-scroll-container),
.chat-history-message .content p:has(+ .button-scroll-container),
.content p:has(+ .button-scroll-container) {
    margin-bottom: 0 !important; /* Force no bottom margin on paragraph */
}

.chat-history-message ul, .chat-history-message ol {
    padding-left: 20px;
    margin: 8px 0;
}

.chat-history-message li {
    margin-bottom: 0px;
    line-height: 1.5;
}

/* Fallback for browsers that don't support :has() - target the last paragraph in content */
.content p:last-of-type {
    margin-bottom: 0; /* Remove last paragraph margin in content divs */
}

/* Format lists within AI messages */
.ai-message ul, .ai-message ol {
    padding-left: 20px; /* Add proper indentation */
    margin: 8px 0; /* Add spacing above and below lists */
}

.ai-message li {
    margin-bottom: 0px; /* Add spacing between list items */
    line-height: 1.5; /* Consistent line height */
}

/* Improve text flow and readability */
.ai-message {
    text-align: left;
    direction: ltr;
}

.ai-message * {
    max-width: 100%;
    box-sizing: border-box;
    word-spacing: normal; /* Ensure normal word spacing */
    letter-spacing: normal; /* Ensure normal letter spacing */
}

/* Clean up any extra spacing in HTML elements */
.ai-message div,
.ai-message span,
.ai-message p {
    white-space: normal; /* Override any pre-wrap settings */
}

/* Ensure buttons and interactive elements have proper spacing */
.ai-message .gulf-air-button,
.ai-message .book-now-button {
    margin: 8px 4px; /* Consistent button spacing */
}

/* Markdown formatting for AI messages */
.ai-message strong {
    font-weight: 600;
    color: #fff;
}

.ai-message em {
    font-style: italic;
    color: rgba(255, 255, 255, 0.95);
}

.typing-indicator {
    background: linear-gradient(135deg, #2c2c54 0%, #40407a 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 12px 16px;
    margin: 4px 0;
    max-width: 80%;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
}

.typing-dots::before {
    content: "AI is typing";
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    margin-right: 8px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.6);
    animation: typing-pulse 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-pulse {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    30% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Typing indicator for chat history panel */
.typing-indicator-history {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(40, 40, 70, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    width: fit-content;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

    .typing-indicator-history .typing-text {
        font-size: 14px;
        color: rgba(255, 255, 255, 0.7);
        margin-right: 8px;
        font-weight: 500;
    }

.typing-indicator-history .typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 14px;
}

.typing-indicator-history .typing-dots::before {
    content: none; /* Remove the "AI is typing" text since we have it as separate element */
}

.typing-indicator-history .typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.6);
    animation: typing-pulse 1.4s infinite ease-in-out;
    display: inline-block;
}

/* Add animation delay for each dot to create sequence */
.typing-indicator-history .typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-indicator-history .typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator-history .typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@media (max-width: 500px) {
    /* Consistent mobile styling for both main chat typing indicator and history chat typing indicator */
    .typing-indicator,
    .typing-indicator-history {
        padding: 12px 16px;
        background: rgba(40, 40, 70, 0.3);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 20px;
        max-width: 80%;
        align-self: flex-start;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        margin: 4px 0;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }
    
    .typing-dots::before,
    .typing-indicator-history .typing-text {
        font-size: 14px;
        font-weight: 500;
        margin-right: 8px;
        color: rgba(255, 255, 255, 0.7);
    }
    
    .typing-dots,
    .typing-indicator-history .typing-dots {
        height: 14px;
        display: flex;
        align-items: center;
        gap: 4px;
    }
    
    .typing-dot,
    .typing-indicator-history .typing-dot {
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background-color: rgba(255, 255, 255, 0.6);
    }
}

/* === CONTROLS === */
.mic-button-container { /* If you need a wrapper for mic/stop */
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
}

.mic-button, .stop-button { /* Example styles if you have separate buttons */
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: #e53935;
    color: white;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

    .mic-button:hover, .stop-button:hover {
        transform: scale(1.05);
    }

    .mic-button:disabled {
        opacity: 0.6;
    }

/* === FOOTER === */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent footer */
    z-index: 40;
}

    .footer a {
        color: rgba(255, 255, 255, 0.7);
        font-size: 12px;
        text-decoration: none;
        transition: color 0.3s ease;
    }

        .footer a:hover {
            color: rgba(255, 255, 255, 1); /* Brighter on hover */
        }

/* === LANGUAGE SELECTION OVERLAY === */
.language-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #1b1b36; /* Dark background */
    padding: 16px;
    z-index: 1500; /* Higher than chat history button */
    transform: translateY(100%); /* Hidden by default */
    transition: transform 0.3s ease;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3); /* Shadow for depth */
}

    .language-overlay.active {
        transform: translateY(0); /* Slide in when active */
    }

.language-header {
    margin-bottom: 20px;
    font-size: 18px;
    color: #fff;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1); /* Subtle separator */
    font-weight: 500;
}

.language-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    cursor: pointer;
    transition: background-color 0.3s ease;
    border-radius: 8px;
    margin: 4px 0;
}

    .language-option:hover {
        background-color: rgba(255, 255, 255, 0.05); /* Subtle hover effect */
        padding-left: 8px; /* Indent on hover for visual feedback */
        padding-right: 8px;
    }

.language-radio {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid #fff; /* White border */
    display: inline-block;
    position: relative;
    transition: all 0.3s ease;
}

    .language-radio.selected {
        border-color: #4CAF50; /* Green when selected */
    }

        .language-radio.selected:after {
            content: '';
            width: 10px;
            height: 10px;
            background-color: #4CAF50; /* Green inner circle */
            border-radius: 50%;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }

/* === LOADING INDICATOR === */
#loading-indicator { /* This is for the <div id="loading-indicator"> inside .avatar-container */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(8, 8, 33, 0.9); /* Semi-transparent overlay */
    display: flex; /* Managed by JS */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    z-index: 300; /* Above avatar, below other overlays */
}

.spinner {
    border: 5px solid rgba(255, 255, 255, 0.3); /* Lighter border for spinner */
    border-radius: 50%;
    border-top: 5px solid white; /* Solid white for spinning part */
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

#loading-percentage {
    color: white;
    font-size: 16px;
    margin-top: 10px;
    font-family: Arial, sans-serif;
}

/* === ERROR OVERLAY STYLES === */
.error-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(8, 8, 33, 0.95); /* Darker overlay for errors */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000; /* Highest z-index */
    animation: fadeIn 0.3s ease;
}

.error-content {
    background: linear-gradient(135deg, #1a1b2e 0%, #16213e 100%); /* Gradient background */
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    max-width: 400px;
    margin: 20px; /* Ensure spacing on small screens */
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); /* Prominent shadow */
    border: 1px solid rgba(255, 255, 255, 0.1); /* Subtle border */
}

    .error-content h3 {
        color: #ff6b6b; /* Red for error titles */
        margin-bottom: 20px;
        font-size: 24px;
        font-weight: 500;
    }

    .error-content p {
        color: rgba(255, 255, 255, 0.8); /* Lighter text for readability */
        margin-bottom: 30px;
        line-height: 1.5;
        font-size: 16px;
    }

    .error-content button {
        background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%); /* Green button */
        color: white;
        border: none;
        padding: 12px 30px;
        border-radius: 25px; /* Pill-shaped button */
        font-size: 16px;
        cursor: pointer;
        transition: all 0.3s ease;
        font-weight: 500;
    }

        .error-content button:hover {
            background: linear-gradient(135deg, #45a049 0%, #3d8b40 100%); /* Darker green on hover */
            transform: translateY(-2px); /* Slight lift on hover */
            box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3); /* Shadow for button */
        }

/* === ANIMATIONS === */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }
}

@keyframes tap {
    0%, 100% {
        transform: scale(1);
    }

    50% {
        transform: scale(0.9);
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px); /* Slight upward movement */
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInFromBottom {
    from {
        transform: translateY(100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideInFromRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeMessage {
    from {
        opacity: 1;
    }
    to {
        opacity: 0.65;
    }
}

@keyframes unfadeMessage {
    from {
        opacity: 0.65;
    }
    to {
        opacity: 1;
    }
}

/* === UTILITIES === */
.hidden {
    display: none !important;
}

.fading-out {
    opacity: 0;
    transform: translateY(-10px); /* Move up as it fades */
    transition: all 0.5s ease;
}

.error-message { /* For inline error messages if needed */
    color: #ff6b6b;
    font-style: italic;
}

/* === RESPONSIVE DESIGN === */

/* Mobile adjustments for #remoteVideo and its contents */
@media (max-width: 768px) {
    body {
        margin: 0;
        padding: 0;
        overflow: hidden;
        position: fixed;
        width: 100vw;
        height: 100vh;
        top: 0;
        left: 0;
    }

    .avatar-container {
        background-image: url('https://airportwayfinding.blob.core.windows.net/appimages/avatar_gulfair_background_mobile.png');
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
        /* Ensure full height coverage */
        height: 100vh;
        width: 100vw;
        position: fixed;
        top: 0;
        left: 0;
    }

    #remoteVideo {
        top: 0; /* Remove top spacing - was 5vh */
        left: 0;
        width: 100%;
        height: 100vh; /* Full viewport height */
        background-image: url('https://airportwayfinding.blob.core.windows.net/appimages/avatar_gulfair_background_mobile.png');
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
        /* Remove background-attachment: fixed for mobile performance */
        padding: 0;
        margin: 0;
        position: absolute;
    }

    .avatar-preview {
        width: 150px;
        height: 150px;
    }

    .chat-container {
        bottom: 90px; /* Keep same as before */
        height: calc(100vh - 140px); /* Use viewport height instead */
        top: auto; /* Let it position from bottom */
    }

    .tap-message {
        font-size: 24px;
    }

    .tap-instruction {
        font-size: 16px;
    }

    .tap-indicator {
        padding: 15px 25px;
        gap: 10px;
    }

    .hand-icon {
        font-size: 24px;
    }

    .corner-controls {
        top: 12px;
        right: 12px;
        gap: 8px;
    }

        .corner-controls button {
            width: 50px;
            height: 50px;
        }

        .corner-controls i {
            font-size: 18px;
        }

    #microphone {
        width: 56px;
        height: 56px;
    }

        #microphone i {
            font-size: 20px;
        }

    .message {
        font-size: 14px;
        padding: 10px 14px;
        max-width: 90%; /* Allow bubbles to be a bit wider on mobile */
    }

    .message-wrapper {
        width: 100%;
        display: flex; /* Ensure display:flex is maintained on mobile */
    }


    .chat-history-panel .button-grid {
        display: flex !important;
        flex-direction: column !important;
        width: 100%;
        gap: 10px;
        /* Fix position issues during scroll */
        transform: translateZ(0);
    }

    .chat-history-panel .gulf-air-button {
        width: 100% !important;
        margin: 0;
        box-sizing: border-box;
        /* Fix position issues during scroll */
        transform: translateZ(0);
        backface-visibility: hidden;
    }
}

/* Extra small mobile devices */
@media (max-width: 480px) {
    .avatar-container {
        background-image: url('https://airportwayfinding.blob.core.windows.net/appimages/avatar_gulfair_background_mobile.png');
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
        height: 100vh;
        width: 100vw;
        position: fixed;
        top: 0;
        left: 0;
    }

    #remoteVideo {
        top: 0; /* Remove top spacing - was 3vh */
        left: 0;
        width: 100%;
        height: 100vh; /* Full viewport height */
        background-image: url('https://airportwayfinding.blob.core.windows.net/appimages/avatar_gulfair_background_mobile.png');
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
        padding: 0;
        margin: 0;
        position: absolute;
    }

    .chat-container {
        bottom: 100px;
        height: calc(100vh - 140px);
        top: auto;
    }
}

/* Very small screens and landscape orientation adjustments */
@media (max-height: 600px) { /* Applies to both portrait and landscape if height is small */
    .avatar-preview {
        width: 120px;
        height: 120px;
        margin-bottom: 20px;
    }

    .tap-content {
        padding: 10px;
    }

    .tap-message {
        font-size: 20px;
        margin-bottom: 10px;
    }

    .tap-instruction {
        font-size: 14px;
        margin-bottom: 25px;
    }

    .bottom-controls {
        bottom: 30px; /* Closer to edge on shorter screens */
    }

    .chat-container {
        bottom: 80px; /* Adjusted for new bottom controls position */
        max-height: 25vh; /* Further reduce chat height */
    }

    .footer {
        height: 30px;
    }

    #remoteVideo {
        top: 0; /* No top margin for full coverage */
        height: 100%; /* Maximize height */
    }
}

@media (max-width: 375px) { /* Styles for very narrow screens like iPhone SE */
    .message {
        max-width: 90%; /* Allow messages to take more width */
        font-size: 13px;
        padding: 10px 12px;
    }
    
    .user-message-wrapper, .ai-message-wrapper {
        padding: 0 8px; /* Less padding on very small screens */
    }

    /* .mic-button, .stop-button - These are general classes, #microphone is primary ID */
#microphone {
        width: 50px;
        height: 50px;
    }
    
    .chat-history-button {
        width: 50px; /* Match microphone size */
        height: 50px;
    }


    .corner-controls button {
        width: 44px;
        height: 44px;
    }

    .corner-controls i {
        font-size: 16px;
    }

    .tap-indicator {
        padding: 12px 20px;
        font-size: 14px;
    }
}



/* === IPHONE NOTCH HANDLING (Safe Area Insets) === */
@supports (padding-top: env(safe-area-inset-top)) {
    body {
        /* Remove safe area padding for full-screen avatar experience */
        padding: 0;
    }
    /* Adjust fixed elements to respect safe areas */
    .footer {
        /* If footer is always at the very bottom of the viewport, adjust its internal padding or position */
        padding-bottom: calc(env(safe-area-inset-bottom) / 2); /* Example: Adjust padding if needed */
        bottom: env(safe-area-inset-bottom); /* Or shift entire element up */
    }

    .bottom-controls {
        /* Use same calculation as chat history button */
        bottom: calc(20px + env(safe-area-inset-bottom));
    }
    /* Ensure chat history button has matching safe area handling */
    .chat-history-button {
        bottom: calc(20px + env(safe-area-inset-bottom));
    }
    /* Adjustments for smaller heights within safe area context */
    @media (max-height: 600px) {
        .bottom-controls {
            bottom: 20px; /* Keep same as chat button instead of 30px */
        }
    }


    .corner-controls {
        /* Default top is 16px. Add safe area inset. */
        top: calc(16px + env(safe-area-inset-top));
    }

    @media (max-width: 768px) { /* Mobile specific corner controls */
        .corner-controls {
            top: calc(12px + env(safe-area-inset-top));
        }
    }


    .chat-container {
        /* Default bottom is 110px. Add safe area inset. */
        bottom: calc(110px + env(safe-area-inset-bottom));
    }
    /* Mobile specific chat container adjustments */
    @media (max-width: 768px) {
        .chat-container {
            bottom: calc(90px + env(safe-area-inset-bottom));
        }
    }

    @media (max-width: 480px) {
        .chat-container {
            bottom: calc(100px + env(safe-area-inset-bottom));
        }
    }

    @media (max-height: 600px) {
        .chat-container {
            bottom: calc(80px + env(safe-area-inset-bottom));
        }
    }

    /* For full-screen avatar experience, ignore safe area insets for the avatar container and video */
    @media (max-width: 768px) {
        .avatar-container {
            top: 0 !important; /* Override safe area */
            height: 100vh !important; /* Full viewport height */
        }
        
        #remoteVideo {
            top: 0 !important; /* Override safe area, full screen */
            height: 100vh !important; /* Full viewport height */
        }
    }

    @media (max-width: 480px) {
        .avatar-container {
            top: 0 !important; /* Override safe area */
            height: 100vh !important; /* Full viewport height */
        }
        
        #remoteVideo {
            top: 0 !important; /* Override safe area, full screen */
            height: 100vh !important; /* Full viewport height */
        }
    }


    #remoteVideo {
        /* Adjust top and height to fit within safe areas correctly */
        /* Desktop base: top: 0; height: 100%; */
        top: env(safe-area-inset-top);
        height: calc(100% - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }
    /* Mobile specific #remoteVideo adjustments considering safe areas */
    @media (max-width: 768px) {
        #remoteVideo {
            top: env(safe-area-inset-top);
            height: calc(100% - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        }
    }

    @media (max-width: 480px) {
        #remoteVideo {
            top: env(safe-area-inset-top);
            height: calc(100% - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        }
    }

    @media (max-height: 600px) { /* This applies to any orientation if height is small */
        #remoteVideo {
            top: env(safe-area-inset-top);
            height: calc(100% - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        }
    }
}


/* === LANDSCAPE ORIENTATION - FIXED === */
@media (orientation: landscape) and (max-height: 500px) { /* Target low-height landscape */
    .avatar-preview {
        width: 100px;
        height: 100px;
        margin-bottom: 15px;
    }

    .tap-message {
        font-size: 20px;
        margin-bottom: 8px;
    }

    .tap-instruction {
        font-size: 14px;
        margin-bottom: 20px;
    }

    .tap-indicator {
        padding: 10px 20px;
        font-size: 13px;
    }

    #remoteVideo {
        /* Base landscape setting for remoteVideo */
        top: 0;
        height: 100%;
        /* padding-bottom: 0; Already set */
        /* align-items: flex-end; Already set */
    }
    /* Adjustments for safe areas in landscape */
    @supports (padding-top: env(safe-area-inset-top)) { /* More accurately (padding-left: env(safe-area-inset-left)) for landscape */
        #remoteVideo {
            top: env(safe-area-inset-top); /* Top notch might exist in some landscape */
            /* Account for side notches often present in landscape. Height is also affected by top/bottom safe areas. */
            height: calc(100% - env(safe-area-inset-top) - env(safe-area-inset-bottom));
            /* The main body padding should handle left/right safe areas for #remoteVideo if it's 100% width */
        }

        .bottom-controls {
            /* Ensure mic button considers horizontal safe areas if it's centered an screen is narrow */
            /* Default 'bottom' value needs to be adjusted for landscape safe area at bottom */
            bottom: calc(20px + env(safe-area-inset-bottom)); /* Example: 20px base for landscape */
            left: calc(env(safe-area-inset-left)); /* Adjust if microphone is not full width */
            right: calc(env(safe-area-inset-right));
            width: auto; /* Recalculate width if using left/right safe areas */
        }        .chat-container {
            /* Ensure chat is not obscured by side safe areas */
            bottom: calc(80px + env(safe-area-inset-bottom)); /* Base bottom for landscape chat */
            left: env(safe-area-inset-left);
            right: env(safe-area-inset-right);
            height: calc(100% - 100px); /* Take most of the screen height */
        }
    }


    .chat-container { /* Non-safe area landscape */
        height: calc(100% - 100px); /* Take most of the screen height */
        bottom: 80px; /* Position above mic button */
    }
}


/* === ACCESSIBILITY IMPROVEMENTS === */

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .avatar-preview,
    .tap-indicator,
    .hand-icon,
    .loading-spinner,
    .spinner {
        animation: none;
    }

    .corner-controls,
    .bottom-controls,
    .chat-container,
    .avatar-container,
    #transparentCanvas /* reduce motion for canvas fade-in */ {
        transition-duration: 0.01s !important; /* Faster transitions, almost instant */
        transition-delay: 0s !important;
    }


        #microphone:hover,
        .corner-controls button:hover,
        .tap-indicator:hover {
            transform: none; /* Disable hover transforms */
        }

    .message-wrapper {
        transition: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    #tap-overlay,
    #avatar-loading {
        background: #000000; /* Solid black background */
    }

    .tap-indicator {
        border-color: #ffffff; /* White border for high contrast */
        background: rgba(255, 255, 255, 0.2);
    }

    .loading-spinner,
    .spinner {
        border-top-color: #ffffff; /* Ensure spinner is visible */
    }

    .corner-controls button {
        background: #000000; /* Black background for buttons */
        border: 2px solid #ffffff; /* White border for buttons */
    }

    .message {
        border: 1px solid rgba(255, 255, 255, 0.5); /* Clearer message borders */
        background-color: #000; /* Ensure messages have solid background */
    }

    .user-message {
        background-color: #000050; /* Dark blue example */
        color: white;
    }

    .ai-message {
        background-color: #101010; /* Dark grey example */
        color: white;
    }


    .message-wrapper:not(:last-child) {
        opacity: 0.85; /* Less fade in high contrast mode */
        filter: none;
    }
}

/* Focus styles for keyboard navigation */
button:focus,
.language-option:focus {
    outline: 3px solid #FFD700 !important; /* Clearer, thicker focus indicator (gold example) */
    outline-offset: 2px;
    box-shadow: 0 0 0 2px #080821; /* Inner shadow to make outline stand out more */
}


/* Print styles */
@media print {
    body {
        background: white;
        color: black;
        padding: 0 !important; /* Reset body padding for print */
    }

    .corner-controls,
    .bottom-controls,
    #tap-overlay,
    #avatar-loading,
    .avatar-container,
    .footer,
    .language-overlay,
    #loading-indicator,
    .error-overlay /* Hide all interactive / non-content elements */ {
        display: none !important;
    }

    .chat-container {
        position: static !important;
        max-height: none !important;
        overflow: visible !important;
        bottom: auto !important;
        left: auto !important;
        right: auto !important;
        transform: none !important;
        opacity: 1 !important;
    }

    .message-wrapper {
        opacity: 1 !important; /* Ensure messages are fully visible */
        filter: none !important;
        max-width: 100% !important; /* Allow messages to take full width */
    }

    .message {
        box-shadow: none !important;
        backdrop-filter: none !important;
    }

    .user-message {
        background-color: #e1f5fe !important; /* Light blue for user */
        color: black !important;
    }

    .ai-message {
        background-color: #f0f0f0 !important; /* Light grey for AI */
        color: black !important;
    }
}

/* === DARK MODE SUPPORT === */
@media (prefers-color-scheme: dark) {
    /* Already dark by default, but we can add explicit dark variations here if needed */
    /* For example, if we had a light mode and wanted to ensure dark mode specific overrides */
    .error-content { /* Ensure error content is styled for dark mode if it wasn't already */
        background: linear-gradient(135deg, #1a1b2e 0%, #16213e 100%);
    }
}

/* === PERFORMANCE OPTIMIZATIONS === */

/* GPU acceleration for smoother animations */
.avatar-preview,
.tap-indicator,
.corner-controls,
.bottom-controls,
.chat-container,
#microphone,
.message-wrapper,
#transparentCanvas /* Add canvas here */ {
    will-change: transform, opacity; /* Specify properties that will change */
    transform: translateZ(0); /* Promote to own layer, use sparingly */
}

/* Optimize repaints for specific elements that animate frequently */
.audio-wave {
    will-change: width, height, opacity;
}

/* === ENHANCED SCROLLING BEHAVIOR === */
.chat-container {
    /* Smooth scrolling for better UX */
    scroll-behavior: smooth;
    /* Improved touch scrolling on mobile */
    -webkit-overflow-scrolling: touch;
}

/* === SPECIAL EFFECTS FOR ACTIVE STATES === */
/* Example: Slight pop effect for the latest message */
.message-wrapper:last-child .message {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); /* Enhanced shadow for latest message */
    /* transform: scale(1.01); Consider performance, can cause reflow */
}

/* Chat History Button and Panel */
.chat-history-button {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 64px; /* Changed from 52px to match microphone */
    height: 64px; /* Changed from 52px to match microphone */
    border-radius: 50%;
    background-color: rgba(25, 25, 45, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 1000;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
    opacity: 0;
    pointer-events: none;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.chat-history-button.active {
    opacity: 1;
    pointer-events: all;
}

.chat-history-button:hover {
    transform: scale(1.05);
    background-color: rgba(35, 35, 65, 0.8);
}

.chat-history-button:active {
    transform: scale(0.95);
}

.chat-history-button i {
    font-size: 22px;
    color: white;
}

.chat-history-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(8, 8, 33, 0.98); /* Match the app background */
    z-index: 1001; /* Higher than any other UI element */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s ease;
}

.chat-history-panel.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.chat-history-header {
    padding: 22px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background-color: rgba(15, 15, 35, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.chat-history-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-history-header h3 {
    font-size: 18px;
    font-weight: 500;
    margin: 0;
    color: #fff;
    letter-spacing: 0.5px;
}

.chat-history-close,
.chat-history-mute {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    font-size: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.chat-history-close:hover,
.chat-history-mute:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.chat-history-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px 36px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    background-color: rgba(8, 8, 33, 0.98);
    /* Add these properties to improve scroll performance */
    transform: translateZ(0);
    will-change: transform;
    perspective: 1000px;
}

.chat-history-empty {
    text-align: center;
    color: rgba(255, 255, 255, 0.5);
    padding: 60px 0;
    font-size: 15px;
}

.chat-history-initial {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px 0;
}

.welcome-text {
    color: rgba(255, 255, 255, 0.9);
    font-size: 16px;
    line-height: 1.5;
    text-align: left;
    padding: 0 5px;
}

.chat-history-message {
    display: flex;
    flex-direction: column;
    padding: 14px;
    border-radius: 18px;
    max-width: 85%; /* Slightly wider on mobile */
    word-break: break-word;
    margin-bottom: 4px; /* Add space between messages */
}

.chat-history-message.user {
    align-self: flex-end;
    background-color: rgba(40, 120, 200, 0.3);
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    text-align: right;
}

.chat-history-message.assistant {
    align-self: flex-start;
    background-color: rgba(40, 40, 70, 0.3);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    text-align: left;
}

.chat-history-message .content {
    font-size: 15px;
    line-height: 1.5;
    color: #fff;
    font-weight: 400;
    word-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    white-space: pre-wrap; /* Preserve white space and wrap text */
}

/* Ensure proper text formatting for markdown content */
.chat-history-message .content p {
    margin: 0 0 10px 0; /* Match main chat AI message spacing */
    line-height: 1.5;
}

.chat-history-message .content p:last-child {
    margin-bottom: 0; /* Remove margin from last paragraph, matching main chat */
}

/* Remove bottom margin from chat history paragraphs when followed by buttons */
.chat-history-message .content p + .button-scroll-container ~ * p,
.chat-history-message .content p:last-of-type {
    margin-bottom: 0 !important; /* Force no bottom margin in chat history */
}

.chat-history-message .content strong {
    font-weight: 600;
    color: #fff;
}

.chat-history-message .content em {
    font-style: italic;
    color: rgba(255, 255, 255, 0.9);
}

/* Format lists within chat history messages - same as main chat */
.chat-history-message .content ul, .chat-history-message .content ol {
    padding-left: 20px; /* Add proper indentation */
    margin: 8px 0; /* Add spacing above and below lists */
}

.chat-history-message .content li {
    margin-bottom: 5px; /* Add spacing between list items */
}

.chat-history-message .timestamp {
    font-size: 10px;
    margin-top: 6px;
    color: rgba(255, 255, 255, 0.5);
    align-self: flex-end;
}

.chat-input-container {
    display: flex;
    padding: 18px 20px 22px;
    background-color: rgba(15, 15, 35, 0.97);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    position: relative;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
}

.chat-input-field {
    flex: 1;
    padding: 16px 48px 16px 20px; /* Added space on the right for icon */
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background-color: rgba(30, 30, 60, 0.4);
    color: white;
    font-size: 15px;
    outline: none;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    -webkit-appearance: none; /* Remove default styling on iOS */
    appearance: none;
}

.chat-input-field:focus {
    border-color: rgba(255, 255, 255, 0.3);
    background-color: rgba(40, 40, 80, 0.5);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.chat-send-button {
    position: absolute;
    right: 30px; /* Better positioning */
    bottom: 30px; /* Center vertically */
    background: none;
    border: none;
    width: 40px; /* Slightly larger touch target */
    height: 40px; /* Slightly larger touch target */
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0; /* Remove any padding */
}

.chat-send-button:hover {
    transform: scale(1.1);
}

.chat-send-button i {
    color: white;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0; /* Remove any default margins */
}


/* === GENERAL CARD STYLES === */
.info-card {
    background: linear-gradient(135deg, #1e1e3f 0%, #2a2a5a 100%);
    border-radius: 12px;
    padding: 15px;
    margin: 10px 0;
    border: 1px solid #3a3a6a;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.card-header {
    font-size: 16px;
    font-weight: bold;
    color: #ffd700;
    margin-bottom: 10px;
    border-bottom: 1px solid #3a3a6a;
    padding-bottom: 8px;
}

.card-content {
    color: #fff;
    line-height: 1.6;
}

.card-content ul {
    margin: 10px 0;
    padding-left: 20px;
}

.card-content li {
    margin: 5px 0;
}

/* Language selection in tap overlay */
.language-selection {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 30px;
    width: 100%;
    max-width: 400px;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

.language-label {
    color: #ffffff;
    font-size: 18px;
    margin-bottom: 15px;
    text-align: center;
    font-weight: 500;
}

.language-dropdown {
    width: 200px;
    padding: 12px 15px;
    margin-bottom: 20px;
    background-color: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    font-size: 16px;
    outline: none;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23FFFFFF%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 15px top 50%;
    background-size: 12px auto;
    cursor: pointer;
}

.language-dropdown:hover {
    background-color: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

.language-dropdown:focus {
    background-color: rgba(255, 255, 255, 0.25);
    border-color: #ffffff;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.language-dropdown option {
    background-color: #1a1a3e;
    color: white;
}

.continue-button {
    width: 100%;
    padding: 14px 20px;
    background: linear-gradient(45deg, #C29A54, #DAB87D);
    color: #080821;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.5px;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    outline: none;
    text-transform: uppercase;
}

.continue-button:hover {
    background: linear-gradient(45deg, #DAB87D, #E6C897);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

.continue-button:active {
    transform: translateY(1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Ultra-wide screen adjustments to prevent background from being too small */
@media (min-width: 1920px) and (min-aspect-ratio: 16/9) {
    .avatar-container {
        background-size: cover;
    }
    
    #remoteVideo {
        background-size: cover;
    }
}

/* For very tall screens, ensure background covers properly */
@media (min-height: 1080px) and (max-aspect-ratio: 4/3) {
    .avatar-container {
        background-size: cover;
    }
    
    #remoteVideo {
        background-size: cover;
    }
}


/* Use mobile background for tablets and phones (non-desktop) */
@media (max-width: 1024px) {
    .avatar-container {
        background-image: url('/image/avatar_gulfair_background_mobile.png') !important;
    }

    #remoteVideo {
        background-image: url('/image/avatar_gulfair_background_mobile.png') !important;
    }

    #avatar-loading {
        background-image: url('/image/avatar_gulfair_background_mobile.png') !important;
    }

    #tap-overlay {
        background-image: url('/image/avatar_gulfair_background_mobile.png') !important;
    }
}

/* Use mobile background for vertical/portrait screens */
@media (orientation: portrait) {
    .avatar-container {
        background-image: url('/image/avatar_gulfair_background_mobile.png') !important;
    }

    #remoteVideo {
        background-image: url('/image/avatar_gulfair_background_mobile.png') !important;
    }

    #avatar-loading {
        background-image: url('/image/avatar_gulfair_background_mobile.png') !important;
    }

    #tap-overlay {
        background-image: url('/image/avatar_gulfair_background_mobile.png') !important;
    }
}