/*
 * Entity-Centric Sidebar Styles (Pipedrive/Kommo-style)
 * SP-UX-NavRestructure
 *
 * Two-part sidebar: icon rail (48px) + expandable panel (240px)
 * Works with Metronic's app-sidebar framework
 */

/* ═══════════════════════════════════════════════════════════ */
/* SIDEBAR CONTAINER                                          */
/* ═══════════════════════════════════════════════════════════ */

.sp-entity-sidebar {
    width: 48px; /* icon rail only by default */
    transition: width 0.25s ease;
    position: relative;
}

.sp-entity-sidebar.sp-entity-sidebar--expanded {
    width: 288px; /* 48px icon rail + 240px panel */
}

/* ═══════════════════════════════════════════════════════════ */
/* ICON RAIL                                                   */
/* ═══════════════════════════════════════════════════════════ */

.sp-icon-rail {
    width: 48px;
    min-width: 48px;
    background-color: var(--bs-app-sidebar-base-bg-color, #1e1e2d);
    border-right: 1px solid var(--bs-app-sidebar-base-border-color, rgba(255, 255, 255, 0.07));
    z-index: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.sp-icon-rail::-webkit-scrollbar {
    width: 0;
}

/* ── Icon Rail Logo ── */

.sp-icon-rail__logo {
    padding: 4px 0;
}

/* ── Icon Rail Items ── */

.sp-icon-rail__item {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 4px;
    position: relative;
    transition: all 0.15s ease;
    color: var(--bs-app-sidebar-base-menu-link-icon-color, #7e8299);
}

.sp-icon-rail__item:hover {
    background-color: rgba(255, 255, 255, 0.06);
    color: var(--bs-app-sidebar-base-menu-link-icon-color-active, #fff);
}

.sp-icon-rail__item--active {
    background-color: rgba(var(--bs-primary-rgb), 0.15);
    color: var(--bs-primary) !important;
}

.sp-icon-rail__item--expanded {
    background-color: rgba(var(--bs-primary-rgb), 0.2);
    color: var(--bs-primary) !important;
}

.sp-icon-rail__item--toggle {
    color: var(--bs-app-sidebar-base-menu-link-icon-color, #7e8299);
    opacity: 0.6;
}

.sp-icon-rail__item--toggle:hover {
    opacity: 1;
}

/* ── View Only Badge ── */

.sp-icon-rail__badge {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 7px;
}

.sp-icon-rail__badge--view-only {
    background-color: var(--bs-info);
    color: #fff;
}

/* ═══════════════════════════════════════════════════════════ */
/* EXPANDABLE PANEL                                            */
/* ═══════════════════════════════════════════════════════════ */

.sp-sidebar-panel {
    width: 240px;
    min-width: 240px;
    background-color: var(--bs-app-sidebar-base-bg-color, #1e1e2d);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-left: 1px solid rgba(255, 255, 255, 0.04);
}

/* ── Transitions ── */

.sp-sidebar-panel--enter {
    transition: all 0.2s ease-out;
}

.sp-sidebar-panel--leave {
    transition: all 0.15s ease-in;
}

/* ── Panel Section ── */

.sp-sidebar-panel__section {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ── Panel Header ── */

.sp-sidebar-panel__header {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.sp-sidebar-panel__header h6 {
    color: var(--bs-app-sidebar-base-menu-heading-color, #636674);
}

/* ── Context Badges ── */

.sp-sidebar-panel__context {
    flex-shrink: 0;
}

.sp-context-badge {
    transition: background-color 0.15s ease;
}

.sp-context-badge:hover {
    opacity: 0.85;
}

/* ── Menu ── */

.sp-sidebar-panel__menu {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.sp-sidebar-panel__menu::-webkit-scrollbar {
    width: 4px;
}

.sp-sidebar-panel__menu::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

/* Menu item styling within the entity sidebar */
.sp-sidebar-panel .menu-item .menu-link {
    padding: 6px 10px;
    border-radius: 6px;
    margin-bottom: 1px;
    color: var(--bs-app-sidebar-base-menu-link-color, #9d9da6);
    font-size: 0.85rem;
}

.sp-sidebar-panel .menu-item .menu-link:hover {
    background-color: rgba(255, 255, 255, 0.04);
    color: var(--bs-app-sidebar-base-menu-link-color-hover, #fff);
}

.sp-sidebar-panel .menu-item .menu-link.active {
    background-color: rgba(var(--bs-primary-rgb), 0.12);
    color: var(--bs-primary);
}

.sp-sidebar-panel .menu-item .menu-link.active .menu-icon i {
    color: var(--bs-primary);
}

.sp-sidebar-panel .menu-item .menu-link .menu-icon {
    width: 24px;
    margin-right: 8px;
    flex-shrink: 0;
}

.sp-sidebar-panel .menu-item .menu-link .menu-icon i {
    color: var(--bs-app-sidebar-base-menu-link-icon-color, #7e8299);
    font-size: 1rem;
}

.sp-sidebar-panel .menu-item .menu-link .menu-title {
    font-weight: 500;
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Section headers inside panel */
.sp-sidebar-panel .menu-section {
    font-size: 0.7rem;
    letter-spacing: 0.5px;
}

/* Disabled items */
.sp-sidebar-panel .menu-item .menu-link.text-muted {
    cursor: not-allowed;
    opacity: 0.5;
}

/* Badges */
.sp-sidebar-panel .menu-link .badge {
    margin-left: auto;
    font-size: 0.65rem;
    padding: 2px 6px;
}

/* ═══════════════════════════════════════════════════════════ */
/* TENANT SELECTOR (bottom of sidebar)                         */
/* ═══════════════════════════════════════════════════════════ */

.sp-sidebar-tenant {
    z-index: 2;
}

/* ═══════════════════════════════════════════════════════════ */
/* RESPONSIVE / MOBILE                                         */
/* ═══════════════════════════════════════════════════════════ */

@media (max-width: 991.98px) {
    /* On mobile, sidebar is a drawer — show full width */
    .sp-entity-sidebar {
        width: 288px !important;
    }

    .sp-sidebar-panel {
        display: flex !important;
    }
}

/* ═══════════════════════════════════════════════════════════ */
/* METRONIC MINIMIZE STATE                                     */
/* ═══════════════════════════════════════════════════════════ */

/* When Metronic minimize is active, only show icon rail */
body.app-sidebar-minimize .sp-entity-sidebar {
    width: 48px;
}

body.app-sidebar-minimize .sp-sidebar-panel {
    display: none;
}

/* ═══════════════════════════════════════════════════════════ */
/* FEATURE TIER (progressive disclosure)                       */
/* ═══════════════════════════════════════════════════════════ */

[data-feature-tier="advanced"] {
    /* Default: visible. Controlled by JS toggle */
}

body.sp-hide-advanced [data-feature-tier="advanced"] {
    display: none !important;
}

/* ═══════════════════════════════════════════════════════════ */
/* LIGHT THEME OVERRIDES                                       */
/* ═══════════════════════════════════════════════════════════ */

[data-bs-theme="light"] .sp-icon-rail {
    background-color: var(--bs-app-sidebar-light-bg-color, #f8f9fa);
    border-right-color: var(--bs-border-color, #e4e6ef);
}

[data-bs-theme="light"] .sp-sidebar-panel {
    background-color: var(--bs-app-sidebar-light-bg-color, #f8f9fa);
    border-left-color: var(--bs-border-color, #e4e6ef);
}

[data-bs-theme="light"] .sp-icon-rail__item {
    color: var(--bs-gray-600);
}

[data-bs-theme="light"] .sp-icon-rail__item:hover {
    background-color: rgba(0, 0, 0, 0.04);
    color: var(--bs-gray-900);
}

[data-bs-theme="light"] .sp-icon-rail__item--active {
    background-color: rgba(var(--bs-primary-rgb), 0.1);
    color: var(--bs-primary) !important;
}

[data-bs-theme="light"] .sp-sidebar-panel .menu-item .menu-link {
    color: var(--bs-gray-700);
}

[data-bs-theme="light"] .sp-sidebar-panel .menu-item .menu-link:hover {
    background-color: rgba(0, 0, 0, 0.03);
    color: var(--bs-gray-900);
}

[data-bs-theme="light"] .sp-sidebar-panel .menu-item .menu-link.active {
    background-color: rgba(var(--bs-primary-rgb), 0.08);
    color: var(--bs-primary);
}
