@import "reset";

/* fonts */

$body-fonts: Arial, Verdana, sans-serif;
$monospace-fonts: monospace;

/* colors */

$blockquote-border-color: rgb(250, 183, 0);
$blockquote-bg-color: rgb(255, 253, 231);
$blockquote-color: rgb(0, 0, 0);

$body-bg-color: rgb(247, 247, 247);
$body-color: rgb(0, 0, 0);

$box-border-color: rgb(211, 211, 211);
$box-bg-color: rgb(241, 241, 241);

$button-bg-color: rgb(3, 25, 79);
$button-color: rgb(255, 255, 255);
$button-border-color: rgb(192, 192, 192);

$code-color: rgb(0, 96, 0);
$code-bg-color: rgb(239, 239, 239);

$del-bg-color: rgb(244, 204, 204);
$ins-bg-color: rgb(217, 234, 211);

$heading-color: rgb(0, 0, 0);

$main-bg-color: rgb(255, 255, 255);
$main-border-color: $box-border-color;

$mobile-nav-drawer-shadow-color: rgba(0, 0, 0, 0.28);
$mobile-nav-backdrop-color: rgba(0, 0, 0, 0.5);

$license-color: rgb(94, 106, 114);
$license-bg-color: rgb(255, 255, 255);

$link-color: rgb(0, 102, 204);
$link-color-heading: $link-color;
$link-color-heading-em: rgb(0, 102, 204); // TODO: Figure out if this is used?
$link-disabled-color: rgb(102, 102, 102); // TODO: Figure out if this is used?
$link-visited-color: rgb(71, 18, 100);

$selector-bg-color: rgb(90, 112, 166);

$sidebar-section-bg-color: rgb(255, 255, 255);
$sidebar-section-color: rgb(72, 72, 72);
$sidebar-section-selected-color: black;

$table-border-color: rgb(217, 217, 217);

// At tablet widths and below, turn the desktop sidebar into a drawer.
$mobile-nav-breakpoint: 768px;

/* page-wide settings */

a {
  color: $link-color;
  &.disabled {
    color: $link-disabled-color;
    text-decoration: none;
  }
}

b {
  font-weight: 700;
}

body {
  background-color: $body-bg-color;
  color: $body-color;
  font-family: $body-fonts;

  &.mobile-nav-open {
    overflow: hidden;
  }
}

code {
  background: $code-bg-color;
  color: $code-color;
  font-family: $monospace-fonts;
}

em,
i {
  font-style: italic;
}

pre {
  background: $code-bg-color;
  border: 1px solid $box-border-color;
  margin: 1em;
  padding: 0.5em 1em 0.5em 1em;
}

header {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin: 5px 5px 5px 10px;

  a {
    align-items: center;
    color: $link-color-heading;
    display: flex;
    text-decoration: none;

    h2 {
      width: 100%;
    }
  }

  img {
    display: block;
    margin-right: 10px;
  }
}

.mobile-nav-toggle {
  align-items: center;
  background: transparent;
  border: 0;
  color: $heading-color;
  cursor: pointer;
  display: none;
  justify-content: center;
  padding: 8px 6px;
}

.mobile-nav-toggle-bars {
  display: grid;
  gap: 4px;
}

.mobile-nav-toggle-bars span {
  background: currentColor;
  display: block;
  height: 2.5px;
  width: 22px;
}

#mobile-nav-backdrop {
  display: none;
}

/* main panel */

#main-wrapper {
  display: flex;
}

.sidebar-nav {
  font-size: 12px;
  line-height: 1.33em;

  section {
    background-color: $sidebar-section-bg-color;
    margin: 0 5px 6px 5px;
    padding: 0 0 0 5px;
  }

  a {
    color: $link-color;
    display: block;
    text-decoration: none;

    &.selected {
      color: $sidebar-section-selected-color;
      font-weight: bold;
    }
  }

  h4 {
    color: $sidebar-section-color;
    font-weight: 700;
    font-size: 13px;
    margin-bottom: 1px;
    padding: 3px 0 2px 0;
  }

  .sidebar-license {
    background-color: $license-bg-color;
    color: $license-color;
    font-size: 10px;
    line-height: normal;
    margin: 0 5px 6px 5px;
    padding: 11px 5px 5px 5px;

    a {
      display: inline;
      text-decoration: underline;
    }
  }

  // Explicitly use the `a` tag to override the specificity of `.sidebar-nav a`.
  a.edit-this-page {
    background-color: $button-bg-color;
    border: 1px solid $button-border-color;
    box-sizing: border-box;
    color: $button-color;
    display: block;
    font-size: 14px;
    font-weight: 700;
    margin: 20px auto;
    padding: 6px 12px;
    text-align: center;
    text-decoration: none;
    width: 90%;
  }
}

#sidebar-left {
  flex: 0 auto;
  min-width: 120px;
  width: 120px;
}

.mobile-nav-header {
  display: none;
}

.mobile-nav-close {
  background-color: transparent;
  border: 0;
  color: $body-color;
  cursor: pointer;
  font-family: $body-fonts;
  font-size: 30px;
  line-height: 1;
  min-height: 40px;
  min-width: 40px;
  padding: 0;
}

main {
  background-color: $main-bg-color;
  border: 1px solid $main-border-color;
  flex: 1 100%;
  font-family: $body-fonts;
  font-size: 13.333px;
  line-height: 1.3;
  margin-right: 5px;
  padding: 20px;

  a:visited {
    color: $link-visited-color;
  }

  a.header-anchor {
    color: inherit;
    text-decoration: inherit;
  }

  blockquote {
    background-color: $blockquote-bg-color;
    border-left: 0.2em solid $blockquote-border-color;
    color: $blockquote-color;
    margin-bottom: 1em;
    padding: 0.2em 1em;
  }

  del {
    background-color: $del-bg-color;
    text-decoration: inherit;
  }

  h1 {
    font-size: 22px;
    font-weight: 700;
    margin: 10px 0 1.4em;

    a {
      color: $link-color-heading;
    }
  }

  h2 {
    font-size: 20px;
    font-weight: 700;
    margin: 1.2em 0 .8em 0;
  }

  h3 {
    font-size: 16px;
    font-weight: 700;
    margin: 1.2em 0 .7em 0;
  }

  h4 {
    font-weight: 700;
    margin: 1.2em 0 .6em 0;

    a {
      color: $link-color-heading;
    }

    i a {
      color: $link-color-heading-em;
      font-weight: 400;
    }
  }

  ins {
    background-color: $ins-bg-color;
    text-decoration: inherit;
  }

  p {
    margin-bottom: 13.33px;
    margin-top: 1.4em;
  }

  pre,
  code {
    white-space: break-spaces;
    word-break: break-all;
  }

  #title-crumbs {
    padding: 6px 0 0 10px;

    + h3 {
      margin-top: 6px;
    }
  }

  ul {
    display: block;
    list-style-position: outside;
    list-style-type: disc;
    margin-bottom: 1em;
    margin-top: 1em;
    padding-left: 40px;

    li {
      margin-bottom: 5px;
      margin-top: 5px;

      > p:first-of-type {
        display: inline;
      }
    }

    ul {
      list-style-type: circle;
      margin-bottom: 0;
      margin-top: 0;

      ul {
        list-style-type: square;
      }
    }
  }

  ol {
    list-style-position: outside;
    list-style-type: decimal;
    padding-left: 40px;
    margin: 1em 0;

    li {
      margin: 5px 0;
      p {
        margin: .5em 0;
      }

      > p:first-of-type {
        display: inline;
      }
    }

    ul {
      list-style-type: circle;
      margin-bottom: 0;
      margin-top: 0;
    }
  }

  table {
    border-collapse: collapse;
    border-spacing: 0px;
    border-width: 1px solid $table-border-color;
    margin: 1.3em 0 1.3em 0;

    td,
    th {
      border: 1px solid $table-border-color;
      padding: 5px 10px 5px 10px;
      vertical-align: top;
    }
  }

  /* Rules for particular extensions */

  // Used by the `{% subpages collections.all %}` extension.
  nav.subpage-listing {
    background-color: $box-bg-color;
    border: 1px solid $box-border-color;

    details {
      margin-left: -1em;
    }

    h4 {
      margin: inherit;
      padding: 0.5em 0 0 0.5em;
    }

    li {
      font-weight: normal;
      list-style: none;
      list-style-image: none;
      margin-left: 1.2em;
      padding-left: 1.3em;

      a {
        text-decoration: none;
      }
    }

    ul {
      padding-left: 0px;
    }

    > ul {
      margin: 0.5em 0 0.5em 0;

      > li {
        border-top: 1px solid white;
        font-weight: bold;
        margin: 3px 0 3px 0;
        padding: 2px 0 2px 1.3em;
      }
    }
  }

  // Used by the `[TOC]` extension.
  .table-of-contents {
    border: 1px solid $box-border-color;
    background-color: $box-bg-color;
    display: table;
    font-size: 12px;
    margin-left: 1em;
    padding: 1em 2em 1em 1em;

    a {
      text-decoration: none;
    }

    > ol::before {
      content: "Contents";
      display: block;
      font-weight: 700;
      margin: 0 0 0.5em -1em;
    }

    ol {
      line-height: 1.1em;
      margin: 0;
      padding-left: 1.2em;

      li {
        list-style-type: none;
      }
    }
  }

  // Used for two-column content "extension".
  .two-column-container {
    align-items: flex-start;
    display: flex;

    > div.column {
      flex: 50%;
      margin: 0;
      padding-right: 30px;
    }
  }
}

@media (min-width: ($mobile-nav-breakpoint + 1px)) {
  // Keep the sidebar visible while scrolling. Top padding keeps its content
  // off the viewport edge when sticky and adds a little more space below
  // the nearby header in its initial position.
  #sidebar-left {
    align-self: flex-start;
    box-sizing: border-box;
    max-height: 100vh;
    overflow-y: auto;
    padding-top: 10px;
    position: sticky;
    top: 0;
  }
}

@media (max-width: $mobile-nav-breakpoint) {
  header {
    flex-wrap: nowrap;
    margin: 5px;
  }

  .header-brand {
    flex: 1 1 auto;
    min-width: 0;

    h2 {
      font-size: 20px;
    }
  }

  .mobile-nav-toggle {
    display: inline-flex;
    flex: 0 0 auto;
    margin-left: 1px;
  }

  #search {
    display: flex;
    flex: 0 0 auto;
    justify-content: flex-end;
    min-width: 0;
    width: auto;
  }

  #search .DocSearch-Button {
    margin: 0;
    height: 40px;
    justify-content: center;
    min-width: 40px;
    padding: 0;
    width: 40px;
  }

  #search .DocSearch-Button-Keys,
  #search .DocSearch-Button-Placeholder {
    display: none;
  }

  #main-wrapper {
    display: block;
  }

  #sidebar-left {
    background-color: $main-bg-color;
    bottom: 0;
    box-shadow: 8px 0 24px $mobile-nav-drawer-shadow-color;
    box-sizing: border-box;
    font-size: 16px;
    left: 0;
    line-height: 1.5;
    min-width: 0;
    overflow-y: auto;
    padding: 12px;
    position: fixed;
    top: 0;
    transform: translateX(-105%);
    transition: transform 180ms ease-out, visibility 0s linear 180ms;
    visibility: hidden;
    width: min(80vw, 300px);
    z-index: 40;

    section,
    .sidebar-license {
      margin: 0 0 10px;
      padding: 8px;
    }

    a {
      padding: 5px 0;
    }

    h4 {
      font-size: 15px;
      padding-bottom: 6px;
    }

    .sidebar-license {
      font-size: 12px;
      line-height: 1.5;
    }

    a.edit-this-page {
      box-sizing: border-box;
      font-size: 16px;
      padding: 10px 14px;
      width: 100%;
    }
  }

  .mobile-nav-header {
    align-items: center;
    background-color: $main-bg-color;
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    position: sticky;
    top: 0;

    h3 {
      font-size: 20px;
      font-weight: 700;
      margin: 0;
    }
  }

  #mobile-nav-backdrop {
    background-color: $mobile-nav-backdrop-color;
    display: block;
    inset: 0;
    opacity: 0;
    pointer-events: none;
    position: fixed;
    transition: opacity 180ms ease-out;
    z-index: 30;
  }

  body.mobile-nav-open {
    #sidebar-left {
      transform: translateX(0);
      transition-delay: 0s;
      visibility: visible;
    }

    #mobile-nav-backdrop {
      opacity: 1;
      pointer-events: auto;
    }
  }

  main {
    margin: 0 5px 5px 5px;
    padding: 16px;

    // Stack the two content columns vertically at the mobile breakpoint so
    // each column has enough horizontal space to remain readable.
    .two-column-container {
      display: block;

      > div.column {
        margin-bottom: 20px;
        padding-right: 0;
      }
    }
  }
}

// Below 400px, the full-size logo and title no longer fit beside the
// search and navigation buttons without wrapping.
@media (max-width: 400px) {
  .header-brand {
    img {
      height: 36px;
      margin-right: 8px;
      width: auto;
    }

    h2 {
      font-size: 17px;
    }
  }
}
