/* =========================================
   SIDEBAR ARCHITECTURE (BEM Methodology)
   Single Source of Truth
========================================= */

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width); /* Hard ceiling stops horizontal shifting */
    height: 100% !important;
    min-height: 100vh !important;
    background-color: #202938;
    padding: 16px 12px;
    
    /* Hardened Flex Layout */
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    gap: 4px;
    
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
    flex-shrink: 0 !important; /* Forces the browser to never compress this column */
    
    /* MacOS-like smooth scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--sidebar-border) transparent;
}
.sidebar::-webkit-scrollbar {
    width: 4px;
}
.sidebar::-webkit-scrollbar-thumb {
    background-color: var(--sidebar-border);
    border-radius: 4px;
}

/* --- Container Item --- */
.sidebar__item {
    display: flex;
    flex-direction: column;
    
    /* Prevent page-specific styles from stretching items */
    flex: 0 0 auto !important; 
    margin: 0 !important; 
    padding: 0 !important;
}

/* --- Parent Links --- */
.sidebar__link {
    display: flex;
    align-items: center;
    height: 40px;
    padding: 0 12px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--sidebar-text);
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.15s ease, color 0.15s ease;
    cursor: pointer;
}

.sidebar__link:hover,
.sidebar__link:focus {
    background-color: var(--sidebar-hover-bg);
    color: var(--sidebar-text-hover);
    outline: none;
}

.sidebar__link.active {
    background-color: #2563EB;
    color: var(--sidebar-text-active);
    font-weight: 600;
}

/* Highlight border for active parent link */
.sidebar__link.active::before {
    content: '';
    position: absolute;
    left: 0;
    height: 24px;
    width: 4px;
    background-color: var(--sp-primary);
    border-radius: 0 4px 4px 0;
}

/* --- Typography & Icons --- */
.sidebar__icon {
    width: 24px;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-right: 10px;
}

.sidebar__text {
    flex-grow: 1;
    white-space: nowrap;
}

.sidebar__chevron {
    font-size: 12px;
    color: var(--sidebar-text-muted);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar__link[aria-expanded="true"] .sidebar__chevron {
    transform: rotate(180deg);
}

/* --- Submenu Area --- */
.sidebar__submenu {
    margin: 4px 0 4px 22px;
    padding-left: 10px;
    border-left: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Bootstrap Collapse overrides to prevent janky margins */
.sidebar .collapse,
.sidebar .collapsing {
    margin: 0;
    padding: 0;
}

/* --- Submenu Links --- */
.sidebar__sublink {
    display: flex;
    align-items: center;
    height: 36px;
    padding: 0 12px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--sidebar-text);
    font-size: 13.5px;
    font-weight: 500;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar__sublink:hover,
.sidebar__sublink:focus {
    background-color: rgba(255,255,255,.08);
    color: #CBD5E1;
    outline: none;
}

.sidebar__sublink.active {
    color: var(--sidebar-text-active);
    font-weight: 600;
}

.sidebar__subicon {
    font-size: 15px;
    margin-right: 8px;
    width: 20px;
}

/* --- Badges --- */
.sidebar__badge {
    background-color: var(--sp-primary);
    color: #FFFFFF;
    font-size: 11px;
    font-weight: 650;
    padding: 2px 8px;
    border-radius: 20px;
    margin-left: 8px;
    line-height: 1.4;
}

/* =========================================
   MOBILE RESPONSIVENESS
========================================= */
@media (max-width: 767.98px) {
    .sidebar {
        position: fixed;
        top: var(--topbar-height);
        left: -260px; /* Hide completely */
        z-index: 1040;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        height: calc(100vh - var(--topbar-height));
        box-shadow: 4px 0 15px rgba(0,0,0,0.1);
    }

    .sidebar.active {
        left: 0;
    }
}

.in-iframe .sidebar__link{
    height: 30px;
}

.in-iframe .sp-btn{
    padding: 0 12px;
}

.in-iframe .sidebar{
    max-width: 200px;
    min-width: 200px;
}

.in-iframe .sidebar__submenu{
    padding-left: 0px;
    gap: 0;
}

.in-iframe .sidebar__link.active{
    font-weight: 500;
}

.saas-page-header{
    background: #FFFFFF;
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    display: flex;
    justify-content: space-between;
    align-items: center;
}