/* =========================================
   VARIABLES & RESET
   ========================================= */
:root {
    --primary: #1a4a3e;
    --primary-dark: #12332b;
    --secondary: #c5a059;
    --bg: #f4f6f9;
    --text: #333333;
    --text-muted: #666666;
    --white: #ffffff;
    --border: #e0e0e0;
    --shadow: 0 4px 6px rgba(0,0,0,0.05);
    --radius: 10px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding-bottom: 80px; /* Espacio para footer */
    font-size: 15px;
    line-height: 1.5;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 15px;
    width: 100%;
}

/* =========================================
   HEADER & NAV
   ========================================= */
.app-header {
    background: var(--primary);
    color: var(--white);
    padding: 15px 20px;
    display: flex;
    flex-wrap: wrap; /* Permite que el menú baje en móviles muy pequeños */
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-logo {
    font-weight: 800;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.app-nav {
    display: flex;
    gap: 15px;
    overflow-x: auto; /* Scroll si no cabe */
}

.app-nav a {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: color 0.2s;
}

.app-nav a:hover, .app-nav a.active {
    color: var(--secondary);
    opacity: 1;
}

/* =========================================
   TABS DE NAVEGACIÓN (SCROLLABLE)
   ========================================= */
.tabs-wrapper {
    display: flex;
    overflow-x: auto;
    gap: 5px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e9ecef;
    padding-bottom: 0;
    -webkit-overflow-scrolling: touch; /* Scroll suave en iOS */
    scrollbar-width: none; /* Ocultar scrollbar Firefox */
}

.tabs-wrapper::-webkit-scrollbar {
    display: none; /* Ocultar scrollbar Chrome/Safari */
}

.tab-link {
    padding: 12px 20px;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 600;
    border-radius: 8px 8px 0 0;
    white-space: nowrap;
    background: transparent;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.tab-link.active {
    background: var(--white);
    color: var(--primary);
    border-color: #e9ecef;
    border-bottom-color: var(--white);
    margin-bottom: -2px;
    border-top: 3px solid var(--secondary);
}

/* =========================================
   CARDS & LAYOUTS
   ========================================= */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

.section-title {
    color: var(--primary);
    margin-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 10px;
    font-size: 1.25rem;
    font-weight: 700;
}

/* Single Column Grid (Para Info y Grupos) */
.single-col-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* En pantallas MUY grandes, permitimos 2 columnas si sobra espacio */
@media (min-width: 900px) {
    .single-col-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
    }
}

/* =========================================
   FILTROS & FORMULARIOS
   ========================================= */
.filters-box {
    background: var(--white);
    padding: 15px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

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

.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: #666;
    margin-bottom: 4px;
    text-transform: uppercase;
}

.form-control, .search-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 0.95rem;
    background: #fff;
    -webkit-appearance: none; /* Eliminar estilos nativos iOS */
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
}

.btn-action {
    background: var(--secondary);
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

/* =========================================
   TABLAS RESPONSIVE
   ========================================= */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 500px; /* Forza scroll horizontal si es muy pequeña */
}

.custom-table th {
    background: #f8f9fa;
    padding: 12px 10px;
    text-align: center;
    font-size: 0.75rem;
    color: #555;
    font-weight: 700;
    text-transform: uppercase;
    border-bottom: 2px solid #ddd;
    white-space: nowrap;
}

.custom-table td {
    padding: 12px 10px;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
    text-align: center;
    vertical-align: middle;
}

.custom-table .text-start { text-align: left; }
.custom-table .text-end { text-align: right; }

.row-gold { background-color: #fffbf0; border-left: 4px solid var(--secondary); }
.row-silver { background-color: #fcfcfc; border-left: 4px solid #b0b0b0; }

/* Score Tag - MEJORADO PARA LEGIBILIDAD */
.score-tag {
    background-color: #ffffff;
    color: #222;
    border: 1px solid #ccc;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 800;
    font-size: 0.9rem;
    white-space: nowrap;
    display: inline-block;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.dgrade-badge {
    background: #e9ecef;
    color: #495057;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 700;
    border: 1px solid #dee2e6;
}

/* =========================================
   GRUPOS (DISEÑO TARJETA)
   ========================================= */
.card-group {
    background: var(--white);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.group-header {
    background: var(--primary);
    color: white;
    padding: 10px;
    font-weight: 700;
    text-align: center;
    text-transform: uppercase;
    font-size: 0.95rem;
}

/* =========================================
   ELIMINATORIAS (MODO LISTA - CLASIFICACIÓN)
   ========================================= */
.bracket-list-box {
    margin-bottom: 15px;
    border-left: 4px solid var(--secondary);
    background: white;
    padding: 15px;
    border-radius: 0 8px 8px 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    border: 1px solid #eee;
    border-left-width: 4px;
}

.bl-head {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #888;
    margin-bottom: 10px;
    text-transform: uppercase;
    font-weight: 700;
}

.bl-body {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
    font-weight: 600;
}

.bl-team {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* =========================================
   CUADRO FINAL (BRACKET TREE)
   ========================================= */
.bracket-wrapper {
    margin-top: 20px;
    overflow-x: auto;
    padding-bottom: 20px;
    -webkit-overflow-scrolling: touch;
}

.bracket-phase-title {
    text-align: center;
    background: #333;
    color: white;
    padding: 8px;
    border-radius: 6px;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 0.85rem;
    margin-bottom: 15px;
    position: sticky;
    left: 0;
}

.bracket-container {
    display: flex;
    padding: 10px;
    gap: 30px;
    min-width: max-content; /* Asegura que no se aplaste */
}

.bracket-round {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    min-width: 220px;
    flex-shrink: 0;
}

.round-title {
    text-align: center;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    font-size: 0.75rem;
    margin-bottom: 10px;
    border-bottom: 2px solid var(--secondary);
    padding-bottom: 4px;
}

.match-node {
    background: white;
    border: 1px solid #ccc;
    border-radius: 6px;
    padding: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    margin: 10px 0;
    position: relative;
    font-size: 0.85rem;
}

/* Conectores Visuales */
.bracket-round:not(:last-child) .match-node::after {
    content: '';
    position: absolute;
    right: -30px;
    top: 50%;
    width: 30px;
    height: 1px;
    background: #bbb;
    z-index: 0;
}

.mn-meta {
    font-size: 0.7rem;
    color: #999;
    text-align: right;
    margin-bottom: 4px;
    border-bottom: 1px solid #f5f5f5;
}

.mn-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
}

.mn-name {
    font-weight: 600;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mn-score {
    font-weight: 700;
    background: #eee;
    padding: 0 6px;
    border-radius: 4px;
    min-width: 24px;
    text-align: center;
}

.mn-win { color: var(--primary); }
.mn-win .mn-score { background: var(--primary); color: white; }
.mn-lose { color: #aaa; text-decoration: line-through; opacity: 0.8; }

/* =========================================
   MODAL CALCULADORA
   ========================================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(3px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.modal-modern {
    background: white;
    width: 90%;
    max-width: 400px;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
    background: var(--primary);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
}

.modal-body { padding: 25px; }

.calc-select {
    width: 100%;
    padding: 12px;
    border: 2px solid #eee;
    border-radius: 8px;
    font-size: 1rem;
    background: #fafafa;
    margin-bottom: 20px;
}

.btn-calc {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(26,74,62,0.3);
}

.calc-result-box {
    background: #f8fff9;
    border: 2px solid #d4edda;
    border-radius: 8px;
    padding: 15px;
    margin-top: 20px;
    display: none;
    text-align: center;
}

/* =========================================
   FOOTER
   ========================================= */
.app-footer {
    background: #2c3e50;
    color: #bdc3c7;
    padding: 40px 0;
    margin-top: 60px;
    text-align: center;
    font-size: 0.85rem;
    border-top: 4px solid var(--secondary);
}

.footer-links {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 15px;
}

.footer-links a {
    color: #ecf0f1;
    text-decoration: none;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--secondary);
}

/* =========================================
   MEDIA QUERIES (MÓVIL HORIZONTAL/VERTICAL)
   ========================================= */
@media (max-width: 600px) {
    .app-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .app-nav { width: 100%; padding-bottom: 5px; }
    .app-nav a { margin-left: 0; margin-right: 15px; }
    .section-title { font-size: 1.1rem; }
    .custom-table th, .custom-table td { padding: 10px 8px; font-size: 0.85rem; }
    .filter-grid { grid-template-columns: 1fr; }
}