/* Installed-app styles: window controls overlay, safe areas, the update
 * toast and the notification settings card. Linked after theme.css and
 * built only from its --ds-* tokens.
 */

/* ---------- Window Controls Overlay (desktop installs) ----------
 * The OS title bar is gone; the window controls float over the page inside
 * the rectangle the browser reports through env(titlebar-area-*). The
 * topbar becomes the title bar: it stays clear of the controls and is the
 * drag handle for the window, while anything interactive stays clickable.
 */
@media (display-mode: window-controls-overlay) {
    .topbar,
    nav.navbar.topbar {
        position: sticky;
        top: env(titlebar-area-y, 0px);
        z-index: 1030;
        min-height: max(56px, env(titlebar-area-height, 0px));
        /* Room for controls on the right (Windows, Linux)… */
        padding-right: max(24px, calc(100vw - env(titlebar-area-x, 0px) - env(titlebar-area-width, 100vw) + 12px)) !important;
        app-region: drag;
        -webkit-app-region: drag;
    }

    /* …and on the left (macOS), where the sidebar meets the top edge. */
    .sidebar .logo {
        margin-top: max(0px, calc(env(titlebar-area-height, 0px) - 12px));
        padding-left: max(6px, calc(env(titlebar-area-x, 0px) - 12px));
        app-region: drag;
        -webkit-app-region: drag;
    }

    /* Pages without a topbar still get a drag strip along the title bar. */
    body::before {
        content: "";
        position: fixed;
        top: env(titlebar-area-y, 0px);
        left: env(titlebar-area-x, 0px);
        width: env(titlebar-area-width, 100%);
        height: env(titlebar-area-height, 0px);
        pointer-events: none;
        app-region: drag;
        -webkit-app-region: drag;
    }

    a,
    button,
    input,
    select,
    textarea,
    label,
    summary,
    [role="button"],
    [tabindex],
    .dropdown-menu,
    .modal {
        app-region: no-drag;
        -webkit-app-region: no-drag;
    }
}

/* ---------- Phones: notches and home indicators ----------
 * Pages use viewport-fit=cover, so keep content out of the unsafe areas.
 */
@supports (padding: env(safe-area-inset-top)) {
    #wrapper {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    @media (display-mode: standalone) {
        .topbar,
        nav.navbar.topbar {
            height: auto;
            min-height: calc(56px + env(safe-area-inset-top));
            padding-top: env(safe-area-inset-top) !important;
        }
    }

    .mobile-sidebar {
        padding-bottom: calc(8px + env(safe-area-inset-bottom)) !important;
    }

    .scroll-to-top {
        bottom: calc(1rem + env(safe-area-inset-bottom));
    }
}

/* ---------- Update prompt ---------- */
.pwa-toast {
    position: fixed;
    left: 50%;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: calc(100vw - 32px);
    padding: 10px 12px 10px 16px;
    background: var(--ds-bg-raised);
    color: var(--ds-text);
    border: 1px solid var(--ds-border-strong);
    border-radius: var(--ds-radius);
    box-shadow: var(--ds-shadow-lg);
    font: 13px/1.4 var(--ds-font);
}

.pwa-toast span { margin-right: 4px; }

@media (max-width: 767.98px) {
    /* Sit above the fixed bottom navigation. */
    .pwa-toast { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- Notification settings (profile page) ---------- */
.pwa-notify__title {
    margin: 0 0 4px;
    font-size: 15px;
    font-weight: 600;
    color: var(--ds-text);
}

.pwa-notify__lede {
    margin: 0 0 16px;
    font-size: 13px;
    color: var(--ds-text-muted);
}

.pwa-notify__row { margin-bottom: 12px; }

.pwa-notify__label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--ds-text);
}

.pwa-notify__help {
    display: block;
    font-size: 12px;
    color: var(--ds-text-muted);
}

.pwa-notify__status {
    min-height: 1.4em;
    margin: 8px 0 0;
    font-size: 13px;
    color: var(--ds-text-muted);
}

.pwa-notify__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}

/* ---------- Offline page ---------- */
.pwa-offline {
    min-height: 100vh;
    margin: 0;
    display: grid;
    place-items: center;
    padding: 16px;
    background: var(--ds-bg-subtle);
    font-family: var(--ds-font);
    color: var(--ds-text);
}

.pwa-offline__card {
    max-width: 380px;
    padding: 32px 28px;
    text-align: center;
    background: var(--ds-bg-raised);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-lg);
    box-shadow: var(--ds-shadow);
}

.pwa-offline__card img { border-radius: 9px; }
.pwa-offline__card h1 { margin: 16px 0 6px; font-size: 17px; font-weight: 600; }
.pwa-offline__card p { margin: 0 0 20px; font-size: 13px; color: var(--ds-text-muted); }
.pwa-offline__card button {
    height: var(--ds-control);
    padding: 0 16px;
    border: 0;
    border-radius: var(--ds-radius-sm);
    background: var(--ds-accent);
    color: var(--ds-accent-text);
    font: 500 13px var(--ds-font);
    cursor: pointer;
}
.pwa-offline__card button:hover { background: var(--ds-accent-hover); }
.pwa-offline__card button:focus-visible { outline: none; box-shadow: var(--ds-focus-ring); }
