/* --- Sidebar Menu Styles --- */
.page-container {
    display: flex;
}

.sidebar {
    width: 250px;
    background-color: #111827;
    color: white;
    /* No top padding: the band below is the top of the sidebar, and a sticky
       element sticks to the padding edge, so any padding here would leave a
       strip above it for the list to scroll through. Bottom padding is added
       via ::after so it stays inside the scrollable area. */
    padding: 0 1.5rem;
    box-sizing: border-box;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    position: fixed;
    top: 0;
    left: 0;
    transition: transform 0.3s ease-in-out, background-color 0.3s, color 0.3s;
    z-index: 1000;
    /* Start off-screen by default */
    transform: translateX(-100%);
}

/* Spacer inside the scrollable area so the version line (last child) is never
   clipped by Chromium/WebKit's known ignored-bottom-padding behavior, and so
   mobile browser UI (address bar / home indicator) doesn't cover it. */
.sidebar::after {
    content: '';
    display: block;
    height: calc(1.5rem + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
}

/* When the .open class is added by JS, slide the menu in */
.sidebar.open,
html.sidebar-open .sidebar {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.sidebar-title {
    font-size: 1.5rem;
    font-weight: 600;
    white-space: nowrap;
    color: white;
}

/* The toggle carries its own card background at every width: on a scrolled page
   the bare glyph used to sit on whatever passed underneath it. */
.menu-toggle {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-card);
    color: var(--text-main);
    font-size: 1.5rem;
    cursor: pointer;
    position: fixed;
    top: 1.5rem;
    left: 1.5rem; /* Always on the left */
    z-index: 1001;
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: color 0.3s, background-color 0.3s;
}

/* When the sidebar is open, the toggle joins the sidebar's own colours, and the
   action buttons beside it are always painted exactly the same way. */
.sidebar.open + .main-content .menu-toggle,
.sidebar-action {
    color: white;
    background-color: #111827;
    border: 1px solid #374151;
    box-shadow: none;
}

/* They live beside the toggle, outside the sidebar, so they are fixed to the
   viewport exactly as it is: scrolling or overscrolling the list never moves
   them. They exist only while the menu is open. */
.sidebar-actions {
    position: fixed;
    top: 1.5rem;
    left: calc(1.5rem + 48px);
    z-index: 1001;
    display: none;
    align-items: center;
    gap: 0.5rem;
}

.sidebar.open + .main-content .sidebar-actions,
html.sidebar-open .sidebar-actions {
    display: flex;
}

.sidebar-actions form {
    display: inline-flex;
    margin: 0;
    padding: 0;
}

.sidebar-action {
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    line-height: 1;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

.sidebar-action:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: -2px;
}

/* The band the three buttons sit on: its own line, above the list, at every
   width. Sticky so the list scrolls underneath it and never shows through. */
.sidebar::before {
    content: '';
    display: block;
    position: sticky;
    top: 0;
    z-index: 1;
    height: 4rem;
    margin: 0 -1.5rem 0.5rem;
    background: inherit;
}

.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav li a,
.sidebar-nav li button {
    display: block;
    width: 100%;
    color: #d1d5db;
    text-decoration: none;
    padding: 0.75rem 0;
    white-space: nowrap;
    transition: background-color 0.2s, color 0.2s;
    border-radius: 0.375rem;
    padding-left: 0.5rem;
    background: transparent;
    border: none;
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.sidebar-nav li button {
    color: inherit;
}

.sidebar-nav li a:hover,
.sidebar-nav li button:hover {
    color: #ffffff;
    background-color: #374151;
}

.sidebar-nav li a.active {
    color: #FFFFFF;
    font-weight: 600;
    background-color: #2563EB;
}

/* Keyboard focus ring inside the dark sidebar: white reads better than blue,
   and a negative offset keeps it from being clipped by the sidebar's overflow. */
.sidebar-nav li a:focus-visible,
.sidebar-nav li button:focus-visible,
.submenu li a:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: -2px;
}


.main-content {
    /* Default state: full width */
    margin-left: 0;
    width: 100%;
    padding: 4rem 1.5rem 1.5rem;
    transition: margin-left 0.3s ease-in-out;
    box-sizing: border-box; /* Prevents padding from adding to the width and causing overflow */
}

/* When the .sidebar-open class is added by JS, push the content over */
.main-content.sidebar-open,
html.sidebar-open .main-content {
    margin-left: 250px;
}

.sidebar-catcher {
    display: none;
}

@media (max-width: 768px) {
    .sidebar {
        width: min(250px, 85vw);
        padding-top: 0;
        font-size: 1rem;
        line-height: 1.25;
    }

    #sidebar .sidebar-nav li a,
    #sidebar .sidebar-nav li button,
    #sidebar .submenu li a {
        font-size: 1rem;
        line-height: 1.25;
    }

    #sidebar .submenu-arrow {
        font-size: 1.1rem;
    }

    #sidebar .server-selector {
        font-size: 1rem;
        line-height: 1.25;
    }

    #sidebar .donate-button {
        font-size: 0.85rem;
        line-height: 1.25;
    }

    #sidebar .app-version {
        font-size: 0.8rem;
        line-height: 1.25;
    }

    #sidebar .donate-heart,
    #sidebar .github-icon {
        width: 14px;
        height: 14px;
    }

    .sidebar::before {
        content: '';
        display: block;
        position: sticky;
        top: 0;
        z-index: 1;
        height: 4rem;
        margin: 0 -1.5rem;
        background: inherit;
    }

    .sidebar-nav {
        margin-top: 0;
    }

    .main-content {
        padding: 4.25rem 0.75rem 1rem;
    }

    .main-content.sidebar-open,
    html.sidebar-open .main-content {
        margin-left: 0;
    }

    .main-content > .container {
        transition: transform 0.3s ease-in-out;
    }

    html.sidebar-open .main-content > .container {
        transform: translateX(min(250px, 85vw));
    }

    html.sidebar-open,
    html.sidebar-open body {
        overflow: hidden;
    }

    html.sidebar-open .page-container {
        overflow-x: hidden;
        overflow-x: clip;
    }

    html.sidebar-open .sidebar-catcher {
        display: block;
        position: fixed;
        top: 0;
        bottom: 0;
        left: min(250px, 85vw);
        right: 0;
        z-index: 999;
        background-color: rgb(0 0 0 / 0.06);
        touch-action: none;
    }

    .menu-toggle {
        top: 10px;
        left: 0.75rem;
        width: 44px;
        height: 44px;
    }

    .sidebar-actions {
        top: 10px;
        left: calc(0.75rem + 52px);
    }

    .sidebar-action {
        width: 44px;
        height: 44px;
    }
}

@media (max-width: 640px) {
    .main-content {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
    .sidebar,
    .main-content > .container {
        transition: none;
    }
}

/* Dark mode sidebar adjustments */
body.dark-mode .sidebar,
html.dark-mode .sidebar {
    background-color: var(--bg-card);
    color: var(--text-main);
    border-right: 1px solid var(--border-color);
}

body.dark-mode .sidebar-title,
html.dark-mode .sidebar-title {
    color: var(--text-title);
}

body.dark-mode .sidebar-nav li a,
body.dark-mode .sidebar-nav li button,
html.dark-mode .sidebar-nav li a,
html.dark-mode .sidebar-nav li button {
    color: var(--text-sub);
}

body.dark-mode .sidebar-nav li a:hover,
body.dark-mode .sidebar-nav li button:hover,
html.dark-mode .sidebar-nav li a:hover,
html.dark-mode .sidebar-nav li button:hover {
    color: var(--text-title);
    background-color: var(--bg-body);
}

body.dark-mode .sidebar-nav li a.active,
html.dark-mode .sidebar-nav li a.active {
    color: #FFFFFF;
    background-color: var(--color-primary);
}

body.dark-mode .sidebar.open + .main-content .menu-toggle,
html.dark-mode .sidebar.open + .main-content .menu-toggle {
    color: var(--text-main);
    background-color: var(--bg-card);
    border-color: var(--border-color);
}

body.dark-mode .sidebar-action,
html.dark-mode .sidebar-action {
    color: var(--text-main);
    background-color: var(--bg-card);
    border-color: var(--border-color);
}

/* --- Submenu / Accordion --- */
.has-submenu > .submenu-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.submenu-arrow {
    display: inline-block;
    transition: transform 0.25s ease;
    font-size: 1.1rem;
    margin-left: 0.25rem;
}

.has-submenu.open > .submenu-toggle .submenu-arrow {
    transform: rotate(90deg);
}

.submenu {
    list-style: none;
    padding: 0;
    margin: 0 0 0 0.5rem;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    border-left: 2px solid rgba(209, 213, 219, 0.25);
}

.has-submenu.open > .submenu {
    max-height: 400px;
}

.submenu li {
    padding-left: 0.5rem;
}

.submenu li a {
    display: block;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    color: #d1d5db;
    text-decoration: none;
    padding: 0.55rem 0.5rem 0.55rem 0.5rem;
    font-size: 1rem;
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-radius: 0.375rem;
    transition: background-color 0.2s, color 0.2s;
}

.submenu li a:hover {
    color: #ffffff;
    background-color: #374151;
}

.submenu li a.active {
    color: #FFFFFF;
    font-weight: 600;
    background-color: #2563EB;
}

/* Submenu - dark mode */
body.dark-mode .submenu li a,
html.dark-mode .submenu li a {
    color: var(--text-sub);
}

body.dark-mode .submenu li a:hover,
html.dark-mode .submenu li a:hover {
    color: var(--text-title);
    background-color: var(--bg-body);
}

body.dark-mode .submenu li a.active,
html.dark-mode .submenu li a.active {
    color: #FFFFFF;
    background-color: var(--color-primary);
}
