/* Sidebar SaaS — UniLicit */
nav.sidebar,
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    box-sizing: border-box;
    background-color: var(--surface-color);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: none;
    contain: layout style;
    border-right: 1px solid var(--border-color);
    overflow: hidden;
    font-family: var(--font-saas, var(--font-family));
}

.sidebar-header {
    padding: 0 0.75rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    box-sizing: border-box;
}

.sidebar-header--slim {
    height: var(--sidebar-header-height);
    min-height: var(--sidebar-header-height);
    max-height: var(--sidebar-header-height);
    padding: 0 0.65rem 0 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem;
    box-sizing: border-box;
    overflow: hidden;
}

/* Chevron cinza no topo direito — dentro do header (sem position:fixed) */
.sidebar-collapse-toggle {
    flex: 0 0 auto;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #94a3b8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.85;
    line-height: 1;
    transition: color 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.sidebar-collapse-toggle i {
    font-size: 0.72rem;
    line-height: 1;
    width: auto;
}

.sidebar-collapse-toggle:hover,
.sidebar-collapse-toggle:focus-visible {
    opacity: 1;
    color: #64748b;
    background: rgba(148, 163, 184, 0.14);
    outline: none;
}

:root[data-theme="dark"] .sidebar-collapse-toggle {
    color: #9ca3af;
}

:root[data-theme="dark"] .sidebar-collapse-toggle:hover,
:root[data-theme="dark"] .sidebar-collapse-toggle:focus-visible {
    color: #d1d5db;
    background: rgba(156, 163, 175, 0.16);
}

.sidebar .logo {
    font-family: var(--font-display, var(--font-saas));
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.02em;
    color: var(--text-color-dark);
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0;
    white-space: nowrap;
    min-width: 0;
    text-decoration: none;
    flex: 1;
}

.sidebar .logo span {
    background: var(--gradient-brand, linear-gradient(135deg, #6366f1, #8b5cf6 48%, #ec4899));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

.sidebar .logo:hover span {
    filter: brightness(1.05);
}

.sidebar .logo i {
    color: var(--primary-color);
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border-radius: 10px;
    background: var(--saas-bg-subtle, #f1f5f9);
    border: 1px solid var(--border-color);
    color: var(--text-color-body);
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 0;
    padding: 0;
}

.theme-toggle:hover {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.theme-toggle i {
    font-size: 1rem;
    width: auto !important;
}

.sidebar .nav-list-container {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    flex: 1;
}

.nav-main-items {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0.65rem 0.55rem 0.75rem;
    overflow-y: auto;
}

.nav-secondary-items {
    flex-shrink: 0;
    padding: 0.65rem 0.55rem 0.85rem;
    border-top: 1px solid var(--border-color);
    background: transparent;
}

.sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
    width: 100%;
}

.sidebar li {
    margin-bottom: 0.12rem;
}

/* Separadores de seção (estilo layout RX) */
.sidebar li.nav-sec {
    margin: 0.7rem 0 0.25rem;
    pointer-events: none;
}

.sidebar li.nav-sec:first-child {
    margin-top: 0.15rem;
}

.sidebar li.nav-sec span {
    display: block;
    padding: 0 0.75rem;
    font-family: var(--font-display, var(--font-saas));
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-color-light, #64748b);
}

.sidebar a {
    color: var(--text-color-body);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.84rem;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    transition: background 0.15s ease, color 0.15s ease;
    position: relative;
    white-space: nowrap;
}

.sidebar a .fas,
.sidebar a .far {
    width: 1.1rem;
    text-align: center;
    font-size: 0.95rem;
    flex-shrink: 0;
    opacity: 0.85;
}

.sidebar a:hover:not(.active):not(.logout-link) {
    background: var(--primary-soft, #eff6ff);
    color: var(--primary-color);
}

.sidebar a:hover .fas {
    opacity: 1;
}

.sidebar a.active {
    background: var(--primary-soft, #eff6ff);
    color: var(--primary-color);
    font-weight: 600;
}

.sidebar a.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 22%;
    bottom: 22%;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--gradient-brand, linear-gradient(135deg, #6366f1, #ec4899));
    box-shadow: 0 0 10px var(--primary-glow, rgba(99, 102, 241, 0.35));
}

.sidebar a.active .fas {
    opacity: 1;
    color: var(--primary-color);
}

/* Grupo expansível — Pesquisa de preços */
.nav-group {
    margin-bottom: 0.12rem;
}

.nav-group-toggle {
    width: 100%;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    color: var(--text-color-body);
    font-weight: 500;
    font-size: 0.84rem;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    text-align: left;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-group-toggle:hover,
.nav-group.has-active .nav-group-toggle {
    background: var(--primary-soft, #eff6ff);
    color: var(--primary-color);
}

.nav-group.has-active .nav-group-toggle {
    font-weight: 600;
}

.nav-group-chevron {
    margin-left: auto;
    font-size: 0.65rem;
    opacity: 0.5;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.nav-group.is-open .nav-group-chevron {
    transform: rotate(180deg);
}

.nav-group-items {
    list-style: none;
    margin: 0 0 0 0.35rem;
    padding: 0;
    border-left: 2px solid var(--border-color);
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition:
        max-height 0.28s cubic-bezier(0.16, 1, 0.3, 1),
        opacity 0.2s ease,
        padding 0.2s ease;
}

.nav-group.is-open .nav-group-items {
    max-height: 8rem;
    opacity: 1;
    padding: 0.15rem 0 0.3rem;
}

.sidebar a.nav-sublink {
    padding: 0.45rem 0.7rem 0.45rem 1rem;
    font-size: 0.8rem;
    font-weight: 500;
    gap: 0.5rem;
}

.sidebar a.nav-sublink.active {
    box-shadow: none;
    background: var(--primary-soft, #eff6ff);
}

.sidebar a.nav-sublink.active::before {
    display: none;
}

@media (max-width: 992px) {
    .nav-group-toggle > span {
        display: none;
    }

    .nav-group-chevron {
        display: none;
    }

    .sidebar li.nav-sec {
        display: none;
    }

    .nav-group-items {
        border-left: none;
        margin-left: 0;
    }

    .sidebar a.nav-sublink {
        justify-content: center;
        padding: 0.65rem 0.5rem;
    }

    .sidebar a.nav-sublink span {
        display: none;
    }

    .sidebar a.nav-sublink .fas {
        display: block;
        opacity: 1;
    }

    .sidebar a.active::before {
        display: none;
    }
}

.sidebar a.logout-link {
    color: var(--text-color-body);
    border: 1px solid var(--border-color);
    background: var(--surface-color);
}

.sidebar a.logout-link:hover {
    background: #fef2f2;
    color: #dc2626;
    border-color: #fecaca;
}

.notification-dot {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 0.85rem;
    width: 8px;
    height: 8px;
    background-color: var(--danger-color);
    border-radius: 50%;
    border: 2px solid var(--surface-color);
    animation: saas-pulse 2s infinite;
}

.sidebar a.active .notification-dot {
    border-color: #eff6ff;
}

@keyframes saas-pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
    70% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.nav-main-items::-webkit-scrollbar {
    width: 4px;
}

.nav-main-items::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.navbar-logo {
    height: 32px;
    width: auto;
    max-width: 100px;
    object-fit: contain;
    flex-shrink: 0;
}

@media (max-width: 992px) {
    nav.sidebar,
    .sidebar {
        width: var(--sidebar-width-collapsed);
    }

    .sidebar .logo span,
    .sidebar a span {
        display: none;
    }

    .sidebar .logo {
        justify-content: center;
    }

    .sidebar a {
        justify-content: center;
        padding: 0.75rem 0.5rem;
    }

    .notification-dot {
        top: 0.45rem;
        right: 0.45rem;
        transform: none;
    }

    .navbar-logo {
        height: 32px;
        max-width: 48px;
    }
}

:root[data-theme="dark"] .sidebar a:hover,
:root[data-theme="dark"] .sidebar a.active {
    background: rgba(59, 130, 246, 0.15);
}

:root[data-theme="dark"] .nav-secondary-items {
    background: var(--bg-color);
}

/* Desktop: sidebar recolhida sob demanda */
html.sidebar-collapsed-pending,
body.sidebar-collapsed {
    --app-sidebar-current: var(--sidebar-width-collapsed);
}

body.sidebar-collapsed nav.sidebar,
body.sidebar-collapsed .sidebar {
    width: var(--sidebar-width-collapsed);
}

body.sidebar-collapsed .sidebar .logo span,
body.sidebar-collapsed .sidebar a span,
body.sidebar-collapsed .nav-group-toggle > span,
body.sidebar-collapsed .nav-group-chevron,
body.sidebar-collapsed .sidebar li.nav-sec {
    display: none;
}

body.sidebar-collapsed .sidebar-header--slim {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: auto;
    min-height: var(--sidebar-header-height);
    max-height: none;
    padding: 0.45rem 0.25rem 0.35rem;
    gap: 0.15rem;
}

body.sidebar-collapsed .sidebar .logo {
    justify-content: center;
    flex: 0 0 auto;
    width: 100%;
}

body.sidebar-collapsed .sidebar-collapse-toggle {
    color: #94a3b8;
    opacity: 0.9;
}

body.sidebar-collapsed .sidebar a,
body.sidebar-collapsed .nav-group-toggle {
    justify-content: center;
    padding: 0.65rem 0.35rem;
    gap: 0;
    max-width: 100%;
    overflow: hidden;
    transform: none !important;
}

body.sidebar-collapsed .sidebar a.active::before {
    display: none;
}

body.sidebar-collapsed .nav-group-items {
    border-left: none;
    margin-left: 0;
}

body.sidebar-collapsed .sidebar a.nav-sublink {
    justify-content: center;
    padding: 0.55rem 0.35rem;
}

body.sidebar-collapsed .sidebar a.nav-sublink .fas {
    display: block;
    opacity: 1;
}

body.sidebar-collapsed .notification-dot {
    top: 0.35rem;
    right: 0.35rem;
    transform: none;
}

body.sidebar-collapsed .navbar-logo {
    height: 28px;
    max-width: 36px;
}

@media (max-width: 992px) {
    .sidebar-collapse-toggle {
        display: none;
    }
}
