/* CRM PWA native-feel layer.
   These rules improve touch behavior, reduce unnecessary paint work, and keep
   the install/offline UI aligned with the existing CRM design system. */

:root {
    --pwa-theme-color: #2563eb;
    --pwa-banner-bg: #0f172a;
    --pwa-banner-text: #ffffff;
    --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 {
    min-height: 100%;
    height: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    text-rendering: optimizeSpeed;
}

.app-main,
.login-shell,
.offline-shell {
    padding-left: max(var(--pwa-safe-left), 0px);
    padding-right: max(var(--pwa-safe-right), 0px);
    padding-bottom: max(var(--pwa-safe-bottom), 0px);
}

.mobile-app-bar {
    padding-top: var(--pwa-safe-top);
}

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

nav,
button,
.btn,
.card,
.leadpro-panel,
.leadpro-stat,
.kanban-card,
.app-sidebar,
.mobile-app-bar {
    -webkit-user-select: none;
    user-select: none;
}

input,
textarea,
select,
[contenteditable="true"] {
    -webkit-user-select: text;
    user-select: text;
}

.table-responsive,
.list-group,
.kanban-board,
.kanban-dropzone,
.app-sidebar-nav,
.call-history,
.call-center-card {
    -webkit-overflow-scrolling: touch;
}

/* Keep below-the-fold panels cheap until they are close to the viewport. */
.leadpro-panel,
.dashboard-widget,
.dashboard-activity,
.call-campaign-card,
.call-center-card,
.calendar-shell,
.webhook-debug-shell,
.duplicate-merge-shell {
    content-visibility: auto;
    contain-intrinsic-size: auto 360px;
}

.kanban-card,
.notification-item,
.dashboard-activity-item {
    contain: layout paint;
}

.pwa-install-banner {
    position: fixed;
    bottom: max(16px, var(--pwa-safe-bottom));
    left: max(16px, var(--pwa-safe-left));
    right: max(16px, var(--pwa-safe-right));
    z-index: 1200;
    max-width: 540px;
    margin-inline: auto;
    padding: 16px 18px;
    border-radius: 14px;
    background: #ffffff;
    color: #0f172a;
    border: 1px solid rgba(37, 99, 235, 0.2);
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25), 0 4px 16px rgba(37, 99, 235, 0.12);
    display: flex;
    flex-direction: column;
    gap: 14px;
    transform: translate3d(0, 120%, 0);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.24s ease;
    pointer-events: none;
    will-change: transform, opacity;
}

.pwa-install-banner.is-visible {
    transform: translate3d(0, 0, 0);
    opacity: 1;
    pointer-events: auto;
}

[data-theme="dark"] .pwa-install-banner {
    background: #1e293b;
    color: #e2e8f0;
    border-color: rgba(96, 165, 250, 0.25);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.pwa-install-banner__content {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.pwa-install-banner__icon {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border-radius: 10px;
    background: rgba(37, 99, 235, 0.1);
    color: #2563eb;
    font-size: 1.25rem;
    line-height: 1;
}

.pwa-install-banner__title {
    display: block;
    font-size: 1rem;
    font-weight: 800;
    margin-bottom: 4px;
    color: #0f172a;
}

[data-theme="dark"] .pwa-install-banner__title {
    color: #f1f5f9;
}

.pwa-install-banner__copy {
    margin: 0;
    font-size: 0.875rem;
    color: #475569;
    line-height: 1.5;
}

[data-theme="dark"] .pwa-install-banner__copy {
    color: #94a3b8;
}

.pwa-install-banner__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.pwa-never-option {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    font-size: 0.82rem;
    font-weight: 700;
    color: #475569;
    cursor: pointer;
}

[data-theme="dark"] .pwa-never-option {
    color: #cbd5e1;
}

.pwa-never-option__input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.pwa-never-option__box {
    width: 18px;
    height: 18px;
    border-radius: 5px;
    border: 2px solid rgba(37, 99, 235, 0.45);
    background: #ffffff;
    display: inline-grid;
    place-items: center;
    flex: 0 0 18px;
}

.pwa-never-option__box::after {
    content: "";
    width: 8px;
    height: 4px;
    border-left: 2px solid #ffffff;
    border-bottom: 2px solid #ffffff;
    transform: rotate(-45deg) translateY(-1px);
    opacity: 0;
}

.pwa-never-option__input:checked + .pwa-never-option__box {
    background: #2563eb;
    border-color: #2563eb;
}

.pwa-never-option__input:checked + .pwa-never-option__box::after {
    opacity: 1;
}

.pwa-never-option__input:focus-visible + .pwa-never-option__box {
    outline: 3px solid rgba(37, 99, 235, 0.25);
    outline-offset: 2px;
}

.pwa-ios-steps {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 10px;
    padding: 10px 12px;
    background: rgba(37, 99, 235, 0.06);
    border-radius: 10px;
    font-size: 0.82rem;
    color: #334155;
}

[data-theme="dark"] .pwa-ios-steps {
    background: rgba(96, 165, 250, 0.1);
    color: #cbd5e1;
}

.pwa-sidebar-install-btn {
    margin-bottom: 8px;
}

.pwa-network-toast {
    position: fixed;
    top: max(14px, calc(var(--pwa-safe-top) + 10px));
    left: max(16px, var(--pwa-safe-left));
    right: max(16px, var(--pwa-safe-right));
    z-index: 1200;
    max-width: 460px;
    margin-inline: auto;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--pwa-banner-bg);
    color: var(--pwa-banner-text);
    font-weight: 700;
    text-align: center;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.2);
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.pwa-network-toast.is-hiding {
    opacity: 0;
    transform: translateY(-8px);
}

.pwa-offline-dot {
    width: 10px;
    height: 10px;
    display: inline-block;
    border-radius: 999px;
    background: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.16);
    transition: background 0.4s ease, box-shadow 0.4s ease;
}

.pwa-offline-dot.is-offline {
    background: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.16);
}

.mobile-app-bar .pwa-offline-dot {
    position: absolute;
    right: 62px;
    top: calc(50% + var(--pwa-safe-top, 0px) / 2);
    transform: translateY(-50%);
    margin: 0;
}

@media (prefers-reduced-motion: reduce) {
    .pwa-install-banner {
        transition: none;
    }
}
