/* Book Detail Modal V2
 * Improved organization and robustness
 * -----------------------------
 * 1. Base Modal Structure
 * 2. Book Detail Layout
 * 3. Preview System
 * 4. Rating Modal
 * 5. Lightbox System
 * 6. Responsive Design
 * 7. Animations
 */

/* -----------------------------
 * 1. Base Modal Structure 
 * ----------------------------- */
.modal-backdrop {
    z-index: 1040 !important;
}

.modal {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 1050 !important;
    background: rgba(0, 0, 0, 0.85) !important;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal.active,
.modal.show {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.modal-dialog {
    position: relative !important;
    width: 98% !important;
    max-width: 1200px !important;
    margin: 20px auto !important;
    height: calc(100vh - 40px) !important;
}

.modal-content {
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
    background: #1e1e1e !important;
    border-radius: 12px !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    overflow: hidden !important;
    max-width: 900px !important;
}

/* Fix modal width issues */
#bookDetailModal {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    padding: 0 !important;
    margin: 0 !important;
    inset: 0 !important;
    overflow-y: hidden !important;
}

#bookDetailModal .modal-dialog {
    width: 95% !important;
    max-width: 1400px !important;
    min-width: 900px !important;
    margin: 20px auto !important;
    transform: none !important;
}

#bookDetailModal .modal-content {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 700px !important;
    max-height: calc(100vh - 40px) !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important; /* Hide overflow at modal level */
}

#bookDetailModal .book-detail-layout {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    height: auto !important;
    overflow: hidden !important;
    max-height: none !important;
}

/* Reset any potential inline styles */
[style*="width"] {
    width: auto !important;
}

/* Add specific rules for the heart icon in the modal */
.modal-heart-icon {
    display: inline-block !important;
    font-style: normal !important;
    font-variant: normal !important;
    text-rendering: auto !important;
    line-height: 1 !important;
    font-family: "Font Awesome 5 Free", "FontAwesome", "Font Awesome 6 Free" !important;
    font-weight: normal !important; /* Default to regular/outline heart (far) */
}

.modal-heart-icon.fas {
    font-weight: 900 !important; /* Solid heart when favorited */
}

.modal-heart-icon.far {
    font-weight: 400 !important; /* Regular/outline heart when not favorited */
}

#modal-favorite-btn .modal-heart-icon.fas {
    font-weight: 900 !important; /* Extra specificity for solid heart */
    font-family: "Font Awesome 5 Free", "FontAwesome", "Font Awesome 6 Free" !important;
}

#modal-favorite-btn .modal-heart-icon.far {
    font-weight: 400 !important; /* Extra specificity for outline heart */
    font-family: "Font Awesome 5 Free", "FontAwesome", "Font Awesome 6 Free" !important;
}

/* -----------------------------
 * 2. Book Detail Layout 
 * ----------------------------- */
.book-detail-layout {
    display: grid !important;
    grid-template-columns: minmax(350px, 30%) 1fr !important;
    gap: 30px !important;
    padding: 30px !important;
    height: calc(100vh - 120px) !important;
    overflow: hidden !important;
}

.book-detail-cover {
    padding: 20px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 20px !important;
    overflow-y: auto !important;
    scrollbar-width: thin !important;
    height: auto !important;
    max-height: calc(95vh - 140px) !important; /* Account for header and some padding */
    overflow-y: auto !important;
    overflow-x: hidden !important;
    will-change: scroll-position !important; /* Performance optimization */
    scrollbar-width: thin !important;
    -webkit-overflow-scrolling: touch !important; /* Smooth scrolling on iOS */
    overscroll-behavior: contain !important; /* Prevent scroll chaining */
}

.book-detail-cover img {
    width: 100% !important;
    height: auto !important;
    max-height: 40vh !important;
    object-fit: contain !important;
    border-radius: 8px !important;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3) !important;
}

.book-detail-info {
    padding: 20px !important;
    overflow-y: auto !important;
    scrollbar-width: thin !important;
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    max-height: calc(95vh - 140px) !important; /* Account for header and some padding */
    overflow-y: auto !important;
    overflow-x: hidden !important;
    will-change: scroll-position !important; /* Performance optimization */
    scrollbar-width: thin !important;
    -webkit-overflow-scrolling: touch !important; /* Smooth scrolling on iOS */
    overscroll-behavior: contain !important; /* Prevent scroll chaining */
}

/* Ensure the description comes before the action buttons */
.book-detail-description {
    margin-bottom: 25px !important;
    order: 10 !important;
}

/* Move action buttons to horizontal row layout with improved spacing */
.book-detail-actions {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important; /* Equal width columns */
    gap: 16px !important; /* Increased gap between buttons */
    margin: 25px 0 !important;
    padding: 20px 0 !important; /* Increased vertical padding */
    position: relative !important;
    z-index: 9000 !important;
    will-change: transform !important;
    transform: translateZ(0) !important;
    order: 20 !important;
    border-top: 1px solid rgba(255, 255, 255, 0.05) !important;
}

/* Apply !important to action button styles to prevent overrides */
.action-btn,
#modal-favorite-btn,
#modal-amazon-btn,
.download-book-btn,
.btn-download-detail,
.btn-favorite-detail,
.btn-amazon-detail {
    position: relative !important;
    height: 46px !important; /* Slightly taller buttons */
    width: 100% !important; /* Take full width of grid cell */
    padding: 0 16px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 10px !important;
    border-radius: 8px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    letter-spacing: 0.3px !important;
    border: none !important;
    cursor: pointer !important;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.25s ease !important;
    overflow: hidden !important;
    text-decoration: none !important;
    white-space: nowrap !important;
    transform: translateZ(0) !important;
    backface-visibility: hidden !important;
    -webkit-font-smoothing: antialiased !important;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2) !important;
    z-index: 9001 !important;
    color: white !important;
    margin: 0 !important; /* Reset any margin */
}

/* Download button - Green gradient */
.btn-download-detail,
.download-book-btn {
    background: linear-gradient(145deg, #10b981, #059669) !important;
    color: white !important;
    border: 1px solid rgba(5, 150, 105, 0.2) !important;
}

.btn-download-detail:hover,
.download-book-btn:hover {
    background: linear-gradient(145deg, #34d399, #10b981) !important;
    transform: translateY(-3px) !important;
    box-shadow: 0 6px 15px rgba(16, 185, 129, 0.3) !important;
}

/* Favorite button - Normal state - Pink gradient (changed from purple) */
.btn-favorite-detail,
#modal-favorite-btn {
    background: linear-gradient(145deg, #ec4899, #db2777) !important; /* Changed to pink */
    color: white !important;
    border: 1px solid rgba(219, 39, 119, 0.2) !important;
}

.btn-favorite-detail:hover,
#modal-favorite-btn:hover {
    background: linear-gradient(145deg, #f472b6, #ec4899) !important; /* Lighter pink on hover */
    transform: translateY(-3px) !important;
    box-shadow: 0 6px 15px rgba(236, 72, 153, 0.3) !important;
}

/* Favorite button - Favorited state - Deeper pink gradient */
.btn-favorite-detail.favorited,
#modal-favorite-btn.favorited {
    background: linear-gradient(145deg, #be185d, #9d174d) !important; /* Deeper pink when favorited */
    color: white !important;
    border: 1px solid rgba(190, 24, 93, 0.2) !important;
}

.btn-favorite-detail.favorited:hover,
#modal-favorite-btn.favorited:hover {
    background: linear-gradient(145deg, #db2777, #be185d) !important;
    transform: translateY(-3px) !important;
    box-shadow: 0 6px 15px rgba(190, 24, 93, 0.3) !important;
}

/* Amazon button - Orange gradient */
.btn-amazon-detail,
#modal-amazon-btn {
    background: linear-gradient(145deg, #f59e0b, #d97706) !important;
    color: white !important;
    border: 1px solid rgba(217, 119, 6, 0.2) !important;
}

.btn-amazon-detail:hover,
#modal-amazon-btn:hover {
    background: linear-gradient(145deg, #fbbf24, #f59e0b) !important;
    transform: translateY(-3px) !important;
    box-shadow: 0 6px 15px rgba(245, 158, 11, 0.3) !important;
}

/* Button focus states */
.action-btn:focus {
    outline: none !important;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2), 0 4px 10px rgba(0, 0, 0, 0.2) !important;
}

/* Button active state */
.action-btn:active {
    transform: translateY(1px) !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
}

/* Button icon and text styling */
.action-btn i {
    font-size: 16px !important;
    margin-right: 8px !important;
    flex-shrink: 0 !important;
}

.action-btn span {
    flex-grow: 1 !important;
    text-align: center !important;
    font-size: 14px !important;
    color: white !important;
}

.action-btn small {
    font-size: 11px !important;
    opacity: 0.8 !important;
    font-weight: normal !important;
    color: white !important;
}

/* Disabled state */
.action-btn:disabled {
    opacity: 0.6 !important;
    cursor: not-allowed !important;
    transform: none !important;
}

/* Put reviews at the bottom */
.book-detail-reviews {
    margin-top: 25px !important;
    padding-top: 25px !important;
    border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
    order: 30 !important; /* Make sure it appears after action buttons */
}

/* Book Details Refinements */
.book-detail-meta {
    display: flex !important;
    gap: 20px !important;
    margin: 15px 0 !important;
    padding: 15px !important;
    background: rgba(255, 255, 255, 0.05) !important;
    border-radius: 10px !important;
}

.book-detail-rating,
.book-detail-downloads {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    font-size: 15px !important;
    color: var(--text-secondary, rgba(255, 255, 255, 0.7)) !important;
}

.book-detail-rating i {
    color: #ffd700 !important;
}

.book-detail-categories {
    margin: 1rem 0 !important;
}

.category-label {
    display: block !important;
    color: rgba(255, 255, 255, 0.7) !important;
    margin-bottom: 0.5rem !important;
    font-size: 0.9rem !important;
}

.category-tags {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
    align-items: center !important;
}

.category-tag {
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    padding: 0.5rem 1rem !important;
    border-radius: 2rem !important;
    font-size: 0.875rem !important;
    background: rgba(255, 255, 255, 0.1) !important;
    color: rgba(255, 255, 255, 0.9) !important;
    transition: all 0.2s ease-in-out !important;
}

.main-category-tag {
    background: linear-gradient(135deg, #ff8f00, #ff6d00) !important;
    color: white !important;
    font-weight: 500 !important;
    box-shadow: 0 2px 4px rgba(255, 109, 0, 0.2) !important;
}

.main-category-tag i {
    font-size: 0.75em !important;
    opacity: 0.9 !important;
}

.additional-categories {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
}

.dark-tag {
    background: rgba(255, 255, 255, 0.1) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
}

.book-detail-specs {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
    gap: 15px !important;
    margin: 25px 0 !important;
    padding: 20px !important;
    background: rgba(0, 0, 0, 0.2) !important;
    border-radius: 10px !important;
}

.spec-item {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    font-size: 14px !important;
    color: var(--text-secondary, rgba(255, 255, 255, 0.7)) !important;
}

.spec-item i {
    font-size: 16px !important;
    color: var(--accent-primary, #4CAF50) !important;
}

/* Enhanced Review Section */
.reviews-list {
    max-width: 800px !important;
    margin: 0 auto !important;
}

.review-item {
    background: rgba(255, 255, 255, 0.03) !important;
    border: 1px solid rgba(255, 255, 255, 0.05) !important;
    border-radius: 8px !important;
    padding: 16px !important;
    margin-bottom: 16px !important;
}

.review-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: flex-start !important;
    margin-bottom: 12px !important;
}

.reviewer-info {
    display: flex !important;
    flex-direction: column !important;
}

.reviewer-name {
    color: #fff !important;
    font-size: 14px !important;
    font-weight: 500 !important;
}

.review-rating {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 4px !important;
}

.review-content {
    color: rgba(255, 255, 255, 0.8) !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    margin: 12px 0 !important;
}

.review-footer {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    margin-top: 12px !important;
}

.review-date {
    color: rgba(255, 255, 255, 0.5) !important;
    font-size: 13px !important;
}

.helpful-btn {
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    padding: 6px 12px !important;
    border-radius: 20px !important;
    font-size: 13px !important;
    color: rgba(255, 255, 255, 0.7) !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    transition: all 0.2s ease !important;
    cursor: pointer !important;
}

.helpful-btn:hover,
.helpful-btn.active {
    background: rgba(255, 255, 255, 0.1) !important;
    color: #fff !important;
    transform: translateY(-1px) !important;
}

.helpful-btn i {
    font-size: 14px !important;
}

/* Review Loading Skeleton */
.skeleton-review {
    padding: 20px !important;
    background: rgba(255, 255, 255, 0.03) !important;
    border-radius: 12px !important;
    margin-bottom: 15px !important;
    animation: pulse 1.5s infinite !important;
}

.skeleton-review::before {
    content: '' !important;
    display: block !important;
    width: 100% !important;
    height: 100px !important;
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.03) 25%,
        rgba(255, 255, 255, 0.05) 50%,
        rgba(255, 255, 255, 0.03) 75%
    ) !important;
    background-size: 200% 100% !important;
    animation: shimmer 1.5s infinite !important;
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 0.8; }
    100% { opacity: 0.6; }
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* -----------------------------
 * 3. Preview System 
 * ----------------------------- */
.preview-section {
    width: 100% !important;
    margin-top: 20px !important;
}

.preview-container {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important; /* Force single row */
    justify-content: center !important; /* Ensure center alignment */
    align-items: center !important;
    gap: 15px !important; /* Increased gap between items */
    padding: 20px !important; /* Increased padding */
    background: rgba(0, 0, 0, 0.2) !important;
    border-radius: 12px !important;
    min-height: auto !important;
    max-height: 160px !important; /* Increased height to accommodate larger thumbnails */
    width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    position: relative !important; /* Added for proper positioning */
    text-align: center !important; /* Center children by default */
    min-height: 120px !important;
}

.preview-item {
    flex: 0 0 auto !important;
    width: 90px !important; /* Increased width */
    height: 115px !important; /* Increased height */
    position: relative !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    overflow: hidden !important;
    border-radius: 8px !important;
    background: rgba(0, 0, 0, 0.3) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    z-index: 1053 !important;
    margin: 0 !important;
    display: inline-block !important;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3) !important;
}

.preview-image {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    border-radius: 8px !important;
}

.preview-item::after {
    content: '\f06e' !important;
    font-family: 'Font Awesome 5 Free' !important;
    font-weight: 900 !important;
    position: absolute !important;
    inset: 0 !important;
    background: rgba(0, 0, 0, 0.5) !important;
    color: white !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 18px !important; /* Increased icon size */
    opacity: 0 !important;
    transition: opacity 0.2s ease !important;
}

.preview-item:hover::after {
    opacity: 1 !important;
}

.preview-item:hover {
    transform: translateY(-5px) !important; /* Increased hover lift effect */
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5) !important; /* Enhanced shadow on hover */
}

.simple-preview-grid {
    display: flex !important;
    justify-content: center !important; /* Center the preview items */
    align-items: center !important;
    gap: 15px !important;
    margin: 0 auto !important; /* Center horizontally */
    width: auto !important; /* Use auto width instead of 100% */
    position: relative !important;
    flex-wrap: nowrap !important;
    min-width: 0 !important; /* Allow proper shrinking */
}

/* Update responsive styles for preview container */
@media (max-width: 992px) {
    .preview-container {
        min-height: 120px !important;
    }
    
    .preview-item {
        width: 80px !important;
        height: 105px !important;
    }
}

@media (max-width: 768px) {
    .preview-container {
        min-height: 100px !important;
        padding: 15px !important;
    }
    
    .preview-item {
        width: 70px !important;
        height: 95px !important;
    }
}

@media (max-width: 576px) {
    .preview-container {
        min-height: 90px !important;
        padding: 10px !important;
    }
    
    .preview-item {
        width: 60px !important;
        height: 80px !important;
    }
}

/* Review section and loading improvements */
.preview-loading, .reviews-loading {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 10px !important;
    margin: 20px 0 !important;
}

/* -----------------------------
 * 4. Rating Modal 
 * ----------------------------- */
#ratingModal {
    z-index: 1070 !important;
}

#ratingModal .modal-dialog {
    max-width: 700px !important;
    width: 95% !important;
    min-width: 400px !important;
    margin: 1.75rem auto !important;
    height: auto !important;
}

#ratingModal .modal-content {
    background: linear-gradient(135deg, #2a2a5a, #1a1a3a) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3) !important;
    min-height: unset !important;
    height: auto !important;
    max-height: calc(90vh - 3.5rem) !important;
    z-index: 1071 !important;
}

#ratingModal .modal-header {
    background: rgba(255, 255, 255, 0.05) !important;
    padding: 1.5rem !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
}

#ratingModal .modal-header h2 {
    color: #fff !important;
    font-size: 1.75rem !important;
    font-weight: 500 !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
}

#ratingModal .modal-body {
    padding: 2rem !important;
    overflow-y: auto !important;
}

.rating-stars {
    display: flex !important;
    justify-content: center !important;
    gap: 0.75rem !important;
    margin: 1rem 0 2rem !important;
    padding: 1.5rem !important;
    background: rgba(255, 255, 255, 0.05) !important;
    border-radius: 12px !important;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1) !important;
}

.rating-star {
    font-size: 2.5rem !important;
    padding: 0.5rem !important;
    color: #ffd700 !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
    transition: all 0.2s ease-in-out !important;
    background: transparent !important;
    border: none !important;
    cursor: pointer !important;
    outline: none !important;
}

.rating-star:hover {
    transform: scale(1.2) rotate(8deg) !important;
    color: #fff45c !important;
}

.rating-star.fas {
    color: #ffd700 !important;
    filter: drop-shadow(0 0 5px rgba(255, 215, 0, 0.5)) !important;
}

#rating-comment {
    background: rgba(255, 255, 255, 0.08) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 8px !important;
    color: #fff !important;
    padding: 1rem !important;
    min-height: 120px !important;
    resize: vertical !important;
    transition: all 0.2s ease !important;
}

#rating-comment:focus {
    background: rgba(255, 255, 255, 0.12) !important;
    border-color: rgba(255, 215, 0, 0.5) !important;
    box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.2) !important;
}

#rating-form label {
    color: rgba(255, 255, 255, 0.9) !important;
    font-size: 1.1rem !important;
    margin-bottom: 0.5rem !important;
}

#submit-rating {
    width: 100% !important;
    padding: 1rem !important;
    margin-top: 1.5rem !important;
    background: linear-gradient(45deg, #ffd700, #ffb347) !important;
    border: none !important;
    border-radius: 8px !important;
    color: #000 !important;
    font-weight: 600 !important;
    font-size: 1.1rem !important;
    transition: all 0.3s ease !important;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3) !important;
}

#submit-rating:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 20px rgba(255, 215, 0, 0.4) !important;
    background: linear-gradient(45deg, #ffcd00, #ffa500) !important;
}

#submit-rating:active {
    transform: translateY(0) !important;
    box-shadow: 0 2px 10px rgba(255, 215, 0, 0.3) !important;
}

/* Update responsive styles */
@media (max-width: 576px) {
    #ratingModal .modal-dialog {
        width: 95% !important;
        min-width: unset !important;
        margin: 1rem auto !important;
    }
    
    #ratingModal .modal-content {
        max-height: calc(100vh - 2rem) !important;
    }
    
    #ratingModal .modal-header {
        padding: 1rem !important;
    }
    
    #ratingModal .modal-body {
        padding: 1rem !important;
    }
}

/* -----------------------------
 * 5. Lightbox System 
 * ----------------------------- */
#previewLightbox {
    position: fixed !important;
    inset: 0 !important;
    z-index: 9999 !important;
    background-color: rgba(0, 0, 0, 0.85) !important;
    display: none !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    overflow: hidden !important;
}

#previewLightbox.active {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.lightbox-container {
    position: relative !important;
    width: 90% !important;
    max-width: 1400px !important;
    height: 90% !important;
    max-height: 90vh !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: visible !important;
    background: rgba(30, 30, 30, 0.85) !important;
    border-radius: 12px !important;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.7) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.lightbox-content {
    position: relative !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    height: 100% !important;
    padding: 30px !important;
    overflow: visible !important;
}

/* Enhanced image styles */
.lightbox-image {
    max-width: 95% !important;
    max-height: 80vh !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
    border-radius: 8px !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6) !important;
    transition: transform 0.3s ease !important;
    transform-origin: center !important;
    margin: 0 auto !important;
    display: block !important;
}

/* Special handling for base64 images */
.lightbox-image.base64-image {
    max-width: 95% !important;
    max-height: 80vh !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
}

/* Close button redesign */
.lightbox-close, 
.modal-close,
#bookDetailModal .close-btn {
    position: absolute !important;
    top: 15px !important;
    right: 15px !important;
    width: 44px !important;
    height: 44px !important;
    background: rgba(255, 255, 255, 0.15) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    border-radius: 50% !important;
    color: white !important;
    font-size: 24px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    z-index: 10000 !important;
    transition: all 0.2s ease !important;
}

.lightbox-close:hover, 
.modal-close:hover,
#bookDetailModal .close-btn:hover {
    background: rgba(255, 255, 255, 0.3) !important;
    transform: scale(1.1) !important;
}

/* Improved navigation controls - positioned closer to the image */
.lightbox-controls {
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    display: flex !important;
    justify-content: space-between !important;
    pointer-events: none !important;
    z-index: 10000 !important;
    width: 100% !important;
    padding: 0 30px !important;
    max-width: 100% !important;
}

.lightbox-nav {
    width: 50px !important;
    height: 50px !important;
    background: rgba(40, 40, 40, 0.7) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    border-radius: 50% !important;
    color: white !important;
    font-size: 24px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    pointer-events: auto !important;
    transition: all 0.2s ease !important;
    margin: 0 -100px !important; /* Pull the buttons in toward the image */
    opacity: 0.8 !important;
}

.lightbox-nav:hover {
    background: rgba(60, 60, 60, 0.9) !important;
    transform: scale(1.1) !important;
    opacity: 1 !important;
}

.lightbox-nav.prev {
    margin-left: 20px !important;
}

.lightbox-nav.next {
    margin-right: 20px !important;
}

.lightbox-caption {
    position: absolute !important;
    bottom: 20px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    text-align: center !important;
    color: white !important;
    font-size: 16px !important;
    padding: 8px 20px !important;
    background: rgba(40, 40, 40, 0.7) !important;
    border-radius: 20px !important;
    z-index: 10000 !important;
    min-width: 150px !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

/* Add navigation hints */
.lightbox-nav::after {
    position: absolute !important;
    top: 110% !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    white-space: nowrap !important;
    font-size: 12px !important;
    background: rgba(0, 0, 0, 0.7) !important;
    padding: 4px 8px !important;
    border-radius: 4px !important;
    opacity: 0 !important;
    transition: opacity 0.2s ease !important;
}

.lightbox-nav.prev::after {
    content: 'Previous (←)' !important;
}

.lightbox-nav.next::after {
    content: 'Next (→)' !important;
}

.lightbox-nav:hover::after {
    opacity: 1 !important;
}

/* Improved media queries for responsive design */
@media (max-width: 992px) {
    .lightbox-container {
        width: 95% !important;
        height: 90% !important;
    }
    
    .lightbox-nav {
        width: 40px !important;
        height: 40px !important;
        font-size: 18px !important;
        margin: 0 -50px !important;
    }
    
    .lightbox-nav.prev {
        margin-left: 10px !important;
    }
    
    .lightbox-nav.next {
        margin-right: 10px !important;
    }
}

@media (max-width: 768px) {
    .lightbox-container {
        width: 95% !important;
        height: 80% !important;
        border-radius: 8px !important;
    }
    
    .lightbox-content {
        padding: 20px !important;
    }
    
    .lightbox-image {
        max-height: 70vh !important;
    }
    
    .lightbox-controls {
        padding: 0 10px !important;
    }
    
    .lightbox-nav {
        margin: 0 !important;
        width: 36px !important;
        height: 36px !important;
        font-size: 16px !important;
    }
    
    .lightbox-caption {
        font-size: 14px !important;
        padding: 6px 12px !important;
    }
}

/* -----------------------------
 * 6. Responsive Design 
 * ----------------------------- */
@media (max-width: 1600px) {
    .modal-dialog {
        max-width: 1400px !important;
    }

    #bookDetailModal .modal-dialog {
        max-width: 1400px !important;
        width: 95% !important;
    }
}

@media (max-width: 1200px) {
    .modal-dialog {
        max-width: 1100px !important;
        min-width: 800px !important;
    }

    #bookDetailModal .modal-dialog {
        max-width: 1100px !important;
        min-width: 800px !important;
    }
}

@media (max-width: 992px) {
    .modal-dialog {
        min-width: 0 !important; /* Remove min-width for mobile */
        width: 95% !important;
    }

    .book-detail-layout {
        grid-template-columns: 1fr !important;
        height: auto !important;
        overflow-y: auto !important;
    }

    .preview-container {
        height: 150px !important;
    }

    #bookDetailModal .modal-dialog {
        min-width: 0 !important;
        width: 95% !important;
    }
}

/* Mobile-specific fixes for scrolling images and content */
@media (max-width: 768px) {
    .modal-dialog {
        width: 95% !important;
        margin: 10px !important;
    }

    .book-detail-layout {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
        overflow-y: visible !important; /* Use visible to ensure content flows */
        max-height: none !important; /* Remove max-height constraint */
        padding: 15px !important; /* Reduce padding for mobile */
        gap: 20px !important;
    }

    .book-detail-cover, .book-detail-info {
        width: 100% !important;
        max-height: none !important; /* Remove height constraints */
        overflow-y: visible !important; /* Don't scroll independently */
        height: auto !important; /* Auto height */
        flex-shrink: 0 !important;
    }

    .book-detail-cover {
        margin-bottom: 20px !important;
    }

    .book-detail-cover img {
        max-height: 300px !important;
        object-fit: contain !important;
    }

    /* Ensure modal content scrolls as a whole */
    #bookDetailModal .modal-body {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        height: auto !important;
        max-height: 85vh !important; /* Leave room for header */
        padding: 0 !important;
    }

    .preview-container {
        height: auto !important;
        min-height: 150px !important;
        padding: 15px 10px !important;
    }

    /* Fix button size on smaller screens */
    .action-btn {
        height: 40px !important;
        padding: 0 12px !important;
        font-size: 13px !important;
    }

    .action-btn span {
        font-size: 12px !important;
    }

    .action-btn small {
        font-size: 10px !important;
    }
}

/* Extra small devices (phones) */
@media (max-width: 480px) {
    .book-detail-actions {
        grid-template-columns: 1fr !important; /* Stack buttons vertically */
        gap: 10px !important;
    }

    .modal-content {
        border-radius: 0 !important; /* Full width on very small screens */
    }

    .book-detail-cover img {
        max-height: 230px !important;
    }

    .book-detail-title {
        font-size: 18px !important;
    }

    /* Single scrollable container for the entire modal body */
    #bookDetailModal .modal-body {
        max-height: 90vh !important;
        -webkit-overflow-scrolling: touch !important;
    }
}

@media (max-width: 576px) {
    .preview-container {
        height: 100px !important;
    }

    .modal-content {
        border-radius: 8px !important;
    }
}

/* Fix modal resizing issues and small screen scrolling */
@media (max-height: 768px) {
    .modal-dialog {
        max-height: 100vh !important; /* Use full viewport height */
        margin: 0 auto !important; /* Remove vertical margin */
    }
    
    .modal-content {
        max-height: 100vh !important;
        border-radius: 0 !important; /* Remove border radius on small screens */
    }
    
    .book-detail-layout {
        height: auto !important;
        overflow: hidden !important;
        max-height: none !important;
    }
    
    .book-detail-cover, .book-detail-info {
        max-height: none !important; /* Remove height constraint */
        overflow-y: auto !important;
    }
    
    /* For portrait mode mobile devices */
    @media (max-width: 576px) {
        .book-detail-layout {
            display: flex !important;
            flex-direction: column !important;
            overflow: visible !important;
        }
        
        .book-detail-cover {
            max-height: 40vh !important; /* Limit cover height */
        }
        
        .book-detail-info {
            padding-bottom: 120px !important; /* Extra bottom padding */
        }
    }
}

/* Responsive adjustments for extremely small screens */
@media (max-height: 500px) {
    .book-detail-layout {
        grid-template-columns: 25% 75% !important; /* Adjust column ratio */
    }
    
    .book-cover img {
        max-height: 25vh !important; /* Smaller cover image */
    }
    
    .book-detail-title {
        font-size: 18px !important; /* Smaller title */
    }
    
    .book-detail-meta, .book-detail-categories, .book-detail-specs {
        margin: 10px 0 !important; /* Tighter spacing */
        padding: 10px !important;
    }
}

/* Custom scrollbar styling */
.preview-container::-webkit-scrollbar,
.book-detail-cover::-webkit-scrollbar,
.book-detail-info::-webkit-scrollbar {
    width: 8px !important;
    height: 8px !important;
    background-color: rgba(0, 0, 0, 0.2) !important;
}

.preview-container::-webkit-scrollbar-track,
.book-detail-cover::-webkit-scrollbar-track,
.book-detail-info::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1) !important;
    border-radius: 3px !important;
}

.preview-container::-webkit-scrollbar-thumb,
.book-detail-cover::-webkit-scrollbar-thumb,
.book-detail-info::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2) !important;
    border-radius: 3px !important;
}

.preview-container::-webkit-scrollbar-thumb:hover,
.book-detail-cover::-webkit-scrollbar-thumb:hover,
.book-detail-info::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25) !important;
}

/* Accessibility improvements */
.modal:focus-within {
    outline: none !important;
}

.modal[inert] {
    pointer-events: none !important;
    cursor: default !important;
}

/* Fix for iOS and Safari */
@supports (-webkit-touch-callout: none) {
    .book-detail-cover, .book-detail-info {
        padding-bottom: 70px !important; /* Add extra padding at bottom for iOS */
    }
}

/* Window resize event handling */
@media (max-height: 600px) {
    .book-detail-layout {
        grid-template-columns: 30% 70% !important; /* Adjust column ratio for small heights */
        max-height: 90vh !important;
    }
    
    .book-cover img {
        max-height: 30vh !important; /* Smaller cover image on short screens */
    }
    
    .book-detail-reviews, .book-detail-actions {
        margin-top: 15px !important;
        padding-top: 15px !important;
    }
}

/* -----------------------------
 * 7. Animations
 * ----------------------------- */
.fade {
    transition: opacity 0.15s linear !important;
}

.fade:not(.show) {
    opacity: 0 !important;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

.fade-in {
    animation: fadeIn 0.3s ease-in-out !important;
}

.fade-out {
    animation: fadeOut 0.3s ease-in-out !important;
}

/* Button animations */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.spinner {
    animation: spin 1s linear infinite !important;
}

/* Button States */
.btn-loading {
    position: relative !important;
    pointer-events: none !important;
}

.btn-loading i {
    animation: spin 1s linear infinite !important;
}

/* Debug Info */
.debug-info {
    display: none !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    background: rgba(0,0,0,0.8) !important;
    color: white !important;
    padding: 10px !important;
    font-family: monospace !important;
    font-size: 12px !important;
    z-index: 9999 !important;
}
