/* ===============================================
   RESPONSIVE DESIGN FIXES & MOBILE OPTIMIZATION
   =============================================== */

/* Base Mobile Styles */
@media (max-width: 768px) {
    /* Navigation Fixes */
    .navbar {
        padding: 0.5rem 1rem;
    }
    
    .nav-container {
        flex-wrap: wrap;
    }
    
    .nav-menu {
        position: fixed;
        top: 70px;
        left: -100%;
        width: 100%;
        height: calc(100vh - 70px);
        background: var(--bg-card, #ffffff);
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        padding: 2rem 0;
        transition: left 0.3s ease;
        box-shadow: 0 5px 20px rgba(0,0,0,0.1);
        z-index: 1000;
    }
    
    .nav-menu.active {
        left: 0;
    }
    
    .nav-link {
        padding: 1rem 2rem;
        font-size: 1.1rem;
        width: 100%;
        text-align: center;
        border-bottom: 1px solid var(--border-primary, #e2e8f0);
    }
    
    .mobile-toggle {
        display: block;
        background: none;
        border: none;
        font-size: 1.5rem;
        color: var(--text-primary, #1e293b);
        cursor: pointer;
        padding: 0.5rem;
    }
    
    /* Hero Section Mobile */
    .hero {
        padding: 3rem 0;
        text-align: center;
    }
    
    .hero-title {
        font-size: 2rem;
        line-height: 1.2;
    }
    
    .hero-subtitle {
        font-size: 1rem;
        margin-bottom: 1.5rem;
    }
    
    .hero-cta {
        flex-direction: column;
        align-items: center;
        gap: 1rem;
    }
    
    .hero-secondary-actions {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .hero-stats {
        grid-template-columns: 1fr;
        gap: 1rem;
        margin-top: 2rem;
    }
    
    /* Cards and Grids Mobile */
    .hostels-grid,
    .roommate-grid,
    .quick-access-grid,
    .campus-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .feature-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    /* Form Mobile Styles */
    .form-row {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .filters {
        flex-direction: column;
        gap: 1rem;
    }
    
    .filter-group {
        width: 100%;
    }
    
    /* Button Mobile Styles */
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
        padding: 1rem;
        font-size: 1rem;
    }
    
    /* Modal Mobile Optimization */
    .modal {
        padding: 0;
        align-items: flex-end;
    }
    
    .modal-content {
        width: 100%;
        max-height: 95vh;
        border-radius: 16px 16px 0 0;
        margin: 0;
    }
    
    .modal-header {
        padding: 1rem;
        position: sticky;
        top: 0;
        background: var(--bg-secondary, #f8fafc);
        z-index: 10;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    /* Landing Page Mobile */
    .landing-container {
        padding: 1rem;
    }
    
    .landing-cta {
        flex-direction: column;
        align-items: stretch;
    }
    
    .cta-button {
        width: 100%;
        justify-content: center;
        margin-bottom: 0.75rem;
    }
    
    /* Dashboard Mobile */
    .dashboard-stats {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .dashboard-actions {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .listings-grid {
        grid-template-columns: 1fr;
    }
    
    /* Footer Mobile */
    .footer-content {
        grid-template-columns: 1fr;
        text-align: center;
        gap: 2rem;
    }
    
    .social-links {
        justify-content: center;
    }
}

/* Tablet Styles */
@media (min-width: 769px) and (max-width: 1024px) {
    .hostels-grid,
    .roommate-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .campus-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .feature-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .dashboard-stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Large Screen Optimization */
@media (min-width: 1400px) {
    .container {
        max-width: 1200px;
    }
    
    .hostels-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .campus-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Print Styles */
@media print {
    .navbar,
    .footer,
    .floating-action-btn,
    .theme-toggle,
    .modal {
        display: none !important;
    }
    
    .hero {
        padding: 1rem 0;
    }
    
    .hero-title {
        color: #000 !important;
    }
    
    a {
        color: #000 !important;
        text-decoration: underline;
    }
}

/* Touch Device Optimization */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .card:hover,
    .btn:hover,
    .nav-link:hover {
        transform: none;
    }
    
    /* Increase touch targets */
    .btn,
    .nav-link,
    button {
        min-height: 48px;
        min-width: 48px;
    }
    
    /* Better tap feedback */
    .btn:active,
    button:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .card,
    .modal-content,
    .btn {
        border: 2px solid var(--text-primary, #000);
    }
    
    .btn-outline {
        background: var(--bg-card, #fff);
    }
}

/* 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;
    }
    
    .sama-logo {
        animation: none;
    }
    
    .scroll-indicator {
        animation: none;
    }
}

/* Focus Visible Support */
.btn:focus-visible,
.nav-link:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid var(--color-primary, #3b82f6);
    outline-offset: 2px;
}

/* Error States */
.form-group.error input,
.form-group.error select,
.form-group.error textarea {
    border-color: var(--color-error, #ef4444);
    background: rgba(239, 68, 68, 0.05);
}

.form-group.error .error-message {
    color: var(--color-error, #ef4444);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: block;
}

/* Success States */
.form-group.success input,
.form-group.success select,
.form-group.success textarea {
    border-color: var(--color-success, #22c55e);
    background: rgba(34, 197, 94, 0.05);
}

/* Loading States */
.btn.loading {
    pointer-events: none;
    opacity: 0.7;
    position: relative;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Accessibility Improvements */
.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 */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--color-primary, #3b82f6);
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
    border-radius: 4px;
}

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

/* Connection Status */
.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--color-error, #ef4444);
    color: white;
    text-align: center;
    padding: 0.5rem;
    z-index: 10001;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.offline-indicator.show {
    transform: translateY(0);
}

/* Performance Optimization */
.card,
.modal-content,
.btn {
    will-change: transform;
}

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

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

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

.lazy-image {
    opacity: 0;
    transition: opacity 0.3s ease;
}

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