/**
 * Responsive and Accessibility Enhancements
 * E-Flux CPO Platform
 */

/* ============================================
   ACCESSIBILITY IMPROVEMENTS
   ============================================ */

/* Focus visible styles for keyboard navigation */
*:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Skip to main content link for screen readers */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #1e40af;
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-link:focus {
    top: 0;
}

/* Improve contrast for better readability */
.text-slate-gray {
    color: #475569 !important;
}

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

/* ============================================
   RESPONSIVE LAYOUT - TABLET
   ============================================ */

@media (max-width: 1024px) {
    /* Sidebar adjustments */
    #sidebar {
        width: 80px;
    }

    #sidebar .sidebar-link span {
        display: none;
    }

    #sidebar .sidebar-link i {
        margin: 0 auto;
    }

    #sidebar .p-6 {
        padding: 1rem;
    }

    /* Adjust main content margin */
    #main-content {
        margin-left: 80px;
    }

    /* Card grid adjustments */
    .grid-cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .grid-cols-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    /* Table improvements */
    table {
        font-size: 13px;
    }

    th, td {
        padding: 12px 8px !important;
    }
}

/* ============================================
   RESPONSIVE LAYOUT - MOBILE
   ============================================ */

@media (max-width: 768px) {
    /* Hide sidebar by default */
    #sidebar {
        transform: translateX(-100%);
        transition: transform 300ms ease;
        width: 240px;
    }

    #sidebar.mobile-open {
        transform: translateX(0);
    }

    /* Remove main content margin */
    #main-content {
        margin-left: 0;
    }

    /* Add mobile header */
    #main-content::before {
        content: '';
        display: block;
        height: 60px;
    }

    /* Mobile header bar */
    .mobile-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: #0f1a34;
        color: white;
        display: flex;
        align-items: center;
        padding: 0 1rem;
        z-index: 40;
    }

    .mobile-menu-btn {
        background: none;
        border: none;
        color: white;
        font-size: 24px;
        cursor: pointer;
        padding: 8px;
    }

    /* Single column layouts */
    .grid-cols-4,
    .grid-cols-3,
    .grid-cols-2 {
        grid-template-columns: repeat(1, minmax(0, 1fr));
    }

    /* Stack filter inputs */
    .grid.gap-4 > div {
        width: 100%;
    }

    /* Full width modals */
    .modal-content {
        max-width: 95%;
        max-height: 95%;
        margin: 10px;
    }

    /* Table scroll */
    .overflow-x-auto {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Hide less important table columns on mobile */
    table td:nth-child(5),
    table th:nth-child(5),
    table td:nth-child(6),
    table th:nth-child(6) {
        display: none;
    }

    /* Adjust padding */
    .p-8 {
        padding: 1rem !important;
    }

    .p-6 {
        padding: 1rem !important;
    }

    /* Text sizes */
    h1 {
        font-size: 24px !important;
    }

    h2 {
        font-size: 18px !important;
    }

    /* Chart height */
    #revenue-chart {
        height: 200px !important;
    }

    /* Card spacing */
    .card {
        margin-bottom: 1rem;
    }

    /* Button text */
    .btn-primary,
    .btn-secondary {
        font-size: 14px;
        padding: 10px 16px;
    }

    /* Hide button text, show icons only on very small screens */
    @media (max-width: 480px) {
        .btn-primary span:not(.fas),
        .btn-secondary span:not(.fas) {
            display: none;
        }
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    #sidebar,
    .btn-primary,
    .btn-secondary,
    .modal,
    #loading-overlay {
        display: none !important;
    }

    #main-content {
        margin-left: 0;
    }

    .card {
        page-break-inside: avoid;
        border: 1px solid #000;
    }

    body {
        background: white;
    }

    * {
        color: black !important;
    }
}

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

/* Use GPU acceleration for animations */
.modal,
.sidebar-link,
.card,
.btn-primary,
.btn-secondary {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Reduce motion for users with vestibular disorders */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .modal {
        animation: none;
    }
}

/* ============================================
   HIGH CONTRAST MODE
   ============================================ */

@media (prefers-contrast: high) {
    .card {
        border: 2px solid #000;
    }

    .btn-primary {
        border: 2px solid #000;
    }

    .status-badge {
        border: 1px solid currentColor;
    }
}

/* ============================================
   DARK MODE (Optional)
   ============================================ */

@media (prefers-color-scheme: dark) {
    /* Can be implemented later if needed */
    /* For now, force light mode for consistency */
    body {
        color-scheme: light;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* Loading state */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid #e2e8f0;
    border-top-color: #1e40af;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

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

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

/* ============================================
   TOAST ANIMATIONS
   ============================================ */

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.animate-slide-in {
    animation: slideInRight 300ms ease-out;
}

/* ============================================
   TOOLTIP STYLES (for future use)
   ============================================ */

[data-tooltip] {
    position: relative;
    cursor: help;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: #1f2937;
    color: white;
    font-size: 12px;
    white-space: nowrap;
    border-radius: 4px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms;
    margin-bottom: 4px;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus::after {
    opacity: 1;
}

/* ============================================
   IMPROVED FORM ACCESSIBILITY
   ============================================ */

input:invalid:not(:focus),
select:invalid:not(:focus),
textarea:invalid:not(:focus) {
    border-color: #ef4444;
}

input:valid:not(:focus),
select:valid:not(:focus),
textarea:valid:not(:focus) {
    border-color: #22c55e;
}

/* Larger touch targets for mobile */
@media (max-width: 768px) {
    button,
    a,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ============================================
   TABLE ENHANCEMENTS
   ============================================ */

/* Sticky table header */
thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #f9fafb;
}

/* Zebra striping for better readability */
tbody tr:nth-child(even) {
    background-color: #f9fafb;
}

/* Row hover improvement */
tbody tr:hover {
    background-color: #f3f4f6 !important;
    cursor: pointer;
}

/* ============================================
   LOADING STATES
   ============================================ */

.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

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

/* ============================================
   TRANSITIONS
   ============================================ */

.transition-all {
    transition-property: all;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 200ms;
}

.transition-colors {
    transition-property: background-color, border-color, color, fill, stroke;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 200ms;
}
