/* Mobile Fixes for Arabic Math Tutor */
/* This file contains essential mobile-specific fixes and improvements */

/* ===========================================
   MOBILE PERFORMANCE OPTIMIZATIONS
   =========================================== */

/* Optimize mobile scrolling and touch */
html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Optimize image loading on mobile */
img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: optimize-contrast;
    will-change: auto;
}

/* Optimize touch targets for mobile */
button, input, select, textarea, a {
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

input, textarea {
    -webkit-user-select: auto;
    user-select: auto;
}

/* ===========================================
   MOBILE RESPONSIVE FIXES
   =========================================== */

/* Mobile Navigation Improvements */
@media (max-width: 767px) {
    /* Fix header height and padding on mobile */
    header .container {
        padding-top: 0;
        padding-bottom: 0;
    }
    
    .mobile-nav {
        min-height: 60px;
        display: flex;
        align-items: center;
    }
    
    /* Mobile menu button improvements */
    .mobile-menu-btn {
        padding: 0.5rem;
        border-radius: 0.5rem;
        background: rgba(255, 255, 255, 0.9);
        border: 1px solid rgba(0, 0, 0, 0.1);
        transition: all 0.2s ease;
        min-height: 44px;
        min-width: 44px;
    }
    
    .mobile-menu-btn:hover {
        background: rgba(99, 102, 241, 0.1);
        border-color: rgba(99, 102, 241, 0.3);
    }
    
    /* Mobile navigation container */
    .mobile-nav-container {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        min-height: 60px;
        height: 60px;
    }
    
    .nav-left,
    .nav-right {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 60px;
        height: 60px;
    }
    
    .nav-center {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 0.75rem;
        height: 60px;
    }
    
    .mobile-icon-btn {
        padding: 0.5rem;
        border-radius: 0.5rem;
        background: rgba(255, 255, 255, 0.9);
        border: 1px solid rgba(0, 0, 0, 0.1);
        transition: all 0.2s ease;
        min-height: 44px;
        min-width: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Mobile title spacing */
    .mobile-page-title {
        line-height: 1.2;
        margin: 0;
        font-size: 0.875rem;
        font-weight: 600;
        color: #1A1A1A;
        text-align: center;
    }
    
    /* Mobile navigation pills */
    .mobile-pill {
        font-size: 11px;
        padding: 4px 8px;
        border-radius: 12px;
        white-space: nowrap;
        min-height: 32px;
    }
}

/* ===========================================
   BUTTON AND FORM FIXES
   =========================================== */

/* Mobile button improvements */
@media (max-width: 640px) {
    button {
        min-height: 44px; /* iOS touch target minimum */
        padding: 0.75rem 1rem;
        font-size: 14px;
        -webkit-appearance: none;
        appearance: none;
    }
    
    /* Large action buttons on mobile */
    .action-btn,
    #start-practice-btn,
    #generate-problem-btn,
    #confirm-analyze-btn {
        width: 100%;
        padding: 1rem;
        font-size: 16px;
        margin-bottom: 0.5rem;
        min-height: 48px;
    }
    
    /* Mobile dropdown fixes */
    select {
        min-height: 44px;
        padding: 0.75rem;
        font-size: 16px; /* Prevents zoom on iOS */
        border-radius: 8px;
        -webkit-appearance: none;
        appearance: none;
    }
    
    /* Mobile input fixes */
    input[type="radio"] {
        min-width: 20px;
        min-height: 20px;
    }
    
    input[type="file"] {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* ===========================================
   CAMERA AND IMAGE CAPTURE OPTIMIZATIONS
   =========================================== */

/* Optimize camera modal for mobile */
@media (max-width: 640px) {
    #camera-video {
        width: 100% !important;
        height: auto !important;
        max-height: 60vh;
        object-fit: cover;
        border-radius: 8px;
    }
    
    .upload-area {
        padding: 1rem !important;
    }
    
    .image-preview {
        max-height: 300px !important;
    }
}

/* ===========================================
   RTL AND ARABIC TEXT FIXES
   =========================================== */

/* Arabic text rendering improvements */
html[dir="rtl"] {
    text-align: right;
}

/* Arabic number display */
.arabic-numbers {
    font-feature-settings: 'lnum' 1;
    direction: ltr;
    display: inline-block;
}

/* Arabic text in buttons */
button[dir="rtl"],
.btn-arabic {
    text-align: center;
    direction: rtl;
}

/* Fix for Arabic text in navigation */
.nav-text {
    direction: rtl;
    text-align: right;
}

/* ===========================================
   MODAL AND POPUP FIXES
   =========================================== */

/* Mobile modal improvements */
@media (max-width: 640px) {
    .modal-content {
        margin: 1rem;
        max-height: calc(100vh - 2rem);
        border-radius: 12px;
    }
    
    /* Modal close button */
    .modal-content button[onclick*="hide"] {
        min-width: 44px;
        min-height: 44px;
        padding: 0.5rem;
    }
    
    /* Points explanation modal */
    #points-explanation-modal .modal-content {
        max-width: calc(100vw - 2rem);
    }
    
    /* Cropper modal optimizations */
    #cropper-modal .bg-white {
        max-height: 95vh;
        margin: 0.5rem;
    }
    
    #cropper-container {
        max-height: 50vh;
        overflow: hidden;
    }
}

/* ===========================================
   CARD AND LAYOUT FIXES
   =========================================== */

/* Mobile card improvements */
@media (max-width: 640px) {
    .card,
    .welcome-card,
    .curriculum-card,
    .problem-card {
        margin: 0.5rem 0;
        padding: 1rem;
        border-radius: 12px;
    }
    
    /* Feature cards on mobile */
    .feature-card {
        padding: 1rem;
        text-align: center;
    }
    
    /* Curriculum items on mobile */
    .curriculum-item {
        padding: 1rem;
        margin-bottom: 0.5rem;
    }
    
    /* Grid fixes for mobile */
    .grid-cols-3 {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .md\\:grid-cols-3 {
        grid-template-columns: 1fr;
    }
    
    .lg\\:grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
}

/* ===========================================
   TYPOGRAPHY FIXES
   =========================================== */

/* Mobile typography */
@media (max-width: 640px) {
    h1 {
        font-size: 1.5rem;
        line-height: 1.3;
    }
    
    h2 {
        font-size: 1.25rem;
        line-height: 1.4;
    }
    
    h3 {
        font-size: 1.1rem;
        line-height: 1.4;
    }
    
    /* Body text */
    p, div {
        line-height: 1.6;
    }
    
    /* Small text improvements */
    small,
    .text-sm {
        font-size: 0.875rem;
        line-height: 1.5;
    }
}

/* ===========================================
   SCROLLBAR OPTIMIZATIONS
   =========================================== */

/* Better mobile scrollbars */
html, body {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

html {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.3) transparent;
}

@media (max-width: 640px) {
    ::-webkit-scrollbar {
        width: 4px;
    }
    
    ::-webkit-scrollbar-track {
        background: transparent;
    }
    
    ::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 2px;
    }
}

/* ===========================================
   ANIMATION AND TRANSITION FIXES
   =========================================== */

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Touch feedback */
@media (hover: none) and (pointer: coarse) {
    button:active,
    .btn:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
}

/* ===========================================
   ACCESSIBILITY FIXES
   =========================================== */

/* High contrast mode support */
@media (prefers-contrast: high) {
    .card,
    .modal-content {
        border: 2px solid #000;
    }
    
    button {
        border: 2px solid #000;
    }
}

/* Focus visible improvements */
button:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: 2px solid #6366F1;
    outline-offset: 2px;
}

/* ===========================================
   PRINT FIXES
   =========================================== */

@media print {
    /* Hide non-essential elements */
    .no-print,
    header,
    footer,
    .modal-backdrop,
    button:not(.print-keep) {
        display: none !important;
    }
    
    /* Optimize print layout */
    body {
        background: white !important;
        color: black !important;
        font-size: 12pt;
        line-height: 1.5;
    }
    
    .card,
    .problem-card {
        border: 1px solid #ccc;
        break-inside: avoid;
        margin-bottom: 1rem;
    }
}

/* ===========================================
   LOADING AND ERROR STATE FIXES
   =========================================== */

/* Loading spinner improvements */
.loading-spinner {
    width: 40px;
    height: 40px;
    margin: 1rem auto;
}

/* Error message styling */
.error-message {
    background: #fee2e2;
    color: #991b1b;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid #fca5a5;
    margin: 1rem 0;
    text-align: center;
}

/* Success message styling */
.success-message {
    background: #dcfce7;
    color: #166534;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid #86efac;
    margin: 1rem 0;
    text-align: center;
}

/* Toast notifications for mobile */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    max-width: 90vw;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    font-weight: 500;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes slideDown {
    from {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
}

.toast.info {
    background: rgba(59, 130, 246, 0.9);
    color: white;
}

.toast.success {
    background: rgba(16, 185, 129, 0.9);
    color: white;
}

.toast.error {
    background: rgba(239, 68, 68, 0.9);
    color: white;
}

/* ===========================================
   UTILITY CLASSES
   =========================================== */

/* Safe area insets for mobile devices */
@supports (padding: max(0px)) {
    .safe-area-inset-top {
        padding-top: max(1rem, env(safe-area-inset-top));
    }
    
    .safe-area-inset-bottom {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* Mobile-only and desktop-only classes */
.mobile-only {
    display: block;
}

.desktop-only {
    display: none;
}

@media (min-width: 768px) {
    .mobile-only {
        display: none;
    }
    
    .desktop-only {
        display: block;
    }
} 