/* Chat Widget Styles */
:root {
	/* Inherit host design tokens when available, with safe fallbacks */
	--primary-color: var(--primary-color-host, #007bff);
	--secondary-color: var(--primary-color-host, #28a745);
	--bot-color: var(--text-color-host, #6c757d);
	--background-color: var(--card-bg-host, #ffffff);
	--text-color: var(--heading-color-host, #333333);
	--border-color: var(--border-color-host, #dee2e6);
	--shadow-color: rgba(0, 0, 0, 0.1);
	--widget-position: bottom-right;
	
	/* Dynamic gradient colors based on user settings */
	--primary-gradient: linear-gradient(135deg, var(--primary-color), var(--primary-color));
	--secondary-gradient: linear-gradient(135deg, var(--secondary-color), var(--secondary-color));
	--bot-gradient: linear-gradient(135deg, var(--bot-color), var(--bot-color));
	--background-gradient: linear-gradient(135deg, var(--background-color), var(--background-color));
	--glass-bg: rgba(255, 255, 255, 0.95);
	--glass-border: rgba(255, 255, 255, 0.2);
}

.chat-widget {
	position: fixed;
	z-index: 9999;
	font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
	direction: rtl;
}

/* Widget Position Classes */
.chat-widget.bottom-right {
    bottom: 20px;
    right: 20px;
}

.chat-widget.bottom-left {
    bottom: 20px;
    left: 20px;
}

.chat-widget.top-right {
    top: 20px;
    right: 20px;
}

.chat-widget.top-left {
    top: 20px;
    left: 20px;
}

/* Response Time Badge */
.response-badge {
    position: absolute;
    white-space: nowrap;
    opacity: 1;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
}

.chat-widget.bottom-right .response-badge {
    bottom: 50%;
    right: 80px;
    transform: translateY(50%);
}

.chat-widget.bottom-left .response-badge {
    bottom: 50%;
    left: 80px;
    transform: translateY(50%);
}

.chat-widget.top-right .response-badge {
    top: 50%;
    right: 80px;
    transform: translateY(-50%);
}

.chat-widget.top-left .response-badge {
    top: 50%;
    left: 80px;
    transform: translateY(-50%);
}

.badge-text {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    color: var(--text-color);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(0, 0, 0, 0.05);
    display: inline-block;
}

.chat-widget:hover .response-badge {
    opacity: 1;
}

/* Chat Button */
.chat-button {
    width: 64px;
    height: 64px;
    background: var(--primary-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    color: white;
    position: relative;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.chat-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.6s ease;
}

.chat-button:hover {
    transform: scale(1.15) rotate(5deg);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.2);
}

.chat-button:hover::before {
    left: 100%;
}

.chat-button:active {
    transform: scale(1.05);
}

/* Chat Window */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 520px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    animation: float 6s ease-in-out infinite;
}

.chat-window.show {
    display: flex;
    animation: slideUpBounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-5px); }
}

@keyframes slideUpBounce {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.9);
    }
    50% {
        transform: translateY(-10px) scale(1.02);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Position adjustments for different widget positions */
.chat-widget.bottom-left .chat-window {
    right: auto;
    left: 0;
}

.chat-widget.top-right .chat-window {
    bottom: auto;
    top: 80px;
}

.chat-widget.top-left .chat-window {
    bottom: auto;
    top: 80px;
    right: auto;
    left: 0;
}

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

/* Chat Header */
.chat-header {
    background: var(--primary-gradient);
    color: white;
    padding: 20px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.chat-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.chat-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    position: relative;
    z-index: 1;
}

.close-button {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 1;
    backdrop-filter: blur(10px);
}

.close-button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1) rotate(90deg);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* Header Controls */
.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    z-index: 1;
}

/* Language Switcher */
.language-switcher {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 15px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    backdrop-filter: blur(10px);
    min-width: 40px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.language-switcher:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.language-switcher:active {
    transform: scale(0.95);
}

.lang-text {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(248, 249, 250, 0.3));
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-color));
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: content-box;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-color));
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    color: var(--text-color);
    font-style: italic;
    padding: 15px 20px;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.02));
    border-radius: 15px;
    border-right: 4px solid var(--primary-color);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    animation: fadeInUp 0.6s ease-out;
}

/* Message Styles */
.message {
    max-width: 85%;
    padding: 16px 20px;
    border-radius: 20px;
    word-wrap: break-word;
    animation: messageSlideBounce 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    position: relative;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

@keyframes messageSlideBounce {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.9);
    }
    50% {
        transform: translateY(-5px) scale(1.02);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.user {
    background: var(--secondary-gradient);
    color: white;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.message.bot {
    background: var(--bot-gradient);
    color: white;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.message.system {
    background: #e9ecef;
    color: var(--text-color);
    align-self: center;
    text-align: center;
    font-size: 14px;
    border-radius: 8px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 16px 20px;
    background: var(--bot-gradient);
    color: white;
    border-radius: 20px;
    border-bottom-left-radius: 6px;
    align-self: flex-start;
    max-width: 90px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(10px);
}

.typing-dot {
    width: 10px;
    height: 10px;
    background: white;
    border-radius: 50%;
    animation: typingBounce 1.6s infinite ease-in-out;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

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

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

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0) scale(1);
        opacity: 0.6;
    }
    30% {
        transform: translateY(-12px) scale(1.2);
        opacity: 1;
    }
}

/* Chat Input */
.chat-input-container {
    padding: 20px 25px;
    background: linear-gradient(135deg, rgba(248, 249, 250, 0.8), rgba(255, 255, 255, 0.9));
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--glass-border);
    display: flex;
    gap: 15px;
    align-items: center;
}

#message-input {
    flex: 1;
    padding: 16px 20px;
    border: 2px solid var(--border-color);
    border-radius: 25px;
    outline: none;
    font-size: 14px;
    direction: rtl;
    text-align: right;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(5px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

#message-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.1), 0 4px 20px rgba(0, 0, 0, 0.05);
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.95);
}

#message-input:hover {
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

.send-button {
    width: 48px;
    height: 48px;
    background: var(--primary-gradient);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    position: relative;
    overflow: hidden;
}

.send-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s ease;
}

.send-button:hover {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-color));
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

.send-button:hover::before {
    left: 100%;
}

.send-button:active {
    transform: scale(0.95);
}

.send-button:disabled {
    background: linear-gradient(135deg, #6c757d, #495057);
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 15px;
        right: 15px;
        left: auto;
        top: auto;
    }
    
    .chat-widget.bottom-left {
        bottom: 15px;
        left: 15px;
        right: auto;
    }
    
    .chat-widget.top-right {
        top: 15px;
        right: 15px;
        bottom: auto;
    }
    
    .chat-widget.top-left {
        top: 15px;
        left: 15px;
        right: auto;
        bottom: auto;
    }
    
    .chat-button {
        width: 56px;
        height: 56px;
    }
    
    /* Completely override chat-window for mobile */
    .chat-window {
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important; /* Dynamic viewport height for mobile */
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        min-width: 100vw !important;
        min-height: 100vh !important;
        min-height: 100dvh !important;
        z-index: 10000 !important; /* Ensure it's above everything */
        overflow: hidden !important; /* Prevent any overflow */
        box-sizing: border-box !important;
        /* Reset all default animations */
        animation: none !important;
    }
    
    /* Ensure chat-window is positioned relative to viewport, not widget */
    .chat-widget .chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
    }
    
    /* Override show animation specifically for mobile */
    .chat-window.show {
        animation: slideUpMobile 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards !important;
        display: flex !important;
    }
    
    @keyframes slideUpMobile {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    /* Override all position classes for mobile - MUST override default positioning */
    .chat-widget.bottom-left .chat-window,
    .chat-widget.top-left .chat-window,
    .chat-widget.top-right .chat-window,
    .chat-widget.bottom-right .chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        margin: 0 !important;
        padding: 0 !important;
        /* Reset any inherited positioning from default styles */
        max-width: 100vw !important;
        min-width: 100vw !important;
        min-height: 100vh !important;
        min-height: 100dvh !important;
        animation: none !important;
    }
    
    /* Override specific position adjustments that might interfere */
    .chat-widget.bottom-left .chat-window {
        right: 0 !important;
        left: 0 !important;
    }
    
    .chat-widget.top-left .chat-window {
        top: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
    }
    
    .chat-widget.top-right .chat-window {
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
    }
    
    .chat-widget.bottom-right .chat-window {
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
    }
    
    .chat-header {
        padding-top: max(18px, env(safe-area-inset-top)) !important;
        padding-bottom: 18px !important;
        padding-left: max(20px, env(safe-area-inset-left)) !important;
        padding-right: max(20px, env(safe-area-inset-right)) !important;
        min-height: 60px;
    }
    
    .chat-header h3 {
        font-size: 16px;
    }
    
    .chat-messages {
        padding: 20px 15px;
    }
    
    .message {
        max-width: 90%;
        padding: 14px 18px;
        font-size: 14px;
    }
    
    .chat-input-container {
        padding-top: 15px !important;
        padding-bottom: max(15px, env(safe-area-inset-bottom)) !important;
        padding-left: max(20px, env(safe-area-inset-left)) !important;
        padding-right: max(20px, env(safe-area-inset-right)) !important;
    }
    
    #message-input {
        padding: 14px 18px;
        font-size: 14px;
    }
    
    .send-button {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
    }
    
    .close-button,
    .language-switcher {
        touch-action: manipulation; /* Better touch handling */
    }
    
    /* Hide response badge on mobile */
    .response-badge {
        display: none !important;
    }
}

/* Prevent body scroll when chat is open on mobile */
@media (max-width: 768px) {
    body.chat-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }
}

/* RTL Support - Arabic */
[dir="rtl"] .message.user {
    border-bottom-right-radius: 6px;
    border-bottom-left-radius: 20px;
    align-self: flex-end;
    margin-left: auto;
    margin-right: 0;
}

[dir="rtl"] .message.bot {
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 20px;
    align-self: flex-start;
    margin-right: auto;
    margin-left: 0;
}

/* LTR Support - English */
[dir="ltr"] .message.user {
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 20px;
    align-self: flex-end;
    margin-right: auto;
    margin-left: 0;
}

[dir="ltr"] .message.bot {
    border-bottom-right-radius: 6px;
    border-bottom-left-radius: 20px;
    align-self: flex-start;
    margin-left: auto;
    margin-right: 0;
}

/* Language-specific message alignment */
[lang="ar"] .message {
    text-align: right;
}

[lang="en"] .message {
    text-align: left;
}

/* Language-specific input placeholder */
[lang="ar"] #message-input::placeholder {
    text-align: right;
}

[lang="en"] #message-input::placeholder {
    text-align: left;
}

/* Additional Modern Effects */
.chat-widget {
    filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.1));
}

.chat-window::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
    border-radius: 20px;
    pointer-events: none;
    z-index: 0;
}

.chat-header,
.chat-messages,
.chat-input-container {
    position: relative;
    z-index: 1;
}

/* Smooth transitions for all interactive elements */
* {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Enhanced focus states */
#message-input:focus,
.send-button:focus,
.close-button:focus {
    outline: none;
}

/* Loading animation for messages */
.message.loading {
    opacity: 0.7;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}
