/* Chatbot Dialog Styles */
.chatbot-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: Arial, sans-serif;
}

/* Chatbot Overlay Styles */
.chatbot-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black */
    z-index: 9998; /* Behind the dialog but above other content */
    display: none; /* Hidden by default */
}

.chatbot-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.9);
    color: #000000;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 2px 10px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
}

.chatbot-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2), 0 3px 15px rgba(0, 0, 0, 0.15);
    background-color: rgba(255, 255, 255, 1);
}

    .chatbot-button i {
        font-size: 24px;
    }

.chatbot-dialog {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 450px;
    height: 550px;
    background-color: white;
    border-radius: 20px;
    box-shadow: 0 8px 50px rgba(0, 0, 0, 0.15), 0 2px 20px rgba(0, 0, 0, 0.1);
    display: none;
    flex-direction: column;
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Media query for larger screens (desktop) */
@media (min-width: 992px) {
    .chatbot-dialog {
        width: 500px;
        height: 600px;
    }

    .chatbot-overlay {
        display: none !important;
    }
}

/* Media query for wider desktop screens */
@media (min-width: 1200px) {
    .chatbot-dialog {
        width: 700px;
        height: 800px;
    }
}

/* Media query for mobile screens (full screen modal) */
@media (max-width: 991px) {
    .chatbot-dialog {
        position: fixed;
        top: 50%;
        left: 50%;
        width: 90%;
        height: 90%;
        transform: translate(-50%, -50%);
        z-index: 9999; /* Ensure dialog is on top of the overlay */
        border-radius: 20px;
        box-shadow: 0 8px 50px rgba(0, 0, 0, 0.15), 0 2px 20px rgba(0, 0, 0, 0.1);
        /* Adjust padding if necessary */
        padding: 10px;
    }

    /* Optionally hide the button when dialog is open, might need JS */
    /* .chatbot-button { display: none; } */

    /* Adjust header/input padding if needed for full screen */
    .chatbot-header, .chatbot-input-container {
        padding-left: 10px;
        padding-right: 10px;
    }
}

.chatbot-header {
    padding: 10px;
    background-color: transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 20px 20px 0 0;
    border-bottom: 1px solid #e6e6e6;
}

.chatbot-title {
    flex: 1;
    margin-right: 20px;
    font-weight: bold;
    color: #000000;
}



    .chatbot-header h3 {
        margin: 0;
        font-size: 20px;
    }

.chatbot-close {
    cursor: pointer;
    font-size: 30px;
}

.chatbot-body {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    word-wrap: break-word;
    word-break: break-word;
}

.message {
    margin-bottom: 10px;
    max-width: 80%;
    padding: 10px;
    border-radius: 18px;
    position: relative; /* Add this for positioning the arrow */
    font-size: 13px; /* Adjust font size */
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.bot-message,
.user-message {
    padding: 10px 16px;
    border-radius: 18px;
    margin-bottom: 10px;
    max-width: 75%;
    display: block;
    width: fit-content;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    white-space: pre-wrap;
}

.bot-message {
    background-color: #f1f0f0;
    color: #222;
    align-self: flex-start;
    margin-left: 0;
    margin-right: auto;
}

.user-message {
    background: #e0f7fa;
    color: #222;
    text-align: right;
    margin-left: auto;
    margin-right: 0;
    padding-bottom: 10px; /* Add padding to make space for the arrow */
}

    /* Arrow styles */
    .bot-message::before, .user-message::before {
        content: "";
        position: absolute;
        bottom: 0; /* Position at the bottom */
        border: 8px solid transparent; /* Base for the triangle */
    }

    .user-message::before {
        right: -7px; /* Position relative to the right edge */
        border-bottom-color: #e0f7fa; /* Arrow color (match bubble) */
        border-bottom-right-radius: 8px; /* Rounded corner effect */
    }

.bot-message::before {
    left: -7px; /* Position relative to the left edge */
    border-bottom-color: #f1f0f0; /* Arrow color (match bubble) */
    border-bottom-left-radius: 8px; /* Rounded corner effect */
}

/* Hide arrow for spinner message */
.spinner-message::before {
    content: none;
}

/* Cursor style for clickable search results */
.search-result-message {
    cursor: pointer;
}

/* Handle long URLs and code blocks */
.message a,
.message code,
.message pre {
    word-break: break-all;
    overflow-wrap: break-word;
    max-width: 100%;
}

/* Ensure images don't overflow */
.message img {
    max-width: 100%;
    height: auto;
}

/* Spinner styles */
.spinner-message {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 10px;
}

.spinner-gif {
    margin: 0;
    padding: 0;
}

/* Typing animation styles */
.typing-message {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 10px;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 6px 10px;
    background-color: #f1f0f0;
    border-radius: 18px;
    max-width: 50px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #999;
    animation: typing-bounce 1.4s infinite ease-in-out;
}

    .typing-dot:nth-child(1) {
        animation-delay: -0.32s;
    }

    .typing-dot:nth-child(2) {
        animation-delay: -0.16s;
    }

    .typing-dot:nth-child(3) {
        animation-delay: 0s;
    }

@keyframes typing-bounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.chatbot-input-container {
    display: flex;
    padding: 15px 20px 20px 20px;
    border-top: 1px solid #e6e6e6;
    align-items: center;
    background-color: transparent;
    border-radius: 0 0 20px 20px;
}

.chatbot-input {
    flex: 1;
    padding: 6px 20px 8px 20px;
    border: 1px solid #e6e6e6;
    border-radius: 25px;
    outline: none;
    font-size: 14px;
    height: 60px;
    background-color: white;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.chatbot-input-text {
    flex: 1;
    border: none;
    outline: none;
    font-size: 14px;
    background: transparent;
    padding: 0;
    margin: 0;
    width: 100%;
    margin-bottom: 8px;
}

.chatbot-input-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
    height: 25px;
    margin-top: auto;
}

.chatbot-rag-button,
.chatbot-db-button {
    padding: 6px 10px;
    border: none;
    border-radius: 12px;
    background-color: #e9ecef;
    color: #6c757d;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    height: 25px;
    transition: all 0.2s ease;
}

    .chatbot-rag-button.active,
    .chatbot-db-button.active {
        background-color: #007bff;
        color: white;
    }



    .chatbot-rag-button i,
    .chatbot-db-button i {
        font-size: 12px;
    }

.chatbot-attach-data-button {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: #e9ecef;
    color: #6c757d;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    right: 50px;
    top: 50%;
    transform: translateY(-50%);
    transition: all 0.2s ease;
}

.chatbot-attach-data-button:hover {
    background-color: #d1ecf1;
    transform: translateY(-50%) scale(1.05);
}

    .chatbot-attach-data-button.active {
        background-color: #007bff;
        color: white;
    }

    .chatbot-attach-data-button i {
        font-size: 14px;
    }

.chatbot-send {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: #007bff;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
}

    .chatbot-send.disabled {
        background-color: #dee2e6;
        color: #adb5bd;
        cursor: not-allowed;
    }

    .chatbot-send i {
        font-size: 14px;
        transform: rotate(0deg);
    }

/* Token usage styling - inside message bubble at bottom right */
.token-usage-inside-bubble {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: #6c757d;
    opacity: 0.8;
    text-align: right;
    margin-top: 4px;
    padding-top: 2px;
}

/* iOS-style message formatting */
.bot-message strong {
    font-weight: bold;
    color: #333;
    display: block;
    margin-bottom: 8px;
}

/* LLM suggested title styling */
.bot-message .llm-title {
    font-weight: bold !important;
    text-decoration: underline !important;
    color: #000000 !important;
    font-size: 16px;
    margin-bottom: 4px;
    margin-top: 0;
    display: block;
}

/* Section title styling */
.bot-message .section-title {
    font-weight: bold !important;
    color: #000000 !important;
    font-size: 14px;
    margin-bottom: 4px;
    margin-top: 8px;
}

.bot-message .section-title:first-child {
    margin-top: 2px;
}

.bot-message .field-label {
    color: #666;
    font-weight: 500;
}

.bot-message .field-value {
    color: #333;
    font-weight: normal;
}

.bot-message .more-indicator {
    color: #999;
    font-style: italic;
    font-size: 12px;
    margin-top: 2px;
    display: block;
}

/* Error message styling - matching iOS red background */
.bot-message.error-message {
    background-color: rgba(220, 53, 69, 0.6) !important; /* Red with 60% opacity like iOS */
    color: #fff !important; /* White text for better contrast */
}

.bot-message.error-message::before {
    border-bottom-color: rgba(220, 53, 69, 0.6) !important; /* Match the bubble color */
}

/* Score-based result styling */
.bot-message.high-confidence-result {
    border-left: 4px solid #4caf50;
    position: relative;
}

.bot-message.medium-confidence-result {
    border-left: 4px solid #ffc107;
    position: relative;
}

.score-display {
    position: absolute;
    top: 8px;
    right: 8px;
    background-color: rgba(0, 0, 0, 0.1);
    color: #666;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    font-family: 'Courier New', monospace;
}

/* Enhanced error message styling */
.bot-message.error-message .error-info {
    margin-top: 8px;
    padding: 8px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    font-size: 12px;
}

/* Hide attach data button */
.chatbot-attach-data-button {
    display: none !important;
}

.bot-message.error-message .recovery-suggestion {
    color: #ffd700;
    font-style: italic;
    margin-top: 4px;
}

/* Database Agent Enquiry Integration Styling */
.message.clickable-enquiry {
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease-in-out;
}

.message.clickable-enquiry:hover {
    background-color: rgba(255, 255, 255, 0.05);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Icon removed - no longer showing 📊 icon on message bubbles */
/* .message.clickable-enquiry::after {
    content: "📊";
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 16px;
    opacity: 0.7;
    transition: opacity 0.2s ease-in-out;
}

.message.clickable-enquiry:hover::after {
    opacity: 1;
} */

/* Enquiry indicator removed - no more icon styling */

/* Enhanced message click feedback */
.message.clickable-enquiry:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Loading state for enquiry opening */
.message.clickable-enquiry.loading {
    pointer-events: none;
    opacity: 0.7;
}

/* Loading state animation removed - no more icon animation */

@keyframes pulse {
    0%, 100% { opacity: 0.7; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.1); }
}

/* Enhanced Markdown Rendering Styles */

/* Headers */
.bot-message .markdown-header {
    font-weight: 600;
    color: #2c3e50;
    margin-top: 16px;
    margin-bottom: 8px;
    line-height: 1.3;
}

.bot-message .markdown-h1 {
    font-size: 20px;
    border-bottom: 2px solid #3498db;
    padding-bottom: 4px;
}

.bot-message .markdown-h2 {
    font-size: 18px;
    border-bottom: 1px solid #bdc3c7;
    padding-bottom: 3px;
}

.bot-message .markdown-h3 {
    font-size: 16px;
    color: #34495e;
}

.bot-message .markdown-h4 {
    font-size: 15px;
    color: #34495e;
}

.bot-message .markdown-h5 {
    font-size: 14px;
    color: #34495e;
}

.bot-message .markdown-h6 {
    font-size: 13px;
    color: #7f8c8d;
    font-style: italic;
}

/* Paragraphs */
.bot-message .markdown-paragraph {
    margin: 8px 0;
    line-height: 1.5;
    color: inherit;
}

/* Bold and Italic */
.bot-message .markdown-bold {
    font-weight: 600;
    color: #2c3e50;
}

.bot-message .markdown-italic {
    font-style: italic;
    color: #34495e;
}

/* Inline Code */
.bot-message .markdown-inline-code {
    background-color: #f8f9fa;
    color: #e74c3c;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    border: 1px solid #e9ecef;
}

/* Code Blocks */
.bot-message pre {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 12px;
    margin: 8px 0;
    overflow-x: auto;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.4;
    color: #2c3e50;
}

.bot-message code {
    background-color: #f8f9fa;
    color: #e74c3c;
    padding: 1px 4px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
}

/* Links */
.bot-message .markdown-link {
    color: #3498db;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
}

.bot-message .markdown-link:hover {
    color: #2980b9;
    border-bottom-color: #2980b9;
}

/* Lists */
.bot-message ul, .bot-message ol {
    margin: 8px 0;
    padding-left: 20px;
}

.bot-message .markdown-list-item {
    margin: 4px 0;
    line-height: 1.4;
    color: inherit;
}

.bot-message ul {
    list-style-type: disc;
}

.bot-message ol {
    list-style-type: decimal;
}

/* Blockquotes */
.bot-message .markdown-blockquote {
    border-left: 4px solid #3498db;
    padding-left: 16px;
    margin: 12px 0;
    color: #7f8c8d;
    font-style: italic;
    background-color: #f8f9fa;
    padding: 8px 16px;
    border-radius: 0 4px 4px 0;
}

/* Horizontal Rules */
.bot-message .markdown-hr {
    border: none;
    height: 1px;
    background-color: #bdc3c7;
    margin: 16px 0;
}

/* Strikethrough */
.bot-message .markdown-strikethrough {
    text-decoration: line-through;
    color: #95a5a6;
}

/* Table styling (if needed in future) */
.bot-message table {
    border-collapse: collapse;
    margin: 12px 0;
    width: 100%;
    font-size: 13px;
}

.bot-message th, .bot-message td {
    border: 1px solid #e9ecef;
    padding: 8px 12px;
    text-align: left;
}

.bot-message th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #2c3e50;
}

.bot-message tr:nth-child(even) {
    background-color: #f8f9fa;
}

/* Ensure proper spacing and inheritance */
.bot-message .markdown-header:first-child {
    margin-top: 0;
}

.bot-message .markdown-paragraph:last-child {
    margin-bottom: 0;
}

/* Override existing styles for Markdown content */
.bot-message strong:not(.markdown-bold) {
    font-weight: inherit;
    color: inherit;
    display: inline;
    margin-bottom: 0;
}

.bot-message em:not(.markdown-italic) {
    font-style: inherit;
    color: inherit;
}