/**
 * Responsive Utilities
 * ابزارهای کمکی و رفع مشکلات کلی ریسپانسیو
 */

/* ====================================
   حذف Horizontal Scroll
   ==================================== */
html,
body {
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    position: relative;
}

/* ====================================
   Container Safe Margins
   ==================================== */
.container {
    padding-left: clamp(16px, 4vw, 24px);
    padding-right: clamp(16px, 4vw, 24px);
}

@media (min-width: 1536px) {
    .container {
        padding-left: 24px;
        padding-right: 24px;
    }
}

/* ====================================
   Prevent Images from Breaking layout
   ==================================== */
img {
    max-width: 100%;
    height: auto;
}

img[class*="w-full"] {
    width: 100%;
}

/* ====================================
   Responsive Widths Utilities
   ==================================== */
.w-responsive-full {
    width: clamp(320px, 100%, 1536px);
}

.w-responsive-container {
    width: clamp(320px, 95vw, 1280px);
    margin: 0 auto;
}

/* ====================================
   Safe Area Padding (for notched devices)
   ==================================== */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    .safe-area-top {
        padding-top: max(0px, env(safe-area-inset-top));
    }
    
    .safe-area-bottom {
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
}

/* ====================================
   Prevent Text Overflow
   ==================================== */
.text-ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.text-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.text-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ====================================
   Aspect Ratio Utility (for older browsers)
   ==================================== */
@supports not (aspect-ratio: 16 / 9) {
    .aspect-16-9 {
        position: relative;
        padding-bottom: 56.25%;
    }
    
    .aspect-16-9 > * {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
    
    .aspect-1-1 {
        position: relative;
        padding-bottom: 100%;
    }
    
    .aspect-1-1 > * {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
}

/* ====================================
   Smooth Scrolling
   ==================================== */
html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

/* ====================================
   Focus Visible (Accessibility)
   ==================================== */
*:focus-visible {
    outline: 2px solid #d2ac67;
    outline-offset: 2px;
}

button:focus-visible,
a:focus-visible {
    outline: 2px solid #d2ac67;
    outline-offset: 2px;
}

/* ====================================
   Prevent Layout Shift
   ==================================== */
.prevent-shift {
    contain: layout;
}

img[loading="lazy"] {
    content-visibility: auto;
}

/* ====================================
   Responsive Table
   ==================================== */
@media (max-width: 767px) {
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table-responsive table {
        min-width: 600px;
    }
}

/* ====================================
   Hidden Utilities - Responsive
   ==================================== */
@media (max-width: 639px) {
    .hidden-mobile {
        display: none !important;
    }
}

@media (min-width: 640px) and (max-width: 1023px) {
    .hidden-tablet {
        display: none !important;
    }
}

@media (min-width: 1024px) {
    .hidden-desktop {
        display: none !important;
    }
}

/* ====================================
   Flex & Grid Gap Responsive
   ==================================== */
.gap-responsive-xs {
    gap: clamp(4px, 0.5vw, 8px);
}

.gap-responsive-sm {
    gap: clamp(8px, 1vw, 16px);
}

.gap-responsive-md {
    gap: clamp(16px, 2vw, 24px);
}

.gap-responsive-lg {
    gap: clamp(24px, 3vw, 40px);
}

.gap-responsive-xl {
    gap: clamp(32px, 4vw, 64px);
}

/* ====================================
   Print Styles
   ==================================== */
@media print {
    .no-print {
        display: none !important;
    }
    
    body {
        background: white;
        color: black;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
    }
}

/* ====================================
   RTL Optimization
   ==================================== */
[dir="rtl"] .ml-auto {
    margin-left: 0;
    margin-right: auto;
}

[dir="rtl"] .mr-auto {
    margin-right: 0;
    margin-left: auto;
}

/* ====================================
   Performance Optimization
   ==================================== */
.lazy-load {
    opacity: 0;
    transition: opacity 0.3s;
}

.lazy-load.loaded {
    opacity: 1;
}

/* GPU Acceleration for animations */
.hardware-accelerated {
    transform: translateZ(0);
    will-change: transform;
}

/* ====================================
   Mobile Viewport Fix
   ==================================== */
@supports (-webkit-touch-callout: none) {
    .min-h-screen {
        min-height: -webkit-fill-available;
    }
}

/* ====================================
   Reduced Data Mode
   ==================================== */
@media (prefers-reduced-data: reduce) {
    * {
        background-image: none !important;
    }
}

/* ====================================
   Dark Mode Support (if needed)
   ==================================== */
@media (prefers-color-scheme: dark) {
    [data-theme="auto"] {
        /* Dark mode styles inherited from theme-mode.css */
    }
}

/* ====================================
   High Contrast Mode
   ==================================== */
@media (prefers-contrast: high) {
    * {
        border-width: 2px !important;
    }
}

/* ====================================
   Landscape Orientation Fixes
   ==================================== */
@media (max-height: 500px) and (orientation: landscape) {
    .hero-slider {
        min-height: 350px;
    }
    
    .footer-container {
        position: relative;
    }
}

/* ====================================
   Foldable/Dual Screen Support
   ==================================== */
@media (horizontal-viewport-segments: 2) {
    .main-content {
        margin-left: env(viewport-segment-width 0 0);
        margin-right: env(viewport-segment-width 1 0);
    }
}

