/* ============================================
   Library Page — Netflix-style Layout
   ============================================ */

.library-page {
    padding-top: 100px;
    min-height: 100vh;
    background: var(--bg-primary);
}

/* Hero */
.library-hero {
    text-align: center;
    padding: 2rem 1rem 1rem;
}

.library-hero-title {
    font-size: clamp(1.8rem, 4vw, 2.8rem);
    font-weight: 800;
    color: var(--text-primary);
    margin: 0 0 0.4rem;
    line-height: 1.2;
}

.library-hero-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto 1.2rem;
    line-height: 1.5;
}

/* Search Bar */
.library-search-bar {
    max-width: 580px;
    margin: 0 auto 1rem;
    position: relative;
}

.library-search-bar input {
    width: 100%;
    padding: 12px 18px 12px 44px;
    font-size: 0.95rem;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.library-search-bar input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.15);
}

.library-search-bar .search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

[dir="rtl"] .library-search-bar .search-icon { left: auto; right: 16px; }
[dir="rtl"] .library-search-bar input { padding: 14px 48px 14px 20px; }

/* ============================================
   Filter Row
   ============================================ */
.library-filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: center;
    padding: 0 1rem 1rem;
    max-width: 800px;
    margin: 0 auto;
}

.filter-dropdown { position: relative; }

.filter-dropdown-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-width: 140px;
}

.filter-dropdown-btn:hover { border-color: var(--color-primary); color: var(--color-primary); }
.filter-dropdown.open .filter-dropdown-btn {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.12);
}

.filter-dropdown-icon { flex-shrink: 0; color: var(--text-muted); }
.filter-dropdown-btn:hover .filter-dropdown-icon { color: var(--color-primary); }
.filter-dropdown-label { flex: 1; text-align: left; }
[dir="rtl"] .filter-dropdown-label { text-align: right; }
.filter-dropdown-arrow { flex-shrink: 0; color: var(--text-muted); transition: transform 0.2s; }
.filter-dropdown.open .filter-dropdown-arrow { transform: rotate(180deg); }

.filter-dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    z-index: 100;
    padding: 6px;
    display: none;
    animation: filterDropFade 0.15s ease;
}

[dir="rtl"] .filter-dropdown-menu { left: auto; right: 0; }
.filter-dropdown.open .filter-dropdown-menu { display: block; }

@keyframes filterDropFade {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.filter-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 14px;
    font-size: 0.86rem;
    font-weight: 500;
    font-family: inherit;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    text-align: left;
}

[dir="rtl"] .filter-dropdown-item { text-align: right; }
.filter-dropdown-item:hover { background: rgba(var(--color-primary-rgb), 0.08); }
.filter-dropdown-item.active { background: rgba(var(--color-primary-rgb), 0.12); color: var(--color-primary); font-weight: 600; }
.filter-dropdown-flag { display: inline-flex; line-height: 1; }
.filter-dropdown-flag svg { border-radius: 2px; display: block; }

.library-filter-select {
    padding: 10px 16px;
    font-size: 0.88rem;
    font-weight: 600;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    min-width: 150px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.library-filter-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.12);
}

/* ============================================
   Netflix-style Section Rows
   ============================================ */
.library-browse {
    max-width: 1300px;
    margin: 0 auto;
    padding: 0 0 4rem;
}

.library-section {
    margin-bottom: 1.5rem;
}

.library-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem 0.5rem;
}

.library-section-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.library-show-more {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    font-size: 0.82rem;
    font-weight: 600;
    font-family: inherit;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    background: transparent;
    color: var(--color-primary);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.library-show-more:hover {
    background: rgba(var(--color-primary-rgb), 0.08);
    border-color: var(--color-primary);
}

/* Row container with arrows */
.library-row {
    position: relative;
    display: flex;
    align-items: center;
}

.library-row-track {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    scroll-behavior: smooth;
    padding: 4px 2rem 8px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    flex: 1;
}

.library-row-track::-webkit-scrollbar { display: none; }

.library-row-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    opacity: 0;
}

.library-row:hover .library-row-arrow { opacity: 1; }
.library-row-arrow:hover { background: var(--color-primary); color: white; }
.library-row-arrow--left { left: 6px; }
.library-row-arrow--right { right: 6px; }
[dir="rtl"] .library-row-arrow--left { left: auto; right: 6px; }
[dir="rtl"] .library-row-arrow--right { right: auto; left: 6px; }

/* ============================================
   Book Card (Netflix tile)
   ============================================ */
.library-row-item {
    flex: 0 0 auto;
}

.lib-card {
    width: 180px;
    height: 100%;
}

.lib-card-link {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.lib-card-cover {
    position: relative;
    width: 180px;
    height: 270px;
    border-radius: 10px;
    overflow: hidden;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    transition: transform 0.25s, box-shadow 0.25s;
}

.lib-card:hover .lib-card-cover {
    transform: translateY(-6px) scale(1.03);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}

.lib-card-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.lib-card-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    text-align: center;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Hover overlay */
.lib-card-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.25s;
}

.lib-card:hover .lib-card-overlay { opacity: 1; }

.lib-card-read-btn {
    padding: 8px 20px;
    font-size: 0.82rem;
    font-weight: 600;
    color: white;
    background: var(--color-primary);
    border-radius: 8px;
    transition: background 0.2s;
}

.lib-card:hover .lib-card-read-btn:hover {
    background: var(--color-primary-dark, #1d4ed8);
}

/* Card info */
.lib-card-info {
    padding: 10px 2px 0;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.lib-card-link {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.lib-card-bottom {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.lib-card-genre {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-primary);
    opacity: 0.8;
}

.lib-card-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 2px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.lib-card-author {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 0 0 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lib-card-price {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--color-primary);
}

.lib-card-free {
    font-size: 0.78rem;
    font-weight: 700;
    color: #10b981;
}

/* ============================================
   Search Results Grid (flat grid when searching)
   ============================================ */
.library-search-results {
    max-width: 1300px;
    margin: 0 auto;
    padding: 0 2rem 4rem;
}

.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1.5rem;
}

.library-grid .lib-card { width: 100%; }
.library-grid .lib-card-cover { width: 100%; height: auto; aspect-ratio: 2/3; }

/* ============================================
   Dark mode
   ============================================ */
[data-theme="dark"] .library-row-arrow {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .lib-card-cover {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .lib-card:hover .lib-card-cover {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .filter-dropdown-menu {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* ============================================
   View Toggle (in filter row)
   ============================================ */
.library-view-toggle {
    display: flex;
    gap: 4px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 3px;
    margin-left: auto;
}

[dir="rtl"] .library-view-toggle { margin-left: 0; margin-right: auto; }

.library-view-btn {
    padding: 7px 14px;
    font-size: 0.82rem;
    font-weight: 600;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 9px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: inherit;
    white-space: nowrap;
}

.library-view-btn.active {
    background: var(--color-primary);
    color: white;
}

/* ============================================
   List View
   ============================================ */
.library-list-view {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 1rem 4rem;
}

.library-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0 1.5rem;
}

.library-results-count {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.library-sort-select {
    min-width: 130px;
    padding: 8px 12px;
    font-size: 0.84rem;
    font-weight: 500;
    border-width: 1px;
    border-radius: 10px;
}

.library-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.lib-list-item {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s, box-shadow 0.2s;
}

.lib-list-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.lib-list-cover {
    width: 90px;
    min-width: 90px;
    height: 135px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-primary);
}

.lib-list-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.lib-list-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.lib-list-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 4px;
    line-height: 1.3;
}

.lib-list-author {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0 0 6px;
}

.lib-list-desc {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin: 0 0 8px;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.lib-list-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
}

.lib-list-meta-left {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
    min-width: 0;
}

.lib-list-meta-right {
    flex-shrink: 0;
    margin-inline-start: auto;
}

.lib-list-format {
    font-size: 0.7rem;
    padding: 2px 7px;
    border-radius: 5px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-weight: 500;
}

.lib-list-tag {
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 6px;
    background: rgba(var(--color-primary-rgb), 0.08);
    color: var(--color-primary);
    font-weight: 600;
}

[data-theme="dark"] .lib-list-item:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* ============================================
   Mobile Responsive
   ============================================ */
@media (max-width: 600px) {
    .library-page { padding-top: 80px; }
    .library-hero { padding: 2rem 1rem 1.5rem; }

    .library-filter-row {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .filter-dropdown-btn { width: 100%; min-width: auto; }
    .library-filter-select { min-width: 100%; }
    .library-view-toggle { margin-left: 0; width: 100%; justify-content: center; }

    .library-section-header { padding: 0 1rem 0.75rem; }
    .library-row-track { padding: 8px 1rem 12px; gap: 12px; }
    .library-row-arrow { display: none; }

    .lib-card { width: 140px; }
    .lib-card-cover { width: 140px; height: 210px; }

    .library-search-results { padding: 0 1rem 4rem; }
    .library-grid { grid-template-columns: repeat(2, 1fr); gap: 1rem; }

    .lib-list-cover { width: 70px; min-width: 70px; height: 105px; }
    .lib-list-desc { display: none; }
    .library-toolbar { flex-direction: column; gap: 8px; align-items: flex-start; }
}

@media (min-width: 601px) and (max-width: 900px) {
    .lib-card { width: 160px; }
    .lib-card-cover { width: 160px; height: 240px; }
}
