/* Semantik ERP Docs — layout and components.
   Layout pieces (header, sidebar, pager, search) are generated by scripts/build_docs.py. */

:root {
    --brand: #5b3df5;
    --brand-strong: #4527d9;
    --brand-soft: #efecff;
    --bg: #ffffff;
    --bg-soft: #f7f7fb;
    --bg-muted: #f1f1f7;
    --surface: #ffffff;
    --text: #1d1b2e;
    --text-soft: #4b4a63;
    --text-muted: #666580;
    --border: #e6e5f0;
    --border-strong: #d6d4e6;
    --code-bg: #f4f3fa;
    --info: #2f6fed;    --info-bg: #eef4ff;
    --success: #0d734d; --success-bg: #e9f8f1;
    --warning: #b45309; --warning-bg: #fff6e6;
    --danger: #c0264b;  --danger-bg: #fdecf0;
    --shadow-sm: 0 1px 2px rgba(23, 20, 51, .06);
    --shadow: 0 6px 24px rgba(23, 20, 51, .08);
    --shadow-lg: 0 24px 64px rgba(23, 20, 51, .18);
    --radius: 12px;
    --radius-sm: 8px;
    --header-h: 60px;
    --sidebar-w: 268px;
    --toc-w: 220px;
    --content-w: 780px;
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color-scheme: light;
}

[data-theme="dark"] {
    --brand: #8b74ff;
    --brand-strong: #a594ff;
    --brand-soft: #241f45;
    --bg: #0f0e17;
    --bg-soft: #15141f;
    --bg-muted: #1c1b29;
    --surface: #17161f;
    --text: #ecebf5;
    --text-soft: #c4c2d6;
    --text-muted: #8e8ca6;
    --border: #2a2939;
    --border-strong: #37354a;
    --code-bg: #1e1d2b;
    --info: #7aa7ff;    --info-bg: #17213a;
    --success: #4fd29b; --success-bg: #12261e;
    --warning: #f5b454; --warning-bg: #2b2112;
    --danger: #ff7d9b;  --danger-bg: #2d1520;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 6px 24px rgba(0, 0, 0, .35);
    --shadow-lg: 0 24px 64px rgba(0, 0, 0, .55);
    color-scheme: dark;
}

html[lang="ar"] { --font: 'Noto Sans Arabic', 'Inter', system-ui, sans-serif; }

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--header-h) + 16px); -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.7;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

.skip-link {
    position: absolute; inset-inline-start: 12px; top: -48px; z-index: 200;
    background: var(--brand); color: #fff; padding: 8px 14px; border-radius: var(--radius-sm);
}
.skip-link:focus { top: 12px; }

/* ---------- Header ---------- */
.header {
    position: sticky; top: 0; z-index: 100;
    height: var(--header-h);
    display: flex; align-items: center; gap: 16px;
    padding: 0 20px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { border-radius: 6px; }
.brand-tag {
    font-size: 12px; font-weight: 600; color: var(--brand);
    background: var(--brand-soft); padding: 2px 8px; border-radius: 999px;
}
.search-trigger {
    flex: 0 1 360px; margin-inline-start: auto;
    display: flex; align-items: center; gap: 10px;
    height: 38px; padding: 0 10px 0 12px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--bg-soft); color: var(--text-muted);
    font: inherit; font-size: 14px; cursor: pointer;
}
.search-trigger:hover { border-color: var(--border-strong); color: var(--text-soft); }
.search-label { flex: 1; text-align: start; }
kbd {
    font-family: var(--mono); font-size: 11px; line-height: 1;
    padding: 4px 6px; border-radius: 6px;
    border: 1px solid var(--border); border-bottom-width: 2px;
    background: var(--surface); color: var(--text-muted);
}
.search-icon {
    width: 16px; height: 16px; flex: none; display: inline-block;
    border: 2px solid currentColor; border-radius: 50%; position: relative;
}
.search-icon::after {
    content: ''; position: absolute; width: 7px; height: 2px; background: currentColor;
    right: -6px; bottom: -3px; transform: rotate(45deg); border-radius: 2px;
}
.header-actions { display: flex; align-items: center; gap: 6px; }
.header-link, .lang-switch {
    color: var(--text-soft); font-size: 14px; font-weight: 500;
    padding: 6px 10px; border-radius: var(--radius-sm);
}
.header-link:hover, .lang-switch:hover { background: var(--bg-muted); color: var(--text); text-decoration: none; }
.lang-switch { border: 1px solid var(--border); }
.icon-btn {
    width: 38px; height: 38px; flex: none;
    display: inline-grid; place-items: center;
    border: 1px solid transparent; border-radius: 10px;
    background: transparent; color: var(--text-soft); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-muted); color: var(--text); }
.theme-icon {
    width: 18px; height: 18px; border-radius: 50%;
    background: currentColor;
    -webkit-mask: radial-gradient(circle at 70% 30%, transparent 32%, #000 34%);
            mask: radial-gradient(circle at 70% 30%, transparent 32%, #000 34%);
}
[data-theme="dark"] .theme-icon {
    -webkit-mask: none; mask: none;
    width: 10px; height: 10px;
    box-shadow: 0 -8px 0 -3px currentColor, 0 8px 0 -3px currentColor, 8px 0 0 -3px currentColor, -8px 0 0 -3px currentColor,
                6px 6px 0 -3px currentColor, -6px -6px 0 -3px currentColor, 6px -6px 0 -3px currentColor, -6px 6px 0 -3px currentColor;
}
.menu-toggle { display: none; flex-direction: column; gap: 4px; }
.menu-toggle span { display: block; width: 18px; height: 2px; background: currentColor; border-radius: 2px; transition: transform .2s, opacity .2s; }
.menu-open .menu-toggle span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.menu-open .menu-toggle span:nth-child(2) { opacity: 0; }
.menu-open .menu-toggle span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px; border-radius: 10px;
    font: inherit; font-size: 15px; font-weight: 600; line-height: 1.2;
    border: 1px solid transparent; cursor: pointer; white-space: nowrap;
    transition: background .15s, border-color .15s, transform .15s;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { border-color: var(--brand); color: var(--brand); }

/* ---------- Layout ---------- */
.layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
}
.layout-home { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }

.sidebar {
    position: sticky; top: var(--header-h);
    height: calc(100vh - var(--header-h));
    overflow-y: auto; overscroll-behavior: contain;
    padding: 24px 16px 40px;
    border-inline-end: 1px solid var(--border);
}
.sidebar ul { list-style: none; margin: 0 0 22px; padding: 0; }
.sidebar-title {
    font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
    color: var(--text-muted); padding: 0 10px; margin-bottom: 6px;
}
html[lang="ar"] .sidebar-title { letter-spacing: 0; }
.sidebar a {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 10px; border-radius: var(--radius-sm);
    color: var(--text-soft); font-size: 14.5px; font-weight: 500;
}
.sidebar a:hover { background: var(--bg-muted); color: var(--text); text-decoration: none; }
.sidebar a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-icon { width: 20px; text-align: center; font-size: 15px; }
.sidebar-links { display: grid; gap: 2px; padding-top: 14px; border-top: 1px solid var(--border); }
.sidebar-links a { font-size: 13.5px; color: var(--text-muted); }

.content { min-width: 0; padding: 32px clamp(20px, 4vw, 56px) 0; }
.content > * { width: 100%; max-width: var(--content-w); margin-inline: auto; }
.layout-home .content > * { max-width: 1040px; }
.content > .breadcrumbs { margin-bottom: 18px; }

.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-muted); margin-bottom: 18px; }
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs a:hover { color: var(--brand); }
.breadcrumbs [aria-current] { color: var(--text-soft); font-weight: 500; }

.toc {
    position: sticky; top: var(--header-h); align-self: start;
    max-height: calc(100vh - var(--header-h)); overflow-y: auto;
    padding: 32px 16px 32px 8px; font-size: 13.5px;
}
html[dir="rtl"] .toc { padding: 32px 8px 32px 16px; }
.toc-title { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px; }
html[lang="ar"] .toc-title { letter-spacing: 0; }
.toc ul { list-style: none; margin: 0; padding: 0; border-inline-start: 1px solid var(--border); }
.toc a {
    display: block; padding: 4px 12px; margin-inline-start: -1px;
    border-inline-start: 2px solid transparent;
    color: var(--text-muted); line-height: 1.45;
}
.toc a:hover { color: var(--text); text-decoration: none; }
.toc a.active { color: var(--brand); border-inline-start-color: var(--brand); font-weight: 600; }
.toc .toc-h3 a { padding-inline-start: 24px; font-size: 13px; }
.toc:empty, .toc.is-empty { visibility: hidden; }

/* ---------- Article typography ---------- */
.doc { color: var(--text-soft); }
.doc h1, .doc h2, .doc h3, .doc h4, .content h1, .content h2 { color: var(--text); line-height: 1.3; scroll-margin-top: calc(var(--header-h) + 16px); }
.doc h1, .content h1 { font-size: clamp(30px, 4vw, 38px); font-weight: 700; letter-spacing: -.02em; margin: 0 0 12px; }
html[lang="ar"] .doc h1, html[lang="ar"] .content h1 { letter-spacing: 0; }
.doc h2 { font-size: 24px; font-weight: 700; margin: 52px 0 14px; padding-top: 8px; border-top: 1px solid var(--border); }
.doc h1 + h2, .doc h1 + p + h2, .doc .lead + h2 { border-top: 0; }
.doc h3 { font-size: 18.5px; font-weight: 650; margin: 32px 0 10px; }
.doc h4 { font-size: 16px; font-weight: 650; margin: 24px 0 8px; }
.doc p { margin: 0 0 16px; }
.doc .lead { font-size: 18px; color: var(--text-soft); margin-bottom: 24px; }
.doc ul, .doc ol { margin: 0 0 18px; padding-inline-start: 24px; }
.doc li { margin: 6px 0; }
.doc li::marker { color: var(--text-muted); }
.doc strong { color: var(--text); font-weight: 650; }
.heading-anchor {
    margin-inline-start: 8px; color: var(--text-muted); opacity: 0; font-weight: 400;
    text-decoration: none !important; transition: opacity .15s;
}
h2:hover .heading-anchor, h3:hover .heading-anchor, .heading-anchor:focus { opacity: 1; }

/* Numbered steps */
.doc ol.steps { list-style: none; padding: 0; counter-reset: step; }
.doc ol.steps > li {
    position: relative; counter-increment: step;
    padding: 2px 0 14px; padding-inline-start: 44px; margin: 0;
}
.doc ol.steps > li::before {
    content: counter(step);
    position: absolute; inset-inline-start: 0; top: 0;
    width: 28px; height: 28px; border-radius: 50%;
    display: grid; place-items: center;
    font-size: 13px; font-weight: 700; color: var(--brand); background: var(--brand-soft);
}
.doc ol.steps > li:not(:last-child)::after {
    content: ''; position: absolute; inset-inline-start: 13.5px; top: 32px; bottom: 2px;
    width: 1px; background: var(--border);
}

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 0 22px; border: 1px solid var(--border); border-radius: var(--radius); }
.doc table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.doc :not(.table-wrap) > table { margin-bottom: 22px; }
.doc th, .doc td { padding: 11px 14px; text-align: start; vertical-align: top; border-bottom: 1px solid var(--border); }
.doc th { background: var(--bg-soft); color: var(--text); font-weight: 650; font-size: 13.5px; white-space: nowrap; }
.doc tr:last-child td { border-bottom: 0; }
.doc tbody tr:hover td, .doc tr:hover td { background: color-mix(in srgb, var(--bg-soft) 60%, transparent); }

/* Code */
.doc code {
    font-family: var(--mono); font-size: .88em;
    background: var(--code-bg); color: var(--text);
    padding: 2px 6px; border-radius: 6px; border: 1px solid var(--border);
}
.doc pre {
    position: relative; overflow-x: auto; direction: ltr; text-align: left;
    margin: 0 0 22px; padding: 16px 18px;
    background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 13.5px; line-height: 1.6;
}
.doc pre code { background: none; border: 0; padding: 0; font-size: inherit; }
.copy-btn {
    position: absolute; top: 8px; inset-inline-end: 8px;
    font: inherit; font-size: 12px; padding: 4px 8px; border-radius: 6px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
    cursor: pointer; opacity: 0; transition: opacity .15s;
}
.doc pre:hover .copy-btn, .copy-btn:focus { opacity: 1; }

/* Callouts */
.alert, .callout {
    display: block; margin: 0 0 22px; padding: 14px 16px;
    border: 1px solid; border-radius: var(--radius);
    font-size: 15px;
}
.alert p:last-child, .callout p:last-child { margin-bottom: 0; }
.alert-info, .callout-info { background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 30%, transparent) }
.alert-success { background: var(--success-bg); border-color: color-mix(in srgb, var(--success) 30%, transparent) }
.alert-warning { background: var(--warning-bg); border-color: color-mix(in srgb, var(--warning) 30%, transparent) }
.alert-danger { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 30%, transparent) }
.callout h3 { margin-top: 0; }

/* Badges */
.badge {
    display: inline-block; padding: 1px 9px; border-radius: 999px;
    font-size: 12.5px; font-weight: 600; line-height: 1.7;
    background: var(--bg-muted); color: var(--text-soft); border: 1px solid var(--border);
}
.badge-success { background: var(--success-bg); color: var(--success); border-color: transparent; }
.badge-warning { background: var(--warning-bg); color: var(--warning); border-color: transparent; }
.badge-danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }

/* Checklist */
.doc ul.checklist { list-style: none; padding: 0; }
.doc ul.checklist li { position: relative; padding-inline-start: 30px; }
.doc ul.checklist li::before {
    content: '✓'; position: absolute; inset-inline-start: 0; top: 2px;
    width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center;
    font-size: 12px; font-weight: 700; color: var(--success); background: var(--success-bg);
}

/* Cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; margin: 0 0 36px; }
.card {
    display: block; padding: 20px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--border); color: var(--text-soft);
    box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s, transform .15s;
}
.card:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--border)); box-shadow: var(--shadow); transform: translateY(-2px); text-decoration: none; }
.card h3, .card-title { margin: 0 0 6px; font-size: 16.5px; font-weight: 650; color: var(--text); border: 0; padding: 0; }
.card p { margin: 0; font-size: 14px; line-height: 1.55; color: var(--text-muted); }
.card-icon {
    display: inline-grid; place-items: center; width: 40px; height: 40px; margin-bottom: 12px;
    border-radius: 10px; background: var(--brand-soft); font-size: 20px;
}

.feature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 0 0 28px; }
.feature { padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-soft); }
.feature span { font-size: 22px; display: block; margin-bottom: 4px; }
.feature strong { display: block; color: var(--text); font-size: 15px; }
.feature p { margin: 2px 0 0; font-size: 13px; line-height: 1.45; color: var(--text-muted); }

/* ---------- Home ---------- */
.hero {
    position: relative; overflow: hidden;
    margin: 0 0 36px; padding: clamp(32px, 6vw, 56px) clamp(24px, 5vw, 48px);
    border-radius: 20px; border: 1px solid var(--border);
    background:
        radial-gradient(800px 300px at 100% 0%, color-mix(in srgb, var(--brand) 22%, transparent), transparent 60%),
        radial-gradient(600px 260px at 0% 100%, color-mix(in srgb, #20c4c4 14%, transparent), transparent 60%),
        var(--bg-soft);
}
.hero h1 { margin-bottom: 12px; }
.hero p { font-size: 18px; color: var(--text-soft); max-width: 620px; margin: 0 0 24px; }
.hero-search {
    display: flex; align-items: center; gap: 12px; width: min(520px, 100%);
    height: 50px; padding: 0 14px; margin-bottom: 22px;
    border: 1px solid var(--border-strong); border-radius: 12px;
    background: var(--surface); color: var(--text-muted); font: inherit; font-size: 15.5px;
    box-shadow: var(--shadow-sm); cursor: pointer; text-align: start;
}
.hero-search kbd { margin-inline-start: auto; }
.hero-search:hover { border-color: var(--brand); }
.hero-buttons { display: flex; flex-wrap: wrap; gap: 12px; }
.popular h2, .content > h2 { font-size: 20px; margin: 0 0 14px; }
.popular ul { list-style: none; padding: 0; margin: 0 0 36px; display: flex; flex-wrap: wrap; gap: 10px; }
.popular a {
    display: inline-block; padding: 8px 14px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text-soft); font-size: 14px; font-weight: 500;
}
.popular a:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }

/* ---------- Page end ---------- */
.help-box {
    display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
    margin: 48px 0 20px; padding: 18px 20px; max-width: var(--content-w);
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-soft);
}
.help-box strong { color: var(--text); }
.help-box p { margin: 2px 0 0; color: var(--text-muted); font-size: 14px; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-width: var(--content-w); margin-bottom: 40px; }
.pager-link {
    display: flex; flex-direction: column; gap: 2px; padding: 14px 18px;
    border: 1px solid var(--border); border-radius: var(--radius); color: var(--text);
    transition: border-color .15s;
}
.pager-link:hover { border-color: var(--brand); text-decoration: none; }
.pager-link span { font-size: 13px; color: var(--text-muted); }
.pager-link strong { color: var(--brand); font-weight: 600; }
.pager-link.next { text-align: end; grid-column: 2; }
.pager-link.prev span::before { content: '← '; }
.pager-link.next span::after { content: ' →'; }
html[dir="rtl"] .pager-link.prev span::before { content: '→ '; }
html[dir="rtl"] .pager-link.next span::after { content: ' ←'; }
.site-footer {
    max-width: var(--content-w); padding: 24px 0 40px; border-top: 1px solid var(--border);
    font-size: 13.5px; color: var(--text-muted); display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
}
.site-footer p { margin: 0; }
.site-footer a { color: var(--text-muted); }
.layout-home .site-footer { max-width: 1040px; }

.back-to-top {
    position: fixed; inset-inline-end: 20px; bottom: 20px; z-index: 50;
    width: 42px; height: 42px; border-radius: 50%;
    border: 1px solid var(--border); background: var(--surface); color: var(--text-soft);
    box-shadow: var(--shadow); cursor: pointer; font-size: 18px;
    opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .2s, transform .2s;
}
.back-to-top.show { opacity: 1; pointer-events: auto; transform: none; }

/* ---------- Search dialog ---------- */
.search-dialog {
    position: fixed; inset: 0; z-index: 300;
    display: flex; justify-content: center; align-items: flex-start;
    padding: 10vh 16px 16px;
    background: rgba(15, 13, 30, .45); backdrop-filter: blur(3px);
}
.search-dialog[hidden] { display: none; }
.search-panel {
    width: min(640px, 100%); max-height: 70vh; display: flex; flex-direction: column;
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); overflow: hidden;
}
.search-field { display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--border); color: var(--text-muted); }
.search-field input {
    flex: 1; height: 56px; border: 0; outline: 0; background: transparent;
    font: inherit; font-size: 17px; color: var(--text);
}
.search-field input::-webkit-search-cancel-button { display: none; }
.search-results { list-style: none; margin: 0; padding: 8px; overflow-y: auto; }
.search-results:empty { display: none; }
.search-results a { display: block; padding: 10px 12px; border-radius: 10px; color: var(--text-soft); }
.search-results a:hover, .search-results a[aria-selected="true"] { background: var(--brand-soft); text-decoration: none; }
.search-results .r-path { font-size: 12px; color: var(--text-muted); }
.search-results .r-title { display: block; color: var(--text); font-weight: 600; font-size: 15px; }
.search-results .r-text { display: block; font-size: 13.5px; color: var(--text-muted); margin-top: 2px; }
.search-results mark { background: color-mix(in srgb, var(--brand) 22%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.search-empty { margin: 0; padding: 28px; text-align: center; color: var(--text-muted); }

/* Inline "On this page" for small screens */
.toc-inline { display: none; margin: 0 0 24px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-soft); }
.toc-inline summary { cursor: pointer; padding: 12px 16px; font-weight: 600; color: var(--text); }
.toc-inline ul { margin: 0; padding: 0 16px 12px; padding-inline-start: 34px; }
.toc-inline li { margin: 4px 0; font-size: 14.5px; }

.sidebar-overlay { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1220px) {
    .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
    .toc { display: none; }
    .toc-inline { display: block; }
}
@media (max-width: 960px) {
    .layout, .layout-home { grid-template-columns: minmax(0, 1fr); }
    .menu-toggle { display: inline-flex; }
    .sidebar {
        position: fixed; top: var(--header-h); bottom: 0; inset-inline-start: 0; z-index: 90;
        width: min(300px, 86vw); height: auto;
        background: var(--bg); box-shadow: var(--shadow-lg);
        transform: translateX(-105%); transition: transform .25s ease;
    }
    html[dir="rtl"] .sidebar { transform: translateX(105%); }
    .menu-open .sidebar { transform: none !important; }
    .sidebar-overlay { display: block; position: fixed; inset: var(--header-h) 0 0; z-index: 80; background: rgba(15, 13, 30, .4); opacity: 0; pointer-events: none; transition: opacity .2s; }
    .menu-open .sidebar-overlay { opacity: 1; pointer-events: auto; }
    .header-link { display: none; }
}
@media (max-width: 680px) {
    .header { gap: 8px; padding: 0 12px; }
    .search-trigger { flex: 0 0 auto; width: 38px; padding: 0; justify-content: center; margin-inline-start: auto; }
    .search-trigger .search-label, .search-trigger kbd, .brand-tag, .header-cta { display: none; }
    .content { padding-top: 24px; }
    .doc h2 { font-size: 21px; margin-top: 40px; }
    .pager { grid-template-columns: 1fr; }
    .pager-link.next { grid-column: auto; }
    .hero-search kbd { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media print {
    .header, .sidebar, .toc, .toc-inline, .pager, .help-box, .back-to-top, .search-dialog { display: none !important; }
    .layout { display: block; }
    .content { padding: 0; }
    a { color: inherit; }
}

/* ---------- 404 ---------- */
.not-found { text-align: center; padding: 10vh 0 6vh; }
.not-found .nf-code {
    font-size: clamp(72px, 14vw, 120px); font-weight: 800; line-height: 1; letter-spacing: -.04em;
    background: linear-gradient(135deg, var(--brand), #20c4c4); -webkit-background-clip: text; background-clip: text; color: transparent;
    margin-bottom: 8px;
}
.not-found p { color: var(--text-muted); max-width: 460px; margin: 0 auto 24px; }
.not-found .hero-search { margin: 0 auto 20px; }
.not-found .hero-buttons { justify-content: center; }

/* ---------- Workflows, formulas, trees (converted from text diagrams) ---------- */
.doc .flow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 10px; }
.doc .flow-step {
    padding: 6px 12px; border-radius: 999px; font-size: 14px; font-weight: 600;
    color: var(--brand); background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 20%, transparent);
}
.doc .flow-sep { color: var(--text-muted); font-size: 14px; }
.doc .flow + :not(.flow-note) { margin-top: 16px; }
.doc .flow-note { font-size: 14px; color: var(--text-muted); margin: 0 0 22px; }
.doc .flow-note::before { content: '↳ '; }
html[dir="rtl"] .doc .flow-note::before { content: '↲ '; }
.doc pre.formula { font-family: var(--font); font-size: 14.5px; white-space: pre-wrap; background: var(--bg-soft); }
html[dir="rtl"] .doc pre.formula { direction: rtl; text-align: right; }
.doc pre.tree { font-size: 13.5px; background: var(--bg-soft); }

/* ---------- App store badges ---------- */
.store-badges { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 14px; }
.store-badge {
    display: inline-flex; align-items: center; gap: 10px;
    min-width: 168px; padding: 8px 16px 8px 12px; border-radius: 12px;
    background: #111; color: #fff; border: 1px solid #333;
    transition: transform .15s, box-shadow .15s;
}
html[dir="rtl"] .store-badge { padding: 8px 12px 8px 16px; }
.store-badge:hover { color: #fff; text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow); }
.store-badge svg { width: 24px; height: 24px; flex: none; }
.store-badge span { display: flex; flex-direction: column; line-height: 1.15; text-align: start; }
.store-badge small { font-size: 11px; opacity: .85; }
.store-badge strong { font-size: 17px; font-weight: 600; color: #fff; letter-spacing: -.01em; }
[data-theme="dark"] .store-badge { background: #000; border-color: #3a3a46; }
.doc .store-note { font-size: 14px; color: var(--text-muted); }
.hero-apps { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--border); }
.hero-apps > span { font-size: 14px; font-weight: 600; color: var(--text-soft); }
.hero-apps .store-badges { margin: 0; }

/* ---------- Process cycle (circular workflow) ---------- */
.doc .cycle { position: relative; width: 100%; max-width: 480px; aspect-ratio: 1; margin: 8px auto 20px; }
.doc .cycle-ring { position: absolute; inset: 0; width: 100%; height: 100%; color: var(--brand); overflow: visible; }
.doc .cycle-ring .track { fill: none; stroke: var(--border); stroke-width: 2; stroke-dasharray: 4 6; }
.doc .cycle-ring path { fill: none; stroke: currentColor; stroke-width: 2.5; }
.doc .cycle-steps { list-style: none; margin: 0; padding: 0; }
.doc .cycle-steps li { position: absolute; width: 22%; aspect-ratio: 1; transform: translate(-50%, -50%); margin: 0; }
.doc .cycle-steps a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    box-sizing: border-box; width: 100%; height: 100%; border-radius: 50%; text-align: center; text-decoration: none; padding: 6px;
    font-size: 13px; font-weight: 600; line-height: 1.25; color: var(--text);
    background: var(--surface); border: 2px solid var(--brand); box-shadow: var(--shadow-sm);
    transition: background .15s, transform .15s;
}
.doc .cycle-steps a:hover { background: var(--brand-soft); transform: scale(1.05); }
.doc .cycle-steps .n {
    display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
    border-radius: 50%; background: var(--brand); color: #fff; font-size: 12px;
}
.doc .cycle-center {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 44%;
    text-align: center; margin: 0;
}
.doc .cycle-center strong { display: block; font-size: 17px; color: var(--brand); }
.doc .cycle-center span { display: block; font-size: 13px; color: var(--text-muted); margin-top: 4px; }
@media (max-width: 560px) {
    .doc .cycle { aspect-ratio: auto; max-width: none; }
    .doc .cycle-ring { display: none; }
    .doc .cycle-steps li { position: static; transform: none; width: auto; aspect-ratio: auto; }
    .doc .cycle-steps li + li::before { content: '↓'; display: block; text-align: center; color: var(--text-muted); margin: 2px 0; }
    .doc .cycle-steps a { flex-direction: row; justify-content: flex-start; gap: 10px; height: auto; border-radius: var(--radius-sm); padding: 10px 14px; font-size: 14px; }
    .doc .cycle-steps a br { display: none; }
    .doc .cycle-center { position: static; transform: none; width: auto; margin-top: 10px; padding: 10px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); }
    .doc .cycle-center strong::before { content: '↺ '; }
}

/* ---------- 8-step process cycle ---------- */
.doc .cycle--8 .cycle-steps li { width: 19%; }
.doc .cycle--8 .cycle-steps a { font-size: 12px; padding: 4px; }
@media (max-width: 560px) {
    .doc .cycle--8 .cycle-steps li { width: auto; }
    .doc .cycle--8 .cycle-steps a { font-size: 14px; padding: 10px 14px; }
}
