/*
 * Dokka theme overrides aligning the API reference with the project's Zensical site
 * (Material Design 3 chrome: indigo primary, slate dark, Inter + JetBrains Mono).
 *
 * Companion to dokka-zensical-chrome.js, which rewrites the page DOM at load time to
 * produce real .md-* scaffolding. This stylesheet (a) loads the Material fonts, (b)
 * hides Dokka's native chrome so it doesn't flash, (c) overrides Dokka's CSS variables
 * for both light and dark schemes, (d) keeps Dokka content tables visible inside the
 * Material content area.
 *
 * Loaded via Dokka 2.x `pluginsConfiguration.html.customStyleSheets` in
 * compose-highlight/build.gradle.kts. See compose-highlight/dokka-theme/README.md.
 */

@import url("https://fonts.googleapis.com/css?family=Inter:300,400,500,700&family=JetBrains+Mono:400,500,700&display=fallback");

/* ── Hide Dokka's native chrome ─────────────────────────────────────────────
 * The chrome script wraps Dokka's #content inside Material scaffolding. Hide Dokka's
 * old top header and sidebar source-of-truth so they don't flash or render twice.
 *
 * The Dokka `#leftColumn` sidebar source is also hidden — our chrome script reads
 * `navigation.html` directly, so the in-DOM sidebar is redundant.
 *
 * Critical: we do NOT hide #filter-section or #searchBar with display:none. Dokka's
 * platform-content-handler.js initializes filter buttons in #filter-section on
 * window.load and walks .main-content for member visibility. If #filter-section's
 * children are display:none Dokka's init aborts and the Members section never shows.
 * Same kind of trap with #searchBar — it must remain interactive so we can delegate
 * Material's search icon clicks to it. Hide them off-screen instead.
 */
#navigation-wrapper,
#leftColumn,
.library-name,
.navigation-controls--break,
/* Dokka's stock footer (.footer with go-to-top + copyright) — replaced by our
 * Material .md-footer-meta block injected inside .md-container. */
#main > .footer,
.footer--container {
    display: none !important;
}
/* #filter-section: kept addressable but visually pushed off-screen so
 * platform-content-handler.js can populate it without it appearing on-page.
 * Children stay un-pointer-event-disabled so its filter-button init walks. */
#filter-section {
    position: absolute !important;
    left: -10000px !important;
    top: 0 !important;
    pointer-events: none;
}

/* #searchBar: kept addressable via off-screen positioning. The Material icon
 * at [data-search-trigger] is the visible click target; the chrome script
 * delegates to the inner #pages-search programmatically. */
#searchBar {
    position: absolute !important;
    left: -10000px !important;
    top: 0 !important;
    pointer-events: none !important;
}

/* Ring UI's search popup is rendered via a React portal into a target div
 * appended to <body>, with the popup positioned via inline `top: 0; left: 0`
 * but offset upward by a JS-applied `margin-top: -<height>px`. The trigger
 * (#searchBar) is off-screen at left:-10000, so the popup ends up at
 * viewport y = -<popupHeight + ~42> with the input row clipped above
 * viewport.
 *
 * Override the inline positioning so the popup pins to the top-right of the
 * viewport, just below the Material header. The popup-wrapper class targets
 * Ring UI's popup container; the rule only matches when the popup is mounted
 * (which is on demand, not at page load). */
[data-test="ring-popup"][data-test-direction="bottom-right"] {
    position: fixed !important;
    top: 3.5rem !important;       /* below the Material header (~3rem) */
    right: 1rem !important;
    left: auto !important;
    bottom: auto !important;
    margin: 0 !important;
    max-width: min(640px, calc(100vw - 2rem)) !important;
    max-height: calc(100vh - 5rem) !important;
    z-index: 1000 !important;
}

/* The chrome script removes Dokka's <header id="navigation-wrapper"> from the page
 * entirely once the wrap is done; until then this rule keeps it from showing.
 */

/* Dokka's #main container needs to lose its native flex layout so our injected
 * .md-container can use Material's grid. We also force a column-flex layout so
 * the footer at the bottom of #main always sits below .md-container — without
 * this, short pages let .md-container collapse to its content height while the
 * sticky sidebar inside it paints all the way down, leaving the footer drawn
 * on top of the sidebar. */
#main {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: none !important;
    grid-template-rows: none !important;
    flex: 1 1 auto !important;
    overflow: visible !important;
}
#main > .md-container {
    flex: 1 0 auto;
}
/* Constrain the sticky sidebar's internal scroll area so it never paints past
 * the viewport's lower edge. Without this, .md-sidebar__scrollwrap takes the
 * full intrinsic height of its content (~750px+ for packages with many types),
 * paints downward beyond the row, and overlaps the footer on short pages.
 *
 * Material's default sidebar uses position:fixed below a media-query
 * breakpoint, where height is bounded explicitly. Our retheme keeps it
 * position:sticky throughout, so we have to bound it ourselves: viewport
 * height minus the header bar (~3rem), with internal scrolling for overflow.
 */
.md-sidebar.md-sidebar--primary {
    height: calc(100vh - 3rem);
}
.md-sidebar.md-sidebar--primary .md-sidebar__scrollwrap {
    max-height: 100%;
    overflow-y: auto;
}

/* The injected article wraps Dokka's #content. Strip Dokka's outer paddings so
 * .md-content__inner spacing wins, then add a sidebar-to-content gutter on the
 * outer .md-content__inner so the article breathes away from the sidebar
 * border. Material's default has zero gap between the two; Dokka pages benefit
 * from a clearer separation. */
.md-content__inner #content {
    padding: 0 !important;
    margin: 0 !important;
}
.md-content__inner {
    padding-left: 1.5rem !important;
}

/* ── Light scheme (Zensical "default") ─────────────────────────────────────── */
:root {
    /* Typography — match Material's Inter + JetBrains Mono stack. */
    --default-font-family: "Inter", "Helvetica", "Arial", system-ui, sans-serif;
    --default-monospace-font-family: "JetBrains Mono", SFMono-Regular, Consolas,
        "Liberation Mono", Menlo, monospace;
    --default-font-size: 16px;

    /* Surfaces — match Material light: pure white body, subtle gray accents. */
    --background-color: #ffffff;
    --default-white: #ffffff;
    --default-gray: #f5f5f5;
    --default-font-color: rgba(0, 0, 0, 0.87);
    --header-font-color: rgba(0, 0, 0, 0.87);

    /* Brand — Material indigo 500 / 600. */
    --color-key-blue: #3f51b5;
    --color-key-blue-hover: #5c6bc0;
    --hover-link-color: #3f51b5;
    --active-tab-border-color: #3f51b5;
    --active-section-color: #3f51b5;
    --sidemenu-section-active-color: #3f51b5;

    /* Borders & subtle backgrounds — Material spec values. */
    --border-color: rgba(0, 0, 0, 0.12);
    --blockquote-background: rgba(63, 81, 181, 0.04);
    --navigation-highlight-color: rgba(63, 81, 181, 0.08);
    --color-background-inline-code: rgba(0, 0, 0, 0.04);
    --color-background-code-block: rgba(0, 0, 0, 0.04);
}

/* ── Dark scheme (Zensical "slate") ────────────────────────────────────────── */
.theme-dark {
    /* Material slate hue — warm dark gray, not pitch black. */
    --background-color: #1e2129;
    --default-white: #1e2129;
    --color-dark: #2a2e3a;
    --default-font-color: rgba(255, 255, 255, 0.92);
    --header-font-color: rgba(255, 255, 255, 0.92);

    /* Indigo 400 reads better than 500 on dark. */
    --color-key-blue: #7986cb;
    --color-key-blue-hover: #9fa8da;
    --hover-link-color: #7986cb;
    --active-tab-border-color: #7986cb;
    --active-section-color: var(--default-font-color);
    --sidemenu-section-active-color: #2a2e3a;

    --border-color: rgba(255, 255, 255, 0.12);
    --blockquote-background: rgba(255, 255, 255, 0.04);
    --navigation-highlight-color: rgba(121, 134, 203, 0.12);
    --color-background-inline-code: rgba(255, 255, 255, 0.08);
    --color-background-code-block: rgba(0, 0, 0, 0.32);
}

/* ── Material container width inside Dokka content ──────────────────────────
 * Dokka constrains content to ~1280px; Material's grid is similar but uses
 * different selectors. Let the Material CSS bundle handle this for the new
 * scaffolding; just stop Dokka's content from constraining itself a second time.
 */
.md-content #content {
    max-width: none !important;
    width: 100% !important;
}

/* ── Primary sidebar width ──────────────────────────────────────────────────
 * Material's default `.md-sidebar` width is 12.1rem (~194px), which truncates
 * names like "HighlightLanguageInfo" and "ThemedHighlightResult" with ellipsis.
 * Bump to 16rem (~256px) so the canonical type names render in full. The
 * media-query rule that hides the sidebar offscreen on narrow viewports also
 * uses 12.1rem, so override that one too — otherwise the sidebar would peek
 * out from the left edge before the breakpoint kicks in.
 */
.md-sidebar.md-sidebar--primary {
    width: 16rem;
}
@media screen and (max-width: 76.234375em) {
    [dir="ltr"] .md-sidebar.md-sidebar--primary { left: -16rem; }
    [dir="rtl"] .md-sidebar.md-sidebar--primary { right: -16rem; }
}

/* ── Sidebar: nesting + expand/collapse + type icons ────────────────────────
 * Dokka emits class-type icons (.toc--icon.class-kt etc.) from ui-kit.min.css,
 * which our chrome script clones into each .md-nav__link. Make them render at
 * a sane size and aligned with the link text.
 */
.md-sidebar--primary .md-nav__icon-type {
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-right: 8px;
    flex-shrink: 0;
    /* Override Dokka's stock .toc--icon { line-height: 32px } which pushes the
     * icon's content box down inside our flex row. With line-height: 1 the
     * icon image and the text baseline center cleanly via align-items:center. */
    line-height: 1;
}
.md-sidebar--primary .md-nav__link {
    display: flex;
    align-items: center;
}

/* Hide the generated checkbox; show only the chevron <label> as the toggle UI. */
.md-sidebar--primary .md-nav__toggle {
    display: none;
}

/* Row that holds the link + chevron in one flex strip, so margin-left:auto on
 * the chevron pushes it to the right edge. Each nested item lays out its row
 * via this wrapper; non-nested items render the link directly without a row. */
.md-sidebar--primary .md-nav__row {
    display: flex;
    align-items: center;
}
.md-sidebar--primary .md-nav__row > .md-nav__link {
    flex: 1 1 auto;
    min-width: 0;  /* allow the link to shrink so chevron stays visible */
}

/* The chevron sits inline with the link, opposite the icon. The arrow-down.svg
 * Dokka ships is white-filled (intended for dark theme); invert it in light mode
 * so the arrow is dark on a light background, leave natural for dark theme. */
.md-sidebar--primary .md-nav__chevron {
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
    margin-right: 8px;
    cursor: pointer;
    background-image: url("../images/arrow-down.svg");
    background-position: center;
    background-repeat: no-repeat;
    background-size: 14px;
    transform: rotate(0);
    transition: transform 150ms ease;
    padding: 0 !important;
    opacity: 0.6;
    filter: invert(1);
}
.theme-dark .md-sidebar--primary .md-nav__chevron {
    filter: none;
}
.md-sidebar--primary .md-nav__chevron:hover {
    opacity: 1;
}
.theme-dark .md-sidebar--primary .md-nav__chevron {
    filter: invert(1);
}
/* When the hidden checkbox is checked, the parent <li> matches :has(:checked).
 * Use :has() to reach across DOM levels (chevron is inside .md-nav__row, while
 * toggle is at li-level — they're not direct siblings). */
.md-sidebar--primary .md-nav__item--nested:has(> .md-nav__toggle:checked) > .md-nav__row > .md-nav__chevron {
    transform: rotate(180deg);
}

/* Nested <nav> is collapsed by default. The expand-toggle's :checked state on the
 * SAME LI as the nav reveals it. */
.md-sidebar--primary .md-nav__item--nested > .md-nav {
    display: none;
}
.md-sidebar--primary .md-nav__item--nested > .md-nav__toggle:checked ~ .md-nav {
    display: block;
}

/* Indent each nesting level a bit; Material defaults are ~12px which feels too far. */
.md-sidebar--primary .md-nav .md-nav {
    padding-left: 8px;
    border-left: 1px solid var(--border-color);
    margin-left: 12px;
}

/* Density: shrink padding so more items fit on screen. Dokka's stock sidebar runs
 * at ~24px row height; Material's defaults are ~36px. Compromise at ~28px. */
.md-sidebar--primary .md-nav__item {
    margin: 0;
    padding: 0;
}
.md-sidebar--primary .md-nav__link {
    padding: 4px 8px !important;
    font-size: 0.78rem !important;
    line-height: 1.5 !important;
    margin: 0 !important;
}

/* Active item: switch from Material's pale lavender to a more prominent indigo.
 * The 0.16 alpha keeps it Material-compliant (vs Dokka's solid blue) while making
 * the current page unmistakably visible. */
.md-sidebar--primary .md-nav__link--active {
    background-color: rgba(63, 81, 181, 0.16);
    color: var(--color-key-blue) !important;
    font-weight: 500;
    border-radius: 4px;
}
.theme-dark .md-sidebar--primary .md-nav__link--active {
    background-color: rgba(121, 134, 203, 0.24);
    color: var(--color-key-blue) !important;
}

/* ── Tweaks Dokka does not expose as variables ─────────────────────────────── */

/* Code blocks: rounded corners + tighter line-height matching Material's `pre` style. */
.sample-container,
.symbol,
code {
    border-radius: 4px;
}

.sample-container,
pre.symbol {
    padding: 12px 16px;
}

/* Inline code — slight horizontal padding so identifiers don't crowd punctuation. */
:not(pre) > code {
    padding: 0.15em 0.4em;
    border-radius: 3px;
    font-size: 0.92em;
}

/* Headings — Material uses Inter at 500 weight. */
h1, h2, h3, h4, h5, h6,
.cover h1,
.cover h2 {
    font-family: "Inter", "Helvetica", "Arial", sans-serif;
    font-weight: 500;
}

/* Lists in the article body. Material's stock .md-typeset gives <ol>/<ul>
 * margin-left: 0 and adds 7.5px between items via .md-typeset li, which
 * makes lists feel airy and lose the leading number indentation. Dokka's
 * stock body styles indent the list and pack items tightly. Restore the
 * indent and tighten inter-item spacing so prose lists in KDoc blocks
 * read like Dokka's natives without trading away Material's font sizing.
 *
 * Material's stylesheet loads after ours and uses .md-typeset specificity
 * (1 class + 1 element), so we need !important to win the cascade. */
.md-typeset ol,
.md-typeset ul {
    padding-left: 1.5em !important;
    margin-left: 0 !important;
}
.md-typeset ol > li,
.md-typeset ul > li {
    margin-bottom: 0 !important;
    padding-left: 0.25em !important;
}
.md-typeset ol > li + li,
.md-typeset ul > li + li {
    margin-top: 0.5em !important;
}

/* Dokka member section headers (Constructors/Properties/Functions). Material's
 * default h2 margins make these labels look detached from the table block that
 * follows. Tighten spacing so the header visually belongs to the section body. */
.md-typeset h2.tableheader {
    margin-top: 1rem !important;
    margin-bottom: 0 !important;
}

.md-typeset h2.tableheader + .table {
    margin-top: 0 !important;
}

/* Links — underline on hover only, mirroring Material's behavior. */
a {
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}
