/* Handbook pages - see api/v1/routers/docs.py. Layout and behaviour follow
   iks-lifecycle-management's docs pages; the colours are Keal's own theme
   tokens from keal.css, so these pages follow the app's light/dark setting
   rather than carrying a palette of their own.

   Full height, three independently scrolling columns: index | article |
   contents. Below 1100px the contents column becomes a right-hand drawer,
   below 700px the index becomes a left-hand one. */

html, body { height: 100%; }
body { display: flex; flex-direction: column; overflow: hidden; }

/* Framed by the app's Docs tab: the app already draws the header. */
[data-embedded] header { display: none; }

.docs-back { color: rgba(255,255,255,0.7); font-size: 13px; text-decoration: none; }
.docs-back:hover { color: #fff; }

.docs-layout { flex: 1; display: flex; min-height: 0; position: relative; }

/* ── Index ─────────────────────────────────────────────────────────────── */
.docs-nav {
    width: 230px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border-strong);
    padding: 14px 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.docs-search-wrap { padding: 0 12px 10px; }
#docs-search {
    width: 100%;
    padding: 6px 10px;
    font-size: 13px;
    border: 1px solid var(--border-input);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    outline: none;
}
#docs-search:focus { border-color: var(--accent); }

a.nav-item {
    display: block;
    padding: 7px 14px;
    margin: 0 6px;
    font-size: 13px;
    color: var(--text);
    text-decoration: none;
    border-radius: 6px;
}
a.nav-item:hover { background: var(--surface-hover); }
a.nav-item.active { background: var(--surface-selected); color: var(--accent); font-weight: 600; }

/* Results take the index's place while searching, rather than covering the
   article - the reader is choosing where to go, not reading yet. */
#docs-search-results { display: flex; flex-direction: column; gap: 1px; padding: 0 6px; }
a.search-result { display: block; padding: 7px 10px; border-radius: 6px; text-decoration: none; color: var(--text); }
a.search-result:hover { background: var(--surface-hover); }
.sr-title { font-size: 13px; font-weight: 600; }
.sr-page { font-size: 11px; color: var(--text-faint); font-weight: 400; margin-left: 6px; }
.sr-snippet { font-size: 11px; color: var(--text-muted); margin-top: 2px; line-height: 1.4; }
.sr-title mark, .sr-snippet mark { background: rgba(250,204,21,0.4); color: inherit; border-radius: 2px; padding: 0 1px; }
.sr-empty { padding: 10px 12px; font-size: 12px; color: var(--text-muted); }

/* ── Contents ──────────────────────────────────────────────────────────── */
.docs-toc {
    width: 210px;
    flex-shrink: 0;
    background: var(--surface);
    border-left: 1px solid var(--border-strong);
    padding: 20px 12px;
    overflow-y: auto;
}
.docs-toc-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding: 0 8px;
}
.toc-list { display: flex; flex-direction: column; gap: 1px; }
a.toc-link {
    display: block;
    color: var(--text-muted);
    text-decoration: none;
    padding: 3px 8px;
    border-left: 2px solid transparent;
    font-size: 12px;
    line-height: 1.4;
}
a.toc-link:hover { color: var(--text); }
a.toc-link.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
a.toc-l3 { padding-left: 20px; font-size: 11px; }

/* ── Drawer controls, only shown at the widths that need them ──────────── */
.nav-toggle, .toc-toggle {
    display: none;
    position: absolute;
    top: 10px;
    z-index: 30;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--text);
    border-radius: 6px;
    font-size: 12px;
    line-height: 1;
    padding: 7px 10px;
    cursor: pointer;
}
.nav-toggle { left: 12px; }
.toc-toggle { right: 12px; }
.nav-backdrop {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 20;
}
.nav-backdrop.show { display: block; }

/* ── Article ───────────────────────────────────────────────────────────── */
.docs-content {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding: 34px 44px 64px;
    scroll-behavior: smooth;
    font-size: 15px;
    line-height: 1.65;
}
/* Running text stays readable on a wide screen; diagrams, tables and code
   may use the full width. */
.docs-content > * { max-width: 72ch; }
.docs-content > table, .docs-content > pre, .docs-content > .mermaid-container { max-width: 100%; }

.docs-content h1 { font-size: 26px; font-weight: 700; margin: 0 0 18px; padding-bottom: 12px; border-bottom: 1px solid var(--border-strong); text-wrap: balance; }
.docs-content h2 { font-size: 19px; font-weight: 650; margin: 32px 0 10px; text-wrap: balance; scroll-margin-top: 12px; }
.docs-content h3 { font-size: 15.5px; font-weight: 650; margin: 24px 0 8px; scroll-margin-top: 12px; }
.docs-content p { margin: 0 0 14px; }
.docs-content ul, .docs-content ol { margin: 0 0 14px; padding-left: 22px; }
.docs-content li { margin-bottom: 5px; }
.docs-content a { color: var(--accent); }
.docs-content .toclink { color: inherit; text-decoration: none; }
.docs-content .headerlink { color: var(--text-faint); text-decoration: none; margin-left: 8px; opacity: 0; font-weight: 400; }
.docs-content h1:hover .headerlink,
.docs-content h2:hover .headerlink,
.docs-content h3:hover .headerlink { opacity: 1; }

.docs-content code {
    font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.88em;
    background: var(--surface-hover);
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    padding: 1px 5px;
}
.docs-content pre {
    position: relative;
    background: var(--surface-hover);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 14px 16px;
    overflow-x: auto;
    margin: 0 0 16px;
}
.docs-content pre code { background: none; border: none; padding: 0; font-size: 13px; line-height: 1.55; }
.copy-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 5;
    font: inherit;
    font-size: 11px;
    line-height: 1;
    padding: 4px 8px;
    border: 1px solid var(--border-strong);
    border-radius: 5px;
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: opacity .12s, color .12s;
}
.docs-content pre:hover .copy-btn, .copy-btn:focus { opacity: 1; }
.copy-btn:hover { color: var(--text); }
.copy-btn.copied { color: var(--btn-success); border-color: var(--btn-success); opacity: 1; }

.docs-content blockquote { margin: 0 0 16px; padding: 2px 16px; border-left: 3px solid var(--border-input); color: var(--text-muted); }
.docs-content table { border-collapse: collapse; width: 100%; margin: 0 0 18px; font-size: 14px; display: block; overflow-x: auto; }
.docs-content th, .docs-content td { border: 1px solid var(--border-strong); padding: 7px 12px; text-align: left; }
.docs-content th { background: var(--surface-hover); font-weight: 650; }
.docs-content hr { border: none; border-top: 1px solid var(--border-strong); margin: 28px 0; }

.docs-content .admonition {
    border: 1px solid var(--border-strong);
    border-left: 3px solid var(--accent);
    border-radius: 6px;
    padding: 12px 16px;
    margin: 0 0 16px;
    background: var(--surface-hover);
}
.docs-content .admonition-title { font-weight: 650; margin: 0 0 6px; }
.docs-content .admonition.warning { border-left-color: var(--btn-warning); }
.docs-content .admonition.danger  { border-left-color: var(--btn-danger); }
.docs-content .admonition.tip     { border-left-color: var(--btn-success); }

.mermaid-container { margin: 0 0 20px; overflow-x: auto; text-align: center; }
.mermaid-container svg { max-width: 100%; height: auto; }

/* ── Progressive collapse ──────────────────────────────────────────────── */
@media (max-width: 1100px) {
    .docs-toc {
        position: absolute;
        top: 0; right: 0;
        height: 100%;
        z-index: 25;
        transform: translateX(100%);
        transition: transform .2s ease;
    }
    /* Shadow only while open - a closed drawer sits just off the edge, and
       its shadow would still fall across the page. */
    .docs-toc.open { transform: translateX(0); box-shadow: -2px 0 10px rgba(0,0,0,0.25); }
    .toc-toggle { display: block; }
    .docs-content { padding-top: 52px; }
}
@media (max-width: 700px) {
    .docs-nav {
        position: absolute;
        top: 0; left: 0;
        height: 100%;
        z-index: 25;
        transform: translateX(-100%);
        transition: transform .2s ease;
    }
    .docs-nav.open { transform: translateX(0); box-shadow: 2px 0 10px rgba(0,0,0,0.25); }
    .nav-toggle { display: block; }
    .docs-content { padding: 52px 20px 40px; }
}
