/*
 * BIP Library, Finder & Scholar: shared sidebar brand header + collapsible side panels
 * (Library "Bookmarks & lists" / "Filters", Finder "Filters", Scholar "Template" / "Sections",
 * Admin › Profile Templates "Categories" / "Filters").
 * State classes live on <html> (set by js/library-sidebar-toggle.js):
 *   .lib-collapse-lists, .lib-collapse-filters, .lib-collapse-template, .lib-collapse-sections,
 *   .lib-collapse-categories
 */

/* ---------- Shared sidebar brand (logo + service name + tagline) ---------- */
.finder-sidebar-brand {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 0 0 12px;
    padding: 0 2px;
    text-align: left;
    width: 100%;
}

.finder-sidebar-brand #bip-logo-flame {
    flex: 0 0 auto;
    width: 64px !important;
    max-width: 40%;
    margin: 0 !important;
}

.finder-sidebar-brand .finder-brand-logo-img {
    display: block;
    max-height: 36px;
    max-width: 100%;
    width: auto;
    height: auto;
    margin: 0;
}

.finder-sidebar-quote {
    margin: 0;
    padding: 0;
    font-size: 11px;
    line-height: 1.25;
    text-align: left;
    max-width: 100%;
    flex: 1 1 auto;
    min-width: 0;
}

.finder-sidebar-quote-lead,
.finder-sidebar-quote-emphasis {
    display: block;
}

.finder-sidebar-quote-emphasis {
    font-size: 1.45em;
    font-weight: 700;
    line-height: 1.15;
}

/* ---------- Toggle header (shared by Library, Finder and Scholar panels) ---------- */
:is(#readings, #finder, #scholar-profile, #admin-templates) .library-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

#readings #toc-panel .library-panel-header {
    padding: 0 2px 12px;
    margin-bottom: 12px;
    border-bottom: 1px dashed #e2e8f0;
}

:is(#readings, #finder, #scholar-profile, #admin-templates) .library-panel-toggle {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 6px;
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.2px;
    color: #1e293b;
    text-align: left;
    cursor: pointer;
}

:is(#readings, #finder, #scholar-profile, #admin-templates) .library-panel-toggle:focus {
    outline: none;
}

:is(#readings, #finder, #scholar-profile, #admin-templates) .library-panel-toggle:focus-visible {
    outline: 2px solid var(--main-color, #278f89);
    outline-offset: 3px;
}

:is(#readings, #finder, #scholar-profile, #admin-templates) .facets-panel-title {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    display: flex;
    align-items: center;
}

:is(#readings, #finder, #scholar-profile, #admin-templates) .library-panel-icon {
    flex: 0 0 auto;
    font-size: 13px;
    color: var(--main-color, #278f89);
}

:is(#readings, #finder, #scholar-profile, #admin-templates) .library-panel-title {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Current list / "All bookmarks", only shown while the lists panel is collapsed */
:is(#readings, #finder, #scholar-profile, #admin-templates) .library-panel-context {
    display: none;
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    font-weight: 500;
    color: #64748b;
}

:is(#readings, #finder, #scholar-profile, #admin-templates) .library-panel-badge {
    flex: 0 0 auto;
    min-width: 18px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--main-color, #278f89);
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    line-height: 16px;
    height: 18px;
    text-align: center;
}

:is(#readings, #finder, #scholar-profile, #admin-templates) .library-panel-chevron {
    flex: 0 0 auto;
    margin-left: auto;
    font-size: 11px;
    color: #94a3b8;
    transition: transform 0.25s ease, color 0.15s ease;
}

:is(#readings, #finder, #scholar-profile, #admin-templates) .library-panel-toggle:hover .library-panel-chevron {
    color: var(--main-color, #278f89);
}

/* ---------- Collapsed states ---------- */
html.lib-collapse-lists #readings #toc-panel .sidebar-body,
html.lib-collapse-filters #readings #readings-facets-panel .library-panel-body,
html.lib-collapse-template #scholar-profile #scholar-template-panel .library-panel-body,
html.lib-collapse-sections #scholar-profile #scholar-sections-panel .library-panel-body,
html.lib-collapse-categories #admin-templates #admin-categories-panel .library-panel-body,
html.lib-collapse-filters #admin-templates #admin-filters-panel .library-panel-body {
    display: none !important;
}

html.lib-collapse-lists #readings #toc-panel .library-panel-chevron,
html.lib-collapse-filters #readings #readings-facets-panel .library-panel-chevron,
html.lib-collapse-template #scholar-profile #scholar-template-panel .library-panel-chevron,
html.lib-collapse-sections #scholar-profile #scholar-sections-panel .library-panel-chevron,
html.lib-collapse-categories #admin-templates #admin-categories-panel .library-panel-chevron,
html.lib-collapse-filters #admin-templates #admin-filters-panel .library-panel-chevron {
    transform: rotate(-90deg);
}

html.lib-collapse-lists #readings #toc-panel .library-panel-context,
html.lib-collapse-template #scholar-profile #scholar-template-panel .library-panel-context {
    display: block;
}

html.lib-collapse-lists #readings #toc-panel,
html.lib-collapse-filters #readings #readings-facets-panel,
html.lib-collapse-template #scholar-profile #scholar-template-panel,
html.lib-collapse-sections #scholar-profile #scholar-sections-panel,
html.lib-collapse-categories #admin-templates #admin-categories-panel,
html.lib-collapse-filters #admin-templates #admin-filters-panel {
    padding-top: 12px;
    padding-bottom: 12px;
}

html.lib-collapse-lists #readings #toc-panel .library-panel-header,
html.lib-collapse-filters #readings #readings-facets-panel .library-panel-header,
html.lib-collapse-template #scholar-profile #scholar-template-panel .library-panel-header,
html.lib-collapse-sections #scholar-profile #scholar-sections-panel .library-panel-header,
html.lib-collapse-categories #admin-templates #admin-categories-panel .library-panel-header,
html.lib-collapse-filters #admin-templates #admin-filters-panel .library-panel-header {
    padding-bottom: 0;
    margin-bottom: 0;
    border-bottom: none;
}

/* ---------- Mobile & tablet (< 992px): compact stack, panels side by side when collapsed ---------- */
@media (max-width: 991px) {
    #readings .readings-layout-row .readings-sidebar-col,
    #scholar-profile .scholar-layout-row .scholar-sidebar-col,
    #admin-templates .admin-layout-row .admin-sidebar-col {
        display: flex !important;
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 12px;
    }

    #readings .readings-layout-row .readings-sidebar-col .finder-sidebar-brand,
    #scholar-profile .scholar-layout-row .scholar-sidebar-col .finder-sidebar-brand {
        flex: 1 1 100%;
        width: 100%;
        justify-content: flex-start;
        margin-bottom: 2px;
    }

    .finder-sidebar-brand #bip-logo-flame {
        width: 56px !important;
    }

    .finder-sidebar-quote {
        text-align: left;
    }

    #readings .readings-layout-row .readings-sidebar-col .library-panel,
    #scholar-profile .scholar-layout-row .scholar-sidebar-col .library-panel,
    #admin-templates .admin-layout-row .admin-sidebar-col .library-panel {
        flex: 1 1 100%;
        min-width: 0;
        margin: 0;
    }

    html.lib-collapse-lists #readings .readings-layout-row .readings-sidebar-col #toc-panel,
    html.lib-collapse-filters #readings .readings-layout-row .readings-sidebar-col #readings-facets-panel,
    html.lib-collapse-template #scholar-profile .scholar-layout-row .scholar-sidebar-col #scholar-template-panel,
    html.lib-collapse-sections #scholar-profile .scholar-layout-row .scholar-sidebar-col #scholar-sections-panel,
    html.lib-collapse-categories #admin-templates .admin-layout-row .admin-sidebar-col #admin-categories-panel,
    html.lib-collapse-filters #admin-templates .admin-layout-row .admin-sidebar-col #admin-filters-panel {
        flex: 1 1 calc(50% - 4px);
    }

    :is(#readings, #scholar-profile, #admin-templates) .library-panel-toggle {
        padding: 4px 0;
    }
}

/* Not enough room for the list name next to the title on small phones */
@media (max-width: 575px) {
    :is(#readings, #scholar-profile, #admin-templates) .library-panel-context {
        display: none !important;
    }
}

/* ---------- Equal height for the collapsed bars ---------- */
:is(#readings, #scholar-profile, #admin-templates) .library-panel-header,
:is(#readings, #scholar-profile, #admin-templates) .library-panel-toggle {
    min-height: 24px;
}

@media (max-width: 991px) {
    /* Collapsed bars sharing a row get the same height regardless of their content */
    #readings .readings-layout-row .readings-sidebar-col,
    #scholar-profile .scholar-layout-row .scholar-sidebar-col,
    #admin-templates .admin-layout-row .admin-sidebar-col {
        align-items: stretch;
    }

    html.lib-collapse-lists #readings #toc-panel,
    html.lib-collapse-filters #readings #readings-facets-panel,
    html.lib-collapse-template #scholar-profile #scholar-template-panel,
    html.lib-collapse-sections #scholar-profile #scholar-sections-panel,
    html.lib-collapse-categories #admin-templates #admin-categories-panel,
    html.lib-collapse-filters #admin-templates #admin-filters-panel {
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
}

/* ---------- Collapsed bars: deterministic, identical height (mobile & tablet) ---------- */
@media (max-width: 991px) {
    html.lib-collapse-lists #readings .readings-layout-row .readings-sidebar-col #toc-panel,
    html.lib-collapse-filters #readings .readings-layout-row .readings-sidebar-col #readings-facets-panel,
    html.lib-collapse-template #scholar-profile .scholar-layout-row .scholar-sidebar-col #scholar-template-panel,
    html.lib-collapse-sections #scholar-profile .scholar-layout-row .scholar-sidebar-col #scholar-sections-panel,
    html.lib-collapse-categories #admin-templates .admin-layout-row .admin-sidebar-col #admin-categories-panel,
    html.lib-collapse-filters #admin-templates .admin-layout-row .admin-sidebar-col #admin-filters-panel {
        box-sizing: border-box !important;
        height: 52px !important;
        min-height: 52px !important;
        max-height: 52px !important;
        margin: 0 !important;
        padding: 0 14px !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: stretch !important;
    }

    html.lib-collapse-lists #readings #toc-panel .library-panel-header,
    html.lib-collapse-filters #readings #readings-facets-panel .library-panel-header,
    html.lib-collapse-template #scholar-profile #scholar-template-panel .library-panel-header,
    html.lib-collapse-sections #scholar-profile #scholar-sections-panel .library-panel-header,
    html.lib-collapse-categories #admin-templates #admin-categories-panel .library-panel-header,
    html.lib-collapse-filters #admin-templates #admin-filters-panel .library-panel-header {
        flex: 1 1 auto;
        min-width: 0;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        min-height: 0 !important;
    }

    html.lib-collapse-filters #readings #readings-facets-panel .facets-panel-title {
        margin: 0 !important;
        padding: 0 !important;
    }

    html.lib-collapse-lists #readings #toc-panel .library-panel-toggle,
    html.lib-collapse-filters #readings #readings-facets-panel .library-panel-toggle,
    html.lib-collapse-template #scholar-profile #scholar-template-panel .library-panel-toggle,
    html.lib-collapse-sections #scholar-profile #scholar-sections-panel .library-panel-toggle,
    html.lib-collapse-categories #admin-templates #admin-categories-panel .library-panel-toggle,
    html.lib-collapse-filters #admin-templates #admin-filters-panel .library-panel-toggle {
        min-height: 0;
        padding: 0;
    }

    /* The "Clear all" button would make the Filters bar taller than the other one */
    html.lib-collapse-filters #readings #readings-facets-panel .facets-clear-all-btn {
        display: none !important;
    }
}


/* ---------- Finder filters panel: collapsed state & layout ---------- */
html.lib-collapse-filters #finder #finder-facets-panel .library-panel-body {
    display: none !important;
}

html.lib-collapse-filters #finder #finder-facets-panel .library-panel-chevron {
    transform: rotate(-90deg);
}

html.lib-collapse-filters #finder #finder-facets-panel {
    padding-top: 12px;
    padding-bottom: 12px;
}

html.lib-collapse-filters #finder #finder-facets-panel .library-panel-header {
    padding-bottom: 0;
    margin-bottom: 0;
    border-bottom: none;
}

@media (max-width: 991px) {
    #finder .finder-layout-row .finder-sidebar-filters {
        display: flex !important;
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 12px;
    }

    #finder .finder-layout-row .finder-sidebar-filters .library-panel {
        flex: 1 1 100%;
        min-width: 0;
        margin: 0;
    }

    #finder .library-panel-toggle {
        padding: 4px 0;
    }

    html.lib-collapse-filters #finder .finder-layout-row .finder-sidebar-filters #finder-facets-panel {
        box-sizing: border-box !important;
        height: 52px !important;
        min-height: 52px !important;
        max-height: 52px !important;
        margin: 0 !important;
        padding: 0 14px !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: stretch !important;
    }

    html.lib-collapse-filters #finder #finder-facets-panel .library-panel-header {
        flex: 1 1 auto;
        min-width: 0;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        min-height: 0 !important;
    }

    html.lib-collapse-filters #finder #finder-facets-panel .facets-panel-title {
        margin: 0 !important;
        padding: 0 !important;
    }

    html.lib-collapse-filters #finder #finder-facets-panel .library-panel-toggle {
        min-height: 0;
        padding: 0;
    }

    html.lib-collapse-filters #finder #finder-facets-panel .facets-clear-all-btn {
        display: none !important;
    }
}

/* Sidebar brand as a link to the service home page (views/site/_sidebar_brand.php) */
a.finder-sidebar-brand-link,
a.finder-sidebar-brand-link:hover,
a.finder-sidebar-brand-link:focus {
    text-decoration: none;
}

a.finder-sidebar-brand-link:hover .finder-sidebar-quote-emphasis,
a.finder-sidebar-brand-link:focus-visible .finder-sidebar-quote-emphasis {
    text-decoration: underline;
}
