/* ==========================================================================
   Tafsir picker for the reader.
   Always visible, fixed height, scrolls inside itself. Selection is shown by
   the row's own styling — no checkbox column.
   Loaded AFTER reader.css so it wins.
   ========================================================================== */

.inline-library {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    margin-bottom: var(--space-md);
}

.lib-panel {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    overflow: hidden;
}

/* ---------- header: search + category filters ---------- */
.lib-panel-head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 0.8rem;
    flex-wrap: wrap;
}

.lib-search {
    position: relative;
    flex: 1 1 240px;
    min-width: 200px;
}

.lib-search input {
    width: 100%;
    height: 38px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 0 0.8rem 0 2.2rem;
    font-family: var(--font-body);
    font-size: 0.92rem;
}

.lib-search input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.lib-search svg {
    position: absolute;
    left: 0.7rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.5;
}

.lib-count {
    font-family: var(--font-mono);
    font-size: 0.66rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    white-space: nowrap;
    padding-right: 0.2rem;
}

.lib-count b {
    color: var(--accent-primary);
    font-weight: 400;
}

.lib-cats {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    padding: 0 0.8rem 0.7rem;
    border-bottom: 1px solid var(--border-subtle);
}

.lib-cat {
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    border-radius: 999px;
    padding: 0.28rem 0.7rem;
    font-family: inherit;
    font-size: 0.76rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.lib-cat:hover {
    border-color: var(--border-active);
    color: var(--text-primary);
}

.lib-cat.on {
    background: var(--accent-glow);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.lib-cat .n {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    opacity: 0.6;
    margin-left: 0.25rem;
}

/* ---------- the list: fixed height, scrolls internally ---------- */
.lib-list {
    height: clamp(240px, 34vh, 360px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 0.8rem 0.8rem;
}

.lib-group-title {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-elevated);
    font-family: var(--font-mono);
    font-size: 0.6rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0.7rem 0 0.3rem;
    margin-bottom: 0.25rem;
    border-bottom: 1px solid var(--border-subtle);
}

.lib-group-items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 0.2rem 0.5rem;
    margin-bottom: 0.3rem;
}

/* one commentary — selection reads off the row itself */
.lib-opt {
    display: block;
    padding: 0.45rem 0.7rem;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.88rem;
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
    width: 100%;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.lib-opt:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.lib-opt.on {
    background: rgba(212, 168, 83, 0.12);
    border-color: var(--accent-primary);
    color: var(--text-gold);
}

.lib-opt.on:hover {
    background: rgba(212, 168, 83, 0.18);
    color: var(--text-gold);
}

.lib-opt .tafsir-name-ar {
    font-family: 'Noto Naskh Arabic', serif;
    opacity: 0.75;
    margin-right: 0.25rem;
}

.lib-opt.on .tafsir-name-ar {
    opacity: 0.9;
}

.lib-opt.is-coming-soon {
    opacity: 0.4;
    cursor: default;
}

.lib-opt.is-coming-soon:hover {
    background: transparent;
    color: var(--text-secondary);
}

.lib-opt .soon {
    font-family: var(--font-mono);
    font-size: 0.56rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-primary);
    opacity: 0.8;
    margin-left: 0.35rem;
}

.lib-empty {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    padding: 2.5rem 1rem;
}

@media (max-width: 768px) {
    .lib-group-items {
        grid-template-columns: 1fr;
    }

    /* Shorter list: the picker shouldn't own half the phone screen */
    .lib-list {
        height: clamp(200px, 32vh, 280px);
        padding: 0 0.7rem 0.7rem;
    }

    .lib-count {
        width: 100%;
        padding-top: 0.1rem;
    }

    /* Touch targets: 35px rows and 25px chips were too small to hit reliably */
    .lib-opt {
        padding: 0.7rem 0.75rem;
        font-size: 0.92rem;
    }

    .lib-search input {
        height: 44px;
        font-size: 16px; /* iOS zooms the page on focus for anything under 16px */
    }

    /* One scrollable row instead of four wrapped ones (was eating 129px) */
    .lib-cats {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding: 0 0.7rem 0.7rem;
        scroll-padding-left: 0.7rem;
    }

    .lib-cats::-webkit-scrollbar {
        display: none;
    }

    .lib-cat {
        flex: 0 0 auto;
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }

    .lib-panel-head {
        padding: 0.7rem;
        gap: 0.5rem;
    }

    /* .section is var(--space-xl) = 8rem, so the reader opened with 128px of
       empty space above the verse on a phone. */
    main.container.section {
        padding-top: 1.25rem;
        padding-bottom: 2.5rem;
    }
}
