/* Mobile Optimization for iOS Home Screen App */

/* Ensure proper sizing on mobile devices */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html, body {
    height: 100%;
    width: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Safe area support for iPhone X and newer */
@supports (padding: max(0px)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Fix gray text issue - ensure text is always visible */
.text-gray-900,
h1, h2, h3, h4, h5, h6,
.font-semibold,
.font-medium {
    color: #111827 !important;
}

/* Ensure inputs are readable */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
textarea,
select {
    color: #111827 !important;
    background-color: #ffffff !important;
    font-size: 16px !important; /* Prevents zoom on iOS */
    -webkit-appearance: none;
    border-radius: 4px;
}

/* Optimize for both orientations */
@media screen and (orientation: portrait) {
    /* Portrait optimizations */
    .container,
    .ns-box {
        max-width: 100%;
        padding: 1rem;
    }
    
    /* Ensure buttons are tappable */
    button,
    .btn,
    [role="button"] {
        min-height: 44px; /* iOS recommended touch target */
        min-width: 44px;
        padding: 12px 16px;
    }
}

@media screen and (orientation: landscape) {
    /* Landscape optimizations */
    .container,
    .ns-box {
        max-width: 100%;
        padding: 0.75rem;
    }
    
    /* Optimize form layouts for landscape */
    .flex.gap-2 {
        flex-wrap: wrap;
    }
    
    /* Ensure buttons remain tappable */
    button,
    .btn,
    [role="button"] {
        min-height: 44px;
        min-width: 44px;
    }
}

/* iPhone specific optimizations */
@media screen and (max-width: 480px) {
    /* Smaller screens */
    .p-4 {
        padding: 0.75rem !important;
    }
    
    .mb-3 {
        margin-bottom: 0.75rem !important;
    }
    
    /* Make text inputs larger for easier input */
    input[type="text"],
    input[type="number"],
    textarea {
        font-size: 16px !important;
        padding: 12px !important;
    }
    
    /* Stack elements vertically on small screens */
    .flex.gap-2 {
        flex-direction: column;
        gap: 0.5rem !important;
    }
    
    .flex.gap-2 > * {
        width: 100% !important;
    }
    
    /* Ensure Add Phone button is full width and visible */
    .flex.flex-col.sm\:flex-row.gap-2 button {
        width: 100% !important;
        margin-top: 0.5rem;
    }
}

/* iPad specific optimizations */
@media screen and (min-width: 481px) and (max-width: 1024px) {
    /* Tablet sizes */
    .container {
        max-width: 90%;
        margin: 0 auto;
    }
    
    /* Better spacing for tablets */
    .p-4 {
        padding: 1.25rem !important;
    }
}

/* Prevent text selection issues on iOS */
input, textarea, select {
    -webkit-user-select: text;
    user-select: text;
}

/* Fix for iOS Safari address bar */
@supports (-webkit-touch-callout: none) {
    body {
        /* iOS Safari specific */
        min-height: -webkit-fill-available;
    }
    
    html {
        height: -webkit-fill-available;
    }
}

/* Ensure proper scrolling */
body {
    position: relative;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Fix for gray backgrounds on dark mode */
.bg-gray-50 {
    background-color: #f9fafb !important;
}

/* Ensure proper contrast */
.text-gray-900 {
    color: #111827 !important;
}

/* Optimize tables for mobile */
@media screen and (max-width: 768px) {
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Fix for iOS input zoom */
@media screen and (max-width: 480px) {
    select,
    textarea,
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="password"] {
        font-size: 16px !important;
    }
}

/* Ensure proper viewport handling */
@media screen and (max-device-width: 480px) {
    html {
        -webkit-text-size-adjust: 100%;
    }
}

/* Landscape phone optimizations */
@media screen and (max-width: 896px) and (orientation: landscape) {
    /* Optimize for landscape phones */
    .p-4 {
        padding: 0.5rem !important;
    }
    
    /* Make forms more compact */
    .mb-3 {
        margin-bottom: 0.5rem !important;
    }
}
