/* ==========================================================================
   Installed-app (PWA) look and feel
   Most rules apply only when the site runs as an installed app: html gets the
   .pwa-standalone class from the inline script in base.html (covers iOS,
   which does not support the display-mode media query reliably).
   ========================================================================== */

:root {
    --pwa-brand: #667eea;
    --pwa-brand-2: #764ba2;
    --pwa-tabbar-h: 64px;
    --pwa-safe-top: env(safe-area-inset-top, 0px);
    --pwa-safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ─── Page-load progress bar (all modes) ─────────────────────────────────── */
#pwa-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0;
    z-index: 2000;
    background: linear-gradient(90deg, var(--pwa-brand), var(--pwa-brand-2));
    box-shadow: 0 0 8px rgba(102, 126, 234, 0.6);
    opacity: 0;
    transition: width 0.4s ease, opacity 0.3s ease;
    pointer-events: none;
}
#pwa-progress.active { opacity: 1; width: 80%; transition: width 8s cubic-bezier(0.1, 0.7, 0.2, 1), opacity 0.2s; }
#pwa-progress.done { opacity: 0; width: 100%; transition: width 0.2s ease, opacity 0.4s ease 0.2s; }

/* ─── Install banner / update toast / network status (all modes) ─────────── */
.pwa-banner {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + var(--pwa-safe-bottom));
    z-index: 1060;
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 18px;
    background: #fff;
    color: #1f2937;
    box-shadow: 0 12px 36px rgba(31, 41, 55, 0.22);
    transform: translateY(150%);
    transition: transform 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
.pwa-banner.show { transform: translateY(0); }
.pwa-banner img { width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0; }
.pwa-banner .pwa-banner-text { flex: 1; min-width: 0; font-size: 0.9rem; line-height: 1.3; }
.pwa-banner .pwa-banner-text strong { display: block; font-size: 0.95rem; }
.pwa-banner .pwa-banner-text small { color: #6b7280; }
/* Self-contained (some landing pages don't load Bootstrap) */
.pwa-banner .btn {
    border: 0;
    border-radius: 12px;
    padding: 8px 16px;
    font-size: 0.875rem;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--pwa-brand), var(--pwa-brand-2));
    white-space: nowrap;
    cursor: pointer;
}
.pwa-banner[hidden] { display: none; }
.pwa-banner .pwa-banner-close {
    border: 0;
    background: transparent;
    color: #9ca3af;
    font-size: 1.25rem;
    line-height: 1;
    padding: 4px;
}

.pwa-net-status {
    position: fixed;
    top: calc(8px + var(--pwa-safe-top));
    left: 50%;
    z-index: 2001;
    transform: translate(-50%, -200%);
    padding: 6px 16px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
    background: #374151;
    transition: transform 0.3s ease;
    pointer-events: none;
}
.pwa-net-status.show { transform: translate(-50%, 0); }
.pwa-net-status.online { background: #059669; }

/* ─── Bottom tab bar (installed app on phones/tablets only) ──────────────── */
.pwa-tabbar { display: none; }

@media (max-width: 991.98px) {
    html.pwa-standalone .pwa-tabbar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1040;
        display: flex;
        justify-content: space-around;
        align-items: stretch;
        height: calc(var(--pwa-tabbar-h) + var(--pwa-safe-bottom));
        padding-bottom: var(--pwa-safe-bottom);
        background: rgba(255, 255, 255, 0.96);
        -webkit-backdrop-filter: saturate(180%) blur(16px);
        backdrop-filter: saturate(180%) blur(16px);
        border-top: 1px solid rgba(0, 0, 0, 0.06);
        box-shadow: 0 -4px 20px rgba(31, 41, 55, 0.06);
    }
    html.pwa-standalone .pwa-tabbar a,
    html.pwa-standalone .pwa-tabbar button {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        border: 0;
        background: transparent;
        color: #6b7280;
        font-size: 0.7rem;
        font-weight: 600;
        text-decoration: none;
        -webkit-tap-highlight-color: transparent;
    }
    html.pwa-standalone .pwa-tabbar i { font-size: 1.25rem; transition: transform 0.2s ease; }
    html.pwa-standalone .pwa-tabbar .active { color: var(--pwa-brand); }
    html.pwa-standalone .pwa-tabbar .active i { transform: translateY(-2px) scale(1.1); }
    html.pwa-standalone .pwa-tabbar a:active i,
    html.pwa-standalone .pwa-tabbar button:active i { transform: scale(0.88); }

    /* Room for the tab bar, and lift floating widgets above it */
    html.pwa-standalone body { padding-bottom: calc(var(--pwa-tabbar-h) + var(--pwa-safe-bottom)); }
    html.pwa-standalone .floating-chat-btn { bottom: calc(var(--pwa-tabbar-h) + 16px + var(--pwa-safe-bottom)); }
    html.pwa-standalone .chat-modal { bottom: calc(var(--pwa-tabbar-h) + 88px + var(--pwa-safe-bottom)); }
    html.pwa-standalone .warmth-toast,
    html.pwa-standalone .pwa-banner { bottom: calc(var(--pwa-tabbar-h) + 12px + var(--pwa-safe-bottom)); }

    /* An app has no website footer; menu and pages are reached via the tab bar */
    html.pwa-standalone .saas-footer { display: none; }

    /* Compact app header */
    html.pwa-standalone .saas-navbar { padding-top: calc(4px + var(--pwa-safe-top)); padding-bottom: 4px; }
    html.pwa-standalone .saas-navbar .logo-icon { width: 132px; height: 45px; object-fit: contain; }
    /* The tab bar's Menu button opens the same menu */
    html.pwa-standalone .saas-navbar .navbar-toggler { display: none; }
    html.pwa-standalone .saas-navbar .navbar-collapse {
        max-height: calc(100vh - 120px - var(--pwa-safe-top) - var(--pwa-tabbar-h));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* iOS zooms into inputs smaller than 16px */
    html.pwa-standalone input,
    html.pwa-standalone select,
    html.pwa-standalone textarea { font-size: max(16px, 1em); }
}

/* ─── Native-feeling touches (installed app, any size) ───────────────────── */
html.pwa-standalone {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
html.pwa-standalone body {
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
}
html.pwa-standalone .saas-navbar,
html.pwa-standalone .pwa-tabbar {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
html.pwa-standalone .btn:active { transform: scale(0.97); }

/* Back button: an installed app has no browser back button (esp. iOS) */
.pwa-back-btn { display: none; }
html.pwa-standalone.pwa-can-go-back .pwa-back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    margin-right: 4px;
    border: 0;
    border-radius: 50%;
    background: rgba(102, 126, 234, 0.1);
    color: var(--pwa-brand);
    font-size: 1rem;
}
html.pwa-standalone.pwa-can-go-back .pwa-back-btn:active { background: rgba(102, 126, 234, 0.22); }

/* Soft fade-in on each page, like an app screen transition */
@media (prefers-reduced-motion: no-preference) {
    /* opacity only: a transform would re-anchor fixed children (modals) */
    html.pwa-standalone #main-content { animation: pwa-screen-in 0.25s ease-out; }
    @keyframes pwa-screen-in {
        from { opacity: 0; }
        to { opacity: 1; }
    }
}

/* ─── "Rotate your phone" overlay (pages with data-orientation) ──────────── */
.pwa-rotate {
    position: fixed;
    inset: 0;
    z-index: 2100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(16px, var(--pwa-safe-top)) 16px max(16px, var(--pwa-safe-bottom));
    background: rgba(17, 24, 39, 0.92);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}
.pwa-rotate[hidden] { display: none; }
.pwa-rotate-card {
    width: 100%;
    max-width: 340px;
    padding: 28px 22px 20px;
    border-radius: 24px;
    background: #fff;
    color: #1f2937;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
.pwa-rotate-card h2 { font-size: 1.3rem; font-weight: 700; margin: 14px 0 6px; }
.pwa-rotate-card p { font-size: 0.95rem; color: #4b5563; margin: 0 0 16px; line-height: 1.45; }
.pwa-rotate-phone {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 84px;
    height: 84px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--pwa-brand), var(--pwa-brand-2));
    color: #fff;
    font-size: 2.4rem;
}
@media (prefers-reduced-motion: no-preference) {
    .pwa-rotate-phone i { animation: pwa-rotate-hint 2.2s ease-in-out infinite; }
    @keyframes pwa-rotate-hint {
        0%, 20% { transform: rotate(0deg); }
        50%, 70% { transform: rotate(-90deg); }
        100% { transform: rotate(0deg); }
    }
}
.pwa-rotate-primary,
.pwa-rotate-secondary {
    display: block;
    width: 100%;
    min-height: 48px;
    border: 0;
    border-radius: 14px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}
.pwa-rotate-primary { color: #fff; background: linear-gradient(135deg, var(--pwa-brand), var(--pwa-brand-2)); margin-bottom: 14px; }
.pwa-rotate-primary[hidden] { display: none; }
.pwa-rotate-secondary { color: #6b7280; background: #f3f4f6; margin-top: 4px; }
.pwa-rotate-help { display: none; font-size: 0.85rem !important; }
.pwa-rotate[data-os="android"] .pwa-rotate-help[data-os="android"],
.pwa-rotate[data-os="ios"] .pwa-rotate-help[data-os="ios"] { display: block; }
/* Short landscape screens: keep the card scrollable */
@media (max-height: 420px) {
    .pwa-rotate { align-items: flex-start; overflow-y: auto; }
}

/* ─── Site-wide mobile fixes (all modes) ─────────────────────────────────── */
/* "Skip to main content" had no styles and showed as text above every page */
.skip-to-content {
    position: absolute;
    left: 8px;
    top: -60px;
    z-index: 2200;
    padding: 10px 16px;
    border-radius: 10px;
    background: var(--pwa-brand);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
}
.skip-to-content:focus { top: calc(8px + var(--pwa-safe-top)); color: #fff; }

/* Main + fixed sidebar grids (inline styles) stack into one column on phones */
@media (max-width: 767.98px) {
    .stack-on-mobile { grid-template-columns: 1fr !important; }
}

/* Full-width Bootstrap button groups (rating / Likert radios) never wrap and
   ran off screen; on phones let them wrap into rows of separate buttons */
@media (max-width: 575.98px) {
    .btn-group.w-100 { flex-wrap: wrap; gap: 6px; }
    .btn-group.w-100 > .btn {
        flex: 1 1 calc(33.333% - 6px);
        margin-left: 0 !important;
        border-radius: 10px !important;
        white-space: normal;
        min-height: 44px;
    }
}
