/* Mobile Responsive Fixes for CARDMATRIX */

/* Prevent iOS zoom on input focus - CRITICAL FIX */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="search"],
input[type="url"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"],
input[type="week"],
textarea,
select {
    font-size: 16px !important; /* iOS won't zoom if >= 16px */
    -webkit-appearance: none;
    appearance: none;
    border-radius: 0.5rem;
}

/* Touch-friendly buttons */
button,
.btn,
input[type="submit"],
input[type="button"],
a.btn {
    min-height: 44px !important; /* Apple's recommended touch target */
    padding: 0.75rem 1.5rem !important;
    font-size: 16px !important;
    -webkit-tap-highlight-color: rgba(245, 158, 11, 0.2);
}

/* Avoid forcing tiny admin/nav controls to full-width min widths */
.mobile-menu-toggle,
.nav-links .nav-link {
    min-width: 0 !important;
}

/* Mobile menu improvements */
@media (max-width: 768px) {
    /* Prevent body scroll when menu is open */
    body.menu-open {
        overflow: hidden;
    }
    
    /* Better mobile navigation */
    .nav-links.has-mobile-toggle {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }
    
    .nav-links.has-mobile-toggle.active {
        max-height: 80vh;
        overflow-y: auto;
    }
    
    /* Full width forms on mobile */
    form {
        width: 100%;
        max-width: 100%;
    }
    
    /* Better form spacing */
    .form-group,
    form > div {
        margin-bottom: 1.5rem;
    }
    
    /* Tables - horizontal scroll */
    .table-wrapper,
    .admin-table-scroll,
    [class*="-table-wrap"] {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        width: 100%;
        max-width: 100%;
    }
    
    /* Do NOT force every table to expand the page width */
    table {
        min-width: 0;
    }
    
    /* Card grids - responsive */
    .cards-grid,
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    
    /* Statistics cards — keep 2 columns on phones, don't force 1fr for dashboard stats */
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    [style*="grid-template-columns: repeat(auto-fit"] {
        grid-template-columns: 1fr !important;
    }
    
    /* Better padding on mobile */
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    section {
        padding: 1.5rem 0;
    }
    
    /* Modal improvements */
    .modal-content {
        width: 95%;
        margin: 1rem auto;
        padding: 1.5rem;
    }
    
    /* Better text sizing */
    h1 { font-size: 1.75rem !important; }
    h2 { font-size: 1.5rem !important; }
    h3 { font-size: 1.25rem !important; }
    
    /* Admin panel fixes */
    .admin-stats-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Better spacing for mobile */
    .section {
        padding: 1rem 0;
    }
}

/* Tablet responsive behavior */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }

    .cards-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr 1fr !important;
    }

    [style*="grid-template-columns: repeat(auto-fit"],
    [style*="grid-template-columns: repeat(auto-fill"] {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    table {
        width: 100%;
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    h1 { font-size: 1.5rem !important; }
    h2 { font-size: 1.25rem !important; }
    h3 { font-size: 1.125rem !important; }
    
    .cards-grid {
        grid-template-columns: 1fr !important;
    }
    
    button,
    .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    body.admin-body button,
    body.admin-body .btn {
        width: auto;
        margin-bottom: 0.35rem;
    }

    body.admin-body .btn.btn-primary[type="submit"],
    body.admin-body form > .btn.btn-primary,
    body.admin-body .submit-btn {
        width: 100%;
    }
}

/* Landscape orientation */
@media (max-width: 768px) and (orientation: landscape) {
    .navbar {
        padding: 0.5rem 0;
    }
    
    .hero-title {
        font-size: 1.5rem !important;
    }
}

/* Prevent text size adjustment on iOS */
html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Better focus states for touch devices */
input:focus,
textarea:focus,
select:focus,
button:focus {
    outline: 2px solid var(--primary, #f59e0b);
    outline-offset: 2px;
}

/* Disable pull-to-refresh on mobile (optional) */
body {
    overscroll-behavior-y: contain;
}
