/* Ensemble documentation: self-contained stylesheet.
   Deliberately standalone rather than importing the portal's compiled CSS: these pages are static
   HTML served straight from public/, so they must render without the Console's React bundle or the
   @webority/theme chain. Brand violet is mirrored from src/assets/styles/index.scss (#7c3aed).
   Keep the two in step if the brand moves. */

:root {
    --brand: #7c3aed;
    --brand-hover: #8b5cf6;
    --brand-soft: #f5f3ff;
    --brand-border: #ddd6fe;

    --bg: #ffffff;
    --bg-muted: #f8f9fb;
    --surface: #ffffff;
    --border: #e5e7eb;
    --border-strong: #d1d5db;

    --text: #1f2430;
    --text-muted: #6b7280;
    --heading: #111827;

    --code-bg: #1e1b2e;
    --code-text: #e9e6f2;
    --code-inline-bg: #f3f0fb;
    --code-inline-text: #5b21b6;

    --sidebar-w: 16.5rem;
    --content-max: 46rem;
    --header-h: 3.75rem;
    --radius: 0.5rem;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --brand: #a78bfa;
        --brand-hover: #c4b5fd;
        --brand-soft: #221c3a;
        --brand-border: #4c3d7a;

        --bg: #14121c;
        --bg-muted: #1a1826;
        --surface: #1c1a29;
        --border: #2e2b3f;
        --border-strong: #3d3954;

        --text: #d7d4e3;
        --text-muted: #9b96ad;
        --heading: #f2f0f8;

        --code-bg: #0f0d18;
        --code-text: #e9e6f2;
        --code-inline-bg: #2a2440;
        --code-inline-text: #c4b5fd;
    }
}

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

html {
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--header-h) + 1rem);
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text);
    background-color: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--brand);
    text-decoration: none;
}

a:hover {
    color: var(--brand-hover);
    text-decoration: underline;
}

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

.doc-header {
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.25rem;
    background-color: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.doc-brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-weight: 650;
    font-size: 1.05rem;
    color: var(--heading);
    letter-spacing: -0.01em;
}

.doc-brand:hover {
    color: var(--heading);
    text-decoration: none;
}

.doc-brand-dot {
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    background-color: var(--brand);
    flex: 0 0 auto;
}

.doc-brand-tag {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-muted);
    padding-left: 0.55rem;
    margin-left: 0.1rem;
    border-left: 1px solid var(--border-strong);
}

.doc-header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    font-size: 0.9rem;
}

.doc-header-actions a {
    color: var(--text-muted);
    font-weight: 500;
}

.doc-header-actions a:hover {
    color: var(--brand);
    text-decoration: none;
}

.doc-header-cta {
    padding: 0.4rem 0.9rem;
    border-radius: var(--radius);
    background-color: var(--brand);
    color: #fff !important;
    font-weight: 550;
}

.doc-header-cta:hover {
    background-color: var(--brand-hover);
    color: #fff !important;
}

.doc-nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background-color: var(--surface);
    color: var(--text);
    font-size: 1.1rem;
    cursor: pointer;
}

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

.doc-layout {
    display: flex;
    align-items: flex-start;
    max-width: 82rem;
    margin: 0 auto;
}

.doc-sidebar {
    position: sticky;
    top: var(--header-h);
    flex: 0 0 var(--sidebar-w);
    width: var(--sidebar-w);
    height: calc(100vh - var(--header-h));
    overflow-y: auto;
    padding: 1.75rem 1rem 3rem 1.25rem;
    border-right: 1px solid var(--border);
}

.doc-sidebar-group + .doc-sidebar-group {
    margin-top: 1.75rem;
}

.doc-sidebar-title {
    margin: 0 0 0.55rem 0.6rem;
    font-size: 0.72rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.doc-sidebar ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.doc-sidebar li + li {
    margin-top: 0.1rem;
}

.doc-sidebar a {
    display: block;
    padding: 0.35rem 0.6rem;
    border-radius: var(--radius);
    font-size: 0.925rem;
    color: var(--text-muted);
    font-weight: 500;
}

.doc-sidebar a:hover {
    background-color: var(--bg-muted);
    color: var(--text);
    text-decoration: none;
}

.doc-sidebar a[aria-current="page"] {
    background-color: var(--brand-soft);
    color: var(--brand);
    font-weight: 600;
}

.doc-main {
    flex: 1 1 auto;
    min-width: 0;
    padding: 2.75rem 2.5rem 6rem;
}

.doc-article {
    max-width: var(--content-max);
}

/* ---------- On this page ----------
   Built by docs.js from the article's own h2s, so it can never fall out of step with the
   headings the way a hand-written list would. */

.doc-toc {
    position: sticky;
    top: var(--header-h);
    flex: 0 0 13.5rem;
    width: 13.5rem;
    max-height: calc(100vh - var(--header-h));
    overflow-y: auto;
    padding: 3.25rem 1.25rem 3rem 0;
}

.doc-toc-title {
    margin: 0 0 0.6rem 0.75rem;
    font-size: 0.72rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.doc-toc ul {
    list-style: none;
    margin: 0;
    padding: 0;
    border-left: 1px solid var(--border);
}

.doc-toc a {
    display: block;
    padding: 0.3rem 0.75rem;
    margin-left: -1px;
    border-left: 2px solid transparent;
    font-size: 0.875rem;
    line-height: 1.45;
    color: var(--text-muted);
}

.doc-toc a:hover {
    color: var(--text);
    text-decoration: none;
}

.doc-toc a[aria-current="true"] {
    border-left-color: var(--brand);
    color: var(--brand);
    font-weight: 550;
}

/* Anchor affordance on hover, without cluttering the heading by default. */

.doc-article h2 .doc-anchor {
    opacity: 0;
    margin-left: 0.4rem;
    font-weight: 400;
    color: var(--text-muted);
    text-decoration: none;
}

.doc-article h2:hover .doc-anchor {
    opacity: 1;
}

/* ---------- Typography ---------- */

.doc-eyebrow {
    margin: 0 0 0.5rem;
    font-size: 0.78rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--brand);
}

.doc-article h1 {
    margin: 0 0 0.75rem;
    font-size: 2.35rem;
    line-height: 1.2;
    letter-spacing: -0.025em;
    font-weight: 700;
    color: var(--heading);
}

.doc-lead {
    margin: 0 0 2.5rem;
    font-size: 1.15rem;
    line-height: 1.65;
    color: var(--text-muted);
}

.doc-article h2 {
    margin: 3rem 0 1rem;
    padding-top: 0.5rem;
    font-size: 1.5rem;
    line-height: 1.3;
    letter-spacing: -0.015em;
    font-weight: 650;
    color: var(--heading);
}

.doc-article h3 {
    margin: 2.25rem 0 0.75rem;
    font-size: 1.15rem;
    font-weight: 650;
    color: var(--heading);
}

.doc-article p {
    margin: 0 0 1.15rem;
}

.doc-article ul,
.doc-article ol {
    margin: 0 0 1.15rem;
    padding-left: 1.35rem;
}

.doc-article li {
    margin-bottom: 0.4rem;
}

.doc-article strong {
    font-weight: 650;
    color: var(--heading);
}

.doc-article hr {
    margin: 3rem 0;
    border: 0;
    border-top: 1px solid var(--border);
}

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

code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    padding: 0.15em 0.4em;
    border-radius: 0.3rem;
    background-color: var(--code-inline-bg);
    color: var(--code-inline-text);
    word-break: break-word;
}

.doc-code {
    position: relative;
    margin: 0 0 1.5rem;
}

.doc-code pre {
    margin: 0;
    padding: 1rem 3.25rem 1rem 1.1rem;
    overflow-x: auto;
    background-color: var(--code-bg);
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.65;
    color: var(--code-text);
}

.doc-code pre code {
    padding: 0;
    background: none;
    color: inherit;
    font-size: inherit;
    word-break: normal;
    white-space: pre;
}

/* Shell prompt + comment colouring, applied via spans in the markup. */

.doc-code .c {
    color: #8b86a3;
}

.doc-code .p {
    color: #a78bfa;
    user-select: none;
}

.doc-copy {
    position: absolute;
    top: 0.55rem;
    right: 0.55rem;
    padding: 0.3rem 0.55rem;
    border: 1px solid rgb(255 255 255 / 18%);
    border-radius: 0.35rem;
    background-color: rgb(255 255 255 / 8%);
    color: #cfcbe0;
    font-family: var(--font);
    font-size: 0.75rem;
    font-weight: 550;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.doc-code:hover .doc-copy,
.doc-copy:focus-visible {
    opacity: 1;
}

.doc-copy:hover {
    background-color: rgb(255 255 255 / 16%);
    color: #fff;
}

.doc-copy[data-copied="true"] {
    opacity: 1;
    border-color: #4ade80;
    color: #4ade80;
}

/* ---------- OS tabs ---------- */

.doc-tabs {
    margin: 0 0 1.5rem;
}

.doc-tablist {
    display: flex;
    gap: 0.25rem;
    margin-bottom: -1px;
    border-bottom: 1px solid var(--border);
}

.doc-tab {
    padding: 0.5rem 0.9rem;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 550;
    cursor: pointer;
}

.doc-tab:hover {
    color: var(--text);
}

.doc-tab[aria-selected="true"] {
    color: var(--brand);
    border-bottom-color: var(--brand);
}

.doc-tabpanel {
    padding-top: 1.25rem;
}

.doc-tabpanel[hidden] {
    display: none;
}

/* ---------- Callouts ---------- */

.doc-note {
    margin: 0 0 1.5rem;
    padding: 0.9rem 1.1rem;
    border: 1px solid var(--border);
    border-left: 3px solid var(--brand);
    border-radius: var(--radius);
    background-color: var(--bg-muted);
    font-size: 0.95rem;
}

.doc-note > *:first-child {
    margin-top: 0;
}

.doc-note > *:last-child {
    margin-bottom: 0;
}

.doc-note-title {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 650;
    color: var(--heading);
}

.doc-note.warn {
    border-left-color: #f59e0b;
}

/* ---------- Steps ---------- */

.doc-steps {
    margin: 0 0 1.5rem;
    padding: 0;
    list-style: none;
    counter-reset: step;
}

.doc-steps > li {
    position: relative;
    counter-increment: step;
    padding-left: 2.75rem;
    padding-bottom: 1.5rem;
}

.doc-steps > li::before {
    content: counter(step);
    position: absolute;
    left: 0;
    top: -0.1rem;
    width: 1.75rem;
    height: 1.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background-color: var(--brand-soft);
    border: 1px solid var(--brand-border);
    color: var(--brand);
    font-size: 0.85rem;
    font-weight: 650;
}

.doc-steps > li::after {
    content: "";
    position: absolute;
    left: 0.85rem;
    top: 1.9rem;
    bottom: 0.25rem;
    width: 1px;
    background-color: var(--border);
}

.doc-steps > li:last-child {
    padding-bottom: 0;
}

.doc-steps > li:last-child::after {
    display: none;
}

.doc-step-title {
    margin: 0 0 0.5rem;
    font-size: 1.05rem;
    font-weight: 650;
    color: var(--heading);
}

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

.doc-table-wrap {
    margin: 0 0 1.5rem;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.doc-article table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.925rem;
}

.doc-article th,
.doc-article td {
    padding: 0.6rem 0.9rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}

.doc-article th {
    background-color: var(--bg-muted);
    font-weight: 650;
    color: var(--heading);
    white-space: nowrap;
}

.doc-article tbody tr:last-child td {
    border-bottom: 0;
}

/* ---------- Cards (index page) ---------- */

.doc-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    gap: 1rem;
    margin: 0 0 2rem;
}

.doc-card {
    display: block;
    padding: 1.15rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--surface);
    color: var(--text);
}

.doc-card:hover {
    border-color: var(--brand-border);
    background-color: var(--brand-soft);
    text-decoration: none;
    color: var(--text);
}

.doc-card-title {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 650;
    color: var(--brand);
}

.doc-card-text {
    font-size: 0.925rem;
    color: var(--text-muted);
}

/* ---------- Next / prev ---------- */

.doc-pager {
    display: flex;
    gap: 1rem;
    margin-top: 4rem;
    padding-top: 1.75rem;
    border-top: 1px solid var(--border);
}

.doc-pager a {
    flex: 1 1 0;
    padding: 0.85rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-weight: 600;
}

.doc-pager a:hover {
    border-color: var(--brand-border);
    background-color: var(--brand-soft);
    text-decoration: none;
}

.doc-pager .next {
    text-align: right;
}

.doc-pager-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 550;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
}

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

@media (max-width: 78rem) {
    .doc-toc {
        display: none;
    }
}

@media (max-width: 62rem) {
    .doc-nav-toggle {
        display: flex;
        order: -1;
    }

    .doc-sidebar {
        display: none;
    }

    .doc-sidebar.open {
        display: block;
        position: fixed;
        top: var(--header-h);
        left: 0;
        z-index: 25;
        width: min(20rem, 82vw);
        height: calc(100vh - var(--header-h));
        background-color: var(--bg);
        border-right: 1px solid var(--border);
        box-shadow: 0 0.5rem 2rem rgb(0 0 0 / 18%);
    }

    .doc-main {
        padding: 2rem 1.25rem 4rem;
    }

    .doc-brand-tag {
        display: none;
    }
}

@media (max-width: 40rem) {
    .doc-article h1 {
        font-size: 1.85rem;
    }

    .doc-lead {
        font-size: 1.05rem;
    }

    .doc-header-actions .hide-sm {
        display: none;
    }

    .doc-pager {
        flex-direction: column;
    }

    .doc-pager .next {
        text-align: left;
    }
}
