/* ==========================================================
   App Shell — mobile-app style UX (keeps brand blue/white/gold)
   ========================================================== */
:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --appbar-h: 56px;
    --tabbar-h: 64px;
    --brand-900: #0f2b5c;
    --brand-600: #006ec7;
    --brand-500: #0c8de9;
    --gold: #fbbf24;
}

[x-cloak] { display: none !important; }

/* Hidden on desktop by default */
.app-tabbar, .app-ptr, .app-progress { display: none; }

/* Top progress bar (shown on all sizes during navigation) */
.app-progress {
    display: block;
    position: fixed; top: 0; left: 0; height: 3px; width: 0;
    background: linear-gradient(90deg, var(--gold), var(--brand-500));
    z-index: 9999; opacity: 0; pointer-events: none;
    transition: width .35s ease, opacity .25s ease;
}
.app-progress.active { opacity: 1; width: 75%; }
.app-progress.done { width: 100%; opacity: 0; }

/* Page transition for swapped content */
#main-content.app-enter { animation: appEnter .28s cubic-bezier(.22,.8,.3,1); }
@keyframes appEnter { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
#main-content.app-loading { opacity: .55; transition: opacity .15s; pointer-events: none; }

/* Skeleton shimmer */
.skeleton {
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 37%, #e2e8f0 63%);
    background-size: 400% 100%; animation: shimmer 1.3s ease infinite; border-radius: 14px;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.app-skeleton-wrap { padding: 16px; display: none; }
.app-skeleton-wrap .skeleton { margin-bottom: 12px; }

/* Bottom sheet (all sizes; trigger only exists on mobile) */
.app-sheet-backdrop {
    position: fixed; inset: 0; background: rgba(7,24,56,.55);
    backdrop-filter: blur(2px); z-index: 1090;
}
.app-sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1100;
    background: #fff; border-radius: 24px 24px 0 0;
    max-height: 85vh; overflow-y: auto; overscroll-behavior: contain;
    padding: 8px 16px calc(24px + var(--safe-bottom));
    box-shadow: 0 -12px 40px rgba(15,43,92,.25);
}
.app-sheet-handle { width: 40px; height: 5px; border-radius: 9px; background: #cbd5e1; margin: 6px auto 14px; }
.app-sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.app-sheet-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
    padding: 14px 6px; border-radius: 16px; background: #f8fafc; border: 1px solid #e2e8f0;
    font-size: 12px; font-weight: 600; color: #334155; text-align: center; line-height: 1.25;
    transition: transform .12s, background .12s; min-height: 84px;
}
.app-sheet-item i { font-size: 22px; color: var(--brand-600); }
.app-sheet-item:active { transform: scale(.95); background: #e0effe; }
.app-sheet-title { font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: #94a3b8; margin: 16px 4px 8px; }

/* Native App Hero Tiles for Mobile & Desktop */
.app-hero-tile {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 12px 6px !important;
    background: #ffffff;
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: 18px !important;
    box-shadow: 0 2px 10px rgba(15, 43, 92, 0.04);
    text-align: center !important;
    text-decoration: none !important;
    user-select: none;
    -webkit-user-select: none;
    min-height: 88px;
    transition: transform 0.18s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.18s, border-color 0.18s;
}
.app-hero-tile:active { transform: scale(0.94); background: #f8fafc; }
@media (hover: hover) and (pointer: fine) {
    .app-hero-tile:hover {
        transform: translateY(-3px);
        box-shadow: 0 10px 24px rgba(15, 43, 92, 0.10);
        border-color: rgba(14, 165, 233, 0.35);
        text-decoration: none;
    }
}
@media (min-width: 640px) {
    .app-hero-tile {
        padding: 16px 10px !important;
        border-radius: 20px !important;
        min-height: 104px;
    }
    .app-hero-icon-box {
        width: 50px !important;
        height: 50px !important;
        min-width: 50px !important;
        min-height: 50px !important;
        max-width: 50px !important;
        max-height: 50px !important;
        font-size: 22px !important;
        margin-bottom: 8px !important;
    }
    .app-hero-tile-title {
        font-size: 13px !important;
    }
    .app-hero-tile-badge {
        font-size: 10px !important;
        padding: 2px 8px !important;
    }
}
.app-hero-icon-box {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    max-width: 44px !important;
    max-height: 44px !important;
    border-radius: 14px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 20px !important;
    color: #ffffff !important;
    margin: 0 auto 6px !important;
    flex-shrink: 0 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.app-hero-tile-title {
    font-size: 11.5px;
    font-weight: 700;
    color: #1e293b;
    line-height: 1.25;
    white-space: nowrap;
    text-align: center;
    display: block;
    width: 100%;
}
.app-hero-tile-badge {
    font-size: 9px;
    font-weight: 800;
    color: #0f2b5c;
    background: #fef3c7;
    padding: 1px 6px;
    border-radius: 6px;
    margin-top: 3px;
    display: inline-block;
}

/* ================= Mobile / tablet only ================= */
@media (max-width: 1023px) {
    html { -webkit-tap-highlight-color: transparent; }
    body { overscroll-behavior-y: contain; padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 80px); }
    input, select, textarea { font-size: 16px !important; }
    button, a, .touch-target { touch-action: manipulation; }
    footer.site-footer { display: none !important; }
    .card-custom:hover { transform: none; }

    /* Compact top app bar */
    header.app-appbar { padding-top: var(--safe-top); }
    header.app-appbar .app-appbar-row { height: var(--appbar-h) !important; }

    /* Bottom tab bar */
    .app-tabbar {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1050;
        height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
        background: rgba(255,255,255,.94); backdrop-filter: blur(16px) saturate(1.4);
        -webkit-backdrop-filter: blur(16px) saturate(1.4);
        border-top: 1px solid rgba(15,43,92,.08);
        box-shadow: 0 -6px 24px rgba(15,43,92,.08);
    }
    .app-tab {
        flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
        gap: 2px; font-size: 10.5px; font-weight: 600; color: #64748b; position: relative;
        background: none; border: 0; transition: color .15s;
    }
    .app-tab i { font-size: 21px; transition: transform .2s cubic-bezier(.3,1.6,.5,1); }
    .app-tab:active i { transform: scale(.85); }
    .app-tab.active { color: var(--brand-900); }
    .app-tab.active i { color: var(--brand-600); transform: translateY(-2px); }
    .app-tab.active::before {
        content: ""; position: absolute; top: 0; width: 28px; height: 3px;
        border-radius: 0 0 4px 4px; background: linear-gradient(90deg, var(--gold), #f59e0b);
    }
    .app-tab .tab-badge {
        position: absolute; top: 6px; left: calc(50% + 6px); min-width: 16px; height: 16px; padding: 0 4px;
        background: #e11d48; color: #fff; border-radius: 9px; font-size: 9px; font-weight: 800;
        display: none; align-items: center; justify-content: center;
    }

    /* Center scan check-in button (authenticated users only) —
       sits fully inside the tab bar (no protrusion); prominent via size + brand icon color */
    .app-tab-scan {
        flex: 0 0 64px;
        align-self: center;
        width: 56px; height: 56px;
        margin: 0 2px;
        border-radius: 9999px;
        background: #fff;
        display: flex; align-items: center; justify-content: center;
        transition: transform .2s cubic-bezier(.3, 1.6, .5, 1);
    }
    .app-tab-scan i { font-size: 40px; color: var(--brand-600); }
    .app-tab-scan:active { transform: scale(.92); }
    .app-tab-scan.active::before { display: none; }

    /* Lift floating UI above the tab bar / Hide back-to-top FAB on mobile */
    #toastContainer { top: calc(var(--appbar-h) + var(--safe-top) + 8px) !important; bottom: auto !important; right: 0; left: 0; margin: 0 auto; }
    .sticky-bottom-action { bottom: calc(var(--tabbar-h) + var(--safe-bottom)) !important; }
    .app-fab-lift { display: none !important; }

    /* Pull to refresh indicator */
    .app-ptr {
        display: flex; position: fixed; top: calc(var(--appbar-h) + var(--safe-top)); left: 50%;
        width: 40px; height: 40px; margin-left: -20px; border-radius: 50%;
        background: #fff; color: var(--brand-600); align-items: center; justify-content: center;
        box-shadow: 0 6px 20px rgba(15,43,92,.2); z-index: 1060;
        transform: translateY(-80px); opacity: 0;
    }
    .app-ptr.spin i { animation: ptrSpin .7s linear infinite; }
    @keyframes ptrSpin { to { transform: rotate(360deg); } }

    /* App-like content feel */
    main#main-content > div { padding-top: 14px !important; }
    .rounded-2xl { border-radius: 20px; }
    .app-skeleton-wrap.show { display: block; }
}

@media (min-width: 1024px) {
    .app-sheet, .app-sheet-backdrop { display: none !important; }
}
