/* =========================================================================
   Liturgy Library — shared presentation
   Navy / gold / cream / white / dark-red liturgical language.
   ========================================================================= */

.library-page {
    --lp-navy: #14243a;
    --lp-navy-deep: #0f1f36;
    --lp-navy-soft: #1c3555;
    --lp-gold: #c5a15a;
    --lp-gold-deep: #c9a44c;
    --lp-cream: #f6eedc;
    --lp-ivory: #f2eadc;
    --lp-red: #8f1d2c;
    --lp-ink: #20242b;
    --lp-muted: #64748b;
    --lp-line: #e2e8f0;
    color: var(--lp-ink);
}

.library-icon {
    width: 1.05rem;
    height: 1.05rem;
    flex: none;
}

/* -------------------------------------------------------- auth required */

.auth-required {
    max-width: 30rem;
    margin: 3rem auto;
    padding: 1.75rem;
    background: #fff;
    border: 1px solid var(--lp-line);
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(20, 36, 58, 0.06);
    color: var(--lp-ink);
    text-align: center;
}

.auth-required h1 {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--lp-navy);
    margin: 0 0 0.5rem;
}

.auth-required p {
    margin: 0 0 1.1rem;
    color: var(--lp-muted);
    font-size: 0.92rem;
}

.auth-required-link {
    display: inline-block;
    background: var(--lp-navy);
    color: #fff;
    border-radius: 6px;
    padding: 9px 18px;
    font-size: 0.88rem;
    font-weight: 600;
    text-decoration: none;
}

.auth-required-link:hover {
    background: var(--lp-navy-soft);
}

.auth-required-link:focus-visible {
    outline: 2px solid var(--lp-gold);
    outline-offset: 2px;
}

/* ---------------------------------------------------------------- areas */

.library-area-page {
    max-width: 1160px;
    margin: 0 auto;
    padding: 1.25rem 0.25rem;
}

.library-area-banner {
    position: relative;
    display: block;
    background: #fff;
    border: 1px solid var(--lp-line);
    border-radius: 10px;
    overflow: hidden;
    margin: 0 0 1rem;
    padding: 0;
}

.library-area-banner img {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    object-fit: cover;
}

/* Real HTML title/description overlaid on the banner artwork. The overlay
   covers the rasterized text baked into the image so it is never readable
   twice; the photographic artwork stays visible on the right (side variant)
   or below the text band (top variant, Cuaresma). */
.library-area-banner-text {
    position: absolute;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.library-area-banner-text--side {
    inset: 0 auto 0 0;
    width: 100%;
    padding: 1rem 38% 1rem 2rem;
    background: linear-gradient(to right, #fff 0%, #fff 64%, rgba(255, 255, 255, 0) 88%);
}

.library-area-banner-text--top {
    inset: 0 0 auto 0;
    padding: 1rem 2rem 2.25rem;
    background: linear-gradient(to bottom, #fff 0%, #fff 62%, rgba(255, 255, 255, 0));
}

.library-banner-title {
    margin: 0 0 0.4rem;
    font-family: Georgia, 'Times New Roman', serif;
    font-weight: 700;
    font-size: clamp(1.4rem, 1rem + 2.4vw, 2.1rem);
    line-height: 1.15;
    color: var(--lp-navy);
    overflow-wrap: anywhere;
}

.library-banner-title--plain {
    margin: 0 0 1rem;
}

.library-banner-description {
    margin: 0;
    font-size: clamp(0.85rem, 0.8rem + 0.4vw, 1rem);
    line-height: 1.5;
    color: #6b6f76;
    overflow-wrap: anywhere;
}

.library-area-title {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.library-open-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 8px 28px;
    border: 0;
    border-radius: 6px;
    background: #062d55;
    color: #fff;
    font-size: 0.88rem;
    font-weight: 700;
    text-decoration: none;
}

.library-open-btn:hover {
    background: #0b3d70;
    color: #fff;
}

.library-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 14px;
}

.library-card {
    position: relative;
    display: block;
    background: #fff;
    border: 1px solid var(--lp-line);
    border-radius: 8px;
    padding: 18px 20px;
    text-decoration: none;
    box-shadow: 0 1px 3px rgba(15, 31, 54, 0.06);
    overflow: hidden;
    transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.library-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(15, 31, 54, 0.12);
}

.library-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 5px;
    background: var(--lp-gold-deep);
    border-radius: 0 2px 2px 0;
}

.library-card:focus-visible {
    outline: 2px solid var(--lp-gold);
    outline-offset: 2px;
}

.library-card-title {
    display: block;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--lp-navy);
    line-height: 1.55;
    overflow-wrap: anywhere;
}

/* ------------------------------------------------------- section viewer */

.library-viewer {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f4f6f8;
    border-radius: 10px;
    padding: 14px;
}

.library-toolbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(20, 36, 58, 0.06);
    border: 1px solid var(--lp-line);
}

.library-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    padding: 6px 10px;
    color: var(--lp-navy);
    font-weight: 600;
    font-size: 0.82rem;
    font-family: inherit;
    white-space: nowrap;
    text-decoration: none;
}

.library-back:hover {
    background: #f4f6f8;
}

.library-back:focus-visible {
    outline: 2px solid var(--lp-gold);
    outline-offset: 1px;
}

.library-back .library-icon {
    color: var(--lp-gold);
}

.library-cats {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 0 auto;
}

.library-cat {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 13px;
    border: 1px solid transparent;
    border-bottom: 2px solid transparent;
    border-radius: 6px 6px 0 0;
    background: none;
    color: #556173;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    text-decoration: none;
    white-space: nowrap;
}

.library-cat .library-icon {
    color: #334a63;
}

.library-cat:hover {
    color: var(--lp-navy);
    background: #eef2f6;
}

.library-cat:hover .library-icon {
    color: var(--lp-navy);
}

.library-cat:focus-visible {
    outline: 2px solid var(--lp-gold);
    outline-offset: -2px;
    border-radius: 6px;
}

.library-cat-active,
.library-cat-active:hover {
    border-bottom-color: var(--lp-gold);
    background: var(--lp-cream);
    color: var(--lp-navy);
}

.library-cat-active .library-icon,
.library-cat-active:hover .library-icon {
    color: #9b762e;
}

.library-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.library-print {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: #fff;
    color: var(--lp-navy);
    border: 1px solid #d5dbe3;
    border-radius: 6px;
    padding: 7px 13px;
    font-size: 0.82rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
}

.library-print:hover {
    border-color: var(--lp-gold);
    background: #fbf3e2;
}

.library-print:focus-visible {
    outline: 2px solid var(--lp-gold);
    outline-offset: 1px;
}

.library-print .library-icon {
    color: #334a63;
}

/* mobile contents disclosure (checkbox driven) */

.library-contents-toggle {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.library-contents-btn,
.library-context-close {
    display: none;
}

.library-body {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 14px;
    align-items: start;
}

/* contextual panel */

.library-context {
    background: var(--lp-navy);
    color: var(--lp-ivory);
    border-radius: 10px;
    padding: 16px 10px 10px;
    position: sticky;
    top: 4rem;
    max-height: calc(100vh - 5rem);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.library-context-scroll {
    overflow-y: auto;
    min-height: 0;
    padding-right: 2px;
}

.library-context-area {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--lp-gold);
    line-height: 1.4;
    padding: 0 10px;
}

.library-context-section {
    display: block;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.02rem;
    font-weight: 600;
    color: #fff;
    line-height: 1.35;
    margin: 2px 0 0;
    padding: 0 10px;
    overflow-wrap: anywhere;
}

.library-context-label {
    display: block;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.5);
    padding: 12px 13px 5px;
}

.library-context-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.12);
    margin: 8px 12px;
}

.library-toc-link,
.library-doc-link {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    border-radius: 0 6px 6px 0;
    padding: 7px 12px;
    font-size: 0.82rem;
    line-height: 1.4;
    font-weight: 400;
    color: #b9c5d3;
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
    overflow-wrap: anywhere;
    transition: background 0.12s ease, color 0.12s ease;
}

.library-toc-link--3 {
    padding-left: 24px;
}

.library-toc-link:hover,
.library-doc-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.06);
}

.library-toc-link:focus-visible,
.library-doc-link:focus-visible {
    outline: 2px solid var(--lp-gold);
    outline-offset: -2px;
}

.library-toc-empty {
    display: block;
    color: rgba(255, 255, 255, 0.48);
    font-size: 0.82rem;
    padding: 4px 13px;
    line-height: 1.4;
}

.library-doc-link-active,
.library-doc-link-active:hover {
    color: #fff;
    font-weight: 600;
    background: rgba(197, 161, 90, 0.14);
    border-left-color: var(--lp-gold);
}

/* document surface */

.library-document {
    background: #fff;
    border-radius: 10px;
    padding: 2.4rem clamp(1.25rem, 4vw, 3.25rem);
    box-shadow: 0 1px 3px rgba(20, 36, 58, 0.06);
    min-width: 0;
}

.library-document-title {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--lp-navy);
    line-height: 1.25;
    margin: 0 0 0.25rem;
}

.library-markdown {
    max-width: 47rem;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.02rem;
    line-height: 1.7;
    color: #262b33;
    overflow-wrap: anywhere;
}

.library-markdown > :first-child {
    margin-top: 0;
}

.library-markdown h1 {
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--lp-navy);
    line-height: 1.25;
    margin: 0 0 1.4rem;
    padding-bottom: 0.45rem;
    border-bottom: 2px solid var(--lp-gold-deep);
}

.library-markdown h2 {
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--lp-navy);
    line-height: 1.3;
    margin: 2.2rem 0 0.8rem;
}

.library-markdown h3 {
    font-size: 1.08rem;
    font-weight: 600;
    color: var(--lp-red);
    margin: 1.7rem 0 0.6rem;
}

.library-markdown h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--lp-red);
    margin: 1.4rem 0 0.5rem;
}

.library-markdown p {
    margin: 0 0 1rem;
}

.library-markdown ul,
.library-markdown ol {
    margin: 0 0 1rem;
    padding-left: 1.6rem;
}

.library-markdown li {
    margin: 0.25rem 0;
}

.library-markdown strong {
    color: #10151d;
}

.library-markdown em {
    font-style: italic;
}

.library-markdown blockquote {
    margin: 0 0 1rem;
    padding: 0.1rem 0 0.1rem 1.1rem;
    border-left: 3px solid var(--lp-gold);
    color: #3d4551;
    font-style: italic;
}

.library-markdown hr {
    border: 0;
    border-top: 1px solid #e3d7bd;
    margin: 2rem auto;
    max-width: 70%;
}

.library-markdown table {
    border-collapse: collapse;
    width: 100%;
    margin: 0 0 1.2rem;
    font-size: 0.95rem;
}

.library-markdown th,
.library-markdown td {
    border: 1px solid var(--lp-line);
    padding: 0.5rem 0.7rem;
    text-align: left;
    vertical-align: top;
}

.library-markdown th {
    background: #f6f4ef;
    color: var(--lp-navy);
    font-weight: 700;
}

.library-markdown code {
    font-family: Consolas, 'Courier New', monospace;
    font-size: 0.88em;
    background: #f1f0ec;
    padding: 0.1em 0.35em;
    border-radius: 3px;
}

.library-markdown pre code {
    display: block;
    background: #f6f4ef;
    padding: 0.9rem 1rem;
    overflow-x: auto;
}

.library-markdown a {
    color: #1a5f8a;
}

/* docx preview + generic download surface */

.library-docx-preview {
    max-width: 47rem;
    font-size: 0.98rem;
    line-height: 1.65;
    color: #262b33;
}

.library-docx-preview h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--lp-navy);
    margin: 1.6rem 0 0.6rem;
}

.library-docx-preview h3 {
    font-size: 1.02rem;
    font-weight: 600;
    color: var(--lp-red);
    margin: 1.3rem 0 0.5rem;
}

.library-docx-preview p {
    margin: 0 0 0.7rem;
}

.library-docx-preview ul,
.library-docx-preview ol {
    margin: 0 0 0.8rem;
    padding-left: 1.5rem;
}

.library-docx-preview table {
    border-collapse: collapse;
    width: 100%;
    margin: 0 0 1rem;
}

.library-docx-preview th,
.library-docx-preview td {
    border: 1px solid #cfd6df;
    padding: 0.45rem 0.6rem;
    text-align: left;
    vertical-align: top;
}

.library-forms-note {
    max-width: 47rem;
    margin: 0 0 1.4rem;
    padding: 0.65rem 0.85rem;
    border-left: 3px solid var(--lp-gold);
    background: #fbf7ef;
    color: #5b5344;
    font-size: 0.85rem;
    font-style: italic;
    line-height: 1.55;
}

.library-download {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--lp-navy);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 9px 16px;
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.library-download:hover {
    background: var(--lp-navy-soft);
}

.library-download:focus-visible {
    outline: 2px solid var(--lp-gold);
    outline-offset: 2px;
}

.library-download .library-icon {
    color: var(--lp-gold);
}

.library-file-hint {
    color: var(--lp-muted);
    font-size: 0.85rem;
    margin: 0 0 1rem;
}

.library-language-note {
    margin: 0 0 1rem;
    padding: 0.6rem 0.9rem;
    border-left: 3px solid var(--lp-gold);
    background: #fbf3e2;
    color: #5b4a1e;
    font-size: 0.88rem;
    line-height: 1.5;
}

.library-empty {
    max-width: 47rem;
    color: #6a7380;
    font-size: 0.92rem;
    font-style: italic;
    padding: 0.5rem 0;
}

/* ------------------------------------------------------------ responsive */

.liturgy-landing {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    padding: 1.5rem 0 2rem;
}

.liturgy-landing-art {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 1040px;
    width: 100%;
    background: #fff;
    border: 1px solid var(--lp-line);
    border-radius: 12px;
    overflow: hidden;
    padding: 10px;
}

.liturgy-landing-art img {
    display: block;
    max-width: 100%;
    max-height: 70vh;
    width: auto;
    height: auto;
    object-fit: contain;
}

.liturgy-landing-art.is-missing {
    display: none;
}

.liturgy-landing-enter {
    display: flex;
    justify-content: center;
}

.library-markdown h1,
.library-markdown h2,
.library-markdown h3,
.library-markdown h4,
.library-docx-preview h2,
.library-docx-preview h3 {
    scroll-margin-top: 5rem;
}

@media (max-width: 1100px) {
    .library-cards {
        grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    }

    .library-body {
        grid-template-columns: 236px minmax(0, 1fr);
    }
}

@media (max-width: 900px) {
    .library-body {
        grid-template-columns: minmax(0, 1fr);
    }

    .library-cards {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    /* contextual panel becomes a disclosure controlled by the toggle */
    .library-contents-btn {
        display: inline-flex;
        align-items: center;
        gap: 7px;
        background: #fff;
        color: var(--lp-navy);
        border: 1px solid #d5dbe3;
        border-radius: 6px;
        padding: 7px 13px;
        font-size: 0.82rem;
        font-weight: 600;
        font-family: inherit;
        cursor: pointer;
        white-space: nowrap;
    }

    .library-contents-btn:hover {
        border-color: var(--lp-gold);
        background: #fbf3e2;
    }

    .library-contents-btn:focus-visible {
        outline: 2px solid var(--lp-gold);
        outline-offset: 1px;
    }

    .library-context {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(300px, 86vw);
        max-height: none;
        border-radius: 0 10px 10px 0;
        z-index: 120;
        transform: translateX(-101%);
        transition: transform 0.22s ease;
        box-shadow: 6px 0 24px rgba(0, 0, 0, 0.3);
    }

    .library-context-close {
        display: flex;
        align-items: center;
        justify-content: center;
        align-self: flex-end;
        width: 30px;
        height: 30px;
        margin: 0 2px 4px;
        border-radius: 6px;
        border: 1px solid rgba(255, 255, 255, 0.18);
        background: none;
        color: var(--lp-ivory);
        font-size: 1.1rem;
        line-height: 1;
        cursor: pointer;
    }

    .library-context-close:focus-visible {
        outline: 2px solid var(--lp-gold);
        outline-offset: 2px;
    }

    .library-page > .library-contents-toggle:checked ~ .library-viewer .library-context {
        transform: translateX(0);
    }

    .library-toolbar {
        flex-wrap: wrap;
    }

    .library-cats {
        order: 3;
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        margin: 2px 0 0;
        padding-top: 4px;
        padding-bottom: 4px;
        border-top: 1px solid #eef0f3;
        scrollbar-width: thin;
        -webkit-mask-image: linear-gradient(to right, #000 92%, transparent);
        mask-image: linear-gradient(to right, #000 92%, transparent);
    }
}

@media (max-width: 600px) {
    .library-viewer {
        padding: 8px;
        border-radius: 8px;
    }

    .library-toolbar {
        padding: 6px 6px;
    }

    .library-cat {
        padding: 8px 10px;
        font-size: 0.82rem;
    }

    .library-document {
        padding: 1.5rem 1.1rem;
    }

    .library-markdown,
    .library-docx-preview {
        font-size: 1rem;
    }

    .library-markdown h1 {
        font-size: 1.5rem;
    }

    .library-area-page {
        padding: 0.75rem 0;
    }

    .library-area-banner {
        margin-bottom: 0.75rem;
    }

    /* On phones the raster text would shrink to an illegible size, so the
       artwork is hidden and the real HTML title/description take over. */
    .library-area-banner img {
        display: none;
    }

    .library-area-banner-text,
    .library-area-banner-text--side,
    .library-area-banner-text--top {
        position: static;
        background: #fff;
        padding: 1rem 1.1rem;
    }

    .library-cards {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* touch targets (coarse pointers only; desktop unchanged) */

@media (pointer: coarse) {
    .library-cat,
    .library-print,
    .library-contents-btn,
    .library-download {
        min-height: 44px;
    }

    .library-doc-link {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .library-context-close {
        width: 44px;
        height: 44px;
    }
}

/* ---------------------------------------------------------------- print */

@media print {
    @page {
        margin: 0.7in 0.75in;
    }

    .sidebar,
    .top-row,
    .navbar-toggler,
    .nav-scrollable,
    #sidebar-collapse-toggle,
    .library-toolbar,
    .library-contents-toggle,
    .library-contents-btn,
    .library-context,
    .library-context-close,
    .library-forms-note,
    #blazor-error-ui,
    .blazor-error-boundary {
        display: none !important;
    }

    .page,
    main,
    article,
    .content {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        width: auto !important;
    }

    .library-viewer,
    .library-body,
    .library-document {
        display: block !important;
        background: #fff !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        padding: 0 !important;
        gap: 0 !important;
        max-width: none !important;
    }

    .library-markdown,
    .library-docx-preview {
        max-width: none !important;
        font-size: 11pt;
        line-height: 1.5;
        color: #000;
    }

    .library-markdown a {
        color: inherit;
        text-decoration: none;
    }

    .library-markdown h1,
    .library-markdown h2,
    .library-markdown h3,
    .library-markdown h4 {
        break-after: avoid-page;
    }

    .library-markdown pre,
    .library-markdown table,
    .library-markdown img,
    .library-docx-preview table,
    .library-docx-preview img {
        break-inside: avoid;
    }

    /* Banner artwork stays on screen only; the real title/description print. */
    .library-area-banner {
        border: 0 !important;
    }

    .library-area-banner img {
        display: none !important;
    }

    .library-area-banner-text,
    .library-area-banner-text--side,
    .library-area-banner-text--top {
        position: static !important;
        background: none !important;
        padding: 0 0 0.6rem !important;
    }
}