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

.pwa-safe-area {
    padding-top: var(--pwa-safe-area-top);
    padding-right: var(--pwa-safe-area-right);
    padding-bottom: var(--pwa-safe-area-bottom);
    padding-left: var(--pwa-safe-area-left);
}

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

@media (display-mode: standalone) {
    html,
    body {
        min-height: 100%;
    }

    body {
        overscroll-behavior-y: contain;
    }

    .browser-only {
        display: none !important;
    }

    .standalone-only {
        display: initial;
    }
}

@media not all and (display-mode: standalone) {
    .standalone-only {
        display: none !important;
    }
}

.pwa-install-button {
    position: fixed;
    right: max(16px, var(--pwa-safe-area-right));
    bottom: max(16px, var(--pwa-safe-area-bottom));
    z-index: 1080;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    min-height: 48px;
    padding: 12px 18px;

    border: 0;
    border-radius: 999px;

    background: #0d6efd;
    color: #ffffff;

    font: inherit;
    font-weight: 700;
    line-height: 1;

    box-shadow: 0 10px 30px rgba(13, 110, 253, 0.3);

    cursor: pointer;
}

.pwa-install-button:hover {
    background: #0b5ed7;
}

.pwa-install-button:focus-visible {
    outline: 3px solid rgba(13, 110, 253, 0.35);
    outline-offset: 3px;
}

.pwa-install-button:disabled {
    opacity: 0.65;
    cursor: wait;
}

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

@media (display-mode: standalone) {
    .pwa-install-button {
        display: none !important;
    }
}

.pwa-update-banner {
    position: fixed;
    left: max(16px, var(--pwa-safe-area-left));
    right: max(16px, var(--pwa-safe-area-right));
    bottom: max(16px, var(--pwa-safe-area-bottom));
    z-index: 1090;

    max-width: 720px;
    margin-inline: auto;

    padding: 16px;

    border: 1px solid #bfdbfe;
    border-radius: 16px;

    background: #ffffff;
    color: #0f172a;

    box-shadow:
        0 18px 50px
        rgba(15, 23, 42, 0.2);
}

.pwa-update-banner[hidden] {
    display: none !important;
}

.pwa-update-banner__content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.pwa-update-banner strong {
    display: block;
    margin-bottom: 4px;
    font-size: 1rem;
}

.pwa-update-banner p {
    margin: 0;
    color: #475569;
    font-size: 0.9rem;
    line-height: 1.5;
}

.pwa-update-banner__actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.pwa-update-banner__update,
.pwa-update-banner__dismiss {
    min-height: 42px;
    padding: 10px 14px;

    border-radius: 10px;

    font: inherit;
    font-weight: 700;

    cursor: pointer;
}

.pwa-update-banner__update {
    border: 1px solid #0d6efd;
    background: #0d6efd;
    color: #ffffff;
}

.pwa-update-banner__update:hover {
    background: #0b5ed7;
}

.pwa-update-banner__update:disabled {
    opacity: 0.65;
    cursor: wait;
}

.pwa-update-banner__dismiss {
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #334155;
}

.pwa-update-banner__dismiss:hover {
    background: #f8fafc;
}

.pwa-update-banner__update:focus-visible,
.pwa-update-banner__dismiss:focus-visible {
    outline: 3px solid rgba(13, 110, 253, 0.3);
    outline-offset: 2px;
}

body:has(.pwa-update-banner:not([hidden]))
.pwa-install-button {
    display: none !important;
}

@media (max-width: 575.98px) {
    .pwa-update-banner__content {
        align-items: stretch;
        flex-direction: column;
    }

    .pwa-update-banner__actions {
        width: 100%;
    }

    .pwa-update-banner__update,
    .pwa-update-banner__dismiss {
        flex: 1;
    }
}

html.pwa-standalone .browser-only {
    display: none !important;
}

html.pwa-browser .standalone-only {
    display: none !important;
}

.pwa-network-status {
    position: fixed;
    top: max(12px, var(--pwa-safe-area-top));
    left: 50%;
    z-index: 1100;

    display: inline-flex;
    align-items: center;
    gap: 8px;

    width: max-content;
    max-width: calc(
        100% -
        var(--pwa-safe-area-left) -
        var(--pwa-safe-area-right) -
        32px
    );

    padding: 10px 16px;

    border: 1px solid transparent;
    border-radius: 999px;

    font-size: 0.875rem;
    font-weight: 700;
    line-height: 1.35;

    box-shadow:
        0 12px 30px
        rgba(15, 23, 42, 0.2);

    transform: translateX(-50%);
}

.pwa-network-status[hidden] {
    display: none !important;
}

.pwa-network-status__indicator {
    width: 10px;
    height: 10px;

    border-radius: 50%;

    background: currentColor;
    flex-shrink: 0;
}

.pwa-network-status--offline {
    border-color: #fecaca;
    background: #fef2f2;
    color: #b91c1c;
}

.pwa-network-status--online {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #15803d;
}

@media (max-width: 575.98px) {
    .pwa-network-status {
        top: max(8px, var(--pwa-safe-area-top));
        width: calc(
            100% -
            var(--pwa-safe-area-left) -
            var(--pwa-safe-area-right) -
            24px
        );

        justify-content: center;
        border-radius: 12px;
        text-align: center;
    }
}

/*
 * =========================================================
 * Mobile-first application foundation
 * =========================================================
 */

html,
body {
    max-width: 100%;
}

body {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

img,
svg,
video,
canvas {
    max-width: 100%;
}

input,
select,
textarea,
button {
    max-width: 100%;
}

@media (max-width: 767.98px) {
    input,
    select,
    textarea {
        font-size: 16px;
    }
}

@media (pointer: coarse) {
    button,
    .btn,
    [role="button"],
    input[type="button"],
    input[type="submit"],
    input[type="reset"] {
        min-height: 44px;
    }

    .form-control,
    .form-select {
        min-height: 44px;
    }

    a.btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

button,
.btn,
[role="button"],
a {
    touch-action: manipulation;
}

.pwa-bottom-safe-spacing {
    padding-bottom: max(
        16px,
        var(--pwa-safe-area-bottom)
    );
}

.pwa-top-safe-spacing {
    padding-top: max(
        12px,
        var(--pwa-safe-area-top)
    );
}

@media (max-width: 575.98px) {
    .container,
    .container-fluid {
        padding-left: max(
            12px,
            var(--pwa-safe-area-left)
        );

        padding-right: max(
            12px,
            var(--pwa-safe-area-right)
        );
    }

    .pwa-mobile-full-width {
        width: 100%;
    }

    .pwa-mobile-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .pwa-mobile-actions > .btn,
    .pwa-mobile-actions > button {
        flex: 1 1 auto;
    }
}

.pwa-table-scroll {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.pwa-table-scroll > table {
    min-width: 720px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible {
    outline: 3px solid rgba(13, 110, 253, 0.35);
    outline-offset: 2px;
}

/*
 * =========================================================
 * Reusable responsive table and action utilities
 * =========================================================
 */

.pwa-table-responsive {
    width: 100%;
    max-width: 100%;

    overflow-x: auto;
    overflow-y: visible;

    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
}

.pwa-table-responsive > table {
    width: 100%;
}

.pwa-table-responsive > table.pwa-wide-table {
    min-width: 760px;
}

.pwa-action-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.pwa-break-text {
    overflow-wrap: anywhere;
    word-break: normal;
}

.pwa-nowrap {
    white-space: nowrap;
}

/*
 * =========================================================
 * Push notification preference control
 * =========================================================
 */

.pwa-notification-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;

    margin: 16px;
    padding: 16px;

    border: 1px solid #dbeafe;
    border-radius: 14px;

    background: #eff6ff;
    color: #0f172a;
}

.pwa-notification-control__text {
    display: flex;
    flex-direction: column;
    gap: 4px;

    min-width: 0;
}

.pwa-notification-control__text strong {
    font-size: 0.95rem;
}

.pwa-notification-control__text span {
    color: #475569;
    font-size: 0.84rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.pwa-notification-control__text
[data-state="success"] {
    color: #15803d;
}

.pwa-notification-control__text
[data-state="error"] {
    color: #b91c1c;
}

.pwa-notification-button {
    flex-shrink: 0;

    min-height: 44px;
    padding: 10px 16px;

    border: 1px solid #0d6efd;
    border-radius: 10px;

    background: #0d6efd;
    color: #ffffff;

    font: inherit;
    font-weight: 700;

    cursor: pointer;
}

.pwa-notification-button:hover {
    background: #0b5ed7;
}

.pwa-notification-button--enabled {
    border-color: #dc3545;
    background: #ffffff;
    color: #dc3545;
}

.pwa-notification-button--enabled:hover {
    background: #fef2f2;
}

.pwa-notification-button:disabled {
    opacity: 0.65;
    cursor: wait;
}

.pwa-notification-button[hidden] {
    display: none !important;
}

@media (max-width: 575.98px) {
    .pwa-notification-control {
        align-items: stretch;
        flex-direction: column;

        margin: 12px;
    }

    .pwa-notification-button {
        width: 100%;
    }
}

.pwa-notification-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.pwa-notification-test-button {
    min-height: 44px;
    padding: 10px 16px;

    border: 1px solid #475569;
    border-radius: 10px;

    background: #ffffff;
    color: #334155;

    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.pwa-notification-test-button:hover {
    background: #f8fafc;
}

.pwa-notification-test-button:disabled {
    opacity: 0.65;
    cursor: wait;
}

.pwa-notification-test-button[hidden] {
    display: none !important;
}

@media (max-width: 575.98px) {
    .pwa-notification-actions {
        align-items: stretch;
        flex-direction: column;
        width: 100%;
    }

    .pwa-notification-test-button {
        width: 100%;
    }
}