/* =====================================================
   MxChat Admin Testing Tab Styles
   ===================================================== */

/* Two-column layout */
.mxch-testing-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}

/* Section titles inside cards */
.mxch-testing-section-title {
    margin: 0 0 16px 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--mxch-text-primary, #1a1a2e);
    display: flex;
    align-items: center;
    gap: 8px;
}

.mxch-testing-section-title::before {
    content: '';
    width: 4px;
    height: 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 2px;
    flex-shrink: 0;
}

/* Quick action buttons row */
.mxch-testing-actions-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.mxch-testing-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #fff;
}

.mxch-testing-btn-danger {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%);
    box-shadow: 0 2px 8px rgba(255, 107, 107, 0.3);
}

.mxch-testing-btn-danger:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4);
}

.mxch-testing-btn-secondary {
    background: linear-gradient(135deg, #64748b 0%, #475569 100%);
    box-shadow: 0 2px 8px rgba(100, 116, 139, 0.3);
}

.mxch-testing-btn-secondary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(100, 116, 139, 0.4);
}

/* Field labels + values */
.mxch-testing-field {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 14px 16px;
    margin-top: 12px;
    font-size: 13px;
    line-height: 1.5;
}

.mxch-testing-field label {
    color: var(--mxch-text-primary, #1e293b);
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mxch-testing-field code {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 3px 8px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 11px;
    font-weight: 600;
}

/* Query display */
.mxch-testing-query-display {
    font-style: italic;
    color: #64748b;
    background: #f8fafc;
    padding: 10px 14px;
    border-radius: 6px;
    border-left: 4px solid #667eea;
    font-weight: 500;
    margin-top: 4px;
}

/* No data placeholder */
.mxch-testing-no-data {
    color: #64748b;
    font-style: italic;
    padding: 16px;
    text-align: center;
    background: #f8fafc;
    border-radius: 6px;
}

/* Results containers */
.mxch-testing-results {
    max-height: 400px;
    overflow-y: auto;
    margin-top: 4px;
    border-radius: 8px;
}

/* System prompt display */
.mxch-testing-system-prompt {
    max-height: 150px;
    overflow-y: auto;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 12px;
    margin-top: 4px;
    font-size: 12px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    line-height: 1.5;
    color: #334155;
    word-break: break-word;
}

/* Debug console */
.mxch-testing-debug-console {
    max-height: 250px;
    overflow-y: auto;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 12px;
    font-size: 12px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    color: #e2e8f0;
}

.mxch-testing-debug-entry {
    margin-bottom: 4px;
    line-height: 1.5;
    word-break: break-word;
}

.mxch-testing-debug-timestamp {
    color: #64748b;
    font-weight: 500;
}

/* =====================================================
   Document Match Cards (reused from test-panel)
   ===================================================== */

.mxch-testing-results .matches-header {
    font-size: 13px;
    margin-bottom: 10px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 6px;
    border-left: 4px solid #667eea;
    font-weight: 600;
    color: #1e293b;
}

.mxch-testing-results .matches-subheader {
    font-size: 11px;
    font-weight: 400;
    color: #64748b;
    margin-left: 6px;
}

.mxch-testing-results .match-card {
    margin-bottom: 10px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    border: 1px solid #e2e8f0;
    transition: all 0.2s ease;
}

.mxch-testing-results .match-card:hover {
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
}

.mxch-testing-results .match-card.above-threshold {
    border-left: 4px solid #10b981;
    background: linear-gradient(135deg, #ecfdf5 0%, #f0fdf4 100%);
}

.mxch-testing-results .match-card.below-threshold {
    border-left: 4px solid #ef4444;
    background: linear-gradient(135deg, #fef2f2 0%, #fef7f7 100%);
}

.mxch-testing-results .match-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.mxch-testing-results .match-card.above-threshold .match-header {
    background: rgba(16, 185, 129, 0.08);
}

.mxch-testing-results .match-card.below-threshold .match-header {
    background: rgba(239, 68, 68, 0.08);
}

.mxch-testing-results .match-title {
    font-weight: 600;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.mxch-testing-results .status-icon {
    font-size: 13px;
}

.mxch-testing-results .match-card.above-threshold .status-icon {
    color: #10b981;
}

.mxch-testing-results .match-card.below-threshold .status-icon {
    color: #ef4444;
}

.mxch-testing-results .similarity-score {
    font-size: 15px;
    font-weight: 700;
}

.mxch-testing-results .match-card.above-threshold .similarity-score {
    color: #10b981;
}

.mxch-testing-results .match-card.below-threshold .similarity-score {
    color: #ef4444;
}

.mxch-testing-results .context-label {
    font-size: 10px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mxch-testing-results .match-card.above-threshold .context-label {
    color: #047857;
}

.mxch-testing-results .match-card.below-threshold .context-label {
    color: #dc2626;
}

.mxch-testing-results .match-source {
    padding: 10px 14px;
    font-size: 12px;
    color: #475569;
    line-height: 1.4;
    word-break: break-word;
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

.mxch-testing-results .source-icon {
    font-size: 13px;
    flex-shrink: 0;
}

.mxch-testing-results .chunk-summary {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    font-size: 10px;
    font-weight: 600;
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    color: #fff;
    border-radius: 10px;
    margin-left: 6px;
}

.mxch-testing-results .chunk-expand-toggle {
    display: block;
    padding: 6px 14px;
    font-size: 11px;
    font-weight: 600;
    color: #6366f1;
    cursor: pointer;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    transition: background 0.15s ease;
}

.mxch-testing-results .chunk-expand-toggle:hover {
    background: rgba(99, 102, 241, 0.08);
}

.mxch-testing-results .chunk-details {
    display: none;
    padding: 0 14px 10px 14px;
    background: rgba(0, 0, 0, 0.02);
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.mxch-testing-results .chunk-details.expanded {
    display: block;
}

.mxch-testing-results .chunk-detail-row {
    display: flex;
    align-items: center;
    padding: 5px 8px;
    margin: 3px 0;
    border-radius: 4px;
    font-size: 12px;
    gap: 8px;
}

.mxch-testing-results .chunk-detail-row.chunk-used {
    background: rgba(16, 185, 129, 0.1);
}

.mxch-testing-results .chunk-detail-row.chunk-not-used {
    background: rgba(100, 116, 139, 0.08);
}

.mxch-testing-results .chunk-detail-icon {
    font-size: 12px;
    width: 16px;
    text-align: center;
}

.mxch-testing-results .chunk-used .chunk-detail-icon {
    color: #10b981;
}

.mxch-testing-results .chunk-not-used .chunk-detail-icon {
    color: #94a3b8;
}

.mxch-testing-results .chunk-detail-num {
    font-weight: 600;
    color: #334155;
    flex: 1;
}

.mxch-testing-results .chunk-detail-score {
    font-weight: 600;
    color: #64748b;
}

/* =====================================================
   Action Cards
   ===================================================== */

.mxch-testing-results .actions-header {
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 12px;
}

.mxch-testing-results .action-card {
    margin-bottom: 4px;
    padding: 8px 10px;
    border-radius: 6px;
    border-left: 3px solid #ccc;
    background: white;
}

.mxch-testing-results .action-card.action-triggered {
    border-left-color: #28a745;
    background: #f8fff9;
}

.mxch-testing-results .action-card.action-above-threshold {
    border-left-color: #ffc107;
    background: #fffdf5;
}

.mxch-testing-results .action-card.action-below-threshold {
    border-left-color: #dc3545;
    background: #fff5f5;
}

.mxch-testing-results .action-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 3px;
}

.mxch-testing-results .action-icon {
    font-size: 12px;
    flex-shrink: 0;
}

.mxch-testing-results .action-name {
    font-weight: 600;
    font-size: 12px;
    color: #333;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mxch-testing-results .action-score {
    font-weight: bold;
    font-size: 11px;
    color: #333;
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 3px;
    flex-shrink: 0;
}

.mxch-testing-results .action-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 10px;
    color: #666;
    gap: 6px;
}

.mxch-testing-results .action-status {
    font-weight: 600;
    text-transform: uppercase;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 9px;
}

.mxch-testing-results .action-triggered .action-status {
    background: #28a745;
    color: white;
}

.mxch-testing-results .action-above-threshold .action-status {
    background: #ffc107;
    color: #333;
}

.mxch-testing-results .action-below-threshold .action-status {
    background: #dc3545;
    color: white;
}

.mxch-testing-results .action-threshold {
    font-size: 10px;
    color: #666;
}

/* Approved URLs */
.mxch-testing-results .urls-header {
    margin-bottom: 8px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 6px;
    border-left: 4px solid #667eea;
    font-size: 13px;
}

.mxch-testing-results .url-card {
    padding: 6px 10px;
    margin-bottom: 4px;
}

.mxch-testing-results .url-line {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.mxch-testing-results .url-link {
    color: #667eea;
    text-decoration: none;
    word-break: break-all;
}

.mxch-testing-results .url-link:hover {
    text-decoration: underline;
}

.mxch-testing-results .urls-note {
    padding: 8px 10px;
    font-size: 11px;
    color: #64748b;
    border-top: 1px solid #e2e8f0;
    margin-top: 4px;
}

/* Status text */
.mxch-testing-results .error-text {
    color: #ef4444;
    font-weight: 500;
}

.mxch-testing-results .success-text {
    color: #10b981;
    font-weight: 500;
}

/* =====================================================
   Chatbot Column - Scoped Overrides
   ===================================================== */

.mxch-testing-chatbot-column {
    position: sticky;
    top: 24px;
}

.mxch-testing-chatbot-scope {
    background: var(--mxch-card-bg, #ffffff);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--mxch-border, #e2e8f0);
}

/* Make the chatbot fill the container instead of floating */
.mxch-testing-chatbot-scope .mxchat-chatbot-wrapper {
    position: relative !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 600px !important;
    max-height: 600px !important;
    display: flex !important;
    flex-direction: column !important;
    border-radius: 12px !important;
    overflow: hidden !important;
    box-shadow: none !important;
    margin: 0 !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
    top: auto !important;
    z-index: auto !important;
}

/* Ensure chatbot container fills available space */
.mxch-testing-chatbot-scope .mxchat-chatbot {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

.mxch-testing-chatbot-scope .chat-container {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

.mxch-testing-chatbot-scope .chat-box {
    flex: 1 !important;
    overflow-y: auto !important;
    min-height: 0 !important;
}

/* Fix WordPress admin input overrides */
.mxch-testing-chatbot-scope .chat-input,
.mxch-testing-chatbot-scope textarea.chat-input {
    box-shadow: none !important;
    border: none !important;
    outline: none !important;
    background: transparent !important;
    min-height: auto !important;
    width: 100% !important;
}

.mxch-testing-chatbot-scope .send-button,
.mxch-testing-chatbot-scope button.send-button {
    box-shadow: none !important;
}

/* Hide floating button if rendered */
.mxch-testing-chatbot-scope .floating-chatbot-button {
    display: none !important;
}

/* Init loader positioning */
.mxch-testing-chatbot-scope .mxchat-init-loader {
    position: relative !important;
}

/* Ensure quick questions are visible */
.mxch-testing-chatbot-scope .mxchat-popular-questions {
    display: block !important;
}

.mxch-testing-chatbot-scope .mxchat-popular-questions-container {
    display: flex !important;
}

.mxch-testing-chatbot-scope .mxchat-popular-question {
    display: block !important;
}

/* Allow collapsed state to hide questions in testing tab */
.mxch-testing-chatbot-scope .mxchat-popular-questions.collapsed .mxchat-popular-question {
    display: none !important;
}

.mxch-testing-chatbot-scope .mxchat-popular-questions.collapsed .questions-collapse-btn {
    display: none !important;
}

/* =====================================================
   Scrollbar styling
   ===================================================== */

.mxch-testing-debug-console::-webkit-scrollbar,
.mxch-testing-results::-webkit-scrollbar,
.mxch-testing-system-prompt::-webkit-scrollbar {
    width: 5px;
}

.mxch-testing-debug-console::-webkit-scrollbar-track {
    background: #334155;
    border-radius: 3px;
}

.mxch-testing-results::-webkit-scrollbar-track,
.mxch-testing-system-prompt::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.mxch-testing-debug-console::-webkit-scrollbar-thumb {
    background: #64748b;
    border-radius: 3px;
}

.mxch-testing-results::-webkit-scrollbar-thumb,
.mxch-testing-system-prompt::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 3px;
}

/* =====================================================
   Responsive
   ===================================================== */

@media screen and (max-width: 1200px) {
    .mxch-testing-layout {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .mxch-testing-chatbot-column {
        position: relative;
        top: 0;
        order: -1; /* Chatbot first on smaller screens */
    }

    .mxch-testing-chatbot-scope .mxchat-chatbot-wrapper {
        height: 500px !important;
        max-height: 500px !important;
    }
}
