#sidebar-container {
    z-index: 2;
    overflow: visible;
    padding: 0;
    margin: 0;
}

#sidebar {
    background: var(--llight-grey);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: var(--p1);
}

#sidebar-body {
    display: flex;
    flex-direction: column;
    gap: var(--p2);

    width: 100%;
    max-height: 100%;
    overflow-y: auto; /* Enable vertical scrolling */
    overflow-x: hidden; /* Prevent horizontal scrolling */
}

#sidebar-header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: var(--p1);

    display: grid;
    grid-template-columns: 2rem auto 2rem;
    align-items: center;
}

#sidebar-header div {
    width: 100%;
}

#sidebar-header > div:last-child {
    text-align: right;
    float: right;
}

#sidebar-header #sidebar-title {
    grid-column: 2;

    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: bold;
    text-align: center;

    display: unset;
    height: calc(var(--icon) * 4);
    padding: var(--p-half) var(--p1) var(--p-half) var(--p1);
    border-radius: var(--border-radius);
}

#sidebar-header img {
    width: calc(var(--icon) * 4);
}

/* Sidebar Toggle Button */
.sidebar-btn {
    --font-size: 1.5rem;
    --sidebar-padding: 0px;
    --icon-padding: var(--p1);
    --border-size: 1px;
    --top-bar-height: calc(40.5px + var(--p1));

    position: absolute;
    top: calc(var(--top-bar-height) + var(--p1));
    right: calc(
        1px - var(--font-size) - (var(--icon-padding) * 2) +
            var(--sidebar-padding)
    );

    padding: var(--p1);
    clip-path: inset(
        -4px -4px -4px calc(var(--border-size) * 2)
    ); /* Clip the shadow on the left edge */

    font-size: var(--font-size);
    background-color: var(--white);
    border-radius: 0 var(--border-radius) var(--border-radius) 0;
    box-shadow: var(--shadow);
    border: var(--shadow-border);
}

#sidebar-container:not(.open) .sidebar-btn {
    /* right: calc(0px - var(--font-size) - (var(--icon-padding) * 2)); */
    /* left: 0;
    right: unset; */
}

/* Drawer Handle */
#sidebar-handle {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    height: var(--p2);
}

.grip {
    grid-column: 2;
    width: 5rem;
    height: var(--p-half);
    background: #ccc;
    border-radius: 2.5px;
    margin: 8px auto;
    cursor: pointer;
}

/* Desktop Sidebar */
@media (min-width: 769px) {
    #sidebar-container {
        position: absolute;
        top: 0;
        left: 0;
        max-width: var(--sidebar-desktop-width);
        max-height: 100%;
        width: 100%;
        height: 100%;
        
        transition: transform 0.3s ease-in-out;
        transform: translateX(-100%);
    }

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

    #sidebar {
        margin-left: var(--p1);
        margin-top: var(--p1);
        margin-bottom: var(--p1);
        max-height: calc(100vh - var(--p1) * 2);

        display: flex;
        flex-direction: column;
        padding: 0;
        height: 100%;
    }

    #sidebar-body {
        --header-height: calc(27.5px + var(--p1) * 2 + var(--p1));
        max-height: calc(100vh - var(--p1) * 2 - var(--header-height));
    }

    #sidebar.open {
        display: block;
    }

    #sidebar:not(.open) {
        /* display: none; */
    }

    #sidebar-handle {
        display: none !important;
    }
}

/* Mobile Drawer */
@media (max-width: 768px) {
    #sidebar-container {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 60vh;
        border-radius: var(--border-radius) var(--border-radius) 0 0;
        transition: transform 0.3s ease-in-out;
    }

    #sidebar {
        /* Let .mobile-drawer and JS control height/transform */
    }

    #sidebar-body {
        max-height: calc(100vh - var(--p1) * 2);
    }

    .sidebar-btn {
        display: none;
    }

    #sidebar-header #sidebar-title {
        /* width: 400%; */
    }

    #sidebar-header img {
        width: calc(var(--icon) * 3.5);
    }
}

.sidebar-card-separator {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: var(--p1);
}

/* .sidebar-content-container {
    max-height: calc(80vh);
} */

/* ==========	Footer	========== */
.sidebar-footer {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: var(--p1);
    margin-top: auto;
    margin-bottom: var(--p1);
}

.sidebar-footer > button {
    font-size: 1.1rem;
    display:flex;
    align-items: center;
    justify-content: center;
    width: calc(var(--icon) * 2.5);
    height: calc(var(--icon) * 2.5);
}

@media (min-width: 769px) {
    .sidebar-footer #logout-btn {
        position: absolute;
        bottom: var(--p2);
        left: var(--p2);
    }
}

@media (max-width: 768px) {
    .sidebar-footer {
        margin-bottom: 0;
        padding-top: 0;
    }
}

button.error-wiggle {
    animation: shake 0.82s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
    border-color: var(--red);
}

@keyframes shake {
    10%,
    90% {
        transform: rotate(-2deg);
    }

    20%,
    80% {
        transform: rotate(4deg);
    }

    30%,
    50%,
    70% {
        transform: rotate(-8deg);
    }

    40%,
    60% {
        transform: rotate(8deg);
    }
}
