/* App Sidebar - Left navigation for /app pages */
/* SINGLE SOURCE OF TRUTH - All /app sidebar styling */
/* Uses established design system variables */

.app-sidebar {
    display: flex;
    flex-direction: column;
    width: 260px;
    min-width: 260px;
    height: calc(100vh - 72px); /* Account for header + margin */
    background: rgba(15, 15, 25, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-lg);
    margin: 12px 0 12px 12px;
    overflow: hidden;
}

.app-sidebar-header {
    padding: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.app-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.app-sidebar-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 0.75rem 1rem;
}

.app-sidebar-section {
    padding: 0.25rem 0;
}

/* Link row container for product links with add button */
.app-sidebar-link-row {
    display: flex;
    align-items: center;
    border-left: 3px solid transparent;
    margin: 0.125rem 0;
    padding-right: 0.5rem;
}

.app-sidebar-link-row:hover {
    background: var(--glass-white-5);
}

.app-sidebar-link-row.active {
    background: rgba(113, 44, 249, 0.1);
    border-left-color: var(--brand-primary);
}

.app-sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
    margin: 0.125rem 0;
    flex: 1;
}

/* Reset for links inside link-row */
.app-sidebar-link-row .app-sidebar-link {
    border-left: none;
    margin: 0;
    padding-right: 0.5rem;
}

.app-sidebar-link:hover {
    background: var(--glass-white-5);
    color: var(--text-primary);
}

.app-sidebar-link-row:hover .app-sidebar-link {
    background: transparent;
    color: var(--text-primary);
}

.app-sidebar-link.active,
.app-sidebar-link-row.active .app-sidebar-link {
    background: rgba(113, 44, 249, 0.1);
    color: var(--brand-primary);
    border-left-color: var(--brand-primary);
    font-weight: 500;
}

.app-sidebar-link-row.active .app-sidebar-link {
    background: transparent;
    border-left: none;
}

.app-sidebar-link-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    color: inherit;
    opacity: 0.7;
}

.app-sidebar-link-icon svg {
    width: 18px;
    height: 18px;
}

.app-sidebar-link.active .app-sidebar-link-icon {
    opacity: 1;
}

.app-sidebar-link-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-sidebar-badge {
    flex-shrink: 0;
    min-width: 20px;
    height: 20px;
    padding: 0 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-xs);
    font-weight: 600;
    background: var(--bg-surface-raised);
    color: var(--text-muted);
    border-radius: 9999px;
}

.app-sidebar-link.active .app-sidebar-badge {
    background: var(--brand-primary);
    color: white;
}

/* Add button for creating new instances */
.app-sidebar-add-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    background: transparent;
    transition: all 0.15s ease;
    text-decoration: none;
}

.app-sidebar-add-btn:hover {
    background: var(--brand-primary);
    color: white;
}

.app-sidebar-link-row.active .app-sidebar-add-btn {
    color: var(--brand-primary);
}

.app-sidebar-link-row.active .app-sidebar-add-btn:hover {
    background: var(--brand-primary);
    color: white;
}

/* Product with sections */
.app-sidebar-product {
    margin-bottom: 0.25rem;
}

/* Inactive products styling */
.app-sidebar-product:not(.enabled) {
    opacity: 0.65;
}

.app-sidebar-product:not(.enabled):hover {
    opacity: 0.85;
}

.app-sidebar-product.expanded {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    margin: 0.25rem 0.5rem;
    overflow: hidden;
}

.app-sidebar-product.expanded .app-sidebar-link {
    border-left: none;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    margin: 0;
}

.app-sidebar-sections {
    padding: 0.25rem 0 0.5rem;
    margin-left: 2.5rem;
}

.app-sidebar-section-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.375rem 0.75rem;
    font-size: var(--text-sm);
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.15s ease;
}

.app-sidebar-section-link:hover {
    background: var(--glass-white-5);
    color: var(--text-primary);
}

.app-sidebar-section-link.active {
    color: var(--brand-primary);
    font-weight: 500;
}

.app-sidebar-section-badge {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* Sub-section groups (accordion) */
.app-sidebar-subsection-group {
    margin-bottom: 0.125rem;
}

.app-sidebar-section-toggle {
    width: 100%;
    border: none;
    background: transparent;
    cursor: pointer;
    text-align: left;
}

.app-sidebar-section-toggle span {
    flex: 1;
}

.app-sidebar-chevron {
    flex-shrink: 0;
    opacity: 0.5;
    transition:
        transform 0.2s ease,
        opacity 0.2s ease;
}

.app-sidebar-section-toggle:hover .app-sidebar-chevron {
    opacity: 0.8;
}

.app-sidebar-subsection-group.expanded .app-sidebar-chevron {
    transform: rotate(90deg);
}

.app-sidebar-subsections {
    display: none;
    padding-left: 0.75rem;
    margin-top: 0.25rem;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    margin-left: 0.25rem;
}

.app-sidebar-subsection-group.expanded .app-sidebar-subsections {
    display: block;
}

.app-sidebar-subsection-link {
    display: block;
    padding: 0.375rem 0.75rem;
    font-size: var(--text-sm);
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
}

.app-sidebar-subsection-link:hover {
    background: var(--glass-white-5);
    color: var(--text-primary);
}

.app-sidebar-subsection-link.active {
    color: var(--brand-primary);
    font-weight: 500;
}

/* Footer */
.app-sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin-top: auto;
}

.app-sidebar-back {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: var(--text-sm);
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.15s ease;
}

.app-sidebar-back:hover {
    background: var(--glass-white-5);
    color: var(--brand-primary);
}

.app-sidebar-back svg {
    width: 16px;
    height: 16px;
}

/* ===================================
   Sidebar Site Selector
   =================================== */

.sidebar-site-selector {
    display: flex;
    flex-direction: column;
}

/* Toggle button (always visible) - matches item styling */
.sidebar-sites-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease;
}

.sidebar-sites-toggle:hover {
    background: var(--glass-white-5);
}

.sidebar-sites-chevron {
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.sidebar-site-selector[data-expanded="true"] .sidebar-sites-chevron {
    transform: rotate(90deg);
}

/* Collapsible sites list */
.sidebar-sites-list {
    display: none;
    flex-direction: column;
    max-height: 300px;
    overflow-y: auto;
}

.sidebar-site-selector[data-expanded="true"] .sidebar-sites-list {
    display: flex;
}

.sidebar-site-selector-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    background: var(--glass-white-10);
    border-radius: var(--radius-md);
    color: var(--text-primary);
}

.sidebar-site-selector-icon svg {
    width: 20px;
    height: 20px;
}

.sidebar-site-selector-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-site-selector-name {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-site-selector-url {
    font-size: var(--text-xs);
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-site-selector-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    text-decoration: none;
    transition: background 0.15s ease;
}

.sidebar-site-selector-item:hover {
    background: var(--glass-white-5);
}

.sidebar-site-selector-item.active {
    background: rgba(113, 44, 249, 0.1);
}

.sidebar-site-selector-item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    background: var(--glass-white-10);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
}

.sidebar-site-selector-item.active .sidebar-site-selector-item-icon {
    background: var(--brand-primary);
    color: white;
}

.sidebar-site-selector-item-icon svg {
    width: 16px;
    height: 16px;
}

.sidebar-site-selector-item-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.sidebar-site-selector-item-name {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-site-selector-item-meta {
    font-size: var(--text-xs);
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-site-selector-check {
    flex-shrink: 0;
    color: var(--brand-primary);
}

.sidebar-site-selector-action {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    font-size: var(--text-sm);
    color: var(--brand-primary);
    text-decoration: none;
    transition: background 0.15s ease;
}

.sidebar-site-selector-action:hover {
    background: var(--glass-white-5);
}

.sidebar-site-selector-action svg {
    width: 14px;
    height: 14px;
}

/* ===================================
   App Layout Container
   =================================== */

.app-layout-container {
    display: flex;
    min-height: calc(100vh - 60px);
}

.app-main {
    flex: 1;
    min-width: 0;
    padding: 1.5rem;
}

/* Mobile responsive */
@media (max-width: 1024px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        right: 0; /* Full width */
        top: 105px; /* Below header with balanced spacing (header ~60px + margin) */
        bottom: 0;
        width: 100%;
        min-width: 100%;
        z-index: 100;
        transform: translateY(-100vh); /* Slide down from top */
        transition: transform 0.3s ease;
        box-shadow: var(--shadow-xl);
        margin: 0;
        border-radius: 0;
        border: none;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        height: calc(100vh - 72px);
        background: rgba(
            15,
            15,
            25,
            0.98
        ); /* Slightly more opaque for full-screen */
    }

    .app-sidebar.open {
        transform: translateY(0);
    }

    .app-sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }

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

    .app-main {
        padding: 1rem;
    }
}

/* ===================================
   Gradient Section in App Layout
   Override gradient-full-page negative margin
   when inside app-main (not needed here)
   =================================== */

.app-main .gradient-animated-section.gradient-full-page {
    margin-top: 0;
    min-height: auto;
}

/* ===================================
   Mobile-only Navigation Section
   Hidden on desktop, shown on mobile
   =================================== */

.app-sidebar-mobile-nav {
    display: none;
}

/* Admin toggle in mobile sidebar */
.app-sidebar-admin-toggle {
    justify-content: flex-start;
    border: none;
    background: transparent;
    cursor: pointer;
    width: 100%;
}

.app-sidebar-admin-toggle .app-sidebar-chevron {
    margin-left: auto;
    flex-shrink: 0;
    opacity: 0.5;
    transition:
        transform 0.2s ease,
        opacity 0.2s ease;
}

.app-sidebar-product.expanded .app-sidebar-admin-toggle .app-sidebar-chevron {
    transform: rotate(90deg);
}

/* Admin sections - hidden by default, shown when expanded */
.app-sidebar-mobile-nav .app-sidebar-sections {
    display: none;
}

.app-sidebar-mobile-nav .app-sidebar-sections.show {
    display: block;
}

/* Sign out link styling */
.app-sidebar-signout {
    color: var(--text-muted);
}

.app-sidebar-signout:hover {
    color: var(--status-error);
    background: rgba(239, 68, 68, 0.1);
}

/* Mobile styles - show mobile nav section */
@media (max-width: 1024px) {
    .app-sidebar-mobile-nav {
        display: block;
        padding-bottom: 1rem;
        margin-top: auto;
    }
}
