/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

/* Header */
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* Tool Description */
.tool-description {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1.5rem;
    text-align: center;
    margin-bottom: 2rem;
}

.description-content {
    max-width: 800px;
    margin: 0 auto;
}

.description-content p {
    font-size: 1.2rem;
    line-height: 1.6;
    margin: 0;
    font-weight: 500;
}

/* Performance Metrics Explanation */
.metrics-explanation {
    background: white;
    padding: 2rem;
    margin-bottom: 2rem;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}

.metrics-content h2 {
    color: #667eea;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    border-bottom: 2px solid #667eea;
    padding-bottom: 0.5rem;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.metric-item {
    background: #f8f9fa;
    padding: 1.5rem;
    border-radius: 8px;
    border-left: 4px solid #667eea;
    transition: all 0.3s ease;
}

.metric-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.metric-item h3 {
    color: #667eea;
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.8rem;
}

.metric-item p {
    color: #666;
    line-height: 1.6;
    margin: 0;
    font-size: 0.95rem;
}

@media (max-width: 768px) {
    .metrics-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .metrics-explanation {
        padding: 1rem;
    }
}

nav {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h1 {
    font-size: 1.8rem;
    font-weight: 600;
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.github-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    text-decoration: none;
    border-radius: 5px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.github-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.github-btn svg {
    flex-shrink: 0;
}

.language-selector select {
    padding: 0.5rem;
    border: none;
    border-radius: 5px;
    background: white;
    color: #333;
    font-size: 0.9rem;
    cursor: pointer;
}

/* Main content */
main {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 2rem;
}

.config-section, .results-section {
    background: white;
    padding: 2rem;
    margin-bottom: 2rem;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

h2 {
    color: #667eea;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    border-bottom: 2px solid #667eea;
    padding-bottom: 0.5rem;
}

/* Form styles */
.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #555;
}

input, select, textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e1e5e9;
    border-radius: 5px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

/* Button */
#startTest {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.1rem;
    border-radius: 5px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    font-weight: 600;
}

#startTest:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

#startTest:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Table styles */
.table-container {
    overflow-x: auto;
    overflow-y: visible;
    border-radius: 5px;
    border: 1px solid #e1e5e9;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid #e1e5e9;
}

th {
    background: #f8f9fa;
    font-weight: 600;
    color: #555;
    position: sticky;
    top: 0;
    z-index: 10;
    overflow: visible;
}

tr:hover {
    background: #f8f9fa;
}

/* Status indicators */
.status-testing {
    color: #ffa500;
    font-weight: 600;
}

.status-completed {
    color: #28a745;
    font-weight: 600;
}

.status-failed {
    color: #dc3545;
    font-weight: 600;
}

/* Result cell */
.result-cell {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    position: relative;
}

.result-cell:hover {
    background: #e9ecef;
}

.result-tooltip {
    position: absolute;
    background: #333;
    color: white;
    padding: 0.5rem;
    border-radius: 5px;
    font-size: 0.8rem;
    max-width: 300px;
    z-index: 1000;
    display: none;
    word-wrap: break-word;
    white-space: normal;
}

/* Error cell */
.error-cell {
    color: #dc3545;
    font-size: 0.9rem;
}

/* Loading animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Results header */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.toggle-viewer-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.toggle-viewer-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* Real-time Viewer */
.realtime-viewer {
    position: fixed;
    top: 0;
    right: 0;
    width: 400px;
    height: 100vh;
    background: white;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.realtime-viewer.visible {
    transform: translateX(0);
}

.hidden {
    display: none !important;
}

/* Statistics and History Section Styles */
.history-controls {
    display: flex;
    gap: 1rem;
    margin-left: auto;
}

.history-container {
    margin-top: 1rem;
}

.history-empty {
    text-align: center;
    padding: 2rem;
    color: #666;
    font-style: italic;
}

.history-record {
    background: white;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.history-header {
    background: #f8f9fa;
    padding: 1rem;
    border-bottom: 1px solid #e1e5e9;
}

.history-header h3 {
    margin: 0 0 0.5rem 0;
    color: #333;
    font-size: 1.1rem;
}

.history-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.9rem;
    color: #666;
}

.history-meta span {
    display: flex;
    align-items: center;
}

.history-meta strong {
    color: #333;
    margin-right: 0.5rem;
}

.history-summary {
    padding: 1rem;
    background: #f8f9fa;
    border-bottom: 1px solid #e1e5e9;
}

.summary-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    font-size: 0.9rem;
}

.summary-stats span {
    display: flex;
    align-items: center;
}

.summary-stats strong {
    color: #333;
    margin-right: 0.5rem;
}

.history-details {
    padding: 1rem;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.history-table th,
.history-table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid #e1e5e9;
}

.history-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #333;
}

.history-table tr:hover {
    background: #f8f9fa;
}

/* Responsive design for history */
@media (max-width: 768px) {
    .history-meta {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .summary-stats {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .history-controls {
        flex-direction: column;
        margin-left: 0;
        margin-top: 1rem;
    }
    
    .history-table {
        font-size: 0.8rem;
    }
    
    .history-table th,
    .history-table td {
        padding: 0.3rem;
    }
}

.realtime-viewer.hidden {
    transform: translateX(100%);
}

.viewer-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.viewer-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.close-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.viewer-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.current-test-info {
    padding: 1rem;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}

.test-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.test-model {
    background: #667eea;
    color: white;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-weight: 500;
}

.test-round {
    background: #f8f9fa;
    color: #495057;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

.test-status {
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-weight: 500;
}

.test-status.testing {
    background: #fff3cd;
    color: #856404;
}

.test-status.completed {
    background: #d4edda;
    color: #155724;
}

.test-status.failed {
    background: #f8d7da;
    color: #721c24;
}

.test-separator {
    color: #ccc;
}

.test-prompt {
    font-size: 0.85rem;
    color: #666;
    background: #f8f9fa;
    padding: 0.5rem;
    border-radius: 4px;
    border-left: 3px solid #667eea;
}

.result-display {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    position: relative;
    background: #fafafa;
}

.result-text {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: #333;
    min-height: 100px;
}

.result-cursor {
    display: inline-block;
    width: 2px;
    height: 1.2em;
    background: #667eea;
    animation: blink 1s infinite;
    margin-left: 2px;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.viewer-stats {
    padding: 1rem;
    background: #f8f9fa;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: space-around;
    flex-shrink: 0;
}

.stat-item {
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 0.2rem;
}

.stat-value {
    display: block;
    font-weight: 600;
    color: #333;
    font-size: 0.9rem;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem;
    color: #666;
    background: white;
    margin-top: 2rem;
}

/* RTL support for Arabic */
[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] nav {
    flex-direction: row-reverse;
}

[dir="rtl"] .language-selector {
    margin-right: auto;
    margin-left: 0;
}

/* Responsive design */
/* Statistics Section */
.statistics-section {
    margin-top: 2rem;
}

.statistics-section .section-header {
    background: #f8f9fa;
    color: #333;
    padding: 1.5rem;
    margin: 0 0 1rem 0;
    border-radius: 5px;
    border: 1px solid #e1e5e9;
}

.statistics-section .section-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.statistics-table-container {
    overflow-x: auto;
    border-radius: 5px;
    border: 1px solid #e1e5e9;
}

#statisticsTable {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

#statisticsTable th {
    background: #f8f9fa;
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: #555;
    border-bottom: 1px solid #e1e5e9;
    position: sticky;
    top: 0;
    z-index: 10;
}

#statisticsTable td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid #e1e5e9;
}

#statisticsTable tbody tr:hover {
    background: #f8f9fa;
}

.stats-success-rate {
    font-weight: 600;
}

.stats-success-rate.high {
    color: #28a745;
}

.stats-success-rate.medium {
    color: #ffc107;
}

.stats-success-rate.low {
    color: #dc3545;
}

/* View Result Button */
.view-result-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.3s ease;
    min-width: 80px;
}

.view-result-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

.view-result-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
    opacity: 0.6;
}

.view-result-btn.error-state {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
}

.view-result-btn.error-state:hover {
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.4);
}

.view-result-btn.testing-state {
    background: #6c757d;
    color: white;
    cursor: not-allowed;
    animation: pulse 2s infinite;
}

.view-result-btn.testing-state:hover {
    background: #6c757d;
    box-shadow: none;
    transform: none;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
    100% {
        opacity: 1;
    }
}

@media (max-width: 768px) {
    nav {
        flex-direction: column;
        gap: 1rem;
    }
    
    main {
        padding: 0 1rem;
    }
    
    .config-section, .results-section {
        padding: 1rem;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    th, td {
        padding: 0.5rem;
        font-size: 0.9rem;
    }
    
    .result-cell {
        max-width: 150px;
    }
    
    .realtime-viewer {
        width: 100%;
        right: -100%;
    }
    
    .realtime-viewer.visible {
        right: 0;
    }
    
    .viewer-content {
        padding: 1rem;
    }
    
    .view-result-btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.7rem;
        min-width: 60px;
    }
}

@media (max-width: 480px) {
    .table-container, .statistics-table-container {
        font-size: 0.8rem;
    }
    
    th, td {
        padding: 0.3rem;
    }
    
    .result-cell {
        max-width: 100px;
    }
    
    .statistics-section .section-header {
        padding: 1rem;
    }
    
    .statistics-section .section-header h2 {
        font-size: 1.2rem;
    }
}

/* Tooltip styles */
.tooltip-icon {
    margin-left: 5px;
    cursor: help;
    font-size: 0.8em;
    opacity: 0.7;
    transition: opacity 0.2s ease;
    position: relative;
}

.tooltip-icon:hover {
    opacity: 1;
}

/* .tooltip-icon:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    white-space: normal;
    max-width: 200px;
    width: max-content;
    z-index: 9999;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    word-wrap: break-word;
    margin-bottom: 5px;
}

.tooltip-icon:hover::before {
    content: '';
    position: absolute;
    bottom: 95%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #333;
    z-index: 9999;
} */