/* ========================================
   PERFORMANCE UTILITIES v1.0 - Phase 5
   Performance & Accessibility
   ======================================== */

/* =====================
   1. GPU ACCELERATION
   ===================== */

/* Force GPU acceleration for smooth animations */
.gpu-accelerate {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Promote element to its own layer */
.will-change-transform {
    will-change: transform;
}

.will-change-opacity {
    will-change: opacity;
}

.will-change-scroll {
    will-change: scroll-position;
}

/* =====================
   2. LAZY LOADING
   ===================== */

/* Placeholder for lazy images */
.lazy-image {
    opacity: 0;
    transition: opacity var(--duration-300) var(--ease-out);
}

.lazy-image.loaded {
    opacity: 1;
}

/* Blur-up placeholder */
.lazy-image-wrapper {
    position: relative;
    overflow: hidden;
    background: var(--bg-elevated);
}

.lazy-image-placeholder {
    position: absolute;
    inset: 0;
    filter: blur(20px);
    transform: scale(1.1);
    transition: opacity var(--duration-500) var(--ease-out);
}

.lazy-image-wrapper.loaded .lazy-image-placeholder {
    opacity: 0;
}

/* =====================
   3. IMAGE OPTIMIZATION
   ===================== */

/* Responsive images */
.img-responsive {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Maintain aspect ratio */
.aspect-square { aspect-ratio: 1 / 1; }
.aspect-video { aspect-ratio: 16 / 9; }
.aspect-poster { aspect-ratio: 2 / 3; }
.aspect-wide { aspect-ratio: 21 / 9; }

/* Object fit */
.object-cover {
    object-fit: cover;
    width: 100%;
    height: 100%;
}

.object-contain {
    object-fit: contain;
    width: 100%;
    height: 100%;
}

.object-fill {
    object-fit: fill;
    width: 100%;
    height: 100%;
}

/* =====================
   4. CONTENT VISIBILITY
   ===================== */

/* Lazy render off-screen content */
.content-lazy {
    content-visibility: auto;
    contain-intrinsic-size: 0 500px;
}

/* Contain layout/paint for performance */
.contain-layout {
    contain: layout;
}

.contain-paint {
    contain: paint;
}

.contain-strict {
    contain: strict;
}

/* =====================
   5. SCROLL PERFORMANCE
   ===================== */

/* Smooth scroll container */
.scroll-smooth {
    scroll-behavior: smooth;
}

/* Snap scroll */
.scroll-snap-x {
    scroll-snap-type: x mandatory;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.scroll-snap-y {
    scroll-snap-type: y mandatory;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.scroll-snap-item {
    scroll-snap-align: start;
}

.scroll-snap-center {
    scroll-snap-align: center;
}

/* Hide scrollbar but keep functionality */
.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

/* Custom scrollbar */
.scrollbar-thin {
    scrollbar-width: thin;
    scrollbar-color: var(--color-primary-500) var(--bg-elevated);
}

.scrollbar-thin::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.scrollbar-thin::-webkit-scrollbar-track {
    background: var(--bg-elevated);
    border-radius: var(--radius-full);
}

.scrollbar-thin::-webkit-scrollbar-thumb {
    background: var(--color-primary-500);
    border-radius: var(--radius-full);
}

/* =====================
   6. TOUCH OPTIMIZATION
   ===================== */

/* Prevent touch highlights */
.no-tap-highlight {
    -webkit-tap-highlight-color: transparent;
}

/* Touch manipulation */
.touch-pan-x {
    touch-action: pan-x;
}

.touch-pan-y {
    touch-action: pan-y;
}

.touch-none {
    touch-action: none;
}

/* =====================
   7. TEXT PERFORMANCE
   ===================== */

/* Font optimization */
.font-smooth {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Prevent text orphans */
.text-balanced {
    text-wrap: balance;
}

/* Text overflow */
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* =====================
   8. VISIBILITY UTILITIES
   ===================== */

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus visible only */
.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    padding: inherit;
    margin: inherit;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* Hidden but accessible */
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* =====================
   9. FOCUS MANAGEMENT
   ===================== */

/* Focus visible only when using keyboard */
:focus {
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--color-primary-500);
    outline-offset: 2px;
}

/* Focus ring */
.focus-ring:focus-visible {
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.3);
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    padding: var(--space-3) var(--space-6);
    background: var(--color-primary-500);
    color: white;
    font-weight: var(--font-weight-semibold);
    border-radius: var(--radius-lg);
    z-index: var(--z-toast);
    transition: top var(--duration-200) var(--ease-out);
}

.skip-link:focus {
    top: var(--space-4);
}

/* =====================
   10. POINTER UTILITIES
   ===================== */

.pointer-events-none {
    pointer-events: none;
}

.pointer-events-auto {
    pointer-events: auto;
}

.cursor-pointer {
    cursor: pointer;
}

.cursor-not-allowed {
    cursor: not-allowed;
}

.cursor-grab {
    cursor: grab;
}

.cursor-grab:active {
    cursor: grabbing;
}

/* =====================
   11. SELECTION
   ===================== */

.select-none {
    user-select: none;
    -webkit-user-select: none;
}

.select-text {
    user-select: text;
    -webkit-user-select: text;
}

.select-all {
    user-select: all;
    -webkit-user-select: all;
}

/* Custom selection color */
::selection {
    background: var(--color-primary-500);
    color: white;
}

::-moz-selection {
    background: var(--color-primary-500);
    color: white;
}

/* =====================
   12. PRINT STYLES
   ===================== */

@media print {
    /* Hide non-essential elements */
    .no-print,
    .modern-header,
    .mobile-bottom-nav,
    .footer-section {
        display: none !important;
    }
    
    /* Reset backgrounds for ink saving */
    body {
        background: white !important;
        color: black !important;
    }
    
    .card,
    .glass-card {
        background: white !important;
        border: 1px solid #ddd !important;
        box-shadow: none !important;
    }
    
    /* Ensure links are visible */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
    
    /* Page breaks */
    .print-break-before {
        page-break-before: always;
    }
    
    .print-break-after {
        page-break-after: always;
    }
    
    .print-break-avoid {
        page-break-inside: avoid;
    }
}

/* =====================
   13. SAFE AREA (Notch)
   ===================== */

.safe-area-top {
    padding-top: env(safe-area-inset-top, 0);
}

.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.safe-area-left {
    padding-left: env(safe-area-inset-left, 0);
}

.safe-area-right {
    padding-right: env(safe-area-inset-right, 0);
}

.safe-area-all {
    padding: env(safe-area-inset-top, 0) 
             env(safe-area-inset-right, 0) 
             env(safe-area-inset-bottom, 0) 
             env(safe-area-inset-left, 0);
}

/* =====================
   14. DISPLAY HELPERS
   ===================== */

/* Responsive display */
@media (max-width: 639px) {
    .hidden-sm { display: none !important; }
}

@media (min-width: 640px) and (max-width: 767px) {
    .hidden-md { display: none !important; }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .hidden-lg { display: none !important; }
}

@media (min-width: 1024px) {
    .hidden-xl { display: none !important; }
}

/* Mobile only */
@media (max-width: 767px) {
    .desktop-only { display: none !important; }
}

/* Desktop only */
@media (min-width: 768px) {
    .mobile-only { display: none !important; }
}

/* =====================
   15. FLEX/GRID HELPERS
   ===================== */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.flex-none { flex: none; }

.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }

.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-around { justify-content: space-around; }
.justify-start { justify-content: flex-start; }
.justify-end { justify-content: flex-end; }

.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }

.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

/* =====================
   16. SPACING HELPERS
   ===================== */

.m-0 { margin: 0; }
.m-auto { margin: auto; }
.mx-auto { margin-left: auto; margin-right: auto; }
.my-auto { margin-top: auto; margin-bottom: auto; }

.p-0 { padding: 0; }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.p-8 { padding: var(--space-8); }

/* =====================
   17. TEXT HELPERS
   ===================== */

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.text-xs { font-size: var(--font-size-xs); }
.text-sm { font-size: var(--font-size-sm); }
.text-base { font-size: var(--font-size-base); }
.text-lg { font-size: var(--font-size-lg); }
.text-xl { font-size: var(--font-size-xl); }
.text-2xl { font-size: var(--font-size-2xl); }

.font-normal { font-weight: var(--font-weight-normal); }
.font-medium { font-weight: var(--font-weight-medium); }
.font-semibold { font-weight: var(--font-weight-semibold); }
.font-bold { font-weight: var(--font-weight-bold); }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--color-success-500); }
.text-danger { color: var(--color-danger-500); }
.text-warning { color: var(--color-warning-500); }
