/*
 * WP RAG Chatbot - Public Chat Widget Styles
 * VERSION: 0.6.1 (Vimeo Popover Fix)
 */
.wp-rag-chat-widget-container {
    /* Optional container styling */
}
#wp-rag-chat-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background-color: #0073aa;
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    z-index: 9998;
    transition: transform 0.2s;
}
#wp-rag-chat-button:hover {
    transform: scale(1.05);
    background-color: #005a87;
}
#wp-rag-chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 350px;
    max-width: calc(100vw - 40px);
    height: 500px;
    max-height: calc(100vh - 110px);
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s, transform 0.3s;
    visibility: hidden;
}

/* --- Styles for Chunk Citations --- */
.chunk-citation {
    display: inline-block;
    margin: 0 1px 0 3px;
    font-size: 0.7em;
    line-height: 1;
    vertical-align: super;
    cursor: pointer;
    color: #005a87;
    font-weight: bold;
    padding: 1px 4px;
    border: 1px solid #a0d2ff;
    border-radius: 3px;
    background-color: #f0f8ff;
    transition: background-color 0.2s, border-color 0.2s;
    user-select: none;
}
.chunk-citation:hover {
    background-color: #d6ebff;
    border-color: #7fbcff;
}

/* --- Styles for Citation Popover --- */
#wp-rag-chat-citation-popover {
    position: absolute;
    background-color: #ffffff;
    border: 1px solid #cccccc;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-radius: 6px;
    padding: 12px;
    width: 480px; /* Increased width for video */
    max-width: calc(100vw - 20px);
    z-index: 10001;
    font-size: 0.9em;
    line-height: 1.45;
    color: #333;
    display: none;
}
#wp-rag-chat-citation-popover .spinner {
    border: 3px solid rgba(0,0,0,0.1);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border-left-color: #0073aa;
    animation: spin 1s linear infinite;
    margin: 10px auto;
    display: block;
}

/* Styles for video player wrapper (Vimeo and YouTube) */
.wp-rag-chat-popover-content .wp-rag-vimeo-wrapper {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    height: 0;
    overflow: hidden;
    margin-bottom: 10px;
    background-color: #000;
    border-radius: 4px;
}
.wp-rag-chat-popover-content .wp-rag-vimeo-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.wp-rag-chat-popover-content p {
    margin-top: 0;
    margin-bottom: 10px;
    max-height: 180px;
    overflow-y: auto;
    background-color: #f9f9f9;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #eee;
}
.wp-rag-chat-popover-content hr { margin: 10px 0; border: 0; border-top: 1px solid #eeeeee; }
.wp-rag-chat-popover-content .popover-links { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 5px; }
.wp-rag-chat-popover-content a { color: #0073aa; text-decoration: none; font-size: 0.95em; }
.wp-rag-chat-popover-content a:hover { text-decoration: underline; }
.wp-rag-chat-popover-content a.highlight-link { font-weight: bold; }
.wp-rag-chat-popover-content .close-popover { 
    position: absolute; 
    top: 10px; 
    right: 10px; 
    background: #dc3545; 
    border: 3px solid #ffffff; 
    border-radius: 50%; 
    font-size: 18px; 
    font-weight: bold;
    line-height: 1; 
    cursor: pointer; 
    color: #ffffff; 
    padding: 6px; 
    width: 32px; 
    height: 32px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    transition: all 0.3s ease;
    box-shadow: 0 4px 8px rgba(220, 53, 69, 0.4), 0 2px 4px rgba(0,0,0,0.2);
    z-index: 1002;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.wp-rag-chat-popover-content .close-popover:hover { 
    color: #ffffff; 
    background: #c82333; 
    border-color: #ffffff; 
    transform: scale(1.15);
    box-shadow: 0 6px 12px rgba(220, 53, 69, 0.5), 0 3px 6px rgba(0,0,0,0.3);
}

/* RTL support for close button */
html[dir="rtl"] .wp-rag-chat-popover-content .close-popover {
    right: auto;
    left: 10px;
}

/* --- General Chat Window Styles --- */
#wp-rag-chat-messages { position: relative; }
#wp-rag-chat-window.visible { opacity: 1; transform: translateY(0) scale(1); visibility: visible; }
#wp-rag-chat-header { background-color: #0073aa; color: #fff; padding: 10px; display: flex; justify-content: space-between; align-items: center; }
#wp-rag-chat-header span { font-weight: bold; margin-right: auto; /* Push subsequent items right */ }
#wp-rag-chat-header button { background: none; border: none; color: #fff; cursor: pointer; padding: 0; }
#wp-rag-chat-header #wp-rag-chat-close { font-size: 24px; margin-left: 5px; }
#wp-rag-chat-messages { flex-grow: 1; padding: 15px; overflow-y: auto; background-color: #f9f9f9; }
.wp-rag-chat-message { margin-bottom: 12px; padding: 8px 12px; border-radius: 10px; max-width: 85%; word-wrap: break-word; line-height: 1.4; }
.wp-rag-chat-user { background-color: #0073aa; color: #fff; margin-left: auto; border-bottom-right-radius: 0; }
.wp-rag-chat-bot { background-color: #e9e9eb; color: #333; margin-right: auto; border-bottom-left-radius: 0; }
.wp-rag-chat-bot.wp-rag-chat-error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }

/* --- Styles for Auto-Generated Links --- */
.wp-rag-chat-message a {
    color: #0073aa;
    text-decoration: none;
    word-break: break-word;
    border-radius: 3px;
    padding: 1px 3px;
    transition: all 0.2s ease;
}
.wp-rag-chat-message a:hover {
    text-decoration: underline;
    color: #005a87;
    background-color: #f0f8ff;
    box-shadow: 0 1px 3px rgba(0, 115, 170, 0.2);
}
.wp-rag-chat-message a:visited {
    color: #6a4c93;
}

/* --- SOURCE LIST STYLES (SPLIT LIST) --- */
.wp-rag-chat-sources.split-sources {
    display: block;
    position: relative;
    max-width: 90%;
    font-size: 0.9em;
    margin-top: 10px;
    margin-bottom: 10px;
    padding: 8px 12px;
    color: #333;
    background-color: #f0f0f0;
    border-radius: 5px;
    margin-right: auto;
    border: 1px solid #e0e0e0;
}
.split-sources .sources-title-cited,
.split-sources .sources-title-more {
    display: block;
    font-weight: bold;
    margin-bottom: 5px;
    margin-top: 8px; /* Space before titles */
    color: #111;
}
.split-sources > strong:first-child {
     margin-top: 0; /* Remove top margin for the very first title */
}
.split-sources ol {
    margin: 0 0 8px 0; /* Space below lists */
    padding: 0;
    list-style: none; /* Disable default browser numbering */
}
.split-sources ol li {
    margin-bottom: 5px;
    position: relative;
    padding-left: 1.5em; /* Make space for custom number */
    line-height: 1.3;
}
.split-sources .sources-list-cited li .source-marker-num {
    position: absolute;
    left: 0;
    top: 1px; /* Adjust vertical alignment */
    width: 1.3em; /* Consistent width */
    text-align: right;
    padding-right: 0.3em;
    font-weight: normal;
    color: #555;
    font-size: 0.9em; /* Slightly smaller */
}
.split-sources hr.sources-separator {
    border: none;
    border-top: 1px dashed #ccc;
    margin: 10px 0 8px 0;
}
.split-sources ol li a {
    color: #0073aa;
    text-decoration: none;
}
.split-sources ol li a:hover {
    text-decoration: underline;
}
.split-sources ol li .source-score {
    font-size: 0.85em;
    color: #666;
    margin-left: 5px;
    font-style: italic;
    white-space: nowrap;
}
.split-sources ol.sources-list-more {
    counter-reset: more-learn-counter;
}
.split-sources ol.sources-list-more li::before {
    counter-increment: more-learn-counter;
    content: counter(more-learn-counter) "."; /* Standard decimal numbering */
    position: absolute;
    left: 0;
    top: 1px;
    width: 1.3em;
    text-align: right;
    padding-right: 0.3em;
    font-weight: normal;
    color: #555;
    font-size: 0.9em;
}
/* --- END SOURCE LIST STYLES --- */


/* --- Loader, Input, Buttons, etc. --- */
#wp-rag-chat-loader { display: flex; align-items: center; justify-content: center; padding: 10px; background-color: rgba(255,255,255,0.8); position: absolute; bottom: 60px; left: 0; right: 0; }
.spinner { border: 3px solid rgba(0,0,0,0.1); width: 18px; height: 18px; border-radius: 50%; border-left-color: #0073aa; animation: spin 1s linear infinite; margin-right: 8px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
#wp-rag-chat-input-area { display: flex; padding: 10px; border-top: 1px solid #e0e0e0; background-color: #fff; align-items: flex-end; }
#wp-rag-chat-input { flex-grow: 1; padding: 8px; border: 1px solid #ccd0d4; border-radius: 4px; resize: none; height: 40px; max-height: 80px; overflow-y: auto; margin-right: 8px; font-family: inherit; }
#wp-rag-chat-input:disabled { background-color: #f6f7f7; }

/* Microphone button styling */
#wp-rag-chat-mic { 
    background-color: #f8f9fa; 
    color: #6c757d; 
    border: 1px solid #dee2e6; 
    border-radius: 4px; 
    padding: 0 8px; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    margin-right: 8px;
    transition: all 0.2s ease;
    height: 40px;
    width: 40px;
}
#wp-rag-chat-mic:hover { 
    background-color: #e9ecef; 
    color: #495057;
    border-color: #adb5bd;
}
#wp-rag-chat-mic.recording { 
    background-color: #dc3545; 
    color: #fff; 
    border-color: #dc3545;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(220, 53, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}

#wp-rag-chat-send { background-color: #0073aa; color: #fff; border: none; border-radius: 4px; padding: 0 12px; cursor: pointer; display: flex; align-items: center; justify-content: center; height: 40px; }
#wp-rag-chat-send:hover { background-color: #005a87; }
#wp-rag-chat-send:disabled { background-color: #a0a5aa; cursor: not-allowed; }
@media (max-width: 500px) { /* Adjusted breakpoint for wider popover */
    #wp-rag-chat-window { width: calc(100vw - 20px); height: calc(100vh - 80px); bottom: 10px; right: 10px; } 
    #wp-rag-chat-button { bottom: 10px; right: 10px; width: 50px; height: 50px; } 
    #wp-rag-chat-citation-popover { width: calc(100vw - 40px); }
}
#wp-rag-chat-new { 
    padding: 4px 8px !important; 
    background-color: #FFD700 !important; 
    border-radius: 4px !important; 
    border: none !important; 
    color: #333 !important; 
    cursor: pointer; 
    font-size: 0.75em !important; 
    font-weight: 600 !important;
    margin-left: auto; 
    margin-right: 6px; 
    white-space: nowrap; 
    transition: all 0.3s ease;
    text-transform: none;
    letter-spacing: 0.1px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15) !important;
    max-width: 120px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}
#wp-rag-chat-new:hover { 
    background-color: #FFED4E !important; 
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2) !important;
}
.wp-rag-chat-header-logo { height: 24px; width: auto; margin-right: 8px; vertical-align: middle; border-radius: 3px; }
.wp-rag-chat-header span { font-size: 0.85em !important; }

/* Example questions pills */
.wp-rag-chat-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 6px 0 8px 0;
}
.wp-rag-chat-examples .wp-rag-chat-example {
    background: #e3f2fd;
    color: #1565c0;
    border: 1px solid #90caf9;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.8em;
    cursor: pointer;
    transition: all 0.2s ease;
}
.wp-rag-chat-examples .wp-rag-chat-example:hover { 
    background: #bbdefb; 
    border-color: #64b5f6;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(21, 101, 192, 0.2);
}