/**
 * Media Utilities CSS
 * Styles for loading states, error handling, and accessibility features
 */

/* ==========================================================================
   Loading States - Skeleton Loaders
   ========================================================================== */

.skeleton-loader {
    position: relative;
    overflow: hidden;
    background: linear-gradient(
        90deg,
        #f0f0f0 0%,
        #e0e0e0 20%,
        #f0f0f0 40%,
        #f0f0f0 100%
    );
    background-size: 200% 100%;
    border-radius: 8px;
}

.skeleton-shimmer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.3) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* Skeleton type-specific styling */
.skeleton-image {
    min-height: 200px;
}

.skeleton-video {
    min-height: 300px;
}

.skeleton-chart,
.skeleton-plot {
    min-height: 400px;
}

.skeleton-table {
    min-height: 250px;
}

.skeleton-pdf {
    min-height: 500px;
}

/* ==========================================================================
   Loading States - Spinner
   ========================================================================== */

.spinner-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    gap: 16px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-top-color: #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.spinner-message {
    color: #666;
    font-size: 14px;
    font-weight: 500;
}

/* ==========================================================================
   Loading States - Progress Bar
   ========================================================================== */

.progress-loader {
    width: 100%;
    padding: 20px;
}

.progress-bar {
    height: 8px;
    background: linear-gradient(90deg, #3498db, #2ecc71);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-text {
    text-align: center;
    margin-top: 8px;
    color: #666;
    font-size: 14px;
    font-weight: 500;
}

/* ==========================================================================
   Error Handling - Error UI
   ========================================================================== */

.media-error {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 24px;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 8px;
    margin: 8px 0;
}

.media-error-icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffc107;
    border-radius: 50%;
    color: #fff;
    font-size: 24px;
}

.media-error-content {
    flex: 1;
}

.media-error-title {
    font-weight: 600;
    font-size: 16px;
    color: #856404;
    margin-bottom: 4px;
}

.media-error-message {
    color: #856404;
    font-size: 14px;
    margin-bottom: 8px;
}

.media-error-details {
    color: #856404;
    font-size: 12px;
    opacity: 0.8;
    margin-bottom: 12px;
}

.media-error-retry {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #ffc107;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.media-error-retry:hover {
    background: #e0a800;
}

.media-error-retry:active {
    transform: scale(0.98);
}

/* Library unavailable variant */
.media-error.library-unavailable {
    background: #d1ecf1;
    border-color: #17a2b8;
}

.media-error.library-unavailable .media-error-icon {
    background: #17a2b8;
}

.media-error.library-unavailable .media-error-title,
.media-error.library-unavailable .media-error-message,
.media-error.library-unavailable .media-error-details {
    color: #0c5460;
}

/* ==========================================================================
   Accessibility - Screen Reader Only
   ========================================================================== */

.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;
}

/* ==========================================================================
   Accessibility - Focus Indicators
   ========================================================================== */

/* Enhanced focus indicators for keyboard navigation */
*:focus {
    outline: none;
}

*:focus-visible {
    outline: 2px solid #3498db;
    outline-offset: 2px;
    border-radius: 4px;
}

button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible {
    outline: 3px solid #3498db;
    outline-offset: 2px;
}

/* ==========================================================================
   Mobile - Touch Targets
   ========================================================================== */

.touch-target {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
}

/* ==========================================================================
   Lazy Loading
   ========================================================================== */

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

img.lazy-loading,
iframe.lazy-loading {
    background: #f0f0f0;
    min-height: 200px;
}

/* Loaded state */
img:not(.lazy-loading),
iframe:not(.lazy-loading) {
    opacity: 1;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media (max-width: 768px) {
    .media-error {
        padding: 16px;
        gap: 12px;
    }

    .media-error-icon {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    .media-error-title {
        font-size: 14px;
    }

    .media-error-message {
        font-size: 13px;
    }

    .media-error-details {
        font-size: 11px;
    }

    .media-error-retry {
        padding: 6px 12px;
        font-size: 13px;
    }

    .spinner {
        width: 36px;
        height: 36px;
        border-width: 3px;
    }

    .spinner-loader {
        padding: 30px 15px;
        gap: 12px;
    }

    .skeleton-image {
        min-height: 150px;
    }

    .skeleton-video {
        min-height: 200px;
    }

    .skeleton-chart,
    .skeleton-plot {
        min-height: 300px;
    }

    .skeleton-pdf {
        min-height: 400px;
    }
}

@media (max-width: 480px) {
    .media-error {
        flex-direction: column;
        text-align: center;
    }

    .media-error-icon {
        margin: 0 auto;
    }

    .skeleton-image {
        min-height: 120px;
    }

    .skeleton-video {
        min-height: 150px;
    }

    .skeleton-chart,
    .skeleton-plot {
        min-height: 250px;
    }

    .skeleton-pdf {
        min-height: 300px;
    }
}

/* ==========================================================================
   Dark Mode Support (Optional)
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .skeleton-loader {
        background: linear-gradient(
            90deg,
            #2a2a2a 0%,
            #3a3a3a 20%,
            #2a2a2a 40%,
            #2a2a2a 100%
        );
    }

    .spinner {
        border-color: rgba(255, 255, 255, 0.1);
        border-top-color: #5dade2;
    }

    .spinner-message {
        color: #ccc;
    }

    .progress-text {
        color: #ccc;
    }

    .media-error {
        background: #3d3d3d;
        border-color: #666;
    }

    .media-error-title,
    .media-error-message,
    .media-error-details {
        color: #f0f0f0;
    }

    img.lazy-loading,
    iframe.lazy-loading {
        background: #2a2a2a;
    }
}

/* ==========================================================================
   Animations
   ========================================================================== */

/* Fade in animation for loaded media */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.media-loaded {
    animation: fadeIn 0.3s ease-in;
}

/* Pulse animation for loading states */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

.loading-pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ==========================================================================
   High Contrast Mode Support
   ========================================================================== */

@media (prefers-contrast: high) {
    .skeleton-loader {
        background: #fff;
        border: 2px solid #000;
    }

    .media-error {
        border-width: 2px;
    }

    *:focus-visible {
        outline-width: 3px;
    }
}

/* ==========================================================================
   Reduced Motion Support
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .skeleton-shimmer {
        animation: none;
    }

    .spinner {
        animation: spin 2s linear infinite;
    }

    .lazy-loading {
        transition: none;
    }

    .media-loaded {
        animation: none;
    }

    .loading-pulse {
        animation: none;
    }
}
