/**
 * WordPress Audio Blog - Waveform Player Styles
 * CSS styling for the waveform audio player
 */

/* Main waveform player wrapper */
.wpab-waveform-player-wrap {
    background: transparent;
    padding: 0;
    margin: 20px 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    /* Performance optimizations */
    contain: layout style paint;
    /* Optimize repaints */
    backface-visibility: hidden;
    /* Prepare for potential animations */
    transform: translateZ(0);
}

/* Header section with title and share button */
.wpab-waveform-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

/* Waveform container (the actual waveform area) */
.wpab-waveform-container {
    overflow: hidden;
    min-height: 20px;
    flex: 1;
    padding: 0 0 0 20px;
    border-left: 1px solid #000;
}

/* Lazy loading optimization - initially hidden until visible */
.wpab-waveform-container.lazy-loading {
    min-height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wpab-waveform-container.lazy-loading::before {
    content: "Loading waveform...";
    color: #6c757d;
    font-size: 14px;
}

/* Waveform visualization container */
.wpab-waveform-wrapper {
    position: relative;
    margin-bottom: 15px;
    border-radius: 4px;
    overflow: hidden;
    min-height: 40px;
}

/* WaveSurfer.js specific styling with performance optimizations */
.wpab-waveform-wrapper wave {
    width: 100% !important;
    /* GPU acceleration for better performance */
    transform: translateZ(0);
    will-change: transform;
}

.wpab-waveform-wrapper canvas {
    display: block;
    width: 100%;
    /* GPU acceleration for canvas rendering */
    transform: translateZ(0);
    will-change: transform;
    /* Optimize canvas rendering */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: optimize-contrast;
    image-rendering: crisp-edges;
}

/* Performance optimizations for low-end devices */
@media (max-device-width: 768px) and (max-device-height: 1024px) {
    .wpab-waveform-wrapper canvas {
        /* Reduce canvas quality on mobile for better performance */
        image-rendering: auto;
    }
}

/* Optimize for devices with limited memory */
@media (max-width: 480px) {
    .wpab-waveform-wrapper wave {
        /* Disable will-change on very small screens to save memory */
        will-change: auto;
    }
    
    .wpab-waveform-wrapper canvas {
        will-change: auto;
    }
}

/* Waveform interactive styling */
.wpab-waveform {
    cursor: pointer;
    outline: none;
    position: relative;
}

/* Controls container */
.wpab-waveform-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Play/Pause button */
.wpab-play-button,
.wpab-play-button:hover {
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    gap: 8px;
    margin: 0 25px 0 0;
    padding: 0;
    font-size: 16px;
    color: #000;
    background: transparent;
    border: none;
    cursor: pointer;
    box-shadow: none;
    transition: all 0.2s ease;
}

/* Play/Pause button icons */
.wpab-play-button :is(.wpab-play-icon, .wpab-pause-icon) {
    width: 38px;
    height: 38px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    background: #000;
    border-radius: 50%;
}

/* Share button */
.wpab-share-button,
.wpab-share-button:hover {
    position: relative;
    display: flex;
    flex-flow: row nowrap;
    justify-content: center;
    align-items: center;
    gap: 5px;
    margin: 0 0 0 50px;
    padding: 0;
    color: #000;
    font-size: 16px;
    font-weight: 500;
    background: transparent;
    border: none;
    cursor: pointer;
    box-shadow: none;
    overflow: visible;
    transition: all 0.2s ease;
}

/* Loading state */
.wpab-waveform-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 20px;
    color: #6c757d;
    font-size: 14px;
}

/* Error state */
.wpab-waveform-error {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 20px;
    color: #dc3545;
    font-size: 14px;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
}

/* Share tooltip */
.wpab-share-tooltip {
    position: absolute;
    background: #333;
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    top: -35px;
    left: 50%;
    transform: translateX(-50%);
}

.wpab-share-tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #333 transparent transparent transparent;
}

.wpab-share-tooltip.show {
    opacity: 1;
}

/* Progress indicator styling */
.wpab-waveform-progress {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: rgba(0, 124, 186, 0.3);
    pointer-events: none;
    transition: width 0.1s ease;
}

/* Hover preview styling */
.wpab-waveform-hover-preview {
    position: absolute;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.2s ease;
    transform: translateX(-50%);
    white-space: nowrap;
}

.wpab-waveform-hover-preview.show {
    opacity: 1;
}

.wpab-waveform-hover-preview::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -4px;
    border-width: 4px;
    border-style: solid;
    border-color: rgba(0, 0, 0, 0.8) transparent transparent transparent;
}

/* Responsive design */
@media (max-width: 768px) {
    .wpab-waveform-container {
        padding: 15px;
        margin: 15px 0;
    }
    
    .wpab-waveform-controls {
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .wpab-play-button {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    .wpab-share-button {
        padding: 6px 12px;
        font-size: 13px;
    }
    
    .wpab-waveform-wrapper {
        min-height: 60px;
    }
}

@media (max-width: 480px) {
    .wpab-waveform-container {
        padding: 12px;
        margin: 10px 0;
    }
    
    .wpab-waveform-label {
        font-size: 13px;
        margin-bottom: 12px;
    }
    
    .wpab-time-display {
        font-size: 13px;
    }
    
    .wpab-waveform-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .wpab-play-button {
        align-self: center;
        margin-bottom: 10px;
    }
    
    .wpab-share-button {
        width: 100%;
        text-align: center;
    }
    
    .wpab-waveform-wrapper {
        min-height: 50px;
        margin-bottom: 12px;
    }
}

/* Screen reader only text for better accessibility */
.wpab-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;
}

/* Ensure screen reader text is never visible but still accessible */
.wpab-sr-only:focus {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
}

/* Skip link for keyboard users (if needed in future) */
.wpab-skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #000;
    color: #fff;
    padding: 8px;
    text-decoration: none;
    border-radius: 3px;
    z-index: 1000;
    transition: top 0.3s;
}

.wpab-skip-link:focus {
    top: 6px;
}

/* Fallback audio player styling */
.wpab-audio-fallback {
    width: 100%;
    margin-top: 10px;
    border-radius: 4px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
}

/* Error message styling */
.wpab-error-message {
    border-radius: 4px;
    padding: 10px;
    margin: 10px 0;
    font-size: 14px;
    display: none;
    line-height: 1.4;
}

.wpab-error-message.wpab-error-message {
    color: #d63638;
    background: #fbeaea;
    border: 1px solid #d63638;
}

.wpab-error-message.wpab-retry-message {
    color: #b32d2e;
    background: #fef7f1;
    border: 1px solid #dba617;
}

.wpab-error-message.wpab-info-message {
    color: #0073aa;
    background: #f0f6fc;
    border: 1px solid #0073aa;
}

.wpab-error-message[role="alert"] {
    display: block;
}

/* Error message text */
.wpab-error-text {
    margin-bottom: 8px;
}

.wpab-error-text:last-child {
    margin-bottom: 0;
}

/* Retry button styling */
.wpab-retry-button {
    background: #0073aa;
    color: white;
    border: none;
    border-radius: 3px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    margin-left: 10px;
    font-weight: 500;
}

.wpab-retry-button:hover {
    background: #424242;
}

.wpab-retry-button:focus {
    outline: 2px solid #929292;
    outline-offset: 2px;
}

.wpab-retry-button:active {
    background: #000f18;
}

.wpab-retry-button:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Loading state enhancements */
.wpab-waveform-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 20px;
    color: #4b4b4b;
    font-size: 14px;
    background: transparent;
    border: none;
    border-radius: 4px;
    position: relative;
}

.wpab-waveform-loading::after {
    content: "";
    width: 20px;
    height: 20px;
    border: 2px solid #e9ecef;
    border-top: 2px solid #6c757d;
    border-radius: 50%;
    animation: wpab-spin 1s linear infinite;
    margin-left: 10px;
}

@keyframes wpab-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error state enhancements */
.wpab-waveform-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 80px;
    color: #dc3545;
    font-size: 14px;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    text-align: center;
    padding: 15px;
}

.wpab-waveform-error .error-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.wpab-waveform-error .error-icon::before {
    content: "⚠️";
}

/* Responsive error handling */
@media (max-width: 768px) {
    .wpab-error-message {
        padding: 8px;
        font-size: 13px;
    }
    
    .wpab-retry-button {
        padding: 5px 10px;
        font-size: 12px;
        margin-left: 8px;
        margin-top: 5px;
        display: block;
        width: auto;
    }
    
    .wpab-error-text {
        margin-bottom: 5px;
    }
}

@media (max-width: 480px) {
    .wpab-error-message {
        padding: 6px;
        font-size: 12px;
        margin: 8px 0;
    }
    
    .wpab-retry-button {
        width: 100%;
        margin-left: 0;
        margin-top: 8px;
        text-align: center;
    }
    
    .wpab-waveform-loading,
    .wpab-waveform-error {
        height: 60px;
        font-size: 13px;
        padding: 10px;
    }
}

/* High contrast mode for error states */
@media (prefers-contrast: high) {
    .wpab-error-message.wpab-error-message {
        border: 2px solid #d63638;
        background: #fff;
    }
    
    .wpab-error-message.wpab-retry-message {
        border: 2px solid #dba617;
        background: #fff;
    }
    
    .wpab-error-message.wpab-info-message {
        border: 2px solid #0073aa;
        background: #fff;
    }
    
    .wpab-retry-button {
        border: 2px solid #0073aa;
    }
}

/* Reduced motion for loading animation */
@media (prefers-reduced-motion: reduce) {
    .wpab-waveform-loading::after {
        animation: none;
        border: 2px solid #6c757d;
    }
}

/* No-script fallback styling */
noscript div {
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 15px;
    margin-top: 10px;
}

noscript p {
    margin: 0 0 10px 0;
    color: #666;
    font-size: 14px;
}

noscript audio {
    width: 100%;
    margin-top: 10px;
}

/* Fallback player container adjustments */
.wpab-waveform-player-wrap .wpab-audio-fallback-created {
    margin-top: 15px;
    border: 1px solid #007cba;
    border-radius: 4px;
    background: #f8f9fa;
}

/* Hide waveform controls when fallback is active */
.wpab-waveform-player-wrap.fallback-active .wpab-waveform-controls {
    display: none;
}

.wpab-waveform-player-wrap.fallback-active .wpab-waveform-header {
    margin-bottom: 10px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .wpab-play-button,
    .wpab-share-button,
    .wpab-share-tooltip,
    .wpab-waveform-progress,
    .wpab-waveform-hover-preview {
        transition: none;
    }
    
    .wpab-play-button:hover,
    .wpab-share-button:hover {
        transform: none;
    }
}