/**
 * Test Result Viewer — Shared CSS
 *
 * Styles for the TestResultViewer component used by both
 * test-runner.html and test-suites.html.
 *
 * Covers: result banner, summary grid, expandable table,
 * conversation items, status badges, transcript panel,
 * message bubbles, and error banners.
 */

/* ── Status Badges ── */
.tr-status-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
}
.tr-status-badge.running { background: #dbeafe; color: #1d4ed8; }
.tr-status-badge.completed { background: #dcfce7; color: #166534; }
.tr-status-badge.failed { background: #fee2e2; color: #991b1b; }
.tr-status-badge.cancelled { background: #fef3c7; color: #92400e; }
.tr-status-badge.pending { background: #f3f4f6; color: #4b5563; }
.tr-status-badge.passed { background: #dcfce7; color: #166534; }
.tr-status-badge.error { background: #fee2e2; color: #991b1b; }
.tr-status-badge.in_progress { background: #dbeafe; color: #1d4ed8; }
.tr-status-badge.max_turns_exceeded { background: #fef3c7; color: #92400e; }

@keyframes tr-badge-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}
.tr-status-badge.running,
.tr-status-badge.in_progress { animation: tr-badge-pulse 1.5s ease-in-out infinite; }

/* ── Message Bubbles ── */
.tr-msg-wrapper { display: flex; flex-direction: column; }
.tr-msg-wrapper.user { align-items: flex-start; }
.tr-msg-wrapper.agent { align-items: flex-end; }

.tr-msg-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 0.2rem;
}
.tr-msg {
    max-width: 85%;
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.4;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.tr-msg.mock-user {
    background: #e2e8f0;
    color: #1e293b;
    border-bottom-left-radius: 4px;
}
.tr-msg.agent {
    background: #2563eb;
    color: white;
    border-bottom-right-radius: 4px;
}
.tr-msg-wrapper.greeting { align-items: center; }
.tr-msg.greeting {
    background: #f0f9ff;
    color: #475569;
    border: 1px dashed #94a3b8;
    font-style: italic;
    font-size: 0.8rem;
}
.tr-msg-wrapper.transcript-source { align-items: center; }
.tr-msg.transcript-source {
    background: #faf5ff;
    color: #6b21a8;
    border: 1px dashed #c084fc;
    font-style: italic;
    font-size: 0.8rem;
}
.tr-msg-wrapper.response-id-source { align-items: center; }
.tr-msg.response-id-source {
    background: #fffbeb;
    color: #92400e;
    border: 1px dashed #f59e0b;
    font-style: italic;
    font-size: 0.8rem;
}
.tr-msg-time {
    font-size: 0.65rem;
    color: var(--color-text-muted);
    margin-top: 0.15rem;
}

/* ── Error Banner ── */
.tr-error-banner {
    margin: 0.75rem 0;
    padding: 0.6rem 0.8rem;
    border-left: 4px solid var(--color-error, #991b1b);
    background: #fee2e2;
    color: #991b1b;
    border-radius: 4px;
    font-size: 0.8rem;
}
.tr-error-banner strong {
    display: block;
    margin-bottom: 0.2rem;
}

/* ── View Transcript Button ── */
.tr-view-transcript-btn {
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
    flex-shrink: 0;
}

/* ── Transcript Slide-Out Panel ── */
.tr-transcript-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 1100;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}
.tr-transcript-overlay.open {
    opacity: 1;
    visibility: visible;
}
.tr-transcript-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(550px, 90vw);
    background: white;
    z-index: 1101;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    transition: transform 0.25s ease;
}
.tr-transcript-panel.open {
    transform: translateX(0);
}
.tr-transcript-panel-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-shrink: 0;
}
.tr-transcript-header-info h3 {
    margin: 0 0 0.25rem 0;
    font-size: 1rem;
}
.tr-transcript-header-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    flex-wrap: wrap;
}
.tr-transcript-close-btn {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--color-text-muted);
    padding: 0 0.25rem;
    line-height: 1;
}
.tr-transcript-close-btn:hover {
    color: var(--color-text);
}
.tr-transcript-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: #fafbfc;
}
.tr-transcript-panel-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--color-border);
    font-size: 0.8rem;
    color: var(--color-text-muted);
    flex-shrink: 0;
    background: white;
}
.tr-transcript-footer-stats {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}
.tr-transcript-graders {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--color-border);
}
.tr-transcript-view-toggle {
    display: inline-flex;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    border: 1px solid var(--color-border, #dee2e6);
    border-radius: 3px;
    background: var(--color-bg, #fff);
    cursor: pointer;
    transition: all 0.15s;
}
.tr-transcript-view-toggle:hover {
    border-color: var(--color-primary, #4a90d9);
    color: var(--color-primary, #4a90d9);
}
.tr-transcript-view-toggle.active {
    background: var(--color-primary, #4a90d9);
    color: white;
    border-color: var(--color-primary, #4a90d9);
}
.tr-raw-json {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #1e293b;
    color: #e2e8f0;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.75rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    display: none;
}
.tr-raw-json.visible { display: block; }
.tr-transcript-messages.hidden { display: none; }
.tr-transcript-footer-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
}
.tr-copy-btn {
    padding: 0.2rem 0.5rem;
    font-size: 0.7rem;
    border: 1px solid var(--color-border, #dee2e6);
    border-radius: 3px;
    background: var(--color-bg, #fff);
    cursor: pointer;
}
.tr-copy-btn:hover { border-color: var(--color-primary, #4a90d9); }
.tr-transcript-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--color-text-muted);
}

/* ── Results View ── */
.tr-result-banner {
    padding: 1rem 1.25rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.1rem;
    font-weight: 600;
}
.tr-result-banner.pass {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #86efac;
}
.tr-result-banner.fail {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}
.tr-result-summary {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.tr-summary-stat {
    padding: 0.75rem;
    background: var(--color-bg-secondary, #f8f9fa);
    border-radius: 6px;
    text-align: center;
}
.tr-summary-stat .label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-bottom: 0.25rem;
}
.tr-summary-stat .value { font-size: 1.2rem; font-weight: 700; }

/* ── Results Table ── */
.trv-table-section {
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}
.trv-table-section h3 {
    margin: 0 0 1rem 0;
    font-size: 1rem;
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 0.5rem;
}
.tr-summary-table { width: 100%; margin-bottom: 1.5rem; }
.tr-summary-table th {
    text-align: left;
    padding: 0.6rem 0.5rem;
    border-bottom: 2px solid var(--color-border);
    font-size: 0.85rem;
    color: var(--color-text-muted);
}
.tr-summary-table td {
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--color-border);
}

/* ── Expandable Rows ── */
.tr-expandable-header {
    cursor: pointer;
    user-select: none;
}
.tr-expandable-header:hover { background: var(--color-bg-secondary, #f8f9fa); }
.tr-expand-icon {
    display: inline-block;
    transition: transform 0.2s;
    margin-right: 0.5rem;
    font-size: 0.75rem;
}
.tr-expand-icon.open { transform: rotate(90deg); }
.tr-detail-row { display: none; }
.tr-detail-row.open { display: table-row; }
.tr-detail-cell { padding: 0.5rem 0.5rem 0.5rem 2rem; }

/* ── Conversation Items ── */
.tr-conversation-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.tr-conversation-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: var(--color-bg-secondary, #f8f9fa);
    border-radius: 4px;
    font-size: 0.85rem;
}
.tr-conversation-item .run-label { font-weight: 600; }
.tr-conversation-item .score { font-family: monospace; }
.tr-conversation-item .reason {
    color: var(--color-text-muted);
    font-size: 0.8rem;
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Result Actions ── */
.tr-result-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}
