/* Mobile-First Optimizations */

/* Prevent layout shifts on mobile */
@media (max-width: 768px) {
    html {
        font-size: 16px; /* Prevent auto-zoom on iOS input focus */
    }

    body {
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
    }

    /* Safe area insets for notched devices */
    body {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    /* Navigation improvements */
    nav {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }

    /* Touch targets minimum 44x44px */
    button,
    a[role="button"],
    [role="button"] {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
    }

    /* Form inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    textarea,
    select {
        min-height: 44px;
        font-size: 16px; /* Prevents auto-zoom */
        padding: 12px;
    }

    /* Improve readability */
    body {
        line-height: 1.6;
        letter-spacing: 0.3px;
    }

    /* Modal improvements */
    .modal,
    dialog {
        margin: 0;
        padding: 1rem;
        max-height: 90vh;
    }

    /* Prevent horizontal scroll */
    body,
    html {
        overflow-x: hidden;
    }

    /* Improve tap feedback */
    button,
    a,
    input,
    textarea,
    select {
        -webkit-tap-highlight-color: transparent;
    }

    /* Better spacing on small screens */
    .px-4,
    .px-6 {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .py-8 {
        padding-top: 1.5rem;
        padding-bottom: 1.5rem;
    }

    /* Improve grid on mobile */
    .grid.grid-cols-2,
    .grid.grid-cols-3,
    .grid.grid-cols-4 {
        grid-template-columns: 1fr;
    }

    @media (min-width: 480px) {
        .grid.grid-cols-2 {
            grid-template-columns: repeat(2, minmax(0, 1fr));
        }
    }

    /* Card improvements */
    .card,
    .rounded-lg,
    .shadow {
        border-radius: 8px;
    }

    /* Typography on mobile */
    h1 {
        font-size: clamp(1.5rem, 5vw, 2.25rem);
    }

    h2 {
        font-size: clamp(1.25rem, 4vw, 1.875rem);
    }

    h3 {
        font-size: clamp(1.1rem, 3vw, 1.25rem);
    }
}

/* Landscape mode adjustments */
@media (max-height: 500px) {
    .header {
        padding: 0.5rem 0;
    }

    main {
        min-height: auto;
    }

    .py-12 {
        padding-top: 1rem;
        padding-bottom: 1rem;
    }
}

/* Tablet and up */
@media (min-width: 768px) {
    /* Safe area insets only on notched devices */
    body.has-notch {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
}

/* High DPI screens (Retina) */
@media (min-device-pixel-ratio: 2),
       (min-resolution: 192dpi) {
    /* Thinner borders on high DPI screens */
    border {
        border-width: 0.5px;
    }
}

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

/* Dark mode mobile improvements */
@media (prefers-color-scheme: dark) {
    [data-theme="dark"] input,
    [data-theme="dark"] textarea,
    [data-theme="dark"] select {
        color-scheme: dark;
    }
}

/* PWA installed mode */
body.pwa-installed {
    /* Adjust for system UI */
    padding-top: max(1rem, env(safe-area-inset-top));
}

/* Landscape mode PWA */
@media (orientation: landscape) and (max-height: 500px) {
    body.pwa-installed {
        padding-top: 0;
    }

    .header {
        height: auto;
    }
}
