/* ===== MOBILE NAV SHEET (≤768px) =====
   The bottom-sheet replacement for the left drawer. Everything here is inside
   the media query: above 768px the sheet does not exist and the navbar carries
   the navigation. */

@media (max-width: 768px) {

    /* ── Backdrop ────────────────────────────────────────────
       A real element, not body::after, so it can fade on its own timing and
       take the click itself instead of relying on a document-level handler. */
    .nav-sheet-backdrop {
        position: fixed;
        inset: 0;
        z-index: 398;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        opacity: 0;
        transition: opacity 0.25s ease;
    }

    .nav-sheet-backdrop.is-open {
        opacity: 1;
    }

    /* ── Sheet ───────────────────────────────────────────────
       Anchored to the bottom and capped at 85dvh: the cap is what keeps the
       sheet from becoming the full-screen panel it is replacing, and dvh (not
       vh) so the mobile URL bar cannot push the handle off screen. */
    .nav-sheet {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 400;
        max-height: 85dvh;
        display: flex;
        flex-direction: column;
        /* Explicitly opaque, not var(--card-bg): in dark mode that token is
           rgba(255,255,255,0.04), a tint meant to sit on the page background.
           On a fixed panel it makes the page show straight through. */
        background: #0c1a0c;
        border-top: 1px solid var(--border, rgba(255, 255, 255, 0.09));
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.45);
        /* Sits off screen until opened; the transform is also what the drag
           gesture writes to, via --drag. */
        transform: translateY(calc(100% + var(--drag, 0px)));
        transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
        overscroll-behavior: contain;
    }

    .nav-sheet.is-open {
        transform: translateY(var(--drag, 0px));
    }

    /* `display: flex` above beats the UA stylesheet's `[hidden] { display: none }`,
       so without this the closed sheet stays rendered off screen with all its
       links in the tab order — Tab from the page would drop the user into a menu
       they cannot see. The attribute-qualified selector outranks .nav-sheet on
       its own, no !important needed. */
    .nav-sheet[hidden] {
        display: none;
    }

    /* While a finger is down the sheet has to track it exactly — any easing
       here reads as lag. */
    .nav-sheet.is-dragging {
        transition: none;
    }

    /* ── Grab handle ─────────────────────────────────────────
       The bar is the drag affordance. It is a <button> as well, so the gesture
       is never the only way out. */
    .nav-sheet-grab {
        flex-shrink: 0;
        width: 100%;
        height: 28px;
        padding: 0;
        border: none;
        background: none;
        cursor: grab;
        touch-action: none;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .nav-sheet-grab::before {
        content: '';
        width: 40px;
        height: 4px;
        border-radius: 2px;
        background: var(--muted-text, rgba(240, 237, 231, 0.35));
    }

    .nav-sheet-grab:active {
        cursor: grabbing;
    }

    /* ── Header ──────────────────────────────────────────────
       The drawer had no title at all — just a full-width bar with an X pushed
       to the right edge. The couple's names say which wedding you are in. */
    .nav-sheet-head {
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-sm);
        padding: 0 var(--space-sm) 0.75rem;
        border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.07));
    }

    .nav-sheet-titles {
        min-width: 0;
    }

    .nav-sheet-eyebrow {
        margin: 0;
        font-size: 0.7rem;
        letter-spacing: 0.09em;
        text-transform: uppercase;
        color: var(--muted-text, rgba(240, 237, 231, 0.45));
    }

    .nav-sheet-title {
        margin: 0;
        font-family: 'Playfair Display', serif;
        font-size: 1.15rem;
        line-height: 1.3;
        color: var(--gold, #c4a860);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .nav-sheet-close {
        flex-shrink: 0;
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 1px solid var(--border, rgba(255, 255, 255, 0.09));
        border-radius: 50%;
        background: none;
        color: var(--light-text, rgba(240, 237, 231, 0.7));
        cursor: pointer;
        transition-property: color, background-color, border-color;
        transition-duration: 0.2s;
    }

    .nav-sheet-close:hover {
        background: rgba(255, 255, 255, 0.06);
        color: var(--dark-text, #f0ede7);
    }

    .nav-sheet-close .icon-svg {
        width: 18px;
        height: 18px;
    }

    /* ── Body ────────────────────────────────────────────────
       The scroller. Safe-area padding at the bottom so the last row clears the
       home indicator. */
    .nav-sheet-body {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        padding: var(--space-sm) var(--space-sm)
                 calc(var(--space-sm) + env(safe-area-inset-bottom, 0px));
        display: flex;
        flex-direction: column;
        gap: var(--space-sm);
    }

    /* ── Groups ──────────────────────────────────────────────
       Headings mirror the desktop navbar's dropdowns, so the two navigations
       describe the same shape. */
    .nav-sheet-group {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .nav-sheet-group-title {
        margin: 0;
        font-size: 0.72rem;
        font-weight: 600;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: var(--muted-text, rgba(240, 237, 231, 0.5));
    }

    .nav-sheet-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    /* ── Tiles ───────────────────────────────────────────────
       Icon and label side by side rather than stacked: stacked tiles look
       tidier in a mockup and read slower, because the label is the thing you
       are actually scanning for. */
    .nav-tile {
        position: relative;
        display: flex;
        align-items: center;
        gap: 0.6rem;
        min-height: 56px;
        padding: 0.6rem 0.75rem;
        border: 1px solid var(--border, rgba(255, 255, 255, 0.07));
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.03);
        color: var(--dark-text, #f0ede7);
        text-decoration: none;
        transition-property: background-color, border-color, color;
        transition-duration: 0.2s;
    }

    .nav-tile:active {
        background: rgba(255, 255, 255, 0.08);
    }

    .nav-tile--wide {
        grid-column: 1 / -1;
    }

    .nav-tile-icon {
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        border-radius: 8px;
        background: rgba(196, 168, 96, 0.12);
        color: var(--gold, #c4a860);
    }

    .nav-tile-icon .icon-svg {
        width: 17px;
        height: 17px;
    }

    .nav-tile-label {
        font-size: 0.88rem;
        line-height: 1.25;
        /* Two lines then ellipsis: "Save the Date" and "Budget Report" need the
           second line in German, and truncating them to one would lose the
           word that tells them apart. */
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    /* Where you are now. A left border rather than a filled tile: the fill
       would make the current page look like the primary action. */
    .nav-tile.is-current {
        border-color: var(--gold, #c4a860);
        background: rgba(196, 168, 96, 0.1);
    }

    .nav-tile.is-current .nav-tile-label {
        color: var(--gold, #c4a860);
    }

    /* ── Locked (Pro teaser) ─────────────────────────────────
       Muted, but still a link: the target page is where the upgrade dialog is,
       so a dead tile would be a dead end. */
    .nav-tile--locked {
        opacity: 0.62;
        padding-right: 2.6rem;
    }

    .nav-tile--locked .nav-tile-icon {
        background: rgba(255, 255, 255, 0.05);
        color: var(--muted-text, rgba(240, 237, 231, 0.55));
    }

    .nav-tile-pro {
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
        padding: 0.1rem 0.35rem;
        border-radius: 4px;
        background: var(--gold, #c4a860);
        color: #1a2c42;
        font-size: 0.62rem;
        font-weight: 700;
        letter-spacing: 0.04em;
        line-height: 1.4;
    }

    /* ── Stats ───────────────────────────────────────────────
       One row, three numbers. The drawer stacked these as label/value pairs and
       spent 120 px on orientation. */
    .nav-sheet-stats {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
        margin-top: 0.25rem;
        padding-top: var(--space-sm);
        border-top: 1px solid var(--border, rgba(255, 255, 255, 0.07));
    }

    .nav-sheet-stat {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.1rem;
    }

    .nav-sheet-stat-value {
        font-size: 1rem;
        font-weight: 600;
        font-variant-numeric: tabular-nums;
        color: var(--dark-text, #f0ede7);
    }

    .nav-sheet-stat-of {
        font-size: 0.8rem;
        font-weight: 400;
        color: var(--muted-text, rgba(240, 237, 231, 0.5));
    }

    .nav-sheet-stat-label {
        font-size: 0.68rem;
        letter-spacing: 0.06em;
        text-transform: uppercase;
        color: var(--muted-text, rgba(240, 237, 231, 0.5));
    }

    /* ── Light mode ──────────────────────────────────────────
       The old drawer relied on a light-mode override elsewhere flipping both
       background and text; spelling it out here keeps the pair together. */
    html:not(.dark-mode) .nav-sheet {
        background: #FFFFFF;
        border-top-color: rgba(0, 0, 0, 0.08);
        box-shadow: 0 -8px 40px rgba(26, 44, 66, 0.16);
    }

    html:not(.dark-mode) .nav-sheet-head {
        border-bottom-color: rgba(0, 0, 0, 0.07);
    }

    html:not(.dark-mode) .nav-sheet-title {
        color: var(--primary, #1a2c42);
    }

    html:not(.dark-mode) .nav-sheet-grab::before {
        background: rgba(26, 44, 66, 0.25);
    }

    html:not(.dark-mode) .nav-sheet-close {
        border-color: rgba(0, 0, 0, 0.1);
        color: rgba(26, 44, 66, 0.7);
    }

    html:not(.dark-mode) .nav-sheet-close:hover {
        background: rgba(26, 44, 66, 0.05);
    }

    html:not(.dark-mode) .nav-tile {
        border-color: rgba(0, 0, 0, 0.08);
        background: #FDFCFB;
        color: var(--primary, #1a2c42);
    }

    html:not(.dark-mode) .nav-tile:active {
        background: rgba(26, 44, 66, 0.05);
    }

    html:not(.dark-mode) .nav-tile.is-current {
        border-color: var(--gold, #c4a860);
        background: rgba(196, 168, 96, 0.12);
    }

    /* Gold reads at 7.9:1 on the dark card and 2.3:1 on a white one — it is the
       dark-mode accent. In light mode the navy text stays and the gold border
       plus tint carry "you are here" on their own. */
    html:not(.dark-mode) .nav-tile.is-current .nav-tile-label {
        color: var(--primary, #1a2c42);
    }

    html:not(.dark-mode) .nav-tile--locked .nav-tile-icon {
        background: rgba(26, 44, 66, 0.06);
        color: rgba(26, 44, 66, 0.5);
    }

    html:not(.dark-mode) .nav-sheet-stats {
        border-top-color: rgba(0, 0, 0, 0.07);
    }

    html:not(.dark-mode) .nav-sheet-stat-value {
        color: var(--primary, #1a2c42);
    }

    /* Body scroll lock while the sheet is open. */
    body.nav-sheet-open {
        overflow: hidden;
    }
}

/* Above the breakpoint the sheet must never appear, whatever state JS left
   behind after a resize. */
@media (min-width: 769px) {
    .nav-sheet,
    .nav-sheet-backdrop {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .nav-sheet,
    .nav-sheet-backdrop,
    .nav-tile,
    .nav-sheet-close {
        transition: none;
    }
}
