/* ========= 基础 & 主题变量 ========= */

:root {
    --bg-page: #f5f5f5;
    --bg-surface: #ffffff;
    --bg-sidebar: #fbfbfb;

    --border-subtle: #e1e4e8;
    --border-strong: #d0d7de;

    --text-main: #24292f;
    --text-muted: #6a737d;
    --text-soft: #95a0ad;

    --accent: #3b82f6;
    --accent-soft: rgba(59, 130, 246, 0.08);

    --shadow-soft: 0 8px 24px rgba(15, 23, 42, 0.08);
    --radius-lg: 12px;
    --radius-md: 8px;
    --radius-pill: 999px;

    --header-height: 64px;
}

/* 深色模式变量覆盖 */
body.theme-dark {
    --bg-page: #0b1120;
    --bg-surface: #020617;
    --bg-sidebar: #020617;

    --border-subtle: #1f2933;
    --border-strong: #273549;

    --text-main: #e5e7eb;
    --text-muted: #9ca3af;
    --text-soft: #6b7280;

    --accent: #60a5fa;
    --accent-soft: rgba(96, 165, 250, 0.18);

    --shadow-soft: 0 18px 45px rgba(0, 0, 0, 0.6);
}

/* 重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ========= 布局 ========= */

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", sans-serif;
    background: var(--bg-page);
    color: var(--text-main);
    min-height: 100vh;
}

/* Notion 式居中主容器 */
.container {
    max-width: 1440px;
    margin: 0 auto;
}

/* 总 App 容器 */
.app {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* 顶部栏（普通流布局，不固定） */
/* ========== 顶部栏固定 ========== */

.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;

    height: var(--header-height);

    z-index: 999;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-soft);

    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
}

/* 让内容不被固定 header 遮住 */
.header-spacer {
    height: var(--header-height);
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-title {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.app-subtitle {
    font-size: 0.85rem;
    color: var(--text-soft);
}

.header-center {
    font-size: 0.95rem;
    color: var(--text-muted);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 图标按钮 */
.icon-btn {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-pill);
    background: var(--bg-surface);
    padding: 6px 10px;
    font-size: 0.9rem;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}

.icon-btn i {
    font-size: 0.9rem;
}

.icon-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.icon-btn:active {
    transform: translateY(1px);
}

/* 布局文字小标签 */
#layout-mode-label {
    font-size: 0.8rem;
}

/* 主体两栏布局：左侧栏 + 右侧内容 */
.main-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 12px;
    align-items: stretch;
}

/* 侧边栏 */

.sidebar {
    background: var(--bg-sidebar);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-soft);

    display: flex;
    flex-direction: column;
    gap: 12px;

    /* 去掉 margin/padding 导致的视觉缩进 */
    padding: 12px;

    /* 高度控制 */
    max-height: calc(100vh - var(--header-height));

    /* 保持跟随顶部固定布局 */
    position: sticky;
    top: var(--header-height);

    /* 让它完全贴齐左边 */
    margin-left: 0;
}

.sidebar-section {
    border-radius: var(--radius-md);
    padding: 8px 6px;
    border: 1px solid transparent;
}

.sidebar-section:hover {
    border-color: var(--border-subtle);
    background: rgba(148, 163, 184, 0.05);
}

.sidebar-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 8px;
}

/* 缩略图容器 */
.thumbs-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    max-height: 260px;
    padding-right: 4px;
}

.thumb-item {
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    padding: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.thumb-item canvas {
    width: 100%;
    display: block;
    border-radius: 6px;
}

.thumb-item:hover {
    border-color: var(--accent);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
}

.thumb-item.active {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.sidebar-hint {
    font-size: 0.8rem;
    color: var(--text-soft);
}

/* 目录容器（当前占位） */
.outline-container {
    font-size: 0.82rem;
    color: var(--text-soft);
}

/* 侧边栏底部统计信息 */
.sidebar-footer {
    margin-top: auto;
}

.stats {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.stats span {
    padding: 4px 8px;
    border-radius: var(--radius-pill);
    border: 1px dashed var(--border-subtle);
}

/* 右侧阅读区 */
.content-area {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-soft);
    padding: 16px 16px 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: calc(100vh - var(--header-height) - 40px);
}

/* ========= PDF 区域 ========= */

.viewer-container {
    position: relative;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    padding: 16px;
    background:
        radial-gradient(circle at top left, rgba(59,130,246,0.05), transparent 55%),
        radial-gradient(circle at bottom right, rgba(236,72,153,0.05), transparent 60%),
        var(--bg-surface);
}

/* PDF 网格：核心分栏布局 */
.pdf-grid {
    display: grid;
    grid-template-columns: 1fr; /* 默认单列（手机、窄屏） */
    gap: 32px;
}

/* 每页容器 */
.page-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* PDF Canvas */
.pdf-page {
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.12);
    background: #ffffff;
    display: block;
    width: 100%;      /* 宽度占满所在列 */
    height: auto;     /* 高度自动，保持等比例 */
    max-width: 100%;
    transition: box-shadow 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

.pdf-page:hover {
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
    border-color: var(--accent);
    transform: translateY(-1px);
}

/* 页码标签 */
.page-number {
    margin-bottom: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.page-number i {
    font-size: 0.85rem;
    color: var(--text-soft);
}

/* 加载态 */
.loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.loading i {
    font-size: 2.4rem;
    margin-bottom: 16px;
    color: var(--text-soft);
    animation: spin 1.2s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========= 阅读进度条 ========= */

.reading-progress {
    margin-top: 16px;
    height: 4px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.25);
    overflow: hidden;
}

#reading-progress-bar {
    height: 100%;
    width: 0%;
    border-radius: inherit;
    background: linear-gradient(90deg, #3b82f6, #ec4899);
    transition: width 0.12s ease-out;
}

/* ========= 页脚 ========= */

.footer {
    font-size: 0.8rem;
    color: var(--text-soft);
    text-align: right;
}

.footer a {
    color: var(--accent);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* ========= 布局模式：单栏 / 双栏 ========= */

/* 电脑宽屏下的自动布局：两栏 */
@media (min-width: 1200px) {
    body.layout-auto .pdf-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* 强制单栏 */
body.layout-single .pdf-grid {
    grid-template-columns: 1fr !important;
}

/* 强制双栏（宽屏才有意义） */
@media (min-width: 992px) {
    body.layout-double .pdf-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

/* ========= 响应式 ========= */

@media (max-width: 1024px) {
    .main-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .sidebar {
        position: static;
        max-height: none;
        order: 2;
    }

    .content-area {
        order: 1;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .app-header {
        flex-wrap: wrap;
        height: auto;
        gap: 6px;
        align-items: flex-start;
        padding: 10px 12px;
    }

    .header-left {
        flex: 1 1 100%;
    }

    .header-center {
        font-size: 0.85rem;
    }

    .header-right {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .sidebar {
        padding: 10px;
    }

    .viewer-container {
        padding: 12px;
    }

    .pdf-grid {
        grid-template-columns: 1fr;
        gap: 24px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 6px;
    }

    .content-area {
        padding: 10px;
    }

    .viewer-container {
        padding: 10px;
    }
}

/* ========= 高分屏渲染优化 ========= */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .pdf-page {
        image-rendering: -webkit-optimize-contrast;
    }
}
