/**
 * Future-Proof Responsive System 2025
 * ====================================
 * 
 * Professional, comprehensive responsive design system following:
 * - W3C Web Standards
 * - WCAG 2.1 AA Accessibility Guidelines
 * - Mobile-First Approach
 * - Progressive Enhancement
 * - Container Queries (Future-Proof)
 * - Modern CSS Features
 * 
 * Breakpoints:
 * - Mobile: 320px - 479px
 * - Tablet: 480px - 767px
 * - Desktop: 768px+
 * - Large Desktop: 1024px+
 * - XL Desktop: 1280px+
 * 
 * Author: KoreaSewa Development Team
 * Version: 3.0.0 (Future-Proof)
 * Last Updated: 2025-01-27
 */

/* ============================================
   CSS CUSTOM PROPERTIES (Future-Proof)
   ============================================ */
:root {
    /* Professional Breakpoint System */
    --bp-mobile: 320px;
    --bp-mobile-lg: 480px;
    --bp-tablet: 768px;
    --bp-desktop: 1024px;
    --bp-desktop-lg: 1280px;
    --bp-desktop-xl: 1536px;
    --bp-desktop-2xl: 1920px;
    
    /* Fluid Typography (Future-Proof) */
    --font-mobile: clamp(14px, 2.5vw, 16px); /* 14px-16px */
    --font-base: clamp(16px, 1.5vw, 18px); /* 16px-18px */
    --font-lg: clamp(18px, 2vw, 24px);
    --font-xl: clamp(24px, 3vw, 32px);
    --font-2xl: clamp(32px, 4vw, 48px);
    --font-3xl: clamp(48px, 5vw, 64px);
    
    /* Professional Spacing (Fluid) */
    --space-xs: clamp(0.25rem, 0.5vw, 0.5rem);
    --space-sm: clamp(0.5rem, 1vw, 0.75rem);
    --space-md: clamp(0.75rem, 1.5vw, 1rem);
    --space-lg: clamp(1rem, 2vw, 1.5rem);
    --space-xl: clamp(1.5rem, 3vw, 2rem);
    --space-2xl: clamp(2rem, 4vw, 3rem);
    
    /* Touch Targets (WCAG 2.1 AA) */
    --touch-min: 44px; /* Minimum for accessibility */
    --touch-comfort: 48px; /* Comfortable size */
    --touch-large: 56px; /* Large targets */
    
    /* Professional Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 350ms ease;
}

/* ============================================
   CRITICAL: Prevent Horizontal Scroll
   ============================================ */
html {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    position: relative;
    margin: 0;
    padding: 0;
    font-size: var(--font-base);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   MOBILE-FIRST BASE STYLES
   ============================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Prevent overflow on all elements */
* {
    max-width: 100%;
}

/* Images - Always Responsive */
img {
    max-width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
}

/* Videos and Media */
video,
iframe,
embed,
object {
    max-width: 100%;
    height: auto;
}

/* Tables - Scroll on Mobile */
table {
    width: 100%;
    border-collapse: collapse;
}

/* ============================================
   MOBILE (320px - 479px)
   ============================================ */
@media (max-width: 479px) {
    /* Typography */
    html {
        font-size: 16px; /* Prevent iOS zoom */
    }
    
    body {
        font-size: var(--font-mobile);
        padding: var(--space-sm);
    }
    
    h1 { font-size: var(--font-2xl); }
    h2 { font-size: var(--font-xl); }
    h3 { font-size: var(--font-lg); }
    h4, h5, h6 { font-size: var(--font-base); }
    
    /* Containers */
    .container,
    .container-fluid {
        padding-left: var(--space-sm);
        padding-right: var(--space-sm);
        width: 100%;
        max-width: 100%;
    }
    
    /* Cards */
    .card {
        padding: var(--space-md);
        margin-bottom: var(--space-md);
        border-radius: 8px;
    }
    
    /* Buttons - Touch Targets */
    button,
    .btn,
    a.button,
    input[type="button"],
    input[type="submit"],
    [role="button"] {
        min-height: var(--touch-min);
        min-width: var(--touch-min);
        padding: var(--space-sm) var(--space-md);
        font-size: 16px; /* Prevent iOS zoom */
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
    
    /* Forms - Prevent iOS Zoom */
    input,
    textarea,
    select {
        font-size: 16px !important; /* Critical: Prevents iOS zoom */
        min-height: var(--touch-min);
        padding: var(--space-sm) var(--space-md);
        width: 100%;
        border-radius: 6px;
    }
    
    /* Navigation - Scoped to exclude koreasewa-header navigation */
    .navbar:not(.koreasewa-header-navigation):not(.koreasewa-navbar-sticky):not([class*="koreasewa"]):not([class*="footer-ultra"]) {
        padding: var(--space-sm);
    }
    
    .nav-link {
        min-height: var(--touch-min);
        padding: var(--space-sm) var(--space-md);
        display: flex;
        align-items: center;
    }
    
    /* Navigation Toggle */
    .navbar-toggler {
        min-width: var(--touch-min);
        min-height: var(--touch-min);
        padding: var(--space-sm);
    }
    
    /* Tables - Horizontal Scroll */
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table-responsive table {
        min-width: 600px;
    }
    
    /* Hide non-essential elements */
    .mobile-hidden {
        display: none !important;
    }
    
    /* Footer */
    footer {
        padding: var(--space-lg) var(--space-sm);
        font-size: 0.875rem;
    }
}

/* ============================================
   TABLET (480px - 767px)
   ============================================ */
@media (min-width: 480px) and (max-width: 767px) {
    body {
        font-size: var(--font-base);
        padding: var(--space-md);
    }
    
    /* Containers */
    .container {
        padding-left: var(--space-md);
        padding-right: var(--space-md);
    }
    
    /* Cards - More Spacing */
    .card {
        padding: var(--space-lg);
        margin-bottom: var(--space-lg);
    }
    
    /* Buttons - Comfortable Size */
    button,
    .btn {
        min-height: var(--touch-comfort);
        padding: var(--space-md) var(--space-lg);
    }
    
    /* Grid - 2 Columns */
    .row [class*="col-"] {
        flex: 0 0 50%;
        max-width: 50%;
    }
    
    /* Tables - Better Spacing */
    table {
        font-size: 0.9375rem;
    }
}

/* ============================================
   DESKTOP (768px+)
   ============================================ */
@media (min-width: 768px) {
    /* Show desktop elements */
    .desktop-hidden {
        display: none !important;
    }
    
    .mobile-hidden {
        display: block !important;
    }
    
    /* Containers */
    .container {
        max-width: 1200px;
        margin: 0 auto;
        padding-left: var(--space-lg);
        padding-right: var(--space-lg);
    }
    
    /* Grid - 3+ Columns */
    .row [class*="col-md-"] {
        flex: 0 0 auto;
    }
}

/* ============================================
   LARGE DESKTOP (1024px+)
   ============================================ */
@media (min-width: 1024px) {
    .container {
        max-width: 1280px;
    }
    
    /* Larger spacing */
    .card {
        padding: var(--space-xl);
    }
}

/* ============================================
   XL DESKTOP (1280px+)
   ============================================ */
@media (min-width: 1280px) {
    .container {
        max-width: 1400px;
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Touch devices only */
    
    /* Larger touch targets */
    a,
    button,
    .btn,
    [role="button"],
    .nav-link {
        min-height: var(--touch-comfort);
        min-width: var(--touch-comfort);
        padding: var(--space-md) var(--space-lg);
    }
    
    /* Remove hover effects on touch */
    *:hover {
        /* Hover effects disabled on touch devices */
    }
    
    /* Better tap feedback */
    a:active,
    button:active,
    .btn:active {
        opacity: 0.7;
        transform: scale(0.98);
    }
    
    /* Touch scrolling */
    .scrollable {
        -webkit-overflow-scrolling: touch;
        overflow-scrolling: touch;
    }
}

/* ============================================
   iOS SAFARI SPECIFIC FIXES
   ============================================ */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari only */
    
    html {
        height: -webkit-fill-available;
    }
    
    body {
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
    
    /* Fix viewport height on iOS */
    .full-height {
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
    
    /* Fix input zoom */
    input,
    textarea,
    select {
        font-size: 16px !important;
    }
    
    /* Fix fixed positioning */
    .fixed,
    [style*="position: fixed"] {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    /* Fix scrolling */
    .scrollable {
        -webkit-overflow-scrolling: touch;
    }
}

/* ============================================
   ANDROID CHROME SPECIFIC FIXES
   ============================================ */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    /* Android Chrome */
    
    a,
    button,
    [role="button"] {
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
}

/* ============================================
   ACCESSIBILITY (WCAG 2.1 AA)
   ============================================ */
/* Focus Indicators */
*:focus-visible {
    outline: 2px solid #007bff;
    outline-offset: 2px;
    border-radius: 4px;
}

/* 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 */
@media (prefers-contrast: high) {
    * {
        border-color: currentColor;
    }
    
    button,
    .btn {
        border: 2px solid currentColor;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }
}

/* ============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================ */
/* Content Visibility (Future-Proof) */
@media (max-width: 768px) {
    .lazy-load {
        content-visibility: auto;
        contain-intrinsic-size: 200px;
    }
}

/* Will-Change for Animations */
.animate {
    will-change: transform, opacity;
}

/* GPU Acceleration */
.gpu-accelerated {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* ============================================
   CONTAINER QUERIES (Future-Proof)
   ============================================ */
@container (min-width: 320px) {
    .container-query-responsive {
        /* Future container query support */
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
/* Responsive Hide/Show */
.mobile-only {
    display: block;
}
@media (min-width: 768px) {
    .mobile-only {
        display: none !important;
    }
}

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

.tablet-only {
    display: none;
}
@media (min-width: 480px) and (max-width: 767px) {
    .tablet-only {
        display: block;
    }
}

/* Responsive Images */
.img-responsive {
    width: 100%;
    height: auto;
    display: block;
}

.img-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.img-contain {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Responsive Tables */
.table-responsive-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Responsive Videos */
.video-responsive {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    height: 0;
    overflow: hidden;
}

.video-responsive iframe,
.video-responsive video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    * {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
    }
    
    .no-print {
        display: none !important;
    }
    
    a {
        text-decoration: underline;
    }
    
    img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }
}

