/**
 * WaterJet PWA — install banner + app-like touch/scroll (standalone & mobile browser).
 * Disable via Admin → Settings → General → PWA checkboxes, or PWA_ENABLED=false in .env.
 */

/* ── Install banner (center modal) ── */
.wj-pwa-install {
    position: fixed;
    inset: 0;
    z-index: 10070;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(16px, env(safe-area-inset-top, 0px)) 16px max(16px, env(safe-area-inset-bottom, 0px));
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.28s ease, visibility 0.28s;
}

.wj-pwa-install.is-visible {
    pointer-events: auto;
    opacity: 1;
    visibility: visible;
}

.wj-pwa-install__card {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 380px;
    margin: 0 auto;
    transform: scale(0.94) translateY(8px);
    transition: transform 0.28s ease;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: 18px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.16);
    padding: 18px 16px 14px;
}

.wj-pwa-install.is-visible .wj-pwa-install__card {
    transform: scale(1) translateY(0);
}

.wj-pwa-install__backdrop {
    position: absolute;
    inset: 0;
    z-index: 0;
    background: rgba(15, 23, 42, 0.42);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.28s ease;
    border: none;
    padding: 0;
    cursor: pointer;
}

.wj-pwa-install.is-visible .wj-pwa-install__backdrop {
    opacity: 1;
}

.wj-pwa-install__close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 999px;
    background: #f1f5f9;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    z-index: 2;
}

.wj-pwa-install__row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-right: 28px;
    margin-bottom: 12px;
}

.wj-pwa-install__icon-wrap {
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: #fff;
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.wj-pwa-install__icon {
    width: 44px;
    height: 44px;
    object-fit: contain;
    display: block;
}

.wj-pwa-install__title {
    display: block;
    font-size: 0.98rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.25;
}

.wj-pwa-install__sub {
    display: block;
    font-size: 0.82rem;
    color: #64748b;
    margin-top: 2px;
    line-height: 1.35;
}

.wj-pwa-install__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.wj-pwa-install__btn {
    flex: 1 1 auto;
    min-height: 42px;
    border-radius: 12px;
    font-size: 0.88rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    touch-action: manipulation;
}

.wj-pwa-install__btn--primary {
    background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

.wj-pwa-install__btn--ghost {
    background: #f8fafc;
    color: #475569;
    border: 1px solid #e2e8f0;
}

.wj-pwa-install__ios-hint {
    margin: 10px 0 0;
    padding: 10px 12px;
    border-radius: 12px;
    background: #eff6ff;
    color: #1e40af;
    font-size: 0.82rem;
    line-height: 1.45;
}

.wj-pwa-install__ios-hint.is-open {
    display: block !important;
}

.wj-pwa-install[data-wj-pwa-mode="installed"] .wj-pwa-install__icon-wrap {
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.35);
}

.wj-pwa-install[data-wj-pwa-mode="installed"] .wj-pwa-install__title {
    color: #059669;
}

.wj-pwa-install__actions[hidden] {
    display: none !important;
}

html.wj-pwa-install-open body {
    overflow: hidden;
}

/* Already installed — hide banner */
html.wj-pwa-standalone .wj-pwa-install {
    display: none !important;
}

/* ── App-like touch & scroll (mobile + installed PWA) ── */
@media (max-width: 768px) {
    html.wj-ui {
        scroll-behavior: auto;
    }

    html.wj-ui body {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: none;
        touch-action: pan-y;
    }

    html.wj-ui .bc_wrap {
        overscroll-behavior-y: none;
    }

    html.wj-ui a,
    html.wj-ui button,
    html.wj-ui .nav-item,
    html.wj-ui .wj-route-card,
    html.wj-ui .wj-ticket-card__cta,
    html.wj-ui .mobile-bottom-nav .nav-item {
        touch-action: manipulation;
    }

    /* Horizontal carousels — snap like native app screens */
    html.wj-ui .wj-routes-scroll,
    html.wj-ui .wj-fleet-scroll,
    html.wj-ui .day-selector-scroll {
        scroll-snap-type: x mandatory;
        scroll-behavior: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        touch-action: pan-x pan-y;
    }

    html.wj-ui .wj-route-card,
    html.wj-ui .wj-fleet-card,
    html.wj-ui .day-selector-scroll > * {
        scroll-snap-align: start;
        scroll-snap-stop: always;
    }
}

/* Installed PWA — tighter app chrome */
html.wj-pwa-standalone body.wj-ui {
    overscroll-behavior: none;
    padding-top: env(safe-area-inset-top, 0);
}

html.wj-pwa-standalone body.wj-ui .bc_header {
    padding-top: env(safe-area-inset-top, 0);
}

html.wj-pwa-standalone body.wj-ui .mobile-bottom-nav {
    bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
}

@media (prefers-reduced-motion: reduce) {
    .wj-pwa-install {
        transition: none;
    }
}
