:root {
    /* Base Variables */
    --primary: #2c3e50;
    --secondary: #3498db;
    --accent: #e74c3c;
    --bg: #f4f7f6;
    --card-bg: #ffffff;
    --text: #333;

    /* Aliases/Compatibilidad para otros archivos */
    --primary-color: var(--primary);
    --accent-color: #27ae60;
    /* Usado en tablas como verde */
    --bg-color: var(--bg);
    --text-color: var(--text);
    --border-color: #ddd;

    /* Variables de Componentes (Comp) */
    --light: #f8f9fa;
    --border: #dee2e6;
    --win: #27ae60;
    --draw: #f39c12;
    --loss: #c0392b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    /* Changed to 0 for full-width footer */
}

.container {
    max-width: 1200px;
    margin: 20px auto;
    /* Added top/bottom margin */
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

header {
    text-align: center;
    margin-bottom: 30px;
}

h1 {
    color: var(--primary);
    text-align: center;
    margin-bottom: 30px;
}

/* --- Enlaces Generales --- */
a {
    text-decoration: none;
    color: var(--primary);
}

a:hover {
    text-decoration: none;
    color: var(--secondary);
}

a.team-link {
    color: var(--primary);
    font-weight: bold;
    border-bottom: 1px dashed var(--primary);
}

a.team-link:hover {
    text-decoration: underline;
    color: var(--accent-color);
    border-color: var(--accent-color);
}

/* =========================================
   COMPONENTE: FILTROS Y CONTROLES
   ========================================= */

/* Estilo General (equipo.html) */
.filters-container {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-top: 15px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 150px;
}

.filter-group label {
    font-size: 0.85rem;
    font-weight: bold;
    margin-bottom: 5px;
    color: var(--primary);
}

/* Estilo General (clasifica.html) */
.controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px;
    background-color: #ecf0f1;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.control-group {
    display: flex;
    flex-direction: column;
}

.control-group label {
    font-size: 0.9em;
    font-weight: bold;
    margin-bottom: 5px;
    color: var(--primary);
}

/* Estilo Panel Complejo (comparacion.html) */
.controls-panel {
    background-color: var(--light);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 20px;
}

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

.form-group {
    display: flex;
    flex-direction: column;
}

/* Inputs Comunes */
select,
input[type="date"] {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
}

.main-select select {
    font-size: 1.2rem;
    border-color: var(--secondary);
}

/* =========================================
   COMPONENTE: BOTONES Y MODOS DE VISTA
   ========================================= */

.view-modes {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.view-btn {
    padding: 10px 20px;
    border: none;
    background-color: #bdc3c7;
    color: #333;
    cursor: pointer;
    border-radius: 20px;
    font-weight: bold;
    transition: background-color 0.3s;
}

.view-btn.active {
    background-color: var(--primary);
    color: white;
}

.view-btn:hover:not(.active) {
    background-color: #95a5a6;
}

/* Botones de Acción (Comp) */
.action-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

button.btn-main {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    color: white;
    transition: opacity 0.2s;
}

.btn-calc {
    background-color: var(--primary);
}

.btn-reset {
    background-color: var(--loss);
}

button.btn-main:hover {
    opacity: 0.9;
}

.btn-group {
    margin-top: 5px;
    display: flex;
    gap: 10px;
}

.btn-small {
    padding: 4px 8px;
    font-size: 12px;
    background: #e2e6ea;
    border: none;
    cursor: pointer;
    border-radius: 3px;
}

.btn-small:hover {
    background: #dbe2e8;
}

.btn-link {
    display: inline-block;
    margin-top: 15px;
    padding: 10px 20px;
    background-color: var(--primary);
    color: white;
    text-decoration: none;
    border-radius: 5px;
    text-align: center;
    font-weight: bold;
    transition: background-color 0.3s;
}

.btn-link:hover {
    background-color: var(--secondary);
}


/* =========================================
   COMPONENTE: TABLAS
   ========================================= */

.table-wrapper,
.table-responsive {
    overflow-x: auto;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
    font-size: 14px;
}

th,
td {
    padding: 12px 15px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: var(--primary);
    color: white;
    position: sticky;
    top: 0;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    z-index: 10;
}

th:hover {
    background-color: #34495e;
}

tr:nth-child(even) {
    background-color: #f9f9f9;
}

tr:hover {
    background-color: #e8f6f3;
}

/* Alineación texto izquierda */
td:nth-child(2),
th:nth-child(2) {
    text-align: left;
}

/* Indicadores de Ordenamiento (Flechas) */
th::after {
    content: '';
    position: absolute;
    right: 5px;
    font-size: 0.8em;
    opacity: 0.6;
}

th.sort-asc::after,
th.asc::after {
    content: '▲';
    opacity: 1;
}

th.sort-desc::after,
th.desc::after {
    content: '▼';
    opacity: 1;
}

.matches-table th {
    background-color: #f2f2f2;
    color: #333;
}

/* Resultados Colores */
.win,
.res-win,
.result-win {
    color: var(--win);
    font-weight: bold;
}

.loss,
.res-loss,
.result-loss {
    color: var(--loss);
    font-weight: bold;
}

.draw,
.res-draw,
.result-draw {
    color: var(--draw);
    font-weight: bold;
}

/* =========================================
   COMPONENTE: ESTADÍSTICAS Y CARDS
   ========================================= */

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

.stat-card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    border-left: 4px solid var(--secondary);
}

.stat-card h3 {
    margin-top: 0;
    font-size: 1rem;
    color: #7f8c8d;
}

.stat-card p {
    font-size: 1.5rem;
    font-weight: bold;
    margin: 10px 0;
}

.stat-card small {
    display: block;
    color: #666;
    font-size: 0.9rem;
}

.best-result {
    border-left-color: #27ae60;
}

.worst-result {
    border-left-color: #e74c3c;
}

.result-list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.85rem;
}

.result-list li {
    padding: 4px 0;
    border-bottom: 1px solid #f1f1f1;
}

/* =========================================
   COMPONENTE: MODAL
   ========================================= */

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 20px;
    border: 1px solid #888;
    width: 90%;
    max-width: 800px;
    border-radius: 8px;
    position: relative;
    max-height: 80vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.close-modal {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    align-self: flex-end;
}

.close-modal:hover {
    color: black;
}

.modal-title {
    color: var(--primary);
    margin-top: 0;
    border-bottom: 2px solid var(--accent-color);
    padding-bottom: 10px;
}

/* =========================================
   ESPECÍFICOS: INDEX / HOME
   ========================================= */

.hero-section {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 20px 30px;
    background: linear-gradient(135deg, #ecf0f1 0%, #d6eaf8 100%);
    color: #2c3e50;
    border: 1px solid #d4e6f1;
    border-radius: 8px;
    margin-bottom: 30px;
    gap: 10px;
}

.hero-top {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 20px;
    width: 100%;
}

.banner-logo {
    max-height: 80px;
    width: auto;
    flex-shrink: 0;
}

.hero-section h1 {
    margin: 0;
    font-size: 1.8rem;
    color: #2c3e50;
}

.hero-section h1 a {
    text-decoration: none;
    color: inherit;
    transition: color 0.3s;
}

.hero-section h1 a:hover {
    color: var(--secondary);
}

.hero-section p {
    font-size: 1rem;
    color: #555;
    margin: 0;
    width: 100%;
}

/* Specific styles for data.html consistency */
.prediction-section {
    background-color: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: 30px;
}

.controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    .controls-grid {
        grid-template-columns: 1fr;
    }

    .results-container {
        grid-template-columns: 1fr !important;
        /* Force stack on mobile */
    }
}

.action-btn {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 1.1rem;
    border-radius: 6px;
    cursor: pointer;
    width: 100%;
    transition: background-color 0.3s;
    font-weight: bold;
}

.action-btn:disabled {
    background-color: #bdc3c7;
    cursor: not-allowed;
}

.action-btn:hover:not(:disabled) {
    background-color: #2980b9;
}

.error-msg {
    color: #c0392b;
    font-weight: bold;
    text-align: center;
    margin-top: 10px;
    display: none;
    padding: 10px;
    background-color: #fadbd8;
    border-radius: 4px;
}

.results-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 30px;
    display: none;
}

.result-card {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    border-left: 5px solid var(--accent);
    text-align: center;
}

.result-card h3 {
    margin-top: 0;
    color: var(--primary);
    font-size: 1.1rem;
}

.winner-name {
    font-size: 1.8rem;
    color: var(--primary);
    font-weight: bold;
    margin: 15px 0;
}

.status-badge {
    display: inline-block;
    padding: 8px 15px;
    border-radius: 20px;
    font-weight: bold;
    margin-top: 10px;
}

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

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

.methodology-section {
    background-color: #f1f3f5;
    padding: 20px;
    border-radius: 8px;
    margin-top: 40px;
    font-size: 0.95rem;
    color: #333;
}

.methodology-section h3 {
    border-bottom: 2px solid #ddd;
    padding-bottom: 10px;
    margin-top: 0;
}

.formula-box {
    background: white;
    padding: 15px;
    border-radius: 4px;
    margin: 15px 0;
    overflow-x: auto;
    text-align: center;
}

/* Scenarios List */
.scenarios-list {
    list-style: none;
    padding: 0;
    margin: 15px 0 0 0;
    text-align: left;
}

.scenario-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #eee;
}

.scenario-item:last-child {
    border-bottom: none;
}

.scenario-label {
    font-weight: bold;
    color: #555;
    display: flex;
    align-items: center;
    gap: 8px;
}

.scenario-result {
    text-align: right;
}

.prob-bar-bg {
    width: 80px;
    height: 6px;
    background: #eee;
    border-radius: 3px;
    margin-top: 5px;
    overflow: hidden;
}

.prob-bar-fill {
    height: 100%;
    background: var(--primary);
}

/* New Styles for History Table */
.history-section {
    margin-top: 30px;
    overflow-x: auto;
}

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

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

.history-table th {
    background-color: #e9ecef;
    font-weight: bold;
    color: var(--primary);
}

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

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

.file-card {
    background: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
    border-top: 5px solid var(--secondary);
    display: flex;
    flex-direction: column;
}

.file-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.15);
}

.file-card h3 {
    margin-top: 0;
    color: var(--primary);
}

.file-card p {
    flex-grow: 1;
    color: #555;
    line-height: 1.5;
}

.quick-stats-section {
    margin-bottom: 40px;
}

.quick-stats-section h2 {
    text-align: center;
    color: var(--primary);
    margin-bottom: 30px;
    position: relative;
    display: inline-block;
    left: 50%;
    transform: translateX(-50%);
}

.quick-stats-section h2::after {
    content: '';
    display: block;
    width: 50px;
    height: 3px;
    background: var(--accent);
    margin: 10px auto 0;
}

.tables-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 25px;
}

.stat-box {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    /* Remove horizontal overflow here if not needed */
    display: flex;
    flex-direction: column;
}

.stat-box h3 {
    background-color: var(--secondary);
    color: white;
    margin: 0;
    padding: 15px;
    text-align: center;
    font-size: 1.1rem;
}

.stat-box-content {
    padding: 0;
    /* Removed max-height to let it grow vertically as requested */
    overflow-y: visible;
}

/* Ajustes tabla mini en home */
.stat-box table {
    width: 100%;
    min-width: 0;
    font-size: 0.85rem;
    border-collapse: collapse;
}

.stat-box th,
.stat-box td {
    padding: 8px 10px;
    border-bottom: 1px solid #eee;
}

/* Columna 1 y 3: Lo mínimo necesario y sin saltos */
.stat-box th:first-child,
.stat-box td:first-child,
.stat-box th:last-child,
.stat-box td:last-child {
    width: 1%;
    white-space: nowrap;
}

.stat-box td:last-child {
    text-align: right;
    font-weight: bold;
    color: var(--primary);
}

/* Columna 2: Flexible y con saltos */
.stat-box th:nth-child(2),
.stat-box td:nth-child(2) {
    white-space: normal;
    word-break: break-word;
    text-align: left;
}

/* =========================================
   COMPONENTE: FOOTER UNIVERSAL (Responsive)
   ========================================= */

.main-footer {
    background-color: #000;
    color: #95a5a6;
    padding: 40px 0 20px 0;
    margin-top: 50px;
    width: 100%;
    font-family: inherit;
}

.footer-container {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 30px;
    padding: 0 20px;
}

.footer-col h3 {
    color: #afbabb;
    border-bottom: 1px solid var(--accent, #3498db);
    padding-bottom: 10px;
    margin-bottom: 20px;
    font-size: 1.2rem;
}

.footer-col p,
.footer-col ul {
    margin: 0 0 10px 0;
    font-size: 0.95rem;
    line-height: 1.6;
}

.footer-col ul {
    list-style: none;
    padding: 0;
}

.footer-col ul li {
    margin-bottom: 10px;
}

.footer-col a {
    color: #afbabb;
    text-decoration: none;
    transition: color 0.3s;
}

.footer-col a:hover {
    color: var(--secondary, #3498db);
}

.footer-bottom {
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #333;
    font-size: 0.85rem;
    opacity: 0.7;
    color: #afbabb;
}

/* Responsividad para móviles */
@media (max-width: 768px) {
    .footer-container {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .footer-col h3 {
        display: inline-block;
    }
}

/* =========================================
   ESPECÍFICOS: COMPARATIVA
   ========================================= */

.team-selector-container {
    grid-column: 1 / -1;
    margin-top: 15px;
}

.team-selector-box {
    border: 1px solid #ccc;
    height: 150px;
    overflow-y: scroll;
    padding: 10px;
    background: white;
    border-radius: 4px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 5px;
}

.team-check-item {
    display: flex;
    align-items: center;
    font-size: 13px;
}

.tabs {
    display: flex;
    margin-bottom: 0;
    border-bottom: 2px solid var(--border);
}

.tab {
    padding: 10px 20px;
    cursor: pointer;
    background: #e9ecef;
    border: 1px solid var(--border);
    border-bottom: none;
    margin-right: 5px;
    border-radius: 5px 5px 0 0;
    font-weight: 600;
}

.tab.active {
    background: white;
    color: var(--accent-color);
    border-bottom: 2px solid white;
    margin-bottom: -2px;
}

/* Loading y Errores */
#loading,
#loadingStats,
#loadingMsg {
    text-align: center;
    padding: 20px;
    font-size: 1.2em;
    color: var(--secondary);
}

.error {
    color: #c0392b;
    font-weight: bold;
}