/**
 * Public Library Styles
 * 
 * Clean, modern design for the public-facing book catalog
 */

/* ==========================================================================
   CSS Variables
   ========================================================================== */
:root {
    --pl-primary: #f7931a;
    --pl-primary-dark: #e6820a;
    --pl-secondary: #2c3e50;
    --pl-accent: #3498db;
    --pl-success: #27ae60;
    --pl-warning: #f39c12;
    --pl-danger: #e74c3c;
    --pl-light: #f8f9fa;
    --pl-dark: #1a1a2e;
    --pl-gray: #6c757d;
    --pl-border: #dee2e6;
    --pl-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --pl-radius: 8px;
    --pl-transition: all 0.2s ease;
}

/* ==========================================================================
   Base Layout
   ========================================================================== */
.public-library {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--pl-light);
    color: var(--pl-dark);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.library-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* ==========================================================================
   Navigation
   ========================================================================== */
.public-nav {
    background: var(--pl-dark);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--pl-shadow);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-logo {
    color: var(--pl-primary);
    font-size: 1.5rem;
    font-weight: bold;
    text-decoration: none;
}

.nav-links {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.nav-links a {
    color: #fff;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--pl-radius);
    transition: var(--pl-transition);
}

.nav-links a:hover,
.nav-links a.active {
    background: rgba(247, 147, 26, 0.2);
    color: var(--pl-primary);
}

.nav-cta {
    background: var(--pl-primary) !important;
    color: var(--pl-dark) !important;
    font-weight: 600;
}

.nav-cta:hover {
    background: var(--pl-primary-dark) !important;
}

/* ==========================================================================
   Flash Messages
   ========================================================================== */
.flash-messages {
    max-width: 1200px;
    margin: 1rem auto;
    padding: 0 1rem;
}

.flash-message {
    padding: 1rem;
    border-radius: var(--pl-radius);
    margin-bottom: 0.5rem;
}

.flash-error {
    background: #fce4e4;
    color: var(--pl-danger);
    border: 1px solid var(--pl-danger);
}

.flash-success {
    background: #e4fce4;
    color: var(--pl-success);
    border: 1px solid var(--pl-success);
}

.flash-info {
    background: #e4f0fc;
    color: var(--pl-accent);
    border: 1px solid var(--pl-accent);
}

/* ==========================================================================
   Main Content
   ========================================================================== */
.public-main {
    flex: 1;
    padding: 2rem 0;
}

/* ==========================================================================
   Hero Section
   ========================================================================== */
.library-hero {
    text-align: center;
    padding: 3rem 2rem;
    background: linear-gradient(135deg, var(--pl-dark), var(--pl-secondary));
    color: #fff;
    border-radius: var(--pl-radius);
    margin-bottom: 2rem;
}

.library-hero h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.library-hero p {
    font-size: 1.2rem;
    opacity: 0.9;
    margin-bottom: 2rem;
}

.hero-stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
}

.hero-stats .stat {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--pl-primary);
}

.stat-label {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* ==========================================================================
   Page Header
   ========================================================================== */
.page-header {
    text-align: center;
    padding: 2rem;
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.page-header p {
    color: var(--pl-gray);
}

/* ==========================================================================
   Filters & Search
   ========================================================================== */
.library-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding: 1rem;
    background: #fff;
    border-radius: var(--pl-radius);
    box-shadow: var(--pl-shadow);
}

.search-box {
    display: flex;
    flex: 1;
    min-width: 200px;
    max-width: 400px;
}

.search-box input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--pl-border);
    border-radius: var(--pl-radius) 0 0 var(--pl-radius);
    font-size: 1rem;
}

.search-box input:focus {
    outline: none;
    border-color: var(--pl-primary);
}

.search-box button {
    padding: 0.75rem 1rem;
    background: var(--pl-primary);
    border: none;
    border-radius: 0 var(--pl-radius) var(--pl-radius) 0;
    cursor: pointer;
    font-size: 1rem;
}

.search-box button:hover {
    background: var(--pl-primary-dark);
}

.sort-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sort-controls label {
    color: var(--pl-gray);
}

.sort-controls select {
    padding: 0.75rem 1rem;
    border: 1px solid var(--pl-border);
    border-radius: var(--pl-radius);
    font-size: 1rem;
    background: #fff;
    cursor: pointer;
}

/* ==========================================================================
   Books Grid
   ========================================================================== */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.book-card {
    background: #fff;
    border-radius: var(--pl-radius);
    box-shadow: var(--pl-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: var(--pl-transition);
}

.book-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.book-cover {
    width: 100%;
    height: 200px;
    background: linear-gradient(135deg, var(--primary-color), #e6840f);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    position: relative;
    overflow: hidden;
}

.book-cover-placeholder {
    font-size: 3rem;
    opacity: 0.5;
}

/* Ensure cover images fill the card area similarly to PWA (edge-cropping allowed to preserve layout)
   - Use absolute positioning and object-fit: cover to match PWA behavior */
.book-cover .book-cover-img,
.book-cover img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    position: absolute;
    top: 0;
    left: 0;
}

.book-info {
    padding: 1rem;
    flex: 1;
}

.book-title {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
    color: var(--pl-dark);
}

.book-author {
    color: var(--pl-gray);
    margin-bottom: 0.75rem;
}

.book-author a {
    color: var(--pl-accent);
    text-decoration: none;
}

.book-author a:hover {
    text-decoration: underline;
}

.book-blurb {
    font-size: 0.9rem;
    color: var(--pl-gray);
    margin-bottom: 0.75rem;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-blurb-section {
    margin: 1.5rem 0;
    padding: 1rem;
    background: var(--pl-light);
    border-radius: var(--pl-radius);
}

.book-blurb-section h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--pl-secondary);
}

.book-blurb-full {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--pl-dark);
}

.book-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--pl-gray);
}

.book-available.in-stock {
    color: var(--pl-success);
}

.book-available.out-of-stock {
    color: var(--pl-danger);
}

.book-actions {
    padding: 1rem;
    display: flex;
    gap: 0.5rem;
    border-top: 1px solid var(--pl-border);
}

.book-actions .btn {
    flex: 1;
    text-align: center;
}

/* ==========================================================================
   Authors Grid
   ========================================================================== */
.authors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.author-card {
    background: #fff;
    border-radius: var(--pl-radius);
    box-shadow: var(--pl-shadow);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    transition: var(--pl-transition);
}

.author-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.author-avatar-large {
    width: 80px;
    height: 80px;
    background: var(--pl-secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    margin: 0 auto;
    overflow: hidden;
}

.author-avatar-large .author-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.author-info {
    text-align: center;
    flex: 1;
}

.author-name {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.author-name a {
    color: var(--pl-dark);
    text-decoration: none;
}

.author-name a:hover {
    color: var(--pl-primary);
}

.author-stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--pl-gray);
    margin-bottom: 0.5rem;
}

.author-stats .available {
    color: var(--pl-success);
}

.author-bio {
    font-size: 0.9rem;
    color: var(--pl-gray);
    line-height: 1.5;
}

.author-actions {
    display: flex;
    gap: 0.5rem;
}

.author-actions .btn {
    flex: 1;
    text-align: center;
}

/* ==========================================================================
   Author Profile
   ========================================================================== */
.author-profile-header {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
    padding: 2rem;
    background: #fff;
    border-radius: var(--pl-radius);
    box-shadow: var(--pl-shadow);
    margin-bottom: 2rem;
}

.author-avatar-xl {
    width: 150px;
    height: 150px;
    background: var(--pl-secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    flex-shrink: 0;
    overflow: hidden;
}

.author-avatar-xl .author-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
}

.author-profile-info {
    flex: 1;
}

.author-profile-info h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.author-profile-stats {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
    color: var(--pl-gray);
}

.author-profile-bio {
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.author-profile-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.author-books h2 {
    margin-bottom: 1.5rem;
}

/* ==========================================================================
   Book Details
   ========================================================================== */
.book-detail {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 2rem;
    padding: 2rem;
    background: #fff;
    border-radius: var(--pl-radius);
    box-shadow: var(--pl-shadow);
    margin-bottom: 2rem;
}

.book-cover-large {
    height: 400px;
    background: linear-gradient(135deg, var(--pl-secondary), var(--pl-dark));
    border-radius: var(--pl-radius);
    display: flex;
    align-items: center;
    justify-content: center;
}

.book-cover-placeholder-large {
    font-size: 6rem;
    opacity: 0.5;
}

.book-detail-info h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.book-detail-author {
    font-size: 1.2rem;
    color: var(--pl-gray);
    margin-bottom: 1.5rem;
}

.book-detail-author a {
    color: var(--pl-accent);
    text-decoration: none;
}

.book-detail-author a:hover {
    text-decoration: underline;
}

.book-detail-meta {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.meta-item {
    padding: 1rem;
    background: var(--pl-light);
    border-radius: var(--pl-radius);
}

.meta-label {
    display: block;
    font-size: 0.85rem;
    color: var(--pl-gray);
    margin-bottom: 0.25rem;
}

.meta-value {
    font-size: 1.1rem;
    font-weight: 600;
}

.meta-value.in-stock {
    color: var(--pl-success);
}

.meta-value.out-of-stock {
    color: var(--pl-danger);
}

.status-badge-large {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border-radius: var(--pl-radius);
    font-weight: 600;
    margin-bottom: 1.5rem;
}

.status-badge-large.available {
    background: #e4fce4;
    color: var(--pl-success);
}

.status-badge-large.out-of-stock {
    background: #fce4e4;
    color: var(--pl-danger);
}

.book-detail-actions {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.how-it-works {
    padding: 1.5rem;
    background: var(--pl-light);
    border-radius: var(--pl-radius);
}

.how-it-works h3 {
    margin-bottom: 1rem;
}

.how-it-works ol {
    margin: 0;
    padding-left: 1.5rem;
}

.how-it-works li {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

/* ==========================================================================
   Author Section in Book Details
   ========================================================================== */
.book-author-section {
    background: #fff;
    border-radius: var(--pl-radius);
    box-shadow: var(--pl-shadow);
    padding: 2rem;
    margin-bottom: 2rem;
}

.book-author-section h2 {
    margin-bottom: 1.5rem;
}

.author-mini-card {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.author-avatar-medium {
    width: 80px;
    height: 80px;
    background: var(--pl-secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    flex-shrink: 0;
    overflow: hidden;
}

.author-avatar-medium .author-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.author-mini-info {
    flex: 1;
}

.author-mini-info h3 {
    margin-bottom: 0.5rem;
}

.author-mini-info p {
    color: var(--pl-gray);
    line-height: 1.5;
    margin-bottom: 0.5rem;
}

.author-mini-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.9rem;
    color: var(--pl-gray);
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border-radius: var(--pl-radius);
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: var(--pl-transition);
    font-size: 1rem;
}

.btn-primary {
    background: var(--pl-primary);
    color: var(--pl-dark);
}

.btn-primary:hover {
    background: var(--pl-primary-dark);
}

.btn-secondary {
    background: var(--pl-light);
    color: var(--pl-dark);
    border: 1px solid var(--pl-border);
}

.btn-secondary:hover {
    background: var(--pl-border);
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
}

.btn-disabled {
    background: var(--pl-gray);
    color: #fff;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Out of Stock button */
.out-of-stock-btn {
    background: var(--pl-danger) !important;
    opacity: 0.7;
}

/* Owned book state */
.btn.owned {
    background: var(--pl-success) !important;
    color: #fff;
    cursor: default;
    pointer-events: none;
}

/* Subscribed state */
.btn.subscribed {
    background: var(--pl-success);
    color: #fff;
}

.btn.subscribed:hover {
    background: #2d9b53;
}

/* Subscribe button transition */
.subscribe-btn,
.claim-btn {
    transition: all 0.3s ease;
}

/* ==========================================================================
   Status Badges
   ========================================================================== */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-badge.available {
    background: #e4fce4;
    color: var(--pl-success);
}

.status-badge.out-of-stock {
    background: #fce4e4;
    color: var(--pl-danger);
}

/* ==========================================================================
   Pagination
   ========================================================================== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 2rem 0;
}

.page-link {
    padding: 0.75rem 1.5rem;
    background: #fff;
    border: 1px solid var(--pl-border);
    border-radius: var(--pl-radius);
    text-decoration: none;
    color: var(--pl-dark);
    transition: var(--pl-transition);
}

.page-link:hover {
    background: var(--pl-primary);
    border-color: var(--pl-primary);
    color: var(--pl-dark);
}

.page-info {
    color: var(--pl-gray);
}

/* ==========================================================================
   Featured Authors
   ========================================================================== */
.featured-authors {
    margin: 2rem 0;
}

.featured-authors h2 {
    margin-bottom: 1rem;
}

.authors-row {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    padding: 0.5rem 0;
}

.featured-author {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    background: #fff;
    border-radius: var(--pl-radius);
    box-shadow: var(--pl-shadow);
    text-decoration: none;
    color: var(--pl-dark);
    min-width: 150px;
    transition: var(--pl-transition);
}

.featured-author:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.featured-author .author-avatar {
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.featured-author .author-avatar .author-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.featured-author .author-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.featured-author .author-books {
    font-size: 0.8rem;
    color: var(--pl-gray);
}

/* ==========================================================================
   CTA Section
   ========================================================================== */
.library-cta {
    text-align: center;
    padding: 3rem 2rem;
    background: linear-gradient(135deg, var(--pl-dark), var(--pl-secondary));
    color: #fff;
    border-radius: var(--pl-radius);
    margin: 2rem 0;
}

.library-cta h2 {
    margin-bottom: 0.5rem;
}

.library-cta p {
    margin-bottom: 1.5rem;
    opacity: 0.9;
}

/* ==========================================================================
   Empty State
   ========================================================================== */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    background: #fff;
    border-radius: var(--pl-radius);
    box-shadow: var(--pl-shadow);
    grid-column: 1 / -1;
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--pl-gray);
}

/* ==========================================================================
   Back Link
   ========================================================================== */
.back-link {
    padding: 1rem 0;
}

.back-link a {
    color: var(--pl-accent);
    text-decoration: none;
}

.back-link a:hover {
    text-decoration: underline;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.public-footer {
    background: var(--pl-dark);
    color: #fff;
    padding: 2rem 0;
    margin-top: auto;
}

.footer-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    text-align: center;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 1rem;
}

.footer-links a {
    color: var(--pl-primary);
    text-decoration: none;
}

.footer-links a:hover {
    text-decoration: underline;
}

.footer-copyright {
    color: var(--pl-gray);
    font-size: 0.9rem;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */
@media (max-width: 768px) {
    .nav-container {
        flex-direction: column;
        gap: 1rem;
    }
    
    .nav-links {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .library-hero h1 {
        font-size: 1.75rem;
    }
    
    .hero-stats {
        flex-direction: column;
        gap: 1rem;
    }
    
    .library-filters {
        flex-direction: column;
    }
    
    .search-box {
        max-width: 100%;
    }
    
    .books-grid,
    .authors-grid {
        grid-template-columns: 1fr;
    }
    
    .author-profile-header {
        flex-direction: column;
        text-align: center;
    }
    
    .author-profile-stats {
        justify-content: center;
    }
    
    .author-profile-actions {
        justify-content: center;
    }
    
    .book-detail {
        grid-template-columns: 1fr;
    }
    
    .book-cover-large {
        height: 250px;
    }
    
    .book-detail-meta {
        grid-template-columns: 1fr;
    }
    
    .author-mini-card {
        flex-direction: column;
        text-align: center;
    }
}
