/**
 * Optimizaciones Responsive Mobile - AjedrezMagno
 *
 * Mejoras para dispositivos móviles y tablets:
 * - Hamburger menu para navegación
 * - Tablas con scroll horizontal
 * - Botones touch-friendly
 * - Espaciado optimizado
 */

/* ========================================
   TABLAS RESPONSIVE (Scroll Horizontal)
   ======================================== */

/* Contenedor wrapper para tablas */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}

/* En móvil, agregar sombras para indicar scroll */
@media (max-width: 768px) {
    .table-responsive {
        box-shadow: inset -10px 0 8px -8px rgba(0, 0, 0, 0.15);
    }

    .table-responsive::-webkit-scrollbar {
        height: 8px;
    }

    .table-responsive::-webkit-scrollbar-track {
        background: #f1f1f1;
    }

    .table-responsive::-webkit-scrollbar-thumb {
        background: #888;
        border-radius: 4px;
    }

    .table-responsive::-webkit-scrollbar-thumb:hover {
        background: #555;
    }
}

/* ========================================
   BOTONES TOUCH-FRIENDLY
   ======================================== */

/* Incrementar tamaño mínimo de botones en móvil */
@media (max-width: 768px) {
    button,
    .btn,
    a.btn,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px !important;
        min-width: 44px !important;
        padding: 12px 20px !important;
        font-size: 16px !important;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    /* Botones pequeños (iconos, etc.) */
    .btn-sm,
    button.btn-sm {
        min-height: 36px !important;
        min-width: 36px !important;
        padding: 8px 14px !important;
        font-size: 14px !important;
    }

    /* Incrementar área touch de links */
    a {
        padding: 4px;
        margin: -4px;
    }

    /* Form inputs también más grandes */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    select,
    textarea {
        min-height: 44px !important;
        font-size: 16px !important;
        padding: 10px 14px !important;
    }
}

/* ========================================
   HAMBURGER MENU - Mobile Navigation
   ======================================== */

/* Botón hamburger (oculto en desktop) */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    margin: 0;
    position: relative;
    z-index: 1001;
}

.hamburger-icon {
    display: block;
    width: 28px;
    height: 20px;
    position: relative;
}

.hamburger-icon span {
    display: block;
    position: absolute;
    height: 3px;
    width: 100%;
    background: var(--text-primary, #2d3748);
    border-radius: 3px;
    opacity: 1;
    left: 0;
    transform: rotate(0deg);
    transition: all 0.25s ease-in-out;
}

.hamburger-icon span:nth-child(1) {
    top: 0px;
}

.hamburger-icon span:nth-child(2) {
    top: 8px;
}

.hamburger-icon span:nth-child(3) {
    top: 16px;
}

/* Animación cuando el menú está abierto */
.mobile-menu-btn.active .hamburger-icon span:nth-child(1) {
    top: 8px;
    transform: rotate(135deg);
}

.mobile-menu-btn.active .hamburger-icon span:nth-child(2) {
    opacity: 0;
    left: -60px;
}

.mobile-menu-btn.active .hamburger-icon span:nth-child(3) {
    top: 8px;
    transform: rotate(-135deg);
}

/* Panel del menú mobile */
.mobile-menu {
    display: none;
    position: fixed;
    top: 0;
    right: -100%;
    width: 280px;
    height: 100vh;
    background: var(--bg-secondary, #ffffff);
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    transition: right 0.3s ease-in-out;
    overflow-y: auto;
    padding: 80px 20px 20px 20px;
}

.mobile-menu.active {
    right: 0;
}

/* Overlay cuando el menú está abierto */
.mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.mobile-menu-overlay.active {
    opacity: 1;
}

/* Items del menú mobile */
.mobile-menu-items {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mobile-menu-item {
    display: block;
    padding: 14px 16px;
    background: var(--bg-card, #ffffff);
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-primary, #2d3748);
    font-weight: 500;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.mobile-menu-item:hover,
.mobile-menu-item:active {
    transform: translateX(-4px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.mobile-menu-item.danger {
    background: #fee;
    color: #c53030;
}

/* ========================================
   RESPONSIVE MOBILE (< 768px)
   ======================================== */

@media (max-width: 768px) {
    /* Mostrar botón hamburger */
    .mobile-menu-btn {
        display: block;
    }

    /* Mostrar panel mobile */
    .mobile-menu {
        display: block;
    }

    /* Ocultar navegación desktop en móvil (si existe) */
    .desktop-nav {
        display: none !important;
    }

    /* Ajustar padding del body para evitar scroll horizontal */
    body {
        overflow-x: hidden;
    }

    /* Containers más estrechos */
    .container {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    /* Cards en columna única */
    .cards-grid,
    .stats-grid {
        grid-template-columns: 1fr !important;
    }

    /* Reducir tamaños de fuente */
    h1 {
        font-size: 24px !important;
    }

    h2 {
        font-size: 20px !important;
    }

    h3 {
        font-size: 18px !important;
    }

    /* Modales a pantalla completa en móvil pequeño */
    @media (max-width: 480px) {
        .modal-box {
            min-height: 100vh;
            border-radius: 0;
        }
    }

    /* Forms: labels encima de inputs */
    form .form-group {
        flex-direction: column;
    }

    form label {
        margin-bottom: 8px;
        width: 100%;
    }

    form input,
    form select,
    form textarea {
        width: 100%;
    }

    /* Botones de acción apilados verticalmente */
    .action-buttons,
    .button-group {
        flex-direction: column;
        width: 100%;
    }

    .action-buttons button,
    .action-buttons .btn,
    .button-group button,
    .button-group .btn {
        width: 100%;
    }

    /* Navbar responsive */
    .navbar {
        flex-wrap: wrap;
        padding: 16px !important;
    }

    .navbar-actions {
        gap: 12px !important;
    }

    .user-info {
        display: none; /* Ocultar info de usuario en navbar móvil */
    }

    /* Toasts más pequeños en móvil */
    .toast {
        min-width: auto !important;
        max-width: calc(100vw - 20px) !important;
    }
}

/* ========================================
   TABLET (768px - 1024px)
   ======================================== */

@media (min-width: 768px) and (max-width: 1024px) {
    /* Cards en 2 columnas */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Container un poco más estrecho */
    .container {
        max-width: 95%;
    }
}

/* ========================================
   LANDSCAPE MOBILE
   ======================================== */

@media (max-height: 500px) and (orientation: landscape) {
    /* Reducir altura de modales en landscape */
    .modal-box {
        max-height: 90vh;
        overflow-y: auto;
    }

    /* Reducir padding vertical */
    .modal-header,
    .modal-body,
    .modal-footer {
        padding-top: 12px;
        padding-bottom: 12px;
    }

    /* Iconos más pequeños */
    .modal-icon {
        width: 48px;
        height: 48px;
        font-size: 24px;
    }
}

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

@media print {
    /* Ocultar elementos no necesarios en impresión */
    .navbar,
    .mobile-menu-btn,
    .mobile-menu,
    .mobile-menu-overlay,
    .toast-container,
    .modal-overlay,
    button,
    .btn {
        display: none !important;
    }

    /* Optimizar para impresión */
    body {
        background: white !important;
        color: black !important;
    }

    .card,
    .stat-card {
        break-inside: avoid;
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
}
