/* ===========================================
   MEJORAS DE RESPONSIVIDAD MÓVIL
   =========================================== */

@media (max-width: 600px) {
    #membershipDebtForm {
        width: 96% !important;
        max-height: 94vh;
        overflow-y: auto;
        padding: 20px !important;
    }

    .membership-debt-actions {
        flex-direction: column-reverse;
    }

    .membership-debt-actions .btn {
        width: 100%;
    }

    .membership-debt-total {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }

    .membership-debt-note {
        min-height: 112px;
    }

    .membership-debt-stepper {
        width: 100%;
        max-width: none;
    }

    .membership-payment-modal {
        width: 96%;
        max-height: 94vh;
        padding: 18px;
    }

    .membership-payment-total {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }

    .membership-advance-options {
        grid-template-columns: 1fr;
    }

    .membership-payment-actions {
        flex-direction: column-reverse;
    }

    .membership-payment-actions .btn {
        width: 100%;
    }
}

/* IMPORTANTE: Este archivo SOLO agrega mejoras móviles
   NO modifica la lógica existente, solo estilos visuales */

/* ============================================
   MEJORAS GENERALES MÓVIL (máx 768px)
   ============================================ */
@media (max-width: 768px) {
    html {
        scroll-behavior: auto !important;
        overscroll-behavior-y: none;
    }

    body {
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
    }

    body::before {
        background-attachment: scroll !important;
    }

    .navbar {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
    
    /* ===== MODAL DE SELECCIÓN DE TIPO DE REGISTRO ===== */
    
    /* Contenedor principal del modal */
    #registration-type-modal > div {
        padding: 20px 15px !important;
        width: 96% !important;
        max-width: 96% !important;
        max-height: 95vh !important;
        overflow-y: auto !important;
        border-radius: 12px !important;
    }
    
    /* Encabezado */
    #registration-type-modal h2 {
        font-size: 1.65em !important;
        line-height: 1.2 !important;
        margin-bottom: 12px !important;
    }
    
    /* Subtítulo rojo con fondo */
    #registration-type-modal > div > div:first-child p {
        font-size: 1.05em !important;
        padding: 9px 15px !important;
        margin-bottom: 20px !important;
    }
    
    /* ===== OPCIÓN PRINCIPAL (VERDE - DEPORTISTA) ===== */
    #registration-type-modal button[onclick*="jugador"]:first-of-type {
        padding: 18px 15px !important;
        margin-bottom: 15px !important;
    }
    
    /* Badge "RECOMENDADO" */
    #registration-type-modal button[onclick*="jugador"]:first-of-type > div[style*="position: absolute"] {
        top: 8px !important;
        right: 8px !important;
        font-size: 0.6em !important;
        padding: 3px 8px !important;
    }
    
    /* Contenedor flex principal */
    #registration-type-modal button[onclick*="jugador"]:first-of-type > div:first-child {
        flex-direction: column !important;
        text-align: center !important;
        gap: 12px !important;
    }
    
    /* Icono de balón */
    #registration-type-modal button[onclick*="jugador"]:first-of-type > div:first-child > div:first-child {
        font-size: 54px !important;
    }
    
    /* Contenedor de texto */
    #registration-type-modal button[onclick*="jugador"]:first-of-type > div:first-child > div:last-child {
        text-align: center !important;
        min-width: auto !important;
    }
    
    /* Título DEPORTISTA */
    #registration-type-modal button[onclick*="jugador"]:first-of-type strong {
        font-size: 1.5em !important;
        line-height: 1.3 !important;
    }
    
    /* Descripción */
    #registration-type-modal button[onclick*="jugador"]:first-of-type p {
        font-size: 1.05em !important;
        line-height: 1.4 !important;
        margin-bottom: 12px !important;
    }
    
    /* Badge amarillo "Al finalizar obtendrás tu carnet" */
    #registration-type-modal button[onclick*="jugador"]:first-of-type > div:first-child > div:last-child > div {
        font-size: 0.95em !important;
        padding: 8px 16px !important;
    }
    
    /* ===== SEPARADOR ===== */
    #registration-type-modal > div > div[style*="position: relative"] {
        margin: 15px 0 12px 0 !important;
    }
    
    #registration-type-modal > div > div[style*="position: relative"] span {
        font-size: 1em !important;
    }
    
    /* ===== GRID DE OPCIONES SECUNDARIAS ===== */
    #registration-type-modal > div > div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
        margin-bottom: 15px !important;
    }
    
    /* ===== BOTONES SECUNDARIOS (MORADO, AZUL, NARANJA) ===== */
    #registration-type-modal button[onclick*="jugador_asociado"],
    #registration-type-modal button[onclick*="asociado"],
    #registration-type-modal button[onclick*="aficionado"] {
        padding: 15px 12px !important;
        min-height: auto !important;
    }
    
    /* Iconos en tarjetas secundarias */
    #registration-type-modal button[onclick*="jugador_asociado"] > div:first-child,
    #registration-type-modal button[onclick*="asociado"] > div:first-child,
    #registration-type-modal button[onclick*="aficionado"] > div:first-child {
        font-size: 44px !important;
        margin-bottom: 10px !important;
    }
    
    /* Títulos de tarjetas secundarias */
    #registration-type-modal button[onclick*="jugador_asociado"] strong,
    #registration-type-modal button[onclick*="asociado"] strong,
    #registration-type-modal button[onclick*="aficionado"] strong {
        font-size: 1.2em !important;
        min-height: auto !important;
        margin-bottom: 10px !important;
    }
    
    /* Descripciones principales */
    #registration-type-modal button[onclick*="jugador_asociado"] > p,
    #registration-type-modal button[onclick*="asociado"] > p,
    #registration-type-modal button[onclick*="aficionado"] > p {
        font-size: 0.95em !important;
        line-height: 1.45 !important;
        margin-bottom: 10px !important;
    }
    
    /* Badges internos semitransparentes */
    #registration-type-modal button[style*="padding: 18px"] > div[style*="background: rgba(255,255,255,0.25)"] {
        font-size: 0.88em !important;
        padding: 7px 11px !important;
        margin-bottom: 7px !important;
    }
    
    #registration-type-modal button[style*="padding: 18px"] > div[style*="background: rgba(255,255,255,0.15)"] {
        font-size: 0.84em !important;
        padding: 7px 11px !important;
        margin-bottom: 6px !important;
    }
    
    /* Badge amarillo final */
    #registration-type-modal button[style*="padding: 18px"] > div[style*="background: #ffeb3b"] {
        font-size: 0.78em !important;
        padding: 6px 11px !important;
    }
    
    /* ===== BOTÓN CANCELAR ===== */
    #registration-type-modal button[onclick*="navigateTo"] {
        margin-top: 8px !important;
        padding: 10px !important;
        font-size: 0.9em !important;
    }
    
    /* ===== MODAL DE ÁRBOL GENEALÓGICO ===== */
    
    /* Modal contenedor */
    #genealogy-choice-modal > div {
        padding: 18px 12px !important;
        width: 96% !important;
        max-width: 96% !important;
        max-height: 95vh !important;
    }
    
    /* Botón cerrar */
    #genealogy-choice-modal > div > button:first-child {
        top: 10px !important;
        right: 10px !important;
        width: 32px !important;
        height: 32px !important;
        font-size: 20px !important;
    }
    
    /* Encabezado flex (logo + texto) - Logo a la izquierda */
    #genealogy-choice-modal > div > div:first-of-type {
        flex-direction: row !important;
        align-items: flex-start !important;
        text-align: left !important;
        gap: 12px !important;
        margin-bottom: 18px !important;
    }
    
    /* Logo */
    #genealogy-choice-modal img {
        width: 60px !important;
        flex-shrink: 0 !important;
        margin-top: 2px !important;
    }
    
    /* Contenedor de texto del header */
    #genealogy-choice-modal > div > div:first-of-type > div {
        flex: 1 !important;
        text-align: left !important;
    }
    
    /* Título principal */
    #genealogy-choice-modal h2 {
        font-size: 1.1em !important;
        line-height: 1.3 !important;
        margin-bottom: 6px !important;
        text-align: left !important;
    }
    
    /* Subtítulo */
    #genealogy-choice-modal > div > div:first-of-type > div > p {
        font-size: 0.8em !important;
        line-height: 1.3 !important;
        text-align: left !important;
    }
    
    /* Tarjetas de opciones (ahora son botones) */
    #genealogy-choice-modal > div > div[style*="display: grid"] > button {
        padding: 12px !important;
    }
    
    /* Contenedor flex dentro de las tarjetas */
    #genealogy-choice-modal > div > div[style*="display: grid"] > button > div {
        flex-direction: row !important;
        align-items: center !important;
        text-align: left !important;
        gap: 12px !important;
    }
    
    /* Iconos circulares - contenedor */
    #genealogy-choice-modal button > div > div[style*="border-radius: 50%"],
    #genealogy-choice-modal button div[style*="width: 90px"][style*="height: 90px"] {
        width: 60px !important;
        height: 60px !important;
        gap: 0px !important;
        flex-direction: row !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-wrap: nowrap !important;
        flex-shrink: 0 !important;
    }
    
    /* Emojis individuales */
    #genealogy-choice-modal button > div > div[style*="border-radius: 50%"] span,
    #genealogy-choice-modal button div[style*="width: 90px"] span {
        font-size: 26px !important;
        line-height: 1 !important;
        display: inline-block !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Contenedor de texto dentro de tarjetas */
    #genealogy-choice-modal button > div > div:nth-child(2) {
        flex: 1 !important;
        text-align: left !important;
    }
    
    /* Títulos de tarjetas */
    #genealogy-choice-modal > div > div[style*="display: grid"] > button h3 {
        font-size: 1.5em !important;
        line-height: 1.2 !important;
        text-align: left !important;
        margin: 0 0 6px 0 !important;
    }
    
    /* Descripciones */
    #genealogy-choice-modal > div > div[style*="display: grid"] > button p {
        font-size: 1.05em !important;
        line-height: 1.4 !important;
        text-align: left !important;
        margin: 0 0 8px 0 !important;
    }
    
    /* Información de tiempo y personas */
    #genealogy-choice-modal > div > div[style*="display: grid"] > button > div > div:nth-child(2) > div {
        flex-direction: row !important;
        gap: 12px !important;
        font-size: 0.75em !important;
        flex-wrap: wrap !important;
    }
    
    #genealogy-choice-modal > div > div[style*="display: grid"] > button > div > div:nth-child(2) > div span {
        display: inline-block !important;
        white-space: nowrap !important;
    }
        gap: 8px !important;
        font-size: 0.85em !important;
    }
    
    /* Flecha en móvil - ocultar o hacer más pequeña */
    #genealogy-choice-modal > div > div[style*="display: grid"] > button > div > div:last-child {
        display: none !important;
    }
    
    /* ===== ÁRBOL GENEALÓGICO - PASO 3 (Tarjetas de familiares) ===== */
    
    /* Contenedor del árbol */
    #familyTree > div {
        padding: 20px 10px !important;
    }
    
    #familyTree h3 {
        font-size: 1.2em !important;
    }
    
    #familyTree p {
        font-size: 0.9em !important;
    }
    
    /* Tarjetas de familiares - hacer responsivas */
    #familyTree button[style*="min-width: 320px"] {
        min-width: 100% !important;
        max-width: 100% !important;
        width: 100% !important;
        padding: 15px 12px !important;
        min-height: 140px !important;
        font-size: 14px !important;
        box-sizing: border-box !important;
        display: block !important;
        text-align: center !important;
    }

    #familyTree button[style*="min-width: 320px"] strong,
    #familyTree button[style*="min-width: 320px"] div {
        max-width: 100% !important;
        word-break: normal !important;
        overflow-wrap: break-word !important;
        text-align: center !important;
    }
    
    /* Emojis dentro de las tarjetas */
    #familyTree button span[style*="font-size: 32px"],
    #familyTree button span[style*="font-size: 24px"] {
        font-size: 28px !important;
    }
    
    /* Textos dentro de las tarjetas */
    #familyTree button strong {
        font-size: 1em !important;
        word-break: break-word !important;
    }
    
    #familyTree button div[style*="font-size: 0.85em"],
    #familyTree button div[style*="font-size: 0.8em"] {
        font-size: 0.75em !important;
    }
    
    /* Flecha entre tarjetas */
    #familyTree > div > div > div[style*="font-size: 32px"] {
        font-size: 24px !important;
        margin: 10px 0 !important;
    }
    
    /* Tarjeta del jugador (azul) */
    #familyTree div[style*="background: #e3f2fd"] {
        padding: 15px !important;
    }
    
    #familyTree div[style*="background: #e3f2fd"] strong {
        font-size: 1em !important;
    }
    
    #familyTree div[style*="background: #e3f2fd"] span[style*="font-size: 32px"] {
        font-size: 28px !important;
    }

    #familyTree .family-member-content {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) !important;
        justify-items: center !important;
        width: 100% !important;
        gap: 10px !important;
    }

    #familyTree .family-member-text {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        text-align: center !important;
    }

    #familyTree .family-member-content .remove-btn {
        justify-self: center !important;
    }

    #familyTree .family-member-badges {
        width: 100% !important;
        text-align: center !important;
    }

    #familyTree .family-member-text h4,
    #familyTree .family-member-text p {
        width: 100% !important;
        white-space: normal !important;
        word-break: normal !important;
        overflow-wrap: break-word !important;
        text-align: center !important;
    }

    
    /* Botón cancelar */
    #genealogy-choice-modal > div > button[onclick*="remove"] {
        font-size: 0.95em !important;
        padding: 12px !important;
    }
    
    /* Nota de privacidad */
    #genealogy-choice-modal > div > div[style*="background: #e8f5e9"] {
        padding: 10px 12px !important;
        font-size: 0.85em !important;
    }
    
    /* Navbar más compacto */
    .navbar {
        padding: 15px 0;
    }
    
    .navbar-brand h1 {
        font-size: 22px !important;
    }
    
    .navbar .subtitle {
        font-size: 12px !important;
    }
    
    .navbar-menu {
        gap: 15px !important;
        flex-wrap: wrap;
        margin-top: 10px !important;
    }
    
    .nav-link {
        font-size: 14px !important;
        padding: 6px 12px !important;
    }

    #logoutLink {
        display: inline-flex;
        flex-basis: 100%;
        justify-content: center;
        margin-top: 2px;
    }
    
    /* Container más ajustado en móvil */
    .container {
        padding: 0 15px !important;
    }
    
    /* Modales más pequeños */
    .modal-content {
        width: 98% !important;
        max-width: none !important;
        border-radius: 8px !important;
        font-size: 14px !important;
    }
    
    .modal-header h2 {
        font-size: 1.1em !important;
    }
    
    .modal-close-btn {
        width: 32px !important;
        height: 32px !important;
        font-size: 20px !important;
    }
    
    /* Formularios más compactos */
    .form-group {
        margin-bottom: 15px !important;
    }
    
    .form-group label {
        font-size: 14px !important;
        margin-bottom: 5px !important;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px !important; /* 16px previene zoom en iOS */
        padding: 10px !important;
    }
    
    /* Botones más grandes para tocar fácil */
    .btn {
        min-height: 44px !important; /* Tamaño mínimo touch iOS */
        font-size: 15px !important;
        padding: 12px 20px !important;
    }
    
    /* Tablas con scroll horizontal */
    .table-container,
    .users-list {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        margin: 0 -15px !important;
        padding: 0 15px !important;
    }
    
    /* Tarjetas de requisitos más compactas */
    .requirement-item {
        padding: 12px !important;
        margin-bottom: 12px !important;
        font-size: 14px !important;
    }
    
    .requirement-item h4 {
        font-size: 15px !important;
        flex-wrap: wrap !important;
    }
    
    .requirement-item ul {
        font-size: 13px !important;
    }
    
    .requirement-item li {
        padding: 6px 0 !important;
    }
    
    /* Checkboxes más grandes para móvil */
    input[type="checkbox"] {
        min-width: 24px !important;
        min-height: 24px !important;
        width: 24px !important;
        height: 24px !important;
    }
    
    /* Etiquetas (badges) más pequeñas */
    .requirement-item h4 span[style*="padding"] {
        font-size: 0.65em !important;
        padding: 2px 6px !important;
    }
    
    /* Grid de 2 columnas en lugar de 3 */
    .registration-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* Wizard steps más compactos */
    .step-indicator {
        margin-bottom: 20px !important;
        padding-bottom: 15px !important;
        gap: 5px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        flex-wrap: nowrap !important;
    }
    
    .step {
        font-size: 11px !important;
        padding: 8px 10px !important;
        margin: 0 2px !important;
        white-space: nowrap !important;
        min-width: fit-content !important;
        flex: 0 1 auto !important;
    }
    
    /* Ocultar número en móvil para ahorrar espacio */
    .step::before {
        content: '';
        display: none;
    }
    
    .step[data-step="1"]::after {
        content: '✓ Datos';
    }
    
    .step[data-step="2"]::after {
        content: '📍 Distrito';
    }
    
    .step[data-step="3"]::after {
        content: '👨‍👩‍👧 Familia';
    }
    
    .step[data-step="4"]::after {
        content: '📋 Revisar';
    }
    
    /* Ocultar texto original */
    .step {
        font-size: 0 !important;
    }
    
    .step::after {
        font-size: 11px !important;
    }
    
    /* Barras de progreso más delgadas */
    div[style*="height: 8px"] {
        height: 6px !important;
    }
    
    /* Acciones del modal en columna */
    .modal-actions {
        flex-direction: column !important;
        gap: 10px !important;
    }
    
    .modal-actions .btn {
        width: 100% !important;
    }


/* ============================================
   MEJORAS ULTRA PEQUEÑO (máx 480px)
   ============================================ */
@media (max-width: 480px) {
    
    /* Modal de registro aún más compacto */
    #registration-type-modal > div {
        padding: 20px 15px !important;
        width: 98% !important;
    }
    
    #registration-type-modal h2 {
        font-size: 1.1em !important;
        margin-bottom: 10px !important;
    }
    
    /* Botón principal JUGADOR ultra compacto */
    #registration-type-modal button[onclick*="jugador"]:first-of-type {
        padding: 15px !important;
    }
    
    #registration-type-modal button[onclick*="jugador"]:first-of-type strong {
        font-size: 1.2em !important;
    }
    
    #registration-type-modal button[onclick*="jugador"]:first-of-type > div > div[style*="font-size: 64px"] {
        font-size: 48px !important;
    }
    
    /* Wizard steps aún más compactos */
    .step {
        font-size: 0 !important;
        padding: 6px 8px !important;
        margin: 0 1px !important;
    }
    
    .step::after {
        font-size: 10px !important;
    }
    
    /* Navbar en una sola columna */
    .navbar-content {
        flex-direction: column !important;
        align-items: flex-start !important;
    }
    
    .navbar-menu {
        width: 100% !important;
        justify-content: flex-start !important;
    }
    
    /* Títulos más pequeños */
    h1 {
        font-size: 1.5em !important;
    }
    
    h2 {
        font-size: 1.3em !important;
    }
    
    h3 {
        font-size: 1.1em !important;
    }
    
    h4 {
        font-size: 1em !important;
    }
    
    /* Padding reducido */
    .container {
        padding: 0 10px !important;
    }
    
    .modal-section {
        padding: 15px !important;
    }
    
    /* Grid de 1 columna en pantallas muy pequeñas */
    .registration-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Iconos más pequeños */
    .registration-option span[style*="font-size"] {
        font-size: 32px !important;
    }
}

/* ============================================
   MEJORAS DE ACCESIBILIDAD TOUCH
   ============================================ */

/* Aumentar área de toque para elementos interactivos */
@media (max-width: 768px) {
    /* NO forzar display en links del navbar, respetar JavaScript */
    a:not(.nav-link), button, label[for] {
        min-height: 44px !important;
        display: inline-flex !important;
        align-items: center !important;
    }
    
    /* Nav links SIN forzar display para que JavaScript pueda ocultarlos */
    .nav-link {
        min-height: 44px;
        align-items: center;
    }
    
    /* Evitar zoom en inputs en iOS */
    input[type="text"],
    input[type="email"],
    input[type="number"],
    input[type="tel"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important;
    }
    
    /* Mejorar scrolling táctil */
    * {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
}

/* ============================================
   ORIENTACIÓN LANDSCAPE EN MÓVIL
   ============================================ */
@media (max-width: 768px) and (orientation: landscape) {
    
    /* Reducir altura del navbar en landscape */
    .navbar {
        padding: 10px 0 !important;
    }
    
    .navbar-brand h1 {
        font-size: 18px !important;
    }
    
    .navbar .subtitle {
        display: none; /* Ocultar subtítulo en landscape para ahorrar espacio */
    }
    
    /* Modales con altura máxima en landscape */
    .modal-content {
        max-height: 85vh !important;
    }
}

/* ============================================
   FIX: PREVENIR SCROLL HORIZONTAL
   ============================================ */
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }
    
    * {
        max-width: 100% !important;
    }
    
    /* Permitir scroll solo en contenedores específicos */
    .table-container,
    .users-list,
    .modal-content {
        max-width: none !important;
    }
}

/* Línea familiar: tarjetas más legibles en pantallas pequeñas */
@media (max-width: 768px) {
    #registration-type-modal h2 {
        font-size: 1.8em !important;
    }

    #registration-type-modal button[onclick*="jugador"]:first-of-type strong {
        font-size: 1.65em !important;
    }

    #registration-type-modal button[onclick*="jugador"]:first-of-type p {
        font-size: 1.15em !important;
    }

    #registration-type-modal button[onclick*="jugador_asociado"] strong,
    #registration-type-modal button[onclick*="asociado"] strong,
    #registration-type-modal button[onclick*="aficionado"] strong {
        font-size: 1.35em !important;
    }

    #registration-type-modal button[onclick*="jugador_asociado"] > p,
    #registration-type-modal button[onclick*="asociado"] > p,
    #registration-type-modal button[onclick*="aficionado"] > p {
        font-size: 1.08em !important;
    }

    #familyTree > div > div:first-child p {
        font-size: 1em !important;
        line-height: 1.4 !important;
    }

    #familyTree button[style*="min-width: 320px"] {
        padding: 24px 18px !important;
        min-height: 190px !important;
        font-size: 18px !important;
    }

    #familyTree button[style*="min-width: 320px"] strong {
        font-size: 1.25em !important;
        line-height: 1.25 !important;
    }

    #familyTree button[style*="min-width: 320px"] span[style*="font-size"] {
        font-size: 40px !important;
        margin-bottom: 12px !important;
    }

    #familyTree button[style*="min-width: 320px"] div[style*="font-size"] {
        font-size: 1em !important;
        line-height: 1.35 !important;
    }

    #familyTree div[style*="background: #e3f2fd"] {
        padding: 22px !important;
    }

    #familyTree div[style*="background: #e3f2fd"] strong {
        font-size: 1.25em !important;
        line-height: 1.3 !important;
    }
}

/* ============================================
   MEJORAS PARA CARGA EN 3G/4G
   ============================================ */
@media (max-width: 768px) {
    
    /* Reducir sombras para mejor rendimiento */
    .modal-content,
    .btn,
    .navbar {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
    }
    
    /* Transiciones más rápidas */
    * {
        transition-duration: 0.2s !important;
    }

    #genealogy-choice-modal h3 {
        font-size: 24px !important;
        line-height: 1.2 !important;
    }

    #genealogy-choice-modal h3 + p {
        font-size: 17px !important;
        line-height: 1.4 !important;
    }
}
