/* =====================================================================
   Audible-Style Preview Player Modal
========================================================================*/

/* Modal Base Styles */
#audiobookPreviewModal .modal-dialog {
    max-width: 95vw;
    width: 1200px;
    margin: 1rem auto;
}

.preview-modal-content {
    border-radius: 16px;
    border: none;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
}

.preview-header {
    border-bottom: 1px solid #e9ecef;
    padding: 1rem 1.5rem;
    background: transparent;
}

.preview-header .btn-close {
    font-size: 1.2rem;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.preview-header .btn-close:hover {
    opacity: 1;
}

.preview-body {
    padding: 0;
}

/* Main Container Layout */
.preview-container {
    display: flex;
    min-height: 70vh;
    background: #ffffff;
}

/* Left Side - Book Info & Player */
.preview-left {
    flex: 1;
    padding: 2rem;
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    border-right: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.book-info-section {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.book-cover-large {
    flex-shrink: 0;
}

.cover-image {
    width: 160px;
    height: 240px;
    object-fit: cover;
    border-radius: 12px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
    transition: transform 0.2s ease;
}

.cover-image:hover {
    transform: translateY(-2px);
}

.book-details-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.book-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--color-text-primary);
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

.book-author,
.book-narrator {
    font-size: 0.95rem;
    color: var(--color-text-secondary);
    margin-bottom: 0.4rem;
    font-weight: 500;
}

.book-metadata {
    display: flex;
    gap: 0.75rem;
    margin: 0.75rem 0;
    flex-wrap: wrap;
}

.metadata-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.85rem;
    background: var(--color-primary-100);
    color: var(--color-primary-700);
    border-radius: 16px;
    font-size: 0.8rem;
    font-weight: 600;
}

.metadata-item i {
    font-size: 0.75rem;
}

.book-description {
    margin-top: 0.75rem;
}

.book-description p {
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--color-text-secondary);
    margin: 0;
}

/* Player Section for Subscribed Users */
.preview-player-section {
    background: #ffffff;
    border-radius: 16px;
    padding: 1.75rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    border: 1px solid #e9ecef;
    margin-top: auto;
}

.current-track-info {
    text-align: center;
    padding: 1rem 0 0 0;
    border-top: 1px solid #e9ecef;
    margin-top: 1.25rem;
}

#current-track-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: 0.25rem;
    line-height: 1.3;
}

#current-track-description {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    line-height: 1.4;
    margin: 0;
}

/* Player Timeline */
.player-timeline {
    margin-bottom: 1.5rem;
}

.timeline-container {
    margin-bottom: 0.75rem;
}

.timeline {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
}

.timeline:hover {
    height: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.timeline-progress {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary-500) 0%, var(--color-primary-600) 100%);
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
    position: relative;
}

.timeline-progress::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    background: #ffffff;
    border: 2px solid var(--color-primary-600);
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.timeline:hover .timeline-progress::after {
    opacity: 1;
}

.time-display {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

/* Player Controls */
.player-controls {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    width: 100%;
}

.progress-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
}

.progress-time {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    min-width: 40px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.progress-bar {
    flex: 1;
    height: 5px;
    background: #e9ecef;
    border-radius: 3px;
    position: relative;
    cursor: pointer;
    transition: height 0.2s ease;
}

.progress-bar:hover {
    height: 6px;
}

.progress {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0%;
    background: var(--color-primary-500);
    border-radius: 3px;
    transition: width 0.1s linear;
}

.progress-handle {
    position: absolute;
    left: 0%;
    top: 50%;
    width: 12px;
    height: 12px;
    background: white;
    border: 2px solid var(--color-primary-500);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.progress-bar:hover .progress-handle {
    opacity: 1;
}

.player-buttons-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    margin: 0;
    padding: 0;
}

.player-buttons {
    display: grid;
    grid-template-columns: auto auto auto;
    gap: 1rem;
    align-items: center;
    justify-content: center;
}

.player-button {
    background: var(--color-primary-500);
    border: none;
    color: white;
    cursor: pointer;
    padding: 0;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    width: 44px;
    height: 44px;
    box-shadow: 0 3px 8px rgba(223, 185, 109, 0.25);
    margin: 0;
}

/* Grid placement for buttons */
#rewind-15 {
    grid-column: 1;
}

#play-pause-btn {
    grid-column: 2;
    visibility: visible !important;
    opacity: 1 !important;
    display: flex !important;
}

#forward-30 {
    grid-column: 3;
}

.player-button:hover:not(:disabled) {
    background: var(--color-primary-600);
    box-shadow: 0 4px 12px rgba(223, 185, 109, 0.35);
}

.player-button:active:not(:disabled) {
    box-shadow: 0 2px 6px rgba(223, 185, 109, 0.3);
}

.player-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #dee2e6;
    box-shadow: none;
}

.player-button i {
    font-size: 1.25rem;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
}

.player-button span {
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.625rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    line-height: 1;
}

/* Play button - larger and more prominent */
.play-button {
    width: 52px;
    height: 52px;
    background: var(--color-primary-500) !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.play-button i {
    font-size: 1.5rem;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-48%, -50%);
    margin: 0;
}

/* Ensure icon is visible */
#play-pause-icon {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    color: white !important;
}

.playback-rate {
    text-align: center;
    margin-top: 0.75rem;
}

.playback-rate-button {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 600;
}

.playback-rate-button:hover {
    background: #e9ecef;
    border-color: #dee2e6;
    color: var(--color-text-primary);
}

/* Subscription Prompt for Non-Subscribers */
.subscription-prompt {
    background: #ffffff;
    border-radius: 16px;
    padding: 2.5rem 1.75rem;
    text-align: center;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    border: 1px solid #e9ecef;
    margin-top: auto;
}

.prompt-content {
    max-width: 280px;
    margin: 0 auto;
}

.prompt-icon {
    font-size: 2.5rem;
    color: var(--color-primary-500);
    margin-bottom: 1rem;
    opacity: 0.7;
}

.subscription-prompt h4 {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--color-text-primary);
    margin-bottom: 0.75rem;
}

.subscription-prompt p {
    color: var(--color-text-secondary);
    margin-bottom: 1.75rem;
    line-height: 1.5;
    font-size: 0.9rem;
}

.btn-subscription {
    background: var(--color-secondary-500);
    color: white;
    padding: 0.7rem 1.75rem;
    border-radius: 50px;
    text-decoration: none;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    font-size: 0.95rem;
    box-shadow: 0 3px 10px rgba(111, 55, 0, 0.2);
}

.btn-subscription:hover {
    background: var(--color-secondary-600);
    transform: translateY(-1px);
    box-shadow: 0 5px 18px rgba(111, 55, 0, 0.3);
    color: white;
    text-decoration: none;
}

/* Right Side - Tracks List */
.preview-right {
    flex: 1;
    background: #f8f9fa;
    border-left: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
}

.tracks-header {
    padding: 2rem 2rem 1rem;
    border-bottom: 1px solid #e9ecef;
    background: #ffffff;
}

.tracks-header h3 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--color-text-primary);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.tracks-header h3 i {
    color: var(--color-primary-600);
}

.tracks-subtitle {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    margin: 0;
}

.tracks-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    max-height: 60vh;
}

/* Track Items */
.track-item {
    background: #ffffff;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.track-item:hover:not(.disabled) {
    border-color: var(--color-primary-400);
    box-shadow: 0 4px 16px rgba(223, 185, 109, 0.15);
    transform: translateY(-1px);
}

.track-item.disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.track-item.playing {
    border-color: var(--color-primary-500);
    background: var(--color-primary-50);
    box-shadow: 0 4px 16px rgba(223, 185, 109, 0.2);
}

.track-number {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    background: var(--color-gray-200);
    color: var(--color-text-secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.track-item.playing .track-number {
    background: var(--color-primary-500);
    color: white;
}

.track-info {
    flex: 1;
    min-width: 0; /* Allows text truncation */
}

.track-name {
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: 0.25rem;
    font-size: 1rem;
    line-height: 1.3;
}

.track-item.playing .track-name {
    color: var(--color-primary-700);
}

.track-description {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.track-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.track-duration {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    font-weight: 500;
    min-width: 40px;
    text-align: right;
}

.track-play-btn {
    width: 36px;
    height: 36px;
    background: var(--color-primary-500);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.track-play-btn:hover {
    background: var(--color-primary-600);
    transform: scale(1.05);
}

.track-locked {
    color: var(--color-text-muted);
    font-size: 1.2rem;
}

.no-tracks {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--color-text-muted);
    font-style: italic;
}

/* Responsive Design */
@media (max-width: 1024px) {
    #audiobookPreviewModal .modal-dialog {
        max-width: 95vw;
        width: 95vw;
        margin: 1rem;
    }
    
    .preview-container {
        flex-direction: column;
        min-height: auto;
    }
    
    .preview-left {
        border-right: none;
        border-bottom: 1px solid #e9ecef;
    }
    
    .book-info-section {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 1.5rem;
    }
    
    .cover-image {
        width: 140px;
        height: 210px;
    }
    
    .book-title {
        font-size: 1.6rem;
    }
    
    .tracks-list {
        max-height: 40vh;
    }
}

@media (max-width: 768px) {
    /* Modal takes full screen on mobile for better PWA experience */
    #audiobookPreviewModal .modal-dialog {
        max-width: 100vw;
        width: 100vw;
        margin: 0;
        max-height: 100vh;
        height: 100vh;
    }
    
    #audiobookPreviewModal .modal-content {
        border-radius: 0;
        height: 100vh;
    }
    
    .preview-left {
        padding: 1.25rem;
    }
    
    .preview-player-section {
        padding: 1.25rem;
    }
    
    .book-info-section {
        gap: 1rem;
    }
    
    .cover-image {
        width: 120px;
        height: 180px;
    }
    
    .book-title {
        font-size: 1.35rem;
    }
    
    .book-author,
    .book-narrator {
        font-size: 0.85rem;
    }
    
    .book-metadata {
        justify-content: center;
        gap: 0.75rem;
    }
    
    .metadata-item {
        padding: 0.3rem 0.7rem;
        font-size: 0.75rem;
    }
    
    .book-description p {
        font-size: 0.85rem;
    }
    
    .player-controls {
        gap: 1rem;
    }
    
    .player-buttons {
        gap: 0.75rem;
    }
    
    .play-button {
        width: 48px;
        height: 48px;
    }
    
    .play-button i {
        font-size: 1.35rem;
    }
    
    .player-button {
        width: 40px;
        height: 40px;
    }
    
    .player-button i {
        font-size: 1.15rem;
    }
    
    .player-button span {
        font-size: 0.6rem;
        bottom: 1px;
    }
    
    .progress-time {
        min-width: 36px;
        font-size: 0.75rem;
    }
    
    .progress-bar {
        height: 4px;
    }
    
    .progress-bar:hover {
        height: 5px;
    }
    
    .playback-rate-button {
        font-size: 0.75rem;
        padding: 5px 12px;
    }
    
    .tracks-header {
        padding: 1.5rem 1rem 0.75rem;
    }
    
    .tracks-list {
        padding: 0.75rem;
    }
    
    .track-item {
        padding: 0.75rem;
    }
    
    .track-actions {
        gap: 0.5rem;
    }
    
    .track-play-btn {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }
}

/* Scrollbar Styling for Tracks List */
.tracks-list::-webkit-scrollbar {
    width: 6px;
}

.tracks-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.tracks-list::-webkit-scrollbar-thumb {
    background: var(--color-gray-400);
    border-radius: 3px;
}

.tracks-list::-webkit-scrollbar-thumb:hover {
    background: var(--color-gray-500);
}

/* Loading States */
.preview-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

.preview-loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e9ecef;
    border-top: 4px solid var(--color-primary-500);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Animation for Modal Entrance */
.modal.fade .modal-dialog {
    transform: scale(0.95);
    transition: transform 0.3s ease-out;
}

.modal.show .modal-dialog {
    transform: scale(1);
}

/* Focus States for Accessibility */
.player-button:focus,
.track-play-btn:focus,
.btn-subscription:focus,
.playback-rate-button:focus {
    outline: 2px solid var(--color-primary-500);
    outline-offset: 2px;
}

.progress-bar:focus {
    outline: 2px solid var(--color-primary-500);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .track-item {
        border-width: 2px;
    }
    
    .timeline {
        border: 1px solid var(--color-text-secondary);
    }
    
    .metadata-item {
        border: 1px solid var(--color-primary-600);
    }
}

/* Preview Button Styling */
.preview-btn {
    background: linear-gradient(135deg, var(--color-primary-500) 0%, var(--color-primary-600) 100%);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    text-decoration: none;
    margin: 0.25rem 0.5rem 0.25rem 0;
    box-shadow: 0 4px 15px rgba(223, 185, 109, 0.3);
}

.preview-btn:hover {
    background: linear-gradient(135deg, var(--color-primary-600) 0%, var(--color-primary-700) 100%);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(223, 185, 109, 0.4);
    color: white;
}

.preview-btn:focus {
    outline: 2px solid var(--color-primary-300);
    outline-offset: 2px;
}

.preview-btn i {
    font-size: 1.1rem;
}
