/* Clean Ask AI Assistant Styles */

/* AI Button in navbar */
.ai-button {
    position: relative;
    transition: all 0.3s ease;
}

.ai-button:hover {
    transform: scale(1.05);
}

/* Ask AI toggle button styling */
#ask-ai-toggle {
    color: inherit;
    text-decoration: none;
    background: transparent;
}

#ask-ai-toggle:hover {
    color: inherit;
    text-decoration: none;
    background: transparent;
    transform: scale(1.05);
}

#ask-ai-toggle:focus {
    color: inherit;
    text-decoration: none;
    background: transparent;
    box-shadow: none;
}

.ai-indicator {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #10b981;
    box-shadow: 0 0 0 2px #ffffff;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }

    70% {
        box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* Sidebar Container */
.ask-ai-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--ask-ai-width, 420px);
    min-width: 360px;
    max-width: 80vw;
    height: 100vh;
    background: white;
    box-shadow: -2px 0 20px rgba(0, 0, 0, 0.15);
    z-index: 1050;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    will-change: transform;
}

/* Resize handle on left edge */
.ask-ai-resize-handle {
    position: absolute;
    left: 0;
    top: 0;
    width: 5px;
    height: 100%;
    cursor: col-resize;
    z-index: 2;
    background: transparent;
    transition: background 0.2s;
}

.ask-ai-resize-handle:hover {
    background: rgba(59, 125, 221, 0.4);
}

.ask-ai-sidebar.resizing .ask-ai-resize-handle {
    background: rgba(59, 125, 221, 0.6);
}

.ask-ai-sidebar.resizing {
    transition: none;
    user-select: none;
}

.ask-ai-sidebar.visible {
    right: 0;
}

.ask-ai-sidebar-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.chat-header {
    padding: 1rem;
    border-bottom: 1px solid #e9ecef;
    background: #f8f9fa;
    flex-shrink: 0;
}

.chat-header h5 {
    color: #343a40;
    font-weight: 600;
}

/* Messages Area */
.chat-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    scroll-behavior: smooth;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 200px;
    position: relative;
}

/* Welcome Message */
.chat-welcome {
    padding: 2rem 1rem;
    color: #6c757d;
    text-align: center;
}

.chat-welcome i {
    color: #007bff;
    margin-bottom: 1rem;
}

/* Quick Suggestions */
.quick-suggestions {
    max-width: 300px;
    margin: 0 auto;
}

.quick-suggestions .btn {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    margin: 0.1rem;
    border-radius: 12px;
    transition: all 0.2s ease;
}

.quick-suggestions .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Date Separator */
.date-separator {
    text-align: center;
    margin: 1rem 0;
    position: relative;
}

.date-separator span {
    background: #f8f9fa;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    color: #6c757d;
    border-radius: 12px;
    border: 1px solid #e9ecef;
    font-weight: 500;
}

/* System Message Styles */
.system-message {
    margin: 0.5rem 0;
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.9rem;
    text-align: center;
}

.system-message.info {
    background: #e3f2fd;
    color: #1976d2;
    border-left: 3px solid #2196f3;
}

.system-message.primary {
    background: #f3e5f5;
    color: #7b1fa2;
    border-left: 3px solid #9c27b0;
}

.system-message.warning {
    background: #fff3e0;
    color: #f57c00;
    border-left: 3px solid #ff9800;
}

/* Message Bubbles */
.message {
    max-width: 85%;
    margin-bottom: 1rem;
    opacity: 1;
    visibility: visible;
    position: relative;
    z-index: 1;
}

.user-message {
    align-self: flex-end;
    margin-left: auto;
}

.assistant-message {
    align-self: flex-start;
    margin-right: auto;
}

.message-content {
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.4;
    word-wrap: break-word;
}

.user-message .message-content {
    background: #007bff;
    color: white;
    border-bottom-right-radius: 4px;
}

.assistant-message .message-content {
    background: #f8f9fa;
    color: #333;
    border: 1px solid #e9ecef;
    border-bottom-left-radius: 4px;
}

/* Markdown Content Styling */
.markdown-content {
    line-height: 1.6;
    color: inherit;
}

.markdown-content p {
    margin: 0 0 1rem 0;
}

.markdown-content p:last-child {
    margin-bottom: 0;
}

.markdown-content ol,
.markdown-content ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.markdown-content li {
    margin-bottom: 0.25rem;
}

.markdown-content a {
    color: #007bff;
    text-decoration: none;
}

.markdown-content a:hover {
    text-decoration: underline;
}

.markdown-content strong {
    font-weight: 600;
}

.message-time {
    font-size: 0.75rem;
    color: #6c757d;
    margin-top: 4px;
    text-align: right;
}

.assistant-message .message-time {
    text-align: left;
}

/* Inline timestamp for user messages (inside bubble) */
.message-time-inline {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.8);
    margin-top: 4px;
    text-align: right;
    font-weight: 300;
}

/* Enhanced Thinking Indicator */
.typing-indicator {
    align-self: flex-start;
}

.thinking-container {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #f8f9fa;
    border-radius: 18px;
    border: 1px solid #e9ecef;
    min-width: 200px;
}

.thinking-icon {
    flex-shrink: 0;
    animation: pulse-brain 2s infinite ease-in-out;
}

.thinking-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.thinking-text {
    font-size: 0.85rem;
    color: #495057;
    font-weight: 500;
    min-height: 1.2em;
    transition: opacity 0.3s ease;
}

.thinking-dots {
    display: flex;
    gap: 4px;
    justify-content: center;
}

.thinking-dots span {
    width: 4px;
    height: 4px;
    background: #6c757d;
    border-radius: 50%;
    animation: typing-dots 1.4s infinite ease-in-out;
}

.thinking-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.thinking-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing-dots {

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

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

@keyframes pulse-brain {

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

    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

/* Typewriter Effect */
.typewriting .message-content::after {
    content: '|';
    display: inline;
    opacity: 1;
    animation: cursor-blink 0.7s infinite;
    margin-left: 2px;
    color: #007bff;
    font-weight: bold;
}

@keyframes cursor-blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Smooth message appearance */
.message {
    animation: message-appear 0.3s ease-out;
}

@keyframes message-appear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

/* Input Area */
.chat-input-container {
    padding: 1rem;
    border-top: 1px solid #e9ecef;
    flex-shrink: 0;
    background: white;
}

.chat-input-container textarea {
    resize: none;
    border: 1px solid #ced4da;
    border-radius: 20px 0 0 20px;
}

.chat-input-container textarea:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.chat-input-container .btn {
    border-radius: 0 20px 20px 0;
}

/* Overlay */
.ask-ai-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    opacity: 0;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(2px);
    will-change: opacity;
}

.ask-ai-overlay.visible {
    display: block;
    opacity: 1;
}

/* Code blocks in messages */
.message-content pre {
    background: #2d3748;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.85rem;
    margin: 8px 0;
}

.message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
}

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

/* Entity Previews */
.entity-preview {
    margin-top: 8px;
    padding: 8px;
    background: #f1f3f4;
    border-radius: 8px;
    border-left: 3px solid #007bff;
    font-size: 0.9rem;
}

/* Mobile Responsive */
@media (max-width: 576px) {
    .ask-ai-sidebar {
        --ask-ai-width: 100% !important;
        width: 100% !important;
        min-width: 100%;
        max-width: 100%;
    }

    .message {
        max-width: 95%;
    }

    .chat-header {
        padding: 0.75rem;
    }

    .chat-messages-container {
        padding: 0.75rem;
    }

    .chat-input-container {
        padding: 0.75rem;
    }
}

/* Animations */
.ask-ai-sidebar {
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.ask-ai-sidebar.visible {
    transform: translateX(0);
}

/* AI Response formatting */
.ai-response {
    margin: 0;
}

.ai-response p {
    margin: 0 0 8px 0;
}

.ai-response p:last-child {
    margin-bottom: 0;
}

/* Focus styles for accessibility */
.chat-input-container textarea:focus,
.chat-header button:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* Load Conversation History Button */
.load-history-container {
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 15px;
    margin-bottom: 15px !important;
}

#load_history_btn {
    border-radius: 20px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    text-decoration: none;
}

#load_history_btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.2);
    text-decoration: none;
}

#load_history_btn small {
    font-size: 0.7rem;
    margin-top: 2px;
}

/* Load More Messages Button */
.load-more-container {
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 15px;
    margin-bottom: 15px !important;
}

#load_more_btn {
    border-radius: 20px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

#load_more_btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(108, 117, 125, 0.2);
}

#load_more_btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

#load_more_btn small {
    font-size: 0.7rem;
    margin-top: 2px;
}

/* Messages container top alignment */
#ai_messages_container {
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

/* Ensure date separators are properly aligned */
.date-separator {
    text-align: center;
    margin: 15px 0 10px 0;
    position: relative;
}

.date-separator span {
    background: #f8f9fa;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.8rem;
    color: #6c757d;
    border: 1px solid #e9ecef;
}

/* Report Preview in Chat - Special Styling */
/* When a report preview is inside a message, reset the bubble styling */
/* Using :has() selector for modern browsers */
.assistant-message .message-content:has(.report-preview) {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
}

/* Ensure report preview takes full width of message area */
.message:has(.report-preview) {
    max-width: 100% !important;
    width: 100% !important;
}

/* Fallback for browsers without :has() support - use .has-report-preview class */
.assistant-message.has-report-preview .message-content,
.message-content.has-report-preview {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
}

.message.has-report-preview {
    max-width: 100% !important;
    width: 100% !important;
}

.message-content .report-preview {
    margin: 0;
    border-radius: 12px;
    overflow: hidden;
}

/* Report preview card styling in chat */
.message-content .report-preview .card-header {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
}

.message-content .report-preview .card-header h6 {
    font-size: 0.85rem;
    margin: 0;
}

/* Table in report preview */
.message-content .report-preview .table-responsive {
    max-height: 250px;
    font-size: 0.8rem;
    overflow: hidden !important;
    /* Ensure content doesn't overflow */
}

/* Ensure report preview card contains all content */
.report-preview {
    overflow: hidden !important;
}

.report-preview .card-body {
    overflow: hidden !important;
}

.message-content .report-preview table {
    margin-bottom: 0;
}

.message-content .report-preview th,
.message-content .report-preview td {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    vertical-align: middle;
}

.message-content .report-preview th {
    background-color: #f8f9fa;
    font-weight: 600;
    border-bottom: 2px solid #dee2e6;
}

/* Action buttons in report preview */
.message-content .report-preview .card-footer {
    padding: 0.5rem 0.75rem;
    background-color: #f8f9fa;
}

.message-content .report-preview .card-footer .btn {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
}

/* Badge styling in report preview header */
.message-content .report-preview .badge {
    font-size: 0.7rem;
    font-weight: 500;
}

/* Ensure proper contrast for text in cards */
.message-content .report-preview .card-body {
    background-color: #fff;
}

/* Chart container in report preview */
.message-content .report-preview .card-body.border-top {
    padding: 0.75rem;
}

/* Ensure message timestamp appears correctly after report preview */
.assistant-message:has(.report-preview) .message-time {
    margin-top: 0.5rem;
}

/* ═══════════════════════════════════════════════════════
   Tool Progress Pills
   ═══════════════════════════════════════════════════════ */
.ai-tool-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
    min-height: 0;
}

.ai-tool-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    background: #e8f0fe;
    color: #1a73e8;
    transition: all 0.3s ease;
}

.ai-tool-pill.completed {
    background: #e6f4ea;
    color: #1e7e34;
}

.ai-tool-pill.error {
    background: #fce8e6;
    color: #d93025;
}

.ai-tool-pill .spinner-border {
    width: 10px;
    height: 10px;
    border-width: 1.5px;
}

/* ═══════════════════════════════════════════════════════
   Typing Dots Animation
   ═══════════════════════════════════════════════════════ */
.ai-typing-dots span {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #adb5bd;
    border-radius: 50%;
    margin: 0 2px;
    animation: ai-dot-bounce 1.4s infinite ease-in-out;
}

.ai-typing-dots span:nth-child(1) {
    animation-delay: 0s;
}

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

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

@keyframes ai-dot-bounce {

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

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

/* ═══════════════════════════════════════════════════════
   Streaming Cursor
   ═══════════════════════════════════════════════════════ */
.ai-streaming-cursor::after {
    content: '▊';
    animation: ai-blink 0.8s infinite;
    color: #6c757d;
    font-size: 0.9em;
}

@keyframes ai-blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}