/* Aerodar CRM Shell & Navigation v32 (Magic UI Futuristic Console)
 * Branch: new-design
 */

a {
    text-decoration: none;
    color: var(--bs-link-color);
    transition: color 0.15s ease;
}

/* FontAwesome Pro 6 */
.fa-solid, .fas { font-weight: 900; }
.fa-regular, .far { font-weight: 400; }
.fa-light, .fal { font-weight: 300; }
.fa-brands, .fab { font-weight: 400; }

li { list-style: none; }

/* ==========================================================================
   1. App Shell Architecture (Floating Futuristic Glass Shell)
   ========================================================================== */
.wrapper {
    display: flex;
    align-items: stretch;
    min-height: 100vh;
    width: 100%;
}

.main {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    overflow: visible;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

#sidebar {
    width: 54px;
    min-width: 54px;
    transition: all 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    background-color: var(--crm-surface);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 25;
    flex: 0 0 auto;
    border-right: 1px solid var(--crm-border);
    max-height: 100vh;
}

#sidebar.expand {
    width: 254px;
    min-width: 254px;
}

/* Desktop Floating Console Shell */
@media (min-width: 992px) {
    .wrapper {
        gap: 0.85rem;
        padding: 0.85rem;
        box-sizing: border-box;
        min-height: 100vh;
    }

    #sidebar {
        margin: 0;
        border-radius: var(--crm-radius-xl);
        border: 1px solid var(--crm-border);
        background: var(--crm-surface);
        box-shadow: var(--crm-shadow);
        overflow: hidden;
        max-height: calc(100vh - 1.7rem);
        align-self: flex-start;
        height: calc(100vh - 1.7rem);
    }

    html[data-bs-theme="dark"] #sidebar {
        background: var(--crm-surface);
        border-color: var(--crm-border);
        box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.6);
    }

    .main {
        height: calc(100vh - 1.7rem);
        max-height: calc(100vh - 1.7rem);
        min-height: 0;
        min-width: 0;
        flex: 1 1 auto;
        width: 100%;
        max-width: 100%;
        border-radius: var(--crm-radius-xl);
        border: 1px solid var(--crm-border);
        background: var(--crm-surface);
        box-shadow: var(--crm-shadow);
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    html[data-bs-theme="dark"] .main {
        background: var(--crm-surface);
        border-color: var(--crm-border);
        box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.6);
    }

    /* #53 TO BE: отчёты и длинные списки скроллятся внутри контента */
    #content {
        background: transparent;
        padding: 0.85rem 1.15rem;
        flex: 1 1 auto;
        min-height: 0;
        min-width: 0;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow-x: auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Mobile / tablet: тот же scrollport — пагинация остаётся внизу экрана */
@media (max-width: 991.98px) {
    .wrapper {
        height: 100dvh;
        max-height: 100dvh;
        min-height: 0;
        overflow: hidden;
    }

    #sidebar {
        max-height: 100dvh;
    }

    .main {
        height: 100dvh;
        max-height: 100dvh;
        min-height: 0;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    #top-navigation,
    #bottom-nav {
        flex: 0 0 auto;
    }

    #content {
        background: transparent;
        padding: 0.75rem 1rem;
        flex: 1 1 auto;
        min-height: 0;
        min-width: 0;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow-x: auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ==========================================================================
   2. Sidebar Navigation Items & Accordions
   ========================================================================== */
#sidebar:not(.expand) .sidebar-logo,
#sidebar:not(.expand) > ul > li > a.sidebar-link > .nav-link-label,
#sidebar:not(.expand) > ul > li > a.sidebar-link > .nav-link-copy,
#sidebar:not(.expand) > ul > li > button.sidebar-link > .nav-link-copy,
#sidebar:not(.expand) > ul > li > a.sidebar-link > span:not(.nav-icon-badge):not(.nav-icon-plain),
#sidebar:not(.expand) > ul > li > button.sidebar-link > span:not(.nav-icon-badge):not(.nav-icon-plain) {
    display: none;
}

#sidebar:not(.expand) > ul > li.nav-block > a.sidebar-link > span.nav-icon-badge,
#sidebar:not(.expand) > ul > li.nav-block > button.sidebar-link > span.nav-icon-badge,
#sidebar:not(.expand) > ul > li > a.sidebar-link > .nav-icon-plain {
    display: inline-flex;
}

.sidebar-top {
    flex: 0 0 auto;
    z-index: 12;
}

/* Sidebar Avatar Widget */
.sidebar-avatar-widget {
    min-height: 40px;
}

.sidebar-avatar-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50% !important;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    outline: none !important;
    box-shadow: none !important;
    text-decoration: none !important;
    flex-shrink: 0;
    overflow: visible;
}

.sidebar-avatar-link:focus,
.sidebar-avatar-link:active,
.sidebar-avatar-link:hover {
    background: transparent !important;
    outline: none !important;
    box-shadow: none !important;
}

.sidebar-avatar-link:hover .sidebar-avatar-circle,
.sidebar-avatar-link:hover .sidebar-avatar-img {
    transform: scale(1.05);
    box-shadow: 0 0 12px rgba(2, 132, 199, 0.35);
}

.sidebar-avatar-circle,
.sidebar-avatar-img {
    width: 40px;
    height: 40px;
    border-radius: 50% !important;
    box-sizing: border-box;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.sidebar-avatar-img {
    object-fit: cover;
    border: 2px solid var(--crm-border-strong, #cbd5e1);
}

.sidebar-avatar-circle {
    background: var(--crm-surface-glass, #ffffff);
    backdrop-filter: blur(8px);
    border: 2px solid var(--crm-border-strong, #cbd5e1);
    color: var(--crm-brand, #0284c7);
    font-weight: 700;
    font-size: 0.92rem;
    line-height: 1;
    user-select: none;
    letter-spacing: 0.02em;
}

.sidebar-avatar-circle.border-success,
.sidebar-avatar-img.border-success {
    border-color: #10b981 !important;
}

.sidebar-avatar-circle.border-danger,
.sidebar-avatar-img.border-danger {
    border-color: #ef4444 !important;
}

.sidebar-avatar-link .reminders-counter {
    top: -5px !important;
    right: -5px !important;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 0.68rem !important;
    font-weight: 700 !important;
    line-height: 18px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px !important;
    box-shadow: 0 2px 6px rgba(225, 29, 72, 0.45);
    border: 2px solid var(--crm-surface, #ffffff) !important;
    z-index: 10 !important;
    pointer-events: none;
}

html[data-bs-theme="dark"] .sidebar-avatar-link .reminders-counter {
    border-color: var(--crm-surface, #1e293b) !important;
}

.sidebar-user-name {
    color: var(--crm-ink) !important;
    transition: color 0.2s ease;
    display: block;
    line-height: 1.25;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-user-name:hover {
    color: var(--crm-brand) !important;
}

.sidebar-toolbar {
    padding: 0.35rem 0.5rem 0.65rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.45rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.sidebar-toolbar-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    gap: 0.4rem;
}

.sidebar-nav {
    padding: 0.5rem 0;
    flex: 1 1 auto;
    min-height: 0;
    z-index: 10;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

a.sidebar-link,
button.sidebar-link {
    padding: 0.55rem 0.85rem;
    color: var(--crm-ink);
    border-radius: var(--crm-radius-sm);
    display: flex;
    align-items: center;
    gap: 0.65rem;
    white-space: nowrap;
    font-weight: 500;
    font-size: 0.88rem;
    position: relative;
    min-height: 2.65rem;
    text-decoration: none;
    transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    -webkit-tap-highlight-color: transparent;
    border: 0;
    background: transparent;
    width: calc(100% - 0.7rem);
    margin: 0.12rem 0.35rem;
    text-align: left;
    cursor: pointer;
}

.nav-icon-plain {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.45rem;
    flex-shrink: 0;
    font-size: 0.95rem;
    color: var(--crm-ink-muted);
    transition: color 0.18s ease, transform 0.18s ease;
}

.sidebar-link:hover .nav-icon-plain {
    color: var(--crm-brand);
    transform: scale(1.1);
}

.nav-link-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    flex: 1 1 auto;
}

.nav-link-label-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Counts next to flat menu labels — only when sidebar is expanded */
.nav-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.01em;
    line-height: 1;
    flex-shrink: 0;
    color: #fff;
}

.nav-count-badge--todo {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.25);
}

.nav-count-badge--mention {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.35);
    animation: nav-count-pulse 1.8s ease-in-out infinite;
}

.nav-count-badge--control {
    background: linear-gradient(135deg, #34d399, #059669);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.35);
    animation: nav-control-pulse 1.8s ease-in-out infinite;
}

@keyframes nav-count-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
    50% { box-shadow: 0 0 0 4px rgba(239, 68, 68, 0); }
}

@keyframes nav-control-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.45); }
    50% { box-shadow: 0 0 0 4px rgba(16, 185, 129, 0); }
}

#sidebar:not(.expand) .nav-count-badge {
    display: none !important;
}

@media (prefers-reduced-motion: reduce) {
    .nav-count-badge--mention,
    .nav-count-badge--control {
        animation: none;
    }
}

.sidebar-item:not(.active) > a.sidebar-link:hover,
.sidebar-item:not(.active) > button.sidebar-link:hover {
    background: rgba(2, 132, 199, 0.08);
    color: var(--crm-brand);
}

.sidebar-item.active > a.sidebar-link,
.sidebar-item.active > button.sidebar-link {
    background: linear-gradient(135deg, rgba(2, 132, 199, 0.14) 0%, rgba(37, 99, 235, 0.08) 100%);
    color: var(--crm-brand) !important;
    font-weight: 650;
    box-shadow: inset 2px 0 0 0 var(--crm-brand);
}

html[data-bs-theme="dark"] .sidebar-item.active > a.sidebar-link,
html[data-bs-theme="dark"] .sidebar-item.active > button.sidebar-link {
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.18) 0%, rgba(56, 189, 248, 0.06) 100%);
    color: var(--crm-brand) !important;
    box-shadow: inset 2px 0 0 0 var(--crm-brand), 0 0 16px rgba(56, 189, 248, 0.15);
}

/* Accordion Nav Block */
.sidebar-item.nav-block > a.sidebar-link,
.sidebar-item.nav-block > button.sidebar-link {
    padding: 0.5rem 1.6rem 0.5rem 0.65rem;
    border-radius: var(--crm-radius);
    min-height: 2.75rem;
}

.sidebar-item.nav-block .nav-icon-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.85rem;
    height: 1.85rem;
    border-radius: var(--crm-radius-xs);
    color: #ffffff;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease;
}

.sidebar-link:hover .nav-icon-badge {
    transform: scale(1.08);
}

.sidebar-item.nav-block .nav-link-copy {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1 1 auto;
    line-height: 1.15;
}

.sidebar-item.nav-block .nav-link-title {
    font-size: 0.86rem;
    font-weight: 600;
}

.sidebar-item.nav-block .nav-link-meta {
    font-size: 0.65rem;
    color: var(--crm-ink-muted);
}

/* Modern Gradient Accents for Nav Tones */
.sidebar-item.nav-tone-neutral .nav-icon-badge { background: linear-gradient(135deg, #64748b, #334155); }
.sidebar-item.nav-tone-tarif .nav-icon-badge { background: linear-gradient(135deg, #f59e0b, #d97706); }
.sidebar-item.nav-tone-company .nav-icon-badge { background: linear-gradient(135deg, #10b981, #0f766e); }
.sidebar-item.nav-tone-system .nav-icon-badge { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }

/* Collapsed Sidebar Hover Dropdown */
#sidebar:not(.expand) .sidebar-item .sidebar-dropdown {
    position: absolute;
    top: 0;
    left: 54px;
    background: var(--crm-surface) !important;
    border: 1px solid var(--crm-border-strong);
    padding: 0.4rem;
    min-width: 15rem;
    width: 15rem;
    display: none;
    border-radius: var(--crm-radius);
    box-shadow: var(--crm-shadow-lg);
    z-index: 50;
    backdrop-filter: blur(16px);
}

#sidebar:not(.expand) .sidebar-item:hover > .has-dropdown + .sidebar-dropdown {
    display: block !important;
    max-height: min(75vh, 26rem);
    overflow-y: auto;
}

#sidebar.expand .sidebar-dropdown.collapse.show {
    display: block !important;
    position: static;
    max-height: none;
    width: auto;
    box-shadow: none;
    background: transparent !important;
}

/* Submenu Links */
a.sidebar-sublink {
    margin: 0.08rem 0.4rem 0.08rem 0.85rem;
    border-radius: var(--crm-radius-xs);
    min-height: 2.25rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.84rem;
    color: var(--crm-ink-muted);
}

a.sidebar-sublink:hover {
    color: var(--crm-brand) !important;
    background: rgba(2, 132, 199, 0.08);
}

.sidebar-item.active > a.sidebar-sublink {
    background: rgba(2, 132, 199, 0.12) !important;
    color: var(--crm-brand) !important;
    font-weight: 600;
}

/* ==========================================================================
   Sidebar Toolbar & Control Buttons (pinned under avatar)
   ========================================================================== */
.sidebar-ctrl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border: 1px solid var(--crm-border-strong);
    background: var(--crm-surface-glass);
    backdrop-filter: blur(8px);
    color: var(--crm-ink-muted);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-ctrl-btn:hover {
    border-color: var(--crm-brand);
    color: var(--crm-brand);
    background: rgba(2, 132, 199, 0.1);
    box-shadow: 0 0 14px rgba(2, 132, 199, 0.25);
    transform: translateY(-1px);
}

.sidebar-ctrl-btn:active {
    transform: translateY(0);
}

/* Expanded state on desktop: pill buttons with labels */
#sidebar.expand .sidebar-toolbar-controls {
    flex-direction: row;
    padding: 0 0.25rem;
}

#sidebar.expand .sidebar-ctrl-btn {
    flex: 1;
    height: 34px;
    padding: 0 0.65rem;
    border-radius: var(--crm-radius-pill);
}

#sidebar.expand .sidebar-ctrl-btn .ctrl-label {
    display: inline-block;
    white-space: nowrap;
}

/* Collapsed state (54px wide): compact icon buttons */
#sidebar:not(.expand) .sidebar-toolbar {
    padding: 0.35rem 0.25rem 0.55rem;
}

#sidebar:not(.expand) .sidebar-toolbar-controls {
    flex-direction: column;
    gap: 0.45rem;
}

#sidebar:not(.expand) .sidebar-ctrl-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 10px;
    flex: 0 0 36px;
}

#sidebar:not(.expand) .sidebar-ctrl-btn .ctrl-label {
    display: none;
}

/* Rotate expand menu icon */
#expandMenu .fa,
#expandMenu .fa-chevron-right {
    transition: transform 0.25s ease;
    font-size: 0.8rem;
}

#expandMenu.expanded .fa,
#expandMenu.expanded .fa-chevron-right {
    transform: rotate(180deg);
}

/* CRM Version Chip */
.crm-version-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.crm-version-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid rgba(148, 163, 184, 0.16);
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--crm-ink-subtle);
    line-height: 1.4;
    transition: all 0.2s ease;
}

.crm-version-chip:hover {
    background: rgba(148, 163, 184, 0.14);
    border-color: rgba(148, 163, 184, 0.28);
    color: var(--crm-ink);
}

.crm-version-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
    flex-shrink: 0;
    display: inline-block;
}

#sidebar:not(.expand) .crm-version-chip {
    width: 8px;
    height: 8px;
    max-width: 8px;
    padding: 0;
    gap: 0;
    font-size: 0;
    line-height: 0;
    overflow: hidden;
    border: 0;
    background: transparent;
}

#sidebar:not(.expand) .crm-version-chip .crm-version-dot {
    display: block;
}

/* Collapsed rail: everything centered, no clipped labels */
#sidebar:not(.expand) .sidebar-top-avatar {
    display: flex;
    justify-content: center;
    align-items: center;
    padding-left: 0 !important;
    padding-right: 0 !important;
    padding-top: 0.75rem !important;
    padding-bottom: 0.25rem !important;
    width: 100% !important;
    box-sizing: border-box;
}

#sidebar:not(.expand) .sidebar-avatar-widget {
    width: 100% !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    margin: 0 auto !important;
    padding: 0 !important;
    min-height: 36px;
}

#sidebar:not(.expand) .sidebar-avatar-widget > .flex-grow-0,
#sidebar:not(.expand) .sidebar-avatar-holder {
    width: 100% !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    margin: 0 auto !important;
    padding: 0 !important;
}

#sidebar:not(.expand) .sidebar-top-avatar .avatar-name {
    display: none !important;
}

#sidebar:not(.expand) .sidebar-avatar-link {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    max-width: 36px !important;
    margin: 0 auto !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: visible !important;
    position: relative !important;
}

#sidebar:not(.expand) .sidebar-avatar-circle,
#sidebar:not(.expand) .sidebar-avatar-img,
#sidebar:not(.expand) .sidebar-top-avatar .avatar {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    max-width: 36px !important;
    font-size: 0.82rem;
    margin: 0 auto !important;
    padding: 0;
    overflow: hidden;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    box-sizing: border-box;
}

#sidebar:not(.expand) .sidebar-avatar-link .reminders-counter {
    top: -4px !important;
    right: -4px !important;
}

#sidebar:not(.expand) .sidebar-toolbar,
#sidebar:not(.expand) .sidebar-toolbar-controls,
#sidebar:not(.expand) .crm-version-wrapper {
    width: 100%;
    align-items: center;
    justify-content: center;
}

#sidebar:not(.expand) .sidebar-nav {
    padding-left: 0;
    padding-right: 0;
    scrollbar-width: none;
}

#sidebar:not(.expand) .sidebar-nav::-webkit-scrollbar {
    width: 0;
    height: 0;
}

#sidebar:not(.expand) .sidebar-item {
    display: flex;
    justify-content: center;
    width: 100%;
}

#sidebar:not(.expand) .sidebar-section-label {
    display: block;
    height: 0;
    margin: 0.4rem 16px;
    padding: 0;
    overflow: hidden;
    border-top: 1px solid var(--crm-border);
}

#sidebar:not(.expand) .sidebar-section-label span {
    display: none;
}

#sidebar:not(.expand) a.sidebar-link,
#sidebar:not(.expand) button.sidebar-link,
#sidebar:not(.expand) .sidebar-item.nav-block > a.sidebar-link,
#sidebar:not(.expand) .sidebar-item.nav-block > button.sidebar-link {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    height: 40px;
    min-height: 40px;
    margin: 0.16rem auto;
    padding: 0;
    justify-content: center;
    gap: 0;
    box-shadow: none;
}

#sidebar:not(.expand) .sidebar-item.active > a.sidebar-link,
#sidebar:not(.expand) .sidebar-item.active > button.sidebar-link {
    box-shadow: none;
}

#sidebar:not(.expand) .nav-icon-plain {
    width: 1.2rem;
    margin: 0;
}

#sidebar:not(.expand) .nav-icon-badge {
    width: 32px;
    height: 32px;
    margin: 0;
    border-radius: 10px;
}

/* Section Labels */
.sidebar-section-label {
    pointer-events: none;
    padding: 0.85rem 1rem 0.35rem;
}

.sidebar-section-label span {
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--crm-ink-subtle);
}

/* ==========================================================================
   3. Top Navigation (Floating Header Bar)
   ========================================================================== */
#top-navigation {
    position: relative;
    z-index: 40;
    flex: 0 0 auto;
    background: var(--crm-surface) !important;
    border-bottom: 1px solid var(--crm-border);
    padding: 0.85rem 1.15rem;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

@media (min-width: 992px) {
    #top-navigation {
        border-top-left-radius: var(--crm-radius-xl);
        border-top-right-radius: var(--crm-radius-xl);
    }
}

#top-navigation .form-control {
    border-radius: var(--crm-radius-pill) !important;
    padding-left: 1rem;
    background: var(--crm-surface-soft) !important;
}

#top-navigation .btn-group > .btn:not(.crm-date-pill):not(.rounded-pill):not(.crm-preset-btn):not(.crm-chart-btn) {
    border-radius: var(--crm-radius-sm);
}

#top-navigation .filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    max-width: 100%;
    min-width: 0;
}

@media (max-width: 767.98px) {
    #top-navigation {
        padding: 0.5rem 0.65rem;
    }
    #top-navigation .filters {
        gap: 0.35rem;
    }
}

/* Bottom Navigation Bar — компактная панель итогов */
#bottom-nav {
    position: sticky;
    bottom: 0;
    z-index: 45;
    flex: 0 0 auto;
    background: color-mix(in srgb, var(--crm-surface) 94%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--crm-border);
    padding: 0.4rem 0.65rem;
    box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.07);
}

.crm-bottom-totals {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 0.75rem;
    width: 100%;
    min-width: 0;
}

.crm-bottom-totals__pager {
    flex: 0 1 auto;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.crm-bottom-totals__pager::-webkit-scrollbar { display: none; }
.crm-bottom-totals__pager .pagination {
    margin: 0;
    flex-wrap: nowrap;
}
.crm-bottom-totals__pager .page-link {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    line-height: 1.2;
}

.crm-bottom-totals__stats {
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0.35rem;
    margin-left: auto;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 1px;
}
.crm-bottom-totals__stats::-webkit-scrollbar { display: none; }

.crm-stat {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.05rem;
    flex: 0 0 auto;
    min-width: 4.4rem;
    padding: 0.28rem 0.55rem;
    border-radius: 0.55rem;
    border: 1px solid var(--crm-border);
    background: var(--crm-surface, var(--bs-body-bg));
    line-height: 1.15;
}
.crm-stat__k {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--crm-muted, #94a3b8);
    white-space: nowrap;
}
.crm-stat__v {
    font-size: 0.84rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    color: var(--crm-ink, var(--bs-body-color));
}
.crm-stat__sub {
    margin-left: 0.25rem;
    font-size: 0.68rem;
    font-weight: 600;
    opacity: 0.7;
}
.crm-stat--ok {
    border-color: color-mix(in srgb, #34d399 40%, transparent);
    background: color-mix(in srgb, #34d399 12%, var(--crm-surface, var(--bs-body-bg)));
}
.crm-stat--ok .crm-stat__v { color: #34d399; }
.crm-stat--warn {
    border-color: color-mix(in srgb, #f59e0b 42%, transparent);
    background: color-mix(in srgb, #f59e0b 12%, var(--crm-surface, var(--bs-body-bg)));
}
.crm-stat--warn .crm-stat__v { color: #fbbf24; }
.crm-stat--paid {
    border-color: color-mix(in srgb, #38bdf8 42%, transparent);
    background: color-mix(in srgb, #38bdf8 12%, var(--crm-surface, var(--bs-body-bg)));
}
.crm-stat--paid .crm-stat__v { color: #7dd3fc; }
.crm-stat--muted .crm-stat__v {
    font-weight: 600;
    opacity: 0.9;
}

@media (min-width: 992px) {
    #bottom-nav {
        border-bottom-left-radius: var(--crm-radius-xl);
        border-bottom-right-radius: var(--crm-radius-xl);
    }
}

@media (max-width: 991.98px) {
    .crm-bottom-totals {
        flex-direction: column;
        align-items: stretch;
        gap: 0.4rem;
    }
    .crm-bottom-totals__stats {
        margin-left: 0;
        width: 100%;
    }
    .crm-stat--desktop { display: none !important; }
}

@media (max-width: 575.98px) {
    #bottom-nav {
        padding: 0.35rem 0.5rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
    }
    .crm-stat {
        min-width: 4.1rem;
        padding: 0.22rem 0.45rem;
    }
    .crm-stat__k { font-size: 0.58rem; }
    .crm-stat__v { font-size: 0.78rem; }
    .crm-bottom-totals__pager .page-link {
        padding: 0.2rem 0.42rem;
        font-size: 0.75rem;
    }
}

/* Page Section Titles */
.page-section-title {
    display: inline-flex;
    align-items: center;
    gap: 0.85rem;
    margin: 0.1rem 0.85rem 0.1rem 0;
    padding: 0.15rem 0;
    vertical-align: middle;
    max-width: 100%;
}
.page-section-title__text {
    min-width: 0;
}
.page-section-title__eyebrow {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--crm-ink-subtle);
    line-height: 1.2;
}
.page-section-title__heading {
    font-size: 1.25rem;
    font-weight: 750;
    letter-spacing: -0.025em;
    line-height: 1.2;
    color: var(--crm-ink);
}
.page-section-title--tarif .page-section-title__eyebrow { color: var(--crm-amber); }
.page-section-title--company .page-section-title__eyebrow { color: var(--crm-emerald); }
.page-section-title--system .page-section-title__eyebrow { color: var(--crm-violet); }
.page-section-title--catalog .page-section-title__eyebrow,
.page-section-title--default .page-section-title__eyebrow { color: var(--crm-brand); }

/* ==========================================================================
   CRM Version Update Modal — MagicUI port (gentle-sand-7960)
   ========================================================================== */
body.crm-vu-open {
    overflow: hidden;
}

.crm-vu-root {
    position: fixed;
    inset: 0;
    z-index: 20050;
    display: grid;
    place-items: center;
    padding: 1.25rem;
    font-family: var(--bs-body-font-family), "Plus Jakarta Sans", ui-sans-serif, system-ui, sans-serif;
}

.crm-vu-root[hidden] {
    display: none !important;
}

.crm-vu-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(6, 9, 19, 0.55);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    animation: crm-vu-fade 0.35s ease;
}

.crm-vu-card {
    position: relative;
    width: min(100%, 380px);
    border-radius: 24px;
    padding: 1.75rem 1.5rem 1.35rem;
    background: linear-gradient(165deg, #ffffff 0%, #f0f9ff 55%, #e0f2fe 100%);
    border: 1px solid rgba(14, 165, 233, 0.22);
    box-shadow:
        0 25px 50px -12px rgba(2, 132, 199, 0.28),
        0 10px 24px -8px rgba(15, 23, 42, 0.18);
    overflow: hidden;
    text-align: center;
    animation: crm-vu-pop 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

html[data-bs-theme="dark"] .crm-vu-card {
    background: linear-gradient(165deg, #0f172a 0%, #0c1a2e 55%, #082f49 100%);
    border-color: rgba(56, 189, 248, 0.28);
    box-shadow:
        0 25px 50px -12px rgba(2, 132, 199, 0.35),
        0 10px 24px -8px rgba(0, 0, 0, 0.45);
}

.crm-vu-beam {
    position: absolute;
    inset: -40%;
    background: conic-gradient(from 0deg, transparent 0 70%, rgba(14, 165, 233, 0.55), rgba(99, 102, 241, 0.45), transparent 100%);
    animation: crm-vu-spin 6s linear infinite;
    opacity: 0.55;
    pointer-events: none;
}

.crm-vu-card::after {
    content: "";
    position: absolute;
    inset: 1.5px;
    border-radius: 22.5px;
    background: linear-gradient(165deg, #ffffff 0%, #f0f9ff 55%, #e0f2fe 100%);
    z-index: 0;
}

html[data-bs-theme="dark"] .crm-vu-card::after {
    background: linear-gradient(165deg, #0f172a 0%, #0c1a2e 55%, #082f49 100%);
}

.crm-vu-glow {
    position: absolute;
    top: -40%;
    left: 20%;
    width: 60%;
    height: 50%;
    background: radial-gradient(circle, rgba(56, 189, 248, 0.35), transparent 70%);
    filter: blur(20px);
    z-index: 1;
    pointer-events: none;
}

.crm-vu-card > *:not(.crm-vu-beam):not(.crm-vu-glow) {
    position: relative;
    z-index: 2;
}

.crm-vu-icon-wrap {
    position: relative;
    width: 72px;
    height: 72px;
    margin: 0.15rem auto 1rem;
    display: grid;
    place-items: center;
    border-radius: 22px;
    background: linear-gradient(145deg, #0ea5e9, #0284c7);
    color: #fff;
    box-shadow: 0 12px 28px -8px rgba(14, 165, 233, 0.65);
}

.crm-vu-icon-ring {
    position: absolute;
    inset: -6px;
    border-radius: 26px;
    border: 1.5px solid rgba(14, 165, 233, 0.35);
    animation: crm-vu-pulse 2.2s ease-in-out infinite;
}

.crm-vu-icon {
    width: 34px;
    height: 34px;
}

.crm-vu-eyebrow {
    margin: 0 0 0.35rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #0284c7;
}

html[data-bs-theme="dark"] .crm-vu-eyebrow {
    color: #38bdf8;
}

.crm-vu-title {
    margin: 0 0 0.55rem;
    font-size: 1.45rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: #0f172a;
    line-height: 1.2;
}

html[data-bs-theme="dark"] .crm-vu-title {
    color: #f8fafc;
}

.crm-vu-text {
    margin: 0 0 1.15rem;
    font-size: 0.92rem;
    line-height: 1.45;
    color: #475569;
}

html[data-bs-theme="dark"] .crm-vu-text {
    color: #94a3b8;
}

.crm-vu-versions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    margin-bottom: 1.25rem;
}

.crm-vu-ver {
    min-width: 96px;
    padding: 0.55rem 0.7rem;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.35);
}

html[data-bs-theme="dark"] .crm-vu-ver {
    background: rgba(15, 23, 42, 0.7);
    border-color: rgba(148, 163, 184, 0.25);
}

.crm-vu-ver-new {
    border-color: rgba(14, 165, 233, 0.45);
    background: rgba(224, 242, 254, 0.9);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.12);
}

html[data-bs-theme="dark"] .crm-vu-ver-new {
    background: rgba(14, 165, 233, 0.15);
}

.crm-vu-ver-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
    margin-bottom: 0.15rem;
}

.crm-vu-ver-value {
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 0.95rem;
    font-weight: 700;
    color: #0f172a;
}

html[data-bs-theme="dark"] .crm-vu-ver-value {
    color: #e2e8f0;
}

.crm-vu-ver-new .crm-vu-ver-value {
    color: #0369a1;
}

html[data-bs-theme="dark"] .crm-vu-ver-new .crm-vu-ver-value {
    color: #7dd3fc;
}

.crm-vu-arrow {
    color: #94a3b8;
    font-weight: 700;
}

.crm-vu-btn-primary {
    position: relative;
    width: 100%;
    border: 0;
    border-radius: 999px;
    padding: 0.85rem 1.25rem;
    background: linear-gradient(135deg, #0284c7, #0ea5e9 45%, #38bdf8);
    color: #fff;
    font-weight: 700;
    font-size: 0.98rem;
    cursor: pointer;
    overflow: hidden;
    box-shadow: 0 12px 24px -10px rgba(2, 132, 199, 0.75);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.crm-vu-btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 16px 28px -10px rgba(2, 132, 199, 0.85);
}

.crm-vu-btn-primary:disabled {
    opacity: 0.85;
    cursor: wait;
}

.crm-vu-btn-primary:focus-visible {
    outline: 3px solid rgba(14, 165, 233, 0.45);
    outline-offset: 2px;
}

.crm-vu-btn-shine {
    position: absolute;
    inset: 0;
    background: linear-gradient(110deg, transparent 20%, rgba(255, 255, 255, 0.45) 45%, transparent 70%);
    background-size: 200% 100%;
    animation: crm-vu-shimmer 2.4s linear infinite;
    pointer-events: none;
}

.crm-vu-btn-label {
    position: relative;
    z-index: 1;
}

.crm-vu-btn-ghost {
    margin-top: 0.65rem;
    width: 100%;
    border: 0;
    background: transparent;
    color: #64748b;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.45rem;
    border-radius: 10px;
}

.crm-vu-btn-ghost:hover {
    color: #0f172a;
    background: rgba(148, 163, 184, 0.12);
}

html[data-bs-theme="dark"] .crm-vu-btn-ghost:hover {
    color: #f1f5f9;
    background: rgba(148, 163, 184, 0.14);
}

.crm-vu-btn-ghost:focus-visible {
    outline: 2px solid rgba(100, 116, 139, 0.45);
    outline-offset: 2px;
}

@keyframes crm-vu-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes crm-vu-pop {
    from { opacity: 0; transform: translateY(14px) scale(0.96); }
    to { opacity: 1; transform: none; }
}

@keyframes crm-vu-spin {
    to { transform: rotate(360deg); }
}

@keyframes crm-vu-pulse {
    0%, 100% { opacity: 0.45; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.05); }
}

@keyframes crm-vu-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .crm-vu-beam,
    .crm-vu-icon-ring,
    .crm-vu-btn-shine,
    .crm-vu-card,
    .crm-vu-backdrop {
        animation: none !important;
    }
}

/* Account panel (avatar → notifications / settings) */
.crm-account-panel {
    --crm-account-pad: 1rem 1.1rem;
    width: min(420px, 100vw) !important;
    background: var(--crm-surface, #fff);
    border-left: 1px solid var(--crm-border, rgba(15, 23, 42, 0.08));
}

.crm-account-panel__head {
    padding: var(--crm-account-pad);
    border-bottom: 1px solid var(--crm-border, rgba(15, 23, 42, 0.08));
    background: linear-gradient(180deg, rgba(var(--crm-brand-rgb, 2, 132, 199), 0.08), transparent 90%);
}

.crm-account-panel__identity {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.9rem;
}

.crm-account-panel__avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--crm-surface-soft, #f8fafc);
    border: 2px solid rgba(var(--crm-brand-rgb, 2, 132, 199), 0.35);
    color: var(--crm-brand, #0284c7);
    font-weight: 700;
    font-size: 0.95rem;
    overflow: hidden;
}

.crm-account-panel__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.crm-account-panel__name {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--crm-ink, #0f172a);
    line-height: 1.25;
}

.crm-account-panel__email {
    font-size: 0.82rem;
    color: var(--crm-ink-muted, #64748b);
}

.crm-account-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    background: var(--crm-surface-soft, #f1f5f9);
    padding: 0.3rem;
    border-radius: 999px;
}

.crm-account-tabs .nav-item {
    min-width: 0;
}

.crm-account-tabs .nav-link {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border-radius: 999px;
    border: 0;
    color: var(--crm-ink-muted, #64748b);
    font-weight: 600;
    font-size: 0.86rem;
    padding: 0.55rem 0.65rem;
    white-space: nowrap;
}

.crm-account-tabs .nav-link .badge {
    min-width: 1.25rem;
    background: var(--crm-rose, #f43f5e);
    font-size: 0.7rem;
}

.crm-account-tabs .nav-link.active {
    background: var(--crm-surface, #fff);
    color: var(--crm-ink, #0f172a);
    box-shadow: var(--crm-shadow-sm, 0 2px 6px rgba(15, 23, 42, 0.08));
}

.crm-account-panel__body {
    padding: 1rem 1.1rem 1.25rem;
}

.crm-account-section-label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--crm-ink-subtle, #94a3b8);
    margin: 0.35rem 0 0.75rem;
}

.crm-account-link-all {
    display: inline-flex;
    align-items: center;
    margin-top: 0.85rem;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    color: var(--crm-brand, #0284c7);
}

.crm-account-link-all:hover {
    text-decoration: underline;
}

.crm-account-actions {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.crm-account-action {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 0.95rem;
    border-radius: 1rem;
    border: 1px solid var(--crm-border, rgba(15, 23, 42, 0.08));
    background: var(--crm-surface, #fff);
    text-decoration: none !important;
    color: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.crm-account-action:hover {
    border-color: rgba(var(--crm-brand-rgb, 2, 132, 199), 0.35);
    box-shadow: var(--crm-shadow-sm, 0 2px 8px rgba(15, 23, 42, 0.06));
    transform: translateY(-1px);
}

.crm-account-action--primary {
    border-color: rgba(var(--crm-brand-rgb, 2, 132, 199), 0.28);
    background: linear-gradient(135deg, rgba(var(--crm-brand-rgb, 2, 132, 199), 0.1), rgba(var(--crm-brand-rgb, 2, 132, 199), 0.02));
}

.crm-account-action--danger:hover {
    border-color: rgba(244, 63, 94, 0.35);
}

.crm-account-action__ico {
    width: 2.35rem;
    height: 2.35rem;
    border-radius: 0.8rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--crm-surface-soft, #f1f5f9);
    color: var(--crm-brand, #0284c7);
    flex-shrink: 0;
}

.crm-account-action__ico--tg {
    color: #2aabee;
}

.crm-account-action--danger .crm-account-action__ico {
    color: #e11d48;
}

.crm-account-action__text {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
    flex: 1;
}

.crm-account-action__text strong {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--crm-ink, #0f172a);
}

.crm-account-action__text small {
    font-size: 0.78rem;
    color: var(--crm-ink-muted, #64748b);
    line-height: 1.3;
}

.crm-account-action__chev {
    color: var(--crm-ink-subtle, #94a3b8);
    font-size: 0.75rem;
}

html[data-bs-theme="dark"] .crm-account-panel__head {
    background: linear-gradient(180deg, rgba(56, 189, 248, 0.12), transparent 90%);
}

html[data-bs-theme="dark"] .crm-account-tabs {
    background: rgba(15, 23, 42, 0.65);
}

html[data-bs-theme="dark"] .crm-account-tabs .nav-link.active {
    background: #1e293b;
    color: #f8fafc;
}

html[data-bs-theme="dark"] .crm-account-action {
    background: #162032;
    border-color: rgba(148, 163, 184, 0.16);
}