/**
 * Production-Ready CSS
 * Comprehensive styles for robust deployment across all devices
 */

/* Critical rendering path optimization */
.critical-above-fold {
    display: block;
    visibility: visible;
}

.below-fold {
    will-change: transform, opacity;
}

/* Enhanced error states */
.error-boundary {
    background: rgba(244, 67, 54, 0.1);
    border: 2px solid #f44336;
    border-radius: 8px;
    padding: 1rem;
    color: #ffffff;
    text-align: center;
    margin: 1rem 0;
}

.error-boundary h3 {
    color: #f44336;
    margin-bottom: 0.5rem;
}

.loading-fallback {
    background: rgba(21, 21, 48, 0.9);
    padding: 2rem;
    text-align: center;
    color: #ffffff;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.loading-spinner {
    border: 3px solid rgba(156, 39, 176, 0.3);
    border-top: 3px solid #9c27b0;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Network status indicators */
.network-status {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 0.5rem;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 9999;
    transition: all 0.3s ease;
    transform: translateY(-100%);
}

.network-status.online {
    background: rgba(76, 175, 80, 0.9);
    color: white;
    transform: translateY(0);
}

.network-status.offline {
    background: rgba(244, 67, 54, 0.9);
    color: white;
    transform: translateY(0);
}

.offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

/* Fallback mode styles */
.fallback-mode {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.fallback-mode * {
    animation: none !important;
    transition: none !important;
}

.fallback-mode .complex-bg {
    background: #151530 !important;
}

/* Performance optimizations */
.gpu-accelerated {
    transform: translateZ(0);
    will-change: transform;
}

.contain-layout {
    contain: layout style;
}

.contain-paint {
    contain: paint;
}

/* Mobile-specific optimizations */
@media (max-width: 768px) {
    /* Improve tap targets */
    .btn,
    .nav-link,
    .form-control,
    button,
    input,
    select,
    textarea {
        min-height: 44px;
        min-width: 44px;
    }

    /* Optimize scrolling */
    body {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }

    /* Reduce visual complexity on mobile */
    .mobile-view .energy-particle {
        opacity: 0.3;
        animation-duration: 4s;
    }

    .mobile-view .cosmic-background {
        opacity: 0.6;
        filter: blur(1px);
    }

    /* Enhanced mobile navigation */
    .mobile-nav {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100vh;
        background: rgba(21, 21, 48, 0.98);
        backdrop-filter: blur(15px);
        border-right: 2px solid rgba(156, 39, 176, 0.3);
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        overflow-y: auto;
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    }

    .mobile-nav.active {
        left: 0;
    }

    .mobile-nav-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }

    .mobile-nav-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    .mobile-nav-item {
        display: block;
        padding: 1rem 1.5rem;
        color: #ffffff;
        text-decoration: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        transition: all 0.2s ease;
        position: relative;
    }

    .mobile-nav-item:hover,
    .mobile-nav-item:focus {
        background: rgba(156, 39, 176, 0.2);
        color: #ffffff;
        transform: translateX(5px);
    }

    .mobile-nav-item:before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 3px;
        background: #9c27b0;
        transform: scaleY(0);
        transition: transform 0.2s ease;
    }

    .mobile-nav-item:hover:before {
        transform: scaleY(1);
    }

    .nav-description {
        display: block;
        font-size: 0.8rem;
        color: rgba(255, 255, 255, 0.7);
        margin-top: 0.25rem;
        font-weight: 400;
    }

    /* Menu toggle button */
    .menu-toggle {
        position: fixed;
        top: 1rem;
        right: 1rem;
        z-index: 1001;
        background: rgba(21, 21, 48, 0.9);
        border: 2px solid rgba(156, 39, 176, 0.5);
        color: #ffffff;
        border-radius: 8px;
        padding: 0.75rem;
        font-size: 1.2rem;
        cursor: pointer;
        transition: all 0.2s ease;
        backdrop-filter: blur(10px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

    .menu-toggle:hover,
    .menu-toggle:focus {
        background: rgba(156, 39, 176, 0.8);
        border-color: #ffffff;
        transform: scale(1.05);
    }

    .menu-toggle.active {
        background: rgba(156, 39, 176, 0.9);
        transform: rotate(90deg);
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn-primary {
        background: #ffffff;
        color: #000000;
        border: 3px solid #000000;
    }

    .btn-secondary {
        background: #000000;
        color: #ffffff;
        border: 3px solid #ffffff;
    }

    .card,
    .modal-content,
    .mobile-nav {
        background: #000000;
        border: 3px solid #ffffff;
    }

    .text-muted {
        color: #ffffff !important;
    }
}

/* 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;
    }

    .energy-particle,
    .floating-element {
        display: none !important;
    }
}

/* Dark mode optimization */
@media (prefers-color-scheme: dark) {
    /* Enhanced dark mode styles */
    :root {
        --bg-primary: #0a0a1a;
        --bg-secondary: #151530;
        --text-primary: #ffffff;
        --text-secondary: rgba(255, 255, 255, 0.8);
        --accent-primary: #9c27b0;
        --accent-secondary: #673ab7;
    }
}

/* Print styles */
@media print {
    body {
        background: white !important;
        color: black !important;
    }

    .mobile-nav,
    .menu-toggle,
    .network-status,
    .offline-banner,
    .btn,
    .energy-particle {
        display: none !important;
    }

    .card {
        border: 1px solid #000000;
        background: white;
        box-shadow: none;
    }

    a {
        color: #000000;
        text-decoration: underline;
    }

    h1, h2, h3, h4, h5, h6 {
        color: #000000;
        page-break-after: avoid;
    }

    .page-break {
        page-break-before: always;
    }
}

/* PWA specific styles */
@media (display-mode: standalone) {
    /* App-like experience when installed as PWA */
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .menu-toggle {
        top: calc(1rem + env(safe-area-inset-top));
    }

    .mobile-nav {
        padding-top: env(safe-area-inset-top);
    }
}

/* Connection-specific optimizations */
@media (prefers-reduced-data: reduce) {
    /* Ultra-low data mode */
    .cosmic-background {
        background: #151530 !important;
    }

    .energy-particle,
    .floating-element,
    .cosmic-animation {
        display: none !important;
    }

    img {
        filter: contrast(0.9) brightness(0.95);
    }

    .btn {
        background: #9c27b0 !important;
        box-shadow: none !important;
    }
}

/* Accessibility enhancements */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #9c27b0;
    color: white;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 10000;
}

.skip-link:focus {
    top: 6px;
}

/* Focus management */
.focus-trap {
    position: relative;
}

.focus-trap:focus-within {
    outline: 2px solid #9c27b0;
    outline-offset: 2px;
}

/* Better focus indicators */
button:focus,
input:focus,
select:focus,
textarea:focus,
.btn:focus,
.nav-link:focus {
    outline: 2px solid #9c27b0;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(156, 39, 176, 0.2);
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .hover-effect:hover {
        transform: none;
    }

    .btn:active {
        transform: scale(0.98);
    }

    .mobile-nav-item:active {
        background: rgba(156, 39, 176, 0.4);
    }
}