/* Dark theme, used when the reader's system (or browser) is set to dark mode.
 *
 * The default Antora UI writes its colours straight into each rule instead of using
 * variables, so every rule that sets a colour in site.css, search.css, tabs.css or
 * hebi.css is restated here with the same selector. This file loads last, so the same
 * selector is enough to win. When the UI bundle or hebi.css gains a rule that sets a
 * colour, add its dark counterpart here.
 *
 * The HEBI orange is 5.2:1 on the page background, so in dark mode it is readable at any
 * size. Hover goes lighter rather than darker, since darker would lose contrast here.
 */

@media (prefers-color-scheme: dark) {
  :root {
    --hebi-dark-bg: #161d21;
    --hebi-dark-surface: #1d262b;
    --hebi-dark-raised: #243037;
    --hebi-dark-border: #34434b;
    --hebi-dark-text: #d4dce0;
    --hebi-dark-heading: #eef2f4;
    --hebi-dark-muted: #9aa8ae;
    --hebi-orange-light: #f29a72;
  }

  /* ---- Page, scrollbars ---- */

  body {
    background: var(--hebi-dark-bg);
    color: var(--hebi-dark-text);
  }

  html {
    scrollbar-color: var(--hebi-dark-border) var(--hebi-dark-bg);
  }

  body * {
    scrollbar-color: var(--hebi-dark-border) transparent;
  }

  html::-webkit-scrollbar {
    background-color: var(--hebi-dark-bg);
  }

  ::-webkit-scrollbar-thumb {
    background-color: var(--hebi-dark-border);
  }

  ::-webkit-scrollbar-thumb:hover {
    background-color: var(--hebi-dark-muted);
  }

  ::selection {
    background: rgb(232 109 57 / 35%);
  }

  /* The UI's icons (home, menu, nav carets, chevrons) are dark SVG backgrounds. */
  .home-link,
  .nav-toggle,
  .nav-menu-toggle,
  .nav-item-toggle,
  .nav-panel-explore .context .version::after,
  .page-versions .version-menu-toggle {
    filter: invert(0.85);
  }

  /* ---- Left navigation ---- */

  .nav,
  .nav-panel-explore {
    background: var(--hebi-dark-surface);
  }

  .nav {
    box-shadow: 0.5px 0 3px #000;
  }

  .nav-menu h3.title {
    color: var(--hebi-dark-heading);
  }

  .nav-panel-explore .context {
    color: var(--hebi-dark-muted);
    box-shadow: 0 -1px 0 var(--hebi-dark-border);
  }

  .nav-panel-explore .components {
    background: var(--hebi-dark-bg);
    box-shadow: inset 0 1px 5px #000;
  }

  .nav-panel-explore .component .version a {
    background: var(--hebi-dark-border);
  }

  .nav-panel-explore .component .is-current a {
    background: var(--hebi-dark-text);
    color: var(--hebi-dark-bg);
  }

  /* ---- Breadcrumb bar ---- */

  .toolbar {
    background-color: var(--hebi-dark-surface);
    box-shadow: 0 1px 0 var(--hebi-dark-border);
    color: var(--hebi-dark-muted);
  }

  .toolbar .edit-this-page a,
  .page-versions .version.is-missing {
    color: var(--hebi-dark-muted);
  }

  .page-versions .version-menu {
    background: var(--hebi-dark-raised);
  }

  /* ---- "Contents" sidebar ---- */

  .toc-menu {
    color: var(--hebi-dark-muted);
  }

  .toc .toc-menu h3 {
    color: var(--hebi-dark-heading);
  }

  .toc .toc-menu a {
    border-left-color: var(--hebi-dark-border);
  }

  .toc .toc-menu a:hover {
    color: var(--hebi-orange-light);
  }

  .toc .toc-menu a.is-active {
    background: rgb(232 109 57 / 15%);
    color: var(--hebi-orange-light);
  }

  .sidebar.toc .toc-menu a:focus {
    background: var(--hebi-dark-surface);
  }

  .toc.sidebar .toc-menu li.is-current-section > a:not(.is-active) {
    color: var(--hebi-dark-heading);
  }

  /* ---- Article text and links ---- */

  .doc {
    color: var(--hebi-dark-text);
  }

  .doc h1,
  .doc h3,
  .doc h4,
  .doc h5,
  .doc h6 {
    color: var(--hebi-dark-heading);
  }

  .doc h2 {
    color: var(--hebi-orange);
  }

  .doc h2:not(.discrete) {
    border-bottom-color: var(--hebi-dark-border);
  }

  .doc h1.sect0 {
    background: var(--hebi-dark-surface);
  }

  .doc a:hover {
    color: var(--hebi-orange-light);
  }

  .doc a.unresolved {
    color: #ff7b72;
  }

  .doc .colist > table code,
  .doc p code,
  .doc thead code {
    background: var(--hebi-dark-raised);
    color: var(--hebi-dark-heading);
  }

  .doc hr {
    border-color: var(--hebi-dark-border);
  }

  .doc kbd {
    background: var(--hebi-dark-raised);
    border-color: var(--hebi-dark-border);
    box-shadow: 0 1px 0 var(--hebi-dark-border), inset 0 0 0 0.1em var(--hebi-dark-surface);
  }

  /* Images are drawn for a white page: product photos are on white, and some drawings
     are black lines on a transparent background. Keep a white backing so nothing
     disappears, and dim everything so the white reads as a soft grey tile rather
     than a glaring box. */
  .doc .imageblock img,
  .doc span.image img {
    background: #fff;
    border-radius: 6px;
    filter: brightness(0.82) contrast(1.05);
  }

  /* Line drawings, block diagrams and plots opt in to being inverted with
     image::file.png[role=invert-dark] (see antora/README.md). hue-rotate turns the
     colours back to roughly their original hue, so red stays red and blue stays blue. */
  .doc .imageblock.invert-dark img,
  .doc span.image.invert-dark img {
    filter: invert(0.9) hue-rotate(180deg);
  }

  /* ---- Tables ---- */

  .doc table.tableblock,
  .doc table.tableblock > * > tr > * {
    border-color: var(--hebi-dark-border);
  }

  .doc table.stripes-all > tbody > tr,
  .doc table.stripes-even > tbody > tr:nth-of-type(2n),
  .doc table.stripes-hover > tbody > tr:hover,
  .doc table.stripes-odd > tbody > tr:nth-of-type(odd) {
    background: var(--hebi-dark-surface);
  }

  .doc table.tableblock > tfoot {
    background: var(--hebi-dark-surface);
  }

  /* ---- Admonitions, quotes, examples, sidebars ---- */

  .doc .admonitionblock td.content {
    background: var(--hebi-dark-surface);
  }

  /* Slate (light mode's NOTE colour) would disappear against the dark page. */
  .doc .admonitionblock td.icon i.icon-note {
    background-color: var(--hebi-grey);
  }

  #preamble .abstract blockquote {
    background: var(--hebi-dark-surface);
    border-left-color: var(--hebi-dark-border);
    color: var(--hebi-dark-text);
  }

  .doc .quoteblock,
  .doc .verseblock {
    background: var(--hebi-dark-surface);
    border-left-color: var(--hebi-dark-muted);
    color: var(--hebi-dark-muted);
  }

  .doc .quoteblock .attribution,
  .doc .admonitionblock .title,
  .doc .exampleblock .title,
  .doc .imageblock .title,
  .doc .listingblock .title,
  .doc .literalblock .title,
  .doc .openblock .title,
  .doc .videoblock .title,
  .doc table.tableblock caption,
  .doc details.result > summary {
    color: var(--hebi-dark-muted);
  }

  .doc .exampleblock > .content,
  .doc details.result > .content {
    background: var(--hebi-dark-bg);
    border-color: var(--hebi-dark-border);
  }

  .doc .sidebarblock {
    background: var(--hebi-dark-raised);
  }

  /* ---- Code blocks ---- */

  .doc .listingblock pre:not(.highlight),
  .doc .literalblock pre,
  .doc pre.highlight > code {
    background: var(--hebi-dark-surface);
    box-shadow: inset 0 0 1.75px var(--hebi-dark-border);
  }

  .doc .source-toolbox .copy-toast {
    background-color: var(--hebi-dark-text);
    color: var(--hebi-dark-bg);
  }

  .doc .source-toolbox .copy-toast::after {
    border-left-color: var(--hebi-dark-text);
  }

  /* highlight.js, GitHub dark colours */
  .hljs-comment,
  .hljs-quote,
  .hljs-meta {
    color: #8b949e;
  }

  .hljs-keyword,
  .hljs-selector-tag,
  .hljs-subst {
    color: #ff7b72;
  }

  .hljs-doctag,
  .hljs-string {
    color: #a5d6ff;
  }

  .hljs-section,
  .hljs-selector-id,
  .hljs-title,
  .hljs-class .hljs-title,
  .hljs-type {
    color: #d2a8ff;
  }

  .hljs-link,
  .hljs-regexp {
    color: #7ee787;
  }

  .hljs-bullet,
  .hljs-symbol,
  .hljs-built_in,
  .hljs-builtin-name,
  .hljs-number,
  .hljs-literal {
    color: #79c0ff;
  }

  .hljs-deletion {
    background: #490202;
  }

  .hljs-addition {
    background: #04260f;
  }

  /* ---- Tabs extension ---- */

  .tablist > ul li,
  .tabs.is-loading .tablist li:first-child::after,
  .tabs:not(.is-loading) .tablist li.is-selected::after,
  .tabpanel {
    background-color: var(--hebi-dark-bg);
  }

  .tabs.is-loading .tablist li:not(:first-child),
  .tabs:not(.is-loading) .tablist li:not(.is-selected) {
    background-color: var(--hebi-dark-surface);
  }

  .tablist > ul li,
  .tabpanel {
    border-color: var(--hebi-dark-border);
  }

  /* ---- Previous / next links ---- */

  nav.pagination {
    border-top-color: var(--hebi-dark-border);
  }

  nav.pagination span::before,
  nav.pagination a::after,
  nav.pagination a::before {
    color: var(--hebi-dark-muted);
  }

  /* ---- Header bar: stays slate; the search box and the phone menu go dark ---- */

  #search-input {
    background: var(--hebi-dark-bg);
    border-color: var(--hebi-dark-border);
    color: var(--hebi-dark-text);
  }

  #search-input:disabled {
    background-color: var(--hebi-dark-raised);
  }

  #search-input:disabled::placeholder {
    color: var(--hebi-dark-muted);
  }

  /* The UI only gives the menu a background on narrow screens, where it drops down
     below the header; from 1024px it sits inside the slate header bar. */
  @media screen and (max-width: 1023.5px) {
    .navbar-menu,
    .navbar-dropdown,
    .navbar .button {
      background: var(--hebi-dark-surface);
      border-color: var(--hebi-dark-border);
    }

    .navbar-menu {
      box-shadow: 0 8px 16px rgb(0 0 0 / 40%);
    }

    .navbar-item,
    .navbar-link,
    .navbar .button {
      color: var(--hebi-dark-text);
    }

    .navbar-menu .navbar-link:hover,
    .navbar-menu a.navbar-item:hover,
    .navbar-dropdown a.navbar-item:hover {
      background: var(--hebi-dark-raised);
    }

    .navbar-dropdown .navbar-item small {
      color: var(--hebi-dark-muted);
    }

    .navbar-divider {
      background-color: var(--hebi-dark-border);
    }
  }

  /* ---- Search results: search-ui.js injects search.css after this file, so "body" ---- */

  body .search-result-dataset {
    background: var(--hebi-dark-surface);
    border-color: var(--hebi-dark-border);
  }

  body .search-result-dropdown-menu {
    box-shadow: 0 1px 0 0 rgb(0 0 0 / 50%), 0 2px 6px 0 rgb(0 0 0 / 40%);
  }

  body .search-result-component-header {
    border-bottom-color: var(--hebi-dark-border);
    color: var(--hebi-dark-heading);
  }

  body .search-result-document-title {
    border-right-color: var(--hebi-dark-border);
    color: var(--hebi-dark-heading);
  }

  body .search-result-document-hit {
    color: var(--hebi-dark-muted);
  }

  body .search-result-document-hit .search-result-section-title {
    color: var(--hebi-dark-text);
  }

  body .search-result-document-hit > a:hover {
    background-color: rgb(232 109 57 / 10%);
  }

  body .search-result-document-hit .search-result-highlight {
    background: rgb(232 109 57 / 18%);
    color: var(--hebi-orange-light);
  }

  body #search-field .filter {
    background: var(--hebi-dark-surface) linear-gradient(180deg, var(--hebi-dark-border) 0, var(--hebi-dark-border)) no-repeat 0 / 1px 50%;
    border-color: var(--hebi-dark-border);
    color: var(--hebi-dark-muted);
  }
}
