/* ==============================================================================
 * VICTORIA SOCCER - SISTEMA DE NAVEGACIÓN Y LAYOUT MAESTRO (NAVBAR.CSS)
 * - Sidebar expandido (240px) / contraído (68px)
 * - Header superior global con Switcher de Sedes independiente
 * - Corrección absoluta de superposición y desbordamiento sobre el contenido
 * ============================================================================== */

:root {
    --vs-sidebar-w-expanded: 240px;
    --vs-sidebar-w-collapsed: 68px;
    --vs-topbar-h: 62px;
    
    /* Paleta Corporativa Victoria Soccer */
    --vs-primary: #1a237e;
    --vs-primary-dark: #0d47a1;
    --vs-accent: #00bcd4;
    --vs-accent-hover: #38bdf8;
    --vs-bg-main: #f8fafc;
    --vs-sidebar-bg: #1e293b;
    --vs-sidebar-bg-dark: #0f172a;
    --vs-text-light: #f8fafc;
    --vs-text-muted: #94a3b8;
    --vs-border-subtle: rgba(255, 255, 255, 0.08);
    --vs-topbar-border: #e2e8f0;
    
    --vs-transition-smooth: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ------------------------------------------------------------------------------
 * REGLAS GENERALES Y RESET DE SEGURIDAD
 * ------------------------------------------------------------------------------ */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0 !important;
    padding: 0;
    background-color: var(--vs-bg-main) !important;
    color: #1e293b;
}

/* ------------------------------------------------------------------------------
 * VISTA PÚBLICA SIN SIDEBAR (index.php, consulta ciudadana)
 * ------------------------------------------------------------------------------ */
body.public-view,
body.no-sidebar {
    padding-left: 0 !important;
    padding-bottom: 0 !important;
    display: block !important;
    background-color: var(--vs-bg-main) !important;
}

body.public-view .sidebar-icon,
body.public-view .vs-topbar,
body.no-sidebar .sidebar-icon,
body.no-sidebar .vs-topbar {
    display: none !important;
}

body.public-view .main-container {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
}

/* Cabecera Pública del Portal de Estadísticas (index.php) */
.public-portal-header {
    background: linear-gradient(135deg, #1a237e 0%, #0d47a1 100%);
    box-shadow: 0 4px 20px rgba(26, 35, 126, 0.25);
    padding: 0.9rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.portal-brand-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, #00bcd4 0%, #0284c7 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 1.4rem;
    box-shadow: 0 4px 12px rgba(0, 188, 212, 0.4);
}

.portal-brand-title {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 1.85rem;
    color: #ffffff;
    letter-spacing: 1.5px;
    line-height: 1;
}

.portal-brand-subtitle {
    font-size: 0.72rem;
    font-weight: 600;
    color: #38bdf8;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.btn-login-portal {
    background: #00bcd4;
    color: #0f172a !important;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.92rem;
    font-weight: 700;
    padding: 0.6rem 1.4rem;
    border-radius: 10px;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 14px rgba(0, 188, 212, 0.4);
    transition: all 0.22s ease;
    text-decoration: none !important;
}

.btn-login-portal:hover {
    background: #38bdf8;
    color: #0f172a !important;
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 188, 212, 0.55);
}

/* ------------------------------------------------------------------------------
 * ESCRITORIO (>= 768px): LAYOUT BLINDADO CONTRA SUPERPOSICIÓN
 * ------------------------------------------------------------------------------ */
@media (min-width: 768px) {
    body {
        padding-left: var(--vs-sidebar-w-expanded) !important;
        margin: 0 !important;
        display: block !important; /* Desactiva cualquier flex centrado que encime vistas */
        min-height: 100vh !important;
        transition: padding-left 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    body.sidebar-collapsed {
        padding-left: var(--vs-sidebar-w-collapsed) !important;
    }

    /* Blindaje del Contenedor Principal para que NUNCA se desborde al sidebar */
    .main-container,
    .main-content,
    main,
    .container-fluid {
        position: relative !important;
        z-index: 1 !important;
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-sizing: border-box !important;
        padding: 0 !important;
    }

    /* Barra Lateral Fija */
    .sidebar-icon {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        height: 100vh !important;
        width: var(--vs-sidebar-w-expanded) !important;
        background: linear-gradient(180deg, var(--vs-sidebar-bg) 0%, var(--vs-sidebar-bg-dark) 100%) !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 0 !important;
        box-shadow: 3px 0 18px rgba(0, 0, 0, 0.25) !important;
        z-index: 1050 !important; /* Por encima de cualquier tabla o card */
        overflow: hidden !important;
        transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
        user-select: none;
        border-right: 1px solid var(--vs-border-subtle);
    }

    .sidebar-icon.collapsed {
        width: var(--vs-sidebar-w-collapsed) !important;
    }

    /* Encabezado del Menú Lateral */
    .sidebar-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 14px 16px;
        height: var(--vs-topbar-h);
        background: rgba(0, 0, 0, 0.22);
        border-bottom: 1px solid var(--vs-border-subtle);
        gap: 10px;
    }

    .sidebar-brand {
        display: flex;
        align-items: center;
        gap: 10px;
        text-decoration: none !important;
        color: #ffffff !important;
        overflow: hidden;
        flex: 1;
    }

    .sidebar-brand-icon {
        width: 36px;
        height: 36px;
        min-width: 36px;
        border-radius: 10px;
        background: linear-gradient(135deg, #00bcd4 0%, #1a237e 100%);
        display: flex;
        align-items: center;
        justify-content: center;
        color: #ffffff;
        font-size: 1.15rem;
        box-shadow: 0 4px 10px rgba(0, 188, 212, 0.35);
    }

    .sidebar-brand-text {
        display: flex;
        flex-direction: column;
        line-height: 1.1;
        white-space: nowrap;
    }

    .sidebar-brand-text .brand-title {
        font-weight: 800;
        font-size: 0.95rem;
        letter-spacing: 0.08em;
        color: #ffffff;
    }

    .sidebar-brand-text .brand-subtitle {
        font-size: 0.68rem;
        font-weight: 600;
        letter-spacing: 0.14em;
        color: var(--vs-accent);
        text-transform: uppercase;
    }

    /* Botón de Toggle del Menú Lateral */
    .sidebar-toggle-btn {
        background: rgba(255, 255, 255, 0.08);
        border: 1px solid rgba(255, 255, 255, 0.14);
        color: var(--vs-text-light);
        width: 32px;
        height: 32px;
        min-width: 32px;
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        outline: none;
        transition: all 0.2s ease;
        padding: 0;
    }

    .sidebar-toggle-btn:hover {
        background: var(--vs-accent);
        color: #0f172a;
        box-shadow: 0 0 12px rgba(0, 188, 212, 0.5);
    }

    .sidebar-toggle-btn i {
        font-size: 0.85rem;
        transition: transform 0.28s ease;
    }

    /* Lista de Navegación */
    .sidebar-menu-list {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 10px 0;
        display: flex;
        flex-direction: column;
        gap: 2px;
        scrollbar-width: thin;
        scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
    }

    .sidebar-menu-list::-webkit-scrollbar {
        width: 4px;
    }

    .sidebar-menu-list::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.15);
        border-radius: 4px;
    }

    /* Ítems del Menú Lateral */
    .sidebar-icon a.sidebar-item {
        color: var(--vs-text-light) !important;
        text-decoration: none !important;
        display: flex !important;
        align-items: center !important;
        padding: 10px 16px !important;
        margin: 0 8px !important;
        border-radius: 8px !important;
        font-size: 0.92rem !important;
        font-weight: 500 !important;
        position: relative !important;
        text-align: left !important;
        transition: var(--vs-transition-smooth) !important;
        white-space: nowrap !important;
        border-left: 3px solid transparent !important;
    }

    .sidebar-icon a.sidebar-item .sidebar-item-icon {
        width: 28px;
        min-width: 28px;
        height: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.15rem;
        margin-right: 12px;
        color: var(--vs-text-muted);
        transition: var(--vs-transition-smooth);
    }

    .sidebar-icon a.sidebar-item .sidebar-label {
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sidebar-icon a.sidebar-item .sidebar-active-indicator {
        width: 7px;
        height: 7px;
        border-radius: 50%;
        background-color: var(--vs-accent);
        box-shadow: 0 0 8px var(--vs-accent);
        margin-left: auto;
    }

    .sidebar-icon a.sidebar-item:hover {
        background-color: rgba(255, 255, 255, 0.08) !important;
        color: #ffffff !important;
        transform: translateX(2px);
    }

    .sidebar-icon a.sidebar-item:hover .sidebar-item-icon {
        color: var(--vs-accent-hover);
    }

    /* Sección Activa Inconfundible */
    .sidebar-icon a.sidebar-item.active {
        background: linear-gradient(90deg, rgba(0, 188, 212, 0.22) 0%, rgba(0, 188, 212, 0.04) 100%) !important;
        color: #ffffff !important;
        font-weight: 700 !important;
        border-left: 3px solid var(--vs-accent) !important;
        box-shadow: inset 0 0 15px rgba(0, 188, 212, 0.08);
    }

    .sidebar-icon a.sidebar-item.active .sidebar-item-icon {
        color: var(--vs-accent) !important;
        filter: drop-shadow(0 0 6px rgba(0, 188, 212, 0.6));
    }

    /* Footer del Menú */
    .sidebar-footer {
        padding: 10px 12px;
        background: rgba(0, 0, 0, 0.25);
        border-top: 1px solid var(--vs-border-subtle);
        display: flex;
        flex-direction: column;
        gap: 6px;
    }

    .sidebar-user-card {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 6px 8px;
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.04);
        overflow: hidden;
    }

    .sidebar-user-avatar {
        width: 32px;
        min-width: 32px;
        height: 32px;
        border-radius: 50%;
        background: rgba(0, 188, 212, 0.15);
        color: var(--vs-accent);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.15rem;
    }

    .sidebar-user-meta {
        display: flex;
        flex-direction: column;
        line-height: 1.2;
        overflow: hidden;
    }

    .sidebar-user-name {
        font-size: 0.8rem;
        font-weight: 600;
        color: #ffffff;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sidebar-user-role {
        font-size: 0.68rem;
        color: var(--vs-text-muted);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sidebar-logout {
        color: #f87171 !important;
    }

    .sidebar-logout:hover {
        background-color: rgba(239, 68, 68, 0.15) !important;
        color: #fca5a5 !important;
    }

    /* --------------------------------------------------------------------------
     * MODO CONTRAÍDO (.collapsed)
     * -------------------------------------------------------------------------- */
    .sidebar-icon.collapsed .sidebar-header {
        justify-content: center;
        padding: 14px 8px;
    }

    .sidebar-icon.collapsed .sidebar-brand-text,
    .sidebar-icon.collapsed .sidebar-brand {
        display: none !important;
    }

    .sidebar-icon.collapsed .sidebar-toggle-btn {
        margin: 0 auto;
    }

    .sidebar-icon.collapsed .sidebar-toggle-btn i {
        transform: rotate(180deg);
    }

    .sidebar-icon.collapsed a.sidebar-item {
        padding: 10px 0 !important;
        margin: 0 8px !important;
        justify-content: center !important;
    }

    .sidebar-icon.collapsed a.sidebar-item .sidebar-item-icon {
        margin-right: 0 !important;
    }

    .sidebar-icon.collapsed a.sidebar-item .sidebar-label,
    .sidebar-icon.collapsed a.sidebar-item .sidebar-active-indicator,
    .sidebar-icon.collapsed .sidebar-user-meta {
        display: none !important;
    }

    .sidebar-icon.collapsed .sidebar-user-card {
        justify-content: center;
        padding: 6px 0;
    }

    .sidebar-icon.collapsed a.sidebar-item[data-tooltip]:hover::after {
        content: attr(data-tooltip);
        position: fixed;
        left: calc(var(--vs-sidebar-w-collapsed) + 8px);
        white-space: nowrap;
        background-color: #0f172a;
        color: #ffffff;
        padding: 6px 12px;
        border-radius: 6px;
        font-size: 0.82rem;
        font-weight: 600;
        z-index: 1060;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
        border: 1px solid rgba(255, 255, 255, 0.1);
        pointer-events: none;
    }
}

/* ------------------------------------------------------------------------------
 * BARRA SUPERIOR GLOBAL INDEPENDIENTE (.vs-topbar)
 * Switcher de Sedes Fijo y Rápido
 * ------------------------------------------------------------------------------ */
.vs-topbar {
    position: sticky;
    top: 0;
    height: var(--vs-topbar-h);
    background: #ffffff;
    border-bottom: 1px solid var(--vs-topbar-border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    z-index: 1020;
    width: 100%;
    box-sizing: border-box;
}

.vs-topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.vs-topbar-toggle-btn {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    color: #1e293b;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.vs-topbar-toggle-btn:hover {
    background: #1a237e;
    color: #ffffff;
    border-color: #1a237e;
}

.vs-topbar-brand-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.vs-topbar-brand-title {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 1.45rem;
    color: #1a237e;
    letter-spacing: 1px;
    line-height: 1;
}

.vs-topbar-badge {
    background: rgba(0, 188, 212, 0.12);
    color: #0284c7;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 12px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.vs-topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Switcher de Sedes Global */
.vs-sede-switcher {
    position: relative;
}

.vs-sede-btn {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    padding: 6px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    outline: none !important;
}

.vs-sede-btn:hover,
.vs-sede-btn:focus {
    background: #ffffff;
    border-color: var(--vs-accent);
    box-shadow: 0 0 0 3px rgba(0, 188, 212, 0.2);
}

.vs-sede-btn::after {
    display: none !important; /* Ocultar flecha estándar de bootstrap */
}

.vs-sede-icon-wrap {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: rgba(0, 188, 212, 0.12);
    color: #00bcd4;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
}

.vs-sede-info {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.vs-sede-hint {
    font-size: 0.65rem;
    font-weight: 700;
    color: #64748b;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.vs-sede-current {
    font-size: 0.92rem;
    font-weight: 700;
    color: #1a237e;
    letter-spacing: 0.02em;
}

.vs-sede-arrow {
    font-size: 0.75rem;
    color: #94a3b8;
    margin-left: 4px;
    transition: transform 0.2s ease;
}

.vs-sede-switcher.show .vs-sede-arrow {
    transform: rotate(180deg);
}

.vs-sede-dropdown-menu {
    border-radius: 12px !important;
    border: 1px solid #e2e8f0 !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12) !important;
    padding: 8px !important;
    min-width: 240px;
    margin-top: 8px !important;
}

.vs-sede-option {
    border-radius: 8px !important;
    padding: 8px 12px !important;
    font-size: 0.9rem !important;
    font-weight: 500 !important;
    color: #334155 !important;
    transition: all 0.15s ease;
}

.vs-sede-option:hover {
    background-color: #f1f5f9 !important;
    color: #1a237e !important;
    transform: translateX(3px);
}

.vs-sede-option.active {
    background: rgba(0, 188, 212, 0.1) !important;
    color: #0284c7 !important;
    font-weight: 700 !important;
}

.vs-sede-manage-link {
    border-radius: 8px !important;
    padding: 8px 12px !important;
    font-size: 0.85rem !important;
    background: #f8fafc;
}

.vs-sede-manage-link:hover {
    background: #e2e8f0 !important;
}

/* User Pill */
.vs-user-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px 4px 6px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 30px;
}

.vs-user-avatar {
    color: #1a237e;
    font-size: 1.4rem;
    display: flex;
    align-items: center;
}

.vs-user-details {
    flex-direction: column;
    line-height: 1.1;
    padding-right: 4px;
}

.vs-user-name {
    font-size: 0.82rem;
    font-weight: 700;
    color: #1e293b;
}

.vs-user-role {
    font-size: 0.65rem;
    color: #10b981;
    font-weight: 600;
}

.vs-quick-logout {
    color: #ef4444;
    padding: 4px 8px;
    border-radius: 50%;
    text-decoration: none;
    transition: background-color 0.2s ease;
}

.vs-quick-logout:hover {
    background: rgba(239, 68, 68, 0.12);
    color: #dc2626;
}

.bg-cyan {
    background-color: var(--vs-accent) !important;
}

.text-cyan {
    color: var(--vs-accent) !important;
}

/* ------------------------------------------------------------------------------
 * MÓVIL (< 768px)
 * ------------------------------------------------------------------------------ */
@media (max-width: 767.98px) {
    body {
        padding-left: 0 !important;
        padding-bottom: 64px !important;
    }

    .vs-topbar-brand-title {
        font-size: 1.15rem;
    }

    .vs-sede-info .vs-sede-hint {
        display: none;
    }

    .vs-sede-btn {
        padding: 5px 8px;
    }

    .vs-topbar {
        padding: 0 0.75rem;
    }

    .sidebar-icon {
        position: fixed !important;
        bottom: 0 !important;
        top: auto !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 60px !important;
        background: #1e293b !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-around !important;
        padding: 0 4px !important;
        box-shadow: 0 -3px 12px rgba(0, 0, 0, 0.3) !important;
        z-index: 1050 !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .sidebar-header,
    .sidebar-footer {
        display: none !important;
    }

    .sidebar-menu-list {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        width: 100% !important;
        height: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .sidebar-icon a.sidebar-item {
        color: #94a3b8 !important;
        text-decoration: none !important;
        font-size: 1.15rem !important;
        padding: 6px 10px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        flex: 1 !important;
        min-width: 48px !important;
        height: 100% !important;
        border: none !important;
    }

    .sidebar-icon a.sidebar-item .sidebar-item-icon {
        margin: 0 !important;
    }

    .sidebar-icon a.sidebar-item .sidebar-label {
        font-size: 0.65rem !important;
        max-width: 54px !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }

    .sidebar-icon a.sidebar-item.active {
        color: #00bcd4 !important;
        background: rgba(0, 188, 212, 0.12) !important;
    }

    .sidebar-icon a.sidebar-item .sidebar-active-indicator {
        display: none !important;
    }
}
