/**
 * AI Assistant Styles - Travelport Cloud
 * Premium Glassmorphism UI with Mobile-First responsiveness
 */

#aiAssistantPanel {
    --ai-primary: #4ecca3;
    --ai-primary-dark: #45b792;
    --ai-bg: rgba(13, 17, 23, 0.95);
    --ai-header: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    --ai-user-bubble: rgba(78, 204, 163, 0.15);
    --ai-assistant-bubble: rgba(48, 54, 61, 0.4);
    --ai-border: rgba(255, 255, 255, 0.1);
    --ai-text: #e6edf3;
    --ai-input-text: #000000;
    --ai-footer-bg: rgba(0, 0, 0, 0.2);
    --ai-bubble-shadow: rgba(0,0,0,0.1);
}

.theme-light #aiAssistantPanel, #aiAssistantPanel.theme-light {
    --ai-primary: #0284c7;
    --ai-primary-dark: #0369a1;
    --ai-bg: rgba(255, 255, 255, 0.98);
    --ai-header: linear-gradient(135deg, #ffffff 0%, #f1f5f9 100%);
    --ai-user-bubble: rgba(2, 132, 199, 0.1);
    --ai-assistant-bubble: #f1f5f9;
    --ai-border: rgba(0, 0, 0, 0.08);
    --ai-text: #1e293b;
    --ai-input-text: #1e293b;
    --ai-footer-bg: #ffffff;
    --ai-bubble-shadow: rgba(0,0,0,0.03);
}

#aiAssistantPanel {
    position: fixed;
    right: 30px;
    top: 80px;
    width: 420px;
    height: 600px;
    background: var(--ai-bg);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid var(--ai-border);
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.03);
    display: none; /* Initially hidden, shown via js */
    flex-direction: column;
    z-index: 2000;
    overflow: hidden;
    color: var(--ai-text);
    font-family: 'Outfit', 'Inter', -apple-system, sans-serif;
    transform: translateY(20px);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s ease, height 0.3s ease, width 0.3s ease;
}

#aiAssistantPanel.minimized {
    height: 52px !important;
    width: 200px !important;
}

#aiAssistantPanel.minimized .panel-content,
#aiAssistantPanel.minimized .ai-assistant-footer {
    display: none;
}

/* Header Styling */
#aiAssistantHeader {
    padding: 14px 20px;
    background: var(--ai-header);
    border-bottom: 1px solid var(--ai-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: move;
    user-select: none;
}

.panel-title {
    font-weight: 700;
    font-size: 13px;
    color: var(--ai-primary);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-sparkle-icon {
    color: var(--ai-primary);
    filter: drop-shadow(0 0 5px var(--ai-primary));
}

.panel-controls {
    display: flex;
    gap: 10px;
}

.ctrl-btn {
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid rgba(0, 0, 0, 0.05);
    color: #64748b;
    font-size: 16px;
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.ctrl-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    color: #1e293b;
    transform: translateY(-1px);
}

#aiCloseBtn:hover {
    background: rgba(248, 81, 73, 0.2);
    color: #f85149;
}

/* Content Area */
.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
    scrollbar-gutter: stable;
}

/* Message Bubbles */
.ai-message {
    padding: 12px 18px;
    border-radius: 18px;
    max-width: 85%;
    font-size: 14.5px;
    line-height: 1.6;
    position: relative;
    animation: slideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.ai-message.assistant {
    background: var(--ai-assistant-bubble);
    border: 1px solid var(--ai-border);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 10px var(--ai-bubble-shadow);
}

.ai-message.assistant.greeting {
    background: linear-gradient(135deg, rgba(78, 204, 163, 0.05) 0%, var(--ai-assistant-bubble) 100%);
    border-left: 3px solid var(--ai-primary);
}

.theme-light #aiAssistantPanel .ai-message.assistant.greeting,
#aiAssistantPanel.theme-light .ai-message.assistant.greeting {
    background: linear-gradient(135deg, rgba(2, 132, 199, 0.05) 0%, #f1f5f9 100%);
}

.ai-message.user {
    background: var(--ai-user-bubble);
    border: 1px solid rgba(78, 204, 163, 0.15);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    color: var(--ai-text);
    box-shadow: 0 2px 10px var(--ai-bubble-shadow);
}

.theme-light #aiAssistantPanel .ai-message.user,
#aiAssistantPanel.theme-light .ai-message.user {
    border-color: rgba(2, 132, 199, 0.15);
}

/* Markdown Tags */
.ai-message.assistant code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 6px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.9em;
    color: var(--ai-primary);
    white-space: pre-wrap;
    word-break: break-all;
    overflow-wrap: break-word;
    max-width: 100%;
    display: inline-block;
    vertical-align: middle;
}

.theme-light #aiAssistantPanel .ai-message.assistant code,
#aiAssistantPanel.theme-light .ai-message.assistant code {
    color: #0369a1;
}

.ai-message.assistant pre {
    background: #0f172a;
    padding: 16px;
    border-radius: 12px;
    white-space: pre-wrap;
    word-break: break-all;
    overflow-wrap: break-word;
    margin: 12px 0;
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
    max-width: 100%;
    box-sizing: border-box;
}

.ai-message.assistant h3 {
    margin: 16px 0 8px 0;
    color: var(--ai-primary);
    font-size: 1.1em;
}

/* Footer & Input */
.ai-assistant-footer {
    padding: 20px;
    background: var(--ai-footer-bg);
    border-top: 1px solid var(--ai-border);
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.input-wrapper {
    flex: 1;
    position: relative;
    background: #f8fafc;
    border: 1px solid var(--ai-border);
    border-radius: 24px;
    transition: all 0.2;
}

.input-wrapper:focus-within {
    border-color: var(--ai-primary);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.1);
}

.ai-input {
    width: 100%;
    background: transparent;
    border: none;
    padding: 12px 20px;
    color: var(--ai-input-text);
    font-family: inherit;
    font-size: 14px;
    outline: none;
}

.ai-send-btn {
    background: var(--ai-primary);
    color: #ffffff;
    border: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 4px 15px rgba(2, 132, 199, 0.2);
}

.ai-send-btn:hover {
    transform: scale(1.1) rotate(-10deg);
    background: var(--ai-primary-dark);
}

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

.ai-mic-btn {
    background: transparent;
    color: var(--ai-text);
    border: 1px solid var(--ai-border);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    opacity: 0.7;
    flex-shrink: 0;
}

.ai-mic-btn:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.05);
    border-color: var(--ai-primary);
    color: var(--ai-primary);
    transform: scale(1.05);
}

.ai-mic-btn.listening {
    background: rgba(248, 81, 73, 0.1);
    border-color: #f85149;
    color: #f85149;
    opacity: 1;
    animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(248, 81, 73, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(248, 81, 73, 0); }
    100% { box-shadow: 0 0 0 0 rgba(248, 81, 73, 0); }
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 15px 20px;
    background: var(--ai-assistant-bubble);
    border-radius: 18px;
    align-self: flex-start;
    border: 1px solid var(--ai-border);
    width: fit-content;
    margin-bottom: 5px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--ai-primary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

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

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1.1); opacity: 1; }
}

/* Scrollbar styling */
.panel-content::-webkit-scrollbar {
    width: 5px;
}

.panel-content::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.08);
    border-radius: 10px;
}

.panel-content::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.15);
}

/* MOBILE ADAPTATION */
@media screen and (max-width: 600px) {
    #aiAssistantPanel {
        right: 0;
        top: 0;
        width: 100% !important;
        height: 100% !important;
        z-index: 30000 !important;
        border-radius: 0;
        border: none;
        pointer-events: auto !important;
        touch-action: manipulation;
        transform: translateY(100%);
        transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    }

    #aiAssistantPanel.minimized {
        height: 100% !important;
        width: 100% !important;
        transform: translateY(calc(100% - 60px));
    }

    #aiAssistantPanel.minimized .panel-content,
    #aiAssistantPanel.minimized .ai-assistant-footer {
        display: none;
    }

    #aiAssistantHeader {
        padding: 18px 24px;
        height: 60px;
    }

    .panel-title {
        font-size: 15px;
    }

    .ai-assistant-footer {
        padding: 15px 15px 35px 15px; /* Added bottom padding for safe areas on mobile */
        background: var(--ai-bg);
    }
    
    .ai-message {
        max-width: 90%;
        font-size: 15px;
    }
}

/* Resize Handles */
.resize-handle {
    position: absolute;
    z-index: 1001;
    /* background: rgba(0,0,0,0.1); */ /* Uncomment for debugging */
}

.resize-handle-n { top: -2px; left: 0; width: 100%; height: 6px; cursor: n-resize; }
.resize-handle-s { bottom: -2px; left: 0; width: 100%; height: 6px; cursor: s-resize; }
.resize-handle-e { top: 0; right: -2px; width: 6px; height: 100%; cursor: e-resize; }
.resize-handle-w { top: 0; left: -2px; width: 6px; height: 100%; cursor: w-resize; }

.resize-handle-ne { top: -4px; right: -4px; width: 12px; height: 12px; cursor: ne-resize; }
.resize-handle-nw { top: -4px; left: -4px; width: 12px; height: 12px; cursor: nw-resize; }
.resize-handle-se { bottom: -4px; right: -4px; width: 12px; height: 12px; cursor: se-resize; }
.resize-handle-sw { bottom: -4px; left: -4px; width: 12px; height: 12px; cursor: sw-resize; }

/* Visual diagonal handle for SE corner */
.resize-handle-se::after {
    content: '';
    position: absolute;
    right: 6px;
    bottom: 6px;
    width: 6px;
    height: 6px;
    border-right: 2px solid var(--ai-primary);
    border-bottom: 2px solid var(--ai-primary);
    opacity: 0.5;
}
