/* AI Support Chat Widget */

/* Chat Toggle Button (Floating) */
.chat-toggle {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--gradient-primary);
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 30px var(--primary-glow);
    z-index: 1000;
    display: grid;
    place-items: center;
    transition: all 0.3s ease;
}

.chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 40px var(--primary-glow);
}

.chat-toggle svg {
    width: 28px;
    height: 28px;
    fill: white;
}

.chat-toggle.active {
    transform: scale(0.9);
}

/* Chat Widget Container */
.chat-widget {
    position: fixed;
    bottom: 6rem;
    right: 2rem;
    width: 420px;
    max-width: calc(100vw - 2rem);
    height: 600px;
    max-height: calc(100vh - 8rem);
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;

    /* Custom Resize Logic */
    min-width: 320px;
    min-height: 400px;
}

.chat-resize-handle {
    position: absolute;
    top: -15px;
    /* Pull it slightly outside/above */
    left: -15px;
    /* Pull it slightly outside/left */
    width: 44px;
    /* Large hit area */
    height: 44px;
    cursor: nw-resize;
    z-index: 2000;
    /* Ensure it's on top of everything */
    background-color: var(--primary);
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.chat-resize-handle:hover {
    transform: scale(1.1);
    background-color: var(--primary-dark);
}

/* Orthogonal Arrows Icon (90 degrees) */
.chat-resize-handle::after {
    content: '';
    width: 24px;
    height: 24px;
    /* Arrows pointing Up and Left */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20V4'/%3E%3Cpath d='M5 11l-7-7 7-7' transform='translate(12, 4)'/%3E%3Cpath d='M4 12h16'/%3E%3Cpath d='M11 5l-7 7 7 7' transform='translate(4, 12)'/%3E%3C/svg%3E");
    /* Wait, that SVG is messy. Let's send a cleaner one: Arrow Left + Arrow Up */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 12H4'/%3E%3Cpath d='M10 18l-6-6 6-6'/%3E%3Cpath d='M12 20V4'/%3E%3Cpath d='M6 10l6-6 6 6' transform='translate(6, 0)'/%3E%3C/svg%3E");
    /* Simpler: just Corner Bracket with Arrowheads */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M19 19V5H5'/%3E%3Cpath d='M8 8L5 5l3-3'/%3E%3Cpath d='M8 2l-3 3 3 3' visibility='hidden'/%3E%3Cpath d='M2 8l3-3 3 3' visibility='hidden'/%3E%3Cpath d='M16 8V5'/%3E%3Cpath d='M8 16H5'/%3E%3C/svg%3E");

    /* Best: Arrow Up and Arrow Left separate */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M19 12H5'/%3E%3Cpath d='M12 19V5'/%3E%3Cpath d='M19 5L5 19' opacity='0'/%3E%3Cpolyline points='12 9 12 5 8 5' opacity='0'/%3E%3Cpath d='M12 5l-4 4'/%3E%3Cpath d='M12 5l4 4'/%3E%3Cpath d='M5 12l4 4'/%3E%3Cpath d='M5 12l4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    display: block;
}

/* Remove old pseudo-element */
.chat-resize-handle::before {
    display: none;
}

.chat-widget.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Chat Header */
.chat-header {
    background: var(--gradient-primary);
    padding: 1rem 1.25rem;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.chat-header-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
}

.chat-header-icon {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    display: grid;
    place-items: center;
}

.chat-header-icon svg {
    width: 20px;
    height: 20px;
    fill: white;
}

.chat-header h3 {
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.chat-close {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background 0.2s ease;
    display: grid;
    place-items: center;
}

.chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-close svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Chat Header Controls (Language + Close) */
.chat-header-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-language-selector {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    padding: 0.4rem 0.75rem;
    color: white;
    font-family: inherit;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
}

.chat-language-selector:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.3);
}

.chat-language-selector:focus {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1);
}

/* Style the dropdown options */
.chat-language-selector option {
    background: var(--bg-dark);
    color: var(--text-main);
    padding: 0.5rem;
}

[data-theme="light"] .chat-language-selector option {
    background: var(--bg-light);
}

/* Chat Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem 0.5rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
}

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

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Chat Message */
.chat-message {
    display: flex;
    gap: 0.25rem;
    animation: messageSlide 0.3s ease;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


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

.message-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 80%;
    /* Constrain width here */
}

.chat-message.user .message-content {
    align-items: flex-end;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--gradient-primary);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.message-avatar svg {
    width: 20px;
    height: 20px;
    fill: white;
}

.chat-message.user .message-avatar {
    background: var(--accent);
}

.message-bubble {
    width: fit-content;
    max-width: 100%;
    /* Relative to wrapper */
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius-md);
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.2);
    color: var(--text-main);
    word-break: normal;
    overflow-wrap: break-word;
}

.chat-message.user .message-bubble {
    background: rgba(139, 92, 246, 0.15);
    border-color: rgba(139, 92, 246, 0.2);
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 0.25rem;
}

/* Typing Indicator */
.typing-indicator {
    display: none;
    /* Hide completely when not active to remove gap */
    gap: 0.75rem;
    padding: 0.5rem 1.5rem;
    /* Reduced padding */
    opacity: 0;
    pointer-events: none;
}

.typing-indicator.active {
    display: flex;
    /* Show only when active */
    animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

.typing-dots {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    padding: 0.875rem 1.125rem;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: var(--radius-md);
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    animation: typingBounce 1.4s infinite;
}

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

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

@keyframes typingBounce {

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

    30% {
        transform: translateY(-8px);
    }
}

/* Chat Input Area */
.chat-input-wrapper {
    padding: 0 1rem 1rem;
    /* Compact padding */
    background: transparent;
    /* Remove grey background */
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

#chat-input-resizer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 12px;
    /* Easy to grab */
    cursor: ns-resize;
    z-index: 10;
    transform: translateY(-50%);
    /* Center on the border */
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Visual Grip Handle (Drag Bar) */
#chat-input-resizer::after {
    content: '';
    width: 40px;
    height: 4px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    transition: background-color 0.2s;
}

#chat-input-resizer:hover::after {
    background-color: var(--primary);
    height: 5px;
}

.chat-input-container {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.chat-input-field {
    flex: 1;
    width: 100%;
    /* Force width */
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 0.875rem 0.75rem;
    /* Reduced horizontal padding */
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    resize: none;
    overflow-y: hidden;
    /* Prevent scrollbar causing wrap */
    max-height: 400px;
    min-height: 44px;
    transition: all 0.3s ease;
}

.chat-input-field:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chat-input-field::placeholder {
    color: var(--text-dim);
}

/* Voice/Send/Speaker Buttons */
.chat-speaker-btn,
.chat-voice-btn,
.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--gradient-primary);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.chat-speaker-btn:hover,
.chat-voice-btn:hover,
.chat-send-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 15px var(--primary-glow);
}

.chat-speaker-btn:active,
.chat-voice-btn:active,
.chat-send-btn:active {
    transform: scale(0.95);
}

.chat-speaker-btn svg,
.chat-voice-btn svg,
.chat-send-btn svg {
    width: 20px;
    height: 20px;
    fill: white;
}

.chat-voice-btn.recording {
    background: #ef4444;
    animation: recordingPulse 1.5s infinite;
}

@keyframes recordingPulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }

    50% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }
}

.chat-voice-btn.speaking {
    transform: scale(1.1);
    box-shadow: 0 0 0 15px rgba(239, 68, 68, 0.3);
    border: 2px solid white;
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 2rem 1.5rem;
    color: var(--text-muted);
}

.welcome-message svg {
    width: 48px;
    height: 48px;
    fill: var(--primary);
    margin: 0 auto 1rem;
}

.welcome-message h4 {
    color: var(--text-main);
    margin-bottom: 0.5rem;
    font-size: 1.25rem;
}

.welcome-message p {
    font-size: 0.95rem;
    margin-bottom: 0;
}

/* Status Indicator */
.chat-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.8);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    animation: statusPulse 2s infinite;
}

@keyframes statusPulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* Mobile Responsive */
@media (max-width: 500px) {
    .chat-widget {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .chat-header {
        border-radius: 0;
    }

    .chat-input-wrapper {
        border-radius: 0;
    }

    .chat-toggle {
        bottom: 1.5rem;
        right: 1.5rem;
    }
}

/* Light Theme Adjustments */
[data-theme="light"] .chat-messages {
    background: rgba(255, 255, 255, 0.5);
}

[data-theme="light"] .chat-input-field {
    background: rgba(255, 255, 255, 0.7);
    color: var(--text-main);
}

[data-theme="light"] .chat-input-field:focus {
    background: rgba(255, 255, 255, 0.9);
}

[data-theme="light"] .message-bubble {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.3);
    color: var(--text-main);
}

[data-theme="light"] .chat-message.user .message-bubble {
    background: rgba(139, 92, 246, 0.1);
    border-color: rgba(139, 92, 246, 0.3);
}