/* ============================================================
   app-shell.css — the "app" chrome on phones.
   Loaded after app.css and pwa.css, so it wins. Everything that changes the
   layout is inside @media (max-width: 800px) and scoped to body.has-shell
   (signed-in, non-admin pages), so desktop and the marketing pages keep the
   look they have. Templates still drive every colour through the tokens.

   What it gives a phone:
     · one-row top bar: back / brand · page title · avatar
     · bottom tab bar: Events · Contacts · + · Account · More (bottom sheet)
     · full-width list cards, 46px tap targets, 16px inputs, sheet modals
     · sticky RSVP bar on the event page, section chips under the hero
     · page-to-page fade (View Transitions) and a top progress bar
   ============================================================ */

:root {
    --shell-top-h: 56px;
    --shell-tab-h: 62px;
    --shell-safe-b: env(safe-area-inset-bottom, 0px);
    --shell-safe-t: env(safe-area-inset-top, 0px);
}

/* ---------- Everywhere: navigation feedback ---------- */
.nav-progress {
    position: fixed; top: 0; left: 0; height: 3px; width: 0;
    background: var(--accent); z-index: 2000; opacity: 0; pointer-events: none;
    transition: width .3s ease, opacity .3s ease;
}
.nav-progress.is-on   { opacity: 1; width: 82%; transition: width 5s cubic-bezier(.08,.7,.2,1), opacity .15s; }
.nav-progress.is-done { width: 100%; opacity: 0; transition: width .15s, opacity .4s .15s; }

/* Short cross-fade between pages in browsers that support cross-document
   view transitions (Chrome 126+, Safari 18.2+). Others just navigate. */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .16s; }
@media (prefers-reduced-motion: reduce) {
    ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* Hidden unless the phone layout below turns them on. */
.shell-top, .tabbar, .sheet-backdrop, .rsvp-bar, .section-chips { display: none; }

/* Native wrapper (UbringitApp user agent) or installed PWA: no "install" nags,
   no outer page feel. */
body.is-app .hide-in-app { display: none !important; }
body.is-app { overscroll-behavior-y: none; }

/* ============================================================
   PHONE LAYOUT
   ============================================================ */
@media (max-width: 800px) {
    body.has-shell {
        -webkit-user-select: none; user-select: none;      /* chrome feels native; content re-enables below */
        touch-action: manipulation;                        /* no double-tap zoom delay */
    }
    body.has-shell main, body.has-shell input, body.has-shell textarea, body.has-shell [contenteditable] { -webkit-user-select: text; user-select: text; }
    body.has-shell .tabbar, body.has-shell .shell-top, body.has-shell .sheet { -webkit-user-select: none; user-select: none; }

    /* ---------- Top bar: one row ---------- */
    body.has-shell .topbar {
        display: block; padding: 0; padding-top: var(--shell-safe-t);
        height: calc(var(--shell-top-h) + var(--shell-safe-t));
        border-bottom: 1px solid color-mix(in srgb, var(--border-soft) 70%, transparent);
    }
    body.has-shell .topbar-brand-row, body.has-shell .topbar-nav-row { display: none; }
    body.has-shell .shell-top {
        display: grid; grid-template-columns: 52px 1fr 52px; align-items: center;
        height: var(--shell-top-h); padding: 0 6px;
    }
    .shell-top-l, .shell-top-r { display: flex; align-items: center; justify-content: center; height: 100%; }
    .shell-top-c { display: flex; align-items: center; justify-content: center; min-width: 0; }
    .shell-back {
        display: inline-flex; align-items: center; justify-content: center;
        width: 44px; height: 44px; border-radius: 999px; color: var(--accent);
    }
    .shell-back:active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
    .shell-back svg { width: 24px; height: 24px; }
    .shell-title {
        font-family: var(--body); font-weight: 700; font-size: 1.02rem; letter-spacing: -0.01em; color: var(--text);
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
    }
    .shell-top-c .brand-logo { height: 26px; width: auto; max-width: 150px; }
    .shell-top-c .brand { gap: 8px; }
    .shell-top-c .brand-name { font-size: 1.15rem; }
    .shell-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 2px solid var(--bg-elev); box-shadow: 0 0 0 1px var(--border-soft); }
    .shell-top-r a { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 999px; position: relative; color: var(--text); }
    .shell-bell svg { width: 24px; height: 24px; }
    .shell-bell.has-unread { color: var(--accent); }
    .shell-bell-n { top: 6px; right: 4px; }
    body.has-shell .topbar.is-hidden { transform: translateY(-100%); }

    /* ---------- Page body ---------- */
    body.has-shell .container {
        padding: 16px 16px calc(var(--shell-tab-h) + var(--shell-safe-b) + 28px);
    }
    body.has-shell .footer { display: none; }           /* legal links live under More */
    body.has-shell h1 { font-size: 1.65rem; letter-spacing: -0.015em; }
    body.has-shell .page-head { margin-bottom: 14px; align-items: center; }
    body.has-shell .page-head h1 { margin: 0; }
    body.has-shell .page-head .btn-primary[data-tour="new-event"] { display: none; }  /* the + tab does this */
    body.has-shell .section-title { margin-top: 22px; margin-bottom: 8px; }

    /* Panels and cards: tighter, rounder, no hover lift. */
    body.has-shell .panel { padding: 16px; border-radius: 18px; }
    body.has-shell .panel + .panel, body.has-shell .two-col > * { margin-top: 12px; }
    body.has-shell .collapsible-panel > h2, body.has-shell .collapsible-panel > h3 { min-height: 28px; }

    /* Event list: one column of rows (date tile · title/meta · chevron). */
    body.has-shell .event-grid { grid-template-columns: 1fr; gap: 10px; margin-top: 6px; }
    body.has-shell .event-card {
        display: grid; grid-template-columns: 60px 1fr 18px; grid-template-areas: "date title chev" "date meta chev" "date host chev";
        align-items: center; column-gap: 14px; row-gap: 2px; padding: 12px 12px 12px 12px; border-radius: 18px;
        transition: background .12s;
    }
    body.has-shell .event-card:hover { transform: none; }
    body.has-shell .event-card:active { background: color-mix(in srgb, var(--accent) 8%, var(--bg-elev)); }
    body.has-shell .event-card::after {
        content: ""; grid-area: chev; width: 9px; height: 9px; border-right: 2px solid var(--text-mute); border-top: 2px solid var(--text-mute);
        transform: rotate(45deg); justify-self: end; margin-right: 4px;
    }
    body.has-shell .event-date {
        grid-area: date; align-self: stretch; display: flex; align-items: center; justify-content: center; text-align: center;
        margin: 0; padding: 8px 4px; border-radius: 14px; font-size: 0.78rem; line-height: 1.15; letter-spacing: 0.02em;
        background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent);
    }
    body.has-shell .event-title { grid-area: title; font-size: 1.02rem; line-height: 1.25; }
    body.has-shell .event-meta { grid-area: meta; margin-top: 0; font-size: 0.82rem; }
    body.has-shell .event-host { grid-area: host; margin-top: 2px; }
    body.has-shell .event-card.has-wallpaper { background-size: cover; }
    /* The first upcoming card on the dashboard is the "up next" one. */
    body.has-shell[data-page="dashboard"] .section-title + .event-grid > .event-card:first-child { border-color: color-mix(in srgb, var(--accent) 45%, var(--border-soft)); box-shadow: 0 10px 30px -18px color-mix(in srgb, var(--accent) 60%, transparent); }

    /* Buttons & forms: thumb-sized. */
    body.has-shell .btn { min-height: 46px; padding: 11px 18px; border-radius: 999px; font-size: 0.95rem; }
    body.has-shell .btn-sm { min-height: 36px; padding: 7px 13px; font-size: 0.85rem; }
    body.has-shell .form input:not([type=checkbox]):not([type=radio]):not([type=range]), body.has-shell .form select, body.has-shell .form textarea,
    body.has-shell input[type=text], body.has-shell input[type=email], body.has-shell input[type=search], body.has-shell input[type=number], body.has-shell input[type=password], body.has-shell select {
        font-size: 16px; min-height: 46px; border-radius: 14px; padding: 10px 14px;
    }
    body.has-shell .form textarea { min-height: 96px; }
    body.has-shell .auth-card { padding: 24px 20px; margin-top: 8px; border-radius: 22px; }
    body.has-shell .items-toolbar { position: sticky; top: calc(var(--shell-top-h) + var(--shell-safe-t) + 8px); z-index: 5; background: var(--bg-elev); padding: 6px 0; }

    /* Modals become bottom sheets. */
    body.has-shell .share-modal-backdrop { align-items: flex-end; padding: 0; }
    body.has-shell .share-modal {
        max-width: none; border-radius: 22px 22px 0 0; padding: 18px 20px calc(20px + var(--shell-safe-b)); max-height: 86vh;
        animation: sheet-up .22s cubic-bezier(.2,.8,.2,1);
    }

    /* Toasts: bottom, above the tab bar — where a phone shows them. */
    body.has-shell .toast-container { top: auto; bottom: calc(var(--shell-tab-h) + var(--shell-safe-b) + 14px); width: calc(100vw - 24px); }
    body.has-shell .push-banner { bottom: calc(var(--shell-tab-h) + var(--shell-safe-b) + 14px); }

    /* ---------- Tab bar ---------- */
    body.has-shell .tabbar {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
        display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
        height: calc(var(--shell-tab-h) + var(--shell-safe-b)); padding: 0 4px var(--shell-safe-b);
        background: color-mix(in srgb, var(--bg-elev) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
        border-top: 1px solid color-mix(in srgb, var(--border-soft) 80%, transparent);
    }
    .tabbar .tab {
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        height: var(--shell-tab-h); color: var(--text-mute); font: 600 0.68rem/1 var(--body); letter-spacing: 0.01em;
        background: none; border: 0; padding: 0; cursor: pointer; text-decoration: none; -webkit-tap-highlight-color: transparent;
    }
    .tabbar .tab svg { width: 24px; height: 24px; stroke-width: 1.9; transition: transform .15s; }
    .tabbar .tab:active svg { transform: scale(.9); }
    .tabbar .tab.is-active { color: var(--accent); }
    .tabbar .tab.is-active svg { fill: color-mix(in srgb, var(--accent) 18%, transparent); }
    .tabbar .tab-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 2px transparent; transition: box-shadow .15s; }
    .tabbar .tab.is-active .tab-avatar { box-shadow: 0 0 0 2px var(--accent); }
    .tabbar .tab-new { color: var(--text-dim); }
    .tabbar .tab-fab {
        display: flex; align-items: center; justify-content: center; width: 46px; height: 46px; border-radius: 16px; margin-top: -22px;
        background: var(--accent); color: var(--accent-text); box-shadow: 0 10px 24px -8px color-mix(in srgb, var(--accent) 70%, transparent);
        transition: transform .15s;
    }
    .tabbar .tab-new:active .tab-fab { transform: scale(.94); }
    .tabbar .tab-fab svg { width: 24px; height: 24px; stroke-width: 2.4; }
    .tabbar .tab-badge { position: absolute; top: 6px; right: calc(50% - 20px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: var(--danger, #d64a3a); color: #fff; font-size: 0.62rem; line-height: 16px; text-align: center; }
    .tabbar .tab { position: relative; }

    /* ---------- Bottom sheet (More) ---------- */
    body.has-shell .sheet-backdrop[hidden] { display: none; }
    body.has-shell .sheet-backdrop {
        display: flex; align-items: flex-end; position: fixed; inset: 0; z-index: 1200;
        background: rgba(0,0,0,.45); animation: fade-in .15s;
    }
    .sheet {
        width: 100%; background: var(--bg-elev); border-radius: 22px 22px 0 0; padding: 8px 12px calc(14px + var(--shell-safe-b));
        box-shadow: 0 -10px 40px rgba(0,0,0,.25); animation: sheet-up .22s cubic-bezier(.2,.8,.2,1); max-height: 80vh; overflow-y: auto;
    }
    .sheet-grab { width: 38px; height: 4px; border-radius: 999px; background: var(--border); margin: 4px auto 12px; }
    .sheet-user { display: flex; align-items: center; gap: 12px; padding: 6px 8px 14px; }
    .sheet-user img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; }
    .sheet-user strong { display: block; font-size: 1rem; }
    .sheet-user span { font-size: 0.82rem; color: var(--text-dim); }
    .sheet-links { display: grid; gap: 2px; }
    .sheet-links a, .sheet-links button {
        display: flex; align-items: center; gap: 12px; padding: 13px 10px; border-radius: 12px; color: var(--text); font: 500 0.97rem var(--body);
        background: none; border: 0; text-align: left; width: 100%; text-decoration: none;
    }
    .sheet-links a:active, .sheet-links button:active { background: var(--bg-elev-2); }
    .sheet-links svg { width: 22px; height: 22px; color: var(--text-dim); flex: none; }
    .sheet-links .pro-chip { margin-left: auto; font-size: 0.68rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: color-mix(in srgb, var(--accent-2, var(--accent)) 22%, transparent); color: var(--text); }
    .sheet-sep { height: 1px; background: var(--border-soft); margin: 6px 4px; }
    .sheet .theme-switcher { display: flex; gap: 6px; padding: 8px 6px 2px; }
    .sheet .theme-switcher button { flex: 1; min-height: 40px; border-radius: 12px; border: 1px solid var(--border-soft); background: var(--bg); color: var(--text-dim); font: 600 0.88rem var(--body); }
    .sheet .theme-switcher button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
    .sheet-legal { display: flex; justify-content: center; gap: 14px; padding: 10px 0 0; font-size: 0.78rem; color: var(--text-mute); }
    .sheet-legal a { color: inherit; }

    /* ---------- Event page ---------- */
    body.has-shell .event-hero {
        margin: -16px -16px 12px; padding: 22px 18px 18px; border-radius: 0 0 24px 24px; display: block;
    }
    body.has-shell .event-hero h1 { font-size: 1.55rem; margin: 4px 0 8px; }
    body.has-shell .event-meta-row { gap: 8px 14px; font-size: 0.9rem; }
    body.has-shell .section-chips {
        display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 14px; padding: 2px 16px 6px; scroll-snap-type: x proximity;
    }
    body.has-shell .section-chips::-webkit-scrollbar { display: none; }
    .section-chips a {
        flex: none; scroll-snap-align: start; display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px;
        background: var(--bg-elev); border: 1px solid var(--border-soft); color: var(--text); font: 600 0.84rem var(--body); text-decoration: none; white-space: nowrap;
    }
    .section-chips a:active, .section-chips a.is-active { background: color-mix(in srgb, var(--accent) 14%, var(--bg-elev)); border-color: var(--accent); color: var(--accent); }
    .section-chips .chip-count { font-size: 0.72rem; color: var(--text-dim); }

    body.has-shell .rsvp-bar {
        position: fixed; left: 0; right: 0; bottom: calc(var(--shell-tab-h) + var(--shell-safe-b)); z-index: 999;
        display: flex; gap: 10px; align-items: center; padding: 10px 14px;
        background: color-mix(in srgb, var(--bg-elev) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
        border-top: 1px solid var(--border-soft);
    }
    .rsvp-bar .rsvp-bar-q { flex: 1 1 auto; min-width: 0; font-weight: 600; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .rsvp-bar .btn { flex: none; }
    body.has-shell:has(.rsvp-bar) .container { padding-bottom: calc(var(--shell-tab-h) + var(--shell-safe-b) + 96px); }
    body.has-shell .rsvp-card { border-radius: 18px; padding: 16px; }
}

@keyframes sheet-up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet, .share-modal, .sheet-backdrop { animation: none !important; } }
