/**
 * CRM mobile fixes.
 * Loaded after the theme CSS to keep mobile overrides readable and isolated.
 */

:root {
    --crm-topbar-height: var(--crm-header-height, 64px);
    --crm-mobile-history-bar-height: 0px;
    --crm-topbar-inset-min: 0px;
    --crm-safe-area-top: 0px;
    --crm-safe-area-left: 0px;
    --crm-safe-area-right: 0px;
    --crm-topbar-stack-height: calc(var(--crm-topbar-height) + var(--crm-mobile-history-bar-height));
    --crm-header-visible: var(--crm-topbar-stack-height);
}

body[data-bs-theme="light"],
body[data-bs-theme="dark"] {
    --crm-topbar-stack-height: calc(var(--crm-topbar-height) + var(--crm-mobile-history-bar-height));
}

@media (max-width: 767.98px), (max-width: 991.98px) and (max-height: 850px) {
    :root,
    body.crm-shell,
    body[data-bs-theme="light"],
    body[data-bs-theme="dark"] {
        --crm-header-offset: 0px;
        --crm-topbar-stack-height: calc(var(--crm-header-height, 64px) + env(safe-area-inset-top, 0px) + var(--crm-mobile-history-bar-height, 0px));
        --crm-header-visible: var(--crm-topbar-stack-height);
    }

    body.crm-pwa-standalone {
        --crm-topbar-stack-height: calc(var(--crm-header-height, 64px) + max(env(safe-area-inset-top, 0px), 28px) + var(--crm-mobile-history-bar-height, 0px));
    }

    body.crm-ios.crm-pwa-standalone {
        --crm-topbar-stack-height: calc(var(--crm-header-height, 64px) + max(env(safe-area-inset-top, 0px), 44px) + var(--crm-mobile-history-bar-height, 0px));
    }
}

#page-topbar {
    display: flex;
    flex-direction: column;
}

.crm-topbar-safe-area {
    flex: 0 0 auto;
    width: 100%;
    height: 0;
    pointer-events: none;
    background-color: var(--bs-header-bg);
}

/* Язык, тема, почта, уведомления, звук — одна строка, выровненные иконки */
.crm-header-icon-tools {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    gap: 0;
}

.crm-header-icon-tools > .dropdown,
.crm-header-icon-tools > div {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.crm-header-icon-tools .header-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: var(--crm-topbar-height);
    padding-top: 0;
    padding-bottom: 0;
    line-height: 1;
}

.crm-header-icon-tools .header-item .icon-lg:not(.layout-mode-dark):not(.layout-mode-light),
.crm-header-icon-tools .header-item svg:not(.layout-mode-dark):not(.layout-mode-light) {
    display: block;
    flex-shrink: 0;
}

.crm-header-icon-tools .header-item .layout-mode-light {
    display: none;
}

body[data-bs-theme="dark"] .crm-header-icon-tools .header-item .layout-mode-dark {
    display: none;
}

body[data-bs-theme="dark"] .crm-header-icon-tools .header-item .layout-mode-light {
    display: block;
}

.crm-header-icon-tools #header-lang-img {
    display: block;
}

.crm-header-icon-tools #crm-sound-toggle {
    padding-top: 0 !important;
}

.crm-header-icon-tools .crm-sound-toggle-icon {
    width: 20px;
    height: 20px;
}

/* Планшет и мобильный: safe-area на всех страницах (header, контент, правые панели). */
@media (max-width: 991.98px) {
    :root {
        --crm-safe-area-left: env(safe-area-inset-left, 0px);
        --crm-safe-area-right: env(safe-area-inset-right, 0px);
        --crm-safe-area-top: env(safe-area-inset-top, 0px);
    }

    #page-topbar {
        padding-top: env(safe-area-inset-top, 0px);
        padding-left: env(safe-area-inset-left, 0px);
        padding-right: env(safe-area-inset-right, 0px);
    }

    body.crm-pwa-standalone #page-topbar {
        padding-top: max(env(safe-area-inset-top, 0px), 28px);
    }

    body.crm-ios.crm-pwa-standalone #page-topbar {
        padding-top: max(env(safe-area-inset-top, 0px), 44px);
    }

    .crm-topbar-safe-area {
        display: none !important;
        height: 0 !important;
    }

    .page-content {
        padding-top: calc(var(--crm-header-offset, 0px) + var(--crm-page-content-pad-top, 1.5rem)) !important;
    }

    /* Список уже сдвинут глобальным padding-top — не дублировать высоту шапки. */
    .crm-clients-page-title-box {
        padding-top: 0.35rem !important;
    }

    .right-bar {
        top: var(--crm-safe-area-top, 0px);
    }

    .rightbar-overlay {
        top: var(--crm-safe-area-top, 0px);
    }

    .offcanvas {
        top: var(--crm-safe-area-top, 0px);
        height: calc(100% - var(--crm-safe-area-top, 0px));
        max-height: calc(100% - var(--crm-safe-area-top, 0px));
    }

    @supports (height: 100dvh) {
        .offcanvas {
            height: calc(100dvh - var(--crm-safe-area-top, 0px));
            max-height: calc(100dvh - var(--crm-safe-area-top, 0px));
        }
    }
}

.crm-mobile-history-bar {
    display: none;
    flex: 0 0 auto;
    width: 100%;
    /* height: var(--crm-mobile-history-bar-height); */
    background: transparent;
    border-bottom: 1px solid var(--bs-border-color);
    padding: 0.3rem max(0.75rem, env(safe-area-inset-right, 0px)) 0.2rem max(0.75rem, env(safe-area-inset-left, 0px));
    z-index: 1;
}

#page-topbar .navbar-header {
    z-index: 2;
}

#page-topbar .navbar-header .dropdown-menu {
    z-index: 1055;
}

.crm-mobile-history-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    height: 100%;
    width: 100%;
    max-width: 100%;
}

.crm-mobile-history-nav__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1rem;
    height: 2rem;
    padding: 0 0.5rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.625rem;
    background: transparent;
    color: var(--bs-header-item-color);
    box-shadow: none !important;
    transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.crm-mobile-history-nav__btn:not(:disabled):hover,
.crm-mobile-history-nav__btn:not(:disabled):focus {
    color: var(--bs-header-item-color);
    background-color: rgba(var(--bs-primary-rgb, 81, 86, 190), 0.08);
    border-color: rgba(var(--bs-primary-rgb, 81, 86, 190), 0.35);
}

.crm-mobile-history-nav__btn:not(:disabled):active {
    background-color: rgba(var(--bs-primary-rgb, 81, 86, 190), 0.14);
}

body[data-bs-theme="dark"] .crm-mobile-history-nav__btn {
    border-color: rgba(255, 255, 255, 0.18);
}

body[data-bs-theme="dark"] .crm-mobile-history-nav__btn:not(:disabled):hover,
body[data-bs-theme="dark"] .crm-mobile-history-nav__btn:not(:disabled):focus {
    background-color: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.28);
}

body[data-bs-theme="dark"] .crm-mobile-history-nav__btn:not(:disabled):active {
    background-color: rgba(255, 255, 255, 0.1);
}

.crm-mobile-history-nav__btn[hidden] {
    display: none !important;
}

.crm-mobile-history-nav__btn:disabled,
.crm-mobile-history-nav__btn[disabled] {
    opacity: 0.38;
    pointer-events: none;
    border-color: var(--bs-border-color);
    background: transparent;
}

@keyframes crm-history-arrow-in {
    from {
        opacity: 0;
        transform: translateY(-70%);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 767.98px) {
    /*
     * Back/forward sit outside the header box. They must not join the
     * topbar's height, or the page below jumps when the buttons appear.
     */
    html.crm-mobile-history-active {
        --crm-mobile-history-bar-height: 0px;
    }

    html.crm-mobile-history-active body:not(.crm-header-away) #page-topbar.crm-shell-header {
        overflow: visible;
    }

    html.crm-mobile-history-active body:not(.crm-header-away) .crm-mobile-history-bar {
        display: block;
        position: absolute;
        top: 100%;
        right: 0;
        left: 0;
        width: auto;
        height: 0;
        margin: 0;
        padding: 0;
        border: 0;
        background: transparent;
        box-shadow: none;
        overflow: visible;
        z-index: 6;
        pointer-events: none;
    }

    html.crm-mobile-history-active body:not(.crm-header-away) .crm-mobile-history-nav {
        display: block;
        width: 100%;
        height: 0;
        pointer-events: none;
    }

    html.crm-mobile-history-active body:not(.crm-header-away) .crm-mobile-history-nav__btn {
        position: absolute;
        top: 0.3rem;
        min-width: 2.25rem;
        height: 2.25rem;
        padding: 0;
        border-color: transparent;
        background: transparent;
        pointer-events: auto;
        transition: color 0.2s ease, opacity 0.2s ease;
        animation: crm-history-arrow-in 0.32s ease both;
    }

    html.crm-mobile-history-active body:not(.crm-header-away) #crm-nav-back {
        left: max(0.35rem, env(safe-area-inset-left, 0px));
    }

    html.crm-mobile-history-active body:not(.crm-header-away) #crm-nav-forward {
        right: max(0.35rem, env(safe-area-inset-right, 0px));
    }

    html.crm-mobile-history-active body:not(.crm-header-away) #page-topbar.crm-shell-header .crm-mobile-history-nav__btn,
    html.crm-mobile-history-active body:not(.crm-header-away) #page-topbar.crm-shell-header .crm-mobile-history-nav__btn:not(:disabled):hover,
    html.crm-mobile-history-active body:not(.crm-header-away) #page-topbar.crm-shell-header .crm-mobile-history-nav__btn:not(:disabled):focus,
    html.crm-mobile-history-active body:not(.crm-header-away) #page-topbar.crm-shell-header .crm-mobile-history-nav__btn:not(:disabled):active {
        color: #1a1d26;
        border-color: transparent;
        background: transparent;
    }

    html.crm-mobile-history-active body:not(.crm-header-away)[data-bs-theme="dark"] #page-topbar.crm-shell-header .crm-mobile-history-nav__btn,
    html.crm-mobile-history-active body:not(.crm-header-away)[data-bs-theme="dark"] #page-topbar.crm-shell-header .crm-mobile-history-nav__btn:not(:disabled):hover,
    html.crm-mobile-history-active body:not(.crm-header-away)[data-bs-theme="dark"] #page-topbar.crm-shell-header .crm-mobile-history-nav__btn:not(:disabled):focus,
    html.crm-mobile-history-active body:not(.crm-header-away)[data-bs-theme="dark"] #page-topbar.crm-shell-header .crm-mobile-history-nav__btn:not(:disabled):active {
        color: #f7f8fb;
    }

    html.crm-mobile-history-active body:not(.crm-header-away) #page-topbar.crm-shell-header .crm-mobile-history-nav__btn.crm-history-on-light,
    html.crm-mobile-history-active body:not(.crm-header-away) #page-topbar.crm-shell-header .crm-mobile-history-nav__btn.crm-history-on-light:not(:disabled):hover,
    html.crm-mobile-history-active body:not(.crm-header-away) #page-topbar.crm-shell-header .crm-mobile-history-nav__btn.crm-history-on-light:not(:disabled):focus,
    html.crm-mobile-history-active body:not(.crm-header-away) #page-topbar.crm-shell-header .crm-mobile-history-nav__btn.crm-history-on-light:not(:disabled):active {
        color: #1a1d26;
    }

    html.crm-mobile-history-active body:not(.crm-header-away) #page-topbar.crm-shell-header .crm-mobile-history-nav__btn.crm-history-on-dark,
    html.crm-mobile-history-active body:not(.crm-header-away) #page-topbar.crm-shell-header .crm-mobile-history-nav__btn.crm-history-on-dark:not(:disabled):hover,
    html.crm-mobile-history-active body:not(.crm-header-away) #page-topbar.crm-shell-header .crm-mobile-history-nav__btn.crm-history-on-dark:not(:disabled):focus,
    html.crm-mobile-history-active body:not(.crm-header-away) #page-topbar.crm-shell-header .crm-mobile-history-nav__btn.crm-history-on-dark:not(:disabled):active {
        color: #f7f8fb;
    }

    html.crm-mobile-history-active body:not(.crm-header-away) #page-topbar.crm-shell-header .crm-mobile-history-nav__btn svg {
        stroke: currentColor;
    }
}

@media (max-width: 767.98px) and (prefers-reduced-motion: reduce) {
    html.crm-mobile-history-active body:not(.crm-header-away) .crm-mobile-history-nav__btn {
        animation: none;
        opacity: 1;
        transform: none;
    }
}

/*
 * Header in document flow has scrolled away: keep back/forward reachable
 * as a compact cluster at the top center (above page content, beside burger).
 */
html.crm-mobile-history-active body.crm-header-away #page-topbar.crm-shell-header {
    overflow: visible;
    z-index: auto;
}

html.crm-mobile-history-active body.crm-header-away .crm-mobile-history-bar {
    display: flex;
    position: fixed;
    top: max(0.4rem, env(safe-area-inset-top, 0px));
    left: 0;
    right: 0;
    width: max-content;
    max-width: calc(100vw - 6rem);
    margin-inline: auto;
    z-index: 1106;
    padding: 0.2rem 0.25rem;
    border: 0;
    background: transparent;
    box-shadow: none;
    pointer-events: auto;
    mix-blend-mode: difference;
}

html.crm-mobile-history-active body.crm-header-away .crm-mobile-history-nav {
    justify-content: center;
    width: auto;
    gap: 0.15rem;
}

html.crm-mobile-history-active body.crm-header-away .crm-mobile-history-nav__btn,
html.crm-mobile-history-active body.crm-header-away .crm-mobile-history-nav__btn:not(:disabled):hover,
html.crm-mobile-history-active body.crm-header-away .crm-mobile-history-nav__btn:not(:disabled):focus,
html.crm-mobile-history-active body.crm-header-away .crm-mobile-history-nav__btn:not(:disabled):active {
    min-width: 2.5rem;
    height: 2.25rem;
    color: #fff;
    border-color: rgba(255, 255, 255, 0.85);
    background: transparent;
    border: none;
}

html.crm-mobile-history-active body.crm-pwa-standalone.crm-header-away .crm-mobile-history-bar {
    top: max(0.4rem, env(safe-area-inset-top, 0px), 28px);
}

html.crm-mobile-history-active body.crm-ios.crm-pwa-standalone.crm-header-away .crm-mobile-history-bar {
    top: max(0.4rem, env(safe-area-inset-top, 0px), 44px);
}

@media (max-width: 767.98px) {
    /*
     * iOS Safari zooms the whole page when a focused form control is below 16px.
     * Keep mobile controls at 16px while preserving desktop/tablet density.
     */
    input,
    select,
    textarea,
    .form-control,
    .form-select,
    .form-control-sm,
    .form-select-sm,
    .input-group-sm > .form-control,
    .input-group-sm > .form-select {
        font-size: 16px !important;
    }

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

    #page-topbar,
    .navbar-header {
        max-width: 100vw;
        overflow: visible;
    }

    .navbar-header {
        min-width: 0;
    }

    .navbar-header > .d-flex:first-child {
        min-width: 0;
        flex: 1 1 auto;
        align-items: center;
    }

    #page-topbar.crm-shell-header .navbar-brand-box .logo img {
        vertical-align: middle;
    }

    .navbar-header > .d-flex:last-child {
        flex: 0 0 auto;
        min-width: 0;
        gap: 0.25rem;
    }

    .crm-header-left-tools {
        min-width: 0;
        flex: 1 1 auto;
    }

    .crm-header-left-tools .app-search,
    #page-header-search-dropdown {
        display: none !important;
    }

    .navbar-header .header-item {
        height: var(--crm-topbar-height);
        padding-left: 0.45rem !important;
        padding-right: 0.45rem !important;
    }

    .crm-header-icon-tools .header-item {
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        padding-left: 0.35rem !important;
        padding-right: 0.35rem !important;
    }

    .navbar-header .dropdown.d-none.d-sm-inline-block {
        display: inline-block !important;
    }

    .crm-header-icon-tools .dropdown.d-none.d-sm-inline-block {
        display: flex !important;
    }

    #crm-sound-toggle {
        display: inline-flex !important;
        align-items: center;
    }

    #page-header-user-dropdown {
        min-width: auto;
    }
}

@media (max-width: 460px) {
    #Profile-admina {
        display: none !important;
    }
}

@media (max-width: 444.98px) {
    .crm-header-user-dropdown {
        display: flex;
        align-items: center;
        align-self: stretch;
        flex-shrink: 0;
    }

    #page-header-user-dropdown.header-item {
        width: 35px !important;
        min-width: 35px !important;
        max-width: 35px !important;
        height: var(--crm-topbar-height, var(--crm-header-height, 64px)) !important;
        min-height: var(--crm-topbar-height, var(--crm-header-height, 64px)) !important;
        max-height: none !important;
        padding: 3px !important;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        box-sizing: border-box;
    }

    #page-header-user-dropdown .header-profile-user {
        width: 29px !important;
        height: 29px !important;
        min-width: 29px;
        min-height: 29px;
        max-width: 29px;
        max-height: 29px;
        padding: 0 !important;
        margin: 0;
        aspect-ratio: 1 / 1;
        object-fit: cover;
        object-position: center;
        border-radius: 50%;
        flex-shrink: 0;
    }

}

@media (max-width: 420px) {
    .navbar-header {
        padding-left: 0 !important;
    }

    #vertical-menu-btn {
        padding-left: 0.35rem !important;
        padding-right: 0.35rem !important;
    }

    .crm-header-attention-btn {
        padding-left: 0.4rem !important;
        padding-right: 0.4rem !important;
    }

    .crm-header-attention-btn__label {
        display: none !important;
    }

    .navbar-header .header-item {
        padding-left: 0.3rem !important;
        padding-right: 0.5rem !important;
    }

    #crm-sound-toggle {
        display: inline-flex !important;
    }
}

@media (max-width: 380px) {
    .navbar-header .header-item {
        padding-left: 0.3rem !important;
        padding-right: 0.3rem !important;
    }
    #page-topbar.crm-shell-header #crm-header-accounting-btn.crm-header-accounting-btn {
        display: none;
    }
}

@media (max-width: 324.98px) {
    body:not([data-sidebar-size=sm]) #vertical-menu-btn {
        margin-right: -8px;
    }
}

@media (max-width: 320px) {
    #page-topbar.crm-shell-header .navbar-header .header-item {
        padding-right: 0.3rem !important;
        padding-left: 0.3rem !important;
    }

    .crm-header-icon-tools .header-item {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
}

@media (max-width: 991.98px) {
    body.sidebar-enable .vertical-menu {
        top: var(--crm-header-visible, var(--crm-topbar-stack-height));
        bottom: 0;
        width: min(280px, 86vw) !important;
        height: auto;
        max-height: none;
        overflow-x: hidden !important;
        overflow-y: hidden !important;
        overscroll-behavior: contain;
    }

    body.sidebar-enable .vertical-menu [data-simplebar].h-100,
    body.sidebar-enable .vertical-menu .simplebar-wrapper,
    body.sidebar-enable .vertical-menu .simplebar-mask,
    body.sidebar-enable .vertical-menu .simplebar-offset,
    body.sidebar-enable .vertical-menu .simplebar-content-wrapper {
        height: 100% !important;
        max-height: 100% !important;
        min-height: 0 !important;
    }

    body.sidebar-enable .vertical-menu .simplebar-content-wrapper {
        overflow-x: hidden !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    body.sidebar-enable .vertical-menu .simplebar-content {
        min-height: auto !important;
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px)) !important;
    }

    body.sidebar-enable .vertical-menu #sidebar-menu {
        text-align: left !important;
        padding-bottom: 0.75rem;
    }

    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu .menu-title {
        display: block !important;
    }

    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu .badge {
        display: inline-block !important;
    }

    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu .sidebar-alert {
        display: block !important;
    }

    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu > ul > li {
        white-space: normal !important;
    }

    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu > ul > li > a {
        width: auto !important;
        padding: 1rem !important;
    }

    body.sidebar-enable .vertical-menu #sidebar-menu > ul > li[data-crm-menu-block="t-invoice-catalog"] > a.crm-sidebar-catalog-link {
        justify-content: flex-start !important;
    }

    body.sidebar-enable .vertical-menu #sidebar-menu > ul > li[data-crm-menu-block="crm-automation-menu"] > a > i {
        font-size: 1rem !important;
        line-height: 1.25rem;
    }

    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu > ul > li > a i,
    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu > ul > li > a svg {
        margin-left: 0 !important;
    }

    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu > ul > li > a span {
        display: inline !important;
        padding-left: 0 !important;
    }

    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu > ul > li > a.has-arrow::after {
        display: block !important;
    }

    body.sidebar-enable[data-sidebar-size="sm"] #sidebar-menu .mm-active > .has-arrow::after {
        transform: rotate(90deg) !important;
    }

    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu > ul > li:hover > a {
        width: auto !important;
        background-color: transparent !important;
    }

    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu ul.sub-menu,
    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu > ul > li:hover > ul,
    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu > ul ul li:hover > ul {
        position: static !important;
        left: auto !important;
        top: auto !important;
        width: auto !important;
        height: auto !important;
        margin-top: 0 !important;
        box-shadow: none !important;
        -webkit-box-shadow: none !important;
    }

    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu ul.sub-menu:not(.mm-show):not(.mm-collapsing) {
        display: none !important;
    }

    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu ul.sub-menu.mm-show,
    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu ul.sub-menu.mm-collapsing {
        display: block !important;
    }

    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu ul.sub-menu li a {
        padding: 0.4rem 1.5rem 0.4rem 1.3rem !important;
    }

    body.sidebar-enable[data-sidebar-size="sm"] .vertical-menu #sidebar-menu ul.sub-menu li ul.sub-menu li a {
        padding-left: 2.4rem !important;
    }

    body.crm-header-away.sidebar-enable .vertical-menu {
        padding-top: env(safe-area-inset-top, 0px);
    }

    body.crm-header-away .crm-sidebar-float-btn {
        top: max(0.5rem, env(safe-area-inset-top, 0px));
        left: max(0.5rem, env(safe-area-inset-left, 0px));
    }

    body.crm-pwa-standalone.crm-header-away .crm-sidebar-float-btn {
        top: max(0.5rem, env(safe-area-inset-top, 0px), 28px);
    }

    body.crm-ios.crm-pwa-standalone.crm-header-away .crm-sidebar-float-btn {
        top: max(0.5rem, env(safe-area-inset-top, 0px), 44px);
    }
}

/* Таймер открытой смены (ЧЧ:ММ:СС) — на телефоне не меньше 14px */
@media (max-width: 767.98px) {
    .crm-shift-elapsed-timer {
        font-size: 22px !important;
        line-height: 1.2;
        font-variant-numeric: tabular-nums;
    }

    .crm-sidebar-shift-cta .crm-shift-elapsed-timer,
    body[data-sidebar-size="sm"] .crm-sidebar-shift-cta .crm-shift-elapsed-timer,
    body[data-sidebar-size="md"] .crm-sidebar-shift-cta .crm-shift-elapsed-timer {
        font-size: 14px !important;
    }

    .crm-shift-timer-btn .crm-shift-elapsed-timer.small,
    .crm-shift-timer-btn .crm-shift-elapsed-timer.font-monospace.small {
        font-size: 14px !important;
    }
}

/*
 * Модалки на телефоне: по центру экрана, ~50px от верха/низа
 * (динамик / notch не перекрывают крестик), скролл внутри body.
 */
@media (max-width: 767.98px) {
    :root {
        --crm-modal-gap-y: max(50px, env(safe-area-inset-top, 0px));
        --crm-modal-gap-y-bottom: max(50px, env(safe-area-inset-bottom, 0px));
        --crm-modal-max-height: calc(100dvh - var(--crm-modal-gap-y) - var(--crm-modal-gap-y-bottom));
    }

    .modal {
        --bs-modal-margin: var(--crm-modal-gap-y);
    }

    .modal.show {
        display: flex !important;
        align-items: center;
        justify-content: center;
        padding: var(--crm-modal-gap-y) max(0.5rem, env(safe-area-inset-right, 0px)) var(--crm-modal-gap-y-bottom) max(0.5rem, env(safe-area-inset-left, 0px)) !important;
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal.show .modal-dialog {
        margin: 0 auto !important;
        max-height: var(--crm-modal-max-height);
        max-width: 100%;
    }

    .modal.show .modal-dialog-centered {
        min-height: 0 !important;
        display: flex;
        align-items: stretch;
    }

    .modal.show .modal-content {
        max-height: var(--crm-modal-max-height);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .modal.show .modal-header,
    .modal.show .modal-footer {
        flex-shrink: 0;
    }

    .modal.show .modal-body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        min-height: 0;
        flex: 1 1 auto;
    }

    .modal.show .modal-dialog-scrollable {
        height: auto;
        max-height: var(--crm-modal-max-height);
    }

    .modal.show .modal-dialog-scrollable .modal-content {
        max-height: var(--crm-modal-max-height);
        overflow: hidden;
    }

    .crm-alert-modal-overlay {
        padding: var(--crm-modal-gap-y) max(1rem, env(safe-area-inset-right, 0px)) var(--crm-modal-gap-y-bottom) max(1rem, env(safe-area-inset-left, 0px));
        align-items: center;
        box-sizing: border-box;
    }

    .crm-alert-modal__panel {
        max-height: var(--crm-modal-max-height);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Dropdown шапки: карточка; на узком экране — по центру окна. */
.crm-header-dd-backdrop,
.crm-header-user-backdrop {
    display: none;
}

.crm-header-user-menu {
    min-width: 16.5rem;
    padding: 0.4rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 1.05rem;
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.16);
}

.crm-header-user-menu__head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.15rem 0.15rem 0.35rem;
    padding: 0.7rem 0.7rem 0.8rem;
    border-radius: 0.85rem;
    background: var(--bs-tertiary-bg);
}

.crm-header-user-menu__avatar {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 999px;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px var(--bs-body-bg);
}

.crm-header-user-menu__id {
    min-width: 0;
}

.crm-header-user-menu__name {
    overflow: hidden;
    font-weight: 700;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crm-header-user-menu .dropdown-divider {
    margin: 0.35rem 0.45rem;
}

.crm-header-user-menu .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    margin: 0.12rem 0;
    padding: 0.62rem 0.7rem;
    border-radius: 0.75rem;
    font-weight: 600;
}

.crm-header-user-menu .dropdown-item i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 2rem;
    height: 2rem;
    margin: 0 !important;
    border-radius: 0.6rem;
    background: var(--bs-tertiary-bg);
    font-size: 1.05rem;
}

.crm-header-user-menu .dropdown-item:hover,
.crm-header-user-menu .dropdown-item:focus {
    background: var(--bs-tertiary-bg);
}

.crm-header-user-menu__logout {
    color: var(--bs-danger);
}

.crm-header-user-menu__logout i {
    background: rgba(var(--bs-danger-rgb), 0.12);
    color: var(--bs-danger);
}

@media (max-width: 767.98px) {
    .crm-header-dd-backdrop.is-open,
    .crm-header-user-backdrop.is-open {
        display: flex;
        position: fixed;
        z-index: 2000;
        inset: 0;
        align-items: center;
        justify-content: center;
        padding: max(1.25rem, env(safe-area-inset-top, 0px)) max(1.25rem, env(safe-area-inset-right, 0px)) max(1.25rem, env(safe-area-inset-bottom, 0px)) max(1.25rem, env(safe-area-inset-left, 0px));
        background: rgba(15, 23, 42, 0.48);
        -webkit-backdrop-filter: blur(3px);
        backdrop-filter: blur(3px);
    }

    .crm-header-dd-backdrop .dropdown-menu.is-centered,
    .crm-header-user-backdrop .dropdown-menu.is-centered,
    .dropdown-menu.is-centered {
        position: relative !important;
        inset: auto !important;
        top: auto !important;
        right: auto !important;
        bottom: auto !important;
        left: auto !important;
        float: none !important;
        transform: none !important;
        margin: 0 !important;
        width: min(22rem, calc(100vw - 2.5rem)) !important;
        max-width: calc(100vw - 2.5rem);
        border-radius: 1.2rem;
        box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
    }

    .crm-header-dd-backdrop .dropdown-menu.is-centered:not(.crm-notify-menu),
    .crm-header-user-backdrop .dropdown-menu.is-centered:not(.crm-notify-menu),
    .dropdown-menu.is-centered:not(.crm-notify-menu) {
        display: block !important;
        padding: 0.55rem;
    }

    .crm-header-dd-backdrop .crm-notify-menu.dropdown-menu.is-centered,
    .crm-header-user-backdrop .crm-notify-menu.dropdown-menu.is-centered,
    .crm-notify-menu.dropdown-menu.is-centered {
        display: flex !important;
        flex-direction: column;
        width: min(24rem, calc(100vw - 2.5rem)) !important;
        max-height: min(34rem, calc(100dvh - 2.5rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)));
        padding: 0;
        overflow: hidden;
    }

    .crm-header-user-menu .dropdown-item {
        min-height: 3rem;
        padding: 0.75rem 0.8rem;
    }

    .crm-header-dd-backdrop .dropdown-menu.is-centered .dropdown-item,
    .crm-header-user-backdrop .dropdown-menu.is-centered .dropdown-item {
        min-height: 2.75rem;
        padding-top: 0.7rem;
        padding-bottom: 0.7rem;
    }
}

/* Колокольчик: карточка, текст остаётся внутри и листается. */
.crm-notify-menu.dropdown-menu {
    width: min(24rem, calc(100vw - 1.25rem));
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--bs-border-color);
    border-radius: 1.05rem;
    background-color: var(--bs-dropdown-bg);
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.16);
}

.crm-notify-menu.dropdown-menu.show {
    display: flex;
    flex-direction: column;
    max-height: min(34rem, calc(100dvh - var(--crm-header-visible, 4rem) - 0.75rem));
}

.crm-notify-menu__head,
.crm-notify-menu__foot {
    flex: 0 0 auto;
}

.crm-notify-menu__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 0.9rem 0.8rem;
    border-bottom: 1px solid var(--bs-border-color);
    background: var(--bs-tertiary-bg);
}

.crm-notify-menu__title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}

.crm-notify-menu__mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 2rem;
    height: 2rem;
    border-radius: 0.65rem;
    background: rgba(var(--bs-primary-rgb), 0.14);
    color: var(--bs-primary);
    font-size: 1.2rem;
    line-height: 1;
}

.crm-notify-menu__mark i {
    color: inherit;
    font-size: 1.25rem;
    line-height: 1;
}

.crm-notify-menu__heading {
    margin: 0;
    overflow: hidden;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crm-notify-menu__unread {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    flex: 0 0 auto;
    max-width: 55%;
    padding: 0.18rem 0.28rem 0.18rem 0.6rem;
    border-radius: 999px;
    background: rgba(var(--bs-danger-rgb), 0.12);
    color: var(--bs-danger);
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
}

.crm-notify-menu__unread.is-empty {
    background: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
}

.crm-notify-menu__unread > span:first-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.crm-notify-menu__unread .unread-mess-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.32rem;
    border-radius: 999px;
    background: var(--bs-danger);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1;
}

.crm-notify-menu__unread.is-empty .unread-mess-count {
    background: var(--bs-tertiary-bg);
    color: var(--bs-secondary-color);
}

.crm-notify-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: min(22rem, calc(100dvh - var(--crm-header-visible, 4rem) - 8rem));
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.35rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 116, 139, 0.45) transparent;
}

.crm-notify-list .crm-skeleton-row {
    padding: 0.55rem 0.6rem;
}

.crm-notify-empty {
    padding: 1.6rem 1rem;
    color: var(--bs-secondary-color);
    font-size: 0.875rem;
    text-align: center;
    overflow-wrap: anywhere;
}

.crm-notify-item {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    min-width: 0;
    max-width: 100%;
    margin: 0.12rem 0;
    padding: 0.62rem 0.65rem;
    border-radius: 0.8rem;
    color: inherit;
    text-decoration: none;
}

.crm-notify-item:hover,
.crm-notify-item:focus-visible {
    background: var(--bs-tertiary-bg);
    color: inherit;
}

.crm-notify-item:focus-visible {
    outline: 2px solid rgba(var(--bs-primary-rgb), 0.4);
    outline-offset: -2px;
}

.crm-notify-item__avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 2.5rem;
    height: 2.5rem;
    overflow: hidden;
    border-radius: 0.8rem;
    background: rgba(var(--bs-primary-rgb), 0.12);
    color: var(--bs-primary);
    font-size: 0.95rem;
    font-weight: 700;
}

.crm-notify-item__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.crm-notify-item__avatar .bx {
    font-size: 1.25rem;
    line-height: 1;
}

.crm-notify-item__main {
    flex: 1 1 auto;
    min-width: 0;
}

.crm-notify-item__row {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    min-width: 0;
}

.crm-notify-item__name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    font-size: 0.875rem;
    font-weight: 700;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crm-notify-item__time {
    flex: 0 0 auto;
    color: var(--bs-secondary-color);
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    white-space: nowrap;
}

.crm-notify-item__text {
    display: -webkit-box;
    margin-top: 0.15rem;
    overflow: hidden;
    color: var(--bs-secondary-color);
    font-size: 0.8125rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
    word-break: break-word;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
}

.crm-notify-item--steps .crm-notify-item__text {
    white-space: pre-line;
    -webkit-line-clamp: 8;
}

.crm-notify-item__count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    align-self: center;
    min-width: 1.35rem;
    height: 1.35rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: var(--bs-danger);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1;
}

.crm-notify-menu__foot {
    display: flex;
    flex-direction: row;
    gap: 0.45rem;
    padding: 0.55rem;
    border-top: 1px solid var(--bs-border-color);
}

.crm-notify-menu__act {
    position: relative;
    display: inline-flex;
    flex: 1 1 0;
    align-items: center;
    justify-content: center;
    height: 2.45rem;
    border-radius: 0.75rem;
    background: var(--crm-shell-chrome-bg, #102440);
    color: #fff;
    font-size: 1.25rem;
    line-height: 1;
    text-decoration: none;
}

.crm-notify-menu__act--chat {
    border: 1px solid var(--bs-border-color);
    background: rgba(var(--bs-primary-rgb), 0.1);
    color: var(--bs-primary);
}

[data-bs-theme=dark] .crm-notify-menu__act--chat {
    border-color: rgba(147, 197, 253, 0.35);
    background: rgba(96, 165, 250, 0.16);
    color: #e8ecf4;
}

[data-bs-theme=dark] .crm-notify-item__avatar {
    background: rgba(96, 165, 250, 0.16);
    color: #93c5fd;
}

.crm-notify-menu__act:hover,
.crm-notify-menu__act:focus-visible {
    background: var(--bs-primary);
    color: #fff;
}

.crm-notify-menu__act:focus-visible {
    outline: 2px solid rgba(var(--bs-primary-rgb), 0.45);
    outline-offset: 2px;
}

.crm-notify-menu__pop-src {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.crm-notify-preview {
    position: fixed;
    z-index: 1080;
    width: max-content;
    max-width: min(20rem, calc(100vw - 1.25rem));
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--crm-color-border);
    border-radius: 0.85rem;
    background: var(--crm-color-surface);
    color: var(--crm-color-text);
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.16);
    font-size: 0.8125rem;
    line-height: 1.45;
    pointer-events: auto;
}

.crm-notify-preview[hidden] {
    display: none !important;
}

.crm-notify-preview__name {
    margin-bottom: 0.22rem;
    font-weight: 700;
    line-height: 1.3;
}

.crm-notify-preview__name[hidden] {
    display: none !important;
}

.crm-notify-preview__text {
    max-height: 12rem;
    overflow: auto;
    color: var(--crm-color-text);
    white-space: pre-line;
    overflow-wrap: anywhere;
    scrollbar-width: thin;
}

.crm-notify-preview::before {
    content: "";
    position: absolute;
    width: 0.65rem;
    height: 0.65rem;
    background: var(--crm-color-surface);
    border-top: 1px solid var(--crm-color-border);
    border-right: 1px solid var(--crm-color-border);
    top: calc(var(--crm-notify-arrow, 1.25rem) - 0.32rem);
}

.crm-notify-preview.is-left::before {
    right: -0.36rem;
    transform: rotate(45deg);
}

.crm-notify-preview.is-right::before {
    left: -0.36rem;
    transform: rotate(225deg);
}

.crm-notify-preview.is-above::before {
    top: auto;
    right: auto;
    bottom: -0.36rem;
    left: 1.15rem;
    transform: rotate(135deg);
}

.crm-notify-preview.is-tip.is-above::before {
    left: calc(var(--crm-notify-arrow, 1.25rem) - 0.32rem);
}

[data-bs-theme=dark] .crm-notify-preview {
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.48);
}

@media (max-width: 600px) {
    .navbar-header .crm-notify-menu.dropdown-menu:not(.is-centered) {
        width: auto;
    }
}
