/* AI Chat Widget Styles - Luna Upgrade */

:root {
    --chat-width: 380px;
    --chat-height: 500px;
    --chat-bg: rgba(27, 38, 59, 0.85); /* Glassmorphism base */
    --chat-header-bg: rgba(65, 90, 119, 0.4);
    --chat-text-color: #E0E1DD;
    --user-msg-bg: #5A7A9A;
    --ai-msg-bg: rgba(44, 62, 80, 0.6);
    --input-bg: rgba(13, 27, 42, 0.6);
    --input-border: rgba(255, 255, 255, 0.2);
    --accent-color: #00b4d8; /* Luna Blue */
}

/* Floating Action Button (FAB) */
.ai-chat-fab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background-color: #415A77; /* Fallback */
    background: linear-gradient(135deg, #415A77, #1B263B);
    color: white;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.2);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    transition: transform 0.3s ease, background-color 0.3s ease;
    backdrop-filter: blur(4px);
}

.ai-chat-fab:hover {
    transform: scale(1.1);
    background-color: var(--user-msg-bg);
}

.ai-chat-fab .icon-close { display: none; }
.ai-chat-fab.open .icon-chat { display: none; }
.ai-chat-fab.open .icon-close { display: block; }

/* Chat Window Container - Glassmorphism */
.ai-chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: var(--chat-width);
    height: var(--chat-height);
    background: var(--chat-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10000;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), width 0.3s ease, height 0.3s ease, bottom 0.3s ease, right 0.3s ease, border-radius 0.3s ease;
}

.ai-chat-window.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Fullscreen Mode */
.ai-chat-window.fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    bottom: 0 !important;
    right: 0 !important;
    border-radius: 0;
    transform: none !important;
    border: none;
}

/* Header */
.ai-chat-header {
    background-color: var(--chat-header-bg);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ai-header-branding {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-avatar-icon {
    font-size: 20px;
    filter: drop-shadow(0 0 5px rgba(255,255,255,0.5));
}

.ai-chat-header h3 {
    margin: 0;
    font-size: 18px;
    color: white;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.ai-header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-ctrl-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    width: 32px;
    height: 32px;
}

.ai-ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    transform: translateY(-1px);
}

/* Messages Area */
.ai-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}
.ai-chat-messages::-webkit-scrollbar-thumb {
    background-color: rgba(255,255,255,0.2);
    border-radius: 3px;
}

.ai-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease;
    position: relative;
}

.ai-message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--user-msg-bg), #4a6fa5);
    color: white;
    border-bottom-right-radius: 2px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.ai-message.assistant {
    align-self: flex-start;
    background-color: var(--ai-msg-bg);
    color: var(--chat-text-color);
    border-bottom-left-radius: 2px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Markdown / Rich Text Styles */
.ai-message-content h1, 
.ai-message-content h2, 
.ai-message-content h3 {
    margin-top: 12px;
    margin-bottom: 8px;
    color: #fff;
    font-size: 1.1em;
    font-weight: 600;
}

.ai-message-content p {
    margin-bottom: 8px;
}
.ai-message-content p:last-child {
    margin-bottom: 0;
}

.ai-message-content ul, 
.ai-message-content ol {
    margin-left: 20px;
    margin-bottom: 10px;
    padding-left: 0;
}

.ai-message-content li {
    margin-bottom: 4px;
}

.ai-message-content strong {
    color: white;
    font-weight: 600;
}

.ai-message-content a {
    color: var(--accent-color);
    text-decoration: none;
    border-bottom: 1px dotted var(--accent-color);
}
.ai-message-content a:hover {
    border-bottom-style: solid;
}

.ai-message-content code {
    background: rgba(0,0,0,0.3);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    color: #e0e0e0;
}

.ai-message-content pre {
    background: rgba(0,0,0,0.3);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
    border: 1px solid rgba(255,255,255,0.05);
}

.ai-message-content pre code {
    background: transparent;
    padding: 0;
    color: #f0f0f0;
    font-size: 0.85em;
}

/* Input Area */
.ai-chat-input-area {
    padding: 15px 20px;
    background-color: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.ai-chat-input {
    flex: 1;
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 20px;
    padding: 12px 16px;
    color: white;
    font-family: inherit;
    font-size: 15px;
    outline: none;
    transition: all 0.2s;
    resize: none;
    min-height: 20px;
    max-height: 100px;
}

.ai-chat-input:focus {
    border-color: var(--accent-color);
    background-color: rgba(13, 27, 42, 0.8);
    box-shadow: 0 0 10px rgba(0, 180, 216, 0.1);
}

.ai-chat-send {
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 180, 216, 0.4);
    flex-shrink: 0;
}

.ai-chat-send:hover {
    transform: scale(1.05);
    background: #0096c7;
}

.ai-chat-send:disabled {
    background-color: #555;
    box-shadow: none;
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
}

/* Loading / Thinking Animation */
.ai-loading {
    align-self: flex-start;
    background-color: transparent; /* Cleaner look */
    padding: 10px 14px;
    border-radius: 12px;
    display: none;
}

.ai-loading.active {
    display: block;
}

.ai-thinking-dots, .typing-dots {
    display: flex;
    gap: 6px;
    padding: 5px;
    justify-content: center;
    align-items: center;
}

.ai-thinking-dots span, .typing-dots span {
    width: 8px;
    height: 8px;
    background-color: var(--accent-color);
    border-radius: 50%;
    animation: pulse 1.4s infinite ease-in-out both;
    opacity: 0.7;
}

.ai-thinking-dots span:nth-child(1), .typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.ai-thinking-dots span:nth-child(2), .typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes pulse {
    0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

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

/* Mobile Responsiveness */
@media (max-width: 480px) {
    .ai-chat-window:not(.fullscreen) {
        width: calc(100% - 40px);
        height: 60vh;
        bottom: 90px;
        right: 20px;
    }
}
/* New Loading Overlay */
.ai-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(27, 38, 59, 0.95);
    backdrop-filter: blur(10px);
    z-index: 20;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.ai-loading-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.ai-loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(0, 180, 216, 0.3);
    border-radius: 50%;
    border-top-color: var(--accent-color);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.ai-loading-text {
    color: white;
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 10px;
}

.ai-fun-fact {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9em;
    min-height: 40px;
    max-width: 80%;
    font-style: italic;
    animation: fadeIn 0.5s ease;
}

.ai-progress-bar {
    width: 200px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin-top: 20px;
    overflow: hidden;
}

.ai-progress-fill {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    transition: width 0.3s ease;
}