/*
 * Although Doxygen supports resizable sidebars, the doxygen-awesome theme intentionally
 * locks the left sidebar to a fixed width. This with fsp_doxygen_overrides.js implements
 * resizable sidebar support.
 *
 * Note: This file expects the doxygen-awesome theme to be used and the doxygen page outline to be enabled.
 */

:root {
    /* Note: fsp_doxygen_overrides.js expects these variables to be in units of px. */

    /* Min width of left navigation sidebar */
    --side-nav-fixed-width: 300px; /* Doxygen-awesome provided variable: Initial width of left sidebar. */
    --fsp-side-nav-min-width: var(--side-nav-fixed-width);

    /* Min width for document content (so that neither sidebar can completely obscure the content) */
    --fsp-content-min-width: 320px;

    /* Default width of the sidebars. Side nav is the left sidebar, page nav is the right sidebar.*/
    --fsp-side-nav-width: var(--fsp-side-nav-min-width);
    --fsp-page-nav-width: 280px;
}

@media screen and (min-width: 768px) {
    /* Note: JavaScript enforces/controls the width limits, so don't use css to set the
     * sidebar widths here since it will conflict with the logic in fsp_doxygen_overrides.js. */
    #side-nav {
        box-sizing: border-box;
        width: var(--fsp-side-nav-width) !important;
        min-width: 0;
        max-width: none;
        padding-right: 0 !important;
    }

    /* Keep logo/search (#top) aligned with the left sidebar. */
    #top {
        box-sizing: border-box;
        width: calc(var(--fsp-side-nav-width) + 1px);
        min-width: 0;
        max-width: none;
    }

    /* Shift content's left edge in sync with the resizable sidebar.
     * doxygen-awesome-sidebar-only.css sets --side-nav-fixed-width !important;
     * which normally would lock the sidebar width. Here we override that
     * with the runtime width.  */
    #doc-content {
        margin-left: var(--fsp-side-nav-width) !important;
    }

    /* Workaround for https://github.com/doxygen/doxygen/issues/11587
     * navtree.js calls constrainPanelWidths() on every resize and left-drag
     * event and uses it to set both panel widths. At non-100% zoom the
     * calculation is off by fractional pixels and silently shrinks the right
     * panel every time the left one moves. This is fixed in Doxygen 1.15+.
     * To workaround we we lock the right grid column and the #page-nav width to CSS
     * variables with !important. This makes navtree.js's .css() calls become no-ops.
     */
    #container {
        grid-template-columns: auto var(--fsp-page-nav-width) !important;
    }

    #page-nav {
        position: relative;
        z-index: 2;
        width: auto !important;
        min-width: 0;
        /* Keep the handle visible when the panel is closed (0 width) so it can be reopened */
        overflow: visible !important;
    }

    /* Keep the left resize handle attached to the sidebar */
    #side-nav .ui-resizable-handle.ui-resizable-e,
    #side-nav #splitbar {
        position: absolute;
        display: block;
        width: 6px;
        border-left: 1px solid var(--separator-color);
        background: var(--page-background-color);
        cursor: ew-resize;
        touch-action: none; /* Prevent touch scrolling while resizing */
        user-select: none; /* Prevent text selection while resizing */
    }

    /* Keep the right-panel resize handle visible and aligned with the panel edge. */
    #page-nav #page-nav-resize-handle {
        position: absolute;
        left: -7px;
        right: auto;
        top: 0;
        bottom: 0;
        width: 7px;
        box-sizing: border-box;
        background: transparent;
        cursor: ew-resize;
        opacity: 1;
        touch-action: none; /* Prevent touch scrolling while resizing */
        user-select: none; /* Prevent text selection while resizing */
    }

    /* Offset the TOC so its content does not sit underneath the resize handle. */
    #page-nav #page-nav-contents {
        left: 7px;
        right: var(--spacing-small);
        width: auto;
        box-sizing: border-box;
    }

    body.resizing,
    body.resizing * {
        cursor: ew-resize !important;
        user-select: none !important;
    }

    /*
     * Preserve the existing 1px alignment corrections.
     * Their cause should be checked against the generated page's borders.
     */
    #nav-path {
        left: calc(var(--fsp-side-nav-width) + 1px);
    }

    /* Hide Doxygen's panel-sync toggle because custom resize handles replace it. */
    #nav-sync {
        display: none;
    }
    /* Resize the Doxygen search controls with the sidebar. */
    #MSearchBox {
        width: calc(
            var(--fsp-side-nav-width)
            - (2 * var(--spacing-medium))
            - var(--searchbar-height)
            - 1px
        ) !important;
    }

    #MSearchField {
        width: calc(
            var(--fsp-side-nav-width)
            - (2 * var(--spacing-medium))
            - var(--searchbar-height)
            - 66px
        ) !important;
    }
}
