/* Samoya Docs - GitBook-inspired theme */
/* Zero dependencies. Pure CSS. */

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

:root {
    --bg: #ffffff;
    --bg-secondary: #fafafa;
    --text: #1a1a1a;
    --text-secondary: #6b6b6b;
    --text-tertiary: #999;
    --border: #eaeaea;
    --border-light: #f0f0f0;
    --accent: #5b6abf;
    --accent-light: #f0f1ff;
    --sidebar-bg: #fafafa;
    --sidebar-width: 260px;
    --toc-width: 240px;
    --header-height: 52px;
    --hint-info-bg: #f0f4ff;
    --hint-info-border: #5b6abf;
    --hint-success-bg: #f0faf4;
    --hint-success-border: #2ecc71;
    --hint-warning-bg: #fffbf0;
    --hint-warning-border: #f0a500;
    --hint-danger-bg: #fff5f5;
    --hint-danger-border: #e74c3c;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --radius: 8px;
}

[data-theme="dark"] {
    --bg: #181818;
    --bg-secondary: #1e1e1e;
    --text: #e0e0e0;
    --text-secondary: #999;
    --text-tertiary: #666;
    --border: #2a2a2a;
    --border-light: #222;
    --accent: #7c8aff;
    --accent-light: rgba(124,138,255,0.1);
    --sidebar-bg: #141414;
    --hint-info-bg: rgba(91,106,191,0.08);
    --hint-success-bg: rgba(46,204,113,0.08);
    --hint-warning-bg: rgba(240,165,0,0.08);
    --hint-danger-bg: rgba(231,76,60,0.08);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

/* ==================== Header ==================== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    backdrop-filter: blur(12px);
    background: rgba(255,255,255,0.92);
}

[data-theme="dark"] .header {
    background: rgba(24,24,24,0.92);
}

.header-inner {
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 20px 0 calc(var(--sidebar-width) + 24px);
    gap: 16px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

/* ==================== Search ==================== */
.search-wrapper {
    position: relative;
    flex: 1;
    max-width: 480px;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 8px 72px 8px 40px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
    transition: all 0.15s ease;
}

.search-input::placeholder {
    color: var(--text-tertiary);
}

.search-input:focus {
    border-color: var(--accent);
    background: var(--bg);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.search-shortcut {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-family: inherit;
    font-size: 0.65rem;
    color: var(--text-tertiary);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    pointer-events: none;
}

/* Search Results Dropdown */
.search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
    max-height: 400px;
    overflow-y: auto;
    z-index: 200;
    display: none;
}

[data-theme="dark"] .search-results {
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}

.search-results.visible {
    display: block;
}

.search-result {
    display: block;
    padding: 12px 16px;
    text-decoration: none;
    border-bottom: 1px solid var(--border-light);
    transition: background 0.1s ease;
}

.search-result:last-child {
    border-bottom: none;
}

.search-result:hover {
    background: var(--bg-secondary);
}

.search-result-title {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 2px;
}

.search-result-section {
    font-size: 0.7rem;
    color: var(--text-tertiary);
}

.search-result-snippet {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
    line-height: 1.4;
}

.search-result-snippet mark {
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 2px;
    padding: 0 2px;
}

.search-no-results {
    padding: 20px 16px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.82rem;
}

/* ==================== Sidebar Brand ==================== */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 12px 14px;
    text-decoration: none;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
    height: var(--header-height);
}

.brand-logo {
    width: 18px;
    height: auto;
    flex-shrink: 0;
}

.brand-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text);
    letter-spacing: -0.01em;
}

/* Logo theme switching */
[data-theme="light"] .logo-dark,
:root:not([data-theme="dark"]) .logo-dark { display: none; }
[data-theme="light"] .logo-light,
:root:not([data-theme="dark"]) .logo-light { display: block; }
[data-theme="dark"] .logo-light { display: none; }
[data-theme="dark"] .logo-dark { display: block; }

/* ==================== Theme Toggle ==================== */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.theme-toggle:hover {
    border-color: var(--text-tertiary);
    color: var(--text);
}

[data-theme="dark"] .sun-icon { display: block; }
[data-theme="dark"] .moon-icon { display: none; }
[data-theme="light"] .sun-icon,
:root:not([data-theme="dark"]) .sun-icon { display: none; }
[data-theme="light"] .moon-icon,
:root:not([data-theme="dark"]) .moon-icon { display: block; }

.menu-toggle {
    display: none;
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--text);
}

/* ==================== Layout ==================== */
.layout {
    display: flex;
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
}

/* ==================== Sidebar ==================== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    z-index: 110;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.sidebar-inner {
    padding: 0 16px 40px;
}

.nav-section {
    margin-bottom: 12px;
}

.nav-section-title {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
    padding: 18px 10px 8px;
    line-height: 1;
}

.nav-link {
    display: block;
    padding: 7px 10px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 5px;
    transition: all 0.1s ease;
    line-height: 1.5;
}

.nav-link:hover {
    color: var(--text);
    background: var(--border-light);
}

.nav-link.active {
    color: var(--accent);
    background: var(--accent-light);
    font-weight: 500;
}

.nav-link.top-level {
    font-weight: 500;
    color: var(--text);
    padding: 8px 10px;
}

/* ==================== Content ==================== */
.content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    gap: 0;
    min-width: 0;
}

.content-body {
    flex: 1;
    padding: 36px 48px 80px;
    min-width: 0;
    max-width: 840px;
}

/* ==================== Right TOC ==================== */
.toc {
    position: sticky;
    top: var(--header-height);
    width: var(--toc-width);
    min-width: var(--toc-width);
    padding: 32px 20px 32px 16px;
    overflow-y: auto;
    scrollbar-width: none;
    height: calc(100vh - var(--header-height));
    align-self: flex-start;
}

.toc::-webkit-scrollbar {
    display: none;
}

.toc-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
    margin-bottom: 12px;
    padding-left: 12px;
}

.toc-link {
    display: block;
    padding: 4px 12px;
    font-size: 0.78rem;
    color: var(--text-tertiary);
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: all 0.15s ease;
    line-height: 1.45;
}

.toc-link:hover {
    color: var(--text-secondary);
}

.toc-link.active {
    color: var(--text);
    border-left-color: var(--accent);
}

.toc-link-sub {
    padding-left: 24px;
    font-size: 0.72rem;
}

/* ==================== Typography ==================== */
.article h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
    margin-bottom: 12px;
    color: var(--text);
}

.article h2 {
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-top: 36px;
    margin-bottom: 10px;
    color: var(--text);
    line-height: 1.3;
}

.article h3 {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-top: 24px;
    margin-bottom: 8px;
    color: var(--text);
}

.article p {
    margin-bottom: 14px;
    color: var(--text);
    font-size: 0.88rem;
}

.article a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.15s ease;
}

.article a:hover {
    border-bottom-color: var(--accent);
}

.article strong {
    font-weight: 600;
    color: var(--text);
}

.article code {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 0.82em;
    font-family: 'JetBrains Mono', 'SF Mono', monospace;
}

.article hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 28px 0;
}

/* ==================== Lists ==================== */
.article ul, .article ol {
    margin-bottom: 14px;
    padding-left: 22px;
}

.article li {
    margin-bottom: 5px;
    font-size: 0.88rem;
    line-height: 1.6;
}

/* ==================== Tables ==================== */
.table-wrapper {
    overflow-x: auto;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

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

.article th {
    background: var(--bg-secondary);
    font-weight: 600;
    text-align: left;
    padding: 9px 14px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.article td {
    padding: 9px 14px;
    border-bottom: 1px solid var(--border-light);
}

.article tr:last-child td {
    border-bottom: none;
}

/* ==================== Hints ==================== */
.hint {
    display: flex;
    gap: 12px;
    padding: 14px 18px;
    border-radius: var(--radius);
    border-left: 4px solid;
    margin-bottom: 18px;
    font-size: 0.84rem;
    line-height: 1.6;
}

.hint-icon {
    flex-shrink: 0;
    font-size: 0.95rem;
    line-height: 1.6;
}

.hint-content {
    flex: 1;
    min-width: 0;
}

.hint-content p {
    margin-bottom: 6px;
    font-size: 0.84rem;
}

.hint-content p:last-child {
    margin-bottom: 0;
}

.hint-info {
    background: var(--hint-info-bg);
    border-left-color: var(--hint-info-border);
}

.hint-success {
    background: var(--hint-success-bg);
    border-left-color: var(--hint-success-border);
}

.hint-warning {
    background: var(--hint-warning-bg);
    border-left-color: var(--hint-warning-border);
}

.hint-danger {
    background: var(--hint-danger-bg);
    border-left-color: var(--hint-danger-border);
}

/* ==================== Pagination ==================== */
.pagination {
    display: flex;
    justify-content: space-between;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    gap: 12px;
}

.pagination-link {
    display: flex;
    flex-direction: column;
    padding: 14px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    transition: all 0.15s ease;
    max-width: 50%;
    min-width: 0;
}

.pagination-link:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.pagination-link.next {
    margin-left: auto;
    text-align: right;
}

.pagination-label {
    font-size: 0.68rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    margin-bottom: 3px;
}

.pagination-title {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* ==================== Responsive: Tablet ==================== */
@media (max-width: 1100px) {
    .toc { display: none; }
    .content-body { max-width: 100%; }
    .header-inner { padding-left: 20px; }
}

/* ==================== Responsive: Mobile ==================== */
@media (max-width: 768px) {
    .menu-toggle { display: flex; }
    .search-shortcut { display: none; }
    .header-inner { padding: 0 12px; }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: none;
        z-index: 200;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,0.15);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 190;
        opacity: 0;
        transition: opacity 0.25s ease;
    }
    .sidebar-overlay.visible {
        display: block;
        opacity: 1;
    }

    .content { margin-left: 0; max-width: 100%; }
    .content-body { padding: 24px 20px 60px; }

    .article h1 { font-size: 1.5rem; }
    .article h2 { font-size: 1.15rem; }

    .table-wrapper { -webkit-overflow-scrolling: touch; }
    .article code { word-break: break-word; }
    .hint { padding: 12px 14px; gap: 10px; }

    .search-results {
        position: fixed;
        top: var(--header-height);
        left: 0; right: 0;
        border-radius: 0;
        max-height: 60vh;
    }

    .pagination { flex-direction: column; }
    .pagination-link { max-width: 100%; }
    .pagination-link.next { text-align: left; margin-left: 0; }

    .ask-panel { width: 100%; }
    .ask-btn span { display: none; }
    .notice { font-size: 0.78rem; padding: 10px 16px; }
}

/* ==================== Responsive: Small Mobile ==================== */
@media (max-width: 480px) {
    .header-inner { padding: 0 8px; gap: 8px; }
    .search-input { font-size: 0.8rem; padding: 7px 40px 7px 36px; }
    .ask-btn { padding: 6px 10px; font-size: 0.78rem; }
    .content-body { padding: 20px 16px 50px; }
    .article h1 { font-size: 1.3rem; }
    .article h2 { font-size: 1.05rem; }
    .article p, .article li { font-size: 0.85rem; }
    .sidebar-brand { padding: 12px 10px; }
    .brand-label { font-size: 0.85rem; }
    .hint { font-size: 0.8rem; padding: 10px 12px; }
    .pagination-link { padding: 12px 14px; }
    .pagination-label { font-size: 0.6rem; }
    .pagination-title { font-size: 0.82rem; }
}

/* ==================== Global Overflow Protection ==================== */
.article {
    overflow-wrap: break-word;
    word-wrap: break-word;
}
.article img { max-width: 100%; height: auto; }

/* ==================== Scrollbar ==================== */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ==================== Animations ==================== */
.article { animation: fadeIn 0.2s ease; }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==================== Ask Button ==================== */
.ask-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 14px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--text-secondary);
    font-family: inherit; font-size: 0.82rem; font-weight: 500;
    cursor: pointer; transition: all 0.15s ease;
    white-space: nowrap; flex-shrink: 0;
}
.ask-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ==================== Ask Panel ==================== */
.ask-panel {
    position: fixed; top: var(--header-height); right: 0; bottom: 0;
    width: 380px; background: var(--bg);
    border-left: 1px solid var(--border); z-index: 90;
    display: flex; flex-direction: column;
    transform: translateX(100%); transition: transform 0.25s ease;
    box-shadow: -4px 0 24px rgba(0,0,0,0.08);
}
[data-theme="dark"] .ask-panel { box-shadow: -4px 0 24px rgba(0,0,0,0.3); }
.ask-panel.visible { transform: translateX(0); }

.ask-panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.ask-panel-title { font-weight: 600; font-size: 0.9rem; color: var(--text); }
.ask-panel-close {
    background: none; border: none; font-size: 1.4rem;
    color: var(--text-tertiary); cursor: pointer; padding: 0 4px; line-height: 1;
}
.ask-panel-close:hover { color: var(--text); }

.ask-panel-messages { flex: 1; overflow-y: auto; padding: 20px; }
.ask-welcome p { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 16px; line-height: 1.5; }
.ask-suggestions { display: flex; flex-direction: column; gap: 8px; }
.ask-suggestion {
    display: block; width: 100%; padding: 10px 14px;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg-secondary); color: var(--text);
    font-family: inherit; font-size: 0.82rem; text-align: left;
    cursor: pointer; transition: all 0.15s ease;
}
.ask-suggestion:hover { border-color: var(--accent); background: var(--accent-light); }

.ask-msg {
    padding: 10px 14px; border-radius: 12px; margin-bottom: 12px;
    font-size: 0.84rem; line-height: 1.5; max-width: 90%;
}
.ask-msg a { color: var(--accent); text-decoration: none; }
.ask-msg a:hover { text-decoration: underline; }
.ask-msg-user { background: var(--accent); color: white; margin-left: auto; border-bottom-right-radius: 4px; }
.ask-msg-bot { background: var(--bg-secondary); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 4px; }

.ask-panel-input { display: flex; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--border); }
.ask-panel-input input {
    flex: 1; padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--text); font-family: inherit; font-size: 0.84rem; outline: none;
}
.ask-panel-input input:focus { border-color: var(--accent); }
.ask-panel-input button {
    padding: 8px 12px; border: none; border-radius: 8px;
    background: var(--accent); color: white; cursor: pointer;
    display: flex; align-items: center; transition: opacity 0.15s ease; flex-shrink: 0;
}
.ask-panel-input button:hover { opacity: 0.9; }

/* ==================== Search Suggestions ==================== */
.search-suggestions-header {
    padding: 10px 16px 6px; font-size: 0.68rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-tertiary);
}
.search-results::-webkit-scrollbar { width: 4px; }
.search-results::-webkit-scrollbar-track { background: transparent; }
.search-results::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
