:root {
    --sidebar-width: 260px;
    --sidebar-width-collapsed: 70px;
    --transition-speed: 0.3s;
}

.sidebar {
    position: fixed;
    height: 100vh;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid var(--sidebar-border);
    transition: width var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1),
                background-color 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                border-color 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-x: hidden;
    z-index: 1050;
    display: flex;
    flex-direction: column;
}

.sidebar[data-state="expanded"] .sidebar__brand-text,
.sidebar[data-state="expanded"] .sidebar__text {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0s linear;
}

.sidebar[data-state="collapsed"] .sidebar__brand-text,
.sidebar[data-state="collapsed"] .sidebar__text {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}

/* Sidebar Header */
.sidebar__header {
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 24px;
    border-bottom: 1px solid var(--sidebar-border);
    background: var(--sidebar-header-bg);
    flex-shrink: 0;
    transition: background-color 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                border-color 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 16px;
    text-decoration: none;
    overflow: hidden; /* Prevent text overflow during transition */
}

.sidebar__toggle-btn {
    background: transparent;
    border: 1px solid var(--sidebar-toggle-border);
    color: var(--sidebar-text-muted);
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar__toggle-btn:hover {
    background: var(--sidebar-toggle-hover-bg);
    color: var(--sidebar-text);
    border-color: var(--accent-purple);
    transform: scale(1.1);
    box-shadow: 0 0 15px var(--accent-purple-20);
}

.sidebar__logo {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    filter: drop-shadow(0 0 8px rgba(133, 65, 212, 0.5));
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Logo Hover Animation */
.sidebar__brand:hover .sidebar__logo {
    transform: rotate(15deg) scale(1.1);
    filter: drop-shadow(0 0 12px rgba(133, 65, 212, 0.8));
}

.sidebar__brand-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--sidebar-text);
    white-space: nowrap;
    letter-spacing: 0.5px;
    opacity: 1;
    transition: opacity var(--transition-speed) ease,
                color 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Navigation Menu */
.sidebar__nav {
    padding: 24px 12px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar__menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Divider */
.sidebar__divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--sidebar-border), transparent);
    margin: 16px 0;
    width: 100%;
}

/* Sidebar Footer */
.sidebar__footer {
    padding: 16px 24px;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    justify-content: flex-end;
    background: transparent;
    flex-shrink: 0;
    transition: border-color 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar__item {
    padding: 0;
    margin-bottom: 8px;
}

.sidebar__link {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    color: var(--sidebar-text-muted);
    text-decoration: none;
    border-radius: 12px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                color 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    margin: 0;
    border: 1px solid transparent;
    position: relative;
    overflow: hidden;
}

.sidebar__icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    font-size: 16px;
    flex-shrink: 0;
    transition: all 0.3s ease;
    color: var(--sidebar-text-muted);
    background: var(--sidebar-icon-bg);
    border-radius: 8px;
    border: 1px solid var(--sidebar-icon-border);
}

/* Professional Icon Colors */
.sidebar__icon--coloring { color: #F472B6; } /* Soft Pink */
.sidebar__icon--puzzle { color: #38BDF8; } /* Sky Blue */
.sidebar__icon--mandala { color: #FBBF24; } /* Warm Amber */
.sidebar__icon--mandala-studio { color: #A78BFA; } /* Soft Purple */
.sidebar__icon--pages { color: #10B981; } /* Emerald */
.sidebar__icon--tools { color: #F97316; } /* Orange */
.sidebar__icon--dashboard { color: #34D399; } /* Emerald Green */
.sidebar__icon--settings { color: #94A3B8; } /* Slate Grey */

/* Hover Glow Effects */
.sidebar__link:hover .sidebar__icon--coloring {
    background: rgba(244, 114, 182, 0.15);
    box-shadow: 0 0 12px rgba(244, 114, 182, 0.3);
    border-color: rgba(244, 114, 182, 0.3);
    color: #FBCFE8;
}

.sidebar__link:hover .sidebar__icon--puzzle {
    background: rgba(56, 189, 248, 0.15);
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.3);
    border-color: rgba(56, 189, 248, 0.3);
    color: #BAE6FD;
}

.sidebar__link:hover .sidebar__icon--mandala {
    background: rgba(251, 191, 36, 0.15);
    box-shadow: 0 0 12px rgba(251, 191, 36, 0.3);
    border-color: rgba(251, 191, 36, 0.3);
    color: #FDE68A;
}

.sidebar__link:hover .sidebar__icon--mandala-studio {
    background: rgba(167, 139, 250, 0.15);
    box-shadow: 0 0 12px rgba(167, 139, 250, 0.3);
    border-color: rgba(167, 139, 250, 0.3);
    color: #DDD6FE;
    animation: pulse-purple 2s infinite;
}

.sidebar__link:hover .sidebar__icon--pages {
    background: rgba(16, 185, 129, 0.15);
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.3);
    border-color: rgba(16, 185, 129, 0.3);
    color: #6EE7B7;
}

.sidebar__link:hover .sidebar__icon--tools {
    background: rgba(249, 115, 22, 0.15);
    box-shadow: 0 0 12px rgba(249, 115, 22, 0.3);
    border-color: rgba(249, 115, 22, 0.3);
    color: #FDBA74;
}

@keyframes pulse-purple {
    0% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(167, 139, 250, 0); }
    100% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0); }
}

.sidebar__link:hover .sidebar__icon--dashboard {
    background: rgba(52, 211, 153, 0.15);
    box-shadow: 0 0 12px rgba(52, 211, 153, 0.3);
    border-color: rgba(52, 211, 153, 0.3);
    color: #A7F3D0;
}

.sidebar__link:hover .sidebar__icon--settings {
    background: rgba(148, 163, 184, 0.15);
    box-shadow: 0 0 12px rgba(148, 163, 184, 0.3);
    border-color: rgba(148, 163, 184, 0.3);
    color: #E2E8F0;
}

.sidebar__text {
    font-size: 15px;
    font-weight: 500;
    letter-spacing: 0.3px;
    opacity: 1;
    transition: opacity var(--transition-speed) ease;
}

/* Active State */
.sidebar__link--active {
    background: var(--sidebar-item-active-bg);
    color: var(--sidebar-text);
    border: 1px solid var(--sidebar-item-active-border);
    box-shadow: 0 0 20px var(--accent-purple-10);
}

.sidebar__link--active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 60%;
    width: 3px;
    background: #A78BFA; /* Soft Purple Accent */
    border-radius: 0 4px 4px 0;
    box-shadow: 0 0 12px rgba(167, 139, 250, 0.5);
}

.sidebar__link--active .sidebar__icon {
    background: var(--accent-purple-15);
    border-color: var(--sidebar-border);
    transform: scale(1.05);
    box-shadow: none;
}

/* Ensure icons retain their specific colors and glow when active */
.sidebar__link--active .sidebar__icon--coloring { color: #F472B6; filter: drop-shadow(0 0 6px rgba(244, 114, 182, 0.5)); }
.sidebar__link--active .sidebar__icon--puzzle { color: #38BDF8; filter: drop-shadow(0 0 6px rgba(56, 189, 248, 0.5)); }
.sidebar__link--active .sidebar__icon--mandala { color: #FBBF24; filter: drop-shadow(0 0 6px rgba(251, 191, 36, 0.5)); }
.sidebar__link--active .sidebar__icon--mandala-studio { color: #A78BFA; filter: drop-shadow(0 0 6px rgba(167, 139, 250, 0.5)); }
.sidebar__link--active .sidebar__icon--dashboard { color: #34D399; filter: drop-shadow(0 0 6px rgba(52, 211, 153, 0.5)); }
.sidebar__link--active .sidebar__icon--settings { color: #94A3B8; filter: drop-shadow(0 0 6px rgba(148, 163, 184, 0.5)); }

/* Hover States */
.sidebar__link:hover:not(.sidebar__link--active) {
    background: var(--sidebar-item-hover);
    color: var(--sidebar-text);
    border-color: var(--accent-purple-20);
    transform: translateX(4px);
}

.sidebar__link:hover .sidebar__icon {
    transform: scale(1.05);
}

/* Collapsed State */
.sidebar[data-state="collapsed"] {
    width: var(--sidebar-width-collapsed);
}

.sidebar[data-state="collapsed"] .sidebar__toggle-btn i {
    transform: rotate(180deg);
}

.sidebar[data-state="collapsed"] .sidebar__header {
    padding: 0;
    justify-content: center;
}

.sidebar[data-state="collapsed"] .sidebar__brand {
    justify-content: center;
    margin: 0;
    width: 100%;
}

.sidebar[data-state="collapsed"] .sidebar__brand-text {
    display: none;
}

.sidebar[data-state="collapsed"] .sidebar__footer {
    justify-content: center;
    padding: 16px 0;
}

.sidebar[data-state="collapsed"] .sidebar__link {
    width: 48px;
    height: 48px;
    padding: 0;
    margin: 0 auto 8px auto;
    justify-content: center;
}

.sidebar[data-state="collapsed"] .sidebar__icon {
    margin: 0;
    width: 100%;
    height: 100%;
    font-size: 22px;
}

.sidebar[data-state="collapsed"] .sidebar__text {
    display: none;
}

/* Tooltip for Collapsed State */
.sidebar[data-state="collapsed"] .sidebar__link:hover .sidebar__text {
    display: block;
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--sidebar-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid var(--sidebar-border);
    box-shadow: var(--shadow-lg);
    white-space: nowrap;
    z-index: 1000;
    color: var(--sidebar-text);
    font-weight: 500;
    font-size: 14px;
    pointer-events: none;
    animation: fadeIn 0.2s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-50%) translateX(-5px); }
    to { opacity: 1; transform: translateY(-50%) translateX(0); }
}

/* Expanded State */
.sidebar[data-state="expanded"] {
    width: var(--sidebar-width);
}

/* Mobile Styles */
@media (max-width: 1024px) {
    .desktop-toggle {
        display: none !important;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform var(--transition-speed) ease,
                    background-color 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        width: var(--sidebar-width) !important;
        z-index: 1000;
        background: var(--sidebar-header-bg); /* Use theme variable */
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar[data-state="collapsed"],
    .sidebar[data-state="expanded"] {
        width: var(--sidebar-width) !important;
    }

    .sidebar[data-state="collapsed"] .sidebar__brand-text,
    .sidebar[data-state="collapsed"] .sidebar__text {
        opacity: 1;
        visibility: visible;
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
        z-index: 999;
        opacity: 0;
        transition: opacity var(--transition-speed) ease;
    }

    .sidebar-backdrop.show {
        display: block;
        opacity: 1;
    }
    
    /* Mobile Sidebar Toggle FAB */
    .mobile-sidebar-fab {
        display: flex !important;
    }
}

/* Mobile Sidebar FAB Button */
.mobile-sidebar-fab {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 56px;
    height: 56px;
    background: var(--gradient-primary, linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%));
    border: none;
    border-radius: 50%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    z-index: 998;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 24px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-sidebar-fab:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 25px rgba(139, 92, 246, 0.5);
}

.mobile-sidebar-fab:active {
    transform: scale(0.95);
}

/* Scrollbar Styling */
.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}

.sidebar:hover::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb-hover);
}
