/* =====================================================
   EquiScore - Estilos Personalizados Modernos
   ===================================================== */

:root {
    --primary-color: #2563eb;
    --primary-dark: #1e40af;
    --primary-light: #3b82f6;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #06b6d4;
    --dark-color: #1f2937;
    --light-color: #f9fafb;
    --border-color: #e5e7eb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f8fafc;
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.5;
    font-size: 0.875rem; /* Reducido de 1rem (16px) a 14px */
}

/* Fondo más sutil para mejor contraste */
.main-content-wrapper {
    background: #f8fafc;
}

/* Navbar Moderno */
.navbar-modern {
    background: white;
    box-shadow: var(--shadow-md);
    padding: 0.625rem 0; /* Reducido de 1rem */
    border-bottom: 1px solid var(--border-color);
}

.navbar-brand-modern {
    font-size: 1.125rem; /* Reducido de 1.5rem */
    font-weight: 700;
    color: var(--primary-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.375rem; /* Reducido */
}

.navbar-brand-modern .brand-text {
    transition: opacity 0.3s ease;
}

.navbar-brand-modern i {
    font-size: 1.25rem; /* Reducido de 1.75rem */
}

/* Sidebar Moderno */
.sidebar-modern {
    background: white;
    min-height: calc(100vh - 80px);
    box-shadow: var(--shadow-md);
    border-right: 1px solid var(--border-color);
    padding: 1rem 0; /* Reducido de 1.5rem */
    transition: all 0.3s ease;
    position: relative;
    /* No establecer width: 100% para que respete el grid de Bootstrap */
}

/* Sidebar colapsado */
.sidebar-modern.collapsed {
    flex: 0 0 70px !important;
    max-width: 70px !important;
    min-width: 70px !important;
}

.sidebar-modern.collapsed .nav-link span,
.sidebar-modern.collapsed .nav-link .brand-text,
.sidebar-modern.collapsed hr,
.sidebar-modern.collapsed .text-uppercase {
    display: none;
}

.sidebar-modern.collapsed .nav-link {
    justify-content: center;
    padding: 0.5rem;
    margin: 0.125rem 0.5rem;
}

.sidebar-modern.collapsed .nav-link i {
    margin: 0;
}

.sidebar-modern .nav-link {
    color: var(--text-secondary);
    padding: 0.5rem 1rem; /* Reducido de 0.75rem 1.5rem */
    margin: 0.125rem 0.75rem; /* Reducido */
    border-radius: 0.375rem; /* Reducido de 0.5rem */
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem; /* Reducido de 0.75rem */
    font-weight: 500;
    font-size: 0.875rem; /* Asegurar tamaño consistente */
    position: relative;
}

.sidebar-modern .nav-link:hover {
    background: var(--light-color);
    color: var(--primary-color);
    transform: translateX(4px);
}

.sidebar-modern.collapsed .nav-link:hover {
    transform: none;
}

.sidebar-modern .nav-link.active {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: white;
    box-shadow: var(--shadow-md);
}

.sidebar-modern .nav-link i {
    font-size: 1rem; /* Reducido de 1.25rem */
    width: 20px; /* Reducido de 24px */
    text-align: center;
    flex-shrink: 0;
}

/* Tooltip para sidebar colapsado */
.sidebar-modern.collapsed .nav-link[title] {
    position: relative;
}

.sidebar-modern.collapsed .nav-link:hover::after {
    content: attr(title);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 0.5rem;
    background: var(--dark-color);
    color: white;
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    white-space: nowrap;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
}

.sidebar-modern.collapsed .nav-link:hover::before {
    content: '';
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right-color: var(--dark-color);
    z-index: 1001;
}

/* Main content - solo ajustar cuando sidebar está colapsado */
.main-content-wrapper.expanded {
    flex: 0 0 calc(100% - 70px) !important;
    max-width: calc(100% - 70px) !important;
}

/* Cuando sidebar NO está colapsado, volver a los valores normales de Bootstrap */
.sidebar-modern:not(.collapsed) ~ main.main-content-wrapper,
.sidebar-modern:not(.collapsed) + main.main-content-wrapper {
    flex: 0 0 auto !important;
    max-width: 100% !important;
}

/* Ajustar contenedor cuando sidebar está colapsado */
#mainContainer.sidebar-collapsed .row {
    margin-left: 0;
    margin-right: 0;
}

/* Cuando sidebar está colapsado, forzar ancho */
#mainContainer.sidebar-collapsed .row > aside.col-md-3,
#mainContainer.sidebar-collapsed .row > aside.col-lg-2 {
    flex: 0 0 70px !important;
    max-width: 70px !important;
    min-width: 70px !important;
}

#mainContainer.sidebar-collapsed .row > main.col-md-9,
#mainContainer.sidebar-collapsed .row > main.col-lg-10 {
    flex: 0 0 calc(100% - 70px) !important;
    max-width: calc(100% - 70px) !important;
}

/* Cuando sidebar NO está colapsado, usar valores normales de Bootstrap */
#mainContainer:not(.sidebar-collapsed) .row > aside.col-md-3 {
    flex: 0 0 25% !important;
    max-width: 25% !important;
}

#mainContainer:not(.sidebar-collapsed) .row > aside.col-lg-2 {
    flex: 0 0 16.666667% !important;
    max-width: 16.666667% !important;
}

#mainContainer:not(.sidebar-collapsed) .row > main.col-md-9 {
    flex: 0 0 75% !important;
    max-width: 75% !important;
}

#mainContainer:not(.sidebar-collapsed) .row > main.col-lg-10 {
    flex: 0 0 83.333333% !important;
    max-width: 83.333333% !important;
}

/* Botón toggle */
.sidebar-toggle {
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all 0.3s ease;
}

.sidebar-toggle:hover {
    transform: scale(1.1);
    color: var(--primary-dark) !important;
}

.sidebar-toggle:focus {
    box-shadow: none;
    outline: none;
}

/* Cards Modernas */
.card-modern {
    background: white;
    border-radius: 0.75rem; /* Reducido de 1rem */
    box-shadow: var(--shadow-lg);
    border: none;
    overflow: hidden;
    transition: all 0.3s ease;
    margin-bottom: 1rem; /* Reducido de 1.5rem */
}

.card-modern:hover {
    transform: translateY(-2px); /* Reducido de -4px */
    box-shadow: var(--shadow-xl);
}

.card-header-modern {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: white;
    padding: 0.875rem 1.25rem; /* Reducido de 1.25rem 1.5rem */
    border: none;
    font-weight: 600;
    font-size: 0.9375rem; /* Reducido de 1.1rem (17.6px a 15px) */
}

.card-body-modern {
    padding: 1rem 1.25rem; /* Reducido de 1.5rem */
}

/* Botones Modernos */
.btn-modern {
    border-radius: 0.375rem; /* Reducido de 0.5rem */
    padding: 0.5rem 1.125rem; /* Reducido de 0.625rem 1.5rem */
    font-weight: 600;
    transition: all 0.3s ease;
    border: none;
    box-shadow: var(--shadow-sm);
    font-size: 0.875rem; /* Asegurar tamaño consistente */
}

.btn-modern:hover {
    transform: translateY(-1px); /* Reducido de -2px */
    box-shadow: var(--shadow-md);
}

.btn-modern-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: white;
}

.btn-modern-success {
    background: linear-gradient(135deg, var(--success-color), #34d399);
    color: white;
}

.btn-modern-danger {
    background: linear-gradient(135deg, var(--danger-color), #f87171);
    color: white;
}

/* Tablas Modernas */
.table-modern {
    border-collapse: separate;
    border-spacing: 0;
}

.table-modern thead {
    background: var(--light-color);
}

.table-modern thead th {
    border: none;
    padding: 0.75rem 0.875rem; /* Reducido de 1rem */
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    font-size: 0.6875rem; /* Reducido de 0.75rem (12px a 11px) */
    letter-spacing: 0.05em;
}

.table-modern tbody tr {
    transition: all 0.2s ease;
}

.table-modern tbody tr:hover {
    background: var(--light-color);
    transform: scale(1.005); /* Reducido de 1.01 */
}

.table-modern tbody td {
    padding: 0.75rem 0.875rem; /* Reducido de 1rem */
    border-top: 1px solid var(--border-color);
    vertical-align: middle;
    font-size: 0.875rem; /* Asegurar tamaño consistente */
}

/* Badges Modernos */
.badge-modern {
    padding: 0.25rem 0.5rem; /* Reducido de 0.375rem 0.75rem */
    border-radius: 0.25rem; /* Reducido de 0.375rem */
    font-weight: 600;
    font-size: 0.6875rem; /* Reducido de 0.75rem (12px a 11px) */
}

/* Última fila ingresada en la tabla de resultados de pista.
   Marca visual (azul distintivo + acento izquierdo) para ubicar de un
   vistazo el último resultado cargado. Se mantiene visible en :hover. */
.table-modern tbody tr.pista-ultimo-ingresado,
.table-modern tbody tr.pista-ultimo-ingresado:hover {
    background: #cfe2ff;
}
.table-modern tbody tr.pista-ultimo-ingresado > td,
.table-modern tbody tr.pista-ultimo-ingresado:hover > td {
    background-color: #cfe2ff !important;
    border-top-color: #9ec5fe;
}
.table-modern tbody tr.pista-ultimo-ingresado > td:first-child {
    box-shadow: inset 4px 0 0 #0d6efd;
}

/* Eliminados (puesto 999 por tarjeta roja / eliminación reglamentaria). */
.table-modern tbody tr.pista-fila-eliminado,
.table-modern tbody tr.pista-fila-eliminado:hover {
    background: #f8d7da;
}
.table-modern tbody tr.pista-fila-eliminado > td,
.table-modern tbody tr.pista-fila-eliminado:hover > td {
    background-color: #f8d7da !important;
    border-top-color: #f1aeb5;
}
.table-modern tbody tr.pista-fila-eliminado > td:first-child {
    box-shadow: inset 4px 0 0 #dc3545;
}

/* Forfait (retiro voluntario / no presentado). */
.table-modern tbody tr.pista-fila-forfait,
.table-modern tbody tr.pista-fila-forfait:hover {
    background: #ccc;
}
.table-modern tbody tr.pista-fila-forfait > td,
.table-modern tbody tr.pista-fila-forfait:hover > td {
    background-color: #ccc !important;
    border-top-color: #b3b3b3;
}
.table-modern tbody tr.pista-fila-forfait > td:first-child {
    box-shadow: inset 4px 0 0 #999;
}

/* Inputs Modernos */
.form-control-modern {
    border-radius: 0.375rem; /* Reducido de 0.5rem */
    border: 2px solid var(--border-color);
    padding: 0.5rem 0.875rem; /* Reducido de 0.75rem 1rem */
    transition: all 0.3s ease;
    font-size: 0.875rem; /* Asegurar tamaño consistente */
}

.form-control-modern:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    outline: none;
}

/* Alertas Modernas */
.alert-modern {
    border-radius: 0.5rem; /* Reducido de 0.75rem */
    border: none;
    padding: 0.75rem 1.125rem; /* Reducido de 1rem 1.5rem */
    box-shadow: var(--shadow-md);
    font-size: 0.875rem; /* Asegurar tamaño consistente */
}

/* Stats Cards */
.stat-card {
    background: white;
    border-radius: 0.75rem; /* Reducido de 1rem */
    padding: 1rem 1.25rem; /* Reducido de 1.5rem */
    box-shadow: var(--shadow-md);
    transition: all 0.3s ease;
    border-left: 3px solid var(--primary-color); /* Reducido de 4px */
}

.stat-card:hover {
    transform: translateY(-2px); /* Reducido de -4px */
    box-shadow: var(--shadow-xl);
}

.stat-card .stat-value {
    font-size: 1.5rem; /* Reducido de 2rem */
    font-weight: 700;
    color: var(--primary-color);
    margin: 0.375rem 0; /* Reducido de 0.5rem */
}

.stat-card .stat-label {
    color: var(--text-secondary);
    font-size: 0.75rem; /* Reducido de 0.875rem */
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Pista Actual - Destacado */
.current-competitor {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border: 2px solid var(--warning-color); /* Reducido de 3px */
    border-radius: 0.75rem; /* Reducido de 1rem */
    padding: 1.25rem 1.5rem; /* Reducido de 2rem */
    margin: 1rem 0; /* Reducido de 1.5rem */
    box-shadow: var(--shadow-xl);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(245, 158, 11, 0);
    }
}

/* Botones pequeños */
.btn-sm {
    padding: 0.25rem 0.5rem; /* Reducido */
    font-size: 0.75rem; /* Reducido */
}

/* Form labels más pequeños */
.form-label {
    font-size: 0.8125rem; /* Reducido de tamaño por defecto */
    margin-bottom: 0.375rem; /* Reducido */
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar-modern {
        min-height: auto;
    }
    
    .card-modern {
        margin-bottom: 1rem;
    }
}

/* Utilidades */
.text-gradient {
    color: var(--primary-color);
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
    font-size: 1.25rem; /* Reducido de tamaño por defecto */
}

/* Títulos más pequeños */
h1, .h1 { font-size: 1.75rem; }
h2, .h2 { font-size: 1.5rem; }
h3, .h3 { font-size: 1.25rem; }
h4, .h4 { font-size: 1.125rem; }
h5, .h5 { font-size: 1rem; }
h6, .h6 { font-size: 0.875rem; }

/* Reducir márgenes de títulos */
h1, h2, h3, h4, h5, h6 {
    margin-bottom: 0.5rem;
}

/* Reducir padding de mb-4 */
.mb-4 {
    margin-bottom: 1rem !important; /* Reducido de 1.5rem */
}

.shadow-modern {
    box-shadow: var(--shadow-lg);
}

.rounded-modern {
    border-radius: 1rem;
}

/* Loading Spinner */
.spinner-modern {
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

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

/* =====================================================
   Cabecera de Control de Pista (compartida por todas las
   pistas: pista.php, pista_desempate.php,
   pista_doble_recorrido.php, pista_dos_fases_especiales.php).
   Meta en una sola línea + botones de acción como íconos.
   ===================================================== */
.pista-header-meta {
    font-weight: 600;
    line-height: 1.4;
}
.pista-header-meta .pista-meta-item {
    white-space: nowrap;
}
.pista-header-meta .pista-meta-sep {
    color: #c8cdd4;
    font-weight: 400;
    user-select: none;
}

.pista-action-btn {
    width: 42px;
    height: 42px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex: 0 0 auto;
}
.pista-action-btn i {
    margin: 0;
}

/* ============================================================
   Cambio rápido de prueba en la pista: chips compactos (solo el
   nombre de categoría) agrupados por día en un acordeón.
   Compartido por todas las pistas.
   ============================================================ */
.pista-cambio-rapido {
    background: #f8f9fa;
    border: 1px solid #e7e9ee;
    border-radius: 0.5rem;
    padding: 0.4rem 0.6rem;
}
.pista-cambio-rapido .pcr-bar-label {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    font-size: 0.7rem;
}
.pista-cambio-rapido .pcr-form {
    margin: 0;
}

/* Cabecera de día (acordeón) */
.pcr-dia + .pcr-dia {
    margin-top: 0.15rem;
}
.pcr-dia-head {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    width: 100%;
    border: none;
    background: transparent;
    padding: 0.2rem 0.1rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: #45505f;
    cursor: pointer;
    text-align: left;
}
.pcr-dia-head:hover {
    color: var(--primary-color, #4361ee);
}
.pcr-dia-head .pcr-caret {
    font-size: 0.65rem;
    transition: transform 0.15s ease;
}
.pcr-dia.pcr-open .pcr-dia-head .pcr-caret {
    transform: rotate(90deg);
}
.pcr-dia-head .pcr-dia-fecha {
    font-weight: 400;
    font-size: 0.72rem;
}
.pcr-dia-head .pcr-dia-count {
    margin-left: auto;
    background: #e2e6ec;
    color: #5b6675;
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.02rem 0.4rem;
}
.pcr-dia-body {
    padding: 0.2rem 0 0.35rem 1rem;
}

/* Chip compacto: una sola línea, solo el nombre. */
.pcr-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
    line-height: 1.1;
    padding: 0.16rem 0.5rem;
    border-radius: 999px;
    border: 1px solid #ccd2db;
    background: #fff;
    color: #34404f;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.12s ease;
}
.pcr-chip:hover {
    border-color: var(--primary-color, #4361ee);
    color: var(--primary-color, #4361ee);
    box-shadow: 0 1px 4px rgba(67, 97, 238, 0.15);
}
.pcr-chip i {
    font-size: 0.62rem;
}
.pcr-chip.pcr-chip-active {
    background: var(--primary-color, #4361ee);
    border-color: var(--primary-color, #4361ee);
    color: #fff;
    cursor: default;
}

/* ===== Desglose de faltas en tabla de resultados de pistas ===== */
/* Diferencia de un vistazo las faltas de PISTA (derribos/desobediencias)
   de las faltas por TIEMPO concedido excedido. */
.pista-faltas-cell {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
}
.pista-faltas-mini {
    display: inline-flex;
    gap: 0.22rem;
}
.pf-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.18rem;
    padding: 0.04rem 0.34rem;
    border-radius: 999px;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: 0.02em;
    white-space: nowrap;
    border: 1px solid transparent;
}
/* Faltas de pista (obstáculos): tono ámbar */
.pf-chip-pista {
    background: #fff4e0;
    color: #b25e00;
    border-color: #ffd591;
}
/* Faltas por tiempo concedido: tono azul */
.pf-chip-tiempo {
    background: #e7f0ff;
    color: #1f4e9b;
    border-color: #b9d2ff;
}

/* ===== Fix de botones outline dentro de .btn-modern ===== */
/* .btn-modern aplica `border: none`, lo que borra el borde de los
   botones .btn-outline-* y deja "Descargar Resumen" y "Descargar Excel"
   casi idénticos. Restauramos borde y color para que se distingan. */
.btn-modern.btn-outline-primary {
    border: 1px solid var(--primary-color, #4361ee);
    color: var(--primary-color, #4361ee);
    background: #fff;
}
.btn-modern.btn-outline-primary:hover {
    background: var(--primary-color, #4361ee);
    color: #fff;
}
.btn-modern.btn-outline-success {
    border: 1px solid var(--success-color, #2ecc71);
    color: var(--success-color, #2ecc71);
    background: #fff;
}
.btn-modern.btn-outline-success:hover {
    background: var(--success-color, #2ecc71);
    color: #fff;
}

