@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ============================================
   AI Chat Assistant Widget - Premium Design
   ============================================ */

:root {
    --ai-chat-primary: #6C63FF;
    --ai-chat-primary-dark: #5A52D5;
    --ai-chat-primary-light: #8B83FF;
    --ai-chat-primary-glow: rgba(108, 99, 255, 0.35);
    --ai-chat-bg: #ffffff;
    --ai-chat-bg-messages: #F8F9FE;
    --ai-chat-text: #1e293b;
    --ai-chat-text-light: #94a3b8;
    --ai-chat-border: #e2e8f0;
    --ai-chat-input-bg: #f1f5f9;
    --ai-chat-bot-bubble: #ffffff;
    --ai-chat-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15), 0 12px 24px -8px rgba(0, 0, 0, 0.1);
    --ai-chat-fab-shadow: 0 8px 24px rgba(108, 99, 255, 0.4);
    --ai-chat-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ---- Floating Action Button ---- */
.ai-chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-chat-primary), var(--ai-chat-primary-dark));
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--ai-chat-fab-shadow);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
    animation: aiChatPulse 2.5s infinite;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

.ai-chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 32px rgba(108, 99, 255, 0.5);
}

.ai-chat-fab:active {
    transform: scale(0.95);
}

.ai-chat-fab.active {
    animation: none;
    background: linear-gradient(135deg, #ff6b6b, #ee5a5a);
    box-shadow: 0 8px 24px rgba(255, 107, 107, 0.4);
}

.ai-chat-fab.active:hover {
    box-shadow: 0 12px 32px rgba(255, 107, 107, 0.5);
}

.ai-chat-fab svg {
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.ai-chat-fab-icon-close {
    position: absolute;
}

.ai-chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    background: #ef4444;
    color: #fff;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--ai-chat-font);
    border: 2px solid #fff;
    animation: aiChatBadgePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ---- Chat Window ---- */
.ai-chat-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 400px;
    height: 580px;
    max-height: 80vh;
    background: var(--ai-chat-bg);
    border-radius: 20px;
    box-shadow: var(--ai-chat-shadow);
    z-index: 99998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    font-family: var(--ai-chat-font);
}

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

/* ---- Header ---- */
.ai-chat-header {
    background: linear-gradient(135deg, var(--ai-chat-primary-dark), var(--ai-chat-primary), var(--ai-chat-primary-light));
    color: #fff;
    padding: 18px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.ai-chat-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -30%;
    width: 200px;
    height: 200px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    pointer-events: none;
}

.ai-chat-header::after {
    content: '';
    position: absolute;
    bottom: -60%;
    left: -20%;
    width: 150px;
    height: 150px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
    pointer-events: none;
}

.ai-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1;
}

.ai-chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.ai-chat-avatar svg {
    color: #fff;
}

.ai-chat-header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ai-chat-assistant-name {
    font-weight: 700;
    font-size: 16px;
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.ai-chat-status {
    font-size: 12px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.ai-chat-status-dot {
    width: 8px;
    height: 8px;
    background: #4ADE80;
    border-radius: 50%;
    display: inline-block;
    animation: aiChatDotPulse 2s infinite;
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.5);
}

.ai-chat-header-actions {
    display: flex;
    gap: 4px;
    z-index: 1;
}

.ai-chat-clear-btn,
.ai-chat-close-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    padding: 0;
}

.ai-chat-clear-btn:hover,
.ai-chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ---- Messages Area ---- */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--ai-chat-bg-messages);
    scroll-behavior: smooth;
}

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

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

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.3);
    border-radius: 10px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.5);
}

/* ---- Message Bubbles ---- */
.ai-chat-message {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    animation: aiChatFadeInUp 0.35s ease-out;
}

.ai-chat-message-bot {
    flex-direction: row;
    align-items: flex-start;
}

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

.ai-chat-message-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(108, 99, 255, 0.1), rgba(108, 99, 255, 0.05));
    background: linear-gradient(135deg,
        color-mix(in srgb, var(--ai-chat-primary) 12%, transparent),
        color-mix(in srgb, var(--ai-chat-primary) 5%, transparent));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.ai-chat-message-avatar svg {
    width: 18px;
    height: 18px;
    color: var(--ai-chat-primary);
}

.ai-chat-message-content {
    max-width: 80%;
    display: flex;
    flex-direction: column;
}

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

.ai-chat-message-bubble {
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.ai-chat-message-bot .ai-chat-message-bubble {
    background: var(--ai-chat-bot-bubble);
    color: var(--ai-chat-text);
    border-radius: 18px 18px 18px 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.ai-chat-message-user .ai-chat-message-bubble {
    background: linear-gradient(135deg, var(--ai-chat-primary), var(--ai-chat-primary-dark));
    color: #fff;
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 2px 8px var(--ai-chat-primary-glow);
}

.ai-chat-message-time {
    font-size: 11px;
    color: var(--ai-chat-text-light);
    margin-top: 4px;
    padding: 0 4px;
    font-weight: 500;
}

.ai-chat-message-user .ai-chat-message-time {
    text-align: right;
}

/* ---- Markdown Content Styling ---- */
.ai-chat-message-bubble p {
    margin: 0 0 8px;
}

.ai-chat-message-bubble p:last-child {
    margin-bottom: 0;
}

.ai-chat-message-bubble strong {
    font-weight: 600;
}

.ai-chat-message-bubble em {
    font-style: italic;
}

.ai-chat-message-bubble code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'SFMono-Regular', Consolas, monospace;
}

.ai-chat-message-user .ai-chat-message-bubble code {
    background: rgba(255, 255, 255, 0.2);
}

.ai-chat-message-bubble pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 13px;
    line-height: 1.5;
}

.ai-chat-message-bubble pre code {
    background: transparent;
    padding: 0;
    font-size: inherit;
    color: inherit;
}

.ai-chat-message-bubble ul,
.ai-chat-message-bubble ol {
    padding-left: 20px;
    margin: 8px 0;
}

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

.ai-chat-message-bubble a {
    color: var(--ai-chat-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.ai-chat-message-user .ai-chat-message-bubble a {
    color: #fff;
}

/* ---- Typing Indicator ---- */
.ai-chat-typing {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    align-items: flex-start;
    animation: aiChatFadeInUp 0.3s ease-out;
}

.ai-chat-typing-dots {
    display: flex;
    gap: 5px;
    padding: 14px 18px;
    background: var(--ai-chat-bot-bubble);
    border-radius: 18px 18px 18px 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    align-items: center;
}

.ai-chat-typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--ai-chat-text-light);
    border-radius: 50%;
    animation: aiChatBounce 1.4s infinite;
}

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

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

/* ---- Suggestion Buttons ---- */
.ai-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 16px;
    background: var(--ai-chat-bg-messages);
    animation: aiChatFadeInUp 0.4s ease-out;
}

.ai-chat-suggestion-btn {
    background: var(--ai-chat-bot-bubble);
    border: 1.5px solid var(--ai-chat-border);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-family: var(--ai-chat-font);
    font-weight: 500;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.ai-chat-suggestion-btn:hover {
    border-color: var(--ai-chat-primary);
    color: var(--ai-chat-primary);
    background: color-mix(in srgb, var(--ai-chat-primary) 6%, #fff);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(108, 99, 255, 0.12);
}

/* ---- Input Area ---- */
.ai-chat-input-area {
    background: var(--ai-chat-bg);
    border-top: 1px solid var(--ai-chat-border);
    padding: 16px 20px;
    flex-shrink: 0;
}

.ai-chat-input-container {
    display: flex;
    background: var(--ai-chat-input-bg);
    border-radius: 16px;
    padding: 4px 4px 4px 16px;
    align-items: flex-end;
    border: 2px solid transparent;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.ai-chat-input-container:focus-within {
    border-color: color-mix(in srgb, var(--ai-chat-primary) 45%, transparent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ai-chat-primary) 10%, transparent);
}

.ai-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    line-height: 1.5;
    font-family: var(--ai-chat-font);
    color: var(--ai-chat-text);
    padding: 8px 0;
    min-height: 24px;
}

.ai-chat-input::placeholder {
    color: var(--ai-chat-text-light);
}

.ai-chat-send-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--ai-chat-primary), var(--ai-chat-primary-dark));
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    padding: 0;
}

.ai-chat-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px var(--ai-chat-primary-glow);
}

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

.ai-chat-send-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.ai-chat-powered {
    text-align: center;
    font-size: 11px;
    color: var(--ai-chat-text-light);
    margin-top: 10px;
    font-weight: 500;
    letter-spacing: 0.02em;
}

/* ---- Error Message ---- */
.ai-chat-error-bubble {
    background: #fef2f2 !important;
    border: 1px solid #fecaca;
    color: #991b1b !important;
}

.ai-chat-retry-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 12px;
    background: #fff;
    border: 1px solid #fca5a5;
    border-radius: 12px;
    font-size: 12px;
    color: #dc2626;
    cursor: pointer;
    font-family: var(--ai-chat-font);
    font-weight: 600;
    transition: all 0.2s ease;
}

.ai-chat-retry-btn:hover {
    background: #fef2f2;
    border-color: #dc2626;
}

/* ---- Keyframe Animations ---- */
@keyframes aiChatPulse {
    0% { box-shadow: 0 8px 24px var(--ai-chat-primary-glow), 0 0 0 0 var(--ai-chat-primary-glow); }
    70% { box-shadow: 0 8px 24px var(--ai-chat-primary-glow), 0 0 0 14px rgba(108, 99, 255, 0); }
    100% { box-shadow: 0 8px 24px var(--ai-chat-primary-glow), 0 0 0 0 rgba(108, 99, 255, 0); }
}

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

@keyframes aiChatBounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

@keyframes aiChatDotPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.85); }
}

@keyframes aiChatBadgePop {
    0% { transform: scale(0); }
    100% { transform: scale(1); }
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
    .ai-chat-window {
        width: calc(100% - 32px);
        max-width: 400px;
        height: 70vh;
        max-height: 500px;
        bottom: 146px; /* Positioned above the FAB (80px + 56px + 10px spacing) */
        right: 16px;
        left: auto;
        border-radius: 20px;
        max-height: 70vh;
    }

    .ai-chat-fab {
        bottom: 80px; /* Raised to clear mobile bottom navigation menu */
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .ai-chat-header {
        padding: 16px;
        border-radius: 0;
    }

    .ai-chat-messages {
        padding: 16px;
    }

    .ai-chat-suggestions {
        padding: 0 16px 12px;
    }

    .ai-chat-input-area {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .ai-chat-suggestion-btn {
        font-size: 12px;
        padding: 6px 12px;
    }
}

@media (max-width: 360px) {
    .ai-chat-message-content {
        max-width: 85%;
    }
}
