/* Modern Responsive Design - Tailwind 3+ Compatible with Container Queries */

/* Container Queries for component-based responsive design */
@container (max-width: 400px) {
    .card {
        padding: 1rem;
        border-radius: 0.75rem;
    }
    
    .card-title {
        font-size: 1.125rem;
    }
}

@container (min-width: 600px) {
    .metric-card {
        display: grid;
        grid-template-columns: auto 1fr;
        align-items: center;
        gap: 1rem;
    }
}

/* Modern responsive utilities using clamp() for fluid design */
:root {
    --fluid-text-sm: clamp(0.875rem, 0.8rem + 0.375vw, 1rem);
    --fluid-text-base: clamp(1rem, 0.9rem + 0.5vw, 1.125rem);
    --fluid-text-lg: clamp(1.125rem, 1rem + 0.625vw, 1.25rem);
    --fluid-text-xl: clamp(1.25rem, 1.1rem + 0.75vw, 1.5rem);
    --fluid-text-2xl: clamp(1.5rem, 1.3rem + 1vw, 1.875rem);
    --fluid-text-3xl: clamp(1.875rem, 1.6rem + 1.375vw, 2.25rem);
    --fluid-text-4xl: clamp(2.25rem, 1.9rem + 1.75vw, 3rem);
    
    --fluid-space-xs: clamp(0.25rem, 0.2rem + 0.25vw, 0.5rem);
    --fluid-space-sm: clamp(0.5rem, 0.4rem + 0.5vw, 0.75rem);
    --fluid-space-md: clamp(1rem, 0.8rem + 1vw, 1.5rem);
    --fluid-space-lg: clamp(1.5rem, 1.2rem + 1.5vw, 2rem);
    --fluid-space-xl: clamp(2rem, 1.6rem + 2vw, 3rem);
    --fluid-space-2xl: clamp(3rem, 2.4rem + 3vw, 4rem);
}

/* Reduced motion preferences */
@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 {
        --shadow: 0 2px 4px 0 rgb(0 0 0 / 0.2);
        --shadow-md: 0 4px 8px -2px rgb(0 0 0 / 0.2);
        --shadow-lg: 0 8px 16px -4px rgb(0 0 0 / 0.2);
    }
    
    .card,
    .btn,
    .form-control {
        border-width: 2px;
    }
    
    .nav-link:focus,
    .btn:focus,
    .form-control:focus {
        outline: 3px solid currentColor;
        outline-offset: 2px;
    }
}

/* Extra large screens (2xl: 1536px+) - Following Tailwind breakpoints */
@media (min-width: 1536px) {
    .container {
        max-width: 1600px;
    }
    
    /* Ensure sidebar stays properly positioned on very wide screens */
    .sidebar {
        left: 0;
        transform: none;
    }
    
    .main-content::before {
        left: var(--sidebar-width);
    }
}

/* Tablet and below (lg: max-width: 1024px) - Tailwind lg breakpoint */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 80px;
    }
    
    .sidebar {
        width: var(--sidebar-width);
        /* Ensure sidebar stays fixed on left */
        left: 0;
        transform: none;
    }
    
    .nav-link span,
    .user-details,
    .logo {
        display: none;
    }
    
    .sidebar-header {
        justify-content: center;
    }
    
    .nav-link {
        justify-content: center;
        padding: var(--spacing-md);
    }
    
    .nav-icon {
        margin-right: 0;
    }
    
    .user-info {
        justify-content: center;
    }
    
    .user-avatar {
        margin-right: 0;
    }
    
    .main-content {
        margin-left: var(--sidebar-width);
    }
    
    .main-content::before {
        left: var(--sidebar-width);
    }
    
    /* Grid utilities removed - using Tailwind responsive grid classes instead */
}

/* Mobile and tablet (md: max-width: 768px) - Tailwind md breakpoint */
@media (max-width: 768px) {
    :root {
        --spacing-2xl: 2rem;
        --spacing-xl: 1.5rem;
        --sidebar-width: 280px;
    }
    
    body {
        background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    }
    
    /* Sidebar mobile - ALWAYS on left, never on top */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        width: var(--sidebar-width);
        height: 100vh;
        /* Ensure proper z-index stacking */
        z-index: var(--z-sidebar);
        /* Smooth transitions */
        transition: transform var(--transition-base);
        /* Force sidebar to always be on left side */
        right: auto;
        flex-direction: column;
    }
    
    .sidebar.open,
    .sidebar.show {
        transform: translateX(0);
        /* Ensure it slides in from the left */
        left: 0;
    }
    
    .sidebar-toggle {
        display: block;
    }
    
    .nav-link span,
    .user-details,
    .logo {
        display: block;
    }
    
    .nav-link {
        justify-content: flex-start;
        padding: var(--spacing-md) var(--spacing-lg);
    }
    
    .nav-icon {
        margin-right: var(--spacing-md);
    }
    
    .main-content {
        margin-left: 0;
        padding: var(--spacing-lg);
    }
    
    .main-content::before {
        left: 0;
    }
    
    /* Mobile overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: var(--z-sidebar-overlay); /* Just below sidebar but above other content */
        backdrop-filter: blur(4px);
        transition: opacity var(--transition-base);
        opacity: 0;
    }
    
    .sidebar-overlay.show {
        display: block;
        opacity: 1;
    }
    
    /* Grid adjustments - using Tailwind responsive classes instead */
    
    /* Cards */
    .card {
        padding: var(--spacing-lg);
        border-radius: var(--radius-lg);
        margin-bottom: var(--spacing-lg);
    }
    
    .card-header {
        margin-bottom: var(--spacing-lg);
        padding-bottom: var(--spacing-md);
    }
    
    .card-title {
        font-size: var(--font-size-lg);
    }
    
    /* Tables */
    .table-container {
        border-radius: 0;
        margin-left: calc(var(--spacing-lg) * -1);
        margin-right: calc(var(--spacing-lg) * -1);
        width: calc(100% + var(--spacing-lg) * 2);
    }
    
    .table {
        font-size: var(--font-size-sm);
    }
    
    .table th,
    .table td {
        padding: var(--spacing-sm);
    }
    
    /* Modal */
    .modal {
        width: 95%;
        margin: var(--spacing-md);
        max-height: calc(100vh - var(--spacing-xl));
    }
    
    .modal-body {
        max-height: calc(100vh - 200px);
    }
    
    /* Forms */
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
        padding: var(--spacing-lg);
        border-radius: var(--radius-lg);
    }
    
    .form-control {
        padding: var(--spacing-lg);
        min-height: 48px;
        border-radius: var(--radius-lg);
    }
    
    .search-input {
        padding: var(--spacing-lg) var(--spacing-lg) var(--spacing-lg) 3.5rem;
        border-radius: var(--radius-2xl);
    }
    
    .btn-group {
        display: flex;
        flex-direction: column;
        gap: var(--spacing-md);
    }
    
    .btn-group .btn {
        margin: 0;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
        min-height: 48px;
        padding: var(--spacing-lg) var(--spacing-xl);
    }
    
    /* Profile */
    .profile-header {
        flex-direction: column;
        text-align: center;
        padding: var(--spacing-lg);
    }
    
    .profile-avatar {
        width: 100px;
        height: 100px;
    }
    
    .profile-meta {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .profile-actions {
        margin-left: 0;
        width: 100%;
        justify-content: center;
    }
    
    /* Charts */
    .chart-container {
        height: 300px;
    }
    
    .chart-legend {
        gap: var(--spacing-md);
    }
    
    /* Metrics */
    .metric-card {
        padding: var(--spacing-lg);
        border-radius: var(--radius-xl);
    }
    
    .metric-value {
        font-size: var(--font-size-3xl);
    }
    
    .metric-label {
        font-size: var(--font-size-sm);
    }
    
    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-lg);
        text-align: left;
    }
    
    .dashboard-header h1 {
        font-size: var(--font-size-3xl);
    }
    
    .dashboard-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    /* Toast */
    .toast-container {
        top: var(--spacing-md);
        left: var(--spacing-md);
        right: var(--spacing-md);
    }
    
    .toast {
        min-width: auto;
        width: 100%;
    }
}

/* Small mobile (sm: max-width: 480px) - Custom breakpoint for very small screens */
@media (max-width: 480px) {
    :root {
        --spacing-2xl: 1.5rem;
        --spacing-xl: 1rem;
        --font-size-4xl: 1.875rem;
        --font-size-3xl: 1.5rem;
        --font-size-2xl: 1.25rem;
    }
    
    .main-content {
        padding: var(--spacing-md);
    }
    
    h1 { font-size: var(--font-size-3xl); }
    h2 { font-size: var(--font-size-2xl); }
    h3 { font-size: var(--font-size-xl); }
    
    /* Hide some columns on very small screens */
    .table th:nth-child(n+4),
    .table td:nth-child(n+4) {
        display: none;
    }
    
    /* Stack form elements */
    .form-row {
        grid-template-columns: 1fr !important;
        gap: var(--spacing-md);
    }
    
    .form-group {
        margin-bottom: var(--spacing-md);
    }
    
    /* Upload items */
    .upload-item {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-sm);
    }
    
    .upload-status {
        width: 100%;
        justify-content: space-between;
    }
    
    .progress-wrapper {
        min-width: auto;
        flex: 1;
    }
}

/* Touch device optimizations - Modern mobile interactions */
@media (hover: none) and (pointer: coarse) {
    /* Ensure proper touch targets (44px minimum) */
    .btn,
    .nav-link,
    .form-control,
    .form-check-input {
        min-height: 44px;
    }
    
    .nav-link {
        padding: 1rem 1.5rem; /* Using rem instead of CSS variables for better compatibility */
    }
    
    /* Remove hover effects on touch devices */
    .card:hover,
    .table tbody tr:hover {
        box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
        background-color: inherit;
        transform: none;
    }
    
    /* Improve tap feedback with subtle animations */
    .btn,
    .nav-link,
    .search-result-item,
    .filter-chip {
        -webkit-tap-highlight-color: rgba(59, 130, 246, 0.1); /* Primary color highlight */
        transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .btn:active,
    .nav-link:active {
        transform: scale(0.98);
    }
    
    /* Prevent zoom on input focus */
    .form-control,
    .search-input,
    input,
    select,
    textarea {
        font-size: 16px; /* Prevents iOS zoom */
    }
}

/* High DPI displays - Retina and high resolution screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi), (min-resolution: 2dppx) {
    /* Use sharper shadows with modern color syntax */
    :root {
        --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.08), 0 1px 2px 0 rgb(0 0 0 / 0.04);
        --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -1px rgb(0 0 0 / 0.04);
        --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -2px rgb(0 0 0 / 0.03);
    }
    
    /* Enhance text rendering on high DPI */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Landscape mobile - Optimized for landscape phones */
@media (max-width: 768px) and (orientation: landscape) {
    :root {
        --sidebar-width: 200px;
    }
    
    .sidebar {
        width: var(--sidebar-width);
    }
    
    /* Optimize modals for landscape */
    .modal {
        max-height: calc(100vh - 1rem);
        margin: 0.5rem;
    }
    
    .modal-body {
        max-height: calc(100vh - 120px);
        overflow-y: auto;
    }
    
    /* Reduce top/bottom spacing in landscape */
    .main-content {
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }
}

/* Modern Print Styles - Optimized for documentation */
@media print {
    /* Hide interactive elements */
    .sidebar,
    .sidebar-toggle,
    .btn,
    .toast-container,
    .modal-backdrop,
    .nav-link,
    [role="button"],
    button {
        display: none !important;
    }
    
    /* Reset layout for print */
    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }
    
    .main-content::before {
        display: none !important;
    }
    
    /* Optimize cards for print */
    .card {
        box-shadow: none !important;
        border: 1px solid #e2e8f0 !important;
        break-inside: avoid;
        margin-bottom: 1rem !important;
    }
    
    /* Print-optimized typography */
    body {
        font-size: 12pt !important;
        line-height: 1.5 !important;
        color: #000 !important;
        background: white !important;
    }
    
    /* Ensure proper page breaks */
    h1, h2, h3, h4, h5, h6 {
        break-after: avoid;
        page-break-after: avoid;
    }
    
    /* Print URLs for links */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 10pt;
        color: #666;
    }
    
    /* Hide decorative elements */
    .chart-container,
    .loading-spinner,
    .pulse-dot {
        display: none !important;
    }
}