/* Page structure ----------------------------------------------------------

+-----+-----------------+------+--------------+
|     | sidebar-chapter | main | sidebar-book |
+=====+=================+======+==============+
| sml | 12 (collapsed)  | 12   | -            |
| md  | 12 (collapsed)  | 9    | 3            |
| lg  | 3               | 7    | 2            |
+-----+-----------------+------+--------------+

Side uses container-fluid so we set up some additional breakpoints, to ensure
that the columns never get too wide, either individually or collectively.

*/


@media (min-width: 1200px) {
  .container-fluid {
    max-width: 95rem;
  }
  .container-fluid .row {
    justify-content: space-evenly;
  }
  .container-fluid main {
    max-width: 45rem;
  }
  .sidebar {
    max-width: 15rem;
  }

  /* Increase font-size for very wide devices */
  body {
    font-size: 18px
  }
}

main {margin-top: 1rem;}

@media (max-width: 991.98px) {
  .sidebar {
    max-width: 100%;
  }

  .collapse-lg {
    display: none;
    padding: 1rem;
    border-radius: 0.2rem;
    background: #fafafa;
    margin-top: 0.5rem;
    margin-bottom: 1rem;
    box-shadow: 5px 5px 10px rgba(0.1, 0.1, 0.1, 0.5);
    border: 1px solid var(--primary);
  }
  .book-toc {
    column-count: 2;
  }
  .sidebar-book, main {
    padding-left: 1rem;
  }
  .sidebar-book {
    margin-top: 1rem;
  }
}
@media (min-width: 992px) {
  .collapse-lg {
    display: block !important;
  }
}
.collapse-lg.show {
  display: block;
}

@media (min-width: 768px) {
  .sidebar-chapter {
    position: sticky;
    max-height: 100vh;
    top: 0;
    overflow-y: auto;
  }
}

@media (min-width: 992px) {
  .sidebar-book {
    position: sticky;
    max-height: 100vh;
    top: 0;
    overflow-y: auto;
  }
}

/* Chapter nav ----------------------------------------- */

.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 2rem;
}
.chapter-nav .prev, .chapter-nav .next {
  padding: 0.5rem;
  border: 1px solid #eee;
  border-radius: 0.2rem;
  box-shadow: 0 .5rem 1rem rgba(0,0,0,.15);
}
.chapter-nav .empty {
  border: none;
}
.chapter-nav .prev a:before {
  content: "« ";
}
.chapter-nav .next a:after {
  content: " »";
}

/* Sidebar ------------------------------------------------------ */

.sidebar h1, .sidebar h2 {
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}
.sidebar h1 {
  font-size: 1.1rem;
}
@media (max-width: 991.98px) {
  .sidebar h1 {
    font-size: 1.5rem;
    margin-top: 0rem;
  }
}
.sidebar h2 {
  font-size: 0.9rem;
}

.sidebar hr {
  margin: 0 0 0.5rem 0;
}

.sidebar li {
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.sidebar li.book-part {
  margin-top: 1rem;
}

.book-toc .active {
  font-weight: bolder;
}

.book-extra {
  border-top: 1px solid #ccc;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  font-size: 0.9rem;
}

.book-extra i {
  font-size: 1.2em;
}

/* Sticky footer ----------------------------------------- */
html, body {height: 100%}

body {
  display: flex;
  flex-direction: column;
}
.container-fluid {
  flex: 1 0 auto;
}
footer {
  flex-shrink: 0;
  font-size: 0.9rem;

}
footer a {
  text-decoration: underline;
}

/* Scrollspy --------------------------------------------- */

nav[data-toggle="toc"] .nav > li {
  margin-bottom: calc(0.5rem - 3px);
}

nav[data-toggle="toc"] .nav > li > a {
  padding: 3px;
  display: block;
}

nav[data-toggle="toc"] .nav > li > a:hover {
  text-decoration: underline;
}

nav[data-toggle="toc"] .nav a.nav-link.active,
nav[data-toggle="toc"] .nav .nav-link.active > li > a {
  background-color: #eee;
}

/* Nav: second level (shown on .active) */
nav[data-toggle="toc"] .nav-link + ul {
  display: none;
}
nav[data-toggle="toc"] .nav-link.active + ul {
  margin-top: 3px;
  display: block;
}

nav[data-toggle="toc"] .nav .nav > li {
  margin-bottom: 0;
}
nav[data-toggle="toc"] .nav .nav > li > a {
  margin-left: 10px;
}
/* Figures -------------------------------------------- */

.figure, .inline-figure {
  width: 100%;
  overflow-x: auto;
}

.inline-figure {
  border: solid 2px #f1f1f1;
  margin-bottom: 1rem; /* to match <p> */
}

.figure {
  border-top: 2px solid #eee;
  border-bottom: 2px solid #eee;
  margin:  1.5rem -0.5rem 1rem -0.5rem;
  padding: 1.5rem    0    1rem      1rem;
}

@media (max-width: 767.98px) {
  .figure {
    margin: 1.5rem -1rem 1.5rem -1rem;
    padding: 1.5rem;
    width: 100vw;
  }
}

caption, p.caption {
  text-align: left;
  margin-top: 1rem;
  margin-bottom: 0;
  font-size: 0.9rem;
  color: #777;
}

/* Headings -------------------------------------------- */

h2 {
  margin-top: 2rem;
  margin-bottom: 1rem;
  font-size: 1.5rem;
}
h3 { margin-top: 1.5em; font-size: 1.2rem; }
h4 { margin-top: 1.5em; font-size: 1.1rem; }
h5 { margin-top: 1.5em; font-size: 1rem; }

h1, h2, h3, h4, h5 {
  line-height: 1.3;
}

.header-section-number {
  color: #6C6C6C;
  font-weight: normal;
}

.dropdown-item .header-section-number {
  position: absolute;
  width: 2rem;
  left: -1rem;
  display: block;
  text-align: right;
}

.anchor {
  font-size: max(0.5em, 1rem);
  margin-left: 0.5rem;
  display: none;
}
h1:hover .anchor,
h2:hover .anchor,
h3:hover .anchor,
h4:hover .anchor,
h5:hover .anchor,
h6:hover .anchor {
  display: inline;
}

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

.inline-table {
  overflow-x: auto;
}

table.kable_wrapper td {
  vertical-align: top;
}


/* Footnotes --------------------------------------------- */

.popover {
  max-width: min(100vw, 32rem);
  font-size: 0.9rem;
  box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.3);
}
.popover-body {
  padding: 0.75rem;
}
.popover-body p:last-child {
  margin-bottom: 0;
}

a.footnote-ref {
  cursor: pointer;
}

/* Search ---------------------------------------------- */

mark {
  background: linear-gradient(-100deg,
    hsla(48,92%,75%,.3),
    hsla(48,92%,75%,.7) 95%,
    hsla(48,92%,75%,.1)
  )
}

.algolia-autocomplete .aa-hint {
  color: #999;
}
.algolia-autocomplete .aa-dropdown-menu {
  width: min(100%, 20rem);
  background-color: #fff;
  border: 1px solid var(--gray);
  border-radius: 0.2rem;
  margin-top: 2px;

  max-height: 50vh;
  overflow-y: auto;
}
.algolia-autocomplete .aa-dropdown-menu .aa-suggestion {
  cursor: pointer;
  padding: 5px 4px;
  border-bottom: 1px #ddd solid;
  font-size: 0.9rem;
}
.algolia-autocomplete .aa-dropdown-menu .aa-suggestion.aa-cursor {
  background-color: #B2D7FF;
}

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

pre {
  position: relative;
  overflow: auto;
  border: 1px solid #eee;
  padding: 0.5rem;
  margin: 0 -0.5rem 1rem -0.5rem;
  background-image: linear-gradient(160deg,#f8f8f8 0,#f1f1f1 100%);
}

@media (max-width: 767.98px) {
  /* Make background span full width on mobile */
  .section > .sourceCode > pre {
    margin: 0 -1rem 1rem -1rem;
    padding: 0.5rem 1rem;
    width: 100vw;
  }
}

code {
  background-color: #f8f8f8;
}

pre code {
  background-color: transparent;
  word-break: normal; /* force wide blocks to scroll, not wrap */
  word-wrap: normal;
}

pre, code {
  border-radius: 0.2rem;
  color: #212529; /* match text colour */
}
code a:any-link {
  color: inherit; /* use colour from syntax highlighting */
  text-decoration: underline;
  text-decoration-color: #ccc;
}

/* copy button */

div.sourceCode {
  position: relative;
}

.btn-copy {
  position: absolute;
  top: 0rem;
  right: -0.5rem; /* coherent with pre margin rule */
}

div.sourceCode > button {
  filter: opacity(50%);
}

div.sourceCode > button:hover {
  filter: opacity(100%);
}

div.sourceCode > button > i.bi::before {
  display: inline-block;
  height: 1rem;
  width: 1rem;
  content: "";
  vertical-align: -0.125em;
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/><path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/></svg>');
  background-repeat: no-repeat;
  background-size: 1rem 1rem;
}

div.sourceCode > button.btn-copy-checked > .bi::before {
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/></svg>');
}

/* https://github.com/rstudio/distill/blob/master/inst/rmarkdown/templates/distill_article/resources/a11y.theme + https://gist.github.com/hadley/f53b6e92df20994fdabe6562d284728a */
code span.ot {color:#007faa}
code span.at {color:#7d9029}
code span.ss {color:#bb6688}
code span.an {color:#545454;}
code span.fu {color:#4254A7}
code span.st {color:#008000}
code span.cf {color:#007faa;}
code span.op {color:#696969}
code span.er {color:#ff0000;}
code span.bn {color:#a1024a}
code span.al {color:#ff0000;}
code span.va {color:#19177c}
code span.bu {}
code span.ex {}
code span.pp {color:#bc7a00}
code span.in {color:#545454;}
code span.vs {color:#008000}
code span.wa {color:#545454; font-style: italic}
code span.do {color:#ba2121; font-style: italic}
code span.im {}
code span.ch {color:#008000}
code span.dt {color:#aa5d00}
code span.fl {color:#a1024a}
code span.co {color:#545454}
code span.cv {color:#545454; font-style: italic}
code span.cn {color:#d91e18}
code span.sc {color:#008000}
code span.dv {color:#a1024a}
code span.kw {color:#007faa;}

/* Misc typography ---------------------------------------------- */

a {
  overflow-wrap: break-word;
  word-wrap: break-word;
}

blockquote {
  border-left: 0.5rem solid #eee;
  padding-left: 0.5rem;
  margin-left: -0.5rem;
}

body {
  line-height: 1.6;
}

.smallcaps {
  font-variant: small-caps;
}

/* special callout blocks */

.rmdnote, .rmdcaution, .rmdimportant, .rmdtip, .rmdwarning {
  margin: 1rem calc(-2px - 0.5em);
  padding: 1rem;
  border: 2px solid #eee;
}

.rmdnote > *:last-child, .rmdcaution > *:last-child, .rmdimportant > *:last-child, .rmdtip > *:last-child, .rmdwarning > *:last-child {
  margin-bottom: 0;
}

@media (max-width: 767.98px) {
  .rmdnote, .rmdcaution, .rmdimportant, .rmdtip, .rmdwarning {
    margin: 1rem -1rem;
    border-width: 4px;
  }
}

.rmdnote {
  border-color: var(--primary);
}
.rmdimportant {
  border-color: var(--success);
}
.rmdcaution {
  border-color: var(--danger);
}
.rmdwarning {
  border-color: var(--warning);
}
.rmdtip {
  border-color: var(--info);
}

.rmdcaution pre, .rmdimportant pre, .rmdnote pre, .rmdtip pre, .rmdwarning pre {
  /* Make code blocks full width in rmdnote */
  margin: 0 -1rem 1rem -1rem;
  padding: 1rem;
}

.rmdcaution .btn-copy, .rmdimportant .btn-copy, .rmdnote .btn-copy, .rmdtip .btn-copy, .rmdwarning .btn-copy {
  /* Needs to be set according to margin in callout pre block */
  right: -1rem;
}

main ul {
 list-style-type: square;
}
main ol, main ul {
  padding-left: 25px;
  margin-bottom: 0;
}
main li {
  margin-bottom: 0.5rem;
}
main ol > li:first-child, main ul > li:first-child {
  margin-top: 0.5rem;
}

/* Cover image */

img.cover {
  float: right;
  margin: 0 1rem 0 1rem;
  box-shadow: 0 .5rem 1rem rgba(0,0,0,.15);
}
@media (max-width: 767.98px) {
  img.cover {
    float: none;
    display: block;
    margin: 0 auto 1rem auto;
  }
}
