/* ========================================
   SISTEMA DE NAVEGACIÓN PROFESIONAL - Bcourt-Mx
   Barra Superior + Menú Hamburguesa Drawer
   Diseño tipo Mercado Pago / Stripe / Shopify
   ======================================== */

:root {
    --nav-height: 56px;
    --sidebar-width: 300px;
    --sidebar-bg: #FFFFFF;
    --sidebar-border: #E5E7EB;
    --sidebar-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    --sidebar-primary: #0055FF;
    --sidebar-primary-dark: #0044CC;
    --sidebar-primary-light: #E8F0FF;
    --sidebar-text: #1F2937;
    --sidebar-text-light: #6B7280;
    --sidebar-hover: #F3F4F6;
    --sidebar-overlay: rgba(0, 0, 0, 0.5);
    --sidebar-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-gradient: linear-gradient(135deg, #0055FF 0%, #0066FF 100%);
}

/* ========================================
   TOP NAVIGATION BAR (Barra Superior Fija)
   ======================================== */
.top-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--sidebar-border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 16px;
    gap: 12px;
}

/* Left section: hamburger + avatar */
.top-nav-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

/* Right section: spacer for centering title */
.top-nav-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    min-width: 76px; /* Match left section width for centering */
}

.top-nav-hamburger {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: all 0.2s;
    flex-shrink: 0;
    /* iOS/Touch compatibility */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
    position: relative;
    z-index: 10;
}

.top-nav-hamburger:hover {
    background: var(--sidebar-hover);
}

.top-nav-hamburger:active {
    background: var(--sidebar-primary-light);
}

.top-nav-hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--sidebar-text);
    border-radius: 2px;
    transition: all 0.3s;
}

.top-nav-hamburger.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.top-nav-hamburger.active span:nth-child(2) {
    opacity: 0;
}

.top-nav-hamburger.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

.top-nav-title {
    flex: 1;
    font-size: 16px;
    font-weight: 700;
    color: #6B8299;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

.top-nav-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.top-nav-action {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--sidebar-text-light);
    font-size: 18px;
    transition: all 0.2s;
}

.top-nav-action:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-primary);
}

.top-nav-avatar {
    width: 32px;
    height: 32px;
    background: var(--sidebar-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.top-nav-app-icon {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    display: block;
    padding: 0;
    overflow: hidden;
    background: #000;
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 8px;
}

.top-nav-app-icon-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: inherit;
}

.top-nav-avatar:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0, 85, 255, 0.3);
}

/* ========================================
   CLUB HEADER (Logo y Nombre del Club)
   ======================================== */
.club-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 24px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: var(--nav-height);
}

.club-header-logo {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    object-fit: cover;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    border: 3px solid rgba(255, 255, 255, 0.3);
    background: white;
}

.club-header-info {
    flex: 1;
}

.club-header-title {
    font-size: 24px;
    font-weight: 800;
    color: white;
    margin: 0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.club-header-subtitle {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.85);
    margin: 4px 0 0;
    font-weight: 500;
}

/* ========================================
   SIDEBAR DRAWER (Panel Lateral)
   ======================================== */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--sidebar-overlay);
    z-index: 1099;
    opacity: 0;
    visibility: hidden;
    pointer-events: none; /* CRITICAL: Prevent blocking clicks when hidden */
    transition: all var(--sidebar-transition);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto; /* Enable clicks when active */
}

.sidebar-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    max-width: 85vw;
    height: 100vh;
    height: 100dvh;
    background: var(--sidebar-bg);
    z-index: 1100;
    transform: translateX(-100%);
    transition: transform var(--sidebar-transition);
    display: flex;
    flex-direction: column;
    box-shadow: var(--sidebar-shadow);
    overflow: hidden;
}

.sidebar-panel.active {
    transform: translateX(0);
}

/* Sidebar Header */
.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 14px;
    background: linear-gradient(135deg, #FAFBFC 0%, #F3F4F6 100%);
    flex-shrink: 0;
}

.sidebar-logo {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.sidebar-brand {
    flex: 1;
    min-width: 0;
}

.sidebar-brand-title {
    font-size: 16px;
    font-weight: 800;
    color: var(--sidebar-primary);
    margin: 0;
    letter-spacing: -0.3px;
}

.sidebar-brand-subtitle {
    font-size: 12px;
    color: var(--sidebar-text-light);
    margin: 2px 0 0;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-close {
    width: 36px;
    height: 36px;
    background: var(--sidebar-hover);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--sidebar-text-light);
    font-size: 22px;
    font-weight: 300;
    transition: all 0.2s;
    flex-shrink: 0;
}

.sidebar-close:hover {
    background: var(--sidebar-primary-light);
    color: var(--sidebar-primary);
}

/* Sidebar User Info */
.sidebar-user {
    padding: 16px 20px;
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--sidebar-primary-light);
    flex-shrink: 0;
}

.sidebar-user-photo {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid var(--sidebar-primary);
    box-shadow: 0 2px 8px rgba(0, 85, 255, 0.25);
}

.sidebar-user-avatar {
    width: 48px;
    height: 48px;
    background: var(--sidebar-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 85, 255, 0.25);
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--sidebar-text);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 11px;
    color: var(--sidebar-primary);
    margin: 2px 0 0;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-user-id {
    font-size: 10px;
    color: var(--sidebar-text-light);
    margin: 2px 0 0;
    font-weight: 500;
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
}

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

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--sidebar-border);
    border-radius: 2px;
}

.sidebar-section {
    margin-bottom: 4px;
}

.sidebar-section-title {
    font-size: 10px;
    font-weight: 700;
    color: var(--sidebar-text-light);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 12px 20px 6px;
    margin: 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    text-decoration: none;
    color: var(--sidebar-text);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
    margin: 0 8px;
    border-radius: 8px;
}

.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-primary);
}

.sidebar-link:active {
    background: var(--sidebar-primary-light);
    transform: scale(0.98);
}

.sidebar-link.active {
    background: var(--sidebar-primary-light);
    color: var(--sidebar-primary);
    font-weight: 600;
    border-left-color: var(--sidebar-primary);
    margin-left: 8px;
    border-radius: 0 8px 8px 0;
}

.sidebar-link-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    min-width: 24px;
    height: 24px;
    font-size: 0;
    line-height: 1;
    color: currentColor;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-link-icon svg {
    display: block;
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sidebar-link-text {
    flex: 1;
}

.sidebar-link-badge {
    background: var(--sidebar-primary);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--sidebar-border);
    background: linear-gradient(135deg, #FAFBFC 0%, #F3F4F6 100%);
    flex-shrink: 0;
}

.sidebar-version {
    font-size: 10px;
    color: var(--sidebar-text-light);
    text-align: center;
}

/* ========================================
   LAYOUT SYSTEM (Sistema de Layout)
   ======================================== */
.app-layout {
    min-height: 100vh;
    opacity: 0;
    animation: fadeIn 0.3s ease forwards;
}

.app-layout.loaded {
    opacity: 1;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.app-content {
    margin-top: var(--nav-height);
    min-height: calc(100vh - var(--nav-height));
}

.app-content.with-club-header {
    margin-top: 0;
}

/* Legacy support - has-sidebar class */
body.has-sidebar {
    padding-top: var(--nav-height) !important;
    padding-left: 0 !important;
}

body.has-sidebar .container,
body.has-sidebar .main-content {
    margin-top: 0;
}

/* ========================================
   FLASH PREVENTION (Prevenir Flashazo/FOUC)
   Sistema Anti-FOUC V3.0 para navegación profesional
   ======================================== */

/* Initial hidden state - prevents content flash */
html:not(.dom-ready) body {
    visibility: hidden;
}

html.dom-ready body {
    visibility: visible;
}

/* Prevent any initial flash by hiding body until CSS loads */
body {
    opacity: 1;
    visibility: visible;
}

.page-loading {
    opacity: 0;
    pointer-events: none;
}

.page-loaded {
    opacity: 1;
    pointer-events: auto;
}

/* Pre-render hidden state for navigation */
.sidebar-toggle,
.top-nav {
    opacity: 1;
}

/* Prevent layout shift - force fixed dimensions */
.top-nav {
    contain: layout style;
    will-change: auto;
}

/* Critical elements always visible */
.top-nav,
.sidebar-panel,
.sidebar-overlay {
    visibility: visible !important;
}

/* ========================================
   PAGE TRANSITIONS (Transiciones de Página)
   Navegación profesional sin flashazos
   ======================================== */

/* Transition out when navigating - NO pointer-events: none to avoid blocking */
body.page-transitioning {
    opacity: 0.3;
    transition: opacity 0.15s ease-out;
}

/* Smooth fade-in on page load */
body.page-entering {
    opacity: 0;
    animation: pageEnter 0.2s ease-out forwards;
}

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

/* Ensure nav stays visible during transitions */
body.page-transitioning .top-nav {
    opacity: 1;
    transition: none;
}

/* Content area transition */
body.page-transitioning .app-container,
body.page-transitioning .main-content,
body.page-transitioning .container {
    opacity: 0;
    transition: opacity 0.12s ease-out;
}

/* Prevent flash on back navigation (bfcache) */
body.page-transitioning-back {
    opacity: 1;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */
@media (max-width: 768px) {
    :root {
        --nav-height: 52px;
    }
    
    .top-nav {
        padding: 0 12px;
    }
    
    .top-nav-hamburger {
        width: 36px;
        height: 36px;
    }
    
    .top-nav-title {
        font-size: 14px;
    }
    
    .top-nav-actions {
        gap: 4px;
    }
    
    .top-nav-action {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }
    
    .sidebar-panel {
        width: 100%;
        max-width: 320px;
    }
    
    .club-header {
        padding: 20px 16px;
    }
    
    .club-header-logo {
        width: 56px;
        height: 56px;
    }
    
    .club-header-title {
        font-size: 20px;
    }
    
    body.has-sidebar {
        padding-left: 0 !important;
    }
}

@media (max-width: 480px) {
    .top-nav {
        padding: 0 12px;
        gap: 8px;
    }
    
    .top-nav-left {
        gap: 8px;
    }
    
    .top-nav-right {
        min-width: 60px; /* Smaller on mobile */
    }
    
    .top-nav-title {
        font-size: 13px;
        max-width: 140px;
    }
    
    .top-nav-avatar {
        width: 28px;
        height: 28px;
        font-size: 10px;
    }

    .top-nav-app-icon {
        width: 28px;
        height: 28px;
        flex-basis: 28px;
    }
    
    .top-nav-hamburger {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }
    
    .club-header-logo {
        width: 48px;
        height: 48px;
    }
    
    .club-header-title {
        font-size: 18px;
    }
    
    .club-header-subtitle {
        font-size: 12px;
    }
}

/* Large screens */
@media (min-width: 1200px) {
    .sidebar-panel {
        width: 320px;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */
@media print {
    .top-nav,
    .sidebar-overlay,
    .sidebar-panel,
    .sidebar-toggle,
    .top-nav-hamburger {
        display: none !important;
    }
    
    body.has-sidebar {
        padding: 0 !important;
    }
    
    .app-content,
    .club-header {
        margin-top: 0 !important;
    }
}

/* ========================================
   LEGACY COMPATIBILITY (Compatibilidad)
   ======================================== */

/* Old sidebar-toggle button support */
.sidebar-toggle {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 1001;
    width: 44px;
    height: 44px;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all var(--sidebar-transition);
}

.sidebar-toggle:hover {
    background: var(--sidebar-primary-light);
    border-color: var(--sidebar-primary);
    transform: scale(1.05);
}

.sidebar-toggle span {
    display: block;
    width: 20px;
    height: 2.5px;
    background: var(--sidebar-text);
    border-radius: 2px;
    transition: all var(--sidebar-transition);
}

.sidebar-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.sidebar-toggle.active span:nth-child(2) {
    opacity: 0;
    transform: translateX(-10px);
}

.sidebar-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* Hide old toggle when top-nav is present */
.has-top-nav .sidebar-toggle {
    display: none !important;
}

/* Mobile adjustments for legacy */
@media (max-width: 768px) {
    .sidebar-toggle {
        top: 12px;
        left: 12px;
        width: 40px;
        height: 40px;
    }
}

/* ========================================
   DARK MODE SUPPORT (Future)
   ======================================== */
@media (prefers-color-scheme: dark) {
    /* Placeholder for future dark mode */
}

/* ========================================
   ACCESSIBILITY
   ======================================== */
.sidebar-toggle:focus,
.top-nav-hamburger:focus,
.sidebar-close:focus,
.sidebar-link:focus {
    outline: 2px solid var(--sidebar-primary);
    outline-offset: 2px;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========================================
   TENANT NAME - Reusable class for club name
   Standard styling: 16px, weight 700, #1F2937
   Used in headers across all pages
   Exception: sidebar-brand-subtitle uses 12px in drawer context
   ======================================== */
.tenant-name {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: #1F2937;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
