/**
 * Responsive Design System - Mobile First Approach
 * 
 * Base styles are mobile-optimized, then enhanced for larger screens
 */

/* ==========================================================================
   Responsive Variables
   ========================================================================== */
:root {
    /* Breakpoints */
    --breakpoint-sm: 576px;
    --breakpoint-md: 768px;
    --breakpoint-lg: 1024px;
    --breakpoint-xl: 1200px;
    --breakpoint-xxl: 1440px;
    
    /* Touch target sizes */
    --touch-target-min: 44px;
    --touch-target-comfortable: 48px;
}

/* ==========================================================================
   Base Styles (Mobile First)
   ========================================================================== */

/* Base Document */
html {
    -webkit-text-size-adjust: 100%;
}

body {
    -webkit-tap-highlight-color: transparent;
}

/* Prevent horizontal overflow */
html,
body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

/* Main content areas */
#page,
#content,
.site-content,
main {
    overflow-x: hidden;
    width: 100%;
}

/* Container - Mobile First */
.container {
    width: 100%;
    padding-left: var(--space-md);
    padding-right: var(--space-md);
    margin-left: auto;
    margin-right: auto;
}

/* Typography - Mobile First */
body {
    font-size: 14px;
}

h1, .h1 {
    font-size: clamp(1.75rem, 5vw, 3rem);
}

h2, .h2 {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
}

h3, .h3 {
    font-size: clamp(1.25rem, 3.5vw, 2rem);
}

h4, .h4 {
    font-size: clamp(1.125rem, 3vw, 1.5rem);
}

p {
    margin-bottom: var(--space-md);
}

/* Touch-friendly interactive elements */
button,
a.button,
.btn,
input[type="submit"],
input[type="button"] {
    min-height: var(--touch-target-min);
    padding: var(--space-sm) var(--space-lg);
}

/* Form elements */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="search"],
input[type="url"],
textarea,
select {
    min-height: var(--touch-target-min);
    padding: var(--space-sm) var(--space-md);
    font-size: 16px; /* Prevents zoom on iOS */
    width: 100%;
}

/* Tables - Mobile scrollable */
table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Images */
img {
    max-width: 100%;
    height: auto;
}

/* Code blocks */
pre {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Grid - Mobile First (single column) */
.grid,
[class*="grid-cols-"] {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-md);
}

/* Flex - Mobile First (column) */
.flex {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* Section spacing - Mobile First */
section {
    padding-top: var(--space-2xl);
    padding-bottom: var(--space-2xl);
}

/* Visibility utilities - Mobile First */
.desktop-only {
    display: none;
}

.tablet-only {
    display: none;
}

.mobile-only {
    display: block;
}

/* Navigation - Mobile First */
.desktop-navigation {
    display: none;
}

.mobile-menu-toggle {
    display: flex;
}

/* Cards - Mobile First */
.card {
    margin-bottom: var(--space-lg);
}

.card-horizontal {
    flex-direction: column;
}

/* Forms - Mobile First */
.form-row {
    flex-direction: column;
}

.form-col {
    width: 100%;
    margin-bottom: var(--space-md);
}

/* ==========================================================================
   Small devices (≥576px)
   ========================================================================== */
@media (min-width: 576px) {
    /* Container */
    .container {
        max-width: 540px;
    }
    
    /* Grid enhancements */
    .grid-cols-sm-2 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ==========================================================================
   Medium devices / Tablets (≥768px)
   ========================================================================== */
@media (min-width: 768px) {
    /* Container */
    .container {
        max-width: 720px;
        padding-left: var(--space-lg);
        padding-right: var(--space-lg);
    }
    
    /* Typography enhancements */
    body {
        font-size: 16px;
    }
    
    p {
        margin-bottom: var(--space-lg);
    }
    
    /* Grid enhancements */
    .grid-cols-2 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .grid-cols-md-3 {
        grid-template-columns: repeat(3, 1fr);
    }
    
    /* Flex enhancements */
    .flex-md-row {
        flex-direction: row;
    }
    
    /* Section spacing */
    section {
        padding-top: var(--space-3xl);
        padding-bottom: var(--space-3xl);
    }
    
    /* Visibility utilities */
    .tablet-only {
        display: block;
    }
    
    /* Cards */
    .card-horizontal {
        flex-direction: row;
    }
    
    /* Forms */
    .form-row {
        flex-direction: row;
    }
    
    .form-col {
        flex: 1;
        margin-bottom: 0;
    }
    
    /* Tables - Normal display */
    table {
        display: table;
    }
}

/* ==========================================================================
   Large devices / Desktops (≥1024px)
   ========================================================================== */
@media (min-width: 1024px) {
    /* Container */
    .container {
        max-width: 960px;
        padding-left: var(--space-xl);
        padding-right: var(--space-xl);
    }
    
    /* Grid enhancements */
    .grid-cols-3 {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .grid-cols-4 {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .grid-cols-lg-4 {
        grid-template-columns: repeat(4, 1fr);
    }
    
    /* Visibility utilities */
    .desktop-only {
        display: block;
    }
    
    .mobile-only {
        display: none;
    }
    
    .tablet-only {
        display: none;
    }
    
    /* Navigation */
    .desktop-navigation {
        display: flex;
    }
    
    .mobile-menu-toggle {
        display: none;
    }
}

/* ==========================================================================
   Extra large devices (≥1200px)
   ========================================================================== */
@media (min-width: 1200px) {
    /* Container */
    .container {
        max-width: 1140px;
    }
    
    /* Grid enhancements */
    .grid-cols-xl-5 {
        grid-template-columns: repeat(5, 1fr);
    }
    
    .grid-cols-xl-6 {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* ==========================================================================
   XXL devices (≥1440px)
   ========================================================================== */
@media (min-width: 1440px) {
    /* Container */
    .container {
        max-width: 1320px;
    }
}

/* ==========================================================================
   Special Cases & Feature Queries
   ========================================================================== */

/* Touch Device Styles */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    a:hover,
    button:hover {
        opacity: 1;
        transform: none;
    }
    
    /* Larger touch targets */
    a,
    button,
    [role="button"],
    input,
    select,
    textarea {
        min-height: var(--touch-target-min);
        min-width: var(--touch-target-min);
    }
    
    /* Disable parallax on touch devices */
    .parallax {
        background-attachment: scroll;
    }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Thinner borders on retina displays */
    .border {
        border-width: 0.5px;
    }
}

/* Landscape Orientation on Small Screens */
@media (orientation: landscape) and (max-height: 500px) {
    /* Reduce vertical spacing on small landscape screens */
    section {
        padding-top: var(--space-xl);
        padding-bottom: var(--space-xl);
    }
    
    .hero-section {
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */
@media print {
    /* Hide non-essential elements */
    .no-print,
    .navigation,
    .mobile-menu,
    .footer-widgets,
    .social-links,
    .back-to-top {
        display: none;
    }
    
    /* Reset colors for print */
    body {
        color: #000;
        background: #fff;
    }
    
    a {
        color: #000;
        text-decoration: underline;
    }
}

/* ==========================================================================
   Utility Classes for Responsive Design
   ========================================================================== */

/* Mobile utilities (default - no media query needed) */
.hidden { display: none; }
.block { display: block; }
.flex { display: flex; }
.grid { display: grid; }
.flex-col { flex-direction: column; }
.text-center { text-align: center; }
.text-left { text-align: left; }
.w-full { width: 100%; }

/* Small utilities */
@media (min-width: 576px) {
    .sm\:block { display: block; }
    .sm\:flex { display: flex; }
    .sm\:hidden { display: none; }
    .sm\:grid { display: grid; }
    .sm\:grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
}

/* Medium utilities */
@media (min-width: 768px) {
    .md\:block { display: block; }
    .md\:flex { display: flex; }
    .md\:hidden { display: none; }
    .md\:grid { display: grid; }
    .md\:grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
    .md\:grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
    .md\:flex-row { flex-direction: row; }
    .md\:text-left { text-align: left; }
    .md\:w-1\/2 { width: 50%; }
    .md\:w-auto { width: auto; }
}

/* Large utilities */
@media (min-width: 1024px) {
    .lg\:block { display: block; }
    .lg\:flex { display: flex; }
    .lg\:hidden { display: none; }
    .lg\:grid { display: grid; }
    .lg\:grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
    .lg\:grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
    .lg\:w-1\/3 { width: 33.333333%; }
    .lg\:w-1\/4 { width: 25%; }
}

/* Extra large utilities */
@media (min-width: 1200px) {
    .xl\:block { display: block; }
    .xl\:grid-cols-5 { grid-template-columns: repeat(5, 1fr); }
    .xl\:grid-cols-6 { grid-template-columns: repeat(6, 1fr); }
}

/* ==========================================================================
   Performance Optimizations
   ========================================================================== */

/* Reduce motion for users who prefer it */
@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;
    }
}

/* ==========================================================================
   Accessibility for Responsive
   ========================================================================== */

/* Ensure focus styles are visible on all devices */
:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Skip links */
.skip-link:focus {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: var(--z-tooltip);
}