/**
 * Sidebar Navigation Styles
 * Collapsible sidebar with mobile overlay
 */

/* ===================================
   Sidebar Toggle Button
   =================================== */
.sidebar-toggle {
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1100;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    transform: scale(1.05);
}

.sidebar-toggle svg {
    width: 24px;
    height: 24px;
    stroke: var(--text-primary);
}

/* ===================================
   Sidebar Container
   =================================== */
.sidebar {
    position: fixed;
    top: 0;
    left: -280px; /* Hidden by default */
    width: 280px;
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    transition: left 0.3s ease;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar.open {
    left: 0;
}

/* ===================================
   Sidebar Header
   =================================== */
.sidebar-header {
    padding: 1.5rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-brand {
    font-family: monospace;
    font-size: 1.5rem;
    font-weight: bold;
    text-decoration: none;
    transition: opacity 0.3s ease;
}

.sidebar-brand:hover {
    opacity: 0.8;
}

.sidebar-close {
    background: none;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s ease;
}

.sidebar-close:hover {
    color: var(--text-primary);
}

.sidebar-close svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

/* ===================================
   Search Form
   =================================== */
.sidebar-search {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-search form {
    position: relative;
}

.sidebar-search input {
    width: 100%;
    padding: 0.625rem 2.5rem 0.625rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: all 0.3s ease;
}

.sidebar-search input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.sidebar-search .search-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s ease;
}

.sidebar-search .search-btn:hover {
    color: var(--primary);
}

/* ===================================
   User Info
   =================================== */
.sidebar-user {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.125rem;
    flex-shrink: 0;
}

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

.user-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9375rem;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-credits {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.user-credits svg {
    stroke: var(--text-secondary);
    flex-shrink: 0;
}

/* ===================================
   Navigation Links
   =================================== */
.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
    overflow-y: auto;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9375rem;
    transition: all 0.3s ease;
    position: relative;
}

.sidebar-nav .nav-link:hover {
    background: var(--bg-hover);
    color: var(--primary);
}

.sidebar-nav .nav-link svg {
    stroke: currentColor;
    flex-shrink: 0;
}

.sidebar-nav .nav-link-primary {
    background: var(--primary);
    color: white;
    margin: 0.5rem 1rem;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
}

.sidebar-nav .nav-link-primary:hover {
    background: #1d4ed8;
    color: white;
}

.sidebar-nav .nav-link-danger {
    color: #dc2626;
}

.sidebar-nav .nav-link-danger:hover {
    background: rgba(220, 38, 38, 0.1);
    color: #b91c1c;
}

.beta-badge {
    margin-left: auto;
    font-size: 0.625rem;
    font-weight: 600;
    padding: 0.125rem 0.5rem;
    background: rgba(251, 191, 36, 0.2);
    color: #f59e0b;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===================================
   Sidebar Footer
   =================================== */
.sidebar-footer {
    padding: 1rem 0;
    border-top: 1px solid var(--border-color);
    /* Add padding for mobile Safari bottom bar */
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
}

/* Profile link in footer - matches theme toggle and logout styling */
.sidebar-footer-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    width: 100%;
    background: none;
    border: none;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9375rem;
    transition: all 0.3s ease;
}

.sidebar-footer-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-footer-link svg {
    stroke: currentColor;
    flex-shrink: 0;
}

.theme-toggle-sidebar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    width: 100%;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.9375rem;
    transition: all 0.3s ease;
    text-align: left;
}

.theme-toggle-sidebar:hover {
    background: var(--bg-hover);
}

.theme-toggle-sidebar .theme-icon {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    flex-shrink: 0;
}

.theme-toggle-sidebar .sun-icon {
    display: none;
}

.theme-toggle-sidebar .moon-icon {
    display: inline-block;
}

[data-theme="dark"] .theme-toggle-sidebar .sun-icon {
    display: inline-block;
}

[data-theme="dark"] .theme-toggle-sidebar .moon-icon {
    display: none;
}

.logout-form {
    margin: 0;
}

.logout-form button {
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* ===================================
   Sidebar Overlay (Mobile)
   =================================== */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1150;
}

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

/* ===================================
   Main Content Wrapper
   =================================== */
.main-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
}

/* Desktop: Sidebar always visible */
@media (min-width: 1024px) {
    .sidebar-toggle {
        display: none;
    }

    .sidebar {
        left: 0;
    }

    .sidebar-close {
        display: none;
    }

    .sidebar-overlay {
        display: none;
    }

    .main-wrapper {
        margin-left: 280px;
    }
}

/* Tablet and below: Sidebar hidden by default */
@media (max-width: 1023px) {
    body.sidebar-open {
        overflow: hidden;
    }
}

/* Mobile: Smaller sidebar */
@media (max-width: 640px) {
    .sidebar {
        width: 260px;
        left: -260px;
    }
}

/* Scrollbar Styling for Sidebar */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ===================================
   Search Placeholder Fix for Dark Mode
   =================================== */
.sidebar-search input::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

[data-theme="dark"] .sidebar-search input::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

/* ===================================
   Credit Badge on Nav Link
   =================================== */
.credit-badge {
    margin-left: auto;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.125rem 0.5rem;
    background: var(--primary);
    color: white;
    border-radius: 9999px;
}
