/* =========================================================================
   PWA layer — toasts, connection banner, installed-mode chrome, safe areas.
   Loaded globally (frontend + user panel) from partials/pwa_head.blade.php.
   ========================================================================= */

/* --- toast: install offer, update available, push permission --- */
.pwa-toast {
    position: fixed;
    left: 50%;
    bottom: 16px;
    transform: translate(-50%, 24px);
    width: min(420px, calc(100% - 24px));
    background: #fff;
    border: 1px solid #e6e8eb;
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(16, 24, 40, .18);
    padding: .9rem 1rem calc(.9rem + env(safe-area-inset-bottom));
    z-index: 2000;
    opacity: 0;
    transition: opacity .22s ease, transform .22s ease;
}

.pwa-toast.is-open {
    opacity: 1;
    transform: translate(-50%, 0);
}

.pwa-toast__body {
    font-size: .88rem;
    color: #1f2a37;
}

.pwa-toast__body strong {
    display: block;
    font-size: .95rem;
    margin-bottom: .15rem;
}

.pwa-toast__body span {
    display: block;
    color: #6b7280;
    font-size: .82rem;
    line-height: 1.5;
}

.pwa-toast__actions {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    margin-top: .75rem;
}

.pwa-toast__btn {
    border: 1px solid #e6e8eb;
    background: #fff;
    color: #1f2a37;
    border-radius: 999px;
    padding: .38rem .9rem;
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
}

.pwa-toast__btn.is-primary {
    background: #1b5e4b;
    border-color: #1b5e4b;
    color: #fff;
}

.pwa-toast__btn:hover {
    filter: brightness(.96);
}

.pwa-toast__btn:focus-visible {
    outline: 2px solid #1b5e4b;
    outline-offset: 2px;
}

/* --- connection banner --- */
.pwa-netbar {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    background: #c0392b;
    color: #fff;
    text-align: center;
    font-size: .82rem;
    font-weight: 600;
    padding: .4rem .75rem;
    padding-top: calc(.4rem + env(safe-area-inset-top));
    z-index: 2100;
}

.pwa-netbar.is-online {
    background: #1a7f4b;
}

/* --- installed (standalone) mode --- */
/* The marketing chrome belongs to the website; the installed app doesn't need it. */
.pwa-standalone .footer,
.pwa-standalone .wtb-footer,
.pwa-standalone .cookies-card {
    display: none !important;
}

/* The installed app already has persistent primary navigation. Keeping the
   public-site header and hamburger above it makes the WebAPK feel like a web
   page inside a shell and wastes the most valuable part of a phone screen. */
.pwa-standalone .header,
.pwa-standalone .wtb-header,
.pwa-standalone .dashboard-nav {
    display: none !important;
}

/* Respect notches, dynamic island and the home indicator */
.pwa-standalone body {
    padding-bottom: env(safe-area-inset-bottom);
}

.pwa-standalone .header,
.pwa-standalone .wtb-header,
.pwa-standalone .dashboard-sidebar {
    padding-top: env(safe-area-inset-top);
}

/* An "Install app" entry is meaningless once installed — pwa.js also hides these. */
.pwa-standalone [data-pwa-install] {
    display: none !important;
}

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

/* =========================================================================
   Installed-app shell — mobile bottom tabs + desktop rail.
   Rendered on every page but only visible under .pwa-standalone, so the
   public website is untouched for browser visitors.
   ========================================================================= */

.pwa-tabbar,
.pwa-rail { display: none; }

/* ---------------------------- mobile: bottom tab bar ---------------------- */
.pwa-standalone .pwa-tabbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    border-top: 1px solid #e6e8eb;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 1040;
}

.pwa-tab {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: .5rem .25rem .45rem;
    color: #6b7280;
    text-decoration: none;
    font-size: .68rem;
    font-weight: 600;
    line-height: 1.2;
    min-height: 58px;
    -webkit-tap-highlight-color: rgba(27, 94, 75, .12);
    touch-action: manipulation;
}

.pwa-tab__icon { position: relative; font-size: 1.35rem; line-height: 1; }

.pwa-tab__label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pwa-tab.is-active { color: #1b5e4b; }
.pwa-tab:hover { color: #1b5e4b; text-decoration: none; }
.pwa-tab:active { background: #f1f7f5; }
.pwa-tab:focus-visible { outline: 2px solid #1b5e4b; outline-offset: -2px; }

.pwa-tab__badge,
.pwa-rail__badge {
    position: absolute;
    top: -4px;
    right: -8px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border-radius: 999px;
    background: #c0392b;
    color: #fff;
    font-size: .62rem;
    font-weight: 700;
    line-height: 17px;
    text-align: center;
}

/* keep page content clear of the bar */
.pwa-standalone body { padding-bottom: calc(58px + env(safe-area-inset-bottom)); }

/* ------------------------------ desktop: left rail ------------------------ */
@media (min-width: 992px) {
    .pwa-standalone .pwa-tabbar { display: none; }
    .pwa-standalone body { padding-bottom: env(safe-area-inset-bottom); padding-left: 248px; }

    .pwa-standalone .pwa-rail {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 248px;
        background: #fff;
        border-right: 1px solid #e6e8eb;
        padding: 1rem .75rem calc(1rem + env(safe-area-inset-bottom));
        padding-top: calc(1rem + env(safe-area-inset-top));
        overflow-y: auto;
        z-index: 1040;
    }

    .pwa-rail__brand { display: block; padding: .25rem .5rem 1rem; }
    .pwa-rail__brand img { max-height: 34px; width: auto; }

    .pwa-rail__nav { display: flex; flex-direction: column; gap: 2px; }

    .pwa-rail__link {
        position: relative;
        display: flex;
        align-items: center;
        gap: .65rem;
        padding: .6rem .7rem;
        border-radius: 10px;
        color: #1f2a37;
        text-decoration: none;
        font-size: .88rem;
        font-weight: 600;
    }

    .pwa-rail__link i { font-size: 1.15rem; color: #6b7280; width: 1.3rem; text-align: center; }
    .pwa-rail__link:hover { background: #f3f6f5; color: #1b5e4b; text-decoration: none; }
    .pwa-rail__link:hover i { color: #1b5e4b; }
    .pwa-rail__link:focus-visible { outline: 2px solid #1b5e4b; outline-offset: 1px; }

    .pwa-rail__link.is-active { background: #eaf3f0; color: #1b5e4b; }
    .pwa-rail__link.is-active i { color: #1b5e4b; }

    .pwa-rail__badge { position: static; margin-left: auto; }

    .pwa-rail__sep { margin: .75rem .5rem; border: 0; border-top: 1px solid #eef1f0; }
    .pwa-rail__logout { margin-top: auto; color: #6b7280; }

    /* the rail replaces the site header/user sidebar in installed mode */
    .pwa-standalone .header,
    .pwa-standalone .wtb-header,
    .pwa-standalone .dashboard-sidebar { display: none !important; }
    .pwa-standalone .dashboard-wrapper { margin-left: 0 !important; width: 100% !important; }
}

/* ------------------------------- share button ---------------------------- */
.pwa-share {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    border: 1px solid #e6e8eb;
    background: #fff;
    color: #1f2a37;
    border-radius: 999px;
    padding: .4rem .9rem;
    font-size: .84rem;
    font-weight: 600;
    cursor: pointer;
}

.pwa-share:hover { background: #f3f6f5; color: #1b5e4b; }
.pwa-share:focus-visible { outline: 2px solid #1b5e4b; outline-offset: 2px; }

/* ---------------- keep floating UI clear of the installed-app tab bar ------- */
@media (max-width: 991.98px) {
    /* The tab bar owns the bottom of the screen in installed mode, so anything
       floating there (AI chat launcher, cookie card, toasts) has to move up. */
    .pwa-standalone .ai-chat-widget,
    .pwa-standalone .cookies-card {
        bottom: calc(66px + env(safe-area-inset-bottom)) !important;
    }

    .pwa-standalone .pwa-toast {
        bottom: calc(66px + env(safe-area-inset-bottom));
    }
}

/* The panel's hamburger opens a sidebar the rail has replaced — hide it. */
.pwa-standalone .dash-sidebar-toggler { display: none !important; }

/* --------- toast must clear the floating chat launcher on narrow screens ---- */
/* The launcher is a 56px circle pinned bottom-right; a bottom-centred toast
   would otherwise run underneath it and swallow the primary action. */
@media (max-width: 991.98px) {
    .pwa-toast { bottom: calc(88px + env(safe-area-inset-bottom)); }
    .pwa-standalone .pwa-toast { bottom: calc(134px + env(safe-area-inset-bottom)); }
}
