/* =============================================================
   sidebar.css — Shared sidebar styles for all Statix pages
   Extracted from per-page <style> blocks (crm.html reference).
   ============================================================= */

/* ----------------------------------------------------------
   SIDEBAR CONTAINER: injection target for sidebar.js.
   position:fixed takes it out of flow so it doesn't push
   .main-content down. Children (.sidebar, .sidebar-overlay)
   are also position:fixed and handle their own sizing.
   ---------------------------------------------------------- */
#sidebar-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    overflow: visible;
}

/* ----------------------------------------------------------
   MOBILE MENU BUTTON (hamburger in top-bar)
   Hidden on desktop, shown on mobile.
   ---------------------------------------------------------- */
.mobile-menu-btn {
    display: none;
    font-size: 20px;
    cursor: pointer;
    margin-left: 10px;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-main);
    border-radius: 12px;
    transition: 0.2s;
}

.mobile-menu-btn:hover {
    background: var(--bg-input);
}

html.sidebar-collapsed .main-content {
    width: calc(100% - 80px) !important;
    margin-left: 80px;
}

@media (max-width: 768px) {
    #sidebar-container {
        width: 0;
        min-height: 0;
    }
}

/* ----------------------------------------------------------
   SIDEBAR GEOMETRY
   ---------------------------------------------------------- */
.sidebar {
    width: 280px !important;
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    transition: width 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 300;
    display: flex;
    flex-direction: column;
    padding: 16px 15px;
}

html.sidebar-collapsed .sidebar {
    width: 80px !important;
    padding: 20px 5px;
}

html.sidebar-collapsed .brand span,
html.sidebar-collapsed .menu-item span,
html.sidebar-collapsed .user-info {
    display: none !important;
}

html.sidebar-collapsed .brand {
    justify-content: center;
    padding: 0;
}

html.sidebar-collapsed .menu-item {
    justify-content: center;
    padding: 12px 0;
}

html.sidebar-collapsed .menu-item i {
    margin: 0;
    font-size: 24px;
}

/* ----------------------------------------------------------
   BRAND / LOGO
   ---------------------------------------------------------- */
.brand {
    font-size: 20px;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding-left: 10px;
    color: var(--text-main);
}

.brand i {
    color: var(--accent);
    font-size: 24px;
}

.brand-icon {
    height: 60px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
    border-radius: 8px;
    display: none;
}

.brand-text {
    height: 64px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
}

/* Show icon, hide text when collapsed.
   Both html. and body. selectors included as safety net during
   the Plan 02 migration transition.
   TODO: Remove body.sidebar-collapsed selectors after common.js
         is the sole toggle implementation (post Plan 02). */
html.sidebar-collapsed .brand-icon,
body.sidebar-collapsed .brand-icon {
    display: block;
    margin: 0 auto;
}

html.sidebar-collapsed .brand-text,
body.sidebar-collapsed .brand-text {
    display: none !important;
}

/* ----------------------------------------------------------
   NAVIGATION MENU
   ---------------------------------------------------------- */
.menu {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex-grow: 1;
    overflow-y: auto;
    min-height: 0;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 16px), transparent 100%);
    mask-image: linear-gradient(to bottom, #000 calc(100% - 16px), transparent 100%);
}

.menu::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    border-radius: 14px;
    text-decoration: none;
    color: var(--text-sec);
    font-weight: 500;
    font-size: 15px;
    transition: 0.2s;
    border: 1px solid transparent;
}

.menu-item i {
    font-size: 20px;
    flex-shrink: 0;
}

.menu-item:hover {
    background: var(--bg-input);
    color: var(--text-main);
}

.menu-item.active {
    background: var(--primary-light);
    color: var(--text-main);
    border-color: var(--accent);
    font-weight: 600;
}

.menu-item.active i {
    color: var(--accent);
}

/* ----------------------------------------------------------
   NAVIGATION GROUPS
   ---------------------------------------------------------- */
.nav-group {
    margin-bottom: 4px;
}

.nav-group:last-child {
    margin-bottom: 0;
}

.nav-group-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 15px 3px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-sec);
    opacity: 0.6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    user-select: none;
    transition: opacity 0.2s;
}

.nav-group-label:hover {
    opacity: 0.9;
}

.nav-group-label i {
    font-size: 14px;
}

.nav-group-chevron {
    font-size: 10px !important;
    margin-left: auto;
    transition: transform 0.25s ease;
}

.nav-group.collapsed .nav-group-chevron {
    transform: rotate(-90deg);
}

/* Collapsible group items */
.nav-group-items {
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow: hidden;
    max-height: 500px;
    transition: max-height 0.3s ease, opacity 0.25s ease;
    opacity: 1;
}

.nav-group.collapsed .nav-group-items {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
}

.badge-new {
    font-size: 10px;
    font-weight: 600;
    background: #22c55e;
    color: #fff;
    padding: 1px 6px;
    border-radius: 6px;
    margin-left: 6px;
    vertical-align: middle;
}

.badge-soon {
    font-size: 10px;
    font-weight: 600;
    background: var(--accent);
    color: #fff;
    padding: 1px 6px;
    border-radius: 6px;
    margin-left: 6px;
    vertical-align: middle;
}

.stub-link {
    opacity: 0.7;
}

.stub-link:hover {
    opacity: 1;
}

/* Collapsed sidebar: group labels show icon only */
html.sidebar-collapsed .nav-group-label span,
html.sidebar-collapsed .nav-group-chevron {
    display: none !important;
}

html.sidebar-collapsed .nav-group-label {
    justify-content: center;
    padding: 6px 0 2px;
    font-size: 16px;
    opacity: 0.35;
}

html.sidebar-collapsed .nav-group-label i {
    font-size: 16px;
}

html.sidebar-collapsed .nav-group {
    margin-bottom: 4px;
    padding-top: 4px;
    border-top: 1px solid var(--border, rgba(255,255,255,0.06));
}

html.sidebar-collapsed .nav-group:first-child {
    border-top: none;
    padding-top: 0;
}

/* Collapsed sidebar + collapsed group */
html.sidebar-collapsed .nav-group.collapsed .nav-group-label {
    opacity: 0.2;
}

html.sidebar-collapsed .nav-group.collapsed .nav-group-items {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
}

/* ----------------------------------------------------------
   SIDEBAR TOGGLE BUTTON
   ---------------------------------------------------------- */
.sidebar-toggle-btn {
    position: absolute;
    right: -18px;
    top: 32px;
    width: 36px;
    height: 36px;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 301;
    color: var(--text-sec);
    transition: all 0.3s ease;
}

.sidebar-toggle-btn:hover {
    color: var(--accent);
    transform: scale(1.15);
}

html.sidebar-collapsed .sidebar-toggle-btn i {
    transform: rotate(180deg);
}

/* ----------------------------------------------------------
   SIDEBAR FOOTER / USER CARD
   ---------------------------------------------------------- */
.sidebar-footer {
    border-top: 1px solid var(--border);
    padding-top: 15px;
}

.tariff-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
}
.tariff-badge i { font-size: 14px; }
.tariff-badge.active {
    background: rgba(33, 148, 127, 0.1);
    border: 1px solid rgba(33, 148, 127, 0.2);
    color: var(--accent, #21947f);
}
.tariff-badge.inactive {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.2);
    color: #f59e0b;
    animation: tariff-pulse 2s ease-in-out infinite;
}
.tariff-badge:hover { transform: translateY(-1px); }
@keyframes tariff-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}
.sidebar-collapsed .tariff-badge span { display: none; }
.sidebar-collapsed .tariff-badge { justify-content: center; padding: 8px; }

.user-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 14px;
    text-decoration: none;
    color: var(--text-main);
    transition: 0.2s;
    cursor: pointer;
    width: 100%;
}

.user-card:hover {
    background: var(--bg-input);
}

.user-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

/* ----------------------------------------------------------
   SIDEBAR OVERLAY (mobile backdrop)
   ---------------------------------------------------------- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 299;
}

/* ----------------------------------------------------------
   MOBILE RESPONSIVE
   ---------------------------------------------------------- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
        /* Полностью отключаем стекло на мобильном — только при открытии применяем solid */
        background-color: transparent !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    /* Псевдоэлементы glass скрываем — они создают эффект прозрачности */
    .sidebar::before,
    .sidebar::after {
        display: none !important;
    }

    html.sidebar-open .sidebar {
        transform: translateX(0) !important;
        width: 280px !important;
        /* Плотный непрозрачный фон — контент позади не просвечивает */
        background-color: var(--bg-base) !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        border-right: 1px solid var(--glass-border);
        border-radius: 0 20px 20px 0;
        box-shadow: 4px 0 32px rgba(0, 0, 0, 0.45);
    }

    /* Светлая тема: явно перекрываем bg-base */
    [data-theme="light"] html.sidebar-open .sidebar,
    html[data-theme="light"].sidebar-open .sidebar {
        background-color: #F2F7F5 !important;
    }

    html.sidebar-open .sidebar-overlay {
        display: block;
        /* Более плотное затемнение + лёгкое размытие контента за overlay */
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }

    .sidebar-toggle-btn {
        display: none;
    }

    .mobile-menu-btn {
        display: flex;
    }

    .main-content {
        width: 100% !important;
        margin-left: 0 !important;
    }

    /* Override sidebar-collapsed width on mobile — match specificity (0,1,1) */
    html.sidebar-collapsed .main-content {
        width: 100% !important;
        margin-left: 0 !important;
    }
}

/* ----------------------------------------------------------
   ACCESSIBILITY
   ---------------------------------------------------------- */
.sidebar-toggle-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ----------------------------------------------------------
   MOBILE: Notification dropdown — не выходит за экран
   ---------------------------------------------------------- */
@media (max-width: 768px) {
    .notif-dropdown {
        width: calc(100vw - 24px) !important;
        right: -8px !important;
        left: auto !important;
        max-height: 60vh;
    }
}

/* ----------------------------------------------------------
   MOBILE: Дополнительные кнопки шапки — переносим под основную строку
   На десктопе .mobile-actions-row скрыт, кнопки показываются в top-bar-actions.
   На мобильном .top-bar-actions скрывает extra-кнопки через .top-bar-extra,
   а .mobile-actions-row разворачивается под основной строкой шапки.
   ---------------------------------------------------------- */
.mobile-actions-row {
    display: none; /* скрыто на десктопе */
}

@media (max-width: 768px) {
    /* Обёртка шапки разрешает перенос */
    .top-bar-inset {
        flex-wrap: wrap !important;
        align-items: center;
    }

    /* Правая группа — только bell + theme + бургер */
    .top-bar-actions {
        flex-shrink: 0;
    }

    /* Скрываем extra-кнопки внутри top-bar-actions */
    .top-bar-actions .top-bar-extra {
        display: none !important;
    }

    /* Показываем secondary-строку под шапкой */
    .mobile-actions-row {
        display: flex;
        align-items: center;
        gap: 8px;
        width: 100%;
        order: 10;
        padding: 8px 0 4px;
        flex-wrap: wrap;
        border-top: 1px solid var(--glass-border);
        margin-top: 4px;
    }

    /* Кнопки в secondary-строке — полноширинные или авто */
    .mobile-actions-row .btn {
        flex: 1;
        min-width: 120px;
        justify-content: center;
    }

    /* Инпуты и select в secondary-строке — на всю ширину */
    .mobile-actions-row input,
    .mobile-actions-row select {
        flex: 1;
        min-width: 0;
        width: 100%;
    }
}

/* ----------------------------------------------------------
   TOAST NOTIFICATION
   ---------------------------------------------------------- */
.statix-toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-card, #1a1a2e);
    color: var(--text-main, #fff);
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 10000;
    pointer-events: none;
    border: 1px solid var(--border, rgba(255,255,255,0.1));
    backdrop-filter: blur(10px);
}

.statix-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ----------------------------------------------------------
   GLOBAL SCROLLBAR (thin, minimal)
   ---------------------------------------------------------- */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(128, 128, 128, 0.2); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(128, 128, 128, 0.4); }
