/* 
 * StudyHub Library - Comprehensive Mobile Optimizations
 * Optimized for Android, iOS, and Tablet devices
 * Author: AI Assistant
 * Version: 1.0
 */

/* ===== GLOBAL MOBILE OPTIMIZATIONS ===== */

/* Prevent zoom on iOS Safari */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    input, textarea, select {
        font-size: 16px !important;
        -webkit-appearance: none;
        -webkit-border-radius: 8px;
        border-radius: 8px;
    }
}

/* Touch-friendly elements */
.btn, button, a, .nav-link, .facility-card, .plan-card, 
.payment-method, .clickable-card, .stat-card {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(37, 99, 235, 0.2);
}

/* Disable text selection on UI elements */
.btn, button, .nav-link, .logo, .hamburger {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Enable text selection for content */
input, textarea, [contenteditable], p, span, div.content {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Smooth scrolling for all devices */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Prevent horizontal scroll */
body {
    overflow-x: hidden;
    position: relative;
}

/* ===== SAFE AREA SUPPORT (iPhone X+) ===== */
@supports (padding: max(0px)) {
    .header, .hero, .footer {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
    
    .container {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
}

/* ===== TABLET OPTIMIZATIONS (769px - 1024px) ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    /* Navigation */
    .nav-menu {
        gap: 1.5rem;
    }
    
    /* Hero Section */
    .hero-content h1 {
        font-size: 3rem;
    }
    
    .hero-stats {
        gap: 1.5rem;
    }
    
    /* Grid Layouts */
    .facilities-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
    
    .plans-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
    
    .testimonials-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Forms */
    .register-form {
        padding: 2.5rem;
    }
    
    .form-row {
        grid-template-columns: 1fr 1fr;
    }
    
    /* Modals */
    .modal-content {
        max-width: 600px;
    }
    
    /* Cards */
    .card {
        padding: 2.5rem;
    }
}

/* ===== MOBILE OPTIMIZATIONS (max-width: 768px) ===== */
@media (max-width: 768px) {
    /* Typography */
    h1 {
        font-size: 2rem !important;
        line-height: 1.2 !important;
    }
    
    h2 {
        font-size: 1.5rem !important;
    }
    
    h3 {
        font-size: 1.3rem !important;
    }
    
    /* Navigation */
    .hamburger {
        display: flex !important;
    }
    
    .nav-menu {
        position: fixed;
        left: -100%;
        top: 70px;
        flex-direction: column;
        background-color: white;
        width: 100%;
        text-align: center;
        transition: 0.3s;
        box-shadow: 0 4px 20px rgba(0,0,0,0.1);
        padding: 2rem 0;
        z-index: 999;
    }
    
    .nav-menu.active {
        left: 0;
    }
    
    .nav-link {
        padding: 12px 20px;
        display: block;
        width: 100%;
    }
    
    /* Hero Section */
    .hero {
        padding: 80px 20px 50px;
        min-height: 100vh;
    }
    
    .hero-content {
        grid-template-columns: 1fr !important;
        text-align: center;
        gap: 2rem;
    }
    
    .hero-stats {
        justify-content: center;
        flex-wrap: wrap;
        gap: 1rem;
    }
    
    .hero-buttons {
        flex-direction: column !important;
        align-items: center !important;
        gap: 1rem;
    }
    
    .hero-buttons a {
        width: 200px !important;
        text-align: center !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Grid Layouts */
    .facilities-grid,
    .plans-grid,
    .testimonials-grid,
    .gallery-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    
    /* Cards */
    .card {
        padding: 1.5rem;
        margin-bottom: 1.5rem;
    }
    
    .facility-card,
    .plan-card,
    .testimonial-card {
        padding: 1.5rem;
    }
    
    /* Forms */
    .register-content {
        grid-template-columns: 1fr !important;
        gap: 2rem;
    }
    
    .register-form {
        padding: 1.5rem !important;
        margin: 0 10px;
    }
    
    .form-row {
        grid-template-columns: 1fr !important;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px !important;
        padding: 12px !important;
        -webkit-appearance: none;
        border-radius: 8px;
        background-color: #fff;
    }
    
    /* Buttons */
    .btn {
        width: 100%;
        text-align: center;
        padding: 14px 20px;
        font-size: 16px;
    }
    
    .btn-large {
        padding: 16px 24px;
        font-size: 16px;
    }
    
    /* Modals */
    .modal-content {
        width: 95% !important;
        padding: 20px;
        margin: 5% auto;
        max-height: 90vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Tables */
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    
    th, td {
        padding: 10px 8px;
        font-size: 0.8rem;
    }
    
    /* Notifications */
    .notification {
        right: 10px !important;
        left: 10px !important;
        max-width: none !important;
        width: auto !important;
    }
    
    /* Section spacing */
    .section-header {
        margin-bottom: 2rem;
    }
    
    .container {
        padding: 0 15px;
    }
}

/* ===== SMALL MOBILE OPTIMIZATIONS (max-width: 480px) ===== */
@media (max-width: 480px) {
    /* Typography */
    h1 {
        font-size: 1.8rem !important;
        line-height: 1.3 !important;
    }
    
    h2 {
        font-size: 1.3rem !important;
    }
    
    /* Hero Section */
    .hero {
        padding: 70px 15px 30px;
    }
    
    .hero-stats {
        flex-direction: column;
        gap: 1rem;
    }
    
    .stat {
        min-width: 120px;
    }
    
    /* Cards */
    .card {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    .facility-card,
    .plan-card {
        padding: 1.2rem;
        margin: 0 5px;
    }
    
    .facility-icon {
        width: 60px;
        height: 60px;
        font-size: 1.5rem;
    }
    
    /* Forms */
    .register-form {
        padding: 1rem !important;
        margin: 0 5px;
    }
    
    .form-group {
        margin-bottom: 1rem;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 10px !important;
        font-size: 16px !important;
    }
    
    .checkbox-label {
        font-size: 0.85rem;
        line-height: 1.4;
    }
    
    .total-amount {
        font-size: 1rem;
        padding: 1rem;
    }
    
    /* Buttons */
    .btn {
        padding: 12px 16px;
        font-size: 14px;
    }
    
    .btn-large {
        padding: 14px 20px;
        font-size: 15px;
    }
    
    /* Modals */
    .modal-content {
        padding: 15px;
        margin: 2% 5px;
        border-radius: 12px;
    }
    
    .modal-header {
        margin-bottom: 15px;
        padding-bottom: 10px;
    }
    
    .modal-title {
        font-size: 1.2rem;
    }
    
    .modal-footer {
        margin-top: 15px;
        padding-top: 12px;
        flex-direction: column;
        gap: 10px;
    }
    
    .modal-footer .btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Tables */
    th, td {
        padding: 8px 6px;
        font-size: 0.75rem;
    }
    
    /* Float buttons */
    .whatsapp-float,
    .call-float {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }
    
    .whatsapp-float {
        bottom: 15px;
        right: 15px;
    }
    
    .call-float {
        bottom: 75px;
        right: 15px;
    }
    
    /* Container */
    .container {
        padding: 0 10px;
    }
}

/* ===== LANDSCAPE MOBILE OPTIMIZATIONS ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .hero {
        min-height: auto;
        padding: 60px 20px 40px;
    }
    
    .modal-content {
        max-height: 85vh;
    }
    
    .chat-container {
        height: calc(100vh - 80px);
    }
}

/* ===== ANDROID SPECIFIC OPTIMIZATIONS ===== */
@media screen and (max-width: 768px) {
    /* Android Chrome input styling */
    input, textarea, select {
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }
    
    /* Android tap highlight */
    * {
        -webkit-tap-highlight-color: rgba(37, 99, 235, 0.1);
    }
}

/* ===== iOS SPECIFIC OPTIMIZATIONS ===== */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari specific styles */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="password"],
    textarea,
    select {
        -webkit-appearance: none;
        -webkit-border-radius: 8px;
        border-radius: 8px;
        font-size: 16px !important;
    }
    
    /* iOS bounce scroll fix */
    body {
        -webkit-overflow-scrolling: touch;
    }
    
    /* iOS input zoom prevention */
    @media screen and (max-device-width: 768px) {
        input, textarea, select {
            font-size: 16px !important;
        }
    }
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }
    
    .card {
        border: 1px solid #333;
    }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */
/* GPU acceleration for smooth animations */
.btn, .card, .modal-content, .nav-menu {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* Optimize repaints */
.hero, .header {
    will-change: transform;
}

/* ===== PRINT STYLES ===== */
@media print {
    .header, .footer, .btn, .hamburger, .whatsapp-float, .call-float {
        display: none !important;
    }
    
    .card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
    
    body {
        background: white !important;
        color: black !important;
    }
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --primary: #3b82f6;
        --dark: #f8fafc;
        --light: #1e293b;
        --gray: #94a3b8;
    }
    
    body {
        background: #0f172a;
        color: #f8fafc;
    }
    
    .card {
        background: rgba(30, 41, 59, 0.95);
        color: #f8fafc;
    }
    
    input, textarea, select {
        background: #1e293b;
        color: #f8fafc;
        border-color: #475569;
    }
}