/* ========================================
   Responsive Utilities CSS
   Mobile-First Design System
   ======================================== */

/* ========================================
   Breakpoint Reference:
   - xs: 0px (base mobile)
   - sm: 640px (large mobile/small tablet)
   - md: 768px (tablet)
   - lg: 1024px (desktop)
   - xl: 1280px (large desktop)
   - 2xl: 1536px (extra large)
   ======================================== */

/* ========================================
   Tap Target Enforcement (44x44px minimum)
   ======================================== */

/* All interactive elements must have minimum tap target */
a,
button,
input[type="button"],
input[type="submit"],
input[type="reset"],
input[type="checkbox"],
input[type="radio"],
select,
[role="button"],
[role="link"],
[role="menuitem"],
[role="tab"],
.clickable,
.tappable {
    min-height: 44px;
    min-width: 44px;
}

/* Form inputs need adequate height */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="url"],
input[type="number"],
input[type="date"],
textarea,
select {
    min-height: 44px;
    padding: var(--space-3);
    font-size: 16px; /* Prevents iOS zoom on focus */
}

/* Checkbox and radio with proper spacing */
input[type="checkbox"],
input[type="radio"] {
    width: 20px;
    height: 20px;
    margin: 12px; /* Creates 44px total tap area */
}

/* Links in navigation */
.nav-link,
.nav-sublink,
.mobile-nav-link,
.mobile-nav-sublink {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: var(--space-2) var(--space-4);
}

/* Small buttons need padding to reach 44px */
.btn-sm,
.btn-icon {
    min-height: 44px;
    min-width: 44px;
    padding: var(--space-2);
}

/* ========================================
   Responsive Typography
   ======================================== */

/* Base: Mobile (320px+) */
html {
    font-size: 16px;
}

h1, .h1 {
    font-size: 1.75rem; /* 28px */
    line-height: 1.2;
}

h2, .h2 {
    font-size: 1.5rem; /* 24px */
    line-height: 1.25;
}

h3, .h3 {
    font-size: 1.25rem; /* 20px */
    line-height: 1.3;
}

h4, .h4 {
    font-size: 1.125rem; /* 18px */
    line-height: 1.35;
}

h5, .h5,
h6, .h6 {
    font-size: 1rem; /* 16px */
    line-height: 1.4;
}

/* Article content typography */
.article-content,
.article-content-enhanced {
    font-size: 1rem; /* 16px mobile */
    line-height: 1.7;
    max-width: 65ch; /* Optimal reading width */
}

/* sm: 640px+ */
@media (min-width: 640px) {
    h1, .h1 { font-size: 2rem; }
    h2, .h2 { font-size: 1.75rem; }
    h3, .h3 { font-size: 1.5rem; }
    
    .article-content,
    .article-content-enhanced {
        font-size: 1.0625rem; /* 17px */
    }
}

/* md: 768px+ */
@media (min-width: 768px) {
    h1, .h1 { font-size: 2.25rem; }
    h2, .h2 { font-size: 1.875rem; }
    h3, .h3 { font-size: 1.5rem; }
}

/* lg: 1024px+ */
@media (min-width: 1024px) {
    h1, .h1 { font-size: 2.5rem; }
    h2, .h2 { font-size: 2rem; }
    h3, .h3 { font-size: 1.75rem; }
    
    .article-content,
    .article-content-enhanced {
        font-size: 1.125rem; /* 18px desktop */
        line-height: 1.8;
    }
}

/* xl: 1280px+ */
@media (min-width: 1280px) {
    h1, .h1 { font-size: 3rem; }
    h2, .h2 { font-size: 2.25rem; }
}

/* ========================================
   Responsive Images with srcset support
   ======================================== */

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Responsive image container */
.img-responsive {
    width: 100%;
    height: auto;
}

/* Aspect ratio containers */
.aspect-video {
    aspect-ratio: 16 / 9;
}

.aspect-square {
    aspect-ratio: 1 / 1;
}

.aspect-4-3 {
    aspect-ratio: 4 / 3;
}

.aspect-3-2 {
    aspect-ratio: 3 / 2;
}

/* Image with object-fit */
.img-cover {
    object-fit: cover;
    width: 100%;
    height: 100%;
}

.img-contain {
    object-fit: contain;
    width: 100%;
    height: 100%;
}

/* ========================================
   Responsive Grid System
   ======================================== */

.grid {
    display: grid;
    gap: var(--space-4);
}

/* Auto-fit grids */
.grid-auto-fit-sm {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.grid-auto-fit-md {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.grid-auto-fit-lg {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

/* Fixed column grids - Mobile first (1 column) */
.grid-cols-1 { grid-template-columns: 1fr; }

@media (min-width: 640px) {
    .sm\:grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 768px) {
    .md\:grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
    .md\:grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1024px) {
    .lg\:grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
    .lg\:grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
    .lg\:grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 1280px) {
    .xl\:grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
    .xl\:grid-cols-5 { grid-template-columns: repeat(5, 1fr); }
}

/* ========================================
   Responsive Spacing
   ======================================== */

/* Padding utilities */
.p-responsive {
    padding: var(--space-4);
}

@media (min-width: 640px) {
    .p-responsive { padding: var(--space-6); }
}

@media (min-width: 1024px) {
    .p-responsive { padding: var(--space-8); }
}

/* Section spacing */
.section-spacing {
    padding-top: var(--space-8);
    padding-bottom: var(--space-8);
}

@media (min-width: 640px) {
    .section-spacing {
        padding-top: var(--space-12);
        padding-bottom: var(--space-12);
    }
}

@media (min-width: 1024px) {
    .section-spacing {
        padding-top: var(--space-16);
        padding-bottom: var(--space-16);
    }
}

/* ========================================
   Responsive Display Utilities
   ======================================== */

/* Hide on mobile, show on larger screens */
.hidden-mobile {
    display: none;
}

@media (min-width: 768px) {
    .hidden-mobile { display: block; }
    .hidden-tablet { display: none; }
}

@media (min-width: 1024px) {
    .hidden-desktop { display: none; }
    .show-desktop { display: block; }
}

/* Show only on specific breakpoints */
.mobile-only {
    display: block;
}

@media (min-width: 768px) {
    .mobile-only { display: none; }
}

.tablet-only {
    display: none;
}

@media (min-width: 768px) and (max-width: 1023px) {
    .tablet-only { display: block; }
}

.desktop-only {
    display: none;
}

@media (min-width: 1024px) {
    .desktop-only { display: block; }
}

/* ========================================
   Container Utilities
   ======================================== */

.container {
    width: 100%;
    max-width: var(--container-xl);
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--space-4);
    padding-right: var(--space-4);
}

@media (min-width: 640px) {
    .container {
        padding-left: var(--space-6);
        padding-right: var(--space-6);
    }
}

@media (min-width: 1024px) {
    .container {
        padding-left: var(--space-8);
        padding-right: var(--space-8);
    }
}

/* Narrow container for article content */
.container-narrow {
    max-width: 720px;
}

/* Wide container */
.container-wide {
    max-width: var(--container-2xl);
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
    /* Hide non-essential elements */
    .no-print,
    .site-header,
    .site-footer,
    .sidebar,
    .comments-section,
    .engagement-section-enhanced,
    .social-sharing-enhanced,
    .newsletter-section,
    .back-to-top,
    .theme-toggle,
    .mobile-menu-toggle,
    .search-toggle,
    nav,
    button,
    .btn {
        display: none !important;
    }
    
    /* Reset colors for print */
    body {
        background: white !important;
        color: black !important;
        font-size: 12pt !important;
        line-height: 1.5 !important;
    }
    
    /* Article content optimization */
    .article-content,
    .article-content-enhanced {
        font-size: 12pt !important;
        line-height: 1.6 !important;
        max-width: 100% !important;
    }
    
    h1 { font-size: 18pt !important; }
    h2 { font-size: 16pt !important; }
    h3 { font-size: 14pt !important; }
    
    /* Show URLs for links */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 10pt;
        color: #666;
    }
    
    /* Don't show URL for internal links */
    a[href^="#"]::after,
    a[href^="javascript"]::after {
        content: "";
    }
    
    /* Page breaks */
    h1, h2, h3 {
        page-break-after: avoid;
    }
    
    img, figure {
        page-break-inside: avoid;
    }
    
    /* Ensure images print */
    img {
        max-width: 100% !important;
    }
}

/* ========================================
   Focus Styles for Accessibility
   ======================================== */

/* Visible focus for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Remove default focus for mouse users */
:focus:not(:focus-visible) {
    outline: none;
}

/* High contrast focus for buttons */
button:focus-visible,
.btn:focus-visible,
[role="button"]:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2);
}

/* ========================================
   Touch Device Optimizations
   ======================================== */

@media (hover: none) and (pointer: coarse) {
    /* Increase tap targets on touch devices */
    a, button, [role="button"] {
        min-height: 48px;
        min-width: 48px;
    }
    
    /* Remove hover effects on touch */
    .article-card:hover,
    .video-card:hover,
    .opinion-card:hover {
        transform: none;
    }
    
    /* Add active state instead */
    .article-card:active,
    .video-card:active,
    .opinion-card:active {
        transform: scale(0.98);
    }
}

/* ========================================
   Reduced Motion Support
   ======================================== */

@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 Mode Support
   ======================================== */

@media (prefers-contrast: high) {
    :root {
        --color-border-primary: #000;
        --color-border-secondary: #000;
    }
    
    a, button {
        text-decoration: underline;
    }
    
    .btn {
        border: 2px solid currentColor;
    }
}
