/* --- CHAT WIDGET SCOPED STYLES --- */

/* CSS VARIABLES (Purple & Gold Brand Theme) */
:root {
    --chat-primary-gradient: linear-gradient(120deg, #8B5CF6, #7C3AED);
    --chat-accent-glow: radial-gradient(circle at 50% 50%, rgba(139, 92, 246, 0.4), transparent 70%);
    --chat-glass-bg: rgba(26, 11, 46, 0.65);
    /* Dark purple glass */
    --chat-glass-border: rgba(167, 139, 250, 0.3);
    /* Light purple border */
    --chat-glass-highlight: rgba(255, 215, 0, 0.2);
    /* Gold highlight */
    --chat-glass-blur: blur(35px) saturate(180%);
    --chat-text-color: #E8E8F0;
    /* Light text for dark bg */
    --chat-text-secondary: #B8B8D0;
    --chat-user-msg-bg: linear-gradient(135deg, #8B5CF6 0%, #7C3AED 100%);
    /* Purple user messages */
    --chat-bot-msg-bg: rgba(44, 18, 80, 0.5);
    /* Dark purple bot messages */
    --chat-shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.3);
    --chat-shadow-lg: 0 25px 60px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(167, 139, 250, 0.2) inset;
    --chat-elegant-ease: cubic-bezier(0.32, 0.72, 0, 1);
}

/* Keyframe Animations */
@keyframes chat-springUp {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }

    60% {
        transform: translateY(-3px);
    }

    80% {
        transform: translateY(1px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes chat-bounceIn {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.96);
    }

    60% {
        transform: translateY(-2px) scale(1.01);
    }

    80% {
        transform: translateY(1px) scale(0.99);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes chat-typingDot {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.7;
    }

    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Typing Indicator */
.chat-typing-indicator {
    display: none;
    align-self: flex-start;
    padding: 12px 16px;
    background: var(--chat-bot-msg-bg);
    border: 0.5px solid rgba(255, 255, 255, 0.6);
    border-radius: 18px;
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.03), inset 0 1px 0 rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px) saturate(150%);
    gap: 6px;
    align-items: center;
    animation: chat-springUp 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.chat-typing-indicator.show {
    display: flex;
}

.chat-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #FFD700;
    /* Gold dot */
    animation: chat-typingDot 1.4s infinite ease-in-out;
}

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

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

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

/* Overlay */
#chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: transparent;
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: all 0.5s var(--chat-elegant-ease);
    pointer-events: none;
}

body.chat-is-open #chat-overlay {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Toggle Button */
#chat-toggle-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #8B5CF6 0%, #7C3AED 50%, #6D28D9 100%);
    color: white;
    box-shadow:
        0 8px 24px rgba(139, 92, 246, 0.4),
        0 4px 12px rgba(139, 92, 246, 0.3),
        0 2px 6px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        inset 0 -2px 0 rgba(0, 0, 0, 0.15);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 9998;
    will-change: transform;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

#chat-toggle-btn:hover {
    transform: scale(1.05);
    box-shadow:
        0 12px 32px rgba(139, 92, 246, 0.45),
        0 6px 16px rgba(139, 92, 246, 0.35),
        0 3px 8px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        inset 0 -2px 0 rgba(0, 0, 0, 0.15);
}

#chat-toggle-btn:active {
    transform: scale(0.95);
}

.chat-toggle-icon {
    position: absolute;
    transition: all 0.6s var(--chat-elegant-ease);
    width: 26px;
    height: 26px;
    fill: currentColor;
}

#chat-icon-chat {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

#chat-icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

body.chat-is-open #chat-icon-chat {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

body.chat-is-open #chat-icon-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Chat Container - Enhanced Apple Glass UI (visionOS Style) */
#chat-widget-container {
    position: fixed;
    bottom: 105px;
    /* More space from toggle button */
    right: 24px;
    width: 400px;
    /* Increased default height + flexible gap (120px top + 120px bottom = 240px safety) */
    height: min(680px, calc(100vh - 240px));
    max-height: calc(100vh - 240px);

    /* Glassmorphism background */
    background: rgba(26, 11, 46, 0.4);
    /* Lighter dark purple glass */
    backdrop-filter: blur(60px) saturate(200%);
    -webkit-backdrop-filter: blur(60px) saturate(200%);

    /* Light purple border */
    border: 1px solid rgba(167, 139, 250, 0.3);
    border-radius: 24px;

    /* Purple-tinted shadows */
    box-shadow:
        0 30px 90px rgba(0, 0, 0, 0.4),
        0 15px 40px rgba(139, 92, 246, 0.1),
        0 5px 15px rgba(0, 0, 0, 0.2),
        0 0 0 1px rgba(167, 139, 250, 0.2) inset;

    display: flex;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(30px) scale(0.96);

    /* Smooth spring animation */
    transition:
        opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.6s cubic-bezier(0.16, 1, 0.3, 1),
        visibility 0.5s;
}

body.chat-is-open #chat-widget-container {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* --- RESPONSIVE BREAKPOINTS --- */

/* Small Laptops & Large Tablets (1366x768) */
@media (max-height: 800px) {
    #chat-widget-container {
        /* Maintain proper gaps: 100px top + 120px bottom = 220px */
        height: min(560px, calc(100vh - 220px));
        max-height: calc(100vh - 220px);
        bottom: 105px;
    }
}

/* 720p Displays (1280x720) - User's Display */
@media (max-height: 720px) {
    #chat-widget-container {
        /* Optimal gaps: 90px top + 130px bottom = 220px total safe margin */
        height: calc(100vh - 220px);
        max-height: calc(100vh - 220px);
        bottom: 105px;
        /* Safe spacing from toggle button */
        /* Top margin: 90px (navbar 70px + 20px gap) */
    }
}

/* Very Small Heights (iPad Mini landscape, etc.) */
@media (max-height: 600px) {
    #chat-widget-container {
        /* Tight but safe: 80px top + 100px bottom = 180px */
        height: calc(100vh - 180px);
        max-height: calc(100vh - 180px);
        bottom: 90px;
    }
}

/* Header - Purple Gradient Glass */
#chat-widget-header {
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 0 0 auto;

    /* Enhanced gradient sweep */
    background: linear-gradient(135deg,
            rgba(255, 255, 255, 0.75) 0%,
            rgba(139, 218, 250, 0.35) 50%,
            /* Stronger light sweep */
            rgba(255, 255, 255, 0.75) 100%);
    backdrop-filter: blur(30px) saturate(200%);
    -webkit-backdrop-filter: blur(30px) saturate(200%);

    border-bottom: 1px solid rgba(167, 139, 250, 0.2);
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;

    /* Subtle shadow */
    box-shadow: 0 1px 3px rgba(139, 92, 246, 0.1);

    z-index: 2;
    flex-shrink: 0;
}

.chat-header-title {
    font-weight: 600;
    font-size: 16px;
    color: #0b1a2eff;
    /* Dark text */
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-status-dot {
    width: 8px;
    height: 8px;
    background-color: #8B5CF6;
    /* Purple status */
    border-radius: 50%;
    flex-shrink: 0;
    position: relative;
}

/* Chat Close Button */
.chat-close-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    min-width: 36px;
    /* Prevent shrinking */
    border: none;
    background: transparent;
    color: #2C1250;
    /* Dark purple */
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.2s ease;
    padding: 0;
    flex-shrink: 0;
}

.chat-close-button:hover {
    background: rgba(139, 92, 246, 0.1);
    color: #8B5CF6;
    transform: scale(1.05);
}

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

.chat-close-button svg {
    width: 24px;
    height: 24px;
    pointer-events: none;
}

/* Chat Body */
#chat-widget-body {
    flex: 1 1 auto;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    position: relative;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
    /* Dark purple gradient background */
    background: linear-gradient(180deg,
            rgba(26, 11, 46, 0.4) 0%,
            rgba(44, 18, 80, 0.3) 30%,
            rgba(15, 6, 32, 0.5) 70%,
            rgba(26, 11, 46, 0.4) 100%);
}

#chat-widget-body::-webkit-scrollbar {
    width: 6px;
}

#chat-widget-body::-webkit-scrollbar-track {
    background: transparent;
}

#chat-widget-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

/* Messages - Enhanced with Animations */
.chat-message {
    max-width: 85%;
    /* Constrain to 85% of chat width */
    padding: 12px 18px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    /* Break words at edges */
    word-break: break-word;
    /* Break long continuous strings */
    overflow-wrap: break-word;
    /* Modern standard */
    position: relative;
    border-radius: 20px;

    /* Prevent message bubbles from being interactive */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    pointer-events: none;
    /* Prevent any click/tap events */
    -webkit-touch-callout: none;
    /* Disable iOS callout */

    /* Slide-in animation */
    animation: messageSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);

    /* Smooth hover effect - only on desktop */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Only enable hover on desktop (hover-capable devices) */
@media (hover: hover) {
    .chat-message:hover {
        transform: translateY(-1px);
    }
}

/* Bot message - Frosted glass */
.chat-bot-message {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(20px) saturate(150%);
    -webkit-backdrop-filter: blur(20px) saturate(150%);
    color: #1a0b2e;
    /* Dark text for white bubble */
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow:
        0 4px 16px rgba(0, 0, 0, 0.08),
        0 2px 8px rgba(0, 0, 0, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

/* User message - Purple gradient */
.chat-user-message {
    align-self: flex-end;
    background: linear-gradient(135deg, #8B5CF6 0%, #7C3AED 100%);
    color: white;
    border: 1px solid rgba(139, 92, 246, 0.5);
    box-shadow:
        0 6px 20px rgba(139, 92, 246, 0.35),
        0 3px 10px rgba(139, 92, 246, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* Message slide-in animation */
@keyframes messageSlideIn {
    0% {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Footer - Purple Gradient Glass */
#chat-widget-footer {
    padding: 16px 20px;

    /* Enhanced gradient sweep */
    background: linear-gradient(135deg,
            rgba(255, 255, 255, 0.75) 0%,
            rgba(139, 218, 250, 0.35) 50%,
            /* Stronger light sweep */
            rgba(255, 255, 255, 0.75) 100%);
    backdrop-filter: blur(30px) saturate(200%);
    -webkit-backdrop-filter: blur(30px) saturate(200%);

    border-top: 1px solid rgba(167, 139, 250, 0.2);
    border-bottom-left-radius: 24px;
    border-bottom-right-radius: 24px;

    /* Subtle shadow */
    box-shadow: 0 -1px 3px rgba(139, 92, 246, 0.1);

    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
}

/* Input with focus glow */
#chat-widget-input {
    flex: 1;
    padding: 14px 20px;
    background: rgba(255, 255, 255, 0.6);
    /* White glass input */
    backdrop-filter: blur(10px);
    border: 2px solid rgba(167, 139, 250, 0.3);
    border-radius: 28px;
    font-size: 14px;
    color: #1a0b2e;
    /* Dark text */
    outline: none;
    transition: all 0.2s;
    resize: none;
    min-height: 46px;
    max-height: 120px;
    overflow-y: auto;
    font-family: inherit;
    line-height: 1.4;
}

#chat-widget-input::placeholder {
    color: #9ca3af;
}

/* Enhanced focus state with purple glow */
#chat-widget-input:focus {
    border-color: #8B5CF6;
    background: rgba(255, 255, 255, 0.9);
    box-shadow:
        0 0 0 3px rgba(139, 92, 246, 0.2),
        0 4px 12px rgba(139, 92, 246, 0.3),
        inset 0 1px 2px rgba(139, 92, 246, 0.1);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Gradient scrollbar */
#chat-widget-input::-webkit-scrollbar {
    width: 0px;
    /* Hide scrollbar completely */
    display: none;
    /* Extra assurance */
}

#chat-widget-input::-webkit-scrollbar-track {
    background: transparent;
}

#chat-widget-input::-webkit-scrollbar-thumb {
    background: transparent;
    /* Make thumb invisible too */
    border-radius: 4px;
}

#chat-widget-input::-webkit-scrollbar-thumb:hover {
    background: transparent;
    /* Keep transparent on hover */
}

/* Send button with purple gradient and pulse */
#chat-widget-send {
    background: linear-gradient(135deg, #8B5CF6 0%, #7C3AED 100%);
    /* Purple button */
    color: white;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    flex-shrink: 0;
    font-size: 20px;
    box-shadow:
        0 6px 20px rgba(139, 92, 246, 0.4),
        0 3px 10px rgba(139, 92, 246, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* Pulse animation on hover */
@keyframes sendPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

#chat-widget-send:hover {
    background: linear-gradient(135deg, #7C3AED 0%, #6D28D9 100%);
    animation: sendPulse 1s ease-in-out infinite;
    box-shadow:
        0 8px 24px rgba(139, 92, 246, 0.5),
        0 4px 12px rgba(139, 92, 246, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

#chat-widget-send:active {
    transform: scale(0.95);
}

#chat-widget-send svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Disabled state */
#chat-widget-send:disabled {
    background: linear-gradient(135deg, #5B21B6 0%, #4C1D95 100%);
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Remove hover animation when disabled */
#chat-widget-send:disabled:hover {
    animation: none;
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.3),
        0 2px 4px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}