/* Flow Logix documentation theme. Native CSS: nesting, light-dark(), :is()/:where(), logical properties */

:root {
    color-scheme: light dark;

    /* Colors: light, dark */
    --bg:          light-dark(#fff,    #0f1419);
    --bg-soft:     light-dark(#f7f8fa, #151b23);
    --bg-code:     light-dark(#f6f8fa, #161b22);
    --bg-code-inl: light-dark(#eff1f4, #1f2630);
    --border:      light-dark(#e3e6eb, #262e39);
    --border-2:    light-dark(#cfd5dd, #36404d);
    --text:        light-dark(#1d2430, #d9dee5);
    --muted:       light-dark(#5a6475, #96a1b0);
    --heading:     light-dark(#0f1621, #f2f4f7);
    --accent:      light-dark(#1f5f99, #6eb0ee);
    --accent-2:    light-dark(#174a78, #94c6f4);
    --accent-bg:   light-dark(#edf4fb, #172a3d);
    --on-accent:   light-dark(#fff,    #0f1419);
    --note:  var(--accent);                  --note-bg:   light-dark(#eef5fc, #13212e);
    --tip:   light-dark(#1d7a4d, #5cc792);   --tip-bg:    light-dark(#edf8f2, #11241b);
    --warn:  light-dark(#9a5b00, #e0a84a);   --warn-bg:   light-dark(#fdf6e7, #2a2012);
    --danger: light-dark(#b42318, #f0857a);  --danger-bg: light-dark(#fdf0ee, #2c1614);
    --accent-line: color-mix(in srgb, var(--accent) 30%, transparent);

    /* Type */
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;

    /* Layout */
    --header-h: 60px;
    --page-max: 1680px;
    --nav-w: 260px;
    --toc-w: 204px;
    --gutter: 24px;
    --main-pad: 40px 40px 72px;
    --measure: 48rem;
    --radius: 8px;
    --radius-lg: 10px;
    --line: 1px solid var(--border);
    --ease: .15s ease;

    /* Theme toggle: an explicit choice overrides the OS setting, and light-dark() follows it */
    &[data-theme="light"] { color-scheme: light; }
    &[data-theme="dark"] { color-scheme: dark; }
}

/* ---------- Base ---------- */

*, ::before, ::after { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--header-h) + 16px); -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.7 var(--font);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    &.nav-open { overflow: hidden; }
}

:where(a) {
    color: var(--accent);
    text-decoration: none;
    &:hover { color: var(--accent-2); text-decoration: underline; text-underline-offset: 2px; }
}

img { max-width: 100%; height: auto; }

.skip-link {
    position: absolute; inset-block-start: 8px; inset-inline-start: -999px; z-index: 100;
    padding: 8px 12px; border-radius: var(--radius); background: var(--bg);
    &:focus { inset-inline-start: 8px; }
}

.pixel { position: absolute; width: 1px; height: 1px; }

/* ---------- Shared patterns ---------- */

/* Small uppercase labels */
:where(.site-nav__title, .page-toc__title, .layers .title, .admonitionblock .icon .title) {
    margin: 0;
    font-size: .75rem;
    font-weight: 650;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}

/* Bordered boxes that highlight on hover */
:where(.cards li, .pager a, .layer li a) {
    border: var(--line);
    transition: border-color var(--ease), color var(--ease), box-shadow var(--ease), translate var(--ease);
    &:hover { border-color: var(--accent); text-decoration: none; }
}

/* Unstyled lists */
:is(.site-nav, .page-toc) ul { list-style: none; margin: 0; padding: 0; }

/* Containers centred at the page width */
:is(.site-header__inner, .layout, .site-footer__inner) { max-width: var(--page-max); margin-inline: auto; }

/* ---------- Header ---------- */

.site-header {
    position: sticky; inset-block-start: 0; z-index: 50;
    height: var(--header-h);
    border-block-end: var(--line);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(180%) blur(8px);
}

.site-header__inner { display: flex; align-items: center; gap: 12px; height: 100%; padding-inline: var(--gutter); }

.brand {
    display: flex; align-items: center; gap: 7px;
    color: var(--heading); font-size: 1.05rem; font-weight: 650; letter-spacing: -.01em;
    &:hover { color: var(--heading); text-decoration: none; }
}
.brand__suffix { color: var(--muted); font-weight: 500; }

.site-header__links {
    display: flex; gap: 24px; margin-inline-start: auto; font-size: .925rem;
    & a { color: var(--muted); font-weight: 500; &:hover { color: var(--heading); text-decoration: none; } }
}

:is(.nav-toggle, .theme-toggle) {
    place-items: center; width: 36px; height: 36px;
    border: 0; border-radius: var(--radius); background: none; color: var(--text); cursor: pointer;
    &:hover { background: var(--bg-soft); }
}
.nav-toggle { display: none; margin-inline-start: -8px; }
.theme-toggle {
    display: inline-grid; margin-inline-end: -8px; color: var(--muted);
    &:hover { color: var(--heading); }
    & svg { grid-area: 1 / 1; display: none; }
    &[data-mode="auto"] .theme-toggle__auto,
    &[data-mode="light"] .theme-toggle__light,
    &[data-mode="dark"] .theme-toggle__dark { display: block; }
}

/* ---------- Layout ---------- */

.layout {
    display: grid;
    grid-template-columns: var(--nav-w) minmax(0, 1fr) var(--toc-w);
    &.layout--home { grid-template-columns: var(--nav-w) minmax(0, 1fr); }
}

:is(.layout__nav, .layout__toc) {
    position: sticky; inset-block-start: var(--header-h); align-self: start;
    max-height: calc(100vh - var(--header-h));
    overflow-y: auto; overscroll-behavior: contain;
}

.layout__nav { min-height: calc(100vh - var(--header-h)); padding: 28px 16px 40px var(--gutter); border-inline-end: var(--line); }
.layout__main { min-width: 0; padding: var(--main-pad); }
.layout__toc { padding: 40px 20px 40px 4px; }

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

.site-nav {
    & .site-nav__group + .site-nav__group { margin-block-start: 26px; }
    & .site-nav__title { margin: 0 0 6px 10px; }
    & a {
        display: block; padding: 5px 10px; border-radius: 6px;
        color: var(--text); font-size: .925rem; line-height: 1.45;
        &:hover { background: var(--bg-soft); color: var(--heading); text-decoration: none; }
        &.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
    }
    & .ext { margin-inline-start: 4px; font-size: .8em; color: var(--muted); }
}

/* ---------- On this page ---------- */

.page-toc {
    font-size: .85rem; line-height: 1.45;
    & .page-toc__title { margin-block-end: 10px; }
    & ul ul { padding-inline-start: 12px; }
    & :is(.sectlevel3, .sectlevel4) { display: none; }
    & a {
        display: block; padding: 4px 0 4px 12px; margin-inline-start: -1px;
        border-inline-start: var(--line); color: var(--muted);
        &:hover { color: var(--heading); text-decoration: none; }
        &.active { color: var(--accent); border-color: var(--accent); }
    }
    & code { all: unset; font-family: var(--mono); font-size: .95em; }
}

/* ---------- Document ---------- */

.doc { max-width: 66rem; margin-inline: auto; }

.doc__header {
    margin-block-end: 36px; padding-block-end: 28px; border-block-end: var(--line);
    & > * { max-width: var(--measure); }
    & h1 { margin: 0; font-size: 2.25rem; line-height: 1.2; font-weight: 700; letter-spacing: -.022em; color: var(--heading); }
}
.doc__eyebrow { margin: 0 0 8px; font-size: .8rem; font-weight: 650; letter-spacing: .02em; color: var(--accent); }
.doc__lead { margin: 14px 0 0; font-size: 1.15rem; line-height: 1.6; color: var(--muted); }

.doc__body {
    /* Prose keeps a readable measure; code, tables and diagrams use the full width */
    & :where(p, .ulist, .olist, .dlist, .admonitionblock, .qlist, .title) { max-width: var(--measure); }
    & :where(td, li, dd) p { max-width: none; }

    & :where(.paragraph, .ulist, .olist, .dlist, .listingblock, .literalblock, .admonitionblock,
             .tableblock, .imageblock, .qlist, .exampleblock, .sidebarblock, .openblock, .colist) { margin-block-end: 20px; }
    & p { margin: 0 0 16px; }
    & .paragraph p:last-child { margin-block-end: 0; }
    & :is(.lead p, #preamble .paragraph:first-child p) { font-size: 1.075rem; }

    /* Headings */
    & :is(h2, h3, h4, h5) {
        color: var(--heading); letter-spacing: -.012em; font-weight: 650;
        & code { padding: 0; background: none; font-size: .9em; }
        & > a.anchor {
            float: left; margin-inline-start: -1.1em; padding-inline-end: .3em;
            color: var(--muted); opacity: 0; text-decoration: none;
            &::before { content: "#"; font-weight: 400; }
        }
        &:hover > a.anchor { opacity: 1; }
    }
    & h2 { margin: 56px 0 14px; font-size: 1.6rem; line-height: 1.3; font-weight: 680; }
    & h3 { margin: 38px 0 10px; font-size: 1.2rem; line-height: 1.4; }
    & h4 { margin: 28px 0 8px; font-size: 1.02rem; line-height: 1.4; }
    & h5 { margin: 24px 0 8px; font-size: .95rem; }
    & > #preamble + .sect1 > h2 { margin-block-start: 44px; }
    & > .sect1:first-child > h2 { margin-block-start: 0; }

    /* Lists */
    & :is(ul, ol) { margin: 0; padding-inline-start: 1.4em; }
    & li { margin: 6px 0; & > p { margin: 0; } &::marker { color: var(--muted); } }
    & dl {
        & dt { margin-block-start: 14px; font-weight: 600; color: var(--heading); }
        & dd { margin: 4px 0 0; & p { margin-block-end: 8px; } }
    }
    & .hdlist td { padding: 4px 16px 4px 0; vertical-align: top; }

    /* Block titles, such as the caption above a code block */
    & :where(.listingblock, .literalblock, .tableblock, .imageblock, .exampleblock, .sidebarblock, .olist, .dlist, .colist) > .title {
        margin: 0 0 8px; font-size: .875rem; font-weight: 600; color: var(--muted);
    }
    & :is(.paragraph, .ulist) > .title { margin-block-start: 24px; font-size: 1rem; color: var(--heading); }

    /* Code */
    & :is(code, kbd) {
        padding: .1em .32em; border-radius: 4px;
        background: var(--bg-code-inl); color: var(--heading);
        font-family: var(--mono); font-size: .86em; overflow-wrap: break-word;
    }
    & a code { color: var(--accent); }
    & pre {
        margin: 0; padding: 16px 18px; overflow-x: auto;
        border: var(--line); border-radius: var(--radius); background: var(--bg-code);
        font: .82rem/1.6 var(--mono); tab-size: 4;
        /* code.hljs: outrank highlight.js, whose stylesheet loads later */
        & :is(code, code.hljs) { padding: 0; background: none; color: var(--text); font-size: inherit; overflow-wrap: normal; white-space: pre; }
    }

    /* Admonitions: AsciiDoc renders a table, shown here as a call-out */
    & .admonitionblock {
        padding: 14px 18px; font-size: .95rem;
        border: 1px solid color-mix(in srgb, var(--note) 25%, transparent);
        border-inline-start: 3px solid var(--note);
        border-radius: var(--radius);
        background: var(--note-bg);
        & :is(table, tbody, tr, td) { display: block; padding: 0; border: 0; background: none; }
        & td.icon .title { margin-block-end: 4px; color: var(--note); }
        & td.content > :last-child, & td.content > .paragraph:last-child p { margin-block-end: 0; }
        &.tip { --note: var(--tip); --note-bg: var(--tip-bg); }
        &:is(.warning, .caution) { --note: var(--warn); --note-bg: var(--warn-bg); }
        &.important { --note: var(--danger); --note-bg: var(--danger-bg); }
    }

    /* Tables */
    & table.tableblock {
        width: 100%; border-collapse: separate; border-spacing: 0; overflow: hidden;
        border: var(--line); border-radius: var(--radius);
        font-size: .92rem; line-height: 1.55;
        & caption { caption-side: top; text-align: start; }
        & col { width: auto !important; }
        & :is(th, td) {
            padding: 10px 14px; text-align: start; vertical-align: top; border-block-end: var(--line);
            & + :is(th, td) { border-inline-start: var(--line); }
        }
        & th { background: var(--bg-soft); color: var(--heading); font-size: .85rem; font-weight: 600; }
        & tr:last-child td { border-block-end: 0; }
        & td code { white-space: nowrap; }
    }
    & p.tableblock { margin: 0; & + p.tableblock { margin-block-start: 8px; } }

    /* Images */
    & .imageblock.right { float: right; margin: 0 0 16px 28px; & img { width: 96px; height: 96px; } }

    /* Q&A lists */
    & .qlist.qanda {
        & ol { padding: 0; list-style: none; }
        & li { margin: 0; padding-block: 18px; border-block-start: var(--line); &:last-child { border-block-end: var(--line); } }
        & li > p:first-child { margin-block-end: 6px; font-weight: 600; color: var(--heading); & em { font-style: normal; } }
    }

    /* Example and sidebar blocks */
    & :is(.exampleblock, .sidebarblock) > .content {
        padding: 16px 18px; border: var(--line); border-radius: var(--radius); background: var(--bg-soft);
    }

    /* Support call-out (snippets/support.adoc) */
    & .sidebarblock.support {
        max-width: var(--measure); margin-block: 32px;
        & > .content { padding: 20px 22px; border-color: var(--accent-line); border-radius: var(--radius-lg); background: var(--accent-bg); }
        & p { margin-block-end: 12px; }
        & .content > :last-child, & .paragraph:last-child p { margin-block-end: 0; }
    }

    /* "See the complete example" links */
    & .source-link p { margin-block-start: -8px; font-size: .875rem; }
}

/* ---------- Buttons and cards (home page) ---------- */

/* [.actions] paragraph of links with role=button */
.paragraph.actions { margin-block-end: 24px; & p { display: flex; flex-wrap: wrap; gap: 12px; } }

:is(.button, .support__cta) {
    display: inline-block; padding: 9px 18px; border-radius: var(--radius);
    font-size: .95rem; font-weight: 600;
}
.support__cta { padding: 6px 15px; font-size: .925rem; }
.button {
    border: 1px solid var(--border-2); color: var(--heading);
    &:hover { background: var(--bg-soft); color: var(--heading); text-decoration: none; }
}
:is(.button.primary, .support__cta) {
    border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent);
    &:hover { border-color: var(--accent-2); background: var(--accent-2); color: var(--on-accent); text-decoration: none; }
}

.doc--home {
    max-width: 60rem;
    & .doc__body h2 { margin-block-start: 48px; font-size: 1.15rem; }
}

.hero {
    padding: 8px 0 32px;
    & h1 { margin: 0; font-size: 2.6rem; line-height: 1.15; font-weight: 720; letter-spacing: -.028em; color: var(--heading); }
}
.hero__lead { max-width: 40rem; margin: 16px 0 0; font-size: 1.2rem; line-height: 1.6; color: var(--muted); }

/* [.cards] list: each item is "link:page[Title] +" followed by a description */
.ulist.cards {
    --min: 260px;
    max-width: none; margin-block-end: 8px;
    &.cards-2 { --min: 320px; max-width: 44rem; }
    & ul { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--min), 1fr)); gap: 16px; margin: 0; padding: 0; list-style: none; }
    & li {
        position: relative; margin: 0; padding: 18px 20px; border-radius: var(--radius-lg); background: var(--bg);
        &:hover { box-shadow: 0 4px 18px -8px color-mix(in srgb, var(--accent) 45%, transparent); translate: 0 -1px; }
    }
    & p { margin: 0; color: var(--muted); font-size: .9rem; line-height: 1.55; }
    & br { display: none; }
    & a {
        display: block; margin-block-end: 4px; color: var(--heading); font-size: 1rem; font-weight: 650; line-height: 1.7;
        &::after { content: ""; position: absolute; inset: 0; border-radius: inherit; } /* the whole card is the link */
        &:hover { color: var(--heading); text-decoration: none; }
    }
}

/* ---------- Layer diagram (why-flowlogix) ---------- */
/* [.layers] example block: a [.layers-start] box beside a [.layers-stack] of titled [.layer] blocks */

.layers {
    max-width: 54rem; margin: 32px 0 40px;
    & :is(.content, .openblock, .sidebarblock, .ulist, .paragraph) { margin: 0; }
    /* .exampleblock: outrank the generic example block box */
    &.exampleblock > .content { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 14px; padding: 0; border: 0; background: none; }
    & .layers-stack > .content { display: flex; flex-direction: column; gap: 10px; padding: 0; border: 0; background: none; }
    & ul { margin: 0; padding: 0; list-style: none; }
    & li { margin: 0; }
    & p { max-width: none; margin: 0; }
}

.layers-start {
    position: relative; display: flex; flex-direction: column; justify-content: center; gap: 8px;
    padding: 18px; border: 1px solid var(--accent-line); border-radius: var(--radius-lg); background: var(--accent-bg);
    &::after {
        content: ""; position: absolute; inset-inline-end: -13px; inset-block-start: 50%; translate: 0 -50%;
        border: 7px solid transparent; border-inline-start-color: color-mix(in srgb, var(--accent) 55%, transparent);
    }
    & > .title { color: var(--accent); }
    & ul { display: flex; flex-direction: column; gap: 8px; font-size: .95rem; font-weight: 600; }
    & .paragraph { margin-block-start: 14px; color: var(--muted); font-size: .8rem; line-height: 1.45; }
}

.layer {
    padding: 14px 18px; border: var(--line); border-radius: var(--radius-lg); background: var(--bg);
    &.layer-app { border-style: dashed; background: var(--bg-soft); }
    & ul { display: flex; flex-wrap: wrap; gap: 8px; margin-block-start: 10px; }
    & li a {
        display: block; padding: 4px 11px; border-color: var(--border-2); border-radius: 999px;
        background: var(--bg-soft); color: var(--heading); font-family: var(--mono); font-size: .85rem;
        &:hover { color: var(--accent); }
    }
    & .paragraph { margin-block-start: 8px; color: var(--muted); font-size: .875rem; line-height: 1.5; }
    &.layer-app .paragraph { margin-block-start: 4px; }
}

/* ---------- Page footer ---------- */

.doc__footer { margin-block-start: 64px; }
.doc__edit { margin: 0 0 20px; font-size: .875rem; & a { color: var(--muted); } }

.pager {
    display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
    & a { display: block; padding: 14px 18px; border-radius: var(--radius); color: var(--heading); font-weight: 600; &:hover { color: var(--accent); } }
    & span { display: block; color: var(--muted); font-size: .8rem; font-weight: 500; }
}
.pager__next { grid-column: 2; text-align: end; }

.site-footer { border-block-start: var(--line); }
.site-footer__inner {
    display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px;
    padding: var(--gutter); color: var(--muted); font-size: .875rem;
    & p { margin: 0; }
    & nav { display: flex; gap: 20px; }
    & a { color: var(--muted); }
}

/* ---------- Responsive ---------- */

@media (max-width: 1200px) {
    :root { --nav-w: 232px; --main-pad: 36px 32px 64px; }
    .layout { grid-template-columns: var(--nav-w) minmax(0, 1fr); }
    .layout__toc { display: none; }
}

@media (max-width: 860px) {
    :root { --gutter: 16px; --main-pad: 28px 20px 56px; }
    .nav-toggle { display: inline-grid; }
    .layout, .layout.layout--home { grid-template-columns: minmax(0, 1fr); }
    .layout__nav {
        display: none; position: fixed; inset: var(--header-h) 0 0; z-index: 40;
        max-height: none; padding: 20px 20px 40px; border: 0; background: var(--bg);
        .nav-open & { display: block; }
    }
    .site-header__links { gap: 16px; }
    .doc__header h1 { font-size: 1.85rem; }
    .hero h1 { font-size: 2rem; }
    .doc__body {
        & .imageblock.right img { width: 72px; height: 72px; }
        & table.tableblock { display: block; overflow-x: auto; & td code { white-space: normal; } }
    }
}

@media (max-width: 700px) {
    .layers.exampleblock > .content { grid-template-columns: minmax(0, 1fr); }
    .layers-start::after { display: none; }
}

@media (max-width: 520px) {
    .site-header__links a:not(:first-child) { display: none; }
    .pager { grid-template-columns: 1fr; }
    .pager__next { grid-column: 1; }
}

@media print {
    :is(.site-header, .layout__nav, .layout__toc, .doc__footer, .site-footer) { display: none; }
    .layout { display: block; }
    .layout__main { padding: 0; }
}
