/*

https://github.com/cocotb/cocotb-web/blob/master/_sass/_custom-styles.scss
https://github.com/cocotb/cocotb-web/blob/master/_sass/_custom-variables.scss

https://www.cocotb.org/assets/css/bootstrap-theme.css

*/

:root {
    --color-cocotb-blue: #3776ab;
    --color-cocotb-blue-darker: rgb(44, 94, 137);
    --color-cocotb-red: #b41d2e;
    --color-cocotb-yellow: #ffcd3c;
    --color-cocotb-green: rgb(79, 196, 100);
    --color-cocotb-green-bg: #e7f6f1;
    --bs-primary: var(--color-cocotb-blue) !important;
    --bs-secondary: var(--color-cocotb-yellow) !important;
}

html {
    --bs-border-radius: 0 !important;
    --bs-border-radius-sm: 0 !important;
    --bs-border-radius-ls: 0 !important;
    --bs-border-radius-pill: 0 !important;

    --pst-font-family-base: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", var(--pst-font-family-base-system);
    --pst-font-family-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", var(--pst-font-family-monospace-system);

    /* base font size - applied at body/html level */
    --pst-font-size-base: 1.0rem;
    --pst-sidebar-font-size: 1.0rem;
    --pst-sidebar-header-font-size: unset;
    --pst-sidebar-header-font-weight: bold;

    /* heading font sizes based on bootstrap sizing */
    --pst-font-size-h1: 2.0rem;
    --pst-font-size-h2: 1.75rem;
    --pst-font-size-h3: 1.5rem;
    --pst-font-size-h4: 1.4rem;
    --pst-font-size-h5: 1.3rem;
    --pst-font-size-h6: 1.2rem;

    --pst-font-size-milli: 0.75rem;

    /* --pst-font-weight-caption: 300; */
    --pst-font-weight-caption: 400;
    --pst-font-weight-heading: 700;
    --pst-admonition-font-weight-heading: 700;

    --pst-icon-admonition-attention: none;
    --pst-icon-admonition-caution: none;
    --pst-icon-admonition-danger: none;
    --pst-icon-admonition-default: none;
    --pst-icon-admonition-error: none;
    --pst-icon-admonition-hint: none;
    --pst-icon-admonition-important: none;
    --pst-icon-admonition-note: none;
    --pst-icon-admonition-seealso: none;
    --pst-icon-admonition-tip: none;
    --pst-icon-admonition-todo: none;
    --pst-icon-admonition-warning: none;

    --pst-icon-versionmodified-default: none;
    --pst-icon-versionmodified-added: none;
    --pst-icon-versionmodified-changed: none;
    --pst-icon-versionmodified-deprecated: none;

    --pst-color-primary: var(--color-cocotb-blue) !important;
    --pst-color-secondary: var(--color-cocotb-yellow) !important;
    --pst-color-secondary-highlight: var(--color-cocotb-blue) !important;
    --pst-color-accent: var(--color-cocotb-yellow) !important;

    --pst-color-link: var(--color-cocotb-blue) !important;
    --pst-color-link-hover: var(--color-cocotb-blue-darker) !important;
}

body {
    line-height: 1.5;
}

h1 {
    color: var(--color-cocotb-blue) !important;
    line-height: 60px !important;
}

h1, h2, h3, h4, h5, h6 {
    margin: calc(0.7 * 2.75rem) 0 calc(0.7 * 1.05rem) !important;
}

h1, h2, h3, h4, h5 {
    font-weight: bold !important;
}

h6 {
    font-style: italic !important;
}

/* settings based on the ones from https://cocotb.org, but apply non-linear scaling of font sizes */
h1 { font-size: calc(0.9 * (1.375rem + 1.5vw)); }
@media (min-width: 1200px) { h1 { font-size: calc(0.9 * 2.5rem); } }

h2 { font-size: calc(0.8 * (1.325rem + 0.9vw)); }
@media (min-width: 1200px) { h2 { font-size: calc(0.8 * 2rem); } }

h3 { font-size: calc(0.7 * (1.3rem + 0.6vw)); }
@media (min-width: 1200px) { h3 { font-size: calc(0.7 * 1.75rem); } }

h4 { font-size: calc(0.7 * (1.275rem + 0.3vw)); }
@media (min-width: 1200px) { h4 { font-size: calc(0.7 * 1.5rem); } }

h5, h6 { font-size: 1.0rem; }

.admonition-title {
    background-color: white !important;
    font-style: normal !important;
}

div.admonition > p.admonition-title,
div.admonition > p.admonition-title + p {
    display: inline;
}

.admonition p.admonition-title ~ *,
div.admonition p.admonition-title ~ * {
    margin: 0;
}

.admonition > .admonition-title,
div.admonition > .admonition-title {
    display: inline;
    margin: 0;
    margin-right: 0.2rem;
    padding: 0;
}

blockquote {
    border-radius: 0 !important;
    box-shadow: none !important;
    padding-top: 0.25rem !important;
    padding-bottom: 0.25rem !important;
}

div.admonition {
    border-radius: 0 !important;
    border-color: var(--color-cocotb-blue) !important;
    box-shadow: none !important;
    padding-bottom: 0 !important;
    margin: 1rem auto !important;
}

div.deprecated,
div.versionadded,
div.versionchanged,
div.versionremoved {
    background-color: white !important;
    /* font-size: 0.75rem !important; */ /* TODO: decide on this */
    border-radius: 0 !important;
    box-shadow: none !important;
    margin: 1.0rem auto;
}

.admonition.warning,
div.deprecated,
div.versionremoved {
    border-color: var(--color-cocotb-yellow) !important;
}

div.versionadded {
    border-color: var(--color-cocotb-green) !important;
}

blockquote,
.admonition.note,
div.versionchanged {
    border-color: var(--color-cocotb-blue) !important;
}

div.deprecated > p,
div.versionadded > p,
div.versionchanged > p,
div.versionremoved > p {
    margin: 0 !important;
}

/* TODO: can be removed once https://github.com/pydata/pydata-sphinx-theme/pull/2087 is in a release */
div.versionremoved {
    vertical-align: middle;
    margin: 1.5625em auto;
    padding: 0 0.6rem;
    overflow: hidden;
    /* break-inside has replaced page-break-inside and is widely usable since 2019 */
    page-break-inside: avoid;
    break-inside: avoid;
    border-left: 0.2rem solid;
    border-color: var(--pst-color-info);
    background-color: var(--pst-color-on-background);
    /* @include box-shadow; */
    position: relative;
}

/* TODO: can be removed once https://github.com/pydata/pydata-sphinx-theme/pull/2087 is in a release */
div.versionremoved > p {
    margin-bottom: 0.6rem;
    margin-top: 0.6rem;
}

span.versionmodified {
    font-style: italic !important;
    font-weight: normal !important;
}

a.headerlink {
    color: var(--pst-color-secondary) !important;
}

a {
    color: var(--pst-color-primary) !important;
    text-decoration-style: solid !important;
}

/* "Hide Search Matches" */
div#searchbox p.highlight-link a {
    background-color: var(--pst-color-on-background) !important;
}

a:hover {
    color: var(--color-cocotb-blue-darker) !important;
    text-decoration-thickness: 1px !important;
}

label.sd-tab-label:hover {
    color: var(--color-cocotb-blue-darker) !important;
    text-decoration-thickness: unset !important;
}

/* code.literal, */
strong.command {
    color: var(--color-cocotb-blue) !important;
    background-color: var(--pst-color-surface) !important;
    font-family: var(--pst-font-family-monospace) !important;
    font-size: 0.875rem !important;
    font-weight: normal !important;
    border: 1px solid var(--pst-color-border) !important;
    border-radius: 0 !important;
    padding: .1rem .25rem !important;
}

.pre {
    color: var(--color-cocotb-blue) !important;
    font-size: 16px;
}

code.xref {
  background-color: transparent;
  font-weight: normal;
}

h1:has(code.xref) code.xref, h2:has(code.xref) code.xref, h3:has(code.xref) code.xref, h4:has(code.xref) code.xref, h5:has(code.xref) code.xref, h6:has(code.xref) code.xref {
  font-weight: bold !important;
}

/* horizontal rule above */
dl.py.class dt.sig.sig-object,
dl.py.exception dt.sig.sig-object,
dl.py.type dt.sig.sig-object,
dl.py.data dt.sig.sig-object,
dl.py.decorator dt.sig.sig-object,
dl.py.function dt.sig.sig-object {
  padding-top: 1.0rem !important;
  border-top: 1.5px solid var(--color-cocotb-blue);
  margin-top: 1.0rem !important;
  font-size: 1.1rem !important;
  font-weight: bold !important;
}

/* remove horizontal rule when this is the first element belonging to this group of classes */
dl.py.class:first-of-type dt.sig.sig-object,
dl.py.exception:first-of-type dt.sig.sig-object,
dl.py.type:first-of-type dt.sig.sig-object,
dl.py.data:first-of-type dt.sig.sig-object,
dl.py.decorator:first-of-type dt.sig.sig-object,
dl.py.function:first-of-type dt.sig.sig-object {
  border-top: none;
}

dl.py.attribute dt.sig.sig-object,
dl.py.classmethod dt.sig.sig-object,
dl.py.decoratormethod dt.sig.sig-object,
dl.py.staticmethod dt.sig.sig-object,
dl.py.method dt.sig.sig-object,
dl.py.property dt.sig.sig-object {
  border-top: none;
  margin-top: 0 !important;
  font-size: 1.0rem !important;
  /* font-weight: normal !important; */
}

dl.py.attribute dt.sig.sig-object .sig-name,
dl.py.classmethod dt.sig.sig-object .sig-name,
dl.py.decoratormethod dt.sig.sig-object .sig-name,
dl.py.staticmethod dt.sig.sig-object .sig-name,
dl.py.method dt.sig.sig-object .sig-name,
dl.py.property dt.sig.sig-object .sig-name {
  font-size: 1.0rem !important;
  /* font-weight: normal !important; */
}

/* remove top margin if preceded by a heading, admonition or version modified */
h1 + dl.py,
h2 + dl.py,
h3 + dl.py,
h4 + dl.py,
h5 + dl.py,
h6 + dl.py,
.admonition + dl.py,
.versionadded + dl.py,
.versionchanged + dl.py,
.versionremoved + dl.py,
.deprecated + dl.py {
  margin-top: 0 !important;
}

dl[class]:not(.option-list, .field-list, .footnote, .glossary, .simple) {
  margin-bottom: 0.5rem !important;
}

/* apidoc "[source]" link */
span.viewcode-link {
    font-weight: normal !important;
    font-size: 0.875rem !important;
}

/* apidoc "Parameters:", "Returns:" etc. */
dl.field-list > dt {
    background-color: white !important;
    padding-left: 0px !important;
}

dl.field-list > dd {
    padding-left: 0px !important;
}

/* highlighted code */
.highlight .hll,
dt:target,
span.highlighted {
    background-color: var(--color-cocotb-yellow) !important;
}

div.code-block-caption span.caption-text {
    font-style: italic;
}

/* search bar */
.bd-search,
.search-button-field {
    border-radius: unset !important;
}

code.download {
    font-weight: normal !important;
}

img {
    margin-top: 1.15rem !important;
    margin-bottom: 1.15rem !important;
}

/* make left and right TOCs a bit tighter */
nav.bd-links li > a,
.toc-entry a.nav-link {
    padding-top: 0.175rem !important;
    padding-bottom: 0.175rem !important;
}

/* disable dark mode button (https://github.com/executablebooks/sphinx-book-theme/issues/750) */
button.theme-switch-button {
    display: none !important;
}

/*
"Usage:" etc. sections in docstrings

This handles any sections that are *not* listed in
https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html#docstring-sections

Sections that *are* listed in there likely have a different behaviour,
e.g. the documented "Example(s):" leads to a '.. rubric::'
(or an .. admonition::' if 'napoleon_use_admonition_for_examples = True').

Such a rubric could be handled with code like the following,
but it is likely not selecting all elements that it should
and might mis-select elements that should be left alone.

//// "dl and any subsequent siblings (but not .versionchanged etc.)" - for "Examples" in apidoc
// dl.field-list.simple ~ *:not(.versionadded):not(.versionchanged):not(.deprecated):not(.versionremoved) {
//     margin-left: 2.5rem;
// }
//
//
//// "dl and next p.rubric sibling..." - "Examples:" in apidoc
// dl.field-list.simple + p.rubric {
//     font-weight: bold;
//     margin-left: 0.5rem !important;
//     border-bottom: unset !important;
// }
*/
dl > dd > dl:not(.field-list.simple) {
    margin-left: 0rem !important;
}

/* fix for extra linebreak in apidoc (https://github.com/pydata/pydata-sphinx-theme/issues/2098) */
simple li p:first-child, .simple dd p:first-child {
    display: inline;
}
.simple li p:first-child + p, .simple dd p:first-child + p {
    display: inline;
}
.simple li p + p + p, .simple dd p + p + p {
    display: block;
}

/* add space between consecutive paragraphs */
p + p {
    margin-top: 0.5rem !important;
}

/* reduce distance after paragraphs a bit */
p {
    margin-bottom: 0.5rem !important;
}


/* reduce big bottom margin in apidoc */
/*
// original from pydata-sphinx-theme:
dl[class]:not(.option-list, .field-list, .footnote, .glossary, .simple) {
    margin-bottom: 3rem;
}
*/
dl.py.attribute,
dl.py.class,
dl.py.classmethod,
dl.py.data,
dl.py.decorator,
dl.py.decoratormethod,
dl.py.exception,
dl.py.function,
dl.py.method,
dl.py.property,
dl.py.staticmethod,
dl.py.type {
    margin-bottom: 1rem;
}

/* dl.cpp.macro seems to be defined in breathe */
dl.cpp.class,
dl.cpp.concept,
dl.cpp.enum,
dl.cpp.enum-class,
dl.cpp.enum-struct,
dl.cpp.function,
dl.cpp.member,
dl.cpp.struct,
dl.cpp.type,
dl.cpp.union,
dl.cpp.var,
dl.cpp.macro {
    margin-bottom: 1rem !important;
}

dl.cpp.enumerator {
    margin-bottom: 0.25rem;
}

/*
Make autolinks to reference documentation less prominent
(https://sphinx-codeautolink.readthedocs.io/en/latest/examples.html#custom-link-styles)
*/
.sphinx-codeautolink-a {
    text-decoration-style: solid !important;
    text-decoration-color: #aaa;
}
.sphinx-codeautolink-a:hover {
    text-decoration-color: black;
}

/*
Classes that are manually set (using :class:)
on e.g. .. code-block:: in the "Upgrading to cocotb 2.0" section
*/
.removed.highlight-python {
    border-left: 0.2rem solid;
    border-color: var(--color-cocotb-red);
}

.deprecated.highlight-python {
    border-left: 0.2rem solid;
    border-color: var(--color-cocotb-yellow);
}

.new.highlight-python {
    border-left: 0.2rem solid;
    border-color: var(--color-cocotb-green);
}

/* A manually inserted horizontal rule */
hr.docutils {
    border: 0;
    border-top: 1.5px solid var(--color-cocotb-blue);
    margin: 1.5rem 0;
    opacity: 1.0;
}

/* Add badges for links that point to docs of specific cocotb versions */
a[href*="docs.cocotb.org"]::after {
    background-color: white;
    color: var(--color-cocotb-blue);
    border: 1px solid;
    border-radius: 4px;
    font-size: 0.6rem;
    font-weight: bold;
    padding: 0px 3px;
    margin-left: 0.1rem;
    vertical-align: super;
    display: inline-block;
    text-decoration: none;
}

a[href*="docs.cocotb.org"][href*="v1.9"]::after {
    content: "v1.9";
}
a[href*="docs.cocotb.org"][href*="v1.8"]::after {
    content: "v1.8";
}
a[href*="docs.cocotb.org"][href*="v1.7"]::after {
    content: "v1.7";
}
a[href*="docs.cocotb.org"][href*="v1.6"]::after {
    content: "v1.6";
}
a[href*="docs.cocotb.org"][href*="v1.5"]::after {
    content: "v1.5";
}
a[href*="docs.cocotb.org"][href*="v1.4"]::after {
    content: "v1.4";
}
a[href*="docs.cocotb.org"][href*="v1.3"]::after {
    content: "v1.3";
}
a[href*="docs.cocotb.org"][href*="v1.2"]::after {
    content: "v1.2";
}
a[href*="docs.cocotb.org"][href*="v1.1"]::after {
    content: "v1.1";
}


/*
Sticky headings for Release Notes only (where we know the heading text spans only one line).
The "release-notes" class on "body" is dynamically set in cocotb.js
*/
body.release-notes h1,
body.release-notes h2,
body.release-notes h3 {
  position: sticky;
  /* top: 48px; */
  height: 48px;
  display: flex;
  align-items: center;
  background-color: var(--pst-color-background);
}

body.release-notes h1 {
  top: calc(1 * 48px);
  z-index: 990;
}

body.release-notes h2 {
  top: calc(2 * 48px);
  z-index: 980;
}

body.release-notes h3 {
  top: calc(3 * 48px);
  z-index: 970;
}


code.literal {
  border: none;
  background-color: unset;
  padding: 0;
}


/* add text "envvar" before environment variable definitions */
dl.std.envvar > dt::before {
    content: "envvar ";
    color: var(--color-cocotb-blue);
    font-style: italic;
}

dl.std.envvar > dt {
    margin-top: 1.5rem;
}

/* Make sure typewriter text has the same font size as the surrounding headings */
h1 .pre,
h2 .pre,
h3 .pre,
h4 .pre,
h5 .pre,
h6 .pre,
h1 code,
h2 code,
h3 code,
h4 code,
h5 code,
h6 code {
    font-size: inherit;
}
