/* ═══════════════════════════════════════════════════════════════════
   Bayleaf PWA — splash screen + "Add to Home Screen" install UI
   Loaded on the storefront <head>. Kept in its own file so the service
   worker can precache it alongside the rest of the app shell.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Splash screen ─────────────────────────────────────────────────
   Server-rendered on first paint (no flash) and removed as soon as the
   app is ready. Only ever visible in standalone mode — a browser tab
   never shows it. */

#fb-pwa-splash {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    padding: 24px;
    background: #FFEB3B;
    background-image: linear-gradient(180deg, #FFEB3B 0%, #FFF3A0 100%);
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    transition: opacity .38s ease, visibility .38s ease;
    /* Respect notches / home indicators in standalone mode. */
    padding-top: max(24px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
}

/* Only paint the splash when actually launched as an installed app — a
   regular browser tab must never flash it. iOS reports standalone through
   `navigator.standalone` rather than `display-mode`, and pwa-install.js
   strips the node there. */
@media not all and (display-mode: standalone),
       not all and (display-mode: fullscreen),
       not all and (display-mode: minimal-ui) {
    #fb-pwa-splash { display: none; }
}

#fb-pwa-splash.fb-splash-hide {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.fb-splash-logo {
    width: 104px;
    height: 104px;
    border-radius: 26px;
    background: #0B6B3A;
    box-shadow: 0 14px 34px rgba(11, 107, 58, .32);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fbSplashPop .55s cubic-bezier(.2, .9, .3, 1.2);
    overflow: hidden;
}

.fb-splash-logo img {
    width: 76%;
    height: 76%;
    object-fit: contain;
    background: transparent;
}

.fb-splash-logo-fallback {
    width: 54px;
    height: 54px;
    color: #FFEB3B;
}

@keyframes fbSplashPop {
    from { opacity: 0; transform: scale(.82); }
    to   { opacity: 1; transform: scale(1); }
}

.fb-splash-name {
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -.01em;
    color: #0B6B3A;
    text-align: center;
}

.fb-splash-tagline {
    font-size: 13.5px;
    font-weight: 500;
    color: rgba(11, 107, 58, .72);
    margin-top: -12px;
    text-align: center;
}

.fb-splash-bar {
    width: 148px;
    height: 4px;
    border-radius: 999px;
    background: rgba(11, 107, 58, .16);
    overflow: hidden;
}

.fb-splash-bar::after {
    content: "";
    display: block;
    width: 45%;
    height: 100%;
    border-radius: 999px;
    background: #0B6B3A;
    animation: fbSplashSlide 1.15s cubic-bezier(.45, 0, .55, 1) infinite;
}

@keyframes fbSplashSlide {
    0%   { transform: translateX(-105%); }
    100% { transform: translateX(325%); }
}

@media (prefers-reduced-motion: reduce) {
    #fb-pwa-splash,
    .fb-splash-logo,
    .fb-splash-bar::after {
        transition: none;
        animation: none;
    }
    .fb-splash-bar::after { width: 100%; }
}

/* ── Install banner ──────────────────────────────────────────────── */

#fb-pwa-install,
#fb-pwa-reopen {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 99990;
    max-width: 440px;
    margin: 0 auto;
    background: #fff;
    border: 1px solid #E5E7EB;
    border-radius: 18px;
    box-shadow: 0 16px 44px rgba(0, 0, 0, .2);
    padding: 16px;
    display: none;
    animation: fbInstallIn .38s cubic-bezier(.2, .85, .3, 1);
}

#fb-pwa-install.fb-install-show,
#fb-pwa-reopen.fb-install-show { display: block; }

@keyframes fbInstallIn {
    from { opacity: 0; transform: translateY(26px); }
    to   { opacity: 1; transform: translateY(0); }
}

.fb-install-row {
    display: flex;
    align-items: flex-start;
    gap: 13px;
}

.fb-install-icon {
    width: 50px;
    height: 50px;
    border-radius: 13px;
    background: #0B6B3A;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 6px 14px rgba(11, 107, 58, .26);
}

.fb-install-icon img {
    width: 78%;
    height: 78%;
    object-fit: contain;
}

.fb-install-icon svg {
    width: 26px;
    height: 26px;
    color: #FFEB3B;
}

.fb-install-text { flex: 1; min-width: 0; }

.fb-install-text strong {
    display: block;
    font-size: 15px;
    font-weight: 700;
    color: #1A1A2E;
    line-height: 1.3;
}

.fb-install-text span {
    display: block;
    font-size: 13px;
    color: #6B7280;
    line-height: 1.45;
    margin-top: 3px;
}

.fb-install-close {
    background: transparent;
    border: none;
    color: #9CA3AF;
    cursor: pointer;
    padding: 4px;
    line-height: 0;
    border-radius: 8px;
    flex-shrink: 0;
}

.fb-install-close:hover { background: #F3F4F6; color: #4B5563; }

.fb-install-actions {
    display: flex;
    gap: 9px;
    margin-top: 14px;
}

.fb-install-btn {
    flex: 1;
    padding: 12px 16px;
    border-radius: 11px;
    border: none;
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background .18s ease, transform .12s ease;
}

.fb-install-btn:active { transform: scale(.98); }

.fb-install-btn[disabled] {
    opacity: .65;
    cursor: default;
    transform: none;
}

.fb-install-btn-primary {
    background: #0B6B3A;
    color: #fff;
    box-shadow: 0 6px 16px rgba(11, 107, 58, .24);
}

.fb-install-btn-primary:hover { background: #085229; }

.fb-install-btn-ghost {
    background: #F3F4F6;
    color: #4B5563;
}

.fb-install-btn-ghost:hover { background: #E5E7EB; }

.fb-install-steps {
    margin-top: 13px;
    padding: 12px 14px;
    background: #F8FAFB;
    border: 1px solid #E9ECEF;
    border-radius: 11px;
    font-size: 13px;
    color: #4B5563;
    line-height: 1.6;
}

.fb-install-steps ol { margin: 6px 0 0 18px; padding: 0; }
.fb-install-steps li { margin-bottom: 3px; }
.fb-install-steps b { color: #0B6B3A; }

/* ── First impression: unmissable ────────────────────────────────── */

/* Only the opening ask gets the full-weight treatment. Repeat reminders fall
   back to the quieter card so the site never nags. */
#fb-pwa-install.fb-install-first {
    padding: 20px;
    border-color: #0B6B3A;
    box-shadow: 0 22px 60px rgba(0, 0, 0, .26), 0 0 0 3px rgba(11, 107, 58, .12);
}

#fb-pwa-install.fb-install-first .fb-install-icon {
    width: 62px;
    height: 62px;
    border-radius: 16px;
}

#fb-pwa-install.fb-install-first .fb-install-icon img {
    width: 82%;
    height: 82%;
}

#fb-pwa-install.fb-install-first .fb-install-text strong { font-size: 17px; }

#fb-pwa-install.fb-install-first .fb-install-text span { font-size: 14px; }

#fb-pwa-install.fb-install-first .fb-install-btn {
    padding: 15px 18px;
    font-size: 15px;
}

@media (max-width: 420px) {
    #fb-pwa-install,
    #fb-pwa-reopen { left: 10px; right: 10px; padding: 14px; }
    .fb-install-actions { flex-direction: column; }
}

/* Keep the banner clear of the sticky mobile footer bar, when present. */
body.fb-has-sticky-footer #fb-pwa-install,
body.fb-has-sticky-footer #fb-pwa-reopen {
    bottom: calc(78px + env(safe-area-inset-bottom));
}

@media (prefers-reduced-motion: reduce) {
    #fb-pwa-install,
    #fb-pwa-reopen { animation: none; }
}

@media (prefers-color-scheme: dark) {
    #fb-pwa-install,
    #fb-pwa-reopen { background: #17281E; border-color: #24382B; }
    .fb-install-text strong { color: #EAF3EC; }
    .fb-install-text span { color: #9DB3A6; }
    .fb-install-close:hover { background: #24382B; color: #D6E5DB; }
    .fb-install-btn-ghost { background: #24382B; color: #D6E5DB; }
    .fb-install-btn-ghost:hover { background: #2E4938; }
    .fb-install-steps { background: #1C3025; border-color: #27402F; color: #B8CCBF; }
    #fb-pwa-install.fb-install-first {
        border-color: #2F8F55;
        box-shadow: 0 22px 60px rgba(0, 0, 0, .5), 0 0 0 3px rgba(47, 143, 85, .22);
    }
}

/* ── Offline toast ───────────────────────────────────────────────── */

#fb-pwa-net {
    position: fixed;
    left: 50%;
    transform: translateX(-50%) translateY(-140%);
    top: calc(10px + env(safe-area-inset-top));
    z-index: 99995;
    background: #4B5563;
    color: #fff;
    font-size: 13.5px;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: 999px;
    box-shadow: 0 8px 22px rgba(0, 0, 0, .22);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: transform .32s cubic-bezier(.2, .85, .3, 1);
    pointer-events: none;
    max-width: calc(100% - 24px);
}

#fb-pwa-net.fb-net-show { transform: translateX(-50%) translateY(0); }
#fb-pwa-net.fb-net-back { background: #0B6B3A; }
#fb-pwa-net svg { width: 16px; height: 16px; flex-shrink: 0; }
