/* ===== 全局樣式 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #10b981;
    --background: #ffffff;
    --surface: #f8fafc;
    --surface-hover: #f1f5f9;
    --border-color: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --code-bg: #1e293b;
    --sidebar-width: 280px;
    --toc-width: 240px;
    --header-height: 64px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

/* 深色模式 */
[data-theme="dark"] {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #10b981;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --border-color: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --code-bg: #0d1117;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--text-primary);
    background: var(--background);
    line-height: 1.6;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ===== 頂部導航欄 ===== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--background);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 2rem;
    max-width: 100%;
    gap: 1rem;
}

.mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    transition: color 0.2s;
}

.mobile-menu-btn:hover {
    color: var(--primary-color);
}

.mobile-menu-btn .close-icon {
    display: none;
}

.mobile-menu-btn.active .menu-icon {
    display: none;
}

.mobile-menu-btn.active .close-icon {
    display: block;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
}

.logo-img {
    height: 40px;
    width: auto;
    object-fit: contain;
    max-width: 200px;
}

.logo-light {
    display: block;
}

.logo-dark {
    display: none;
}

[data-theme="dark"] .logo-light {
    display: none;
}

[data-theme="dark"] .logo-dark {
    display: block;
}

.logo-fallback {
    display: flex;
    align-items: center;
}

.logo-text {
    font-size: 1.5rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-badge {
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 0.375rem 0.625rem;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.1), rgba(16, 185, 129, 0.1));
    color: var(--primary-color);
    border: 1px solid rgba(37, 99, 235, 0.2);
    border-radius: 0.375rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    transition: all 0.2s ease;
}

.logo-badge:hover {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.15), rgba(16, 185, 129, 0.15));
    border-color: rgba(37, 99, 235, 0.3);
    transform: translateY(-1px);
}

[data-theme="dark"] .logo-badge {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(16, 185, 129, 0.15));
    color: #60a5fa;
    border-color: rgba(59, 130, 246, 0.3);
}

[data-theme="dark"] .logo-badge:hover {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(16, 185, 129, 0.2));
    border-color: rgba(59, 130, 246, 0.4);
}

.search-container {
    position: relative;
    flex: 1;
    max-width: 500px;
    margin: 0 2rem;
}

.search-input {
    width: 100%;
    padding: 0.625rem 1rem 0.625rem 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    transition: all 0.2s;
    background: var(--surface);
    color: var(--text-primary);
}

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

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    background: var(--background);
}

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

.header-links {
    display: flex;
    gap: 1rem;
}

.language-switcher {
    display: flex;
    gap: 0.25rem;
    margin-right: 1rem;
    padding: 0.25rem;
    background: var(--surface);
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}

.lang-btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.lang-btn:hover {
    color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
}

.lang-btn.active {
    color: white;
    background: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.theme-toggle:hover {
    background: var(--surface-hover);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.theme-toggle .sun-icon {
    display: none;
}

.theme-toggle .moon-icon {
    display: block;
}

[data-theme="dark"] .theme-toggle .sun-icon {
    display: block;
}

[data-theme="dark"] .theme-toggle .moon-icon {
    display: none;
}

/* ===== 主容器 ===== */
.main-container {
    display: flex;
    margin-top: var(--header-height);
    height: calc(100vh - var(--header-height));
}

/* ===== 移動端遮罩層 ===== */
.mobile-overlay {
    display: none;
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 89;
    opacity: 0;
    transition: opacity 0.3s;
}

.mobile-overlay.active {
    display: block;
    opacity: 1;
}

/* ===== 側邊欄 ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
}

.nav {
    padding: 1.5rem 0;
}

.nav-section {
    margin-bottom: 2.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.nav-section:last-child {
    border-bottom: none;
}

.nav-title {
    font-size: 0.9375rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-primary);
    padding: 0.5rem 1.5rem;
    margin-bottom: 1rem;
}

.nav-subsection {
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
}

.nav-subtitle {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-primary);
    padding: 0.75rem 1.5rem 0.5rem 1.75rem;
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    opacity: 0.9;
}

.nav-list {
    list-style: none;
}

.nav-link {
    display: block;
    padding: 0.5rem 1.5rem;
    font-size: 0.9375rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 2px solid transparent;
}

.nav-subsection .nav-link {
    padding-left: 2.25rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.nav-subsection .nav-link:hover,
.nav-subsection .nav-link.active {
    color: var(--text-secondary);
}

.nav-subsection .nav-link.active {
    color: var(--primary-color);
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.nav-link.active {
    color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
    border-left-color: var(--primary-color);
    font-weight: 500;
}

/* ===== 主內容區 ===== */
.content {
    flex: 1;
    overflow-y: auto;
    background: var(--background);
    padding: 2rem 3rem;
    max-width: calc(100% - var(--sidebar-width) - var(--toc-width));
}

#content-container {
    max-width: 900px;
}

.loading {
    text-align: center;
    padding: 4rem 0;
    color: var(--text-muted);
    font-size: 1.125rem;
}

/* ===== 右側目錄 ===== */
.toc {
    width: var(--toc-width);
    background: var(--background);
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    display: none;
}

@media (min-width: 1280px) {
    .toc {
        display: block;
    }
}

.toc-content {
    padding: 1.5rem;
}

.toc-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.toc-nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.toc-link {
    display: block;
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-left: 2px solid var(--border-color);
    transition: all 0.2s;
}

.toc-link:hover {
    color: var(--text-primary);
    border-left-color: var(--text-muted);
}

.toc-link.active {
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    font-weight: 500;
}

/* ===== 文章內容樣式 ===== */
.article h1 {
    font-size: 2.25rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    line-height: 1.2;
}

.article h2 {
    font-size: 1.875rem;
    font-weight: 600;
    margin-top: 3rem;
    margin-bottom: 1.25rem;
    color: var(--text-primary);
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.article h3 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.article h4 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.article p {
    margin-bottom: 1.25rem;
    color: var(--text-secondary);
    font-size: 1rem;
}

.article ul, .article ol {
    margin-bottom: 1.25rem;
    padding-left: 1.5rem;
}

.article li {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.article a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.2s;
}

.article a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

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

.article code {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875em;
    padding: 0.2em 0.4em;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    color: #e11d48;
}

[data-theme="dark"] .article code {
    color: #fb7185;
    background: var(--surface);
}

.article pre {
    margin: 1.5rem 0;
    padding: 1.25rem;
    background: var(--code-bg);
    border-radius: 0.5rem;
    overflow-x: auto;
    box-shadow: var(--shadow-md);
    /* code-bg is always dark navy; force light text for contrast in both themes */
    color: #e2e8f0;
}

.article pre code {
    font-size: 0.875rem;
    line-height: 1.7;
    background: transparent;
    border: none;
    padding: 0;
    /* Inherit the light color from .article pre — overrides any earlier color */
    color: inherit;
}

/* hljs syntax-highlighted blocks come with their own background/colors via
   atom-one-dark; ensure our pre wrapper doesn't double-paint a background. */
.article pre code.hljs {
    background: transparent !important;
    padding: 0;
}

.article blockquote {
    margin: 1.5rem 0;
    padding: 1rem 1.5rem;
    background: rgba(37, 99, 235, 0.05);
    border-left: 4px solid var(--primary-color);
    border-radius: 0.25rem;
}

.article blockquote p {
    margin: 0;
    color: var(--text-primary);
    font-weight: 500;
}

/* ===== 表格樣式 ===== */
.article table {
    width: 100%;
    margin: 1.5rem 0;
    border-collapse: collapse;
    font-size: 0.875rem;
    box-shadow: var(--shadow-sm);
    border-radius: 0.5rem;
    overflow: hidden;
}

.article thead {
    background: var(--surface);
}

.article th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
}

.article td {
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

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

.article tbody tr:hover {
    background: var(--surface);
}

/* ===== 標籤與徽章 ===== */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-get {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
}

.badge-post {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary-color);
}

.badge-put {
    background: rgba(245, 158, 11, 0.1);
    color: #d97706;
}

.badge-delete {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

.badge-ws {
    background: rgba(139, 92, 246, 0.1);
    color: #7c3aed;
}

/* ===== API 端點樣式 ===== */
.api-endpoint {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1.5rem 0;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}

.api-endpoint .method {
    font-weight: 700;
    font-size: 0.875rem;
}

.api-endpoint .path {
    flex: 1;
    color: var(--text-primary);
    font-size: 0.9375rem;
}

/* ===== 限速提示 ===== */
.rate-limit {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    margin: 1rem 0;
    background: rgba(245, 158, 11, 0.05);
    border: 1px solid rgba(245, 158, 11, 0.2);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    color: #d97706;
}

/* ===== 參數區塊 ===== */
.parameters {
    margin: 1.5rem 0;
}

.parameters h3, .parameters h4 {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}

/* ===== 代碼範例區塊 ===== */
.code-example {
    margin: 1.5rem 0;
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    background: #1e293b;
    border-radius: 0.5rem 0.5rem 0 0;
    border-bottom: 1px solid #334155;
}

.code-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: #94a3b8;
}

.copy-button {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: #e2e8f0;
    background: transparent;
    border: 1px solid #475569;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.2s;
}

.copy-button:hover {
    background: #334155;
    border-color: #64748b;
}

.code-example pre {
    margin: 0;
    border-radius: 0 0 0.5rem 0.5rem;
}

/* ===== 響應式設計 ===== */
@media (max-width: 1280px) {
    .content {
        max-width: calc(100% - var(--sidebar-width));
    }
}

@media (max-width: 1024px) {
    .header-content {
        padding: 0 1rem;
    }

    .mobile-menu-btn {
        display: flex;
    }

    .search-container {
        flex: 1;
        max-width: none;
        margin: 0 0.5rem;
    }

    .search-input {
        font-size: 0.8125rem;
        padding: 0.5rem 0.75rem 0.5rem 2.25rem;
    }

    .search-icon {
        left: 0.5rem;
        width: 18px;
        height: 18px;
    }

    .language-switcher {
        margin-right: 0.5rem;
    }

    .lang-btn {
        padding: 0.375rem 0.625rem;
        font-size: 0.75rem;
    }

    .theme-toggle {
        width: 36px;
        height: 36px;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: var(--header-height);
        transition: left 0.3s ease;
        z-index: 90;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        left: 0;
    }

    .content {
        max-width: 100%;
        width: 100%;
        padding: 1.5rem 1rem;
    }

    #content-container {
        max-width: 100%;
    }

    .nav-title {
        font-size: 0.875rem;
        padding: 0.375rem 1.25rem;
    }

    .nav-subtitle {
        font-size: 0.8125rem;
        padding: 0.5rem 1.25rem 0.375rem 1.75rem;
    }
}

@media (max-width: 640px) {
    .header-content {
        padding: 0 0.75rem;
        gap: 0.5rem;
    }

    .logo-img {
        height: 32px;
        max-width: 120px;
    }

    .logo-badge {
        font-size: 0.625rem;
        padding: 0.3rem 0.5rem;
    }

    .search-container {
        display: none;
    }

    .language-switcher {
        flex-direction: column;
        gap: 0;
        padding: 0.125rem;
        margin-right: 0.25rem;
    }

    .lang-btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.7rem;
    }

    .theme-toggle {
        width: 32px;
        height: 32px;
    }

    .theme-toggle svg {
        width: 18px;
        height: 18px;
    }

    .mobile-menu-btn {
        width: 36px;
        height: 36px;
    }

    .mobile-menu-btn svg {
        width: 22px;
        height: 22px;
    }

    .content {
        padding: 1rem 0.75rem;
    }

    .article h1 {
        font-size: 1.75rem;
    }

    .article h2 {
        font-size: 1.5rem;
        margin-top: 2rem;
    }

    .article h3 {
        font-size: 1.25rem;
    }

    .article h4 {
        font-size: 1.125rem;
    }

    .article pre {
        margin: 1rem -0.75rem;
        border-radius: 0;
        padding: 1rem 0.75rem;
    }

    .article table {
        font-size: 0.8125rem;
    }

    .article th,
    .article td {
        padding: 0.5rem 0.75rem;
    }

    .api-endpoint {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        padding: 0.875rem 1rem;
    }

    .nav-link {
        padding: 0.625rem 1rem;
        font-size: 0.9375rem;
    }

    .nav-subsection .nav-link {
        padding-left: 1.75rem;
        font-size: 0.9375rem;
    }

    .nav-title {
        font-size: 0.875rem;
        padding: 0.375rem 1rem;
    }

    .nav-subtitle {
        font-size: 0.8125rem;
        font-weight: 700;
        padding: 0.625rem 1.25rem 0.375rem 1.5rem;
        margin-top: 1rem;
    }
}

/* ===== 滾動條樣式 ===== */
.sidebar::-webkit-scrollbar,
.content::-webkit-scrollbar,
.toc::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track,
.content::-webkit-scrollbar-track,
.toc::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb,
.content::-webkit-scrollbar-thumb,
.toc::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.content::-webkit-scrollbar-thumb:hover,
.toc::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== 動畫 ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.article {
    animation: fadeIn 0.4s ease-out;
}
