/*********************************************
* Variables *
*********************************************/
// Breakpoints from Bootstrap: https://getbootstrap.com/docs/4.1/layout/overview/#responsive-breakpoints
$breakpoint-xl: 1200px;
$breakpoint-lg: 992px;
$breakpoint-md: 768px;
$breakpoint-sm: 576px;

// Colors
$non-content-grey: #5a5a5a;

/*********************************************
* Whole page *
*********************************************/

$topbar-height: 3em;

body {
    padding-top: 0px !important;
    img {
        max-width: 100%;
    }
}

code {
    font-size: 87.5% !important;
}

/*********************************************
* Main body *
*********************************************/

main.bd-content {
    padding-top: $topbar-height !important;
    padding-bottom: 0px !important;

    #main-content {
        // Content links and link color
        a.headerlink {
            opacity: 0;
            margin-left: .2em;

            &:hover {
                background-color: transparent;
                color: #0071bc;
                opacity: 1 !important;
            }
        }

        a, a:visited {
            color: #0071bc;
        }

        h1, h2, h3, h4, h5 {
            color: black;
            &:hover a.headerlink {
                opacity: .5;
            }
            // Make sure titles don't become hyperlink color when there are labels
            a.toc-backref {
                color: inherit;
            }
        }

        div.section {
            padding-right: 1em;
            overflow: visible !important;  // So that sidebars don't cause a scroll

            // List styles to avoid too much whitespace
            ul, ol {
                p {
                    margin-bottom: 0;
                }
            }
        }

        // Math equations
        span.eqno {
            float: right;
            font-size: 1.2em;
        }

        // Figures
        div.figure {
            width: 100%;
            margin-bottom: 1em;
            text-align: center;

            &.align-left {
                text-align: left;
                p.caption {
                    margin-left: 0;
                }
            }
            &.align-right {
                text-align: right;
                p.caption {
                    margin-right: 0;
                }
            }

            p.caption {
                margin: .5em 10%;
            }

            &.margin, &.margin-caption {
                p.caption {
                    margin: .5em 0;
                }
            }

            &.margin-caption p.caption {
                text-align: left;
            }

            span.caption-number {
                font-weight: bold;
            }

            span {
                font-size: .9rem;
            }
        }

        // Within-page Table of contents
        div.contents {
            padding: 1em;
            p.topic-title {
                font-size: 1.5em;
                padding: .5em 0 0 1em;
            }
        }

        // Misc text and directives
        p.centered {
            text-align: center;
        }

        // Tables from sphinx-tabs

        div.sphinx-tabs > div.sphinx-menu {
            padding: 0;
        }

        div.sphinx-tabs > div.sphinx-menu > a.item {
            width: auto;
            margin: 0px 0px -1px 0px;
        }

        // Footnotes and Citations
        span.brackets, a.brackets {
            &:before {
                content: "[";
            }

            &:after {
                content: "]";
            }
        }

        .footnote-reference, a.bibtex.internal {
            font-size: 1em;
        }

        // See: https://docutils.sourceforge.io/docs/user/rst/quickref.html#definition-lists
        // TODO the field list should be a different format,
        // but be wary of issues like https://github.com/pandas-dev/pydata-sphinx-theme/issues/193
        dl.simple, dl.field-list {
            & dd {
                margin-left: 1.5em;
            }
            & dd:not(:last-child) {
                margin-bottom: 0px;
                p:last-child {
                    margin-bottom: 0px;
                }
            }
        }

        dl.glossary {
            dd {
                margin-left: 1.5em;
            }
        }

        dl.footnote {

            span.fn-backref {
                font-size: 1em;
                padding-left:.1em;
            }

            dd {
                font-size:.9em;
                margin-left: 3em;
            }
        }

        dl.citation {
            margin-left: 3em;
        }

        dl.footnote {
            dt.label {
                float: left;
            }

            dd p {
                padding-left: 1.5em;
            }
        }

        // auto-doc, see: https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-autoattribute
        // adapted from https://github.com/readthedocs/readthedocs.org/blob/master/readthedocs/core/static/core/css/theme.css
        dl.module, dl.class, dl.exception, dl.function, dl.decorator, dl.data, dl.method, dl.attribute {
            dt {
                .headerlink {
                    &:before {
                        -webkit-font-smoothing: antialiased;
                        font-family: "FontAwesome";
                        display: inline-block;
                        font-style: normal;
                        font-weight: normal;
                        line-height: 1;
                        text-decoration: inherit;
                    }
                    display: inline-block;
                    font: normal normal normal 14px/1 FontAwesome;
                    font-size: inherit;
                    text-rendering: auto;
                    -webkit-font-smoothing: antialiased;
                    -moz-osx-font-smoothing: grayscale;
                    font-family: inherit;
                    visibility: hidden;
                    font-size: 14px;
                    &:after {
                        content: "";
                        font-family: FontAwesome;
                    }
                }
                .fa-pull-left.headerlink {
                    margin-right: .3em;
                }
                .fa-pull-right.headerlink {
                    margin-left: .3em;
                }
                .pull-left.headerlink {
                    margin-right: .3em;
                }
                .pull-right.headerlink {
                    margin-left: .3em;
                }
                a {
                    .headerlink {
                        display: inline-block;
                        text-decoration: inherit;
                    }
                }
                .btn {
                    .headerlink {
                        display: inline;
                    }
                    .fa-large.headerlink {
                        line-height: .9em;
                    }
                    .fa-spin.headerlink {
                        display: inline-block;
                    }
                }
                .nav {
                    .headerlink {
                        display: inline;
                    }
                    .fa-large.headerlink {
                        line-height: .9em;
                    }
                    .fa-spin.headerlink {
                        display: inline-block;
                    }
                }
                .btn.headerlink {
                    &:before {
                        opacity: .5;
                        -webkit-transition: opacity .05s ease-in;
                        -moz-transition: opacity .05s ease-in;
                        transition: opacity .05s ease-in;
                    }
                    &:hover {
                        &:before {
                            opacity: 1;
                        }
                    }
                }
                .btn-mini {
                    .headerlink {
                        &:before {
                            font-size: 14px;
                            vertical-align: -15%;
                        }
                    }
                }
                .rst-versions {
                    .rst-current-version {
                        .headerlink {
                            color: #fcfcfc;
                        }
                    }
                }
                &:hover {
                    .headerlink {
                        &:after {
                            visibility: visible;
                        }
                    }
                }
                font-weight: bold;
            }
            margin-bottom: 24px;
            p {
                margin-bottom: 12px !important;
            }
            table {
                margin-bottom: 12px !important;
            }
            ul {
                margin-bottom: 12px !important;
            }
            ol {
                margin-bottom: 12px !important;
            }
            dd {
                margin: 0 0 12px 24px;
            }
            &:not(.docutils) {
                margin-bottom: 24px;
                dt {
                    display: table;
                    margin: 6px 0;
                    font-size: 90%;
                    line-height: normal;
                    background: #e7f2fa;
                    color: #2980B9;
                    border-top: solid 3px #6ab0de;
                    padding: 6px;
                    position: relative;
                    &:before {
                        color: #6ab0de;
                    }
                    .headerlink {
                        color: #404040;
                        font-size: 100% !important;
                    }
                    &:first-child {
                        margin-top: 0;
                    }
                }
                dl {
                    dt {
                        margin-bottom: 6px;
                        border: none;
                        border-left: solid 3px #ccc;
                        background: #f0f0f0;
                        color: #555;
                        .headerlink {
                            color: #404040;
                            font-size: 100% !important;
                        }
                    }
                }
                tt {
                    font-weight: bold;
                    font-weight: bold;
                }
                code {
                    font-weight: bold;
                }
                tt.descname {
                    background-color: transparent;
                    background-color: transparent;
                    border: none;
                    border: none;
                    padding: 0;
                    padding: 0;
                    font-size: 100% !important;
                    font-size: 100% !important;
                    font-weight: bold;
                    font-weight: bold;
                }
                tt.descclassname {
                    background-color: transparent;
                    background-color: transparent;
                    border: none;
                    border: none;
                    padding: 0;
                    padding: 0;
                    font-size: 100% !important;
                    font-size: 100% !important;
                }
                code.descname {
                    background-color: transparent;
                    border: none;
                    padding: 0;
                    font-size: 100% !important;
                    font-weight: bold;
                }
                code.descclassname {
                    background-color: transparent;
                    border: none;
                    padding: 0;
                    font-size: 100% !important;
                }
                .optional {
                    display: inline-block;
                    padding: 0 4px;
                    color: #000;
                    font-weight: bold;
                }
                .property {
                    display: inline-block;
                    padding-right: 8px;
                }
            }
            .viewcode-link {
                display: inline-block;
                color: #27AE60;
                font-size: 80%;
                padding-left: 24px;
            }
        }
    }
}

// Cell-specific controls
div.cell {

    div.cell_output {
        padding-right: 0;
    }

    &.tag_output_scroll {
        div.cell_output {
            max-height: 24em;
            overflow-y: auto;
        }
    }
}

// Extension over-rides
// Toggle-button overrides
.toggle.admonition button.toggle-button {
    top: 0.5em !important;
}

button.toggle-button-hidden:before {
    bottom: 0.2em !important;
}

// Margin and content-sidebar rules
// Need to add a few specifics for `tag_` because these won't have a parent `.sidebar` class
div.sidebar, div.margin, div.margin-caption p.caption, .cell.tag_popout, .cell.tag_margin {
    width: 40%;
    float: right;
    border-left: 1px #a4a6a7 solid;
    margin-left: 0.5em;
    padding: .2em 0 .2em 1em;

    p {
        margin-bottom: 0;
    }

    p.sidebar-title {
        font-weight: bold;
        font-size: 1.2em;
    }
}


// Right margin CSS, largely copied from https://edwardtufte.github.io/tufte-css/
// 992px is the L breakpoint in bootstrap
@media (min-width: $breakpoint-md) {
    div.cell.tag_popout, div.cell.tag_margin, div.margin, div.margin-caption p.caption {
        border: none;
        clear: right;
        width: 31% !important;
        margin: 0 -35% 0 0 !important;
        padding: 0 !important;
        font-size: 0.9rem;
        line-height: 1.3;
        vertical-align: baseline;
        position: relative;

        p {
            margin-bottom: .5em;

            &.sidebar-title {
                font-size: 1em;
            }
        }


    }

    // Make cell outputs take up more space if they're in the margin
    div.cell.tag_margin .cell_output {
        padding-left: 0;
    }

    div.sidebar:not(.margin) {
        width: 60%;
        margin-left: 1.5em;
        margin-right: -28%;
    }

}


@media (min-width: $breakpoint-md) {
    div.cell.tag_full-width, div.cell.tag_full_width, div.full_width, div.full-width {
        width: 136% !important;
    }
}

blockquote {
    margin: 1em;
    padding: .2em 1.5em;
    border-left: 4px solid #ccc;

    &.pull-quote, &.epigraph, &.highlights {
        font-size:1.25em;
        border-left: none;
    }

    div > p {
        margin-bottom: .5em;
    }

    div > p + p.attribution {
        font-style: normal;
        font-size: .9em;
        text-align: right;
        color: #6c757d;
        padding-right: 2em;
    }
}

// Code cells have background at the `pre` level so remove from here
div.highlight {
    background: none;
}

// Thebelab over-rides
.thebelab-cell {
    border: none !important;
}

button.thebe-launch-button {
    height: 2.5em;
    font-size: 1em;
}

// toc directive styles
div.tableofcontents-wrapper p.caption {
    font-weight: 600 !important;
    margin-bottom: 0em !important;
}

/*********************************************
* Top Bar *
*********************************************/
.topbar {
    margin: 0em auto 1em auto !important;
    padding-top: .25em;
    padding-bottom: .25em;
    background-color: white;
    height: $topbar-height;
    transition: left .2s;

    > div {
        height: 2.5em;
        top: 0px;
    }

    .topbar-main {
        > button, > div, > a {
            float: left;
            height: 100%;
        }

        button.topbarbtn {
            margin: 0 .1em;
            background-color: white;
            color: $non-content-grey;
            border: none;
            padding-top: .1rem;
            padding-bottom: .1rem;
            font-size: 1.4em;

            i.fab {
                vertical-align: baseline;
                line-height: 1;
            }
        }

        // buttons float right
        div.dropdown-buttons-trigger, a.edit-button, a.full-screen-button {
            float: right;
        }
    }
}

.bd-topbar-whitespace {
    padding-right: none;
    @media (max-width: 768px) {
        display: none;
    }
}

// Download buttons
span.topbar-button-text {
    margin-left: 0.4em;

    @media (max-width: $breakpoint-md) {
        display: none;
    }
}

div.dropdown-buttons-trigger {

    div.dropdown-buttons {
        display: none;
        position: absolute;
        max-width: 130px;
        margin-top: .2em;
        z-index: 1000;

        &.sourcebuttons .topbarbtn i {
            padding-right: 6px;
            margin-left: -5px;
            font-size: .9em !important;
        }

        button.topbarbtn {
            padding-top: .35rem;
            padding-bottom: .35rem;
            min-width: 120px !important;
            border: 1px white solid !important;
            background-color: $non-content-grey;
            color: white;
            font-size: 1em;
        }
    }

    &:hover div.dropdown-buttons {
        display: block;
    }
}

a.dropdown-buttons i {
    margin-right: .5em;
}

button.topbarbtn img {
    height: 1.15em;
    padding-right: 6px;
    margin-left: -5px;
}

#navbar-toggler {
    position: relative;
    margin-right: 1em;
    margin-left: .5em;
    color: $non-content-grey;

    i {
        transition: opacity .3s, transform .3s;
        position: absolute;
        top: 16%;
        left: 0;
        display: block;
        font-size: 1.2em;
    }

    i.fa-bars {
        opacity: 0;
        transform: rotate(180deg) scale(.5);
    }

    i.fa-arrow-left, i.fa-arrow-up {
        opacity: 1;
    }

    &.collapsed {
        i.fa-bars {
            opacity: 1;
            transform: rotate(0) scale(1);
        }

        i.fa-arrow-left, i.fa-arrow-up {
            opacity: 0;
            transform: rotate(-180deg) scale(.5);
        }
    }
}


@media (max-width: $breakpoint-md) {
    #navbar-toggler {
        i.fa-arrow-up {
            display: inherit;
        }

        i.fa-arrow-left {
            display: none;
        }
    }
}

@media (min-width: $breakpoint-md) {
    #navbar-toggler {
        i.fa-arrow-up {
            display: none;
        }

        i.fa-arrow-left {
            display: inherit;
        }
    }
}

/*********************************************
* Table of Contents *
*********************************************/

.bd-toc {
    padding: 0px !important;
    overflow-y: visible;
    background: white;
    right: 0;
    z-index: 999;
    transition: height .35s ease;

    // Colors
    div.onthispage, .toc-entry a {
        color: $non-content-grey;
    }

    // By default the nav is hidden unless a few conditions are met
    nav {
        opacity: 0;
        max-height: 0;
        transition: opacity 0.2s ease, max-height .7s ease;
        overflow-y: hidden;
        background: white;

        // TOC link color
        a:hover, li.active > a.active {
            color: #0071bc;
        }

        li.active > a.active {
            border-left: 2px solid #0071bc;
        }
    }

    // On hover or w/ a show class, we show the TOC
    &:hover, &.show {
        nav {
            max-height: 100vh;
            opacity: 1;
        }

        // Hide the arrow when we display the toc
        .tocsection:after {
            opacity: 0;
        }
    }

    .tocsection {
        padding: .5rem 0 .5rem 1rem !important;

        &:after {
            content: "\f107";
            font-family: "Font Awesome 5 Free";
            font-weight: 900;
            padding-left: .5em;
            transition: opacity .3s ease;
        }
    }

    .toc-entry a {
        padding: .125rem 1rem !important;
    }

    // Make sure the pydata sphinx theme edit button doesn't show up
    div.editthispage {
        display: none;
    }
}

/*********************************************
* Left Nav Bar *
*********************************************/
.bd-sidebar  {
    top: 0px !important;
    overflow-y: auto;
    height: 100vh !important;

    // Sidebar link color
    nav ul.nav {
        li a, ul li a {
            color: $non-content-grey;
        }
        a:hover, li.active > a, li.active > a:hover {
            color: #0071bc;
        }
    }

    scrollbar-width: thin;
    &::-webkit-scrollbar {
        width: 5px;
    }

    &::-webkit-scrollbar {
        background: #f1f1f1;
    }

    &::-webkit-scrollbar-thumb {
        background: #c1c1c1;
    }

    // Hide the scrollbar until hover on wide screens
    @media (min-width: $breakpoint-lg) {
        &:not(:hover) {
            -ms-overflow-style: none;

            &::-webkit-scrollbar {
              background: #FFFFFF;
            }

            &::-webkit-scrollbar-thumb {
              background: #FFFFFF;
            }
        }
    }

    h1.site-logo {
        margin: .5em 0 0 0;
        font-size: 1.1em;
        color: black;
        text-align: center;
    }

    div.navbar_extra_footer {
        text-align: center;
        font-size: .9em;
        color: $non-content-grey;
        margin-bottom: 3em;
    }

    &.collapsing {
        border: none;
        overflow: hidden;
        position: relative;
        padding-top: 0;
    }

    // Captions
    p.caption {
        margin-top: 1.25em;
        margin-bottom: 0;
        font-size: 1.2em;
    }

    // External links
    li > a > i {
        font-size: .8em;
        margin-left: 0.3em;
    }
}

.toc-h1, .toc-h2, .toc-h3, .toc-h4 {
    > a {
        font-size: 0.9em;
    }
    font-size: 1em;
}

.site-navigation, .site-navigation.collapsing {
    transition: flex .2s ease 0s, height .35s ease, opacity 0.2s ease;
}

#site-navigation {
    @media (max-width: $breakpoint-md) {
        position: fixed;
        margin-top: $topbar-height;
        z-index: 2000;
        background: white;
    }
}

@media (max-width: $breakpoint-md) {

    .bd-sidebar {
        height: 60vh !important;
        border-bottom: 3px solid #c3c3c3;

        &.collapsing {
            height: 0px !important;
        }

        // If we're only a single page, sidebar should hide at narrow widths.
        &.single-page {
            display: none;
        }
    }
}

@media (min-width: $breakpoint-md) {
    .bd-sidebar {
        z-index: 2000 !important;
    }

    .site-navigation.collapsing {
        flex: 0 0 0px;
        padding: 0;
    }
}


div.navbar-brand-box {
    @media (min-width: $breakpoint-md) {
        padding-top: 2em;
    }

    a.navbar-brand {
        width: 100%;
        height: auto;

        img {
            display: block;
            height: auto;
            width: auto;
            max-height:10vh;
            max-width: 100%;
            margin: 0 auto;
            @media (min-width: $breakpoint-md) {
                max-height: 15vh !important;
            }
        }
    }
}

nav.bd-links {
    margin-left: 0px;
    max-height: none !important;

    p.caption {
        font-size: 0.9em;
        text-transform: uppercase;
        font-weight: bold;

        &:first-child {
            margin-top: 0;
        }
    }

    ul {
        list-style: none;
    }

    li {
        width: 100%;
    }

    li.toctree-l1, li.toctree-l2, li.toctree-l3, li.toctree-l4, li.toctree-l5  {
        > a {
            font-size: 0.9em;
        }
        font-size: 1em;
    }

    > ul.nav {
        // Make sure the first items don't have any padding
        padding-left: 0;

        // Subsequent items should have padding
        ul {
            // Only left padding
            padding: 0 0 0 1rem;
        }

        // Links don't have the horizontal padding, uls do
        a {
            padding: .25rem 0 !important;
        }
    }
}

// Navbar and topbar sidebar padding should max at 300px
@media (min-width: $breakpoint-md) {
    .bd-sidebar, .bd-topbar-whitespace {
        max-width: 275px;
    }
}


/*********************************************
* Footer *
*********************************************/
.prev-next-bottom {
    height: 3em;
}

@import 'print';
