/* ==========================================================================
   Notes Hub PWA — install prompt, update prompt, network toast
   ========================================================================== */

/* ── Install banner ─────────────────────────────────────────── */
.noteshub-pwa-install {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    width: min(480px, calc(100vw - 32px));
    background: var(--nh-bg, #fff);
    color: var(--nh-text, #0f172a);
    border: 1px solid var(--nh-border, #e2e8f0);
    border-radius: 16px;
    box-shadow: 0 25px 60px -20px rgba(15, 23, 42, .35);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    opacity: 0;
    transition: opacity .3s ease, transform .35s cubic-bezier(.16, 1, .3, 1);
    /*
     * BUGFIX: was 100040, which sat ABOVE the mobile drawer (100000) in
     * theme.css. Opening the site menu left the install banner floating on
     * top of the blurred backdrop, untappable. Placed below every modal
     * layer (drawer 100000, auth 100050, pickers 100150) but above normal
     * page content and the sticky header (9990).
     */
    z-index: 9995;
    pointer-events: none;
    font-family: var(--nh-font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
}
.noteshub-pwa-install.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.noteshub-pwa-install-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    overflow: hidden;
    flex-shrink: 0;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    box-shadow: 0 6px 16px -4px rgba(99, 102, 241, .4);
}
.noteshub-pwa-install-icon img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
}

.noteshub-pwa-install-body { flex: 1; min-width: 0; }
.noteshub-pwa-install-title {
    display: block;
    font-size: 14px;
    font-weight: 800;
    color: var(--nh-text, #0f172a);
    letter-spacing: -0.01em;
    margin-bottom: 2px;
}
.noteshub-pwa-install-text {
    font-size: 12.5px;
    color: var(--nh-text-muted, #64748b);
    margin: 0;
    line-height: 1.4;
}

.noteshub-pwa-install-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.noteshub-pwa-install-skip,
.noteshub-pwa-install-go {
    border: none;
    border-radius: 10px;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    line-height: 1;
    transition: transform .1s ease, opacity .15s ease;
    white-space: nowrap;
}
.noteshub-pwa-install-skip {
    background: transparent;
    color: var(--nh-text-muted, #64748b);
}
.noteshub-pwa-install-skip:hover { color: var(--nh-text, #0f172a); }
.noteshub-pwa-install-go {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    box-shadow: 0 4px 12px -4px rgba(99, 102, 241, .5);
}
.noteshub-pwa-install-go:hover { transform: translateY(-1px); }
.noteshub-pwa-install-go:active { transform: translateY(0) scale(.97); }

/* ── Update prompt ──────────────────────────────────────────── */
.noteshub-pwa-update {
    position: fixed;
    top: calc(16px + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    width: min(460px, calc(100vw - 32px));
    background: var(--nh-bg, #fff);
    color: var(--nh-text, #0f172a);
    border: 1px solid var(--nh-border, #e2e8f0);
    border-radius: 14px;
    box-shadow: 0 20px 50px -20px rgba(15, 23, 42, .3);
    padding: 12px 14px 12px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    opacity: 0;
    transition: opacity .3s ease, transform .35s cubic-bezier(.16, 1, .3, 1);
    /* BUGFIX: same z-index reasoning as .noteshub-pwa-install above. */
    z-index: 9995;
    pointer-events: none;
    font-family: var(--nh-font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
}
.noteshub-pwa-update.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.noteshub-pwa-update-body { flex: 1; min-width: 0; }
.noteshub-pwa-update-body strong {
    display: block;
    font-size: 14px;
    font-weight: 800;
    color: var(--nh-text, #0f172a);
    margin-bottom: 2px;
}
.noteshub-pwa-update-body p {
    font-size: 12.5px;
    color: var(--nh-text-muted, #64748b);
    margin: 0;
    line-height: 1.4;
}

.noteshub-pwa-update-go {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 9px 18px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    line-height: 1;
    flex-shrink: 0;
    box-shadow: 0 4px 12px -4px rgba(99, 102, 241, .5);
    transition: transform .1s ease, opacity .15s ease;
}
.noteshub-pwa-update-go:hover { transform: translateY(-1px); }
.noteshub-pwa-update.loading .noteshub-pwa-update-go {
    opacity: .6;
    pointer-events: none;
}
.noteshub-pwa-update.loading .noteshub-pwa-update-go::after {
    content: '';
    display: inline-block;
    width: 10px; height: 10px;
    border: 2px solid rgba(255, 255, 255, .4);
    border-top-color: #fff;
    border-radius: 50%;
    margin-left: 8px;
    vertical-align: middle;
    animation: noteshub-pwa-spin .7s linear infinite;
}
@keyframes noteshub-pwa-spin { to { transform: rotate(360deg); } }

/* ── Network toast ──────────────────────────────────────────── */
.noteshub-pwa-toast {
    position: fixed;
    /*
     * BUGFIX: was the same `bottom` as .noteshub-pwa-install, so a
     * "Back online" toast shown while the install banner was visible landed
     * directly on top of it. Offset higher so the two coexist.
     */
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    background: #0f172a;
    color: #fff;
    padding: 11px 20px;
    border-radius: 999px;
    font-size: 13.5px;
    font-weight: 700;
    box-shadow: 0 12px 30px -8px rgba(15, 23, 42, .5);
    opacity: 0;
    transition: opacity .25s ease, transform .3s cubic-bezier(.16, 1, .3, 1);
    /* BUGFIX: moved below the mobile drawer (100000). */
    z-index: 9996;
    pointer-events: none;
    font-family: var(--nh-font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
    max-width: calc(100vw - 32px);
    text-align: center;
}
.noteshub-pwa-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.noteshub-pwa-toast.warn { background: #b45309; }
.noteshub-pwa-toast.success { background: #047857; }

/* ── Standalone mode adjustments ────────────────────────────── */
html.noteshub-standalone body {
    /* Add extra top padding for status bar on iOS */
    padding-top: env(safe-area-inset-top, 0px);
}
html.noteshub-standalone .noteshub-header {
    top: env(safe-area-inset-top, 0px);
}
html.noteshub-standalone .noteshub-pwa-install { display: none !important; }

/* ── Offline state body class ───────────────────────────────── */
html.noteshub-offline .noteshub-header {
    filter: saturate(.7);
}
html.noteshub-offline::before {
    /*
     * BUGFIX: the content was hardcoded English. CSS `content` can't go
     * through esc_html_e()/__() directly, so surface it via a custom
     * property that PHP (wp_add_inline_style) or JS can set on <html>.
     * Falls back to the original English string so nothing regresses.
     *
     * Set from PHP like:
     *   wp_add_inline_style( 'noteshub-pwa', ':root{--nh-offline-label:"' .
     *     esc_js( __( '📴 Offline', 'notes-hub' ) ) . '";}' );
     */
    content: var(--nh-offline-label, '📴 Offline');
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 8px);
    right: calc(env(safe-area-inset-right, 0px) + 12px);
    background: #b45309;
    color: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 800;
    /* BUGFIX: moved below the mobile drawer (100000). */
    z-index: 9997;
    letter-spacing: .3px;
    font-family: var(--nh-font, sans-serif);
    pointer-events: none;
}

/* ── Dark mode overrides ────────────────────────────────────── */
html.nh-dark .noteshub-pwa-install,
html.nh-dark .noteshub-pwa-update {
    background: #1e293b;
    border-color: #334155;
    color: #f8fafc;
}
html.nh-dark .noteshub-pwa-install-title,
html.nh-dark .noteshub-pwa-update-body strong { color: #f8fafc; }
html.nh-dark .noteshub-pwa-install-text,
html.nh-dark .noteshub-pwa-update-body p { color: #94a3b8; }
html.nh-dark .noteshub-pwa-install-skip { color: #94a3b8; }
html.nh-dark .noteshub-pwa-install-skip:hover { color: #f8fafc; }

/* ── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .noteshub-pwa-install {
        left: 12px;
        right: 12px;
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        width: auto;
        transform: translateY(20px);
        padding: 12px 14px;
    }
    .noteshub-pwa-install.show { transform: translateY(0); }

    .noteshub-pwa-install-icon { width: 42px; height: 42px; }
    .noteshub-pwa-install-title { font-size: 13.5px; }
    .noteshub-pwa-install-text { font-size: 12px; }
    .noteshub-pwa-install-skip,
    .noteshub-pwa-install-go { padding: 8px 12px; font-size: 12.5px; }

    .noteshub-pwa-update {
        left: 12px;
        right: 12px;
        top: calc(12px + env(safe-area-inset-top, 0px));
        width: auto;
        transform: translateY(-20px);
    }
    .noteshub-pwa-update.show { transform: translateY(0); }
}

/*
 * BUGFIX: the original nested this @media inside @media (max-width: 600px).
 * That works in modern browsers, but older Safari (< 15), pre-Chromium Edge,
 * and several CSS minifiers silently drop nested @media blocks. Flattened
 * to a top-level query — same effective behaviour (only matches when the
 * viewport is <= 380px), no compatibility risk.
 */
@media (max-width: 380px) {
    .noteshub-pwa-install {
        flex-wrap: wrap;
    }
    .noteshub-pwa-install-actions {
        width: 100%;
        justify-content: flex-end;
        margin-top: 6px;
    }
}

/* ── Print ──────────────────────────────────────────────────── */
/*
 * BUGFIX: no print rules existed in this file, so the install/update
 * banners, the network toast, and the html.noteshub-offline::before badge
 * would all render on printed pages. theme.css hides its own chrome in
 * print but doesn't know about these elements.
 */
@media print {
    .noteshub-pwa-install,
    .noteshub-pwa-update,
    .noteshub-pwa-toast,
    html.noteshub-offline::before {
        display: none !important;
    }
}