/* ================================================
   MOBILE COMPATIBILITY - ALL DEVICES
   Android phones, iPhones, Tablets, iPads
   ================================================ */

/* ===== UNIVERSAL MOBILE FIXES ===== */

/* Prevent text size adjustment on orientation change */
html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Smooth scrolling on mobile */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Better font rendering on mobile */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Prevent horizontal scroll on all devices */
body, html {
    overflow-x: hidden;
    max-width: 100vw;
    position: relative;
}

/* ===== TOUCH-FRIENDLY ELEMENTS ===== */

/* Larger touch targets (minimum 44x44px - Apple HIG) */
a, button, input, select, textarea {
    min-height: 44px;
    min-width: 44px;
}

/* Better tap highlight color */
* {
    -webkit-tap-highlight-color: rgba(37, 117, 252, 0.2);
    -webkit-touch-callout: none;
}

/* Remove tap delay on mobile */
a, button, input, select, textarea {
    touch-action: manipulation;
}

/* Prevent text selection on double-tap */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* ===== RESPONSIVE IMAGES ===== */

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Prevent image zoom on double-tap */
img {
    pointer-events: none;
    user-select: none;
}

/* Allow image interaction when needed */
.clickable-image {
    pointer-events: auto;
}

/* ===== RESPONSIVE TYPOGRAPHY ===== */

/* Base font size - scales properly */
html {
    font-size: 16px;
}

/* Responsive headings */
h1 {
    font-size: clamp(28px, 5vw, 48px);
}

h2 {
    font-size: clamp(24px, 4vw, 36px);
}

h3 {
    font-size: clamp(20px, 3vw, 28px);
}

h4 {
    font-size: clamp(18px, 2.5vw, 24px);
}

p {
    font-size: clamp(14px, 2vw, 16px);
    line-height: 1.6;
}

/* ===== FORMS - MOBILE OPTIMIZED ===== */

input, textarea, select {
    font-size: 16px !important; /* Prevents iOS zoom */
    padding: 12px;
    border-radius: 8px;
    width: 100%;
    box-sizing: border-box;
}

/* iOS form fixes */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
textarea {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Better select on mobile */
select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

/* Remove input zoom on iOS */
@supports (-webkit-touch-callout: none) {
    input, textarea, select {
        font-size: 16px !important;
    }
}

/* ===== BUTTONS - TOUCH OPTIMIZED ===== */

button, .btn, .btn-primary, .btn-secondary, .btn-outline {
    min-height: 48px;
    min-width: 48px;
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* Active state for touch feedback */
button:active, .btn:active {
    transform: scale(0.98);
    opacity: 0.9;
}

/* ===== NAVIGATION - MOBILE FRIENDLY ===== */

/* Hamburger menu - larger touch target */
.mobile-menu-btn {
    min-width: 48px;
    min-height: 48px;
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mobile navigation links */
.mobile-nav a {
    min-height: 48px;
    padding: 14px 20px;
    display: flex;
    align-items: center;
}

/* ===== ANDROID SPECIFIC FIXES ===== */

/* Fix for Android Chrome */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    select, textarea, input {
        font-size: 16px;
    }
}

/* Samsung Internet browser */
@supports (-webkit-appearance: none) {
    input[type="date"],
    input[type="time"] {
        min-height: 48px;
    }
}

/* ===== iOS SPECIFIC FIXES ===== */

/* iPhone notch safe areas */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    header {
        padding-top: max(0px, env(safe-area-inset-top));
    }
    
    footer {
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
}

/* Fix iOS input shadows */
input, textarea, select {
    -webkit-appearance: none;
    box-shadow: none;
}

/* iOS date picker */
input[type="date"],
input[type="time"],
input[type="datetime-local"] {
    -webkit-appearance: none;
    min-height: 48px;
}

/* ===== TABLET OPTIMIZATIONS ===== */

/* iPad and Android tablets (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
    .container-custom {
        padding: 0 32px;
    }
    
    /* Tablet-specific font sizes */
    h1 { font-size: 40px; }
    h2 { font-size: 32px; }
    h3 { font-size: 24px; }
    
    /* Touch targets still generous */
    button, .btn {
        min-height: 44px;
        padding: 10px 20px;
    }
}

/* ===== DEVICE-SPECIFIC BREAKPOINTS ===== */

/* Small phones (320px - 374px) */
@media (max-width: 374px) {
    .container-custom {
        padding: 0 12px;
    }
    
    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }
    
    button, .btn {
        font-size: 14px;
        padding: 10px 16px;
    }
}

/* iPhone SE, 5s (375px - 413px) */
@media (min-width: 375px) and (max-width: 413px) {
    .container-custom {
        padding: 0 16px;
    }
}

/* iPhone 12, 13, Android standard (414px - 767px) */
@media (min-width: 414px) and (max-width: 767px) {
    .container-custom {
        padding: 0 20px;
    }
}

/* iPad Mini, small tablets (768px - 820px) */
@media (min-width: 768px) and (max-width: 820px) {
    .container-custom {
        padding: 0 28px;
    }
}

/* iPad, iPad Air (821px - 1024px) */
@media (min-width: 821px) and (max-width: 1024px) {
    .container-custom {
        padding: 0 32px;
    }
}

/* iPad Pro (1024px+) */
@media (min-width: 1024px) and (max-width: 1366px) {
    .container-custom {
        padding: 0 40px;
    }
}

/* ===== LANDSCAPE MODE ===== */

/* Mobile landscape */
@media (max-height: 500px) and (orientation: landscape) {
    header {
        min-height: 60px;
    }
    
    .hero-section {
        min-height: 80vh;
    }
    
    /* Reduce vertical padding in landscape */
    section {
        padding: 40px 0;
    }
}

/* Tablet landscape */
@media (min-width: 768px) and (max-height: 600px) and (orientation: landscape) {
    .hero-section {
        min-height: 70vh;
    }
}

/* ===== GRID SYSTEMS - RESPONSIVE ===== */

/* Mobile-first grid */
.grid {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
}

/* 2 columns on larger phones */
@media (min-width: 480px) {
    .grid-sm-2 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* 3 columns on tablets */
@media (min-width: 768px) {
    .grid-md-3 {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* 4 columns on desktop */
@media (min-width: 1024px) {
    .grid-lg-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ===== CARDS - MOBILE OPTIMIZED ===== */

.card {
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

/* Prevent card overflow */
.card img {
    width: 100%;
    height: auto;
    object-fit: cover;
}

/* ===== MODAL/POPUP - MOBILE FIXES ===== */

.modal, .account-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
}

.modal-content {
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Better modal on small phones */
@media (max-width: 480px) {
    .modal-content {
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
    }
}

/* ===== TABLES - RESPONSIVE ===== */

table {
    width: 100%;
    overflow-x: auto;
    display: block;
}

@media (max-width: 768px) {
    /* Stack table on mobile */
    table, thead, tbody, th, td, tr {
        display: block;
    }
    
    thead tr {
        display: none;
    }
    
    td {
        text-align: left;
        padding-left: 50%;
        position: relative;
    }
    
    td::before {
        content: attr(data-label);
        position: absolute;
        left: 6px;
        width: 45%;
        padding-right: 10px;
        font-weight: bold;
    }
}

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

/* Hardware acceleration for animations */
.animate, .transition {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Lazy load images */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

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

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid #2575FC;
    outline-offset: 2px;
}

/* Skip to content link */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: #2575FC;
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100000;
}

.skip-to-content:focus {
    top: 0;
}

/* ===== PRINT STYLES ===== */

@media print {
    .no-print, header, footer, .mobile-menu-btn {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.5;
    }
}

/* ===== DARK MODE SUPPORT ===== */

@media (prefers-color-scheme: dark) {
    /* Optional: Add dark mode styles */
    /* This is for devices with dark mode enabled */
}

/* ===== REDUCE MOTION ===== */

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

/* ===== HIGH CONTRAST MODE ===== */

@media (prefers-contrast: high) {
    button, .btn {
        border: 2px solid currentColor;
    }
}

/* ===== FLEXBOX UTILITIES - MOBILE SAFE ===== */

.flex {
    display: flex;
    flex-wrap: wrap;
}

.flex-nowrap {
    flex-wrap: nowrap;
}

.flex-col {
    flex-direction: column;
}

/* ===== SPACING UTILITIES - RESPONSIVE ===== */

/* Mobile spacing */
@media (max-width: 768px) {
    .mb-mobile-4 { margin-bottom: 1rem; }
    .mb-mobile-8 { margin-bottom: 2rem; }
    .p-mobile-4 { padding: 1rem; }
    .p-mobile-6 { padding: 1.5rem; }
}

/* ===== ANDROID CHROME FIXES ===== */

/* Address bar color */
meta[name="theme-color"] {
    content: #6A11CB;
}

/* ===== PWA SUPPORT ===== */

/* Splash screen colors */
meta[name="apple-mobile-web-app-status-bar-style"] {
    content: default;
}

/* ===== FINAL CATCH-ALL ===== */

/* Ensure everything fits */
* {
    max-width: 100%;
    box-sizing: border-box;
}

/* Container safety */
.container, .container-custom, .wrapper {
    max-width: 100vw;
    overflow-x: hidden;
}

/* Safe padding for all devices */
@supports (padding: env(safe-area-inset-left)) {
    .safe-padding {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}
