/* Modern Sidebar Styles */
:root {
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 70px;
    --sidebar-bg: #ffffff;
    --sidebar-hover: #f3f4f6;
    --sidebar-active: #3b82f6;
    --sidebar-text: #6b7280;
    --sidebar-text-active: #ffffff;
    --sidebar-border: #e5e7eb;
}

.modern-sidebar {
    position: fixed;
    top: var(--header-height, 70px);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height, 70px));
    background: var(--sidebar-bg);
    z-index: 900;
    display: flex;
    flex-direction: column;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

.modern-sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Brand Section */
.sidebar-brand {
    padding: 20px;
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 70px;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: #1f2937;
    flex: 1;
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
    flex-shrink: 0;
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.3s;
}

.modern-sidebar.collapsed .logo-text {
    opacity: 0;
    visibility: hidden;
}

.admin-badge {
    background: #ef4444;
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-left: 8px;
    white-space: nowrap;
}

.modern-sidebar.collapsed .admin-badge {
    display: none;
}

.sidebar-toggle-btn {
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.3s;
}

.sidebar-toggle-btn:hover {
    background: var(--sidebar-hover);
    color: #3b82f6;
}

/* Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 0;
}

.nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-item {
    margin-bottom: 2px;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    color: var(--nav-color);
    text-decoration: none;
    transition: all 0.2s ease;
    position: relative;
    cursor: pointer;
    z-index: 901;
    pointer-events: auto !important;
}

.nav-link:hover {
    background: var(--sidebar-hover);
    color: #3b82f6;
}

.nav-link.active {
    background: var(--sidebar-active);
    color: var(--sidebar-text-active);
}

.nav-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    color: inherit;
}

.nav-text {
    margin-left: 10px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.3s;
}

.nav-pro-badge {
    margin-left: auto;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #4338ca;
    background: #e0e7ff;
    padding: 0.12rem 0.4rem;
    border-radius: 999px;
}

.modern-sidebar.collapsed .nav-pro-badge {
    display: none;
}

.nav-link--gated {
    opacity: 0.92;
}

.modern-sidebar.collapsed .nav-text {
    opacity: 0;
    visibility: hidden;
}

.nav-arrow {
    margin-left: auto;
    font-size: 12px;
    transition: transform 0.3s;
    opacity: 0.7;
}

.nav-item.open .nav-arrow {
    transform: rotate(180deg);
}

.modern-sidebar.collapsed .nav-arrow {
    display: none;
}

/* Submenu */
.submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: #f9fafb;
}

.nav-item.open .submenu {
    max-height: 500px;
}

.submenu .nav-link {
    padding: 6px 12px 6px 44px;
    font-size: 13px;
}

.modern-sidebar.collapsed .submenu {
    display: none;
}

/* Profile Section */
.sidebar-profile {
    padding: 20px;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.profile-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.profile-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-details {
    min-width: 0;
    flex: 1;
}

.profile-name {
    color: #1f2937;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-role {
    color: var(--sidebar-text);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modern-sidebar.collapsed .profile-details {
    display: none;
}

.profile-actions {
    display: flex;
    gap: 8px;
}

.profile-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: #f3f4f6;
    color: var(--sidebar-text);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 14px;
    transition: all 0.3s;
}

.profile-action-btn:hover {
    background: #e5e7eb;
    color: #3b82f6;
}

.modern-sidebar.collapsed .profile-actions {
    flex-direction: column;
}

/* Mobile Overlay - cobre tudo (inclusive o header) quando o drawer abre */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1050;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    display: none;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Main Content Adjustment */
.main-content {
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.main-content.sidebar-collapsed {
    margin-left: var(--sidebar-collapsed-width);
}

/* Footer Adjustment — desloca o rodapé para não ficar embaixo da sidebar fixa.
   Usa sibling combinator para acompanhar automaticamente o estado collapsed
   da sidebar sem exigir JS adicional. */
.modern-sidebar ~ .main-footer {
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modern-sidebar.collapsed ~ .main-footer {
    margin-left: var(--sidebar-collapsed-width);
}

/* Responsive - até 1024px tratamos a sidebar como drawer (off-canvas) */
@media (max-width: 1024px) {
    .modern-sidebar {
        top: 0;
        height: 100vh;
        transform: translateX(-100%);
        z-index: 1100; /* acima do header e do overlay */
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.25);
    }

    .modern-sidebar.mobile-open {
        transform: translateX(0);
    }

    /* No mobile, ignorar o estado "collapsed" do desktop */
    .modern-sidebar.collapsed {
        width: var(--sidebar-width);
        transform: translateX(-100%);
    }

    .modern-sidebar.collapsed.mobile-open {
        transform: translateX(0);
    }

    .modern-sidebar.collapsed .logo-text,
    .modern-sidebar.collapsed .nav-text,
    .modern-sidebar.collapsed .profile-details,
    .modern-sidebar.mobile-open .logo-text,
    .modern-sidebar.mobile-open .nav-text,
    .modern-sidebar.mobile-open .profile-details {
        opacity: 1;
        visibility: visible;
    }

    .sidebar-overlay {
        display: block;
    }

    .main-content,
    .main-content.sidebar-collapsed {
        margin-left: 0;
    }

    .modern-sidebar ~ .main-footer,
    .modern-sidebar.collapsed ~ .main-footer {
        margin-left: 0;
    }

    /* Trava de rolagem enquanto o drawer está aberto */
    body.sidebar-mobile-open {
        overflow: hidden;
    }
}

/* Smooth Scrollbar */
.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 2px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Tooltip for collapsed sidebar */
.modern-sidebar.collapsed .nav-link {
    position: relative;
}

.modern-sidebar.collapsed .nav-link::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 10px;
    background: #333;
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    z-index: 1001;
    pointer-events: none;
}

.modern-sidebar.collapsed .nav-link:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Animation for menu items */
.nav-item {
    animation: slideInLeft 0.3s ease forwards;
    opacity: 0;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Stagger animation */
.nav-item:nth-child(1) { animation-delay: 0.05s; }
.nav-item:nth-child(2) { animation-delay: 0.1s; }
.nav-item:nth-child(3) { animation-delay: 0.15s; }
.nav-item:nth-child(4) { animation-delay: 0.2s; }
.nav-item:nth-child(5) { animation-delay: 0.25s; }
.nav-item:nth-child(6) { animation-delay: 0.3s; }
.nav-item:nth-child(7) { animation-delay: 0.35s; }
.nav-item:nth-child(8) { animation-delay: 0.4s; }
.nav-item:nth-child(9) { animation-delay: 0.45s; }
.nav-item:nth-child(10) { animation-delay: 0.5s; }
.nav-item:nth-child(11) { animation-delay: 0.55s; }
.nav-item:nth-child(12) { animation-delay: 0.6s; }
.nav-item:nth-child(13) { animation-delay: 0.65s; }
.nav-item:nth-child(14) { animation-delay: 0.7s; }
.nav-item:nth-child(15) { animation-delay: 0.75s; }

/* Topo da sidebar: logo ou nome do negócio */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    /* Espaço superior confortável abaixo do topo da sidebar (já deslocada pelo header fixo) */
    padding: 14px 14px 10px 14px;
    border-bottom: 1px solid var(--sidebar-border);
    min-height: 52px;
    flex-shrink: 0;
}

.sidebar-business-link {
    display: flex;
    align-items: center;
    min-width: 0;
    flex: 1;
    text-decoration: none;
    color: #1f2937;
}

.sidebar-business-logo {
    display: block;
    max-height: 44px;
    max-width: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    object-position: left center;
}

.sidebar-business-name {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.sidebar-business-name--muted {
    font-size: 0.95rem;
    font-weight: 600;
    color: #9ca3af;
}

.sidebar-business-fallback-icon {
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: #fff;
    font-size: 1rem;
    flex-shrink: 0;
}

.modern-sidebar.collapsed .sidebar-business-logo {
    max-width: 40px;
    max-height: 40px;
    margin: 0 auto;
}

.modern-sidebar.collapsed .sidebar-business-name {
    display: none;
}

.modern-sidebar.collapsed .sidebar-business-link--textonly .sidebar-business-logo {
    display: none;
}

.modern-sidebar.collapsed .sidebar-business-link--textonly .sidebar-business-fallback-icon {
    display: flex;
}

.modern-sidebar.collapsed .sidebar-header {
    flex-direction: column;
    justify-content: center;
    padding: 14px 8px 10px 8px;
    gap: 8px;
}

.modern-sidebar.collapsed .sidebar-toggle {
    order: -1;
    align-self: center;
}

.modern-sidebar.collapsed .sidebar-business-link {
    justify-content: center;
}
