/* ===== VARIABLES ===== */
:root {
    --sidebar-width: 260px;
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --dark-bg: #0f172a;
    --dark-surface: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --body-bg: #f1f5f9;
    --card-bg: #ffffff;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 0.375rem;
    --radius: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
}

/* ===== GLOBAL ===== */
* {
    box-sizing: border-box;
}

body {
    background-color: var(--body-bg);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 0.85rem;
    line-height: 1.5;
    color: #1e293b;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden; /* <--- AGREGAR ESTO: Evita scroll lateral global */
}

/* ===== TYPOGRAPHY ===== */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: #0f172a;
    line-height: 1.3;
}

.h1, .h2, .h3, .h4, .h5, .h6 {
    font-weight: 600;
}

/* ===== LOGIN ===== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    position: relative;
}

.login-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    opacity: 0.5;
}

.login-box {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0,0,0,0.05);
    width: 100%;
    max-width: 420px;
    position: relative;
    z-index: 1;
}

.login-box .form-control {
    background-color: #f8fafc;
    border-color: #e2e8f0;
}

.login-box .form-control:focus {
    background-color: #ffffff;
    border-color: var(--primary-color);
}

/* ===== MOBILE HEADER (Updated) ===== */
.mobile-header {
    display: none; /* Oculto en escritorio */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 60px; /* Ligeramente más alto para mejor touch target */
    background-color: #0f172a;
    z-index: 1040;
    padding: 0 16px;
    border-bottom: 1px solid #334155;
    box-sizing: border-box;
    /* Flexbox para alinear elementos */
    align-items: center;
    justify-content: space-between; /* Botón izq, Título der */
}

/* Marca (Título) */
.mobile-header .brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #f8fafc;
    font-weight: 600;
    font-size: 1.125rem;
    text-decoration: none;
    height: 100%;
    flex-shrink: 0; /* Evitar que se encoja demasiado */
}

.mobile-header .brand i {
    color: #2563eb;
    font-size: 1.25rem;
}

/* Botón Hamburguesa */
.btn-menu-toggle {
    display: none; /* Se activa en media query */
    background: transparent;
    border: none;
    color: #ffffff !important;
    font-size: 1.75rem;
    padding: 8px;
    cursor: pointer;
    border-radius: 6px;
    line-height: 1;
    min-width: 48px;  /* Área táctil mínima */
    min-height: 48px;
    justify-content: center;
    align-items: center;
    z-index: 1070; /* Por encima de todo */
}

.btn-menu-toggle:hover,
.btn-menu-toggle:focus {
    background-color: rgba(255, 255, 255, 0.1);
    outline: none;
}

/* ===== SIDEBAR OVERLAY ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1049;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(2px);
    width: 100%; /* <--- CAMBIAR: Si tenías 100vw, cámbialo a 100% */
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

/* ===== SIDEBAR ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--dark-bg);
    z-index: 1050;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 1.25rem;
}

.sidebar-brand i {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.sidebar-brand:hover {
    color: var(--text-primary);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
}

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

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

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

.nav-section {
    margin-bottom: 1.5rem;
}

.nav-section-title {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0 0.75rem;
    margin-bottom: 0.5rem;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    color: var(--text-secondary);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s ease;
    margin-bottom: 0.125rem;
}

.sidebar .nav-link i {
    font-size: 1.125rem;
    width: 1.25rem;
    text-align: center;
    opacity: 0.8;
}

.sidebar .nav-link:hover {
    background-color: var(--dark-surface);
    color: var(--text-primary);
}

.sidebar .nav-link:hover i {
    opacity: 1;
}

.sidebar .nav-link.active {
    background-color: var(--primary-color);
    color: #ffffff;
}

.sidebar .nav-link.active i {
    opacity: 1;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    background: var(--dark-surface);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

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

.sidebar-user-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ===== MAIN CONTENT ===== */
.main-wrapper {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    min-width: 0; /* <--- FIX CRÍTICO: Permite que el contenedor se encoja en móviles */
    width: 100%;  /* <--- Asegura que ocupe el ancho disponible */
}

.main-content .container-fluid {
    padding: 1.5rem 2rem;
    max-width: 1600px;
}

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e2e8f0;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
    color: #0f172a;
}

.page-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ===== CARDS ===== */
.card {
    background: var(--card-bg);
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow);
    transform: none;
}

.card-header {
    padding: 0.75rem 1rem; /* Más compacto */
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.card-body {
    padding: 1rem;
}

.card-footer {
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    padding: 1rem 1.25rem;
}

/* Stats Cards */
.stat-card {
    position: relative;
    overflow: hidden;
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1;
}

.stat-card .stat-label {
    font-size: 0.8125rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ===== TABLES ===== */
.table {
    margin-bottom: 0;
}

.table > :not(caption) > * > * {
    padding: 0.5rem 0.75rem; /* Antes era 0.875rem 1rem */
    font-size: 0.85rem;
}

.table > thead {
    background-color: #f8fafc;
}

.table > thead th {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom-width: 1px;
}

.table-hover tbody tr {
    transition: background-color 0.15s ease;
}

.table-hover tbody tr:hover {
    background-color: #f8fafc;
}

/* ===== BUTTONS ===== */
.btn {
    font-weight: 500;
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-outline-primary {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-outline-primary:hover {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon.btn-sm {
    width: 32px;
    height: 32px;
}

/* ===== BADGES ===== */
.badge {
    font-weight: 600;
    font-size: 0.65rem;       /* Más pequeño (era 0.75rem) */
    padding: 0.35em 0.6em;    /* Padding más ajustado */
    border-radius: 4px;       /* Menos redondeado, más técnico */
    text-transform: uppercase; /* Letras mayúsculas */
    letter-spacing: 0.5px;    /* Espaciado para legibilidad */
    vertical-align: middle;
}

.badge-success {
    background-color: #dcfce7;
    color: #166534;
}

.badge-warning {
    background-color: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background-color: #fee2e2;
    color: #991b1b;
}

.badge-info {
    background-color: #dbeafe;
    color: #1e40af;
}

.badge-secondary {
    background-color: #f1f5f9;
    color: #475569;
}

/* ===== MODALS ===== */
.modal-content {
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ===== ALERTS ===== */
.alert {
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
}

.alert-success {
    background-color: #dcfce7;
    color: #166534;
}

.alert-warning {
    background-color: #fef3c7;
    color: #92400e;
}

.alert-danger {
    background-color: #fee2e2;
    color: #991b1b;
}

.alert-info {
    background-color: #dbeafe;
    color: #1e40af;
}

/* ===== FORMS ===== */
.form-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.375rem;
}

.form-control, .form-select {
    font-size: 0.875rem;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius);
    border-color: #d1d5db;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

.form-control::placeholder {
    color: #9ca3af;
}

.input-group-text {
    font-size: 0.875rem;
    background-color: #f9fafb;
    border-color: #d1d5db;
}

.form-switch .form-check-input {
    width: 2.5rem;
    height: 1.25rem;
}

/* ===== TABS ===== */
.nav-tabs {
    border-bottom: 1px solid #e2e8f0;
    gap: 0.25rem;
}

.nav-tabs .nav-link {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.875rem;
    padding: 0.75rem 1rem;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    transition: all 0.15s ease;
}

.nav-tabs .nav-link:hover {
    color: var(--primary-color);
    border-color: transparent;
}

.nav-tabs .nav-link.active {
    color: var(--primary-color);
    background: transparent;
    border-bottom-color: var(--primary-color);
}

/* ===== POLY RESULT CARDS ===== */
.poly-result-card {
    border: 1px solid #e2e8f0;
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--card-bg);
}

.poly-result-card:hover {
    border-color: var(--primary-color);
    background-color: #f8fafc;
}

.poly-result-card.selected {
    border-color: var(--primary-color);
    background-color: #eff6ff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ===== SOFASCORE IMPORT ===== */
.sofascore-match-item {
    border: 1px solid #e2e8f0;
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    transition: all 0.15s ease;
}

.sofascore-match-item:hover {
    background-color: #f8fafc;
    border-color: #cbd5e1;
}

/* ===== SPINNER ===== */
.spinner-border {
    width: 1.5rem;
    height: 1.5rem;
}

.spinner-border-sm {
    width: 1rem;
    height: 1rem;
}

/* ===== UTILITIES ===== */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.bg-gradient-dark {
    background: linear-gradient(135deg, var(--dark-bg) 0%, var(--dark-surface) 100%);
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h5 {
    color: #374151;
    margin-bottom: 0.5rem;
}

/* ===== LOADING ===== */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: inherit;
}

/* ===== TOAST ===== */
.toast-container {
    z-index: 1100;
}

.toast {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

/* ===== DROPDOWN ===== */
.dropdown-menu {
    border: 1px solid #e2e8f0;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0.5rem;
}

.dropdown-item {
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

.dropdown-item:hover {
    background-color: #f1f5f9;
}

.dropdown-menu-dark {
    background-color: var(--dark-surface);
    border-color: var(--border-color);
}

.dropdown-menu-dark .dropdown-item {
    color: var(--text-secondary);
}

.dropdown-menu-dark .dropdown-item:hover {
    background-color: var(--dark-bg);
    color: var(--text-primary);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 991.98px) {
    .main-content .container-fluid {
        padding: 1.25rem 1.5rem;
    }
}

@media (max-width: 767.98px) {
    .mobile-header {
        display: flex !important; /* Force flex display */
    }

    .btn-menu-toggle {
        display: flex !important; /* Visible on mobile */
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .sidebar-header {
        display: none;
    }

    .sidebar-nav {
        padding-top: 6rem;
    }

    .main-content {
        margin-left: 0;
        padding-top: 60px; /* Adjust for header height */
    }

    .main-content .container-fluid {
        padding: 1rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .page-title {
        font-size: 1.25rem;
    }

    .card-body {
        padding: 1rem;
    }

    .table-responsive {
        margin: 0 -1rem;
        padding: 0 1rem;
    }

    .btn {
        padding: 0.625rem 1rem;
    }

    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-body {
        padding: 1rem;
    }

    /* Hide text on small buttons in mobile */
    .btn-mobile-icon .btn-text {
        display: none;
    }
}

@media (max-width: 575.98px) {
    .stat-card .stat-value {
        font-size: 1.5rem;
    }

    .stat-card .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from { transform: translateY(-10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.fade-in {
    animation: fadeIn 0.2s ease;
}

.slide-in {
    animation: slideIn 0.3s ease;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* FIX PARA MODALS EN MÓVIL */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 0.5rem; /* Margen pequeño alrededor */
        max-width: calc(100% - 1rem); /* Asegurar que no se salga */
        height: calc(100% - 1rem); /* Altura casi completa pero con margen */
        display: flex;
        align-items: center; /* Centrar verticalmente si es pequeño */
    }

    .modal-content {
        max-height: 95vh; /* Nunca más alto que la pantalla */
        display: flex;
        flex-direction: column; /* Estructura flexible vertical */
        width: 100%;
    }

    .modal-header, .modal-footer {
        flex-shrink: 0; /* Evita que header/footer se aplasten */
        padding: 0.75rem 1rem; /* Header más compacto */
    }

    .modal-body {
        overflow-y: auto; /* IMPORTANTE: El scroll ocurre SOLO aquí dentro */
        flex: 1 1 auto;   /* Ocupa el espacio restante */
        padding: 1rem;
    }
    
    /* Ajuste para el título del modal en móvil */
    .modal-title {
        font-size: 1rem;
        line-height: 1.2;
    }
}