/* ── Library Modal ─────────────────────────────────────────── */

.library-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.42);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 10200;
    display: none;
    align-items: center;
    justify-content: center;
}
.library-backdrop.visible { display: flex; }

.library-modal {
    width: 95vw;
    height: 92vh;
    background: var(--background, #FAF9F6);
    border-radius: 16px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.25), 0 0 0 1px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.library-modal .frosted-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    flex-shrink: 0;
}
.library-modal .frosted-header h3 { margin: 0; font-size: 1rem; font-weight: 600; }

/* ── Body ────────────────────────────────────────────────── */

.library-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Nav Rail (mirrors main Bible nav) ───────────────────── */

.library-nav-rail {
    width: var(--nav-rail-width, 110px);
    min-width: var(--nav-rail-width, 110px);
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border, #e2e8f0);
    background: var(--background, #FAF9F6);
    overflow-y: auto;
    padding: 0.25rem 0;
}

/* Reuse the main nav button styles */
.library-nav-rail .icon-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.85rem 0.5rem 0.7rem;
    margin: 2px 6px;
    width: calc(100% - 12px);
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary, #6B5D54);
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.library-nav-rail .icon-nav-btn:hover {
    background: var(--highlight, #f0f0ea);
    color: var(--text-primary, #2C2416);
}
.library-nav-rail .icon-nav-btn.active {
    background: linear-gradient(135deg, var(--primary, #5B4B8A) 0%, var(--primary-dark, #4A3B73) 100%);
    color: #fff;
}
.library-nav-rail .icon-nav-btn svg { width: 22px; height: 22px; }
.library-nav-rail .icon-nav-divider {
    width: 60%;
    height: 1px;
    background: var(--border, #e2e8f0);
    margin: 4px auto;
}

/* ── Content Area ────────────────────────────────────────── */

.library-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface, #fff);
}

.library-content-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem 1rem;
    border-bottom: 1px solid var(--border, #e2e8f0);
    flex-shrink: 0;
    gap: 0.5rem;
}

.library-nav-btn {
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 6px;
    background: var(--surface, #fff);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
}
.library-nav-btn:hover { background: var(--highlight, #f0f0ea); }
.library-nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.library-ref-display {
    display: inline-flex;
    align-items: baseline;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 8px;
    font-family: 'Crimson Text', Georgia, serif;
    font-size: 1rem;
}
.library-ref-segment {
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}
.library-ref-segment:hover {
    color: var(--primary, #5B4B8A);
    background: rgba(91, 75, 138, 0.07);
}
.library-ref-dot {
    color: var(--text-secondary);
    padding: 0 0.15rem;
    font-size: 0.8rem;
}

/* ── Reading Area (paragraph cards go here) ──────────────── */

.library-reading-area {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem 1.25rem;
}

/* ── Sidebar (opens from nav rail buttons) ───────────────── */

.library-sidebar {
    width: 0;
    overflow: hidden;
    border-left: none;
    background: var(--surface, #fff);
    transition: width 0.25s ease;
}
.library-sidebar.open {
    width: 380px;
    border-left: 1px solid var(--border, #e2e8f0);
    overflow-y: auto;
}

/* ── Chapter Picker Button (title-driven) ────── */

.lp-chapter-btn {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    padding: 0.5rem 0.6rem;
    min-height: 52px;
}
.lp-ch-title {
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.lp-chapter-btn.current .lp-ch-title {
    color: rgba(255,255,255,0.9);
}

/* ── Paragraph Card ──────────────────────────────────────── */

.library-paragraph-card {
    display: flex;
    gap: 0.5rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border-light, rgba(0,0,0,0.06));
}
.library-paragraph-card:last-child { border-bottom: none; }

.library-para-num {
    min-width: 28px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-secondary, #6B5D54);
    text-align: right;
    padding-top: 0.3rem;
    user-select: none;
}

.library-para-body {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.library-para-content {
    font-family: 'Crimson Text', Georgia, serif;
    font-size: 1.05rem;
    line-height: 1.7;
    color: var(--text-primary, #2C2416);
}

.library-para-actions {
    display: flex;
    gap: 0.3rem;
    margin-top: 0.35rem;
    justify-content: flex-end;
    opacity: 0;
    transition: opacity 0.15s;
}

.library-paragraph-card:hover .library-para-actions {
    opacity: 1;
}

/* ── Empty State ─────────────────────────────────────────── */

.library-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    text-align: center;
    padding: 2rem;
}
.library-empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.library-empty-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.5rem; color: var(--text-primary); }
.library-empty-text { font-size: 0.85rem; max-width: 300px; line-height: 1.5; }

/* ── Mobile ──────────────────────────────────────────────── */

@media (max-width: 768px) {
    .library-modal { width: 100vw; height: 100vh; height: 100dvh; border-radius: 0; }

    /* Body stacks: content on top, nav at bottom */
    .library-body { flex-direction: column; }

    /* Nav rail → horizontal bottom bar */
    .library-nav-rail {
        width: 100%;
        min-width: unset;
        flex-direction: row;
        border-left: none;
        border-top: 1px solid var(--border, #e2e8f0);
        order: 2;
        flex-shrink: 0;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 0;
    }
    .library-nav-rail .icon-nav-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 0.4rem 0.6rem;
        margin: 2px;
    }
    .library-nav-rail .icon-nav-btn .icon-nav-label { display: none; }
    .library-nav-rail .icon-nav-divider {
        width: 1px;
        height: 60%;
        align-self: center;
        margin: 0 2px;
    }

    /* Content area fills above bottom bar */
    .library-content { order: 1; flex: 1; min-height: 0; }

    /* Compact top nav — single line, tappable */
    .library-content-nav {
        padding: 0.3rem 0.5rem;
        gap: 0.3rem;
    }
    .library-content-nav.collapsed .library-ref-display {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        max-width: 100%;
        font-size: 0.85rem;
    }
    .library-content-nav.collapsed .library-ref-dot { display: none; }
    .library-content-nav.collapsed .library-nav-btn { display: none; }

    .library-reading-area { padding: 0.75rem; }

    /* Sidebar → fixed slide-over with backdrop */
    .library-sidebar {
        position: fixed;
        top: 0;
        right: 0;
        height: 100vh;
        height: 100dvh;
        z-index: 10250;
        transform: translateX(100%);
        transition: transform 0.25s ease;
        background: var(--background, #FAF9F6);
    }
    .library-sidebar.open {
        width: 85vw;
        max-width: 400px;
        transform: translateX(0);
        box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    }

    /* Backdrop behind sidebar */
    .library-sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.3);
        z-index: 10249;
    }
    .library-sidebar-backdrop.visible { display: block; }
}

/* ─── Library Tag Refs (sidebar tag panel) ─── */
.tag-library-ref {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.78rem;
    color: var(--text-primary);
    transition: background 0.12s;
}
.tag-library-ref:hover {
    background: var(--highlight);
    color: var(--primary);
}
.tag-library-unassign {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-secondary);
    opacity: 0;
    padding: 0 2px;
    line-height: 1;
    margin-left: auto;
    flex-shrink: 0;
}
.tag-library-ref:hover .tag-library-unassign {
    opacity: 1;
}
.tag-library-unassign:hover {
    color: #E57373;
}

/* Tag dots — mirrors .commentary-tag-dots / .commentary-tag-dot */
.library-tag-dots {
    display: flex;
    gap: 3px;
    align-items: center;
}
.library-tag-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

/* Send-to-Study button flash feedback */
.library-para-send-study.library-feedback-flash {
    background: #4caf50 !important;
    color: #fff !important;
    border-color: #43a047 !important;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}
