/*

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;
}

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;
    box-shadow: none !important;
    padding-bottom: 0 !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;
}

.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;
}

/* normal font weight for .pre ... */
.pre {
    font-weight: normal;
}
/* ... but restore bold when .pre is in headings
   (a check for "not in headings" does not really exist in CSS)
*/
h1:has(.pre) .pre, h2:has(.pre) .pre, h3:has(.pre) .pre, h4:has(.pre) .pre, h5:has(.pre) .pre, h6:has(.pre) .pre {
    font-weight: bold;
}

/* 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) */
dl.field-list.simple > dd > p,
dl.field-list.simple > dd > ul.simple > li > p {
    display: inline !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.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;
}

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 */
/* Common styles for all cocotb version badges */
a[href*="docs.cocotb.org"]::after {
    background-color: var(--color-cocotb-blue);
    color: white;
    font-size: 0.6rem;
    padding: 0px 3px;
    margin-left: 0.1rem;
    border-radius: 4px;
    vertical-align: super;
    text-decoration: none;
    display: inline-block;
}

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;
}
