/* =====================================================
   eBrain Sidebar & Command Palette Styles
   ===================================================== */

:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 64px;
    --sidebar-bg: #1a1a2e;
    --sidebar-text: #a0a0b0;
    --sidebar-text-hover: #ffffff;
    --sidebar-active-bg: rgba(223, 32, 118, 0.15);
    --sidebar-active-text: #DF2076;
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --sidebar-group-bg: rgba(255, 255, 255, 0.03);
    --top-bar-height: 48px;
    --centara-primary: #DF2076;
    --centara-primary-light: rgba(223, 32, 118, 0.1);
}

/* Base layout */
body.has-sidebar {
    background-color: #f8f9fa;
}

.main-wrapper {
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

body.has-sidebar .main-wrapper {
    margin-left: var(--sidebar-width);
}

body.has-sidebar.sidebar-collapsed .main-wrapper,
body.has-sidebar:has(#sidebar.collapsed) .main-wrapper {
    margin-left: var(--sidebar-collapsed-width);
}

/* =====================================================
   Sidebar Navigation (use #sidebar to avoid conflicts)
   ===================================================== */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: width 0.3s ease;
    overflow: hidden;
}

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

/* Sidebar Header */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--sidebar-border);
    min-height: 64px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: white;
}

.sidebar-logo {
    height: 24px;
    width: auto;
}

.sidebar-logo-collapsed {
    display: none;
    height: 28px;
    width: auto;
}

#sidebar.collapsed .sidebar-logo {
    display: none;
}

#sidebar.collapsed .sidebar-logo-collapsed {
    display: block;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--sidebar-text);
    padding: 8px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

#sidebar.collapsed .sidebar-toggle {
    transform: rotate(180deg);
}

#sidebar.collapsed .sidebar-toggle {
    position: absolute;
    right: 10px;
}

/* Search trigger */
.sidebar-search-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 12px 12px 8px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--sidebar-border);
    border-radius: 8px;
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    text-align: left;
    width: calc(100% - 24px);
}

.sidebar-search-trigger:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
}

.sidebar-search-text {
    flex: 1;
}

.sidebar-kbd {
    display: flex;
    gap: 2px;
}

.kbd-key {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-family: system-ui, -apple-system, sans-serif;
}

#sidebar.collapsed .sidebar-search-trigger {
    padding: 10px;
    justify-content: center;
}

#sidebar.collapsed .sidebar-search-text,
#sidebar.collapsed .sidebar-kbd {
    display: none;
}

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

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

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

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

/* Sidebar Links */
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--sidebar-text-hover);
}

.sidebar-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    border-left-color: var(--centara-primary);
}

.sidebar-link i {
    width: 20px;
    text-align: center;
    font-size: 16px;
    flex-shrink: 0;
}

#sidebar.collapsed .sidebar-link {
    padding: 12px;
    justify-content: center;
}

#sidebar.collapsed .sidebar-link span {
    display: none;
}

/* Sidebar Groups */
.sidebar-group {
    margin: 4px 0;
}

.sidebar-group-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    border-left: 3px solid transparent;
}

.sidebar-group-toggle:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--sidebar-text-hover);
}

.sidebar-group-toggle.open {
    color: var(--sidebar-text-hover);
}

.sidebar-group-toggle i:first-child {
    width: 20px;
    text-align: center;
    font-size: 16px;
    flex-shrink: 0;
}

.sidebar-group-toggle span {
    flex: 1;
}

.sidebar-group-arrow {
    font-size: 10px;
    transition: transform 0.2s;
}

.sidebar-group-toggle.open .sidebar-group-arrow {
    transform: rotate(180deg);
}

#sidebar.collapsed .sidebar-group-toggle {
    padding: 12px;
    justify-content: center;
}

#sidebar.collapsed .sidebar-group-toggle span,
#sidebar.collapsed .sidebar-group-arrow {
    display: none;
}

/* Group Content */
.sidebar-group-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: var(--sidebar-group-bg);
}

.sidebar-group-content.open {
    max-height: 600px;
}

#sidebar.collapsed .sidebar-group-content {
    display: none;
}

.sidebar-sublink {
    display: block;
    padding: 8px 16px 8px 48px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13px;
    transition: all 0.15s;
}

.sidebar-sublink:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--sidebar-text-hover);
}

.sidebar-sublink.active {
    color: var(--sidebar-active-text);
    background: var(--sidebar-active-bg);
}

.sidebar-divider {
    height: 1px;
    background: var(--sidebar-border);
    margin: 6px 16px 6px 48px;
}

/* Admin Link */
.sidebar-admin-link {
    margin-top: auto;
    border-top: 1px solid var(--sidebar-border);
}

/* Sidebar Footer / User */
.sidebar-footer {
    border-top: 1px solid var(--sidebar-border);
    padding: 12px;
}

.sidebar-version {
    text-align: center;
    margin-bottom: 8px;
}

.sidebar-version-label {
    font-size: 10px;
    color: var(--sidebar-text);
    opacity: 0.4;
    letter-spacing: 0.05em;
}

#sidebar.collapsed .sidebar-version-label {
    display: none;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 500;
    color: white;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-menu {
    display: flex;
    gap: 4px;
}

.sidebar-user-menu a {
    padding: 6px 8px;
    color: var(--sidebar-text);
    border-radius: 6px;
    transition: all 0.15s;
}

.sidebar-user-menu a:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

#sidebar.collapsed .sidebar-user-info,
#sidebar.collapsed .sidebar-user-menu {
    display: none;
}

#sidebar.collapsed .sidebar-user {
    justify-content: center;
}

/* =====================================================
   Top Bar
   ===================================================== */
.top-bar {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: white;
    border-bottom: 1px solid #e5e7eb;
    height: var(--top-bar-height);
}

body.has-sidebar .top-bar {
    display: flex;
}

.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    color: #374151;
    padding: 8px;
    cursor: pointer;
}

.top-bar-spacer {
    flex: 1;
}

.top-bar-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    color: #6b7280;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
}

.top-bar-search:hover {
    background: #e5e7eb;
    border-color: #d1d5db;
}

.top-bar-search kbd {
    background: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    border: 1px solid #e5e7eb;
}

/* =====================================================
   Command Palette
   ===================================================== */
.command-palette-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
}

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

.command-palette {
    position: fixed;
    top: 15%;
    left: 50%;
    transform: translateX(-50%) scale(0.95);
    width: 90%;
    max-width: 600px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
    overflow: hidden;
}

.command-palette.active {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) scale(1);
}

.command-palette-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
}

.command-palette-icon {
    color: #9ca3af;
    font-size: 18px;
}

.command-palette-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 16px;
    background: transparent;
}

.command-palette-input::placeholder {
    color: #9ca3af;
}

.command-palette-esc {
    background: #f3f4f6;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    color: #6b7280;
    border: 1px solid #e5e7eb;
}

.command-palette-results {
    max-height: 400px;
    overflow-y: auto;
    padding: 8px;
}

.command-palette-category {
    padding: 8px 12px 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
}

.command-palette-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: #374151;
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.1s;
}

.command-palette-item:hover,
.command-palette-item.selected {
    background: var(--centara-primary-light);
    color: var(--centara-primary);
}

.command-palette-item i {
    width: 20px;
    text-align: center;
    color: #9ca3af;
}

.command-palette-item:hover i,
.command-palette-item.selected i {
    color: var(--centara-primary);
}

.command-palette-item-title {
    flex: 1;
}

.command-palette-item-title mark {
    background: rgba(223, 32, 118, 0.2);
    color: inherit;
    border-radius: 2px;
    padding: 0 2px;
}

.command-palette-empty {
    padding: 40px 20px;
    text-align: center;
    color: #9ca3af;
}

.command-palette-empty i {
    font-size: 32px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.command-palette-footer {
    display: flex;
    justify-content: center;
    gap: 24px;
    padding: 12px 20px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    font-size: 12px;
    color: #6b7280;
}

.command-palette-footer kbd {
    background: white;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #e5e7eb;
    margin: 0 2px;
}

/* =====================================================
   Responsive
   ===================================================== */
@media (max-width: 1024px) {
    #sidebar {
        width: var(--sidebar-collapsed-width);
    }

    body.has-sidebar .main-wrapper {
        margin-left: var(--sidebar-collapsed-width);
    }

    #sidebar .sidebar-logo {
        display: none;
    }

    #sidebar .sidebar-logo-collapsed {
        display: block;
    }

    #sidebar .sidebar-search-trigger {
        padding: 10px;
        justify-content: center;
    }

    #sidebar .sidebar-search-text,
    #sidebar .sidebar-kbd {
        display: none;
    }

    #sidebar .sidebar-link {
        padding: 12px;
        justify-content: center;
    }

    #sidebar .sidebar-link span {
        display: none;
    }

    #sidebar .sidebar-group-toggle {
        padding: 12px;
        justify-content: center;
    }

    #sidebar .sidebar-group-toggle span,
    #sidebar .sidebar-group-arrow {
        display: none;
    }

    #sidebar .sidebar-group-content {
        display: none;
    }

    #sidebar .sidebar-user-info,
    #sidebar .sidebar-user-menu {
        display: none;
    }

    #sidebar .sidebar-user {
        justify-content: center;
    }

    #sidebar .sidebar-toggle {
        display: none;
    }
}

@media (max-width: 768px) {
    #sidebar {
        width: var(--sidebar-width);
        transform: translateX(-100%);
    }

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

    body.has-sidebar .main-wrapper {
        margin-left: 0;
    }

    .mobile-menu-toggle {
        display: block;
    }

    /* Restore full sidebar on mobile when open */
    #sidebar.mobile-open .sidebar-logo {
        display: block;
    }

    #sidebar.mobile-open .sidebar-logo-collapsed {
        display: none;
    }

    #sidebar.mobile-open .sidebar-search-trigger {
        padding: 10px 12px;
        justify-content: flex-start;
    }

    #sidebar.mobile-open .sidebar-search-text,
    #sidebar.mobile-open .sidebar-kbd {
        display: flex;
    }

    #sidebar.mobile-open .sidebar-link {
        padding: 10px 16px;
        justify-content: flex-start;
    }

    #sidebar.mobile-open .sidebar-link span {
        display: inline;
    }

    #sidebar.mobile-open .sidebar-group-toggle {
        padding: 10px 16px;
        justify-content: flex-start;
    }

    #sidebar.mobile-open .sidebar-group-toggle span,
    #sidebar.mobile-open .sidebar-group-arrow {
        display: inline;
    }

    #sidebar.mobile-open .sidebar-group-content {
        display: block;
    }

    #sidebar.mobile-open .sidebar-user-info,
    #sidebar.mobile-open .sidebar-user-menu {
        display: flex;
    }

    #sidebar.mobile-open .sidebar-user {
        justify-content: flex-start;
    }

    .top-bar-search span {
        display: none;
    }
}

/* =====================================================
   Main Content Area Adjustments
   ===================================================== */
.main-content {
    min-height: calc(100vh - var(--top-bar-height));
}

/* Adjust card and table styles for better fit */
body.has-sidebar .container-fluid {
    max-width: 100%;
    padding-left: 24px;
    padding-right: 24px;
}

/* Ensure content doesn't overflow on smaller screens */
body.has-sidebar .table-responsive {
    overflow-x: auto;
}
