/* ========================================
   MOBILE-FIRST RESPONSIVE ENHANCEMENTS
   For smooth experience on ALL devices
   ======================================== */

/* ===== MOBILE MENU BUTTON ===== */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--primary, #4f46e5);
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.mobile-menu-btn:hover {
    background: rgba(79, 70, 229, 0.1);
}

.mobile-menu-btn:active {
    transform: scale(0.95);
}

/* Show mobile menu button on small screens */
@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex;
    }
    
    .nav {
        display: none !important;
    }
    
    .nav.mobile-active {
        display: flex !important;
        position: fixed;
        top: 70px;
        left: 0;
        right: 0;
        background: white;
        flex-direction: column;
        padding: 20px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
        z-index: 999;
        animation: slideDown 0.3s ease;
    }
    
    @keyframes slideDown {
        from {
            opacity: 0;
            transform: translateY(-20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    .nav.mobile-active .nav-link {
        padding: 16px 20px;
        font-size: 18px;
        border-bottom: 1px solid #e5e7eb;
        display: block;
        text-align: left;
    }
    
    .nav.mobile-active .nav-link:last-child {
        border-bottom: none;
    }
}

/* ===== IMPROVED TOUCH TARGETS ===== */
/* Minimum 44x44px touch targets as per WCAG guidelines */

button, 
.btn, 
.cta-button,
.submit-btn,
.result-btn,
input[type="button"],
input[type="submit"],
.portion-btn,
.food-btn,
.toggle-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 24px !important;
    font-size: 16px !important;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(79, 70, 229, 0.2);
}

/* Fix for iOS zoom on focus */
input,
select,
textarea {
    font-size: 16px !important;
}

/* ===== MOBILE TYPOGRAPHY IMPROVEMENTS ===== */
@media (max-width: 768px) {
    /* Hero Section */
    .hero-title {
        font-size: 36px !important;
        line-height: 1.2 !important;
        margin-bottom: 20px;
    }
    
    .hero-subtitle {
        font-size: 18px !important;
        line-height: 1.6 !important;
    }
    
    /* Section Titles */
    .section-title {
        font-size: 28px !important;
        line-height: 1.3 !important;
    }
    
    .section-subtitle {
        font-size: 16px !important;
    }
    
    /* Card Titles */
    .food-card h3,
    .feature-card h3,
    .blog-card h3 {
        font-size: 18px !important;
    }
    
    /* Body Text */
    p, li {
        font-size: 16px !important;
        line-height: 1.6 !important;
    }
}

@media (max-width: 480px) {
    .hero-title {
        font-size: 28px !important;
    }
    
    .hero-subtitle {
        font-size: 16px !important;
    }
    
    .section-title {
        font-size: 24px !important;
    }
}

/* ===== MOBILE SPACING IMPROVEMENTS ===== */
@media (max-width: 768px) {
    /* Container Padding */
    .container {
        padding: 0 16px !important;
    }
    
    /* Section Padding */
    section {
        padding: 40px 0 !important;
    }
    
    .hero {
        padding: 60px 0 !important;
    }
    
    /* Card Spacing */
    .food-card,
    .feature-card,
    .blog-card {
        padding: 20px !important;
    }
    
    /* Form Spacing */
    .form-group {
        margin-bottom: 20px !important;
    }
    
    label {
        margin-bottom: 8px !important;
        display: block;
    }
}

/* ===== CALCULATOR MOBILE OPTIMIZATION ===== */
@media (max-width: 768px) {
    .calculator-section {
        padding: 30px 16px !important;
    }
    
    .food-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }
    
    .food-card {
        min-height: 140px;
    }
    
    .food-icon {
        font-size: 36px !important;
    }
    
    .portion-controls {
        flex-direction: column;
        gap: 12px;
    }
    
    .portion-btn {
        width: 100%;
        justify-content: center;
    }
    
    .result-box {
        padding: 24px 16px !important;
    }
    
    .calorie-display {
        font-size: 42px !important;
    }
}

/* ===== FORM MOBILE OPTIMIZATION ===== */
@media (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="number"],
    select,
    textarea {
        width: 100%;
        padding: 14px 16px !important;
        font-size: 16px !important;
        border-radius: 8px;
        border: 2px solid #e5e7eb;
    }
    
    input:focus,
    select:focus,
    textarea:focus {
        outline: none;
        border-color: #4f46e5;
        box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
    }
    
    .form-row {
        display: flex;
        flex-direction: column;
        gap: 20px;
    }
}

/* ===== HEADER MOBILE FIX ===== */
@media (max-width: 768px) {
    .header {
        padding: 12px 0 !important;
        position: sticky;
        top: 0;
        z-index: 100;
        background: white;
    }
    
    .header .container {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
    }
    
    .logo {
        font-size: 20px !important;
    }
    
    .logo-icon {
        font-size: 28px !important;
    }
    
    .header-stats {
        display: none !important;
    }
}

/* ===== FOOTER MOBILE OPTIMIZATION ===== */
@media (max-width: 768px) {
    .footer {
        padding: 40px 0 20px !important;
    }
    
    .footer-content {
        grid-template-columns: 1fr !important;
        gap: 32px !important;
    }
    
    .footer-brand {
        text-align: center;
        grid-column: span 1 !important;
    }
    
    .footer-section h4 {
        font-size: 18px !important;
    }
    
    .footer-links {
        font-size: 14px !important;
    }
    
    .footer-social {
        justify-content: center;
        gap: 16px;
    }
    
    .social-link {
        width: 44px !important;
        height: 44px !important;
        font-size: 20px !important;
    }
    
    .footer-bottom {
        flex-direction: column;
        text-align: center;
        gap: 16px;
    }
}

/* ===== CARD GRID MOBILE OPTIMIZATION ===== */
@media (max-width: 768px) {
    .features-grid,
    .benefits-grid,
    .values-grid {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }
    
    .blog-grid {
        grid-template-columns: 1fr !important;
        gap: 24px !important;
    }
}

/* ===== MODAL MOBILE OPTIMIZATION ===== */
@media (max-width: 768px) {
    .modal,
    .terms-popup,
    .info-modal {
        max-width: 95% !important;
        margin: 20px !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
    }
    
    .modal {
        padding: 0 !important;
        overflow: hidden !important;
        pointer-events: auto !important;
        background: rgba(0, 0, 0, 0.2) !important;
        backdrop-filter: blur(2px) !important;
    }
    
    .modal-content {
        padding: 20px 16px !important;
        max-height: 92vh !important;
        max-width: 100% !important;
        width: calc(100% - 20px) !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        margin: 10px !important;
        border-radius: 20px 20px 0 0 !important;
        touch-action: pan-y !important;
        position: relative !important;
    }
    
    .portion-modal-header {
        margin-bottom: 16px !important;
    }
    
    .portion-food-emoji {
        font-size: 48px !important;
        margin-bottom: 12px !important;
    }
    
    .portion-food-name {
        font-size: 22px !important;
    }
    
    .portion-instruction {
        font-size: 14px !important;
        margin-bottom: 16px !important;
    }
    
    .portion-option {
        padding: 14px !important;
    }
    
    .portion-size {
        font-size: 16px !important;
    }
    
    .portion-calories {
        font-size: 18px !important;
    }
    
    .portion-macros {
        font-size: 12px !important;
    }
    
    .modal-header h2 {
        font-size: 20px !important;
    }
    
    .modal-close {
        width: 32px !important;
        height: 32px !important;
        font-size: 20px !important;
        top: 12px !important;
        right: 12px !important;
    }
    
    .quick-add-modal {
        padding: 0 !important;
        background: rgba(0, 0, 0, 0.2) !important;
        backdrop-filter: blur(2px) !important;
    }
    
    .quick-add-content {
        width: calc(100% - 20px) !important;
        max-height: 92vh !important;
        margin: 10px !important;
        border-radius: 20px 20px 0 0 !important;
    }
}

/* ===== TABLE MOBILE OPTIMIZATION ===== */
@media (max-width: 768px) {
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    th, td {
        padding: 12px 8px !important;
        font-size: 14px !important;
    }
}

/* ===== FLOATING ELEMENTS MOBILE FIX ===== */
@media (max-width: 768px) {
    .floating-food {
        display: none !important;
    }
    
    .back-to-top {
        width: 50px !important;
        height: 50px !important;
        bottom: 20px !important;
        right: 20px !important;
        font-size: 20px !important;
    }
}

/* ===== SMOOTH SCROLLING ===== */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* ===== PREVENT HORIZONTAL SCROLL ===== */
body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
}

* {
    max-width: 100%;
}

/* ===== IMAGE RESPONSIVENESS ===== */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ===== VIDEO RESPONSIVENESS ===== */
video, iframe {
    max-width: 100%;
    height: auto;
}

/* ===== MOBILE LANDSCAPE MODE ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .hero {
        padding: 40px 0 !important;
    }
    
    .hero-title {
        font-size: 32px !important;
    }
    
    .modal,
    .terms-popup {
        max-height: 80vh !important;
    }
}

/* ===== VERY SMALL SCREENS (320px) ===== */
@media (max-width: 375px) {
    .container {
        padding: 0 12px !important;
    }
    
    .hero-title {
        font-size: 24px !important;
    }
    
    .hero-subtitle {
        font-size: 14px !important;
    }
    
    button,
    .btn,
    .cta-button {
        font-size: 14px !important;
        padding: 10px 20px !important;
    }
    
    .food-grid {
        grid-template-columns: 1fr !important;
    }
    
    .section-title {
        font-size: 22px !important;
    }
}

/* ===== ACCESSIBILITY - FOCUS VISIBLE ===== */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid #4f46e5;
    outline-offset: 2px;
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ===== HIGH CONTRAST MODE ===== */
@media (prefers-contrast: high) {
    button,
    .btn,
    .cta-button {
        border: 2px solid currentColor;
    }
}

/* ===== DARK MODE SUPPORT (if needed in future) ===== */
@media (prefers-color-scheme: dark) {
    :root {
        /* Dark mode variables can be added here */
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .header,
    .footer,
    .mobile-menu-btn,
    .back-to-top,
    .ad-container,
    .floating-food {
        display: none !important;
    }
    
    body {
        color: #000;
        background: #fff;
    }
    
    a {
        text-decoration: underline;
    }
}

/* ===== TABLET OPTIMIZATION (768px - 1024px) ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding: 0 24px;
    }
    
    .food-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .features-grid,
    .blog-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .hero-title {
        font-size: 44px;
    }
}

/* ===== IMPROVED MOBILE PERFORMANCE ===== */
@media (max-width: 768px) {
    /* Use GPU acceleration for smooth animations */
    .nav.mobile-active,
    .modal,
    .food-card,
    .feature-card {
        will-change: transform;
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }
    
    /* Optimize images on mobile */
    img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ===== SAFE AREA INSETS (for devices with notches) ===== */
@supports (padding: max(0px)) {
    .header {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
    
    .footer {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}

/* ===== MOBILE MENU CLOSE ON SCROLL ===== */
@media (max-width: 768px) {
    .nav.mobile-active {
        max-height: calc(100vh - 70px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ===== FIX FOR MOBILE SAFARI ===== */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari specific fixes */
    .hero {
        min-height: -webkit-fill-available;
    }
    
    input,
    select,
    textarea {
        -webkit-appearance: none;
        border-radius: 8px;
    }
}

/* ===== LOADING PERFORMANCE ===== */
@media (max-width: 768px) {
    /* Lazy load images below the fold */
    img[loading="lazy"] {
        opacity: 0;
        transition: opacity 0.3s;
    }
    
    img[loading="lazy"].loaded {
        opacity: 1;
    }
}
