/* ============================================================
   MOBILE / RESPONSIVE SHELL — crmka
   Breakpoint: < 1024px = mobile
   ============================================================ */

/* ── Фиксируем хедер и убираем болтание на мобильных ── */
@media (max-width: 1023.98px) {
    html {
        overflow-x: clip; /* только здесь — не ломает root-scroller */
    }
    body {
        /* НЕ ставим overflow-x на body: это меняет root-scroller в Chrome/Android
           и блокирует touch-scroll на всей странице */
        overscroll-behavior: none; /* убирает iOS-резинку / bounce */
        /* 56 header + 52 summary + 44 status + 40 date = 192px */
        padding-top: 192px !important;
        padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
    }
    body.mob-wh-view {
        /* 56 header + mob-wh-filters height (set by JS via --mob-wh-pad) */
        padding-top: var(--mob-wh-pad, 112px) !important;
    }
    body.mob-board-view {
        padding-top: 108px !important;
    }
    body.mob-board-view #mob-date-bar {
        top: 56px !important;
    }
    .app-header {
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        background: linear-gradient(180deg, rgba(255,255,255,0.98) 0%, rgba(255,255,255,0.95) 100%) !important;
        backdrop-filter: saturate(1.25) blur(14px);
        -webkit-backdrop-filter: saturate(1.25) blur(14px);
        box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
    }

    #board-btn-header { display: none !important; }
    #orders-table-container { display: none !important; }
    .wh-table-wrap { display: none !important; }
    #wh-footer-bar { display: none !important; }
    .date-filters-container { display: none !important; }
    .view-toggle { display: none !important; }
    .stat-bar { display: none !important; }
    #export-orders-xls-btn,
    #export-warehouse-xls-btn { display: none !important; }

    .container-fluid {
        padding-left: 8px;
        padding-right: 8px;
    }

    .card {
        border: 1px solid #e8ecf3;
        border-radius: 18px;
        overflow: hidden;
        box-shadow: 0 16px 40px rgba(15, 23, 42, 0.06);
        background: linear-gradient(180deg, #ffffff 0%, #fbfcff 100%);
    }

    .card-header {
        padding: 10px 12px;
        background: linear-gradient(180deg, #ffffff 0%, #faf8ff 100%);
        border-bottom: 1px solid #edf1f7;
    }
    .card-body {
        padding: 8px 12px;
    }
    .ch-title {
        font-size: .875rem;
    }
    .ch-btn {
        font-size: .82rem;
        padding: .38rem .75rem;
    }

    #new-order-btn-header,
    #add-warehouse-item-btn { display: none !important; }

    #drp-popup {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        background: #ffffff !important;
        border-radius: 18px 18px 0 0 !important;
        border: 1px solid #e5e7eb !important;
        box-shadow: 0 -8px 32px rgba(0,0,0,.15) !important;
        z-index: 1100 !important;
        padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px)) !important;
    }
    #drp-popup::after {
        content: '';
        display: block;
        width: 42px;
        height: 5px;
        border-radius: 999px;
        background: #d6dbe5;
        position: absolute;
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
    }
    #drp-popup .drp-month-header {
        margin-top: 8px;
    }
    #drp-popup .drp-col-divider,
    #drp-cal-right { display: none !important; }
    #drp-popup .drp-calendars { justify-content: center !important; }
    #drp-cal-left {
        width: 100% !important;
        max-width: 340px !important;
        margin: 0 auto !important;
    }
    #drp-popup .drp-footer {
        gap: 10px;
        align-items: stretch;
        flex-direction: column;
    }
    #drp-popup .drp-actions {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
    #drp-popup .drp-btn-cancel,
    #drp-popup .drp-btn-apply {
        min-height: 42px;
        width: 100%;
    }
    #drp-popup.drp-open::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.35);
        z-index: -1;
    }

    #mob-summary-bar,
    #mob-status-filters,
    #mob-wh-filters,
    #mob-date-bar {
        position: fixed !important;
        left: 0;
        right: 0;
        z-index: 920;
    }
    #mob-summary-bar {
        top: 56px;
        z-index: 922;
    }
    #mob-status-filters {
        top: 108px;
        z-index: 921;
    }
    #mob-wh-filters {
        top: 56px;
        z-index: 921;
    }
    #mob-date-bar { top: 152px; }

    #pagination-container,
    #wh-pagination-container {
        display: none !important;
    }
}

/* ── Компактный хедер на мобильных ── */
@media (max-width: 1023.98px) {
    .app-header-inner {
        padding: 0 0.75rem !important;
        gap: 0.35rem !important;
        min-height: 56px;
    }
    .app-logo {
        margin-right: 0.15rem;
    }
    .app-logo span {
        font-size: 1rem;
    }
    .app-header-actions .hdr-btn span {
        display: none !important;
    }
    .app-header-actions .hdr-btn {
        width: 38px;
        height: 38px;
        padding: 0 !important;
        min-width: 38px;
        justify-content: center !important;
        border-radius: 11px !important;
    }
    .app-header-actions .hdr-btn.active {
        box-shadow: 0 8px 18px rgba(79, 70, 229, 0.14);
    }
    .hdr-profile-info { display: none !important; }
    .hdr-separator { display: none !important; }
    .hdr-separator-v { display: none !important; }
    #reports-btn-header { display: none !important; }
    .app-header-right { gap: 6px !important; }
    .hdr-support-btn span { display: none !important; }
    .hdr-support-btn {
        width: 36px !important;
        height: 36px !important;
        padding: 0 !important;
        justify-content: center !important;
        border-radius: 11px !important;
    }
    .hdr-support-btn i { font-size: .95rem !important; }
    .hdr-profile {
        padding: 2px !important;
    }
    .hdr-avatar {
        width: 34px;
        height: 34px;
        font-size: 0.78rem;
        box-shadow: 0 8px 18px rgba(99, 102, 241, 0.18);
    }
    .hdr-icon-btn {
        width: 36px;
        height: 36px;
        border-radius: 11px;
    }
    .hdr-my-toggle {
        padding: 2px !important;
        gap: 6px !important;
    }
    .hdr-my-label {
        display: block !important;
        font-size: .66rem;
        line-height: 1.05;
        white-space: normal;
    }
    .hdr-my-track {
        width: 34px;
        height: 20px;
    }
    .hdr-my-thumb {
        width: 16px;
        height: 16px;
    }
    .hdr-my-toggle input:checked ~ .hdr-my-track .hdr-my-thumb {
        transform: translateX(14px);
    }
}

/* Скрыть мобильные shell-элементы на десктопе */
@media (min-width: 1024px) {
    #mob-summary-bar { display: none !important; }
    #mob-status-filters { display: none !important; }
    #mob-wh-filters { display: none !important; }
    #mob-date-bar { display: none !important; }
    #mob-fab-bar { display: none !important; }
}

/* ── FAB-бар ── */
.mob-fab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 950;
    padding: .65rem .85rem calc(.65rem + env(safe-area-inset-bottom, 0px));
    background: rgba(255,255,255,0.96);
    border-top: 1px solid #e8eaed;
    box-shadow: 0 -12px 28px rgba(15, 23, 42, 0.08);
    backdrop-filter: saturate(1.2) blur(12px);
    -webkit-backdrop-filter: saturate(1.2) blur(12px);
}

.mob-fab-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .85rem 1rem;
    border-radius: 14px;
    border: none;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 52px;
    -webkit-tap-highlight-color: transparent;
    transition: opacity .13s, transform .1s;
}

.mob-fab-btn:active {
    opacity: .85;
    transform: scale(.98);
}

.mob-fab-btn i { font-size: 1.1rem; }

.mob-fab-primary {
    background: #4f46e5;
    color: #fff;
}

.mob-fab-success {
    background: #059669;
    color: #fff;
}

/* ── Мобильная полоска дат ── */
.mob-date-bar {
    display: flex;
    align-items: center;
    gap: .35rem;
    touch-action: pan-x;
    overflow-x: auto;
    scrollbar-width: none;
    padding: .45rem .85rem;
    background: rgba(255,255,255,0.98);
    border-bottom: 1px solid #e8eaed;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.04);
    -webkit-overflow-scrolling: touch;
}

.mob-date-bar::-webkit-scrollbar { display: none; }

.mob-date-pill {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .3rem .75rem;
    border-radius: 20px;
    border: 1.5px solid #e8eaed;
    background: #fff;
    font-family: inherit;
    font-size: .8rem;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background .12s, border-color .12s, color .12s;
    -webkit-tap-highlight-color: transparent;
}

.mob-date-pill.active {
    background: #ebe9ff;
    border-color: #c7d2fe;
    color: #4f46e5;
}

.mob-date-pill:active { transform: scale(.96); }

.mob-date-cal {
    margin-left: auto;
    flex-shrink: 0;
}

.mob-date-cal.has-value {
    background: #ede9fe;
    border-color: #a78bfa;
    color: #5b21b6;
}

#mob-drp-label:empty { display: none; }

/* ── Итого ── */
.mob-summary-bar {
    background: rgba(255,255,255,0.98);
    border-bottom: 1px solid #e8eaed;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.04);
    padding: .65rem 1rem .55rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    column-gap: .75rem;
    min-height: 52px;
}

.mob-summary-copy {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.mob-summary-label {
    font-size: .78rem;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: .05em;
    min-width: 0;
}

.mob-summary-meta {
    font-size: .66rem;
    font-weight: 500;
    color: #94a3b8;
    letter-spacing: .02em;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mob-summary-amount {
    font-size: 1.1rem;
    font-weight: 800;
    color: #4f46e5;
    letter-spacing: -.02em;
    white-space: nowrap;
    text-align: right;
}

/* ── Фильтры-иконки ── */
.mob-status-filters {
    display: flex;
    align-items: center;
    gap: .4rem;
    touch-action: pan-x;
    overflow-x: auto;
    scrollbar-width: none;
    padding: .5rem 1rem;
    background: rgba(255,255,255,0.98);
    border-bottom: 1px solid #e8eaed;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.04);
    -webkit-overflow-scrolling: touch;
}

.mob-status-filters::-webkit-scrollbar { display: none; }

.mob-sf-pill {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .3rem .65rem;
    border-radius: 20px;
    border: 1.5px solid #e8eaed;
    background: #fff;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    font-size: .8rem;
    font-weight: 600;
    color: #64748b;
    transition: background .13s, border-color .13s, color .13s;
    -webkit-tap-highlight-color: transparent;
    font-family: inherit;
}

.mob-sf-pill i { font-size: .85rem; }

.mob-sf-pill .mob-sf-count {
    font-size: .8rem;
    font-weight: 700;
    min-width: 14px;
    text-align: center;
}

.mob-sf-pill.active {
    background: var(--mob-sf-bg, #ebe9ff);
    border-color: transparent;
    color: var(--mob-sf-color, #4f46e5);
}

.mob-sf-pill:active { transform: scale(.96); }

/* Warehouse category filter bar — wrapping grid */
#mob-wh-filters {
    flex-wrap: wrap;
    overflow-x: hidden;
    gap: .35rem;
}
#mob-wh-filters .mob-sf-pill {
    width: calc(33.33% - 0.24rem);
    justify-content: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Спиннер ленивой пагинации ── */
.mob-load-spinner {
    display: flex;
    justify-content: center;
    gap: .35rem;
    padding: 1.25rem 0;
}

.mob-load-spinner span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #c7d2fe;
    animation: mobBounce .9s ease-in-out infinite;
}

.mob-load-spinner span:nth-child(2) { animation-delay: .15s; }
.mob-load-spinner span:nth-child(3) { animation-delay: .3s; }

@keyframes mobBounce {
    0%, 80%, 100% { transform: scale(.7); opacity: .5; }
    40% { transform: scale(1); opacity: 1; }
}
