/* Reset y configuración base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

/* Header */
header {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    font-weight: 700;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
    font-weight: 400;
}

/* Controles */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 30px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}

.input-group {
    display: flex;
    flex-direction: column;
    min-width: 200px;
    flex: 1;
}

.input-group label {
    font-weight: 600;
    margin-bottom: 8px;
    color: #495057;
    font-size: 0.9rem;
}

.input-group input {
    padding: 12px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.input-group input:focus {
    outline: none;
    border-color: #4facfe;
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.1);
}

/* Botones */
.buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    padding: 30px;
    justify-content: center;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
}

.btn.primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}

.btn.secondary {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.btn.secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(240, 147, 251, 0.3);
}

.btn.tertiary {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
}

.btn.tertiary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(79, 172, 254, 0.3);
}

.btn.info {
    background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
    color: white;
}

.btn.info:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(67, 233, 123, 0.3);
}

/* Explicación matemática */
.explanation {
    margin: 30px;
    padding: 25px;
    background: #e8f4f8;
    border-radius: 10px;
    border-left: 5px solid #4facfe;
    transition: all 0.3s ease;
}

.explanation.hidden {
    display: none;
}

.explanation h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.formula {
    background: white;
    padding: 15px;
    border-radius: 8px;
    margin: 15px 0;
    border: 1px solid #ddd;
}

.formula code {
    background: #f1f3f4;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    color: #d63384;
}

.explanation ul {
    margin: 15px 0;
    padding-left: 20px;
}

.explanation li {
    margin: 8px 0;
}

/* Resultados */
.results {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
    padding: 30px;
}

.result-section.full-width {
    grid-column: 1 / -1;
}

/* Estadísticas avanzadas */
.advanced-stats {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
    padding: 30px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
}

.stat-section {
    background: white;
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.stat-section h3 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-size: 1.3rem;
    border-bottom: 2px solid #4facfe;
    padding-bottom: 10px;
}

.result-section h3 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-size: 1.3rem;
    border-bottom: 2px solid #4facfe;
    padding-bottom: 10px;
}

/* Tabla de resultados */
.table-container {
    overflow-x: auto;
    border-radius: 10px;
    border: 1px solid #e9ecef;
}

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

.results-table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 10px;
    text-align: center;
    font-weight: 600;
    font-size: 0.8rem;
}

.results-table td {
    padding: 12px 10px;
    text-align: center;
    border-bottom: 1px solid #e9ecef;
}

.results-table tr:nth-child(even) {
    background: #f8f9fa;
}

.results-table tr:hover {
    background: #e3f2fd;
}

.top-candidate {
    background: #d4edda !important;
    border-left: 4px solid #28a745;
}

.bottom-candidate {
    background: #f8d7da !important;
    border-left: 4px solid #dc3545;
}

.score-total {
    font-weight: 700;
    color: #495057;
}

/* JSON Output */
.json-output {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 20px;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    color: #495057;
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
}

/* Estadísticas */
.stats {
    padding: 30px;
    background: #f8f9fa;
}

.stats h3 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-size: 1.3rem;
    text-align: center;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border-left: 4px solid #4facfe;
}

.stat-card h4 {
    color: #2c3e50;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.stat-card p {
    margin: 8px 0;
    color: #495057;
}

.seed-info {
    text-align: center;
    padding: 15px;
    background: white;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

/* Mensajes de estado */
.no-data {
    text-align: center;
    color: #6c757d;
    font-style: italic;
    padding: 40px;
}

/* Inputs adicionales */
.help-text {
    font-size: 0.8rem;
    color: #6c757d;
    margin-top: 4px;
    font-style: italic;
}

.input-group select {
    padding: 12px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
    background: white;
}

.input-group select:focus {
    outline: none;
    border-color: #4facfe;
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.1);
}

/* Estadísticas globales */
.stats-overview {
    margin-bottom: 25px;
}

.stat-summary h4 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
}

.summary-item {
    display: flex;
    flex-direction: column;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #4facfe;
}

.summary-item .label {
    font-size: 0.85rem;
    color: #6c757d;
    margin-bottom: 4px;
}

.summary-item .value {
    font-weight: 600;
    color: #2c3e50;
    font-size: 1.1rem;
}

/* Tabla de estadísticas */
.stat-table-container {
    overflow-x: auto;
    margin: 20px 0;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    overflow: hidden;
}

.stats-table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 8px;
    text-align: center;
    font-weight: 600;
    font-size: 0.8rem;
}

.stats-table td {
    padding: 12px 8px;
    text-align: center;
    border-bottom: 1px solid #e9ecef;
}

.stats-table .variable-name {
    font-weight: 600;
    text-align: left;
    background: #f8f9fa;
}

.stats-table .highlighted-row {
    background: #e3f2fd;
    font-weight: 500;
}

.stats-table tr:hover {
    background: #e8f4f8;
}

/* Covarianzas */
.covariance-info {
    margin-top: 25px;
    padding: 20px;
    background: #f1f8ff;
    border-radius: 8px;
    border: 1px solid #e1ecf4;
}

.covariance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.cov-item {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    background: white;
    border-radius: 6px;
    border: 1px solid #d1ecf1;
}

.cov-label {
    font-weight: 500;
    color: #495057;
}

.cov-value {
    font-family: 'Courier New', monospace;
    color: #2c3e50;
    font-weight: 600;
}

/* Descomposición de varianza */
.variance-breakdown {
    space-y: 25px;
}

.formula-section {
    margin-bottom: 25px;
}

.formula-display {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #28a745;
    margin: 15px 0;
}

.formula-display code {
    background: transparent;
    color: #495057;
    font-size: 0.9rem;
    line-height: 1.6;
}

.variance-comparison {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin: 25px 0;
}

.variance-item {
    text-align: center;
    padding: 20px;
    background: #e8f4f8;
    border-radius: 10px;
    border: 2px solid #4facfe;
}

.variance-item h5 {
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 0.9rem;
}

.variance-value {
    font-family: 'Courier New', monospace;
    font-size: 1.2rem;
    font-weight: 700;
    color: #495057;
}

/* Barras de contribución */
.contribution-analysis {
    margin-top: 25px;
}

.contribution-bars {
    space-y: 15px;
}

.contribution-item {
    margin-bottom: 15px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.contrib-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.contrib-name {
    font-weight: 600;
    color: #2c3e50;
}

.contrib-percent {
    font-weight: 700;
    color: #495057;
}

.contrib-bar {
    height: 20px;
    background: #e9ecef;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 5px;
}

.contrib-fill {
    height: 100%;
    transition: width 0.8s ease;
    border-radius: 10px;
}

.contrib-fill.trabajo {
    background: linear-gradient(135deg, #28a745, #20c997);
}

.contrib-fill.suerte {
    background: linear-gradient(135deg, #ffc107, #fd7e14);
}

.contrib-fill.covarianza {
    background: linear-gradient(135deg, #6f42c1, #e83e8c);
}

.contrib-absolute {
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    color: #6c757d;
    text-align: right;
}

/* Análisis de sensibilidad */
.sensitivity-analysis {
    space-y: 25px;
}

.sensitivity-explanation {
    margin-bottom: 25px;
    padding: 20px;
    background: #fff3cd;
    border-radius: 8px;
    border: 1px solid #ffeaa7;
}

.sensitivity-explanation p {
    color: #495057;
    margin: 15px 0;
    line-height: 1.6;
}

.probability-table {
    overflow-x: auto;
    margin: 25px 0;
}

.sensitivity-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    overflow: hidden;
}

.sensitivity-table th {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    padding: 15px 10px;
    text-align: center;
    font-weight: 600;
}

.sensitivity-table td {
    padding: 12px 10px;
    text-align: center;
    border-bottom: 1px solid #e9ecef;
}

.sensitivity-table .percentage {
    font-weight: 700;
    color: #e83e8c;
}

.sensitivity-table .interpretation {
    font-weight: 500;
}

.sensitivity-insights {
    margin-top: 25px;
    padding: 20px;
    background: #d1ecf1;
    border-radius: 8px;
    border: 1px solid #bee5eb;
}

.insights-list {
    list-style: none;
    padding: 0;
}

.insights-list li {
    margin: 12px 0;
    padding: 12px;
    background: white;
    border-radius: 6px;
    border-left: 4px solid #17a2b8;
    line-height: 1.5;
}

/* Indicador de carga */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-content {
    background: white;
    padding: 40px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #4facfe;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

.loading-detail {
    font-size: 0.9rem;
    color: #6c757d;
    margin-top: 10px;
}

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

/* Recomendaciones técnicas */
.technical-recommendations {
    margin: 25px 0;
    padding: 20px;
    background: #e8f5e8;
    border-radius: 8px;
    border: 1px solid #c3e6c3;
}

.recommendations-list {
    list-style: none;
    padding: 0;
}

.recommendations-list li {
    margin: 8px 0;
    padding: 8px;
    background: white;
    border-radius: 4px;
    border-left: 3px solid #28a745;
}

.explanations {
    margin: 25px 0;
    padding: 20px;
    background: #f0f8ff;
    border-radius: 8px;
    border: 1px solid #d1ecf1;
}

.explanations-content p {
    margin: 15px 0;
    line-height: 1.6;
    color: #495057;
}

/* Responsivo */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    header h1 {
        font-size: 2rem;
    }

    .controls {
        flex-direction: column;
        padding: 20px;
    }

    .buttons {
        flex-direction: column;
        padding: 20px;
    }

    .btn {
        width: 100%;
        margin: 5px 0;
    }

    .results {
        padding: 20px;
    }

    .advanced-stats {
        padding: 20px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .results-table {
        font-size: 0.8rem;
    }

    .results-table th,
    .results-table td {
        padding: 8px 6px;
    }

    .stats-table {
        font-size: 0.75rem;
    }

    .stats-table th,
    .stats-table td {
        padding: 8px 4px;
    }

    .summary-grid {
        grid-template-columns: 1fr;
    }

    .variance-comparison {
        grid-template-columns: 1fr;
    }

    .covariance-grid {
        grid-template-columns: 1fr;
    }

    .sensitivity-table {
        font-size: 0.8rem;
    }

    .loading-content {
        padding: 20px;
        margin: 20px;
    }
}

@media (max-width: 480px) {
    header {
        padding: 20px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .results-table {
        font-size: 0.7rem;
    }

    .stats-table {
        font-size: 0.7rem;
    }

    .sensitivity-table {
        font-size: 0.7rem;
    }

    .json-output {
        font-size: 0.7rem;
    }

    .formula-display code {
        font-size: 0.75rem;
    }

    .contrib-label {
        flex-direction: column;
        align-items: flex-start;
    }

    .insights-list li {
        font-size: 0.9rem;
    }
}

/* Animaciones */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.results,
.advanced-stats,
.stats,
.explanation {
    animation: fadeIn 0.5s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(-20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.contribution-item {
    animation: slideIn 0.6s ease-out;
}

.insights-list li {
    animation: fadeIn 0.7s ease-out;
}