// Override bootstrap variables
$spacer: 1rem;

$container-max-widths: (
  sm: 540px,
  md: 720px,
  lg: 960px,
  xl: 1400px,
);

$grid-breakpoints: (
  xs: 0,
  sm: 540px,
  md: 720px,
  lg: 960px,
  xl: 1200px,
);

// Import Bootstrap core
@import '~bootstrap/scss/bootstrap';

@import './base';
@import './navbar';
@import './admonitions';
@import './api';

// Custom css, TODO: to be refactored in different partials
// GitHub blockquote style
blockquote {
  padding: 0 1em;
  color: #6a737d;
  border-left: .25em solid #dfe2e5;
}

// For consistency, add bracket around footnotes/citations which are
// cited more than once. E.g. [Newton](1,2) instead of Newton(1,2)
dt.label > span.brackets:not(:only-child):before {
  content: "[";
}

dt.label > span.brackets:not(:only-child):after {
  content: "]";
}

// Make footnote as a supercript
a.footnote-reference {
  vertical-align: super;
  font-size: small;
}

div.deprecated {
  margin-bottom: 10px;
  margin-top: 10px;
  padding: 7px;
  background-color: #f3e5e5;
  border: 1px solid #eed3d7;
  border-radius: 0.5rem;

  p {
    color: #b94a48;
    display: inline;
  }
}

.topic {
  background-color: #eee;
}

.seealso dd {
  margin-top: 0;
  margin-bottom: 0;
}

.viewcode-back {
  font-family: var(--pst-font-family-base);
}

.viewcode-block:target {
  background-color: #f4debf;
  border-top: 1px solid #ac9;
  border-bottom: 1px solid #ac9;
}

span.guilabel {
  border: 1px solid #7fbbe3;
  background: #e7f2fa;
  font-size: 80%;
  font-weight: 700;
  border-radius: 4px;
  padding: 2.4px 6px;
  margin: auto 2px;
}

/**
 * Footer
 */

footer {

  width: 100%;
  border-top: 1px solid #ccc;
  padding: 10px;

  .footer-item p {
    margin-bottom: 0;
  }
}

/* -------------------------------------------------------------------------- */

.bd-search {
  position: relative;
  padding: 1rem 15px;
  margin-right: -15px;
  margin-left: -15px;

  .icon {
    position: absolute;
    color: #a4a6a7;
    left: 25px;
    top: 25px;
  }

  input {
    border-radius: 0;
    border: 0;
    border-bottom: 1px solid #e5e5e5;
    padding-left: 35px;
  }
}

/* minimal copy paste from bootstrap docs css to get sidebars working */

.bd-toc {
  -ms-flex-order: 2;
  order: 2;

  height: calc(100vh - 2rem);
  overflow-y: auto;

  @supports (position: -webkit-sticky) or (position: sticky) {
    position: -webkit-sticky;
    position: sticky;
    top: calc(var(--pst-header-height) + 20px);
    height: calc(100vh - 5rem);
    overflow-y: auto;
  }

  .onthispage {
    color: #a4a6a7;
  }
}

.section-nav {
  padding-left: 0;
  border-left: 1px solid #eee;
  border-bottom: none;

  ul {
    padding-left: 1rem;
  }
}

.toc-entry {
  display: block;

  a {
    display: block;
    padding: 0.125rem 1.5rem;
    color: rgba(var(--pst-color-toc-link), 1);

    @include media-breakpoint-up(xl) {
      padding-right: 0;
    }

    &:hover {
      color: rgba(var(--pst-color-toc-link-hover), 1);
      text-decoration: none;
    }
  }
}

.bd-sidebar {
  padding-top: 1em;

  @include media-breakpoint-up(md) {
    border-right: 1px solid rgba(0, 0, 0, 0.1);

    @supports (position: -webkit-sticky) or (position: sticky) {
      position: -webkit-sticky;
      position: sticky;
      top: calc(var(--pst-header-height) + 20px);
      z-index: 1000;
      height: calc(100vh - var(--pst-header-height) - 20px);
    }
  }

  &.no-sidebar {
    border-right: 0;
  }
}

.bd-links {
  padding-top: 1rem;
  padding-bottom: 1rem;
  margin-right: -15px;
  margin-left: -15px;

  @include media-breakpoint-up(md) {
    display: block;

    @supports (position: -webkit-sticky) or (position: sticky) {
      max-height: calc(100vh - 11rem);
      overflow-y: auto;
    }
  }
}

.bd-sidenav {
  display: none;
}

.bd-content {
  padding-top: 20px;

  .section {
    max-width: 100%;

    // make every overflowing elements in main content scrollable
    table {
      display: block;
      overflow: auto;
    }
  }
}

.bd-toc-link {
  display: block;
  padding: 0.25rem 1.5rem;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.65);

  &:hover {
    color: rgba(0, 0, 0, 0.85);
    text-decoration: none;
  }
}

.bd-toc-item.active {
  margin-bottom: 1rem;

  &:not(:first-child) {
    margin-top: 1rem;
  }

  > {
    .bd-toc-link {
      color: rgba(0, 0, 0, 0.85);

      &:hover {
        background-color: transparent;
      }
    }

    .bd-sidenav {
      display: block;
    }
  }
}

nav.bd-links {

  p.caption {
      font-size: var(--pst-sidebar-caption-font-size);
      text-transform: uppercase;
      font-weight: bold;
      position: relative;
      margin-top: 1.25em;
      margin-bottom: 0.5em;
      padding: 0 1.5rem;
      color: rgba(var(--pst-color-sidebar-caption), 1);
      &:first-child {
          margin-top: 0;
      }
  }
}

.bd-sidebar .nav {

  font-size: var(--pst-sidebar-font-size);

  ul {
    list-style: none;
    padding: 0 0 0 1.5rem;
  }

  li > a {
    display: block;
    padding: 0.25rem 1.5rem;
    color: rgba(var(--pst-color-sidebar-link), 1);

    &:hover {
      color: rgba(var(--pst-color-sidebar-link-hover), 1);
      text-decoration: none;
      background-color: transparent;
    }

    &.reference.external {
      &:after {
        font-family: 'Font Awesome 5 Free';
        font-weight: 900;
        content: '\f35d';
        font-size: .75em;
        margin-left: 0.3em
      }
    }
  }

  .active {
    > a,
    &:hover > a {
      font-weight: 600;
      color: rgba(var(--pst-color-sidebar-link-active), 1);
    }
  }
}

/* adjust toc font sizes to improve overview */
.toc-h2 {
  font-size: 0.85rem;
}

.toc-h3 {
  font-size: 0.75rem;
}

.toc-h4 {
  font-size: 0.65rem;
}

.toc-entry > .nav-link.active {
  font-weight: 600;
  color: #130654;
  color: rgba(var(--pst-color-toc-link-active), 1);
  background-color: transparent;
  border-left: 2px solid rgba(var(--pst-color-toc-link-active), 1);
}

.nav-link:hover {
  border-style: none;
}

#navbar-main-elements li.nav-item i {
  font-size: 0.7rem;
  padding-left: 2px;
  vertical-align: middle;
}

/* Collapsing of the TOC sidebar while scrolling */

/* Nav: hide second level (shown on .active) */

.bd-toc .nav {
  .nav {
    display: none;

    // So we can manually specify a level as visible in the config
    &.visible {
      display: block;
    }
  }

  > .active > ul {
    display: block;
  }
}

/* Previous / Next buttons */

.prev-next-area {
  margin: 20px 0px;

  p {
    margin: 0 0.3em;
    line-height: 1.3em;
  }

  i {
    font-size: 1.2em;
  }

  a {
    // So that buttons align with icons
    display: flex;
    align-items: center;
    border: none;
    padding: 10px;
    max-width: 45%;
    overflow-x: hidden;
    color: rgba(0, 0, 0, 0.65);
    text-decoration: none;

    p.prev-next-title {
      color: rgba(var(--pst-color-link), 1);
      font-weight: 600;
      font-size: 1.1em;
    }

    &:hover p.prev-next-title {
      text-decoration: underline;
    }

    .prev-next-info {
      flex-direction: column;
      margin: 0 .5em;

      .prev-next-subtitle {
        text-transform: capitalize;
      }
    }

    &.left-prev {
      float: left;
    }

    &.right-next {
      float: right;
      
      div.prev-next-info {
        text-align: right;
      }
    }    
  }
}

/* Alert Styling */

.alert {
  /* Avoid too large empty space below alert boxes. */
  padding-bottom: 0;
}

.alert-info a {
  /* higher contrast for links in info boxes. */
  color: #e83e8c;
}

/* Icon Links */

#navbar-icon-links {
  i {
    &.fa,
    &.fab,
    &.far,
    &.fas{
      vertical-align: middle;
      font-style: normal;
      font-size: 1.5rem;
      line-height: 1.25;
    }

    /* Social media buttons */
    &.fa-github-square:before {
      color: #333;
    }

    &.fa-twitter-square:before {
      color: #55acee;
    }

    &.fa-gitlab:before {
      color: #548
    }

    &.fa-bitbucket:before {
      color: #0052cc;
    }
  }
}


/* TOC section headers */

.tocsection {
  padding-left: 10px;
  border-left: 1px solid #eee;
  padding: 0.3rem 1.5rem;

  i {
    padding-right: 0.5rem;
  }
}

.editthispage {
  padding-top: 2rem;

  a {
    color: var(--pst-color-sidebar-link-active);
  }
}

/* Special-case over-rides */

// xarray output display in bootstrap
.xr-wrap[hidden] {
  display: block!important;
}


////////////////////////////////////////////////////////////////////////////////
// Togglable expand/collapse
////////////////////////////////////////////////////////////////////////////////


.toctree-checkbox {
  position: absolute;
  display: none;
}

.toctree-checkbox {
  ~ ul {
    display: none;
  }
  ~ label i {
    transform: rotate(0deg);
  }
}
.toctree-checkbox:checked {
  ~ ul {
    display: block;
  }
  ~ label i {
    transform: rotate(180deg);
  }
}


.bd-sidebar {

  li {
    position: relative;
  }
  label {
    position: absolute;
    top: 0;
    right: 0;
    // height: var(--sidebar-item-height);
    height: 30px;
    width: 30px;
    // width: var(--sidebar-expander-width);

    cursor: pointer;

    display: flex;
    justify-content: center;
    align-items: center;

    &:hover {
      background: rgba(var(--pst-color-sidebar-expander-background-hover), 1);
    }

    i {
      display: inline-block;
      font-size: 0.75rem;
      text-align: center;
      &:hover {
        color: rgba(var(--pst-color-sidebar-link-hover), 1);
      }
    }
  }

  // If it has children, add a bit more padding to wrap the content to avoid
  // overlapping with the <label>
  li.has-children {
    > .reference {
      padding-right: 30px;
    }
  }
}

// From https://stackoverflow.com/a/34372191
table.highlighttable td.linenos,
span.linenos,
div.doctest > div.highlight span.gp {  /* gp: Generic.Prompt */
  user-select: none;
  -webkit-user-select: text; /* Safari fallback only */
  -webkit-user-select: none; /* Chrome/Safari */
  -moz-user-select: none; /* Firefox */
  -ms-user-select: none; /* IE10+ */
}

// Bootstrap adds margin to their general container class. However, sphinx/docutils
// can also generate output with the container class, but in those cases we should
// not add the margin from bootstrap.
.docutils.container {
  padding-left: unset;
  padding-right: unset;
}
