@use 'sass:color';

@use 'variables' as v;
@use 'variables-dark' as v_darktheme;

@mixin menu_vertical_current_hover_dark_mode_colors {
    &:hover {
        background-color: #777777;
        color: darkorange;
    }
}

@mixin menu_vertical_current_dark_mode_colors {
    @include menu_vertical_current_hover_dark_mode_colors;
    & {
        color: v_darktheme.$color-menu-font;
    }


    &:visited {
        color: v_darktheme.$color-menu-font;
        @include menu_vertical_current_hover_dark_mode_colors;
    }
}

@mixin menu_vertical_alt_current_hover_dark_mode_colors {
    color: v_darktheme.$color-menu-alt-font;
    &:hover {
        color: v_darktheme.$color-menu-alt-font-hover;
    }
}

@media (prefers-color-scheme: dark) {

    html {
        background-color: v_darktheme.$color-bg-dark !important;
    }
    body {
        background-color: v_darktheme.$color-bg-dark !important;
    }
    img {
        &.dark-mode-invert-image {
            -webkit-filter: invert(0.9);
            filter: invert(0.9);
        }
        &.dark-mode-light-background {
            background-color: lightgrey !important;
        }
    }
    label {
        color: white;
    }
    .rst-content code,
    .rst-content tt,
    code {
        color: v_darktheme.$color-code-font;
        background-color: v_darktheme.$color-code-bg !important;
        border: 1px solid v_darktheme.$color-code-border;
    }
    pre {
        color: v_darktheme.$color-code-font;
        background-color: v_darktheme.$color-code-bg !important;
        border: 1px solid v_darktheme.$color-code-border;
    }
    .btn {
        background-color: v_darktheme.$color-theme-bg-dark;
        color: #fff;

        &:hover {
            background-color: color.scale(v_darktheme.$color-theme-bg-dark, $lightness: 10%);
        }
    }

    .btn-neutral {
        background-color: #b3b6b6 !important;
        color: #404040 !important;
    }

    .wy-nav-content-wrap {
        background: v_darktheme.$color-bg-dark !important;
    }
    .wy-nav-content {
        background: v_darktheme.$color-content-bg !important;
        color: v_darktheme.$color-content-font;
        ::selection {
            // color: #333333;
            // background: lightyellow;

            // background: #002770;
            background: #474747;
        }
    }

    .wy-side-nav-search {
        background-color: v_darktheme.$color-theme-bg-dark;
    }

    .wy-nav-side {
        background-color: color.scale(v_darktheme.$color-menu-bg-l1, $lightness: -10%);
    }

    .wy-menu-vertical {
        li {
            button.toctree-expand {
                color: lightgrey;
            }
            button.toctree-expand:before {
                color: lightgrey;
            }
            ul {
                background-color: v_darktheme.$color-menu-bg-l1;
            }
            a {
                @include menu_vertical_alt_current_hover_dark_mode_colors;

                & {
                    background-color: v_darktheme.$color-menu-bg-l1;
                }

                &:hover {
                    background-color: v_darktheme.$color-menu-bg-hover;
                }

                &:visited {
                    @include menu_vertical_alt_current_hover_dark_mode_colors;

                    & {
                        background-color: v_darktheme.$color-menu-bg-l1;
                    }

                    &:hover {
                        background-color: v_darktheme.$color-menu-bg-hover;
                    }
                }
            }
            &.toctree-l2 {
                &.current>a {
                    background-color: v_darktheme.$color-menu-bg-l1;
                }
            }
            &.current {
                & {
                    background-color: v_darktheme.$color-menu-bg-l1;
                }

                a {
                    & {
                        background-color: v_darktheme.$color-menu-bg-l1;
                    }
                    @include menu_vertical_current_dark_mode_colors;

                    &:hover {
                        background-color: v_darktheme.$color-menu-bg-hover;
                    }
                    &:visited {
                        background-color: v_darktheme.$color-menu-bg-l1;
                        &:hover {
                            background-color: v_darktheme.$color-menu-bg-hover;
                        }
                    }
                }
                &.toctree-l2 {
                    background-color: v_darktheme.$color-menu-bg-l1;

                    li.toctree-l3>a {
                        @include menu_vertical_current_dark_mode_colors;

                        & {
                            background-color: v_darktheme.$color-menu-bg-l2;
                        }
                        &:hover {
                            background-color: v_darktheme.$color-menu-bg-hover;
                        }
                        &:visited {
                            background-color: v_darktheme.$color-menu-bg-l2;
                            &:hover {
                                background-color: v_darktheme.$color-menu-bg-hover;
                            }
                        }
                    }
                }
                &.toctree-l3 {
                    li.toctree-l4>a {
                        @include menu_vertical_current_dark_mode_colors;

                        & {
                            background-color: v_darktheme.$color-menu-bg-l3;
                        }
                        &:hover {
                            background-color: v_darktheme.$color-menu-bg-hover;
                        }
                        &:visited {
                            background-color: v_darktheme.$color-menu-bg-l3;
                            &:hover {
                                background-color: v_darktheme.$color-menu-bg-hover;
                            }
                        }
                    }
                }
            }
        }
    }

    .admonition-in-other-languages {
        background: v_darktheme.$color-theme-alt-bg;
    }
    .rst-content {
        .highlight {
            background: v_darktheme.$color-theme-alt-bg;
        }
    }
    .rst-content .admonition,
    .rst-content .admonition-todo,
    .rst-content .attention,
    .rst-content .caution,
    .rst-content .danger,
    .rst-content .error,
    .rst-content .hint,
    .rst-content .important,
    .rst-content .note,
    .rst-content .seealso,
    .rst-content .tip,
    .rst-content .warning,
    .wy-alert {
        background: v_darktheme.$color-theme-alt-bg;
    }
    .rst-content .admonition-title, .wy-alert-title {
        // background: #6ab0de;
        background: #1a608e;
    }
    .rst-content div[class^=highlight],
    .rst-content pre.literal-block {
        border: 1px solid v_darktheme.$color-code-border;
        color: v_darktheme.$color-code-font;
    }
    .rst-content code.literal,
    .rst-content tt.literal {
        color: v_darktheme.$color-code-font;
    }
    .rst-content table.docutils thead,
    .rst-content table.field-list thead,
    .wy-table thead {
        background: #666666 !important;
        color: #cccccc !important;
    }
    .rst-content table.docutils,
    .wy-table-bordered-all {
        border: 1px solid v_darktheme.$color-border;
    }
    .rst-content table.docutils td,
    .wy-table-bordered-all td {
        border-bottom: 1px solid v_darktheme.$color-border;
        border-left: 1px solid v_darktheme.$color-border;
    }
    .wy-table-bordered {
        border: 1px solid v_darktheme.$color-border;
    }
    .wy-table-bordered-rows td {
        border-bottom: 1px solid v_darktheme.$color-border;
    }
    .wy-table-horizontal td,
    .wy-table-horizontal th {
        border-bottom: 1px solid v_darktheme.$color-border;
    }

    .rst-content table.docutils:not(.field-list) tr:nth-child(2n-1) td,
    .wy-table-backed,
    .wy-table-odd td,
    .wy-table-striped tr:nth-child(2n-1) td {
        background-color: v_darktheme.$color-theme-alt-bg;
    }

    //
    // theme overrides: widget
    //

    .tab {
        button {
            color: v_darktheme.$color-tab-font;
            border-left: 1px dotted v_darktheme.$color-widget-border;
            border-right: 1px dotted v_darktheme.$color-widget-border;
            border-bottom: 1px dotted v_darktheme.$color-widget-border;
            &:hover {
                background-color: color.scale(v_darktheme.$color-theme-bg-dark, $lightness: 30%);
                color: v_darktheme.$color-tab-hover-font;
            }
            &.active {
                color: v_darktheme.$color-tab-active-font;
                border-left: 1px solid v_darktheme.$color-widget-border;
                border-right: 1px solid v_darktheme.$color-widget-border;
                border-bottom: 3px solid v_darktheme.$color-theme-bg-dark;
            }
        }
    }

    .settings-bar {
        background-color: v_darktheme.$color-settingsbar-bg;
        color: white;

        button {
            background-color: transparent;
            color: white;
        }

        .dropdown-container {
            .dropdown-content {
                background-color: v_darktheme.$color-bg-dark;

                a {
                    color: white;

                    &:hover {
                        background-color: #ddd;
                    }
                }
            }
        }
    }

    .compiler-switch-help-info {
        background-color: v_darktheme.$color-settingsbar-bg;
    }

    .compiler-switch-help-info-click-remove {
        background-color: v_darktheme.$color-settingsbar-bg;
    }

    div {
        &.editor-container {
            border: 1px solid v_darktheme.$color-widget-border;
        }
        &.editor_label {
            border: 1px solid v_darktheme.$color-widget-border;
            color: v.$color-font-grey;
        }
        &.non-tabbed-links {
            border: 1px solid v_darktheme.$color-widget-border;
        }
        &.code_block_info {
            background: v_darktheme.$color-widget-output-area;
        }
        &.code_block_info_contents {
            color: v.$color-font-grey;
        }
        &.output_line {
            color: v.$color-font-grey;
        }
        &.output_msg {
            color: v.$color-widget-msg;
            &:hover {
                background-color: #fdd;
            }
        }
        &.output_msg_info {
            color: v_darktheme.$color-widget-info;
            &:hover {
                background-color: v.$color-widget-msg-info-bg-hover;
            }
        }
        &.output_info {
            color: v_darktheme.$color-widget-info;
        }
        &.output_error {
            color: v.$color-widget-error;
        }
        &.output_success {
            color: v.$color-widget-success;
        }
        &.output-area {
            background: v_darktheme.$color-widget-output-area;
        }
    }

    .read-only {
        background-color: v.$color-widget-readonly;
        opacity: 0.2;
        position: absolute;
    }

    a.ebook-download-button {
        background-color: v_darktheme.$color-theme-bg-dark;
    }

    //
    // Pygments: code coloring
    //

    .highlight .hll { background-color: #373B41; }
    .highlight { background: #1D1F21; }
    .highlight .c { color: #969896; font-style: italic } /* Comment */
    .highlight .err { border: 1px solid #FF0000 } /* Error */
    .highlight .k { color: #41c2ea; font-weight: bold } /* Keyword */
    .highlight .o { color: #8ABEB7; } /* Operator */
    .highlight .p { color: #8ABEB7; } /* Operator (new?) */
    .highlight .ch { color: #969896; font-style: italic } /* Comment.Hashbang */
    .highlight .cm { color: #969896; font-style: italic } /* Comment.Multiline */
    .highlight .cp { color: #969896; } /* Comment.Preproc */
    .highlight .cpf { color: #969896; font-style: italic } /* Comment.PreprocFile */
    .highlight .c1 { color: #969896; font-style: italic } /* Comment.Single */
    .highlight .cs { color: #969896; background-color: #fff0f0 } /* Comment.Special */
    .highlight .gd { color: #A00000; } /* Generic.Deleted */
    .highlight .ge { font-style: italic } /* Generic.Emph */
    .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
    .highlight .gr { color: #FF0000; } /* Generic.Error */
    .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
    .highlight .gi { color: #00A000; } /* Generic.Inserted */
    .highlight .go { color: #DEB85F; } /* Generic.Output */
    .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
    .highlight .gs { font-weight: bold } /* Generic.Strong */
    .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
    .highlight .gt { color: #0044DD; } /* Generic.Traceback */
    .highlight .kc { color: #B294BB; font-weight: bold } /* Keyword.Constant */
    .highlight .kd { color: #B294BB; font-weight: bold } /* Keyword.Declaration */
    .highlight .kn { color: #B294BB; font-weight: bold } /* Keyword.Namespace */
    .highlight .kp { color: #B294BB; } /* Keyword.Pseudo */
    .highlight .kr { color: #B294BB; font-weight: bold } /* Keyword.Reserved */
    .highlight .kt { color: #B294BB; } /* Keyword.Type */
    .highlight .m { color: #DE935F; } /* Literal.Number */
    .highlight .s { color: #B5BD68; } /* Literal.String */
    .highlight .n { color: #DE935F; } /* Name (new?) */
    .highlight .na { color: #DE935F; } /* Name.Attribute */
    .highlight .nb { color: #DE935F; } /* Name.Builtin */
    .highlight .nc { color: #F0C674; font-weight: bold } /* Name.Class */
    .highlight .no { color: #DE935F; } /* Name.Constant */
    .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */
    .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */
    .highlight .ne { color: #007020; } /* Name.Exception */
    .highlight .nf { color: #81A2BE; } /* Name.Function */
    .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */
    .highlight .nn { color: #c1c1c1; font-weight: bold } /* Name.Namespace */
    .highlight .nt { color: #ccb350; font-weight: bold } /* Name.Tag */
    .highlight .nv { color: #CC6666; } /* Name.Variable */
    .highlight .ow { color: #B294BB; font-weight: bold } /* Operator.Word */
    .highlight .w { color: #bbbbbb; } /* Text.Whitespace */
    .highlight .mb { color: #DE935F; } /* Literal.Number.Bin */
    .highlight .mf { color: #DE935F; } /* Literal.Number.Float */
    .highlight .mh { color: #DE935F; } /* Literal.Number.Hex */
    .highlight .mi { color: #DE935F; } /* Literal.Number.Integer */
    .highlight .mo { color: #DE935F; } /* Literal.Number.Oct */
    .highlight .sa { color: #DE935F; } /* Literal.String.Affix */
    .highlight .sb { color: #DE935F; } /* Literal.String.Backtick */
    .highlight .sc { color: #DE935F; } /* Literal.String.Char */
    .highlight .dl { color: #DE935F; } /* Literal.String.Delimiter */
    .highlight .sd { color: #DE935F; font-style: italic } /* Literal.String.Doc */
    .highlight .s2 { color: #b3e87f; } /* Literal.String.Double */
    .highlight .se { color: #DE935F; font-weight: bold } /* Literal.String.Escape */
    .highlight .sh { color: #DE935F } /* Literal.String.Heredoc */
    .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */
    .highlight .sx { color: #c65d09; } /* Literal.String.Other */
    .highlight .sr { color: #235388; } /* Literal.String.Regex */
    .highlight .s1 { color: #b3e87f; } /* Literal.String.Single */
    .highlight .ss { color: #517918; } /* Literal.String.Symbol */
    .highlight .bp { color: #007020; } /* Name.Builtin.Pseudo */
    .highlight .fm { color: #81A2BE; } /* Name.Function.Magic */
    .highlight .vc { color: #CC6666; } /* Name.Variable.Class */
    .highlight .vg { color: #CC6666; } /* Name.Variable.Global */
    .highlight .vi { color: #CC6666; } /* Name.Variable.Instance */
    .highlight .vm { color: #CC6666; } /* Name.Variable.Magic */
    .highlight .il { color: #DE935F; } /* Literal.Number.Integer.Long */
}
