/* In Berea — application shell
   Isolated from the public and admin headers.
   Desktop: fixed header and collapsible rail.
   Mobile: scrolling header, floating bottom navigation.
*/

body.berea-app {
    --app-top: 58px;
    --app-side-wide: 232px;
    --app-side-narrow: 58px;
    --app-mobile-nav-height: 52px;
    margin: 0;
    background: #fcfcfc;
    color: #181818;
    font-family: 'Source Sans 3', Arial, sans-serif;
}
.berea-app button,
.berea-app input { font: inherit; }
.berea-app button { cursor: pointer; }
.berea-app a { text-decoration: none; }

/* ---------------- Global desktop header ---------------- */
.app-topbar {
    height: var(--app-top);
    position: fixed;
    inset: 0 0 auto;
    z-index: 110;
    background: #050505;
    color: #fff;
}
.app-topbar-inner {
    height: 100%;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 18px;
}
.app-icon-btn {
    border: 0;
    color: #fff;
    background: transparent;
    font-size: 22px;
    padding: 5px;
    line-height: 1;
}
.app-icon-btn svg { display: block; }
.app-wordmark {
    font-family: 'Barlow Condensed', sans-serif;
    color: #fff;
    font-size: 31px;
    text-transform: uppercase;
    font-weight: 600;
    line-height: 1;
}
.app-wordmark span { padding-left: 3px; }
.app-topbar-spacer { flex: 1; }
.app-scripture-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f6f6f6;
    color: #111;
    border: 0;
    padding: 7px 16px;
    text-transform: uppercase;
    letter-spacing: .08em;
    font-size: 13px;
    font-weight: 600;
}
.app-scripture-action svg { display: block; }
.app-account-link {
    color: #fff;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .06em;
}

/* ---------------- Layout and desktop sidebar ---------------- */
.app-layout {
    padding-top: var(--app-top);
    min-height: 100dvh;
}
.app-sidebar {
    position: fixed;
    top: var(--app-top);
    bottom: 0;
    left: 0;
    width: var(--app-side-narrow);
    background: #fff;
    border-right: 1px solid #e6e6e6;
    z-index: 90;
    transition: width .18s ease;
    overflow: hidden;
}
.berea-app.sidebar-expanded .app-sidebar { width: var(--app-side-wide); }
.app-sidebar-inner {
    padding: 14px 8px;
    min-width: var(--app-side-wide);
}
.app-nav-caption {
    color: #848484;
    letter-spacing: .17em;
    font-size: 10px;
    padding: 8px 12px;
    margin-top: 7px;
    white-space: nowrap;
    opacity: 0;
}
.berea-app.sidebar-expanded .app-nav-caption { opacity: 1; }
.app-nav-link {
    display: flex;
    align-items: center;
    text-align: left;
    gap: 13px;
    width: 100%;
    border: 0;
    background: transparent;
    border-radius: 5px;
    padding: 7px;
    color: #222;
    font-size: 14px;
    white-space: nowrap;
    min-height: 30px;
}
.app-nav-link:hover,
.app-nav-link:focus-visible { background: #f1f1f1; }
.app-nav-glyph {
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.app-nav-glyph svg {
    display: block;
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
}
.app-nav-label {
    opacity: 0;
    transition: opacity .12s;
}
.berea-app.sidebar-expanded .app-nav-label { opacity: 1; }
.app-guest-hint {
    font-size: 12px;
    color: #666;
    margin: 10px 14px 16px;
    max-width: 190px;
    opacity: 0;
}
.berea-app.sidebar-expanded .app-guest-hint { opacity: 1; }
.app-sidebar-scrim { display: none; }
.app-main {
    margin-left: var(--app-side-narrow);
    min-height: calc(100dvh - var(--app-top));
    transition: margin-left .18s ease;
}
.berea-app.sidebar-expanded .app-main { margin-left: var(--app-side-wide); }

/* ---------------- Test-route content ---------------- */
.app-demo { max-width: 1120px; padding: 35px 28px 70px; margin: auto; }
.app-eyebrow { font-size: 12px; letter-spacing: .15em; font-weight: 600; color: #777; }
.app-demo h1 {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: clamp(36px, 5vw, 64px);
    line-height: 1.05;
    margin: 8px 0 20px;
}
.app-demo-lead { max-width: 750px; font-size: 18px; line-height: 1.5; }
.app-demo-card { background: #fff; padding: 25px; margin-top: 22px; border: 1px solid #e6e6e6; }
.app-demo-card h2 { margin: 5px 0 10px; }
.app-demo-card p { max-width: 670px; }
.app-demo-cta { background: #111; color: #fff; border: 0; padding: 12px 18px; margin-top: 10px; }

/* ---------------- Scripture finder ---------------- */
.app-finder-backdrop[hidden] { display: none !important; }
.app-finder-backdrop {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(0, 0, 0, .64);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: clamp(35px, 12vh, 115px) 15px 20px;
    overflow-y: auto;
}
.app-finder {
    width: min(600px, 100%);
    background: #fff;
    padding: 24px;
    box-shadow: 0 20px 70px #0004;
    color: #151515;
    max-height: calc(100dvh - 65px);
    overflow: auto;
}
.app-finder-titlebar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: -24px;
    background: #fff;
    z-index: 2;
    padding-top: 4px;
}
.app-finder h2 { font-size: 22px; margin: 0 0 15px; font-family: 'Barlow Condensed', sans-serif; }
.app-finder-titlebar button { background: none; border: 0; font-size: 30px; line-height: 1; }
.app-finder label { font-size: 13px; font-weight: 600; }
.app-finder input { margin: 6px 0 4px; padding: 13px 12px; width: 100%; border: 1px solid #999; font-size: 18px; border-radius: 0; }
.app-finder p { font-size: 12px; color: #686868; margin: 4px 0 13px; }
.app-finder-matches { display: grid; gap: 5px; }
.app-match { padding: 10px 12px; text-align: left; border: 1px solid #e4e4e4; background: #fff; display: flex; justify-content: space-between; }
.app-match[aria-selected=true],
.app-match:hover { background: #ededed; border-color: #aaa; }
.app-match small { color: #707070; }
.app-finder-chapters { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-top: 16px; }
.app-finder-chapters button { border: 1px solid #ddd; background: #f6f6f6; min-height: 40px; }
.app-finder-chapters button:hover { background: #111; color: #fff; }
.app-finder-status { font-size: 12px; color: #666; margin-top: 12px; }

/* ---------------- Bible integration: desktop ---------------- */
.berea-app .bible-shell { max-width: 1100px; width: 100%; box-sizing: border-box; }
.berea-app .bible-chapterbar { top: calc(var(--app-top) + 2px); }
.berea-app .bible-note-fab { bottom: 24px; }

/* ---------------- Mobile bottom navigation: desktop hidden ---------------- */
.app-mobile-bar { display: none; }
.app-mobile-bar .app-mobile-icon {
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.app-mobile-bar .app-mobile-icon svg {
    display: block;
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
}

/* =========================================================
   MOBILE APPLICATION — one breakpoint, no competing overrides
   ========================================================= */
@media (max-width: 800px) {
    body.berea-app { --app-top: 56px; }

    /* Header scrolls away with the page; bottom bar owns navigation. */
    .berea-app .app-topbar {
        position: relative;
        inset: auto;
        top: auto;
        height: var(--app-top);
    }
    .berea-app .app-topbar .app-sidebar-toggle,
    .berea-app .app-topbar .app-scripture-action { display: none; }
    .berea-app .app-layout { padding-top: 0; min-height: 0; }
    .berea-app .app-main,
    .berea-app.sidebar-expanded .app-main {
        margin-left: 0;
        min-height: 0;
        padding-bottom: calc(var(--app-mobile-nav-height) + env(safe-area-inset-bottom, 0px) + 20px);
    }

    /* Sidebar intentionally becomes invisible after the slide-out.
       Important for Safari's safe-area compositing on close. */
    .berea-app .app-sidebar {
        top: 0;
        bottom: 0;
        width: min(82vw, 300px);
        height: 100dvh;
        transform: translateX(-102%);
        opacity: 0;
        visibility: hidden;
        transition: transform .18s ease, opacity .18s ease, visibility .18s ease;
        box-shadow: none;
    }
    .berea-app.sidebar-expanded .app-sidebar {
        width: min(82vw, 300px);
        transform: translateX(0);
        opacity: 1;
        visibility: visible;
        box-shadow: 10px 0 30px #0002;
    }
    .app-sidebar-inner { min-width: 0; }
    .berea-app .app-nav-caption,
    .berea-app .app-nav-label,
    .berea-app .app-guest-hint { opacity: 1; }
    .berea-app .app-sidebar-scrim {
        position: fixed;
        inset: 0;
        background: #ffffffde;
        z-index: 85;
    }
    .berea-app.sidebar-expanded .app-sidebar-scrim { display: block; }

    /* Floating white pill: maintain the user's chosen appearance.
       The page is intentionally visible around/below this bar. */
    .berea-app .app-mobile-bar {
        position: fixed;
        left: 50%;
        right: auto;
        bottom: 4px;
        transform: translateX(-50%);
        width: 97%;
        height: calc(var(--app-mobile-nav-height) + env(safe-area-inset-bottom, 0px));
        z-index: 120;
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        align-items: stretch;
        padding: 0 8px env(safe-area-inset-bottom, 0px);
        border: 0;
        border-radius: 25px;
        background: #fff;
        box-sizing: border-box;
        transition: none;
    }
    .berea-app .app-mobile-bar a,
    .berea-app .app-mobile-bar button {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        min-width: 0;
        min-height: 0;
        height: 100%;
        margin: 0;
        padding: 5px 3px;
        border: 0;
        border-radius: 0;
        background: transparent;
        color: #000;
        font-family: 'Source Sans 3', sans-serif;
        font-size: 11px;
        font-weight: 400;
        line-height: 1.2;
        text-align: center;
        text-decoration: none;
    }
    .berea-app .app-mobile-bar .app-mobile-primary {
        background: transparent !important;
        color: #959595;
    }
    .berea-app .app-mobile-bar a:focus-visible,
    .berea-app .app-mobile-bar button:focus-visible {
        outline: 2px solid #333;
        outline-offset: -3px;
    }

    /* Preserve the proven Safari behavior: remove bar while these
       overlays are open; restore it when they close. */
    body.berea-app.sidebar-expanded .app-mobile-bar,
    body.berea-app:has(.bible-note-drawer.is-open) .app-mobile-bar {
        display: none !important;
    }

    /* Reader and contextual buttons */
    .berea-app .bible-shell { padding: 16px; }
    .berea-app .bible-chapterbar { top: 0; }
    .berea-app .bible-note-fab {
        position: fixed;
        top: auto;
        right: 0;
        bottom: calc(var(--app-mobile-nav-height) + env(safe-area-inset-bottom, 0px) + 16px);
    }
    .berea-app .studies-trigger {
        position: fixed;
        top: auto;
        right: 0;
        bottom: calc(var(--app-mobile-nav-height) + env(safe-area-inset-bottom, 0px) + 76px);
    }
    .berea-app .bible-note-drawer {
        width: min(420px, 100%);
        height: 100dvh;
        bottom: 0;
        z-index: 210;
    }
    .berea-app .app-demo { padding: 27px 17px 60px; }
    .berea-app .app-finder { padding: 18px; }
    .berea-app .app-finder-titlebar { top: -18px; }
    .berea-app .app-finder-chapters { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
    .berea-app * { transition: none !important; }
}
/* Direct passage action sits above the chapter grid */
.berea-app .app-finder-chapters .app-reference-open {
    grid-column: 1 / -1;
    width: 100%;
    min-height: 46px;
    padding: 12px 16px;

    background: #181818;
    color: #fff;
    border: 1px solid #181818;

    font-size: 15px;
    font-weight: 600;
    text-align: left;
    white-space: normal;
}

.berea-app .app-finder-chapters .app-reference-open:hover,
.berea-app .app-finder-chapters .app-reference-open:focus-visible {
    background: #333;
    color: #fff;
}