/* FIXED VERSION: Complete UBS Lineup CSS with proper containment */

/* ==========================================================================
   CONTAINER FIXES - Prevent all overflow issues
   ========================================================================== */

.ubs-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    
    /* CRITICAL: Prevent horizontal overflow */
    overflow-x: hidden;
    box-sizing: border-box;
    width: 100%;
}

.ubs-full-width-container {
    max-width: 100%;
    padding: 0;
    margin: 0 auto;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* ==========================================================================
   GRID LAYOUT FIXES
   ========================================================================== */

.ubs-grid-section {
    display: flex;
    flex-wrap: wrap;
    gap: 30px;
    
    /* CRITICAL: Prevent grid from overflowing */
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.ubs-main-content {
    flex: 1 1 60%;
    min-width: 300px;
    max-width: 100%;
    background: #fff;
    padding: 35px;
    border-radius: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    
    /* CRITICAL: Proper containment */
    overflow: hidden;
    box-sizing: border-box;
}

.ubs-sidebar {
    flex: 0 0 360px;
    width: 360px;
    max-width: 100%;
    box-sizing: border-box;
}

/* ==========================================================================
   LINEUP SECTION FIXES - Keep within main content area
   ========================================================================== */

.ubs-lineup-section {
    background: #ffffff;
    padding: 35px;
    border-radius: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    margin: 30px 0;
    border: 1px solid #e2e8f0;
    
    /* CRITICAL: Ensure lineup sections stay contained */
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
    
    /* FIXED: Ensure this appears within main content flow */
    position: relative;
    z-index: 1;
}

.ubs-last5-section {
    background: #ffffff;
    padding: 35px;
    border-radius: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    margin: 30px 0;
    border: 1px solid #e2e8f0;
    
    /* CRITICAL: Proper containment */
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
}

/* ==========================================================================
   LINEUP DISPLAY FIXES
   ========================================================================== */

.ubs-lineups-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin: 25px 0;
    
    /* CRITICAL: Prevent grid overflow */
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.ubs-team-lineup {
    background: linear-gradient(to bottom, #f8f9fa 0%, #ffffff 100%);
    padding: 25px;
    border-radius: 15px;
    border: 1px solid #e2e8f0;
    
    /* CRITICAL: Ensure proper containment */
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
    min-width: 0; /* Important for flex/grid children */
}

.ubs-formation-display-enhanced {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 20px;
    background: linear-gradient(to bottom, #1a5f1a 0%, #2d7a2d 100%);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    
    /* CRITICAL: Prevent formation from overflowing */
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
}

.ubs-formation-display-enhanced::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(90deg, rgba(255,255,255,0.1) 1px, transparent 1px),
        linear-gradient(rgba(255,255,255,0.1) 1px, transparent 1px);
    background-size: 50px 50px;
    pointer-events: none;
}

.ubs-formation-line {
    display: flex;
    justify-content: space-around;
    align-items: center;
    position: relative;
    z-index: 1;
    
    /* CRITICAL: Better responsive behavior */
    flex-wrap: wrap;
    gap: 10px;
    min-height: 60px;
    
    /* CRITICAL: Prevent line overflow */
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.ubs-player-card-enhanced {
    background: linear-gradient(145deg, #ffffff 0%, #f8fafc 100%);
    border-radius: 12px;
    padding: 12px;
    text-align: center;
    
    /* CRITICAL: Responsive width instead of fixed min-width */
    min-width: 80px;
    max-width: 140px;
    flex: 1;
    
    border: 2px solid #e2e8f0;
    transition: all 0.3s ease;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    position: relative;
    overflow: hidden;
    
    /* CRITICAL: Ensure proper box sizing */
    box-sizing: border-box;
}

.ubs-player-card-enhanced::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--ubs-primary-color, #0073aa);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.ubs-player-card-enhanced:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 8px 20px rgba(0,0,0,0.2);
    border-color: var(--ubs-primary-color, #0073aa);
}

.ubs-player-card-enhanced:hover::before {
    opacity: 1;
}

.ubs-player-card-enhanced.high {
    border-color: #16a34a;
}

.ubs-player-card-enhanced.medium {
    border-color: #f59e0b;
}

.ubs-player-card-enhanced.low {
    border-color: #ef4444;
}

/* ==========================================================================
   PLAYER PHOTO AND IMAGE FIXES
   ========================================================================== */

.ubs-player-photo-container {
    margin-bottom: 8px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 54px; /* Ensure consistent height */
}

.ubs-player-photo-small {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255,255,255,0.8);
    transition: all 0.3s ease;
    display: block;
}

.ubs-player-initials {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ubs-primary-color, #0073aa) 0%, var(--ubs-secondary-color, #00a0d2) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    border: 2px solid rgba(255,255,255,0.8);
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.ubs-player-card-enhanced:hover .ubs-player-photo-small,
.ubs-player-card-enhanced:hover .ubs-player-initials {
    transform: scale(1.1);
    border-color: var(--ubs-primary-color, #0073aa);
}

.ubs-player-number {
    font-weight: bold;
    color: var(--ubs-primary-color, #0073aa);
    font-size: 0.9em;
    margin-bottom: 4px;
}

.ubs-player-name {
    font-size: 0.85em;
    font-weight: 600;
    margin: 4px 0;
    color: #1f2937;
    line-height: 1.2;
    
    /* CRITICAL: Handle long names */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ubs-player-meta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.ubs-player-position {
    font-size: 0.75em;
    color: #6b7280;
    text-transform: uppercase;
    font-weight: 500;
}

.ubs-player-flag {
    width: 16px;
    height: auto;
    border-radius: 2px;
    border: 1px solid rgba(0,0,0,0.1);
}

/* ==========================================================================
   LINEUP HEADER AND METADATA
   ========================================================================== */

.ubs-lineup-team-name {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    font-size: 1.2em;
    font-weight: bold;
    
    /* CRITICAL: Handle long team names */
    flex-wrap: wrap;
    gap: 10px;
}

.ubs-formation-badge {
    background: var(--ubs-primary-color, #0073aa);
    color: white;
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 0.8em;
    white-space: nowrap;
}

.ubs-lineup-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8em;
    font-weight: 700;
    text-transform: uppercase;
    margin-left: 10px;
}

.ubs-lineup-badge.confirmed {
    background-color: #16a34a;
    color: white;
}

.ubs-lineup-badge.predicted {
    background-color: #f59e0b;
    color: white;
}

.ubs-lineup-analysis {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
    border-left: 4px solid var(--ubs-primary-color, #0073aa);
    
    /* CRITICAL: Ensure proper containment */
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.ubs-lineup-disclaimer {
    background: #f0f9ff;
    padding: 15px;
    border-radius: 8px;
    margin-top: 20px;
    border-left: 4px solid #0ea5e9;
    font-size: 0.9em;
    
    /* CRITICAL: Ensure proper containment */
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

/* ==========================================================================
   RESPONSIVE DESIGN - Mobile First Approach
   ========================================================================== */

@media (max-width: 1024px) {
    .ubs-main-content,
    .ubs-sidebar {
        flex-basis: 100%;
        width: 100%;
        max-width: 100%;
    }
    
    .ubs-sidebar-card {
        position: relative;
        top: auto;
        margin-top: 30px;
    }
    
    .ubs-grid-section {
        flex-direction: column;
        gap: 20px;
    }
}

@media (max-width: 768px) {
    .ubs-container {
        padding: 15px;
    }
    
    .ubs-lineup-section,
    .ubs-last5-section {
        padding: 25px;
        margin: 20px 0;
    }
    
    .ubs-main-content {
        padding: 25px;
    }
    
    .ubs-lineups-container {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .ubs-team-lineup {
        padding: 20px;
    }
    
    .ubs-formation-display-enhanced {
        padding: 15px;
        gap: 12px;
    }
    
    .ubs-formation-line {
        gap: 8px;
        justify-content: center;
    }
    
    .ubs-player-card-enhanced {
        min-width: 70px;
        max-width: 100px;
        padding: 8px;
    }
    
    .ubs-player-photo-small,
    .ubs-player-initials {
        width: 40px;
        height: 40px;
    }
    
    .ubs-player-initials {
        font-size: 14px;
    }
    
    .ubs-player-name {
        font-size: 0.8em;
    }
    
    .ubs-player-number {
        font-size: 0.8em;
    }
    
    .ubs-player-position {
        font-size: 0.7em;
    }
    
    .ubs-lineup-team-name {
        font-size: 1.1em;
        text-align: center;
        flex-direction: column;
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .ubs-container {
        padding: 10px;
    }
    
    .ubs-lineup-section,
    .ubs-last5-section {
        padding: 20px;
        margin: 15px 0;
    }
    
    .ubs-main-content {
        padding: 20px;
    }
    
    .ubs-formation-display-enhanced {
        padding: 12px;
        gap: 10px;
    }
    
    .ubs-formation-line {
        gap: 6px;
    }
    
    .ubs-player-card-enhanced {
        min-width: 60px;
        max-width: 80px;
        padding: 6px;
    }
    
    .ubs-player-photo-small,
    .ubs-player-initials {
        width: 35px;
        height: 35px;
    }
    
    .ubs-player-initials {
        font-size: 12px;
    }
    
    .ubs-player-name {
        font-size: 0.75em;
    }
    
    .ubs-player-number {
        font-size: 0.75em;
    }
    
    .ubs-player-position {
        font-size: 0.65em;
    }
}

/* ==========================================================================
   ANIMATION AND LOADING STATES
   ========================================================================== */

.ubs-player-card-enhanced {
    animation: slideInUp 0.6s ease forwards;
    opacity: 0;
    transform: translateY(20px);
}

.ubs-formation-line[data-line="0"] .ubs-player-card-enhanced { 
    animation-delay: 0.1s; 
}
.ubs-formation-line[data-line="1"] .ubs-player-card-enhanced { 
    animation-delay: 0.2s; 
}
.ubs-formation-line[data-line="2"] .ubs-player-card-enhanced { 
    animation-delay: 0.3s; 
}
.ubs-formation-line[data-line="3"] .ubs-player-card-enhanced { 
    animation-delay: 0.4s; 
}

@keyframes slideInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   IMAGE FALLBACK STYLES
   ========================================================================== */

.ubs-team-logo {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    background: rgba(255,255,255,0.1);
    transition: all 0.2s ease;
    object-fit: contain;
    display: block;
}

.ubs-player-photo,
.ubs-player-photo-small {
    max-width: 100%;
    height: auto;
    border-radius: 50%;
    object-fit: cover;
    transition: all 0.2s ease;
    background: rgba(255,255,255,0.1);
    display: block;
}

/* Loading state for images */
.ubs-team-logo,
.ubs-player-photo,
.ubs-player-photo-small {
    opacity: 0;
    animation: ubs-image-fade-in 0.3s ease forwards;
}

@keyframes ubs-image-fade-in {
    to {
        opacity: 1;
    }
}

/* ==========================================================================
   PRINT STYLES
   ========================================================================== */

@media print {
    .ubs-lineup-section,
    .ubs-last5-section {
        box-shadow: none;
        border: 1px solid #000;
        page-break-inside: avoid;
    }
    
    .ubs-player-card-enhanced {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .ubs-formation-display-enhanced {
        background: #f0f0f0 !important;
    }
}

/* ==========================================================================
   ACCESSIBILITY IMPROVEMENTS
   ========================================================================== */

.ubs-player-card-enhanced:focus-visible {
    outline: 3px solid var(--ubs-primary-color, #0073aa);
    outline-offset: 2px;
}

.ubs-player-card-enhanced:focus:not(:focus-visible) {
    outline: none;
}

/* High contrast mode adjustments */
@media (prefers-contrast: high) {
    .ubs-player-card-enhanced {
        border-width: 2px !important;
    }
    
    .ubs-formation-badge {
        border: 2px solid currentColor !important;
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .ubs-player-card-enhanced,
    .ubs-player-photo-small,
    .ubs-player-initials {
        animation: none !important;
        transition: none !important;
    }
    
    .ubs-player-card-enhanced:hover {
        transform: none !important;
    }
}

/* ==========================================================================
   DARK MODE SUPPORT
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .ubs-lineup-section,
    .ubs-last5-section {
        background: #1f2937;
        color: #f9fafb;
        border-color: #374151;
    }
    
    .ubs-player-card-enhanced {
        background: #374151;
        color: #f9fafb;
        border-color: #4b5563;
    }
    
    .ubs-team-lineup {
        background: #1f2937;
        border-color: #374151;
    }
    
    .ubs-lineup-analysis {
        background: #374151;
        color: #f9fafb;
    }
    
    .ubs-lineup-disclaimer {
        background: #1e40af;
        color: #f9fafb;
    }
}
