/* ===== shadcn-style docs layout ===== */
.docs-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.docs-shell > .docs-page {
    flex: 1 0 auto;
}

.docs-page {
    position: relative;
    padding: calc(var(--nav-h, 72px) + 2rem) 0 5rem;
    background:
        radial-gradient(1100px 500px at 85% -10%, rgba(var(--brand-accent-rgb), .18), transparent 60%),
        radial-gradient(900px 500px at 0% 10%, rgba(var(--brand-ui-rgb), .14), transparent 55%),
        linear-gradient(180deg, #eef4ff 0%, var(--bg) 100%);
    color: var(--ink, #0f172a);
}

.docs-container {
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 clamp(1rem, 3vw, 2rem);
}

/* 3-column frame: nav | content | toc */
.docs-frame {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr) 200px;
    gap: 0 2.5rem;
    align-items: start;
}

/* ===== Left nav (shadcn sidebar) ===== */
.docs-nav-aside,
.docs-toc-aside {
    position: sticky;
    top: calc(var(--nav-h, 72px) + 1rem);
    align-self: start;
    max-height: calc(100vh - var(--nav-h, 72px) - 2rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    z-index: 2;
}

.docs-nav-aside {
    padding-right: 0.5rem;
}

.docs-nav-back {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--muted, #64748b) !important;
    text-decoration: none;
    margin-bottom: 1.5rem;
    padding: 0.25rem 0;
    transition: color 0.15s;
}

.docs-nav-back:hover {
    color: var(--ink, #0f172a) !important;
}

.docs-nav-group + .docs-nav-group {
    margin-top: 1.5rem;
}

.docs-nav-heading,
.docs-toc-heading {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted, #64748b);
    margin: 0 0 0.5rem;
    padding: 0 0.75rem;
}

.docs-nav {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.docs-nav-link {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 400;
    line-height: 1.4;
    color: var(--muted, #64748b);
    text-decoration: none;
    transition: background 0.12s, color 0.12s;
}

.docs-nav-link:hover {
    background: rgba(15, 23, 42, 0.05);
    color: var(--ink, #0f172a);
}

.docs-nav-link.is-active {
    background: rgba(15, 23, 42, 0.07);
    color: var(--ink, #0f172a);
    font-weight: 500;
}

.docs-nav-link--external {
    font-size: 0.8125rem;
}

.docs-nav-link--pdf {
    min-width: 0;
}

.docs-nav-link--pdf .docs-pdf-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

/* ===== Center content ===== */
.docs-center {
    min-width: 0;
    max-width: 720px;
    justify-self: center;
    width: 100%;
}

.docs-article-header {
    margin-bottom: 1.75rem;
}

.docs-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.25rem 2rem;
    flex-wrap: wrap;
}

.docs-page-header-content {
    min-width: 0;
    flex: 1 1 auto;
}

.docs-page-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    margin-top: 0.15rem;
}

.docs-header-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    height: 2.25rem;
    padding: 0 0.85rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1;
    color: var(--ink, #0f172a) !important;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 0.375rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.docs-header-btn:hover {
    background: #fff;
    border-color: rgba(15, 23, 42, 0.18);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    color: var(--ink, #0f172a) !important;
}

.docs-header-btn .bi {
    font-size: 0.95rem;
    opacity: 0.85;
}

.docs-header-nav-group {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 0.375rem;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.docs-header-icon-btn {
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    color: var(--ink, #0f172a);
    text-decoration: none;
    background: transparent;
    transition: background 0.12s;
}

.docs-header-icon-btn:hover {
    background: rgba(15, 23, 42, 0.05);
    color: var(--ink, #0f172a);
}

.docs-header-icon-btn + .docs-header-icon-btn,
.docs-header-icon-btn.is-disabled + .docs-header-icon-btn,
.docs-header-icon-btn + .docs-header-icon-btn.is-disabled {
    border-left: 1px solid rgba(15, 23, 42, 0.1);
}

.docs-header-icon-btn.is-disabled {
    opacity: 0.35;
    cursor: default;
}

.docs-header-icon-btn .bi {
    font-size: 1rem;
    line-height: 1;
}

.docs-article-title {
    font-size: clamp(1.875rem, 4vw, 2.25rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.15;
    margin: 0 0 0.5rem;
}

.docs-article-meta {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0.15rem 0 0;
    font-size: 0.8125rem;
    font-weight: 400;
    line-height: 1.4;
    color: var(--muted, #64748b);
    opacity: 0.9;
}

.docs-article-meta .bi {
    font-size: 0.8125rem;
    opacity: 0.55;
}

.docs-article-meta time {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
}

/* ===== Right TOC (On This Page) ===== */
.docs-toc-aside {
    padding-left: 0.5rem;
    border-left: 1px solid rgba(15, 23, 42, 0.08);
}

.docs-toc {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.docs-toc-link {
    display: block;
    padding: 0.25rem 0.75rem;
    font-size: 0.8125rem;
    line-height: 1.45;
    color: var(--muted, #64748b);
    text-decoration: none;
    border-left: 2px solid transparent;
    margin-left: -1px;
    transition: color 0.12s, border-color 0.12s;
}

.docs-toc-link:hover {
    color: var(--ink, #0f172a);
}

.docs-toc-link.is-active {
    color: var(--ink, #0f172a);
    font-weight: 500;
    border-left-color: var(--ink, #0f172a);
}

.docs-toc-link--sub {
    padding-left: 1.25rem;
    font-size: 0.75rem;
}

/* ===== Pager (prev / next) ===== */
.docs-pager {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(15, 23, 42, 0.08);
}

.docs-pager-link {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 1rem 1.15rem;
    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 0.5rem;
    text-decoration: none;
    color: inherit;
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(8px);
    transition: border-color 0.15s, background 0.15s;
}

.docs-pager-link:hover {
    border-color: rgba(15, 23, 42, 0.18);
    background: rgba(255, 255, 255, 0.85);
}

.docs-pager-link--next {
    text-align: right;
    grid-column: 2;
}

.docs-pager-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--muted, #64748b);
}

.docs-pager-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ink, #0f172a);
}

/* ===== Markdown prose ===== */
.docs-content.markdown-body {
    line-height: 1.75;
    font-size: 1rem;
    color: var(--ink, #0f172a);
}

.docs-content.markdown-body > :first-child {
    margin-top: 0;
}

.docs-content.markdown-body h2,
.docs-content.markdown-body h3,
.docs-content.markdown-body h4,
.docs-content.markdown-body h5,
.docs-content.markdown-body h6 {
    scroll-margin-top: calc(var(--nav-h, 72px) + 1.25rem);
    font-weight: 600;
    letter-spacing: -0.015em;
    color: var(--ink, #0f172a);
    line-height: 1.35;
}

.docs-content.markdown-body h2 {
    font-size: 1.375rem;
    margin: 2.5rem 0 0.75rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

.docs-content.markdown-body h3 {
    font-size: 1.125rem;
    margin: 2rem 0 0.5rem;
}

.docs-content.markdown-body h4 {
    font-size: 1rem;
    margin: 1.5rem 0 0.4rem;
    font-weight: 600;
}

.docs-content.markdown-body h5 {
    font-size: 0.9375rem;
    margin: 1.25rem 0 0.35rem;
    font-weight: 600;
}

.docs-content.markdown-body h6 {
    font-size: 0.875rem;
    margin: 1rem 0 0.3rem;
    font-weight: 600;
    color: var(--muted, #64748b);
}

.docs-content.markdown-body p,
.docs-content.markdown-body ul,
.docs-content.markdown-body ol {
    margin-bottom: 1.125rem;
}

.docs-content.markdown-body ul,
.docs-content.markdown-body ol {
    padding-left: 1.5rem;
}

.docs-content.markdown-body li + li {
    margin-top: 0.25rem;
}

.docs-content.markdown-body strong {
    font-weight: 600;
}

.docs-content.markdown-body img {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
    border: 1px solid rgba(15, 23, 42, 0.1);
    margin: 1.5rem 0;
}

.docs-content.markdown-body code {
    font-size: 0.875em;
    background: rgba(15, 23, 42, 0.06);
    padding: 0.15rem 0.4rem;
    border-radius: 0.25rem;
}

.docs-content.markdown-body pre {
    background: #18181b;
    color: #fafafa;
    padding: 1rem 1.15rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
    line-height: 1.6;
}

.docs-content.markdown-body pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

.docs-content.markdown-body blockquote {
    margin: 1.25rem 0;
    padding: 0.75rem 1rem;
    border-left: 3px solid var(--brand, #1872c4);
    background: rgba(var(--brand-ui-rgb, 24, 114, 196), 0.06);
    border-radius: 0 0.375rem 0.375rem 0;
    color: var(--muted, #64748b);
}

.docs-content.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
}

.docs-content.markdown-body th,
.docs-content.markdown-body td {
    border: 1px solid rgba(15, 23, 42, 0.1);
    padding: 0.5rem 0.75rem;
    text-align: left;
}

.docs-content.markdown-body th {
    background: rgba(15, 23, 42, 0.04);
    font-weight: 600;
}

/* ===== Dark mode ===== */
[data-theme="dark"] .docs-page {
    background:
        radial-gradient(1100px 500px at 85% -10%, rgba(var(--brand-accent-rgb), .14), transparent 60%),
        radial-gradient(900px 500px at 0% 10%, rgba(var(--brand-ui-rgb), .12), transparent 55%),
        linear-gradient(180deg, #0f172a 0%, #0b1120 100%);
}

[data-theme="dark"] .docs-article-header,
[data-theme="dark"] .docs-pager,
[data-theme="dark"] .docs-toc-aside {
    border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .docs-nav-link:hover,
[data-theme="dark"] .docs-nav-link.is-active {
    background: rgba(255, 255, 255, 0.06);
    color: #e2e8f0;
}

[data-theme="dark"] .docs-nav-link {
    color: #94a3b8;
}

[data-theme="dark"] .docs-toc-link.is-active {
    border-left-color: #e2e8f0;
    color: #e2e8f0;
}

[data-theme="dark"] .docs-toc-link:hover {
    color: #e2e8f0;
}

[data-theme="dark"] .docs-pager-link {
    background: rgba(19, 28, 46, 0.7);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .docs-pager-link:hover {
    background: rgba(19, 28, 46, 0.95);
}

[data-theme="dark"] .docs-header-btn,
[data-theme="dark"] .docs-header-nav-group {
    background: rgba(19, 28, 46, 0.85);
    border-color: rgba(255, 255, 255, 0.12);
    color: #e2e8f0 !important;
}

[data-theme="dark"] .docs-header-btn:hover {
    background: rgba(19, 28, 46, 1);
    color: #fff !important;
}

[data-theme="dark"] .docs-header-icon-btn {
    color: #e2e8f0;
}

[data-theme="dark"] .docs-header-icon-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

[data-theme="dark"] .docs-header-icon-btn + .docs-header-icon-btn,
[data-theme="dark"] .docs-header-icon-btn.is-disabled + .docs-header-icon-btn,
[data-theme="dark"] .docs-header-icon-btn + .docs-header-icon-btn.is-disabled {
    border-left-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .docs-content.markdown-body code {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .docs-content.markdown-body h2 {
    border-color: rgba(255, 255, 255, 0.08);
}

/* ===== Responsive ===== */
@media (max-width: 1199px) {
    .docs-frame {
        grid-template-columns: 200px minmax(0, 1fr);
        gap: 0 2rem;
    }

    .docs-toc-aside {
        display: none;
    }

    .docs-center {
        max-width: none;
        grid-column: 2;
    }
}

@media (max-width: 767px) {
    .docs-page {
        padding-top: calc(var(--nav-h, 72px) + 1.25rem);
    }

    .docs-frame {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .docs-nav-aside {
        position: static;
        max-height: none;
        overflow: visible;
        padding-right: 0;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.5rem 0.75rem;
        padding-bottom: 1rem;
        border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    }

    .docs-nav-back {
        margin-bottom: 0;
        width: 100%;
    }

    .docs-nav-group {
        display: contents;
    }

    .docs-nav-heading {
        display: none;
    }

    .docs-nav {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.35rem;
        width: 100%;
    }

    .docs-nav-link {
        font-size: 0.8125rem;
        padding: 0.35rem 0.65rem;
        border: 1px solid rgba(15, 23, 42, 0.1);
        background: rgba(255, 255, 255, 0.6);
    }

    .docs-nav-link.is-active {
        border-color: rgba(15, 23, 42, 0.2);
        background: rgba(255, 255, 255, 0.9);
    }

    .docs-center {
        grid-column: 1;
    }

    .docs-pager {
        grid-template-columns: 1fr;
    }

    .docs-pager-link--next {
        grid-column: 1;
        text-align: left;
    }

    .docs-page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .docs-page-header-content {
        flex: none;
    }

    .docs-page-header-actions {
        width: 100%;
        justify-content: flex-start;
        margin-top: 0;
    }

    .docs-article-header {
        margin-bottom: 1.25rem;
    }

    .docs-article-title {
        font-size: 1.625rem;
    }
}

/* ===== Admin (legacy) ===== */
.doc-markdown-editor {
    font-size: 0.9rem;
    line-height: 1.5;
    tab-size: 2;
}

.doc-admin-preview {
    min-height: 200px;
}

.doc-admin-preview img {
    max-width: 100%;
    height: auto;
}
