:root {
    --app-safe-top: env(safe-area-inset-top, 0px);
    --app-safe-right: env(safe-area-inset-right, 0px);
    --app-safe-bottom: env(safe-area-inset-bottom, 0px);
    --app-safe-left: env(safe-area-inset-left, 0px);
    --app-viewport-height: 100vh;
    --app-pwa-radius-sm: 12px;
    --app-pwa-radius-md: 16px;
    --app-pwa-radius-lg: 22px;
    --app-pwa-sheet-z: 1007;
    --app-pwa-status-z: 1004;
}

@supports (height: 100svh) {
    :root {
        --app-viewport-height: 100svh;
    }
}

@supports (height: 100dvh) {
    :root {
        --app-viewport-height: 100dvh;
    }
}

.pwa-status {
    align-items: center;
    background: rgba(7, 17, 31, 0.94);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--app-pwa-radius-md);
    bottom: max(12px, var(--app-safe-bottom));
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.25);
    color: #fff;
    display: flex;
    font-family: "IBM Plex Sans", Arial, Helvetica, sans-serif;
    font-size: 13px;
    gap: 12px;
    justify-content: space-between;
    left: max(12px, var(--app-safe-left));
    opacity: 0;
    padding: 10px 12px;
    pointer-events: none;
    position: fixed;
    right: max(12px, var(--app-safe-right));
    transform: translateY(calc(100% + 24px));
    transition: transform 160ms ease, opacity 160ms ease;
    z-index: var(--app-pwa-status-z);
}

.pwa-status.is-visible {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.pwa-status__text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pwa-status__actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.pwa-status button {
    background: #fff;
    border: 0;
    border-radius: 999px;
    color: #07111f;
    font: inherit;
    font-weight: 800;
    min-height: 30px;
    padding: 7px 10px;
}

.pwa-status button[hidden] {
    display: none;
}

.pwa-status button[data-pwa-dismiss] {
    width: 30px;
    height: 30px;
    padding: 0;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.pwa-status.is-online {
    background: rgba(22, 101, 52, 0.94);
}

.pwa-status.is-offline,
.pwa-status.is-error {
    background: rgba(127, 29, 29, 0.95);
}

.pwa-status.is-syncing {
    background: rgba(30, 64, 175, 0.95);
}

.pwa-install-hint {
    bottom: max(64px, calc(var(--app-safe-bottom) + 64px));
    display: none;
    font-family: "IBM Plex Sans", Arial, Helvetica, sans-serif;
    left: max(12px, var(--app-safe-left));
    margin: 0 auto;
    max-width: 420px;
    position: fixed;
    right: max(12px, var(--app-safe-right));
    z-index: var(--app-pwa-sheet-z);
}

.pwa-install-hint.is-visible {
    display: block;
}

.pwa-install-hint__backdrop {
    display: none;
}

.pwa-install-hint__panel {
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: var(--app-pwa-radius-lg);
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.22);
    color: #172033;
    padding: 16px;
}

.pwa-install-hint__handle {
    display: none;
}

.pwa-install-hint__head {
    display: grid;
    grid-template-columns: 42px 1fr;
    gap: 12px;
    align-items: start;
}

.pwa-install-hint__head > span {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 14px;
    background: #dbeafe;
    color: #1d4ed8;
    font-size: 22px;
    font-weight: 900;
}

.pwa-install-hint strong {
    display: block;
    margin-bottom: 3px;
    font-size: 16px;
    line-height: 1.15;
}

.pwa-install-hint p {
    margin: 0;
    color: #64748b;
    font-size: 13px;
    line-height: 1.35;
}

.pwa-install-hint ol {
    margin: 12px 0 14px;
    padding: 10px 10px 10px 30px;
    border-radius: 14px;
    background: #f8fafc;
    color: #334155;
    font-size: 13px;
    line-height: 1.35;
}

.pwa-install-hint li + li {
    margin-top: 5px;
}

.pwa-install-hint__actions {
    display: flex;
    gap: 8px;
}

.pwa-install-hint__panel button {
    flex: 1 1 0;
    border: 0;
    border-radius: 12px;
    min-height: 42px;
    padding: 11px 12px;
    font-weight: 800;
}

.pwa-install-hint__panel button[data-pwa-install] {
    background: #1d4ed8;
    color: #fff;
}

.pwa-install-hint__panel button[data-pwa-install-dismiss] {
    background: #e5e7eb;
    color: #111827;
}

.pwa-update-sheet {
    bottom: max(64px, calc(var(--app-safe-bottom) + 64px));
    display: none;
    font-family: "IBM Plex Sans", Arial, Helvetica, sans-serif;
    left: max(12px, var(--app-safe-left));
    margin: 0 auto;
    max-width: 420px;
    position: fixed;
    right: max(12px, var(--app-safe-right));
    z-index: calc(var(--app-pwa-sheet-z) + 1);
}

.pwa-update-sheet.is-visible {
    display: block;
}

.pwa-update-sheet__backdrop {
    display: none;
}

.pwa-update-sheet__panel {
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: var(--app-pwa-radius-lg);
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.22);
    color: #172033;
    padding: 16px;
}

.pwa-update-sheet__handle {
    display: none;
}

.pwa-update-sheet__head {
    align-items: start;
    display: grid;
    gap: 12px;
    grid-template-columns: 42px 1fr;
}

.pwa-update-sheet__head > span {
    background: #dcfce7;
    border-radius: 14px;
    color: #15803d;
    display: grid;
    font-size: 22px;
    font-weight: 900;
    height: 42px;
    place-items: center;
    width: 42px;
}

.pwa-update-sheet strong {
    display: block;
    font-size: 16px;
    line-height: 1.15;
    margin-bottom: 3px;
}

.pwa-update-sheet p {
    color: #64748b;
    font-size: 13px;
    line-height: 1.35;
    margin: 0;
}

.pwa-update-sheet__actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.pwa-update-sheet__panel button {
    border: 0;
    border-radius: 12px;
    flex: 1 1 0;
    font-weight: 800;
    min-height: 42px;
    padding: 11px 12px;
}

.pwa-update-sheet__panel button[data-pwa-update-apply] {
    background: #15803d;
    color: #fff;
}

.pwa-update-sheet__panel button[data-pwa-update-dismiss] {
    background: #e5e7eb;
    color: #111827;
}

body[data-bs-theme="dark"] .pwa-install-hint__panel,
html[data-bs-theme="dark"] .pwa-install-hint__panel,
body[data-bs-theme="dark"] .pwa-update-sheet__panel,
html[data-bs-theme="dark"] .pwa-update-sheet__panel {
    background: #111827;
    border-color: rgba(255, 255, 255, 0.12);
    color: #f8fafc;
}

body[data-bs-theme="dark"] .pwa-install-hint p,
html[data-bs-theme="dark"] .pwa-install-hint p,
body[data-bs-theme="dark"] .pwa-update-sheet p,
html[data-bs-theme="dark"] .pwa-update-sheet p {
    color: #94a3b8;
}

body[data-bs-theme="dark"] .pwa-install-hint ol,
html[data-bs-theme="dark"] .pwa-install-hint ol {
    background: rgba(255, 255, 255, 0.06);
    color: #dbe4ef;
}

body[data-bs-theme="dark"] .pwa-install-hint__panel button[data-pwa-install-dismiss],
html[data-bs-theme="dark"] .pwa-install-hint__panel button[data-pwa-install-dismiss],
body[data-bs-theme="dark"] .pwa-update-sheet__panel button[data-pwa-update-dismiss],
html[data-bs-theme="dark"] .pwa-update-sheet__panel button[data-pwa-update-dismiss] {
    background: rgba(255, 255, 255, 0.1);
    color: #f8fafc;
}

@media (max-width: 991.98px) {
    .pwa-install-hint {
        bottom: auto;
        display: block;
        inset: 0;
        margin: 0;
        max-width: none;
        opacity: 0;
        pointer-events: none;
        transition: opacity 180ms ease, visibility 0s linear 220ms;
        visibility: hidden;
    }

    .pwa-install-hint.is-visible {
        opacity: 1;
        pointer-events: auto;
        transition-delay: 0s;
        visibility: visible;
    }

    .pwa-install-hint__backdrop {
        appearance: none;
        background: rgba(19, 21, 22, 0.44);
        border: 0;
        display: block;
        inset: 0;
        opacity: 0;
        padding: 0;
        position: absolute;
        transition: opacity 180ms ease;
        width: 100%;
    }

    .pwa-install-hint.is-visible .pwa-install-hint__backdrop {
        opacity: 1;
    }

    .pwa-install-hint__panel {
        border-radius: var(--app-pwa-radius-lg) var(--app-pwa-radius-lg) 0 0;
        border-width: 1px 0 0;
        bottom: 0;
        box-shadow: 0 -1rem 3rem rgba(15, 23, 42, 0.22);
        left: 0;
        max-height: min(34rem, calc(100dvh - var(--app-safe-top) - 0.75rem));
        overflow: auto;
        padding: 1rem 1rem calc(1rem + var(--app-safe-bottom));
        position: absolute;
        right: 0;
        transform: translate3d(0, calc(100% + 1.5rem + var(--app-safe-bottom)), 0);
        transition: transform 220ms ease;
    }

    .pwa-install-hint.is-visible .pwa-install-hint__panel {
        transform: translate3d(0, 0, 0);
    }

    .pwa-install-hint__handle {
        background: rgba(100, 116, 139, 0.35);
        border-radius: 999px;
        display: block;
        height: 4px;
        margin: 0 auto 0.75rem;
        width: 2.75rem;
    }

    .pwa-update-sheet {
        bottom: auto;
        display: block;
        inset: 0;
        margin: 0;
        max-width: none;
        opacity: 0;
        pointer-events: none;
        transition: opacity 180ms ease, visibility 0s linear 220ms;
        visibility: hidden;
    }

    .pwa-update-sheet.is-visible {
        opacity: 1;
        pointer-events: auto;
        transition-delay: 0s;
        visibility: visible;
    }

    .pwa-update-sheet__backdrop {
        appearance: none;
        background: rgba(19, 21, 22, 0.44);
        border: 0;
        display: block;
        height: 100%;
        inset: 0;
        opacity: 0;
        padding: 0;
        position: absolute;
        transition: opacity 180ms ease;
        width: 100%;
    }

    .pwa-update-sheet.is-visible .pwa-update-sheet__backdrop {
        opacity: 1;
    }

    .pwa-update-sheet__panel {
        border-radius: var(--app-pwa-radius-lg) var(--app-pwa-radius-lg) 0 0;
        border-width: 1px 0 0;
        bottom: 0;
        box-shadow: 0 -1rem 3rem rgba(15, 23, 42, 0.22);
        left: 0;
        max-height: min(30rem, calc(100dvh - var(--app-safe-top) - 0.75rem));
        overflow: auto;
        padding: 1rem 1rem calc(1rem + var(--app-safe-bottom));
        position: absolute;
        right: 0;
        transform: translate3d(0, calc(100% + 1.5rem + var(--app-safe-bottom)), 0);
        transition: transform 220ms ease;
    }

    .pwa-update-sheet.is-visible .pwa-update-sheet__panel {
        transform: translate3d(0, 0, 0);
    }

    .pwa-update-sheet__handle {
        background: rgba(100, 116, 139, 0.35);
        border-radius: 999px;
        display: block;
        height: 4px;
        margin: 0 auto 0.75rem;
        width: 2.75rem;
    }

    .pwa-status {
        border-radius: var(--app-pwa-radius-md);
        font-size: 12px;
        left: max(10px, var(--app-safe-left));
        right: max(10px, var(--app-safe-right));
    }
}

@media (prefers-reduced-motion: reduce) {
    .pwa-status,
    .pwa-install-hint,
    .pwa-install-hint__backdrop,
    .pwa-install-hint__panel,
    .pwa-update-sheet,
    .pwa-update-sheet__backdrop,
    .pwa-update-sheet__panel {
        transition: none;
    }
}

.pwa-offline-page {
    min-height: var(--app-viewport-height);
    display: grid;
    place-items: center;
    padding: 24px;
    background: #f6f8fb;
    color: #172033;
}

.pwa-offline-card {
    width: min(100%, 420px);
    padding: 24px;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.12);
    text-align: center;
}

.pwa-offline-card__icon {
    display: inline-grid;
    width: 54px;
    height: 54px;
    place-items: center;
    border-radius: 999px;
    background: #fee2e2;
    color: #b91c1c;
    font-size: 28px;
    font-weight: 900;
}

.pwa-offline-card h1 {
    margin: 18px 0 10px;
    font-size: 26px;
}

.pwa-offline-card p {
    margin: 0;
    color: #64748b;
    line-height: 1.5;
}

.pwa-offline-card__button {
    display: inline-flex;
    margin-top: 20px;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 0 18px;
    border-radius: 999px;
    background: #1d4ed8;
    color: #fff;
    font-weight: 800;
    text-decoration: none;
}
