/* Header Consistency Fix */
.header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    margin-bottom: 30px !important;
    flex-wrap: wrap !important;
    gap: 15px !important;
}

.header .header-right {
    display: flex !important;
    align-items: center !important;
    gap: 20px !important;
}

/* Content Title styling */
.content-title {
    margin-bottom: 30px;
}

.content-title h1 {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.content-title p {
    color: var(--text-secondary);
    font-size: 16px;
}

/* Books Grid */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
    margin-bottom: 40px;
    margin-top: 20px;
}

/* Refined Book Tile Styling */
.book-tile {
    background: var(--bg-elevated);
    border-radius: var(--book-border-radius);
    overflow: hidden;
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    flex-direction: column;
    box-shadow: var(--book-shadow);
    border: 1px solid rgba(255, 255, 255, 0.05);
    height: 100%;  /* Make all tiles equal height */
}

.book-tile:hover {
    transform: translateY(-5px);
    box-shadow: var(--book-hover-shadow);
}

/* Update or add these styles */
.book-cover {
    position: relative;
    width: 100%;
    height: 240px;  /* Adjust height as needed */
    border-radius: 8px;
    overflow: hidden;
}

.book-cover img {
    object-fit: cover;
    object-position: top;  /* This makes the image align from top */
    width: 100%;
    height: 100%;
    border-radius: 8px;
}

.book-cover .book-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, rgba(0,0,0,0) 50%, rgba(0,0,0,0.7) 100%);
    pointer-events: none;
}

.no-cover {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-elevated);
    border-radius: 8px;
    color: var(--text-secondary);
}

.no-cover i {
    font-size: 32px;
    margin-bottom: 8px;
}

.book-cover {
    position: relative;
    height: 220px;
    overflow: hidden;
    background: #1a1a2e; /* Dark background for empty covers */
}

.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}

.book-tile:hover .book-cover img {
    transform: scale(1.08);
}

/* Improved book info spacing */
.book-info {
    padding: 16px !important;
    display: flex !important;
    flex-direction: column !important;
    flex-grow: 1 !important;
    justify-content: space-between !important;
    background: var(--bg-card) !important;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* Better title typography */
.book-title {
    font-size: 16px !important;
    font-weight: 600 !important;
    line-height: 1.3 !important;
    color: var(--text-primary) !important;
    margin-bottom: 8px !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    min-height: 42px !important;
}

/* Improved book meta layout */
.book-meta {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 0 !important;
    margin: 8px 0 12px 0 !important;  /* Adjusted margin */
}

.book-rating, .book-downloads {
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
    font-size: 13px !important;
    color: var(--text-secondary) !important;
    padding: 3px 8px !important;
    border-radius: 50px !important;
    background: rgba(0, 0, 0, 0.1) !important;
}

.book-rating i {
    color: #f59e0b !important;
}

.book-downloads i {
    color: #3b82f6 !important;
}

/* Enhanced action buttons styling */
.book-actions {
    display: flex !important;
    justify-content: space-around !important; /* Changed to space-around for better spacing */
    gap: 8px !important; /* Reduced gap */
    margin-top: 10px !important;
    padding: 4px 0 !important;
    position: relative !important;
    z-index: 5 !important;
    width: 100% !important;
}

.book-actions button {
    width: 34px !important; /* Adjusted size */
    height: 34px !important;
    border-radius: 50% !important;
    border: none !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important; /* Lighter shadow */
    position: relative !important;
}

.book-actions button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.book-actions button:hover {
    transform: translateY(-3px) scale(1.05) !important;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2) !important;
}

.book-actions button:hover::before {
    opacity: 1;
}

.book-actions button:active {
    transform: translateY(0) scale(0.98) !important;
}

.book-actions button i {
    font-size: 14px !important; /* Smaller icons */
    transition: transform 0.2s ease !important;
}

.book-actions button:hover i {
    transform: scale(1.1) !important;
}

/* Distinct button colors */
.btn-quick-view {
    background: linear-gradient(145deg, #4f46e5, #3b82f6) !important;
    color: white !important;
}

.btn-download {
    background: linear-gradient(145deg, #10b981, #059669) !important;
    color: white !important;
}

.btn-amazon {
    background: linear-gradient(145deg, #f59e0b, #d97706) !important;
    color: white !important;
}

.btn-rate {
    background: linear-gradient(145deg, #9061f9, #6d28d9) !important;
    color: white !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 32px !important;
    height: 32px !important;
    border-radius: 50% !important;
    border: none !important;
    cursor: pointer !important;
    z-index: 5 !important;
    opacity: 1 !important;
    visibility: visible !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
    position: relative !important;
    overflow: visible !important;
    transition: transform 0.2s ease !important;
}

.btn-rate:hover, .btn-rate:active, .btn-rate:focus {
    transform: translateY(-3px) !important;
    box-shadow: 0 4px 15px rgba(109, 40, 217, 0.5) !important;
    background: linear-gradient(145deg, #a370fc, #7d38e2) !important;
    outline: none !important;
}

.btn-rate i {
    color: white !important;
    font-size: 14px !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: none !important;
}

.btn-favorite {
    background: linear-gradient(145deg, #ec4899, #be185d) !important;
    color: white !important;
}

/* Distinct button colors for tile buttons */
.btn-tile-download {
    background: linear-gradient(145deg, #10b981, #059669) !important;
    color: white !important;
}

.btn-tile-favorite {
    background: linear-gradient(145deg, #ec4899, #be185d) !important;
    color: white !important;
}

/* Update button states for tile buttons */
.book-tile .btn-tile-favorite.favorited {
    background: linear-gradient(145deg, #be185d, #9d174d) !important;
}

.book-tile .btn-tile-favorite.favorited i {
    color: white !important;
}

/* Downloaded state indicator for buttons */
.btn-tile-download.already-downloaded {
    background: linear-gradient(145deg, #20c997, #0ca678) !important; /* Slightly different green */
    box-shadow: 0 2px 8px rgba(32, 201, 151, 0.3) !important;
}

.btn-tile-download.already-downloaded::after {
    content: 'Already Downloaded';
    font-size: 10px;
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 3px 6px;
    border-radius: 3px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.btn-tile-download.already-downloaded:hover::after {
    opacity: 1;
    visibility: visible;
    bottom: -25px;
}

/* Improved button tooltips */
.book-actions button::after {
    content: attr(aria-label);
    position: absolute;
    bottom: calc(100% + 5px);
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.book-actions button:hover::after {
    opacity: 1;
    visibility: visible;
    bottom: calc(100% + 8px);
}

/* Add hover effects to book tiles */
.book-cover::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, 0) 40%);
    opacity: 0.6;
    transition: opacity 0.3s ease;
}

.book-tile:hover .book-cover::after {
    opacity: 0.8;
}

/* Improve grid layout for better tile alignment */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
    margin-bottom: 40px;
    margin-top: 20px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
        gap: 20px;
    }
    
    .book-cover {
        height: 180px;
    }
    
    .book-info {
        padding: 12px !important;
    }
    
    .book-title {
        font-size: 14px !important;
        min-height: 38px !important;
    }
    
    .book-meta {
        margin: 8px 0 !important;
    }
    
    .book-actions button {
        width: 32px !important;
        height: 32px !important;
    }
}

@media (max-width: 576px) {
    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 15px;
    }
    
    .book-cover {
        height: 160px;
    }
    
    .book-info {
        padding: 10px !important;
    }
    
    .book-title {
        font-size: 13px !important;
        min-height: 34px !important;
    }
    
    .book-meta {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 5px !important;
    }
    
    .book-actions {
        gap: 5px !important;
    }
    
    .book-actions button {
        width: 28px !important;
        height: 28px !important;
    }
    
    .book-actions button i {
        font-size: 12px !important;
    }
}

/* Fix for book actions and buttons that aren't displaying */
.book-actions {
    position: relative !important; /* Change from absolute to relative */
    top: auto !important;
    right: auto !important;
    left: auto !important;
    display: flex !important;
    flex-direction: row !important; /* Change from column to row */
    justify-content: center !important; /* Center the buttons */
    gap: 12px !important; /* Increase gap for horizontal layout */
    z-index: 5 !important;
    padding: 10px 0 !important; /* Add vertical padding */
    margin-top: 10px !important; /* Add space between ratings and buttons */
    background: transparent !important;
    opacity: 1 !important;
    visibility: visible !important;
    width: 100% !important; /* Take full width of container */
}

.book-actions button {
    width: 32px !important;
    height: 32px !important;
    border-radius: 50%;
    border: none;
    display: flex !important;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0.85 !important; /* Slightly transparent */
    visibility: visible !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3) !important; /* Add shadow for better visibility */
}

.book-actions button:hover {
    opacity: 1 !important;
    transform: scale(1.1);
}

/* Ensure button background colors are visible */
.btn-quick-view {
    background: rgba(59, 130, 246, 0.8) !important;
    color: white !important;
}

.btn-download {
    background: rgba(16, 185, 129, 0.8) !important;
    color: white !important;
}

.btn-amazon {
    background: rgba(245, 158, 11, 0.8) !important;
    color: white !important;
    display: flex !important; /* Ensure display is flex */
    align-items: center !important;
    justify-content: center !important;
    width: 32px !important;
    height: 32px !important;
    border-radius: 50% !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.btn-favorite {
    background: rgba(236, 72, 153, 0.8) !important;
    color: white !important;
}

/* Stronger overrides for book meta information */
.book-meta {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    color: var(--text-secondary) !important;
    font-size: 14px !important;
    margin-top: 8px !important; /* Reduce margin */
    margin-bottom: 0 !important; /* Ensure no bottom margin that might push buttons down */
    padding: 0 5px !important;
    font-weight: 500 !important;
    opacity: 1 !important;
    visibility: visible !important;
    position: relative !important;
    z-index: 3 !important; /* Lower than buttons but still visible */
    height: auto !important;
    min-height: 20px !important;
    overflow: visible !important;
    background: transparent !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    background: var(--bg-card) !important;
}

.book-rating, 
.book-downloads {
    display: flex !important;
    align-items: center !important;
    gap: 5px !important;
    opacity: 1 !important;
    visibility: visible !important;
    min-width: 40px !important;
    position: relative !important;
    z-index: 6 !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: static !important;
    padding: 0 !important;
    margin: 0 !important;
}

.book-rating i,
.book-downloads i {
    display: inline-block !important;
    width: auto !important;
    height: auto !important;
    font-size: 14px !important;
    visibility: visible !important;
    opacity: 1 !important;
    overflow: visible !important;
    margin-right: 4px !important;
    line-height: 1 !important;
}

.book-rating i {
    color: #f59e0b !important; /* Amber/yellow color for stars */
}

.book-downloads i {
    color: #3b82f6 !important; /* Blue color for downloads */
}

.book-rating span,
.book-downloads span {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    color: var(--text-secondary) !important;
    font-weight: 500 !important;
    font-size: 14px !important;
    line-height: 1 !important;
}

/* Ensure the book info has proper spacing */
.book-info {
    padding: 12px 15px 12px !important; /* Reduce bottom padding */
    flex-grow: 1 !important;
    background: var(--bg-card) !important;
    min-height: 100px !important; /* Ensure enough space */
    display: flex !important;
    flex-direction: column !important;
    position: relative !important;
    z-index: 2 !important;
    justify-content: space-between !important; /* Ensure even spacing */
    margin-top: 0 !important; /* Ensure no unexpected margin */
}

.book-info {
    padding: 12px 15px 12px;  /* Reduce top padding slightly */
    flex-grow: 1;
    background: var(--bg-card);
    position: relative; /* Ensure z-index works */
    z-index: 2; /* Lower than book-actions but still above other elements */
}

/* Enhance book title and meta display */
.book-title {
    font-size: 16px !important;
    font-weight: 600 !important;
    margin-bottom: 6px !important;
    line-height: 1.3 !important;
    color: var(--text-primary) !important;
    max-height: 42px !important;
    overflow: hidden !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important; /* Limit to 2 lines */
    -webkit-box-orient: vertical !important;
    text-overflow: ellipsis !important;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 6px;  /* Reduced from 8px */
    line-height: 1.3;
    color: var(--text-primary);
    max-height: 42px;    /* Limit to ~2 lines */
    overflow: hidden;
    min-height: 42px !important; /* Fixed height for 2 lines of text */
}

/* Fix for book-meta visibility issues */
.book-meta {
    display: flex !important;
    justify-content: space-between;
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 8px;
    padding: 0 5px;
    font-weight: 500;
    opacity: 1 !important;
    visibility: visible !important;
}

.book-rating, .book-downloads {
    display: flex !important;
    align-items: center;
    gap: 5px;
    opacity: 1 !important;
    visibility: visible !important;
}

.book-rating i {
    color: #f59e0b !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.book-downloads i {
    color: #3b82f6 !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.book-footer, .book-category, .book-tags, .book-badge {
    display: none;
}

.book-overlay {
    display: none;
}

/* Pagination styling */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 40px 0;
    gap: 5px;
    flex-wrap: wrap;
    padding: 0 10px;
}

.pagination a,
.pagination span {
    min-width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 15px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.2s ease;
    color: var(--text-primary);
    background: var(--bg-elevated);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.pagination a:hover {
    background: var(--accent-purple);
    color: white;
    transform: translateY(-1px);
}

.pagination .current {
    background: var(--accent-purple);
    color: white;
    font-weight: 600;
}

.pagination .first,
.pagination .last,
.pagination .prev,
.pagination .next {
    font-weight: 500;
}

.pagination .disabled {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}

@media (max-width: 768px) {
    .pagination {
        gap: 4px;
    }

    .pagination a,
    .pagination span {
        min-width: 36px;
        height: 36px;
        padding: 0 10px;
        font-size: 13px;
    }
}

/* Skeleton loading styles */
.preview-skeleton {
    display: flex;
    gap: 10px;
    width: 100%;
}

.skeleton-thumbnail {
    width: 70px;
    height: 90px;
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-elevated) 50%, var(--bg-card) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 5px;
    flex-shrink: 0;
}

.skeleton-review {
    height: 100px;
    margin-bottom: 15px;
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-elevated) 50%, var(--bg-card) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 8px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* User Favorites indicator */
.book-tile.favorited .btn-favorite {
    background: rgba(236, 72, 153, 1) !important;
}

.book-tile.favorited .btn-favorite i {
    color: white !important;
}

/* Pagination server-side implementation */
.pagination-loader {
    width: 100%;
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

.pagination-loader .loader {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Add these new styles for credits display */
.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 10px;
}

/* Credits display - improved alignment */
.credits-display {
    background: var(--bg-elevated);
    padding: 10px 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 15px;
    color: var(--text-primary);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.05);
    min-width: 230px;
    transition: all 0.2s ease;
}

.credits-display:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

.credits-display .next-reset {
    font-size: 0.8em;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: center;
    opacity: 0.9;
}

.credits-display:hover .next-reset {
    opacity: 1;
}

.credits-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.credits-icon i {
    color: var(--accent-yellow);
    font-size: 22px;
}

.credits-text {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.credits-amount {
    font-weight: 500;
    line-height: 1.3;
}

.credits-amount strong {
    color: var(--accent-yellow);
    font-weight: 600;
    font-size: 16px;
}

.credits-info {
    color: var(--text-tertiary);
    font-size: 12px;
    line-height: 1.2;
}

/* Rating Modal Styles */
#ratingModal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background-color: rgba(0, 0, 0, 0.5) !important;
    display: none !important;
    justify-content: center !important;
    align-items: center !important;
    z-index: 1050 !important;
    padding: 1rem !important;
}

#ratingModal .modal-overlay {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: rgba(0, 0, 0, 0.5) !important;
}

#ratingModal .modal-content {
    position: relative !important;
    background: var(--bg-elevated) !important;
    border-radius: 12px !important;
    padding: 20px !important;
    max-width: 500px !important;
    width: 100% !important;
    margin: auto !important;
    z-index: 1051 !important;
    transform: translateY(0) !important;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3) !important;
}

#ratingModal.show {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
}

#ratingModal h2 {
    color: var(--text-primary) !important;
    margin-bottom: 20px !important;
    font-size: 24px !important;
    font-weight: 600 !important;
}

#ratingModal .modal-close {
    position: absolute !important;
    right: 15px !important;
    top: 15px !important;
    background: transparent !important;
    border: none !important;
    color: var(--text-secondary) !important;
    cursor: pointer !important;
    padding: 10px !important;
    transition: color 0.2s ease !important;
    font-size: 24px !important;  /* Increased font size */
    width: 44px !important;      /* Increased button width */
    height: 44px !important;     /* Increased button height */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    z-index: 1060 !important;
}

#ratingModal .modal-close:hover {
    color: var(--text-primary) !important;
    background: rgba(255, 255, 255, 0.1) !important;
}
