/**
 * Production-Ready Enhancement CSS
 * Final optimization and professional styling for MWG Hostels Platform
 */

/* ===== CRITICAL FIXES ===== */

/* Fix backdrop-filter for Safari */
.glass {
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
}

.glass-card {
    -webkit-backdrop-filter: blur(15px);
    backdrop-filter: blur(15px);
}

/* Enhanced High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #000000;
        --secondary-color: #ffffff;
        --background-overlay: rgba(255, 255, 255, 0.95);
        --text-color: #000000;
        --card-background: rgba(255, 255, 255, 0.98);
    }
    
    .glass, .glass-card {
        background: rgba(255, 255, 255, 0.98);
        border: 2px solid #000000;
    }
    
    .btn-primary {
        background: #000000 !important;
        color: #ffffff !important;
        border: 2px solid #000000 !important;
    }
    
    .btn-secondary {
        background: #ffffff !important;
        color: #000000 !important;
        border: 2px solid #000000 !important;
    }
}

/* Enhanced Reduced Motion */
@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;
    }
    
    .floating-animation,
    .glow-effect,
    .pulse-effect {
        animation: none !important;
    }
    
    .parallax-bg {
        transform: none !important;
    }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */

/* Optimize loading states */
.loading-placeholder {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s infinite;
    border-radius: 8px;
}

@keyframes loading-shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Lazy loading optimization */
.lazy-load {
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

/* Critical resource hints */
.preload-important {
    content: "";
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

/* ===== ENHANCED ACCESSIBILITY ===== */

/* Skip links enhancement */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--primary-color);
    color: white;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 600;
    z-index: 10000;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 6px;
    outline: 3px solid #ffff00;
    outline-offset: 2px;
}

/* Enhanced focus indicators */
.focus-visible {
    outline: 3px solid #007bff;
    outline-offset: 2px;
    border-radius: 4px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid #007bff;
    outline-offset: 2px;
}

/* Screen reader enhancements */
.sr-only {
    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;
}

.sr-only-focusable:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    padding: 0.5rem !important;
    margin: 0 !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
}

/* ===== MOBILE OPTIMIZATIONS ===== */

/* Touch target optimization */
@media (max-width: 768px) {
    button, .btn, a, input, select, textarea {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
    }
    
    .hostel-card {
        margin-bottom: 16px;
        touch-action: manipulation;
    }
    
    .cta-button {
        font-size: 16px; /* Prevent zoom on iOS */
        min-height: 48px;
    }
    
    /* Safe area insets for modern phones */
    .main-container {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
    
    /* Improved scroll performance */
    .scrollable-content {
        scroll-behavior: smooth;
    }
}

/* ===== PWA ENHANCEMENTS ===== */

/* PWA install prompt */
.install-prompt {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background: var(--card-background);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 16px;
    z-index: 1000;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
}

.install-prompt.show {
    transform: translateY(0);
    opacity: 1;
}

.install-prompt .install-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.install-prompt .install-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.install-prompt .install-text {
    flex: 1;
}

.install-prompt .install-title {
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-color);
}

.install-prompt .install-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
}

.install-buttons {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.install-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.install-btn.primary {
    background: var(--primary-color);
    color: white;
}

.install-btn.secondary {
    background: rgba(0, 0, 0, 0.1);
    color: var(--text-color);
}

/* Connection status indicator */
.connection-status {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    z-index: 1000;
    transition: all 0.3s ease;
    transform: translateY(-50px);
    opacity: 0;
}

.connection-status.show {
    transform: translateY(0);
    opacity: 1;
}

.connection-status.connection-fast {
    background: #10b981;
    color: white;
}

.connection-status.connection-slow {
    background: #f59e0b;
    color: white;
}

.connection-status.connection-offline {
    background: #ef4444;
    color: white;
}

.connection-status.connection-data-saver {
    background: #6366f1;
    color: white;
}

/* ===== ENHANCED ANIMATIONS ===== */

/* Stagger animations for lists */
.stagger-animation {
    opacity: 0;
    transform: translateY(20px);
    animation: stagger-in 0.6s ease forwards;
}

.stagger-animation:nth-child(1) { animation-delay: 0.1s; }
.stagger-animation:nth-child(2) { animation-delay: 0.2s; }
.stagger-animation:nth-child(3) { animation-delay: 0.3s; }
.stagger-animation:nth-child(4) { animation-delay: 0.4s; }
.stagger-animation:nth-child(5) { animation-delay: 0.5s; }

@keyframes stagger-in {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Enhanced hover effects */
.enhanced-hover {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
}

.enhanced-hover:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

/* Micro-interactions */
.btn-micro {
    position: relative;
    overflow: hidden;
}

.btn-micro::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

.btn-micro:hover::before {
    left: 100%;
}

/* ===== PRINT STYLES ===== */
@media print {
    .no-print,
    .header-nav,
    .cta-buttons,
    .floating-nav,
    .install-prompt,
    .connection-status {
        display: none !important;
    }
    
    .main-container {
        max-width: none;
        margin: 0;
        padding: 0;
        background: white;
    }
    
    .hostel-card {
        break-inside: avoid;
        border: 1px solid #ccc;
        margin-bottom: 20px;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 12px;
        color: #666;
    }
}

/* ===== ERROR STATES ===== */

/* Enhanced error messaging */
.error-state {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
    color: #991b1b;
}

.error-state .error-icon {
    color: #dc2626;
    margin-right: 8px;
}

.error-state .error-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.error-state .error-message {
    font-size: 14px;
    line-height: 1.5;
}

.error-state .error-actions {
    margin-top: 12px;
    display: flex;
    gap: 8px;
}

/* Success states */
.success-state {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
    color: #166534;
}

.success-state .success-icon {
    color: #16a34a;
    margin-right: 8px;
}

/* Warning states */
.warning-state {
    background: #fffbeb;
    border: 1px solid #fed7aa;
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
    color: #92400e;
}

.warning-state .warning-icon {
    color: #d97706;
    margin-right: 8px;
}

/* ===== DARK MODE ENHANCEMENTS ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --primary-color: #3b82f6;
        --secondary-color: #64748b;
        --background-color: #0f172a;
        --background-overlay: rgba(15, 23, 42, 0.9);
        --text-color: #f8fafc;
        --text-secondary: #cbd5e1;
        --card-background: rgba(30, 41, 59, 0.8);
        --border-color: rgba(148, 163, 184, 0.2);
    }
    
    .glass {
        background: rgba(30, 41, 59, 0.8);
        border: 1px solid rgba(148, 163, 184, 0.2);
    }
    
    .error-state {
        background: #450a0a;
        border-color: #7f1d1d;
        color: #fca5a5;
    }
    
    .success-state {
        background: #052e16;
        border-color: #166534;
        color: #86efac;
    }
    
    .warning-state {
        background: #451a03;
        border-color: #92400e;
        color: #fcd34d;
    }
}

/* ===== ADVANCED GRID LAYOUTS ===== */

/* Modern CSS Grid for hostel cards */
.hostel-grid-modern {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 24px;
    margin: 24px 0;
}

/* Masonry-like layout for varied content */
.masonry-layout {
    column-count: 3;
    column-gap: 24px;
    column-fill: balance;
}

.masonry-layout .masonry-item {
    break-inside: avoid;
    margin-bottom: 24px;
}

@media (max-width: 768px) {
    .masonry-layout {
        column-count: 1;
    }
}

/* ===== FINAL POLISH ===== */

/* Smooth scrolling enhancement */
html {
    scroll-behavior: smooth;
}

/* Selection styling */
::selection {
    background: rgba(59, 130, 246, 0.3);
    color: inherit;
}

/* Enhanced placeholder styling */
::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(59, 130, 246, 0.8);
}

/* Final responsive typography */
.responsive-text {
    font-size: clamp(1rem, 2.5vw, 1.25rem);
    line-height: 1.6;
}

.responsive-heading {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    line-height: 1.2;
}

/* Performance monitoring display */
.performance-indicator {
    position: fixed;
    bottom: 20px;
    left: 20px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    border-radius: 4px;
    font-size: 12px;
    font-family: monospace;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.performance-indicator.show {
    opacity: 1;
}

/* Critical path optimization */
.critical-resource {
    font-display: swap;
    /* Loading strategy handled via HTML attributes */
}

/* Non-critical resources use lazy loading via HTML loading="lazy" attribute */

/* ===== PRODUCTION READY STATES ===== */

/* Loading states for production */
.production-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-secondary);
}

.production-loading .spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 12px;
}

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

/* Final accessibility compliance */
.accessibility-compliant {
    outline: none;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.accessibility-compliant:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* Production error boundary */
.error-boundary {
    padding: 40px;
    text-align: center;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    margin: 20px;
}

.error-boundary h2 {
    color: #dc2626;
    margin-bottom: 16px;
}

.error-boundary p {
    color: #991b1b;
    margin-bottom: 20px;
}

.error-boundary button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}