/* ==========================================================================
   layout.css — 骨架：header、側欄、內容欄、右側欄
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html {
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--h-header) + 32px);
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    -webkit-font-smoothing: antialiased;
}

/* 內容一律浮在背景光暈層之上 */
.doc-header,
.doc-sidebar,
.doc-main { position: relative; z-index: var(--z-content); }

/* ---------- Header ---------- */

.doc-header {
    position: fixed;
    inset: 0 0 auto 0;
    height: var(--h-header);
    z-index: var(--z-header);
    display: flex;
    align-items: center;
    gap: var(--sp-5);
    padding: 0 var(--sp-5);
    border-bottom: 1px solid var(--hairline);
}

.doc-brand {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    text-decoration: none;
    color: var(--text);
    flex-shrink: 0;
}

/* VoAI 是雙行字標（VoAI + 絕好聲創），26px 會讓中文那行糊掉，拉到 34px */
.doc-brand img { height: 34px; width: auto; display: block; }

.doc-brand span {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text-muted);
    padding-left: var(--sp-3);
    border-left: 1px solid var(--hairline);
    white-space: nowrap;
}

.doc-header__spacer { flex: 1; }

.doc-header__links { display: flex; align-items: center; gap: var(--sp-5); }

.doc-header__links a {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
}

.doc-header__links a:hover { color: var(--text); }

/* 搜尋 */
.doc-search { position: relative; width: 250px; flex-shrink: 1; }

.doc-search input {
    width: 100%;
    height: 36px;
    padding: 0 var(--sp-4);
    font-family: inherit;
    font-size: var(--fs-sm);
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-full);
    outline: none;
}

.doc-search input::placeholder { color: var(--text-subtle); }
.doc-search input:focus { border-color: var(--border-strong); background: var(--surface-hover); }

.doc-search kbd {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    color: var(--text-subtle);
    pointer-events: none;
}

.doc-search input:focus + kbd { display: none; }

.doc-search__results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    max-height: 340px;
    overflow-y: auto;
    padding: var(--sp-2);
    display: none;
}

.doc-search__results[data-open="true"] { display: block; }

.doc-search__results a {
    display: block;
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--r-md);
    text-decoration: none;
    color: var(--text);
    font-size: var(--fs-sm);
    line-height: 1.4;
}

.doc-search__results a:hover,
.doc-search__results a[data-active="true"] { background: var(--surface-hover); }

.doc-search__results small { display: block; color: var(--text-subtle); font-size: var(--fs-xs); }
.doc-search__empty { padding: var(--sp-3); color: var(--text-subtle); font-size: var(--fs-sm); }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid transparent;
    border-radius: var(--r-full);
    cursor: pointer;
    padding: 0;
}

.icon-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border); }
.icon-btn svg { width: 17px; height: 17px; }

.doc-menu-btn { display: none; }

/* ---------- 側欄 ---------- */

.doc-sidebar {
    position: fixed;
    top: var(--h-header);
    bottom: 0;
    left: 0;
    width: var(--w-sidebar);
    z-index: var(--z-sidebar);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--sp-6) var(--sp-4) var(--sp-9);
    border-right: 1px solid var(--hairline);
}

.nav-group + .nav-group { margin-top: var(--sp-6); }

.nav-group__title {
    font-size: var(--fs-xs);
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-subtle);
    padding: 0 var(--sp-3);
    margin-bottom: var(--sp-3);
}

.nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 9px var(--sp-3);
    border-radius: var(--r-md);
    font-size: var(--fs-sm);
    line-height: 1.45;
    color: var(--text-muted);
    text-decoration: none;
}

.nav-link:hover { background: var(--surface); color: var(--text); }

.nav-link[aria-current="page"] {
    background: var(--surface-hover);
    color: var(--text);
    font-weight: 600;
}

/* 目前頁左側的指示條 */
.nav-link[aria-current="page"]::before {
    content: "";
    position: absolute;
    left: 0;
    top: 20%;
    bottom: 20%;
    width: 2px;
    border-radius: var(--r-full);
    background: var(--text);
}

.nav-link__icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: .8;
}

.nav-link__icon svg { width: 100%; height: 100%; display: block; }

/* ---------- 主內容 ---------- */

.doc-main {
    padding-top: var(--h-header);
    padding-left: var(--w-sidebar);
}

.doc-layout {
    display: grid;
    gap: var(--sp-7);
    padding: var(--sp-8) var(--sp-6) var(--sp-9);
    margin: 0 auto;
}

.doc-layout--article {
    grid-template-columns: minmax(0, var(--w-content)) var(--w-toc);
    max-width: calc(var(--w-content) + var(--w-toc) + var(--sp-7) + var(--sp-6) * 2);
}

.doc-layout--reference {
    grid-template-columns: minmax(0, var(--w-content)) var(--w-codepanel);
    max-width: calc(var(--w-content) + var(--w-codepanel) + var(--sp-7) + var(--sp-6) * 2);
}

/* 首頁：滿版單欄，讓 hero 展得開 */
.doc-layout--wide {
    grid-template-columns: minmax(0, 1fr);
    max-width: 1120px;
    padding-top: var(--sp-7);
}

.doc-content { min-width: 0; }

/* ---------- 右側 sticky 欄 ---------- */

.doc-aside {
    position: sticky;
    top: calc(var(--h-header) + var(--sp-6));
    align-self: start;
    max-height: calc(100vh - var(--h-header) - var(--sp-8));
    overflow-y: auto;
    min-width: 0;
}

.toc__title {
    font-size: var(--fs-xs);
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-subtle);
    margin-bottom: var(--sp-3);
}

.toc a {
    display: block;
    padding: 5px 0 5px var(--sp-4);
    border-left: 2px solid var(--hairline);
    font-size: var(--fs-sm);
    line-height: 1.5;
    color: var(--text-muted);
    text-decoration: none;
}

.toc a:hover { color: var(--text); }

.toc a[data-active="true"] {
    color: var(--text);
    font-weight: 600;
    border-left-color: var(--text);
}

.toc a[data-level="3"] { padding-left: var(--sp-6); font-size: var(--fs-xs); }

/* ---------- 頁尾導航 ---------- */

.doc-pager {
    display: flex;
    gap: var(--sp-4);
    margin-top: var(--sp-9);
    padding-top: var(--sp-6);
    border-top: 1px solid var(--hairline);
}

.doc-pager a {
    flex: 1;
    padding: var(--sp-4) var(--sp-5);
    border-radius: var(--r-lg);
    text-decoration: none;
    color: var(--text);
    font-size: var(--fs-sm);
    font-weight: 600;
    background: var(--surface);
    border: 1px solid var(--border);
}

.doc-pager a:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.doc-pager small { display: block; color: var(--text-subtle); font-size: var(--fs-xs); font-weight: 400; }
.doc-pager .is-next { text-align: right; }

/* ---------- 響應式 ---------- */

@media (max-width: 1280px) {
    .doc-layout--reference,
    .doc-layout--article {
        grid-template-columns: minmax(0, 1fr);
        max-width: 880px;
    }

    .doc-aside { position: static; max-height: none; }
    .doc-layout--article .doc-aside { display: none; }
}

@media (max-width: 1024px) {
    .doc-main { padding-left: 0; }

    .doc-sidebar {
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 0 0 60px rgba(0, 0, 0, .45);
    }

    .doc-sidebar[data-open="true"] { transform: translateX(0); }

    .doc-menu-btn { display: inline-flex; }
    .doc-header__links { display: none; }
    .doc-search { width: 190px; }
}

@media (max-width: 640px) {
    .doc-layout { padding: var(--sp-6) var(--sp-4) var(--sp-8); }
    .doc-search { display: none; }
    .doc-brand span { display: none; }
}
