/* ============================================
   Markdown 预览器 · viewer.css
   依赖 style.css 的主题变量与 article.css 的 .prose 排版
   ============================================ */

/* hidden 属性必须始终生效：
   .drop-overlay 等元素设置了 display，会覆盖浏览器默认的 [hidden] { display: none } */
body.viewer-page [hidden] { display: none !important; }

/* ---------- 主区域 ---------- */
.viewer-main { min-height: calc(100vh - 200px); }

.viewer-view {
    max-width: var(--maxw);
    margin: 0 auto;
    padding: calc(var(--header-h) + 76px) 24px 80px;
}

/* ---------- 工具栏 ---------- */
.viewer-toolbar {
    position: fixed;
    top: var(--header-h);
    left: 0; right: 0;
    z-index: 60;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px max(24px, calc((100% - var(--maxw)) / 2 + 24px));
    background: var(--bg);
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.toolbar-left { flex: 1; }

.toolbar-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 50px;
    background: var(--bg-card);
    color: var(--text-soft);
    font-size: 0.88rem; font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    user-select: none;
}
.toolbar-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}
.toolbar-btn:active { transform: translateY(0); }

.toolbar-doc-title {
    min-width: 0;
    font-size: 0.92rem; font-weight: 600; color: var(--text-soft);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* 目录按钮：仅文档视图 + 移动端显示 */
.toolbar-btn.toc-btn { display: none; }
body.doc-open .toolbar-btn.toc-btn { display: inline-flex; }
@media (min-width: 1025px) {
    body.doc-open .toolbar-btn.toc-btn { display: none; }
}

/* ---------- 首页 / 空态 ---------- */
.viewer-hero {
    max-width: 640px; margin: 0 auto;
    text-align: center;
}
.viewer-hero-icon { font-size: 3rem; margin-bottom: 12px; }
.viewer-hero h1 {
    font-size: clamp(1.8rem, 4vw, 2.4rem);
    font-weight: 700; letter-spacing: -0.5px;
    margin-bottom: 12px;
}
.viewer-hero-sub { color: var(--text-soft); margin-bottom: 36px; line-height: 1.7; }

.dropzone {
    padding: 44px 24px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    transition: var(--transition);
    cursor: pointer;
}
.dropzone:hover, .dropzone.dragover {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 5%, var(--bg-card));
}
.dropzone-main { font-weight: 600; color: var(--text-soft); margin-bottom: 8px; }
.dropzone-or { color: var(--text-mute); font-size: 0.85rem; margin-bottom: 16px; }

.viewer-actions {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 12px;
    margin-top: 24px;
}
.viewer-note {
    margin-top: 28px; font-size: 0.82rem; color: var(--text-mute); line-height: 1.7;
}

/* ---------- 站内文档库 ---------- */
.library-wrap { max-width: 860px; margin: 0 auto; }
.lib-search {
    width: 100%;
    padding: 12px 18px;
    border: 1px solid var(--border);
    border-radius: 50px;
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.95rem; font-family: inherit;
    outline: none;
    transition: var(--transition);
    margin-bottom: 28px;
}
.lib-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }

.lib-group { margin-bottom: 36px; }
.lib-group-title {
    font-size: 1.05rem; font-weight: 700;
    margin-bottom: 16px;
    display: flex; align-items: center; gap: 8px;
}
.lib-series {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    margin-bottom: 14px;
    overflow: hidden;
}
.lib-series > summary {
    list-style: none;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 14px 20px;
    font-weight: 600; color: var(--text);
    cursor: pointer;
    transition: var(--transition);
}
.lib-series > summary::-webkit-details-marker { display: none; }
.lib-series > summary::after {
    content: '▾';
    color: var(--text-mute);
    transition: var(--transition);
}
.lib-series:not([open]) > summary::after { transform: rotate(-90deg); }
.lib-series > summary:hover { color: var(--accent); }
.lib-series-body { padding: 0 20px 16px; }

.lib-chapter-title {
    font-size: 0.8rem; color: var(--text-mute);
    font-family: 'JetBrains Mono', monospace;
    margin: 14px 0 6px;
}
.lib-doc {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-soft);
    text-decoration: none;
    transition: var(--transition);
}
.lib-doc:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); color: var(--accent); }
.lib-doc-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-doc-meta {
    flex-shrink: 0;
    font-size: 0.75rem; color: var(--text-mute);
    font-family: 'JetBrains Mono', monospace;
}
.lib-empty { text-align: center; color: var(--text-mute); padding: 40px 0; }
.lib-loading { text-align: center; color: var(--text-mute); padding: 40px 0; }

/* ---------- 粘贴预览 ---------- */
.paste-wrap {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    height: calc(100vh - var(--header-h) - 180px);
    min-height: 420px;
}
.paste-editor, .paste-preview {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    overflow: hidden auto;
}
.paste-editor textarea {
    width: 100%; height: 100%;
    padding: 20px;
    border: none; outline: none;
    background: transparent;
    color: var(--text);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.88rem; line-height: 1.7;
    resize: none;
}
.paste-preview { padding: 20px 24px; }
.paste-preview .paste-empty { color: var(--text-mute); }

/* ---------- 文档视图元信息 ---------- */
.doc-meta {
    display: flex; align-items: center; flex-wrap: wrap; gap: 12px;
    margin-bottom: 28px; padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem; color: var(--text-mute);
    font-family: 'JetBrains Mono', monospace;
}
.doc-badge {
    padding: 4px 12px; border-radius: 50px;
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    color: var(--accent);
    font-weight: 600;
}
.doc-html-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}
.doc-html-link:hover { text-decoration: underline; }

/* 锚点跳转预留导航高度 */
.prose h1, .prose h2, .prose h3, .prose h4 { scroll-margin-top: calc(var(--header-h) + 76px); }

/* ---------- 目录（桌面侧栏） ---------- */
.viewer-toc {
    position: sticky; top: calc(var(--header-h) + 76px);
    max-height: calc(100vh - var(--header-h) - 100px);
    overflow-y: auto;
    font-size: 0.85rem;
}
.viewer-toc h4, .toc-drawer-head h4 {
    font-size: 0.78rem; color: var(--text-mute); text-transform: uppercase;
    letter-spacing: 1px; margin-bottom: 12px; font-weight: 600;
}
.viewer-toc ul, #tocDrawerList { list-style: none; padding: 0; margin: 0; }
.viewer-toc li, #tocDrawerList li { margin: 0; }
.viewer-toc a, #tocDrawerList a {
    display: block; padding: 5px 0 5px 12px; color: var(--text-mute);
    border-left: 2px solid transparent;
    text-decoration: none;
    transition: var(--transition);
    line-height: 1.4;
}
.viewer-toc a:hover, #tocDrawerList a:hover { color: var(--accent); }
.viewer-toc a.active, #tocDrawerList a.active {
    color: var(--accent); border-left-color: var(--accent); font-weight: 500;
}
.toc-l3 a { padding-left: 26px !important; }

/* ---------- 移动端目录抽屉 ---------- */
.toc-drawer { position: fixed; inset: 0; z-index: 90; }
.toc-drawer-backdrop {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, 0.45);
}
.toc-drawer-panel {
    position: absolute; top: 0; right: 0; bottom: 0;
    width: min(320px, 84vw);
    background: var(--bg-card);
    box-shadow: var(--shadow-lg);
    padding: 20px;
    overflow-y: auto;
    animation: drawerIn 0.25s ease;
}
@keyframes drawerIn {
    from { transform: translateX(30px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
.toc-drawer-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 8px;
}
.toc-drawer-head button {
    border: none; background: none;
    font-size: 1.1rem; color: var(--text-mute);
    cursor: pointer; padding: 6px;
}

/* ---------- 拖拽遮罩 ---------- */
.drop-overlay {
    position: fixed; inset: 0; z-index: 120;
    background: color-mix(in srgb, var(--bg) 70%, transparent);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    padding: 32px;
    pointer-events: none; /* 拖拽事件始终落在页面元素上，避免 enter/leave 计数错乱 */
}
.drop-overlay-inner {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    border: 3px dashed var(--accent);
    border-radius: var(--radius);
    font-size: 1.3rem; font-weight: 700; color: var(--accent);
    background: color-mix(in srgb, var(--accent) 5%, transparent);
}

/* ---------- 轻提示 ---------- */
.viewer-toast {
    position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%);
    z-index: 130;
    max-width: min(90vw, 420px);
    padding: 12px 22px;
    border-radius: 50px;
    background: var(--text);
    color: var(--bg);
    font-size: 0.9rem; font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: toastIn 0.25s ease;
}
@keyframes toastIn {
    from { transform: translate(-50%, 10px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

/* ---------- 响应式 ---------- */
@media (max-width: 640px) {
    .toolbar-btn { padding: 8px 11px; }
    .toolbar-label { display: none; }
    .toolbar-doc-title { font-size: 0.85rem; }
    .viewer-view { padding: calc(var(--header-h) + 66px) 16px 60px; }
    .dropzone { padding: 32px 16px; }
    /* iOS Safari 会对 font-size < 16px 的输入框聚焦时自动放大页面 */
    .paste-editor textarea,
    .lib-search { font-size: 16px; }
}
@media (max-width: 1024px) {
    /* 粘贴预览：上下堆叠 */
    .paste-wrap {
        grid-template-columns: 1fr;
        height: auto;
    }
    .paste-editor { height: 38vh; }
    .paste-preview { height: 42vh; }
    /* 目录走抽屉 */
    .viewer-toc { display: none; }
}
@media (min-width: 1025px) {
    .toc-drawer { display: none; }
}
