/* AI Report Modal - Premium Light Design */
:root {
    --ai-primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --ai-glass-bg: rgba(255, 255, 255, 0.95);
    --ai-glass-border: rgba(0, 0, 0, 0.1);
    --ai-text-glow: 0 0 10px rgba(118, 75, 162, 0.3);
    --ai-accent-color: #667eea;
}

/* Modal Content Container */
.ai-modal-content {
    background-color: #ffffff !important;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.98)) !important;
    backdrop-filter: blur(16px) !important;
    -webkit-backdrop-filter: blur(16px) !important;
    border: 1px solid rgba(0, 0, 0, 0.1) !important;
    border-radius: 20px !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15) !important;
    overflow: hidden !important;
    color: #1f2937 !important;
    height: 90vh !important;
    display: flex !important;
    flex-direction: column !important;
    position: relative;
}

.ai-modal-header {
    background: transparent !important;
    color: #1f2937 !important;
    flex-shrink: 0;
}

.ai-modal-body {
    background: transparent !important;
    color: #1f2937 !important;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Header */
.ai-modal-header {
    border-bottom: 1px solid var(--ai-glass-border);
    padding: 1.5rem;
    position: relative;
}

.ai-modal-title {
    font-weight: 700;
    font-size: 1.25rem;
    background: linear-gradient(to right, #667eea, #764ba2);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-modal-title i {
    color: var(--ai-accent-color);
    -webkit-text-fill-color: var(--ai-accent-color);
    filter: drop-shadow(0 0 5px var(--ai-accent-color));
}

.btn-close-white {
    filter: none;
    opacity: 0.5;
    transition: opacity 0.3s;
}

.btn-close-white:hover {
    opacity: 1;
}

/* Chat History */
.ai-chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    padding-bottom: 100px;
    /* Space for input area */
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Scrollbar Styling */
.ai-chat-history::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-history::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}

.ai-chat-history::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

/* Chat Messages */
.chat-message {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    animation: fadeIn 0.3s ease-out;
}

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

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--ai-accent-color);
    box-shadow: 0 0 10px rgba(0, 210, 255, 0.3);
    flex-shrink: 0;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-bubble {
    max-width: 80%;
    padding: 1rem;
    border-radius: 15px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
}

/* AI Bubble Style */
.ai-message .chat-bubble {
    background: #f3f4f6;
    border: 1px solid var(--ai-glass-border);
    border-top-left-radius: 0;
    color: #1f2937;
}

/* User Bubble Style */
.user-message .chat-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-top-right-radius: 0;
    color: #fff;
    box-shadow: 0 4px 15px rgba(118, 75, 162, 0.3);
}

/* Input Area */
.ai-input-area {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 1.5rem;
    background: linear-gradient(to top, #ffffff 80%, transparent);
    z-index: 10;
}

.ai-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-chat-input {
    background: #f9fafb !important;
    border: 1px solid rgba(0, 0, 0, 0.15) !important;
    border-radius: 25px !important;
    padding: 0.8rem 3rem 0.8rem 1.5rem !important;
    color: #1f2937 !important;
    width: 100%;
    transition: all 0.3s ease;
}

.ai-chat-input::placeholder {
    color: #9ca3af !important;
}

.ai-chat-input:focus {
    background: #ffffff !important;
    border-color: var(--ai-accent-color) !important;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.2) !important;
    outline: none;
}

.btn-send-chat {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--ai-accent-color);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-send-chat:hover {
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 0 10px var(--ai-accent-color);
}

/* Result Area */
.ai-result-container {
    margin-top: 1.5rem;
    color: #374151;
    font-size: 0.95rem;
    line-height: 1.6;
    background: #f9fafb;
    border: 1px solid var(--ai-glass-border);
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    animation: fadeIn 0.5s ease-out;
    position: relative;
}

/* Copy Report Button */
.copy-report-btn {
    position: sticky;
    bottom: 10px;
    float: right;
    margin-top: 1rem;
    padding: 0.6rem 1.2rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    border-radius: 25px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.copy-report-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.copy-report-btn:active {
    transform: translateY(0);
}

.copy-report-btn.copied {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.copy-report-btn i {
    font-size: 0.9rem;
}

.ai-result-container h1,
.ai-result-container h2,
.ai-result-container h3 {
    color: var(--ai-accent-color);
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

.ai-result-container h1 {
    font-size: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
}

.ai-result-container h2 {
    font-size: 1.25rem;
}

.ai-result-container h3 {
    font-size: 1.1rem;
}

.ai-result-container ul,
.ai-result-container ol {
    padding-left: 1.5rem;
    margin: 0.5rem 0 1rem;
}

.ai-result-container ul {
    list-style: none;
    padding-left: 0;
}

.ai-result-container ul > li {
    position: relative;
    padding-left: 1.4rem;
    margin-bottom: 0.55rem;
    line-height: 1.65;
}

.ai-result-container ul > li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.65em;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
}

.ai-result-container ol {
    list-style: decimal;
}

.ai-result-container ol > li {
    margin-bottom: 0.5rem;
    line-height: 1.65;
    padding-left: 0.25rem;
}

.ai-result-container ul ul,
.ai-result-container ol ol,
.ai-result-container ul ol,
.ai-result-container ol ul {
    margin: 0.4rem 0 0.4rem 0.25rem;
}

.ai-result-container ul ul > li::before {
    background: #a5b4fc;
    box-shadow: none;
    width: 5px;
    height: 5px;
    top: 0.7em;
}

.ai-result-container strong {
    color: #1e1b4b;
    font-weight: 700;
}

.ai-result-container em {
    color: #6366f1;
    font-style: italic;
}

.ai-result-container p {
    margin-bottom: 1rem;
    line-height: 1.7;
}

.ai-result-container hr {
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    margin: 1.25rem 0;
}

.ai-result-container blockquote {
    border-left: 3px solid #667eea;
    margin: 0.85rem 0;
    padding: 0.5rem 0.85rem;
    background: rgba(102, 126, 234, 0.06);
    border-radius: 0 8px 8px 0;
    color: #374151;
    font-style: italic;
}

html.dark .ai-result-container strong {
    color: #f8fafc;
}

html.dark .ai-result-container em {
    color: #a78bfa;
}

html.dark .ai-result-container hr {
    border-color: rgba(255, 255, 255, 0.08);
}

html.dark .ai-result-container blockquote {
    background: rgba(167, 139, 250, 0.08);
    border-color: #a78bfa;
    color: #cbd5e1;
}

html.dark .ai-result-container ul ul > li::before {
    background: #c4b5fd;
}

/* Helper Text */
.ai-helper-text {
    font-size: 0.75rem;
    color: rgba(0, 0, 0, 0.4);
    margin-top: 0.5rem;
    text-align: center;
}

/* Modal Expansion Animation */
.modal-expand .modal-dialog {
    max-width: 900px;
    transition: max-width 0.5s ease-in-out;
}

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

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

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
    background: #f3f4f6;
    border: 1px solid var(--ai-glass-border);
    border-radius: 0 15px 15px 15px;
    width: fit-content;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: rgba(102, 126, 234, 0.6);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

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

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

@keyframes typing {

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

    40% {
        transform: scale(1);
    }
}

/* ── Dark Mode Overrides ── */
html.dark .ai-modal-content {
    background-color: #0f172a !important;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.98), rgba(30, 41, 59, 0.98)) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    color: #f1f5f9 !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5) !important;
}

html.dark .ai-modal-header {
    border-bottom-color: rgba(255, 255, 255, 0.1);
    color: #f1f5f9 !important;
}

html.dark .ai-modal-header .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

html.dark .ai-chat-history::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

html.dark .ai-chat-history::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
}

html.dark .ai-message .chat-bubble {
    background: #1e293b;
    border-color: rgba(255, 255, 255, 0.1);
    color: #f1f5f9;
}

html.dark .ai-input-area {
    background: linear-gradient(to top, #0f172a 80%, transparent);
}

html.dark .ai-chat-input {
    background: #1e293b !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    color: #f1f5f9 !important;
}

html.dark .ai-chat-input::placeholder {
    color: #64748b !important;
}

html.dark .ai-chat-input:focus {
    background: #0f172a !important;
    border-color: var(--ai-accent-color) !important;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.3) !important;
}

html.dark .ai-result-container {
    background: #1e293b;
    border-color: rgba(255, 255, 255, 0.1);
    color: #cbd5e1;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

html.dark .ai-result-container strong {
    color: #f8fafc;
}

html.dark .ai-helper-text {
    color: rgba(255, 255, 255, 0.3);
}

html.dark .typing-indicator {
    background: #1e293b;
    border-color: rgba(255, 255, 255, 0.1);
}

html.dark .ai-modal-title {
    background: linear-gradient(to right, #a78bfa, #c084fc);
    -webkit-background-clip: text;
    background-clip: text;
}

/* Additional Fixes for Markdown content */
html.dark .ai-modal-content .markdown-body {
    background-color: transparent !important;
    color: #cbd5e1 !important;
}

html.dark .ai-modal-content .markdown-body h1,
html.dark .ai-modal-content .markdown-body h2,
html.dark .ai-modal-content .markdown-body h3 {
    color: #a78bfa !important;
}

.chat-bubble.w-100 {
    max-width: 100% !important;
}

/* ── Markdown typography inside AI report bubble ── */
.chat-bubble.markdown-body p {
    margin-top: 0;
    margin-bottom: 0.75rem;
    line-height: 1.7;
}

.chat-bubble.markdown-body p:last-child {
    margin-bottom: 0;
}

.chat-bubble.markdown-body h1,
.chat-bubble.markdown-body h2,
.chat-bubble.markdown-body h3,
.chat-bubble.markdown-body h4 {
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
    line-height: 1.3;
    color: #4f46e5;
}

.chat-bubble.markdown-body h1 { font-size: 1.15rem; border-bottom: 2px solid rgba(79,70,229,0.2); padding-bottom: 0.3rem; }
.chat-bubble.markdown-body h2 { font-size: 1.05rem; border-bottom: 1px solid rgba(79,70,229,0.15); padding-bottom: 0.25rem; }
.chat-bubble.markdown-body h3 { font-size: 0.97rem; }
.chat-bubble.markdown-body h4 { font-size: 0.93rem; color: #6366f1; }

.chat-bubble.markdown-body ul,
.chat-bubble.markdown-body ol {
    margin: 0.5rem 0 0.75rem 1.25rem;
    padding: 0;
}

.chat-bubble.markdown-body li {
    margin-bottom: 0.35rem;
    line-height: 1.6;
}

.chat-bubble.markdown-body strong {
    font-weight: 700;
    color: #1e1b4b;
}

.chat-bubble.markdown-body em {
    color: #6366f1;
    font-style: italic;
}

.chat-bubble.markdown-body hr {
    border: none;
    border-top: 1px solid rgba(0,0,0,0.1);
    margin: 1rem 0;
}

.chat-bubble.markdown-body blockquote {
    border-left: 3px solid #667eea;
    margin: 0.75rem 0;
    padding: 0.4rem 0.75rem;
    background: rgba(102,126,234,0.06);
    border-radius: 0 6px 6px 0;
    color: #374151;
    font-style: italic;
}

/* Dark mode overrides */
html.dark .chat-bubble.markdown-body h1,
html.dark .chat-bubble.markdown-body h2,
html.dark .chat-bubble.markdown-body h3,
html.dark .chat-bubble.markdown-body h4 {
    color: #a78bfa;
}

html.dark .chat-bubble.markdown-body h1 { border-color: rgba(167,139,250,0.25); }
html.dark .chat-bubble.markdown-body h2 { border-color: rgba(167,139,250,0.18); }

html.dark .chat-bubble.markdown-body strong {
    color: #e2e8f0;
}

html.dark .chat-bubble.markdown-body em {
    color: #a78bfa;
}

html.dark .chat-bubble.markdown-body hr {
    border-color: rgba(255,255,255,0.1);
}

html.dark .chat-bubble.markdown-body blockquote {
    background: rgba(167,139,250,0.08);
    border-color: #a78bfa;
    color: #cbd5e1;
}