/* ═══════════════════════════════════════════════════════════════
   GiproAppMobile — Мобильные стили PWA
   Все классы с префиксом pwa-
   Применяются только при body.pwa-mobile-active
   ═══════════════════════════════════════════════════════════════ */

/* ─── PWA Variables ───────────────────────────────────────────── */
:root {
    --pwa-gold: #0C6FD1;
    --pwa-gold-light: #EFF6FF;
    --pwa-gold-dim: rgba(12, 111, 209, 0.08);
    --pwa-inactive: #9CA3AF;
    --pwa-bg: #FFFFFF;
    --pwa-bg-page: #F0F2F5;
    --pwa-border: #E5E7EB;
    --pwa-overlay: rgba(0, 0, 0, 0.5);
    --pwa-text: #1F2937;
    --pwa-text-2: #6B7280;
    --pwa-text-3: #9CA3AF;
    --pwa-red: #EF4444;
    --pwa-green: #10B981;
    --pwa-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --pwa-shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
    --pwa-radius: 12px;
    --pwa-header-h: 56px;
    --pwa-tab-h: 60px;
}

/* ═══ BASE LAYOUT & IPHONE VIEWPORT STABILIZATION ═══ */
html {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    -webkit-text-size-adjust: 100% !important;
    text-size-adjust: 100% !important;
}

body.pwa-mobile-active,
html.pwa-mobile-active body {
    max-width: 100vw !important;
    width: 100% !important;
    overflow-x: hidden !important;
    position: relative !important;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: contain;
}

body.pwa-mobile-active .sidebar,
html.pwa-mobile-active .sidebar {
    display: none !important;
    width: 0 !important;
}

body.pwa-mobile-active .topbar,
html.pwa-mobile-active .topbar {
    display: none !important;
    height: 0 !important;
}

body.pwa-mobile-active .layout,
html.pwa-mobile-active .layout {
    display: block !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
}

body.pwa-mobile-active .main,
html.pwa-mobile-active .main {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
}

body.pwa-mobile-active .content,
html.pwa-mobile-active .content {
    padding: 12px 10px !important;
    padding-top: calc(var(--pwa-header-h) + env(safe-area-inset-top, 0px) + 12px) !important;
    padding-bottom: calc(var(--pwa-tab-h) + env(safe-area-inset-bottom, 0px) + 24px) !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    background: var(--pwa-bg-page);
}

/* ═══ MOBILE HEADER (ALWAYS SAFE-AREA AWARE FOR IPHONE NOTCH) ═══ */
.pwa-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: calc(var(--pwa-header-h) + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--pwa-bg);
    border-bottom: 1px solid var(--pwa-border);
    box-shadow: var(--pwa-shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-left: calc(14px + env(safe-area-inset-left, 0px));
    padding-right: calc(14px + env(safe-area-inset-right, 0px));
    z-index: 9997;
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
}

.pwa-menu-btn {
    background: none; border: none;
    padding: 10px; margin-left: -10px;
    cursor: pointer;
    display: flex; flex-direction: column; gap: 5px;
    min-width: 44px; min-height: 44px;
    justify-content: center; align-items: center;
}

.pwa-hamburger {
    display: block;
    width: 22px; height: 2px;
    background: var(--pwa-text);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.pwa-logo {
    font-size: 17px; font-weight: 700;
    color: var(--pwa-gold);
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.pwa-logo-badge {
    background: var(--pwa-gold-light);
    color: var(--pwa-gold);
    font-size: 11px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 6px;
    letter-spacing: 1px;
    border: 1px solid rgba(12, 111, 209, 0.2);
}

.pwa-page-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--pwa-text);
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pwa-actions { display: flex; align-items: center; gap: 4px; }

.pwa-refresh-btn {
    background: none; border: none;
    padding: 10px;
    cursor: pointer; position: relative;
    color: var(--pwa-text);
    min-width: 44px; min-height: 44px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    transition: background 0.2s, transform 0.2s;
}
.pwa-refresh-btn:active {
    background: rgba(12, 111, 209, 0.08);
    transform: scale(0.9);
}
.pwa-refresh-btn.pwa-spinning svg {
    animation: pwaSpin 0.6s linear infinite;
}
@keyframes pwaSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.pwa-notification-btn {
    background: none; border: none;
    padding: 10px; margin-right: -6px;
    cursor: pointer; position: relative;
    color: var(--pwa-text);
    min-width: 44px; min-height: 44px;
    display: flex; align-items: center; justify-content: center;
}

/* ═══ BADGES ═══ */
.pwa-badge {
    position: absolute; top: 4px; right: 4px;
    background: var(--pwa-red); color: white;
    font-size: 10px; font-weight: 700;
    min-width: 18px; height: 18px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    padding: 0 5px; box-sizing: border-box;
    border: 2px solid white;
}

/* ═══ TAB BAR ═══ */
.pwa-tab-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(var(--pwa-tab-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--pwa-bg);
    border-top: 1px solid var(--pwa-border);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    z-index: 9997;
}

.pwa-tab-item {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 4px;
    text-decoration: none;
    color: var(--pwa-inactive);
    flex: 1; position: relative;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s ease;
}

.pwa-tab-item.pwa-active {
    color: var(--pwa-gold);
}

/* Gold dot under active tab */
.pwa-tab-item.pwa-active::after {
    content: '';
    position: absolute;
    top: 0; left: 50%;
    transform: translateX(-50%);
    width: 24px; height: 3px;
    background: var(--pwa-gold);
    border-radius: 0 0 3px 3px;
}

.pwa-tab-icon-wrap {
    position: relative;
    display: flex; align-items: center; justify-content: center;
    width: 28px; height: 28px;
}

.pwa-tab-label {
    font-size: 11px; font-weight: 500;
    line-height: 1;
}

.pwa-tab-item .pwa-badge {
    top: -6px; right: -10px;
    font-size: 9px; min-width: 16px; height: 16px;
    border: 2px solid white;
}

/* ═══ DRAWER & OVERLAY ═══ */
.pwa-drawer-overlay {
    position: fixed; inset: 0;
    background: var(--pwa-overlay);
    z-index: 9998;
    opacity: 0; visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.pwa-drawer-overlay.pwa-open { opacity: 1; visibility: visible; }

.pwa-drawer {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 300px; max-width: 85vw;
    background: var(--pwa-bg);
    z-index: 9999;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; flex-direction: column;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
}
.pwa-drawer.pwa-open { transform: translateX(0); }

.pwa-drawer-header {
    padding: 24px calc(20px + env(safe-area-inset-right, 0px)) 20px calc(20px + env(safe-area-inset-left, 0px));
    display: flex; justify-content: space-between; align-items: flex-start;
    border-bottom: 1px solid var(--pwa-border);
    background: linear-gradient(135deg, var(--pwa-gold-light), #FFF);
}

.pwa-drawer-user { display: flex; align-items: center; gap: 14px; }

.pwa-avatar {
    width: 44px; height: 44px;
    background: linear-gradient(135deg, #0C6FD1, #0958A5);
    color: white; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 700;
    text-transform: uppercase;
    box-shadow: 0 2px 8px rgba(12, 111, 209, 0.3);
}

.pwa-user-details {
    overflow: hidden;
    min-width: 0;
}

.pwa-user-name {
    font-weight: 600; color: var(--pwa-text);
    font-size: 15px; line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 190px;
}

.pwa-user-role {
    color: var(--pwa-text-2);
    font-size: 12px; margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 190px;
}

.pwa-impersonation-bar {
    background: linear-gradient(135deg, #FEF3C7, #FDE68A);
    border: 1px solid #F59E0B;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 8px 16px;
    font-size: 12px;
    color: #92400E;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.pwa-impersonation-btn {
    background: #D97706;
    color: #FFF;
    border: none;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.pwa-drawer-close {
    background: none; border: none;
    font-size: 28px; color: var(--pwa-text-3);
    cursor: pointer; line-height: 1;
    padding: 4px; margin: -4px -4px 0 0;
    min-width: 44px; min-height: 44px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}
.pwa-drawer-close:active { background: rgba(0,0,0,0.05); }

.pwa-drawer-menu {
    padding: 8px 0;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)) !important;
    overscroll-behavior-y: contain;
    flex: 1;
}

.pwa-menu-item {
    display: flex; align-items: center;
    padding: 14px 20px;
    color: var(--pwa-text);
    text-decoration: none;
    font-size: 15px;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
    border-left: 3px solid transparent;
}
.pwa-menu-item:active { background: #F3F4F6; }

.pwa-menu-item.pwa-active {
    background: var(--pwa-gold-dim);
    color: var(--pwa-gold);
    border-left-color: var(--pwa-gold);
    font-weight: 600;
}

.pwa-menu-icon {
    margin-right: 16px; font-size: 20px;
    width: 28px; text-align: center; flex-shrink: 0;
}

.pwa-drawer-divider {
    height: 1px;
    background: var(--pwa-border);
    margin: 8px 16px;
}

/* ═══ MOBILE PAGE ADAPTATIONS ═══ */
@media (max-width: 768px) {

    /* ─── Touch targets & Inputs ─── */
    button, input[type="submit"], input[type="button"], .btn {
        min-height: 44px;
    }
    input[type="text"], input[type="number"], input[type="email"],
    input[type="password"], input[type="search"], input[type="date"],
    input[type="tel"], input[type="datetime-local"], select, textarea,
    .form-control, .form-input {
        min-height: 44px;
        font-size: 16px !important; /* Prevents iOS auto-zoom on .form-input */
    }

    /* ─── Page title / h1 ─── */
    body.pwa-mobile-active h1 {
        font-size: 22px !important;
        margin-bottom: 16px !important;
    }

    /* ─── Stats cards ─── */
    body.pwa-mobile-active .stats-row,
    body.pwa-mobile-active .alert-banner {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }

    body.pwa-mobile-active .stats-row > *,
    body.pwa-mobile-active .alert-card {
        padding: 14px !important;
        border-radius: var(--pwa-radius) !important;
    }

    /* ─── Grids to single column ─── */
    body.pwa-mobile-active .modules-grid,
    body.pwa-mobile-active .grid {
        grid-template-columns: 1fr !important;
    }

    /* ─── Tables → mobile-friendly ─── */
    body.pwa-mobile-active table,
    html.pwa-mobile-active table,
    body.pwa-mobile-active .table,
    body.pwa-mobile-active .users-table,
    body.pwa-mobile-active .result-table {
        font-size: 13px;
        min-width: 650px !important;
        width: 100% !important;
    }

    body.pwa-mobile-active table thead {
        position: sticky;
        top: 0;
        z-index: 10;
        background: #ffffff !important;
    }

    body.pwa-mobile-active table th {
        padding: 10px 8px !important;
        font-size: 11px !important;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--pwa-text-2) !important;
        background: #ffffff !important;
        white-space: nowrap;
    }

    body.pwa-mobile-active table td {
        padding: 12px 8px !important;
        vertical-align: middle;
    }


    /* Universal table overflow protection without relying solely on :has() */
    body.pwa-mobile-active .card table,
    body.pwa-mobile-active .content table,
    body.pwa-mobile-active main table {
        display: table;
        width: 100% !important;
    }
    body.pwa-mobile-active .card:not(.stats-card):not(.alert-card):not(.pulse-card),
    body.pwa-mobile-active .table-responsive,
    body.pwa-mobile-active .table-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* Scrollable table wrapper */
    body.pwa-mobile-active .table-container,
    body.pwa-mobile-active .table-responsive,
    body.pwa-mobile-active .card:has(table),
    body.pwa-mobile-active div:has(> table),
    body.pwa-mobile-active .card {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        border-radius: var(--pwa-radius);
        box-shadow: var(--pwa-shadow);
        max-width: 100% !important;
    }

    /* ─── Cards ─── */
    body.pwa-mobile-active .card {
        border-radius: var(--pwa-radius) !important;
        box-shadow: var(--pwa-shadow) !important;
        padding: 16px !important;
    }

    /* ─── Modals → fullscreen ─── */
    body.pwa-mobile-active .modal-overlay.open .modal-dialog,
    body.pwa-mobile-active .modal-content,
    body.pwa-mobile-active .wh-modal .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 16px 16px 0 0 !important;
        max-height: 90vh;
        max-height: 90dvh !important;
        position: fixed;
        bottom: var(--pwa-keyboard-offset, 0px) !important;
        left: 0; right: 0;
        top: auto !important;
        overflow-y: auto;
        overscroll-behavior-y: contain;
        padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)) !important;
        transition: bottom 0.15s ease-out;
    }

    /* ─── Buttons ─── */
    body.pwa-mobile-active .btn,
    body.pwa-mobile-active button.btn {
        border-radius: 10px;
        font-size: 14px;
        padding: 10px 18px;
    }

    /* ─── Tabs (page tabs like "Все счета") ─── */
    body.pwa-mobile-active .tab-bar,
    body.pwa-mobile-active .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        gap: 0 !important;
    }

    /* ═══ CHAT — Mobile Layout ═══ */
    body.pwa-mobile-active .chat-container {
        flex-direction: column !important;
        height: calc(100vh - var(--pwa-header-h) - var(--pwa-tab-h)) !important;
        height: calc(100dvh - var(--pwa-header-h) - var(--pwa-tab-h)) !important;
        position: fixed !important;
        top: var(--pwa-header-h);
        left: 0; right: 0;
        bottom: var(--pwa-tab-h);
        border-radius: 0 !important;
        border: none !important;
        margin: 0 !important;
        overflow: hidden;
        overscroll-behavior-y: contain;
    }

    body.pwa-mobile-active .chat-sidebar {
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        border-right: none !important;
    }

    body.pwa-mobile-active .chat-main {
        display: none !important;
        width: 100% !important;
        height: 100% !important;
    }

    body.pwa-mobile-active.pwa-chat-open .chat-sidebar { display: none !important; }
    body.pwa-mobile-active.pwa-chat-open .chat-main { display: flex !important; }
    body.pwa-mobile-active.pwa-chat-open .pwa-tab-bar { display: none !important; }
    body.pwa-mobile-active.pwa-chat-open .chat-container {
        bottom: var(--pwa-keyboard-offset, 0px) !important;
        height: calc(100vh - var(--pwa-header-h) - var(--pwa-keyboard-offset, 0px)) !important;
        height: calc(100dvh - var(--pwa-header-h) - var(--pwa-keyboard-offset, 0px)) !important;
        transition: bottom 0.15s ease-out, height 0.15s ease-out;
    }

    /* ═══ VIRTUAL KEYBOARD ACTIVE — HIDE TAB BAR & FABs ═══ */
    body.pwa-mobile-active.pwa-keyboard-active .pwa-tab-bar {
        display: none !important;
    }
    body.pwa-mobile-active.pwa-keyboard-active #tasks-fab,
    body.pwa-mobile-active.pwa-keyboard-active .tasks-floating-btn,
    body.pwa-mobile-active.pwa-keyboard-active #ai-fab-btn {
        display: none !important;
    }

    /* Back button */
    .pwa-chat-back {
        display: none;
        background: none; border: none;
        color: var(--pwa-gold);
        font-size: 22px; font-weight: 600;
        padding: 8px 12px 8px 4px;
        cursor: pointer;
        min-width: 44px; min-height: 44px;
        align-items: center; justify-content: center;
    }
    body.pwa-mobile-active .pwa-chat-back { display: flex !important; }

    body.pwa-mobile-active .chat-input-area {
        padding: 10px 12px !important;
        gap: 8px !important;
        background: var(--pwa-bg);
        border-top: 1px solid var(--pwa-border);
    }

    body.pwa-mobile-active .chat-input {
        font-size: 16px !important;
        border-radius: 20px !important;
        padding: 10px 16px !important;
    }

    body.pwa-mobile-active .contact-item {
        padding: 14px 16px !important;
        min-height: 56px;
        border-bottom: 1px solid #F3F4F6;
    }

    body.pwa-mobile-active .chat-messages { padding: 12px !important; }

    body.pwa-mobile-active .content:has(.chat-container) {
        padding: 0 !important;
        padding-top: var(--pwa-header-h) !important;
        padding-bottom: calc(var(--pwa-tab-h) + env(safe-area-inset-bottom, 0px)) !important;
        overflow: hidden !important;
    }

    /* ═══ AI ASSISTANT (Gemini) — Mobile Adaptation ═══ */
    body.pwa-mobile-active #ai-fab-btn {
        bottom: calc(var(--pwa-tab-h) + 16px + env(safe-area-inset-bottom, 0px)) !important;
        right: 16px !important;
        box-shadow: 0 4px 16px rgba(0,0,0,0.3) !important;
    }

    body.pwa-mobile-active #ai-chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        min-width: 0 !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        min-height: 0 !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
        box-sizing: border-box !important;
        z-index: 10005 !important;
    }

    body.pwa-mobile-active #ai-chat-window .ai-window-sidebar {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* ═══ DASHBOARD — Bento & Pulse Mobile Overhaul ═══ */
    body.pwa-mobile-active .bento-workspace {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        width: 100% !important;
        max-width: 100% !important;
        margin-bottom: 20px !important;
    }

    body.pwa-mobile-active .bento-card,
    body.pwa-mobile-active .col-12,
    body.pwa-mobile-active .col-8,
    body.pwa-mobile-active .col-7,
    body.pwa-mobile-active .col-6,
    body.pwa-mobile-active .col-5,
    body.pwa-mobile-active .col-4 {
        grid-column: span 1 / -1 !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        padding: 14px 12px !important;
        margin: 0 !important;
    }

    body.pwa-mobile-active .bento-header {
        flex-wrap: wrap !important;
        gap: 8px !important;
        margin-bottom: 12px !important;
    }

    body.pwa-mobile-active .bento-title {
        font-size: 0.88rem !important;
        line-height: 1.3 !important;
    }

    body.pwa-mobile-active .pulse-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
        margin-bottom: 16px !important;
        width: 100% !important;
    }

    body.pwa-mobile-active .pulse-card {
        padding: 10px 8px !important;
        gap: 8px !important;
        border-radius: 12px !important;
        min-width: 0 !important;
        overflow: hidden !important;
    }

    body.pwa-mobile-active .pulse-icon-box {
        width: 34px !important;
        height: 34px !important;
        font-size: 1.05rem !important;
        border-radius: 8px !important;
        flex-shrink: 0 !important;
    }

    body.pwa-mobile-active .pulse-num {
        font-size: 1.05rem !important;
        line-height: 1.15 !important;
    }

    body.pwa-mobile-active .pulse-lbl {
        font-size: 0.65rem !important;
        line-height: 1.2 !important;
    }

    body.pwa-mobile-active .quick-actions-bar {
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 8px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding-bottom: 6px !important;
        margin-bottom: 14px !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    body.pwa-mobile-active .quick-action-btn {
        flex-shrink: 0 !important;
        padding: 8px 12px !important;
        font-size: 0.8rem !important;
        border-radius: 10px !important;
        min-width: 0 !important;
    }

    body.pwa-mobile-active .role-bar {
        padding: 4px 6px !important;
        margin-bottom: 14px !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        border-radius: 12px !important;
    }

    body.pwa-mobile-active .role-tabs {
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 4px !important;
        width: max-content !important;
    }

    body.pwa-mobile-active .r-tab {
        padding: 6px 12px !important;
        font-size: 0.78rem !important;
        white-space: nowrap !important;
    }

    /* ═══ GLOBAL OVERFLOW & SIZE GUARDS ═══ */
    body.pwa-mobile-active canvas,
    body.pwa-mobile-active img,
    body.pwa-mobile-active svg {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* ═══ MODAL Z-INDEX ELEVATION OVER PWA CHROME ═══ */
    body.pwa-mobile-active .modal-overlay,
    body.pwa-mobile-active .wh-modal,
    body.pwa-mobile-active .modal,
    body.pwa-mobile-active .modal-backdrop,
    body.pwa-mobile-active [class*="modal-overlay"],
    body.pwa-mobile-active [class*="wh-modal"],
    body.pwa-mobile-active .preview-modal,
    body.pwa-mobile-active dialog {
        z-index: 10001 !important;
    }

    /* ═══ MEMOS (Служебные записки) — Mobile ═══ */
    body.pwa-mobile-active .memo-tabs {
        overflow-x: auto !important;
        white-space: nowrap !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px !important;
    }

    body.pwa-mobile-active .memo-tab {
        padding: 8px 14px !important;
        font-size: 0.85rem !important;
    }

    /* ═══ ABZ (Асфальтобетонный завод) — Mobile ═══ */
    body.pwa-mobile-active .abz-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
    }

    body.pwa-mobile-active .abz-header .filters {
        flex-direction: column !important;
        width: 100% !important;
    }

    body.pwa-mobile-active .abz-header select,
    body.pwa-mobile-active .abz-header button {
        width: 100% !important;
    }

    /* ═══ LABORATORY (Лаборатория ГОСТ) — Mobile ═══ */
    body.pwa-mobile-active .filter-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }

    body.pwa-mobile-active .filter-bar > * {
        width: 100% !important;
    }

    body.pwa-mobile-active .form-row {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    body.pwa-mobile-active .modal-box {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 16px 16px 0 0 !important;
        margin: 0 !important;
        max-height: 90dvh !important;
        overflow-y: auto !important;
        overscroll-behavior: contain !important;
    }

    /* ═══ OCR / TASKS WIDGET — Mobile floating position ═══ */
    body.pwa-mobile-active #tasks-fab,
    body.pwa-mobile-active .tasks-floating-btn {
        bottom: calc(var(--pwa-tab-h) + 76px + env(safe-area-inset-bottom, 0px)) !important;
        right: 16px !important;
    }

    /* ═══ CALENDAR & PLANNER (/calendar) — Mobile Adaptation ═══ */
    body.pwa-mobile-active .calendar-container {
        grid-template-columns: 1fr !important;
        height: auto !important;
        min-height: auto !important;
        gap: 16px !important;
    }

    body.pwa-mobile-active .planner-sidebar {
        max-height: 380px !important;
        border-radius: var(--pwa-radius) !important;
    }

    body.pwa-mobile-active .calendar-main {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        border-radius: var(--pwa-radius) !important;
    }

    body.pwa-mobile-active .cal-top-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    /* ═══ TREE ARCHITECTURE & GRAPH (/tree) — Mobile Adaptation ═══ */
    body.pwa-mobile-active .unified-container {
        height: calc(100vh - var(--pwa-header-h) - var(--pwa-tab-h)) !important;
        padding: 0 !important;
    }

    body.pwa-mobile-active .unified-topbar {
        padding: 8px 12px !important;
        gap: 8px !important;
        overflow-x: auto !important;
        white-space: nowrap !important;
        -webkit-overflow-scrolling: touch;
    }

    body.pwa-mobile-active .cluster-filters {
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 6px !important;
    }

    /* ═══ RZD (ЖД перевозки) — Mobile Overhaul ═══ */
    body.pwa-mobile-active .wh-modal .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 16px 16px 0 0 !important;
        margin: 0 !important;
        max-height: 90dvh !important;
        overflow-y: auto !important;
        overscroll-behavior: contain !important;
    }

    body.pwa-mobile-active #rzd-content div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    body.pwa-mobile-active #rzd-content > div:first-child {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    body.pwa-mobile-active #rzd-content > div:first-child button.btn-primary {
        width: 100% !important;
        padding: 10px 14px !important;
        font-size: 0.9rem !important;
        justify-content: center !important;
        min-height: 42px !important;
    }

    body.pwa-mobile-active #rzd-search-input,
    body.pwa-mobile-active #rzd-filter-status {
        min-width: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        flex: 1 1 100% !important;
        box-sizing: border-box !important;
        font-size: 16px !important;
    }

    body.pwa-mobile-active #rzd-content .card {
        padding: 12px 14px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    body.pwa-mobile-active #rzd-content .card div[style*="justify-content:space-between"] {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    body.pwa-mobile-active #btn-rzd-bulk-accept,
    body.pwa-mobile-active #btn-rzd-bulk-depart {
        flex: 1 1 auto !important;
        font-size: 0.82rem !important;
        padding: 9px 12px !important;
        white-space: nowrap !important;
        min-height: 40px !important;
    }

    body.pwa-mobile-active #rzd-date-from,
    body.pwa-mobile-active #rzd-date-to {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        font-size: 0.82rem !important;
        padding: 6px 8px !important;
    }

    body.pwa-mobile-active #rzd-content table.table {
        min-width: 680px !important;
    }

    body.pwa-mobile-active #rzd-wagons-tbody .rzd-wagon-check,
    body.pwa-mobile-active #rzd-select-all {
        width: 20px !important;
        height: 20px !important;
        accent-color: #0c6fd1 !important;
        cursor: pointer !important;
    }

    body.pwa-mobile-active #rzd-wagons-tbody button {
        min-height: 36px !important;
        padding: 6px 12px !important;
        font-size: 0.8rem !important;
        border-radius: 6px !important;
    }

    body.pwa-mobile-active #rzd-connection-badge {
        font-size: 0.72rem !important;
        max-width: 100% !important;
        white-space: normal !important;
        line-height: 1.3 !important;
    }

    body.pwa-mobile-active #modal-add-wagon div[style*="display:flex"] {
        flex-direction: column !important;
        gap: 8px !important;
    }

    body.pwa-mobile-active #modal-add-wagon .form-group {
        margin-bottom: 8px !important;
        width: 100% !important;
    }

    body.pwa-mobile-active #modal-add-wagon input,
    body.pwa-mobile-active #modal-add-wagon select {
        font-size: 16px !important;
    }

    /* ═══ WAREHOUSE & STOCK (/warehouse) — Mobile Adaptation ═══ */
    body.pwa-mobile-active .tabs {
        overflow-x: auto !important;
        flex-wrap: nowrap !important;
        white-space: nowrap !important;
        -webkit-overflow-scrolling: touch !important;
        padding-bottom: 8px !important;
        gap: 8px !important;
        border-bottom: 1px solid var(--pwa-border) !important;
    }

    body.pwa-mobile-active .tab {
        flex-shrink: 0 !important;
        font-size: 13px !important;
        padding: 8px 14px !important;
    }

    body.pwa-mobile-active .tab-content .card {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    body.pwa-mobile-active .topbar-actions {
        gap: 4px !important;
    }

    body.pwa-mobile-active .topbar-actions #global-header-icons {
        gap: 8px !important;
        margin-right: 8px !important;
    }

    /* ═══ 3D BIM & PROJECTS (/projects/{pid}) — Mobile ═══ */
    body.pwa-mobile-active #bimViewport,
    html.pwa-mobile-active #bimViewport,
    body.pwa-mobile-active .bim-container,
    body.pwa-mobile-active div[style*="height:880px"] {
        height: 340px !important;
        max-height: 45vh !important;
        width: 100% !important;
        border-radius: 12px !important;
        overflow: hidden !important;
    }

    body.pwa-mobile-active #bimViewport canvas {
        height: 100% !important;
        width: 100% !important;
    }
}

/* ─── Login page ─── */
@media (max-width: 600px) {
    .login-card { width: 95vw !important; padding: 24px 20px !important; }
}

/* ─── Small phones (iPhone 11 Pro 375px, SE 320px, etc.) ─── */
@media (max-width: 480px) {
    .pwa-tab-label { font-size: 10px; }
    .pwa-logo { font-size: 16px; letter-spacing: 1px; }
    .pwa-tab-item { gap: 2px; }
    body.pwa-mobile-active .content,
    html.pwa-mobile-active .content {
        padding: 10px 8px !important;
        padding-top: calc(var(--pwa-header-h) + env(safe-area-inset-top, 0px) + 12px) !important;
        padding-bottom: calc(var(--pwa-tab-h) + env(safe-area-inset-bottom, 0px) + 24px) !important;
        box-sizing: border-box !important;
    }
    body.pwa-mobile-active .stats-row,
    body.pwa-mobile-active .alert-banner {
        grid-template-columns: 1fr !important;
    }
}

/* ─── PWA Standalone Mode (installed app) ─── */
@media (display-mode: standalone) {
    .pwa-header {
        padding-top: env(safe-area-inset-top, 20px);
        height: calc(var(--pwa-header-h) + env(safe-area-inset-top, 20px));
    }
    .pwa-drawer { padding-top: env(safe-area-inset-top, 20px); }
    body.pwa-mobile-active .content,
    html.pwa-mobile-active .content {
        padding-top: calc(var(--pwa-header-h) + env(safe-area-inset-top, 20px) + 12px) !important;
    }
}

/* ═══ TACTILE TOUCH FEEDBACK (:active) ═══ */
@media (hover: none) and (pointer: coarse) {
    body.pwa-mobile-active .pwa-tab-item:active,
    body.pwa-mobile-active .pwa-menu-item:active,
    body.pwa-mobile-active .btn:active,
    body.pwa-mobile-active button.btn:active,
    body.pwa-mobile-active .quick-action-btn:active,
    body.pwa-mobile-active .r-tab:active,
    body.pwa-mobile-active .pwa-menu-btn:active,
    body.pwa-mobile-active .pwa-notification-btn:active,
    body.pwa-mobile-active .card:active {
        transform: scale(0.97);
        opacity: 0.88;
        transition: transform 0.08s ease, opacity 0.08s ease;
    }
}

/* ═══ PWA INSTALL ONBOARDING & GUIDES ═══ */
.pwa-install-menu-item {
    background: linear-gradient(135deg, rgba(12, 111, 209, 0.08), rgba(24, 144, 255, 0.12)) !important;
    border: 1.5px solid #0C6FD1 !important;
    color: #0C6FD1 !important;
    font-weight: 700 !important;
    border-radius: 10px !important;
    margin: 8px 16px !important;
}

.pwa-ios-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10010;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: pwaFadeIn 0.25s ease;
}

@keyframes pwaFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.pwa-ios-card {
    background: #FFFFFF;
    width: 100%;
    max-width: 440px;
    border-radius: 20px 20px 0 0;
    padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px));
    text-align: center;
    position: relative;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
    animation: pwaSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes pwaSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.pwa-ios-close {
    position: absolute;
    top: 14px;
    right: 16px;
    background: none;
    border: none;
    font-size: 24px;
    color: #94A3B8;
    cursor: pointer;
    line-height: 1;
}

.pwa-ios-step {
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    margin: 14px 0;
    padding: 10px 14px;
    background: #F8FAFC;
    border-radius: 12px;
    border: 1px solid #E2E8F0;
    font-size: 0.9rem;
    color: #1E293B;
}

.pwa-ios-step-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
}

/* ═══ LANDSCAPE ORIENTATION (COMPACT CHROME) ═══ */
@media (orientation: landscape) and (max-height: 500px) {
    :root {
        --pwa-header-h: 42px;
        --pwa-tab-h: 44px;
    }
    .pwa-header {
        height: calc(42px + env(safe-area-inset-top, 0px));
        padding-top: env(safe-area-inset-top, 0px);
        padding-left: calc(12px + env(safe-area-inset-left, 0px));
        padding-right: calc(12px + env(safe-area-inset-right, 0px));
    }
    .pwa-tab-bar {
        height: calc(44px + env(safe-area-inset-bottom, 0px));
        padding-left: calc(12px + env(safe-area-inset-left, 0px));
        padding-right: calc(12px + env(safe-area-inset-right, 0px));
    }
    .pwa-drawer-header,
    .pwa-drawer-menu {
        padding-left: calc(20px + env(safe-area-inset-left, 0px)) !important;
        padding-right: calc(20px + env(safe-area-inset-right, 0px)) !important;
    }
    .pwa-tab-label {
        display: none !important;
    }
    .pwa-tab-icon-wrap {
        width: 22px !important;
        height: 22px !important;
    }
    body.pwa-mobile-active .content,
    html.pwa-mobile-active .content {
        padding-top: calc(42px + env(safe-area-inset-top, 0px) + 8px) !important;
        padding-bottom: calc(44px + env(safe-area-inset-bottom, 0px) + 12px) !important;
    }
}

/* ═══ NETWORK STATUS TOAST ═══ */
.pwa-network-toast {
    position: fixed;
    top: calc(var(--pwa-header-h) + env(safe-area-inset-top, 0px) + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(-150%);
    color: #FFFFFF;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 20px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
    z-index: 10020;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
    white-space: nowrap;
}
.pwa-network-toast.pwa-toast-show {
    transform: translateX(-50%) translateY(0);
}

/* ═══ INSTANT TAP RESPONSE (Eliminates 300ms tap delay) ═══ */
body.pwa-mobile-active a,
body.pwa-mobile-active button,
body.pwa-mobile-active input,
body.pwa-mobile-active select,
body.pwa-mobile-active textarea,
body.pwa-mobile-active .pwa-tab-item,
body.pwa-mobile-active .pwa-menu-item,
body.pwa-mobile-active .btn,
body.pwa-mobile-active .card {
    touch-action: manipulation;
}

/* ═══ DISABLE SYSTEM CALLOUT & TEXT SELECTION ON CHROME ═══ */
.pwa-header,
.pwa-tab-bar,
.pwa-drawer,
.pwa-menu-btn,
.pwa-refresh-btn,
.pwa-notification-btn,
.pwa-tab-item,
.pwa-menu-item,
.btn {
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
}

/* ═══ FORM SUBMISSION LOCK & PREVENT DOUBLE TAP ═══ */
.pwa-submitting {
    pointer-events: none !important;
    opacity: 0.65 !important;
    cursor: not-allowed !important;
}

/* ═══ TOAST STACKING (Offset second toast) ═══ */
#pwa-network-toast.pwa-toast-show ~ #pwa-update-toast.pwa-toast-show,
.pwa-network-toast + .pwa-network-toast {
    top: calc(var(--pwa-header-h) + env(safe-area-inset-top, 0px) + 52px) !important;
}

/* ═══ MINIMUM 44PX TOUCH TARGETS (A11Y) ═══ */
.modal-close,
.pwa-drawer-close,
.pwa-chat-back,
.pwa-menu-btn,
.pwa-refresh-btn,
.pwa-notification-btn {
    min-width: 44px !important;
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
}

/* ═══ PRINT ISOLATION (Hides PWA Chrome on Print & PDF Export) ═══ */
@media print {
    #pwa-header,
    .pwa-header,
    #pwa-tab-bar,
    .pwa-tab-bar,
    #pwa-drawer,
    .pwa-drawer,
    #pwa-drawer-overlay,
    .pwa-drawer-overlay,
    .pwa-network-toast,
    #pwa-network-toast,
    #pwa-update-toast,
    #ai-fab-btn,
    #ai-chat-window,
    .pwa-actions {
        display: none !important;
    }
    body, html {
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
    }
}


/* ═══ PWA PUSH NOTIFICATIONS STYLES (iOS 16.4+ & MOBILE) ═══ */
.pwa-push-banner {
    position: fixed;
    bottom: calc(var(--pwa-tab-h, 60px) + env(safe-area-inset-bottom, 0px) + 12px);
    left: 12px;
    right: 12px;
    background: #FFFFFF;
    border-radius: 14px;
    padding: 12px 14px;
    box-shadow: 0 8px 24px rgba(12, 111, 209, 0.2), 0 2px 8px rgba(0,0,0,0.08);
    border: 1px solid rgba(12, 111, 209, 0.2);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10000;
    animation: pwaSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes pwaSlideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.pwa-push-banner-icon {
    font-size: 24px;
    flex-shrink: 0;
}
.pwa-push-banner-text {
    flex: 1;
    min-width: 0;
}
.pwa-push-banner-title {
    font-weight: 700;
    font-size: 0.85rem;
    color: #1E293B;
    margin-bottom: 2px;
}
.pwa-push-banner-desc {
    font-size: 0.75rem;
    color: #64748B;
    line-height: 1.25;
}
.pwa-push-banner-btn {
    background: #0C6FD1;
    color: #FFFFFF;
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
}
.pwa-push-banner-close {
    background: transparent;
    border: none;
    color: #94A3B8;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 4px;
    flex-shrink: 0;
}
.pwa-chat-bell-btn {
    background: rgba(12, 111, 209, 0.1);
    color: #0C6FD1;
    border: 1px solid rgba(12, 111, 209, 0.25);
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    margin-right: 8px;
    flex-shrink: 0;
    transition: all 0.2s ease;
}
.pwa-chat-bell-btn.pwa-bell-enabled {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
    border-color: rgba(16, 185, 129, 0.25);
}
.pwa-menu-push-status {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 6px;
    margin-left: auto;
    font-weight: 600;
}
.pwa-menu-push-status.active {
    background: #DCFCE7;
    color: #15803D;
}
.pwa-menu-push-status.inactive {
    background: #FEF3C7;
    color: #B45309;
}
