:root {
    --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);
}

html.is-standalone {
    min-height: 100%;
    background: #f8fafc;
}

html.is-standalone body {
    min-height: 100%;
    overscroll-behavior-y: contain;
    -webkit-touch-callout: none;
    padding-right: var(--pwa-safe-right);
    padding-bottom: var(--pwa-safe-bottom);
    padding-left: var(--pwa-safe-left);
}

html.is-standalone .topbar,
html.is-native-app .topbar {
    height: calc(76px + var(--pwa-safe-top));
    padding-top: var(--pwa-safe-top);
}

html.is-standalone .header-nav,
html.is-native-app .header-nav {
    min-height: 76px;
}

html.is-standalone .left-sidebar,
html.is-native-app .left-sidebar {
    padding-top: calc(16px + var(--pwa-safe-top));
}

html.is-standalone .page-wrapper,
html.is-native-app .page-wrapper {
    padding-top: calc(96px + var(--pwa-safe-top));
}

@media (max-width: 1200px) {
    html.is-standalone .topbar,
    html.is-native-app .topbar {
        height: calc(68px + var(--pwa-safe-top));
    }

    html.is-standalone .header-nav,
    html.is-native-app .header-nav {
        min-height: 68px;
    }

    html.is-standalone .left-sidebar,
    html.is-native-app .left-sidebar {
        padding-top: calc(32px + var(--pwa-safe-top));
    }

    html.is-standalone .page-wrapper,
    html.is-native-app .page-wrapper {
        padding-top: calc(84px + var(--pwa-safe-top));
    }
}

@media (max-width: 640px) {
    html.is-standalone .topbar,
    html.is-native-app .topbar {
        height: calc(60px + var(--pwa-safe-top));
    }

    html.is-standalone .header-nav,
    html.is-native-app .header-nav {
        min-height: 60px;
    }

    html.is-standalone .page-wrapper,
    html.is-native-app .page-wrapper {
        padding-top: calc(74px + var(--pwa-safe-top));
    }
}

.pwa-install-card {
    position: fixed;
    right: max(16px, var(--pwa-safe-right));
    bottom: max(16px, var(--pwa-safe-bottom));
    z-index: 2100;
    display: none;
    width: min(360px, calc(100vw - 32px));
    border: 1px solid rgba(15, 118, 110, .18);
    border-radius: 8px;
    background: rgba(255, 255, 255, .96);
    color: #0f172a;
    padding: 14px;
    box-shadow: 0 22px 55px rgba(15, 23, 42, .18);
    backdrop-filter: blur(12px);
}

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

.pwa-install-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

.pwa-install-icon {
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    border-radius: 8px;
    object-fit: cover;
}

.pwa-install-copy {
    min-width: 0;
    flex: 1 1 auto;
}

.pwa-install-copy strong,
.pwa-install-copy small {
    display: block;
}

.pwa-install-copy strong {
    font-size: 14px;
    line-height: 1.25;
}

.pwa-install-copy small {
    margin-top: 2px;
    color: #64748b;
    font-size: 12px;
    line-height: 1.35;
}

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

.pwa-install-actions button {
    min-height: 38px;
    border: 1px solid #dbe4ee;
    border-radius: 8px;
    background: #fff;
    color: #334155;
    padding: 8px 12px;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.pwa-install-actions button[data-pwa-install] {
    border-color: #0f766e;
    background: #0f766e;
    color: #fff;
}

.mobile-download-card {
    position: fixed;
    right: max(16px, var(--pwa-safe-right));
    bottom: max(16px, var(--pwa-safe-bottom));
    z-index: 2120;
    display: none;
    width: min(380px, calc(100vw - 32px));
    border: 1px solid rgba(15, 118, 110, .18);
    border-radius: 8px;
    background: rgba(255, 255, 255, .97);
    color: #0f172a;
    padding: 14px;
    box-shadow: 0 22px 55px rgba(15, 23, 42, .18);
    backdrop-filter: blur(12px);
}

.mobile-download-card.is-visible {
    display: block;
}

.mobile-download-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 12px;
}

.mobile-download-actions button,
.mobile-download-actions a {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid #dbe4ee;
    border-radius: 8px;
    background: #fff;
    color: #334155;
    padding: 8px 12px;
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
}

.mobile-download-actions a {
    border-color: #0f766e;
    background: #0f766e;
    color: #fff;
}

.mobile-download-actions .mobile-download-primary {
    border-color: #0f766e;
    background: #0f766e;
    color: #fff;
}

.mobile-app-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 2300;
    display: none;
    align-items: flex-end;
    justify-content: center;
    background: rgba(15, 23, 42, .22);
    padding: 14px max(14px, var(--pwa-safe-right)) max(14px, var(--pwa-safe-bottom)) max(14px, var(--pwa-safe-left));
}

.mobile-app-modal-backdrop.is-visible {
    display: flex;
}

.mobile-app-modal {
    position: relative;
    width: min(390px, 100%);
    border: 1px solid rgba(15, 118, 110, .18);
    border-radius: 10px;
    background: rgba(255, 255, 255, .98);
    color: #0f172a;
    padding: 16px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, .26);
    backdrop-filter: blur(12px);
}

.mobile-app-modal-close {
    position: absolute;
    top: 8px;
    right: 9px;
    display: grid;
    width: 28px;
    height: 28px;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: #eef8f8;
    color: #0f766e;
    font-size: 19px;
    line-height: 1;
}

[dir="rtl"] .mobile-app-modal-close {
    right: auto;
    left: 9px;
}

.mobile-app-modal-note {
    margin: 12px 0 0;
    border-radius: 8px;
    background: #ecfeff;
    color: #155e75;
    padding: 9px 10px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.45;
}

@media (max-width: 640px) {
    .pwa-install-card,
    .mobile-download-card {
        right: max(10px, var(--pwa-safe-right));
        left: max(10px, var(--pwa-safe-left));
        bottom: max(10px, var(--pwa-safe-bottom));
        width: auto;
    }
}

.mobile-app-nav {
    position: fixed;
    right: max(8px, var(--pwa-safe-right));
    bottom: max(6px, var(--pwa-safe-bottom));
    left: max(8px, var(--pwa-safe-left));
    z-index: 20;
    display: none;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    min-height: 56px;
    border: 1px solid rgba(15, 23, 42, .1);
    border-radius: 8px;
    background: rgba(255, 255, 255, .96);
    padding: 4px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, .14);
    backdrop-filter: blur(14px);
}

.mobile-app-nav-item {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 2px;
    border-radius: 7px;
    color: #64748b;
    font-size: 10px;
    font-weight: 800;
    line-height: 1.15;
    text-align: center;
    text-decoration: none;
}

.mobile-nav-badge {
    align-items: center;
    background: #d92d20;
    border: 2px solid #fff;
    border-radius: 999px;
    color: #fff;
    display: inline-flex;
    font-size: 10px;
    font-weight: 800;
    height: 18px;
    justify-content: center;
    min-width: 18px;
    padding: 0 4px;
    position: absolute;
    right: 18px;
    top: 4px;
}

.mobile-app-nav-item i {
    color: currentColor;
    font-size: 16px;
    line-height: 1;
}

.mobile-app-nav-item span {
    display: block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-app-nav-item.is-active {
    background: #ccfbf1;
    color: #0f766e;
}

@media print {
    body.has-mobile-app-nav {
        padding-bottom: 0 !important;
    }

    .mobile-app-nav,
    .pwa-install-card,
    .mobile-download-card,
    .pwa-draft-notice {
        display: none !important;
    }
}

.pwa-draft-notice {
    position: fixed;
    right: max(16px, var(--pwa-safe-right));
    bottom: max(90px, calc(74px + var(--pwa-safe-bottom)));
    z-index: 2100;
    max-width: min(320px, calc(100vw - 32px));
    transform: translateY(12px);
    border: 1px solid rgba(15, 118, 110, .18);
    border-radius: 8px;
    background: rgba(15, 118, 110, .96);
    color: #fff;
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 800;
    line-height: 1.35;
    box-shadow: 0 16px 35px rgba(15, 23, 42, .2);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
}

.pwa-draft-notice.is-visible {
    transform: translateY(0);
    opacity: 1;
}

.pwa-connectivity-status {
    position: fixed;
    top: max(10px, calc(8px + var(--pwa-safe-top)));
    left: 50%;
    z-index: 2400;
    display: none;
    max-width: min(440px, calc(100vw - 24px));
    transform: translateX(-50%);
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 8px;
    padding: 9px 13px;
    color: #fff;
    background: #334155;
    box-shadow: 0 12px 28px rgba(15, 23, 42, .2);
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    line-height: 1.3;
    text-align: center;
}

.pwa-connectivity-status.is-visible {
    display: block;
}

.pwa-connectivity-status[data-state="offline"] {
    background: #9a3412;
}

.pwa-connectivity-status[data-state="pending"] {
    background: #a16207;
    cursor: pointer;
}

.pwa-connectivity-status[data-state="syncing"] {
    background: #155e75;
}

.pwa-connectivity-status[data-state="synced"] {
    background: #0f766e;
}

@media (max-width: 768px) {
    html,
    body {
        overscroll-behavior-y: none;
        -webkit-overflow-scrolling: touch;
    }

    body.has-mobile-app-nav {
        padding-bottom: calc(68px + var(--pwa-safe-bottom));
        overscroll-behavior-y: none;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        touch-action: pan-y;
    }

    #main-wrapper,
    .page-wrapper,
    .mobile-app-nav,
    .mobile-app-nav * {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    .mobile-app-nav {
        display: grid;
        overscroll-behavior: contain;
        touch-action: manipulation;
    }

    .show-sidebar .mobile-app-nav {
        z-index: 1;
    }

    .pwa-install-card {
        bottom: calc(68px + var(--pwa-safe-bottom));
    }

    .mobile-download-card {
        bottom: calc(68px + var(--pwa-safe-bottom));
    }
}

@media (display-mode: standalone) and (max-width: 1024px) {
    html,
    body {
        overscroll-behavior-y: none;
        -webkit-overflow-scrolling: touch;
    }

    body.has-mobile-app-nav {
        padding-bottom: calc(68px + var(--pwa-safe-bottom));
        overscroll-behavior-y: none;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        touch-action: pan-y;
    }

    #main-wrapper,
    .page-wrapper,
    .mobile-app-nav,
    .mobile-app-nav * {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    .mobile-app-nav {
        display: grid;
        overscroll-behavior: contain;
        touch-action: manipulation;
    }

    .show-sidebar .mobile-app-nav {
        z-index: 1;
    }
}
