:root {
    --app-height: 100dvh;
    --pwa-safe-top: env(safe-area-inset-top, 0px);
    --pwa-safe-right: env(safe-area-inset-right, 0px);
    --pwa-safe-bottom: env(safe-area-inset-bottom, 0px);
    --pwa-safe-left: env(safe-area-inset-left, 0px);
}

[data-pwa-install][hidden] {
    display: none !important;
}

.nav-install,
.pwa-sidebar-button,
.pwa-auth-button {
    min-height: 42px;
    border: 0;
    border-radius: 12px;
    padding: 9px 14px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.nav-install {
    color: #052e20;
    background: #10b981;
    white-space: nowrap;
}

.pwa-sidebar-button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #dbeafe;
    background: #1e293b;
    text-align: left;
}

.pwa-auth-button {
    width: 100%;
    color: #065f46;
    background: #d1fae5;
    margin-top: 10px;
}

.pwa-network-status {
    position: fixed;
    z-index: 9998;
    left: 50%;
    top: calc(12px + var(--pwa-safe-top));
    transform: translate(-50%, -160%);
    min-height: 40px;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: calc(100vw - 32px);
    padding: 9px 15px;
    border-radius: 999px;
    background: #7f1d1d;
    color: #fff;
    box-shadow: 0 16px 40px rgba(15, 23, 42, .22);
    font-size: .84rem;
    font-weight: 800;
    opacity: 0;
    transition: transform .22s ease, opacity .22s ease;
}

.pwa-network-status.show {
    transform: translate(-50%, 0);
    opacity: 1;
}

.pwa-network-status.online {
    background: #047857;
}

.pwa-update-toast {
    position: fixed;
    z-index: 9997;
    right: calc(18px + var(--pwa-safe-right));
    bottom: calc(18px + var(--pwa-safe-bottom));
    width: min(390px, calc(100vw - 36px));
    padding: 17px;
    border-radius: 18px;
    background: #0f172a;
    color: #fff;
    box-shadow: 0 24px 60px rgba(2, 6, 23, .32);
    display: grid;
    gap: 12px;
}

.pwa-update-toast strong,
.pwa-update-toast small {
    display: block;
}

.pwa-update-toast small {
    margin-top: 4px;
    color: #cbd5e1;
    line-height: 1.45;
}

.pwa-update-actions {
    display: flex;
    gap: 9px;
}

.pwa-update-actions button {
    min-height: 40px;
    border: 0;
    border-radius: 11px;
    padding: 8px 13px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.pwa-update-actions button:first-child {
    background: #10b981;
    color: #052e20;
}

.pwa-update-actions button:last-child {
    background: #1e293b;
    color: #fff;
}

.pwa-dialog-backdrop {
    position: fixed;
    z-index: 10000;
    inset: 0;
    display: grid;
    place-items: center;
    padding:
        calc(20px + var(--pwa-safe-top))
        calc(20px + var(--pwa-safe-right))
        calc(20px + var(--pwa-safe-bottom))
        calc(20px + var(--pwa-safe-left));
    background: rgba(2, 6, 23, .72);
    backdrop-filter: blur(8px);
}

.pwa-dialog {
    width: min(520px, 100%);
    max-height: min(720px, calc(var(--app-height) - 40px));
    overflow: auto;
    border-radius: 24px;
    padding: 24px;
    background: #fff;
    color: #172033;
    box-shadow: 0 30px 90px rgba(2, 6, 23, .34);
    -webkit-overflow-scrolling: touch;
}

.pwa-dialog-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.pwa-dialog-icon {
    width: 54px;
    height: 54px;
    flex: 0 0 auto;
    border-radius: 17px;
    object-fit: cover;
}

.pwa-dialog-header div {
    min-width: 0;
    flex: 1;
}

.pwa-dialog h2 {
    margin: 0;
    color: #0f172a;
    font-size: 1.35rem;
}

.pwa-dialog p {
    margin: 7px 0 0;
    color: #64748b;
}

.pwa-dialog-close {
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 13px;
    background: #eef2f7;
    color: #334155;
    cursor: pointer;
    font-size: 1.2rem;
}

.pwa-steps {
    display: grid;
    gap: 11px;
    padding: 0;
    margin: 22px 0;
    list-style: none;
}

.pwa-steps li {
    display: grid;
    grid-template-columns: 34px 1fr;
    gap: 11px;
    align-items: start;
    padding: 13px;
    border-radius: 15px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.pwa-steps span {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    background: #d1fae5;
    color: #047857;
    font-weight: 900;
}

.pwa-dialog-primary {
    width: 100%;
    min-height: 46px;
    border: 0;
    border-radius: 13px;
    background: #10b981;
    color: #052e20;
    font: inherit;
    font-weight: 900;
    cursor: pointer;
}

@media (display-mode: standalone) {
    [data-pwa-install] {
        display: none !important;
    }

    body {
        padding-bottom: var(--pwa-safe-bottom);
    }
}

@media (max-width: 900px) {
    .nav-install {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 600px) {
    .pwa-dialog-backdrop {
        align-items: end;
        padding: 0;
    }

    .pwa-dialog {
        width: 100%;
        max-height: calc(var(--app-height) - var(--pwa-safe-top));
        border-radius: 24px 24px 0 0;
        padding:
            22px
            calc(20px + var(--pwa-safe-right))
            calc(22px + var(--pwa-safe-bottom))
            calc(20px + var(--pwa-safe-left));
    }

    .pwa-update-toast {
        left: calc(12px + var(--pwa-safe-left));
        right: calc(12px + var(--pwa-safe-right));
        bottom: calc(12px + var(--pwa-safe-bottom));
        width: auto;
    }
}
