/* ==========================================================================
   InfoRapid KnowledgeBase Builder – User Guide
   Custom styles for the left-hand navigation (table of contents)

   Goal: give the flat section list a visible hierarchy again.
   Material's "navigation.sections" feature renders top-level entries as
   section labels and deliberately removes the indentation of their children,
   so section and page ended up at the exact same x position. Here we add
     * automatic chapter numbering (1, 2, 2.1, 2.2 ...) via CSS counters
     * real indentation for the pages inside a section
     * a calmer, more "chapter like" look for the section headers
   Everything is purely visual – no Markdown file needs to change, and the
   numbering follows the nav order in mkdocs.yml in every language.
   ========================================================================== */

:root {
  /* Width of the number column for the pages. Measured, not guessed: the
     widest two-digit number ("4.12") renders 35.4px wide, which is 1.77rem –
     at 1.35rem every entry from 4.10 on pushed its title 8px out of the
     column. Numbers scale with rem just like the text, so a rem value keeps
     the alignment across the theme's different root font sizes.
     The numbers are set right aligned inside that column (text-align: right
     further down). Left aligned, a short number like "4.1" left a gap of
     roughly 18px to its title while "4.12" left 9px – the column has to be as
     wide as the widest number, and the difference showed up as empty space. */
  --kbb-nav-number-width: 1.8rem;
  /* Third level: "4.10.1" measures 50.1px = 2.51rem. */
  --kbb-nav-number-width-sub: 2.55rem;
  /* Chapter numbers are single digits and need far less room. */
  --kbb-nav-number-width-top: 0.55rem;
  /* Indentation of the pages inside a section. */
  --kbb-nav-indent: 0.7rem;
  /* Distance between the number and the title. */
  --kbb-nav-number-gap: 0.25rem;
}

/* The colours of the numbers are NOT given a default here on purpose.
   Material puts data-md-color-scheme on <body>, so on <html> (= :root) the
   scheme dependent variables still hold their light mode values. Declaring
   --kbb-nav-page-number-color: var(--md-default-fg-color--light) at :root
   froze black at 54% and inherited it into the dark scheme, where the page
   numbers ended up at a contrast of 1.1:1 – black on black.
   The scheme dependent default therefore lives in the var() fallback inside
   the rules below, where it is resolved on the element that actually uses it.
   Only the overrides are declared as variables. */

/* Indigo on the dark background only reaches a contrast of about 1.9:1 and the
   chapter numbers become nearly invisible – use a light indigo there instead. */
[data-md-color-scheme="slate"] {
  --kbb-nav-number-color: #8c9eff;
}

/* On the highlighted entry the number takes the colour of the pill's text. */
.md-nav--primary .md-nav__link--active {
  --kbb-nav-number-color: currentColor;
  --kbb-nav-page-number-color: currentColor;
}

/* --------------------------------------------------------------------------
   1. Counters
   -------------------------------------------------------------------------- */

/* Reset the chapter counter once per sidebar. */
.md-nav--primary > .md-nav__list {
  counter-reset: kbb-section;
}

/* Every top level entry is a chapter and starts its own page counter. */
.md-nav--primary > .md-nav__list > .md-nav__item {
  counter-increment: kbb-section;
  counter-reset: kbb-page;
}

/* Every entry inside a section is a numbered page and opens its own counter
   for the third level (a page that is reached from inside another menu). */
.md-nav--primary > .md-nav__list > .md-nav__item > .md-nav > .md-nav__list > .md-nav__item {
  counter-increment: kbb-page;
  counter-reset: kbb-sub;
}

/* Third level: 4.6.1, 4.10.1 ... */
.md-nav--primary > .md-nav__list > .md-nav__item > .md-nav > .md-nav__list > .md-nav__item > .md-nav:not(.md-nav--secondary) > .md-nav__list > .md-nav__item {
  counter-increment: kbb-sub;
}

/* --------------------------------------------------------------------------
   2. Rendering the numbers
   The section header is either a <label> (plain section) or, with
   navigation.indexes enabled, an <a> inside a .md-nav__container <div>.
   Selecting the element types explicitly avoids numbering the container twice.
   -------------------------------------------------------------------------- */

.md-nav--primary > .md-nav__list > .md-nav__item > a.md-nav__link::before,
.md-nav--primary > .md-nav__list > .md-nav__item > label.md-nav__link::before,
.md-nav--primary > .md-nav__list > .md-nav__item > .md-nav__container > a.md-nav__link::before {
  content: counter(kbb-section);
  flex: 0 0 auto;
  min-width: var(--kbb-nav-number-width-top);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: right;
  color: var(--kbb-nav-number-color, var(--md-primary-fg-color));
}

.md-nav--primary > .md-nav__list > .md-nav__item > .md-nav > .md-nav__list > .md-nav__item > a.md-nav__link::before,
.md-nav--primary > .md-nav__list > .md-nav__item > .md-nav > .md-nav__list > .md-nav__item > label.md-nav__link::before,
.md-nav--primary > .md-nav__list > .md-nav__item > .md-nav > .md-nav__list > .md-nav__item > .md-nav__container > a.md-nav__link::before {
  content: counter(kbb-section) "." counter(kbb-page);
  flex: 0 0 auto;
  min-width: var(--kbb-nav-number-width);
  font-variant-numeric: tabular-nums;
  font-weight: 400;
  text-align: right;
  color: var(--kbb-nav-page-number-color, var(--md-default-fg-color--light));
}

/* Third level – pages that are not a button of their own but sit inside the
   panel of the button above them (4.6.1 Tags, 4.10.1 Memorize Items). */
.md-nav--primary > .md-nav__list > .md-nav__item > .md-nav > .md-nav__list > .md-nav__item > .md-nav:not(.md-nav--secondary) > .md-nav__list > .md-nav__item > a.md-nav__link::before,
.md-nav--primary > .md-nav__list > .md-nav__item > .md-nav > .md-nav__list > .md-nav__item > .md-nav:not(.md-nav--secondary) > .md-nav__list > .md-nav__item > label.md-nav__link::before,
.md-nav--primary > .md-nav__list > .md-nav__item > .md-nav > .md-nav__list > .md-nav__item > .md-nav:not(.md-nav--secondary) > .md-nav__list > .md-nav__item > .md-nav__container > a.md-nav__link::before {
  content: counter(kbb-section) "." counter(kbb-page) "." counter(kbb-sub);
  flex: 0 0 auto;
  min-width: var(--kbb-nav-number-width-sub);
  font-variant-numeric: tabular-nums;
  font-weight: 400;
  text-align: right;
  color: var(--kbb-nav-page-number-color, var(--md-default-fg-color--light));
}

/* The title of the sidebar itself must not take part in the numbering. */
.md-nav--primary > .md-nav__title::before {
  content: none;
}

/* --------------------------------------------------------------------------
   3. Indentation and spacing
   -------------------------------------------------------------------------- */

/* Pages of a section move to the right, the number column stays readable. */
.md-nav--primary > .md-nav__list > .md-nav__item > .md-nav {
  padding-left: var(--kbb-nav-indent);
  margin-top: 0;
}

/* Third level indents once more, but less – the longer number already sets
   it apart, and the sidebar is narrow. */
.md-nav--primary > .md-nav__list > .md-nav__item > .md-nav > .md-nav__list > .md-nav__item > .md-nav {
  padding-left: 0;
  margin-top: 0;
  margin-bottom: 0;
}

/* A little more air between the chapters – but only between them. */
.md-nav--primary > .md-nav__list > .md-nav__item--section {
  margin-top: 0.7rem;
}

.md-nav--primary > .md-nav__list > .md-nav__item--section:first-child {
  margin-top: 0;
}

/* Tighter rhythm: Material puts margin-top: .625em on every nav link, which
   together with its own padding adds up to a lot of empty space in a list of
   25 entries. Halve the margin and drop the extra padding. */
.md-nav--primary .md-nav__link {
  line-height: 1.3;
  margin-top: 0.25rem;
  padding-top: 0;
  padding-bottom: 0;
  gap: var(--kbb-nav-number-gap);
}

@media screen and (min-width: 76.25em) {
  /* The sidebar repeats the site name, which already sits in the header. */
  .md-sidebar--primary .md-nav--primary > .md-nav__title {
    display: none;
  }

  .md-sidebar--primary .md-nav--primary > .md-nav__list {
    padding-top: 0;
  }

  /* No collapse arrow on the nested groups (4.6, 4.10). The chapters one level
     up have no such control either, and with two sub-entries in total there is
     nothing worth folding away. */
  .md-nav--primary .md-nav__item--nested > .md-nav__container > label.md-nav__link {
    display: none;
  }

  /* Material collapses on the desktop via grid-template-rows and
     visibility: collapse. With the control gone the open state has to be
     forced, otherwise it would depend on a checkbox nobody can reach. */
  .md-nav--primary .md-nav__toggle ~ .md-nav {
    grid-template-rows: 1fr;
    opacity: 1;
    visibility: visible;
    transition: none;
  }

  .md-nav--primary .md-nav__toggle ~ .md-nav > .md-nav__list {
    overflow: visible;
  }

  /* Material's list padding would leave extra air below the last sub-entry. */
  .md-nav--primary .md-nav__item--nested:not(.md-nav__item--section) > .md-nav > .md-nav__list {
    padding-bottom: 0;
  }

  /* The container <div> of an index entry carries the class md-nav__link
     itself, so the margin-top set further up applies twice – once to the
     container, once to the <a> inside it. */
  .md-nav--primary .md-nav__container > .md-nav__link {
    margin-top: 0;
  }
}

/* --------------------------------------------------------------------------
   3b. The drawer on narrow screens

   Material turns the whole navigation into a stack of sliding panels there:
   every section and every nested group opens as its own screen with a back
   arrow, so the reader only ever sees one level at a time. The rules below
   lay the same tree out inline, exactly as on the desktop.

   One thing must stay untouched: on narrow screens Material embeds the page's
   own table of contents into the drawer as .md-nav--secondary. That one keeps
   its collapsible behaviour – it is page content, not a menu level, and the
   counters must not number it either (see the :not() in the selectors above).
   -------------------------------------------------------------------------- */

@media screen and (max-width: 76.2344em) {
  .md-nav--primary .md-nav:not(.md-nav--secondary) {
    position: static;
    height: auto;
    background: none;
    z-index: auto;
    transform: none;
    opacity: 1;
    transition: none;
    display: block;
  }

  /* The panel headings (back arrow + repeated section name) become pointless
     once the levels are laid out inline. Direct child only – as a descendant
     selector this also caught the table of contents' own heading. */
  .md-nav--primary .md-nav:not(.md-nav--secondary) > .md-nav__title {
    display: none;
  }

  /* No "pancake" view: Material puts the page's own table of contents into the
     drawer, reachable through a toggle on the highlighted entry. That toggle
     is a <label>, and the real link next to it is hidden while it exists – so
     tapping it replaced the menu with the page outline and nothing led back.
     Hide the toggle and its table of contents, show the real link instead.
     The selectors are Material's own, otherwise its attribute selector
     ([for="__toc"], four components) wins and nothing changes. */
  .md-nav--primary .md-nav__link[for="__toc"] ~ .md-nav {
    display: none;
  }

  .md-nav--primary .md-nav__link[for="__toc"] {
    display: none;
  }

  .md-nav--primary .md-nav__link[for="__toc"] + .md-nav__link {
    display: flex;
  }

  /* Same as on the desktop: no collapse control on the nested groups. */
  .md-nav--primary .md-nav__item--nested > .md-nav__link .md-nav__icon,
  .md-nav--primary .md-nav__item--nested > .md-nav__container > label.md-nav__link {
    display: none;
  }

  .md-nav--primary > .md-nav__list > .md-nav__item > .md-nav {
    padding-left: var(--kbb-nav-indent);
  }

  .md-nav--primary .md-nav__container > .md-nav__link {
    margin-top: 0;
  }
}

/* --------------------------------------------------------------------------
   4. Section headers as chapter headings
   -------------------------------------------------------------------------- */

.md-nav--primary > .md-nav__list > .md-nav__item--section > label.md-nav__link,
.md-nav--primary > .md-nav__list > .md-nav__item--section > .md-nav__container > a.md-nav__link {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--md-default-fg-color);
  margin-bottom: 0.15rem;
}

/* Keep the section header clickable-looking when it has an index page. */
.md-nav--primary > .md-nav__list > .md-nav__item--section > .md-nav__container > a.md-nav__link:hover {
  color: var(--md-accent-fg-color);
}

/* --------------------------------------------------------------------------
   5. Active page: a soft pill instead of just coloured text
   -------------------------------------------------------------------------- */

/* .md-nav__item steht mit drin, weil Material im Schmalmodus mit
   ".md-nav--primary .md-nav__item--active > .md-nav__link" nachfaerbt – drei
   Klassen. Ohne den Zusatz gewinnt Materials Regel und der Text auf der
   blauen Pille wird indigo auf indigo. */
.md-nav--primary .md-nav__item .md-nav__link--active,
.md-nav--primary .md-nav__item .md-nav__link--active:hover {
  background-color: var(--md-primary-fg-color--light);
  color: var(--md-primary-bg-color);
  border-radius: 0.15rem;
}

/* The padding trick only on the desktop. In the drawer Material already gives
   every entry a left padding of 0.8rem; overriding it with 0.3rem pulled the
   highlighted entry 16px out of the column all the others line up in. */
@media screen and (min-width: 76.25em) {
  .md-nav--primary .md-nav__item .md-nav__link--active,
  .md-nav--primary .md-nav__item .md-nav__link--active:hover {
    padding-left: 0.3rem;
    padding-right: 0.3rem;
    margin-left: -0.3rem;
  }
}

/* The colour itself comes from the --kbb-nav-*-color overrides at the top of
   this file; a plain descendant selector would lose against the long chains
   used for the counters. */

/* --------------------------------------------------------------------------
   6. Content typography – slightly tighter than the Material default

   Material ships with line-height 1.6 and 1.25em margins around every block,
   which reads airy on short marketing pages but wastes a lot of screen on a
   long reference manual. The values below tighten the rhythm a little without
   making the text feel cramped.
   -------------------------------------------------------------------------- */

.md-typeset {
  line-height: 1.55;
}

/* The heading and its first paragraph belong together. */
.md-typeset h1 {
  margin-bottom: 0.55em;
  line-height: 1.25;
}

.md-typeset h2 {
  margin-top: 1.3em;
  margin-bottom: 0.5em;
  line-height: 1.3;
}

.md-typeset h3 {
  margin-top: 1.1em;
  margin-bottom: 0.4em;
}

.md-typeset h4,
.md-typeset h5,
.md-typeset h6 {
  margin-top: 0.9em;
  margin-bottom: 0.35em;
}

.md-typeset p,
.md-typeset ul,
.md-typeset ol,
.md-typeset blockquote {
  margin-top: 0.8em;
  margin-bottom: 0.8em;
}

.md-typeset li {
  margin-bottom: 0.35em;
}

.md-typeset li > ul,
.md-typeset li > ol {
  margin-top: 0.35em;
  margin-bottom: 0.35em;
}

/* Horizontal rules separate sections – they do not need this much room. */
.md-typeset hr {
  margin: 1.2em 0;
}

/* Screenshots sit closer to the text they illustrate. */
.md-typeset img {
  margin-top: 0.4em;
  margin-bottom: 0.4em;
}

/* --------------------------------------------------------------------------
   7. Small polish for individual components
   -------------------------------------------------------------------------- */

/* Grid cards used on the section overview pages. */
.md-typeset .grid.cards > ul > li {
  border-radius: 0.3rem;
}

/* Keyboard keys (pymdownx.keys) a bit more like real caps. */
.md-typeset kbd {
  font-size: 0.85em;
}

/* The ¶ behind a heading copies a link to that section. On the page title it
   has no purpose: the page URL already points there and the page is already
   scrolled to the top, so clicking it looks like nothing happens. Keep it on
   h2 and below, drop it on h1.
   To switch the anchors off completely, remove "permalink: true" from the toc
   extension in mkdocs.yml – then this rule becomes obsolete as well. */
.md-typeset h1 .headerlink {
  display: none;
}

/* The right hand table of contents follows the same tighter rhythm. */
.md-nav--secondary .md-nav__link {
  margin-top: 0.3rem;
  line-height: 1.3;
}

/* --------------------------------------------------------------------------
   8. Dark mode contrast

   Material's slate scheme puts the body text at 82% opacity (8.93:1) but the
   headings at 56% (4.92:1) – the largest element on the page ends up as the
   palest one, which is what makes the dark mode look washed out. The values
   below lift the foreground and darken the background a little, and give the
   headings the same colour as the body text:

       body text  8.93:1  ->  11.87:1
       heading    4.92:1  ->  11.87:1

   Deliberately not pure white on pure black (that would be ~14:1) – at that
   ratio light text on a dark ground starts to bloom in longer passages.
   -------------------------------------------------------------------------- */

[data-md-color-scheme="slate"] {
  --md-default-bg-color: hsla(var(--md-hue), 15%, 12%, 1);
  --md-default-fg-color: hsla(var(--md-hue), 15%, 95%, 0.88);
  --md-default-fg-color--light: hsla(var(--md-hue), 15%, 95%, 0.74);
  --md-default-fg-color--lighter: hsla(var(--md-hue), 15%, 95%, 0.4);
  --md-typeset-color: var(--md-default-fg-color);
}

/* Material dims h1 to --md-default-fg-color--light in every scheme. On the
   dark background that reads as an unfinished headline. */
[data-md-color-scheme="slate"] .md-typeset h1 {
  color: var(--md-default-fg-color);
}

/* --------------------------------------------------------------------------
   9. Rules: tables and section separators

   Material draws every rule far too faintly to see:

       table rules   12% opacity  ->  1.32:1 light / 1.40:1 dark
       <hr>           7% opacity  ->  1.17:1 light / 1.37:1 dark

   WCAG asks for 3:1 on the boundaries of non-text content, so both were well
   below it, and in the dark scheme practically invisible. Material also draws
   no vertical table rules at all, which lets the two key columns of the
   shortcut tables (Windows | Mac) run into each other.

   One shared colour for both, so tables and separators stay a family. Not
   pushed beyond 3:1 on purpose – heavier rules make the shortcut tables read
   like a spreadsheet.

   The selectors mirror Material's own so the specificity matches; extra.css is
   loaded after the theme and therefore wins on source order. Note that these
   are scheme level declarations, not :root ones – see the comment at the top
   of this file for why that distinction matters.
   -------------------------------------------------------------------------- */

:root,
[data-md-color-scheme="default"] {
  --kbb-rule-color: rgba(0, 0, 0, 0.42); /* 3.04:1 */
  --md-typeset-table-color: var(--kbb-rule-color);
}

[data-md-color-scheme="slate"] {
  --kbb-rule-color: hsla(var(--md-hue), 15%, 95%, 0.35); /* 2.99:1 */
  --md-typeset-table-color: var(--kbb-rule-color);
}

/* Vertical rules between the columns – not on the first cell of a row. */
.md-typeset table:not([class]) td + td,
.md-typeset table:not([class]) th + th {
  border-left: 0.05rem solid var(--md-typeset-table-color);
}

/* Section separators. Material uses --md-default-fg-color--lightest here,
   which is a different (and even paler) variable than the table colour. */
.md-typeset hr {
  border-bottom-color: var(--kbb-rule-color);
}
