* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
    background: #f5f6f8;
    color: #1f2329;
    overscroll-behavior: none;
}

/* ---------- 登录/注册页 ---------- */

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
}

.auth-card {
    width: min(360px, calc(100vw - 32px));
    background: #fff;
    border-radius: 8px;
    padding: 32px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.auth-card h1 {
    margin: 0 0 24px;
    font-size: 20px;
    text-align: center;
}

.auth-card label {
    display: block;
    font-size: 13px;
    color: #57606a;
    margin-bottom: 6px;
}

.auth-card input {
    width: 100%;
    padding: 8px 10px;
    margin-bottom: 16px;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    font-size: 14px;
}

.auth-card button {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 6px;
    background: #2563eb;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
}

.auth-card button:hover {
    background: #1d4ed8;
}

.auth-switch {
    text-align: center;
    margin-top: 16px;
    font-size: 13px;
}

.auth-switch a {
    color: #2563eb;
    cursor: pointer;
    text-decoration: none;
}

.auth-error {
    color: #cf222e;
    font-size: 13px;
    margin-bottom: 12px;
    min-height: 16px;
}

/* ---------- 工作台页 ---------- */

.workbench {
    display: flex;
    height: 100vh;
    height: 100dvh;
    position: relative;
    overflow: hidden;
}

.sidebar {
    --sidebar-width: 260px;
    width: var(--sidebar-width);
    min-width: 180px;
    max-width: min(480px, 80vw);
    background: #fff;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    position: relative;
    flex: 0 0 auto;
    min-height: 0;
    transition: width 160ms ease, min-width 160ms ease, margin 160ms ease, opacity 160ms ease;
    z-index: 20;
}

.sidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    margin: 0;
    opacity: 0;
    pointer-events: none;
    border-right-width: 0;
    overflow: hidden;
}

.sidebar-resizer {
    position: absolute;
    top: 0;
    right: -3px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 30;
    touch-action: none;
}

.sidebar-resizer:hover,
.sidebar-resizer:focus-visible,
body.sidebar-resizing .sidebar-resizer {
    background: rgba(47, 184, 189, 0.35);
}

.sidebar-expand-btn {
    position: absolute;
    left: 8px;
    top: 10px;
    z-index: 25;
    width: 32px;
    height: 32px;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    background: #fff;
    color: #3f4751;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}

.sidebar-expand-btn:hover {
    border-color: #2fb8bd;
    color: #167d82;
}

.workspace-header {
    min-height: 41px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e5e7eb;
    padding-right: 4px;
}

.workspace-tabs {
    align-self: stretch;
    display: flex;
    align-items: stretch;
    min-width: 0;
}

.workspace-tab {
    min-width: 64px;
    border: none;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: #57606a;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
}

.workspace-tab:hover {
    color: #1f2329;
    background: #f7f8fa;
}

.workspace-tab.active {
    border-bottom-color: #2fb8bd;
    color: #1f2329;
}

.workspace-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.import-actions {
    display: flex;
    gap: 6px;
    padding: 7px 8px;
    border-bottom: 1px solid #e5e7eb;
}

.import-action-btn {
    flex: 1;
    padding: 5px 4px;
    border: 1px solid #d0d7de;
    border-radius: 4px;
    background: #fff;
    color: #3f4751;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
}

.import-action-btn:hover {
    border-color: #2fb8bd;
    color: #167d82;
    background: #f5fbfb;
}

.import-status {
    padding: 7px 10px;
    border-bottom: 1px solid #e5e7eb;
    background: #f0f9fa;
    color: #167d82;
    font-size: 12px;
}

.import-action-btn:disabled {
    cursor: wait;
    opacity: 0.45;
}

.icon-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 16px;
    color: #57606a;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1.2;
}

.icon-btn:hover {
    background: #f0f1f3;
}

.file-tree,
.outline-tree {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 8px 5px;
    -webkit-overflow-scrolling: touch;
}

.tree-node {
    user-select: none;
}

.tree-row {
    min-height: 28px;
    display: flex;
    align-items: center;
    padding: 3px 4px 3px 6px;
    border-radius: 2px;
    cursor: pointer;
    font-size: 13px;
    gap: 5px;
}

.tree-row:hover {
    background: #f0f1f3;
}

.tree-row.active {
    background: #eceeef;
}

.folder-row.active {
    color: #167d82;
}

.tree-disclosure {
    width: 14px;
    height: 20px;
    flex: 0 0 14px;
    border: none;
    padding: 0;
    background: transparent;
    cursor: pointer;
    position: relative;
}

.tree-disclosure::before {
    content: "";
    position: absolute;
    top: 7px;
    left: 3px;
    width: 6px;
    height: 6px;
    border-right: 1px solid #667085;
    border-bottom: 1px solid #667085;
    transform: rotate(45deg);
    transition: transform 120ms ease;
}

.tree-disclosure.collapsed::before {
    top: 6px;
    left: 2px;
    transform: rotate(-45deg);
}

.tree-leaf-space {
    width: 14px;
    flex: 0 0 14px;
}

.tree-icon {
    position: relative;
    width: 11px;
    height: 9px;
    flex: 0 0 11px;
    border: 1px solid #44c4ce;
}

.folder-icon {
    margin-top: 2px;
}

.folder-icon::before {
    content: "";
    position: absolute;
    left: 1px;
    top: -4px;
    width: 5px;
    height: 3px;
    border: 1px solid #44c4ce;
    border-bottom: none;
}

.file-icon {
    height: 12px;
    background: #fff;
}

.file-icon::after {
    content: "";
    position: absolute;
    top: -1px;
    right: -1px;
    width: 4px;
    height: 4px;
    border-left: 1px solid #44c4ce;
    border-bottom: 1px solid #44c4ce;
    background: #fff;
}

.pdf-icon {
    border-color: #e35d6a;
    background: #fff7f7;
}

.pdf-icon::after {
    border-left-color: #e35d6a;
    border-bottom-color: #e35d6a;
}

.tree-label {
    min-width: 0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-more-btn {
    margin-left: auto;
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #8b949e;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    opacity: 0.35;
}

.tree-row:hover .tree-more-btn,
.tree-row.active .tree-more-btn,
.tree-more-btn:focus-visible,
.tree-more-btn[aria-expanded="true"] {
    opacity: 1;
    background: #e8eaed;
    color: #3f4751;
}

.folder-children {
    margin-left: 15px;
}

.outline-item {
    flex: 1;
    min-width: 0;
    min-height: 27px;
    border: none;
    border-radius: 2px;
    background: transparent;
    color: #3f4751;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    overflow: hidden;
    padding: 4px 8px;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.outline-row {
    display: flex;
    align-items: center;
    min-height: 27px;
    border-radius: 2px;
}

.outline-row:hover {
    background: #f0f1f3;
}

.outline-row.active,
.outline-item.active {
    background: #e7f6f7;
    color: #0f6e73;
    font-weight: 600;
}

.outline-row.active {
    box-shadow: inset 2px 0 0 #2fb8bd;
}

.outline-disclosure,
.outline-disclosure-space {
    width: 18px;
    height: 22px;
    flex: 0 0 18px;
}

.outline-disclosure {
    position: relative;
    border: none;
    padding: 0;
    background: transparent;
    cursor: pointer;
}

.outline-disclosure::before {
    content: "";
    position: absolute;
    top: 7px;
    left: 5px;
    width: 6px;
    height: 6px;
    border-right: 1px solid #667085;
    border-bottom: 1px solid #667085;
    transform: rotate(45deg);
    transition: transform 120ms ease;
}

.outline-disclosure.collapsed::before {
    top: 6px;
    left: 4px;
    transform: rotate(-45deg);
}

.outline-children {
    margin-left: 18px;
}

.outline-item:hover {
    background: #f0f1f3;
}

.outline-item.active:hover {
    background: #dcf1f2;
}

.outline-empty {
    padding: 14px 9px;
    color: #8b949e;
    font-size: 12px;
}

.editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #fff;
}

.editor-toolbar {
    padding: 10px 16px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    gap: 10px;
}

.editor-toolbar input {
    flex: 1;
    min-width: 0;
    border: none;
    font-size: 18px;
    font-weight: 600;
    outline: none;
    background: transparent;
}

.save-status {
    font-size: 12px;
    color: #8b949e;
    min-width: 48px;
    white-space: nowrap;
}

.editor-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #8b949e;
    font-size: 14px;
    padding: 24px;
    text-align: center;
}

#vditor {
    flex: 1;
    min-height: 0;
}

#vditor img {
    max-width: 100%;
    height: auto;
}

/*
 * 去掉 Vditor 所见即所得默认的左侧灰色 H1/H2/... 等级标记，
 * 仅用下方自定义标题样式区分等级。
 */
#vditor .vditor-wysiwyg > .vditor-reset > h1:before,
#vditor .vditor-wysiwyg > .vditor-reset > h2:before,
#vditor .vditor-wysiwyg > .vditor-reset > h3:before,
#vditor .vditor-wysiwyg > .vditor-reset > h4:before,
#vditor .vditor-wysiwyg > .vditor-reset > h5:before,
#vditor .vditor-wysiwyg > .vditor-reset > h6:before,
#vditor .vditor-ir .vditor-reset > h1:before,
#vditor .vditor-ir .vditor-reset > h2:before,
#vditor .vditor-ir .vditor-reset > h3:before,
#vditor .vditor-ir .vditor-reset > h4:before,
#vditor .vditor-ir .vditor-reset > h5:before,
#vditor .vditor-ir .vditor-reset > h6:before {
    content: none !important;
    display: none !important;
    float: none !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 0 !important;
    height: 0 !important;
    border: none !important;
    background: none !important;
}

/*
 * 标题等级样式（对齐参考图意图）：
 * 一级：最大字号、居中
 * 二级：青绿底标签感
 * 三级：左侧色条
 * 四级：实心圆点
 * 五级：空心圆点
 * 六级：短横线 + 更淡字色
 */
#vditor .vditor-reset h1,
#vditor .vditor-wysiwyg h1 {
    font-size: 1.85em;
    font-weight: 700;
    text-align: center;
    margin: 1.1em 0 0.7em;
    color: #1f2328;
    line-height: 1.35;
}

#vditor .vditor-reset h2,
#vditor .vditor-wysiwyg h2 {
    display: inline-block;
    font-size: 1.2em;
    font-weight: 700;
    color: #fff;
    background: #44c4ce;
    border-radius: 8px;
    padding: 0.18em 0.62em;
    margin: 1em 0 0.55em;
    line-height: 1.4;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

#vditor .vditor-reset h3,
#vditor .vditor-wysiwyg h3 {
    font-size: 1.12em;
    font-weight: 700;
    color: #1f2328;
    margin: 0.95em 0 0.45em;
    padding: 0.1em 0 0.1em 0.7em;
    border-left: 4px solid #44c4ce;
    line-height: 1.45;
}

#vditor .vditor-reset h4,
#vditor .vditor-wysiwyg h4 {
    font-size: 1.05em;
    font-weight: 650;
    color: #24292f;
    margin: 0.85em 0 0.4em;
    padding-left: 0.15em;
    line-height: 1.45;
}

/* 四级装饰点：用更高优先级覆盖上面的「隐藏 before」规则 */
#vditor .vditor-wysiwyg > .vditor-reset > h4:before,
#vditor .vditor-reset h4::before,
#vditor .vditor-wysiwyg h4::before {
    content: "" !important;
    display: inline-block !important;
    float: none !important;
    width: 0.42em !important;
    height: 0.42em !important;
    margin: 0 0.45em 0 0 !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 50%;
    background: #44c4ce !important;
    vertical-align: 0.08em;
}

#vditor .vditor-reset h5,
#vditor .vditor-wysiwyg h5 {
    font-size: 1em;
    font-weight: 600;
    color: #3f4751;
    margin: 0.75em 0 0.35em;
    line-height: 1.45;
}

#vditor .vditor-wysiwyg > .vditor-reset > h5:before,
#vditor .vditor-reset h5::before,
#vditor .vditor-wysiwyg h5::before {
    content: "" !important;
    display: inline-block !important;
    float: none !important;
    width: 0.38em !important;
    height: 0.38em !important;
    margin: 0 0.45em 0 0 !important;
    padding: 0 !important;
    border-radius: 50%;
    border: 1.5px solid #44c4ce !important;
    background: transparent !important;
    vertical-align: 0.06em;
    box-sizing: border-box;
}

#vditor .vditor-reset h6,
#vditor .vditor-wysiwyg h6 {
    font-size: 0.95em;
    font-weight: 600;
    color: #667085;
    margin: 0.7em 0 0.3em;
    line-height: 1.45;
}

#vditor .vditor-wysiwyg > .vditor-reset > h6:before,
#vditor .vditor-reset h6::before,
#vditor .vditor-wysiwyg h6::before {
    content: "" !important;
    display: inline-block !important;
    float: none !important;
    width: 0.55em !important;
    height: 0 !important;
    margin: 0 0.45em 0 0 !important;
    padding: 0 !important;
    border: none !important;
    border-top: 2px solid #98a2b3 !important;
    background: none !important;
    vertical-align: 0.28em;
}

.source-editor {
    flex: 1;
    width: 100%;
    min-height: 0;
    resize: none;
    border: 0;
    outline: none;
    padding: 18px 22px;
    background: #fff;
    color: #242934;
    font: 15px/1.65 Consolas, "Cascadia Code", monospace;
    tab-size: 4;
    white-space: pre-wrap;
    overflow: auto;
}

.pdf-viewer {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #f6f7f9;
}

.pdf-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-bottom: 1px solid #e5e7eb;
    background: #fff;
}

.pdf-tool-btn,
.pdf-tool-link {
    border: 1px solid #d0d7de;
    border-radius: 6px;
    background: #fff;
    color: #24292f;
    font-size: 12px;
    line-height: 1;
    padding: 6px 10px;
    cursor: pointer;
    text-decoration: none;
    user-select: none;
}

.pdf-tool-btn:hover,
.pdf-tool-link:hover {
    background: #f3f4f6;
}

.pdf-tool-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.pdf-page-info {
    min-width: 64px;
    font-size: 12px;
    color: #57606a;
    text-align: center;
}

.pdf-canvas-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 16px;
    position: relative;
}

.pdf-canvas-wrap canvas {
    max-width: none;
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.12);
    background: #fff;
}

.pdf-status {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid #e5e7eb;
    color: #57606a;
    font-size: 13px;
    z-index: 1;
}

.btn-danger {
    color: #cf222e;
}

.hidden {
    display: none !important;
}

/* ---------- 右键/三点菜单 ---------- */

.context-menu {
    position: fixed;
    z-index: 1000;
    min-width: 148px;
    padding: 4px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

.context-menu-item {
    width: 100%;
    display: block;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #1f2329;
    text-align: left;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
}

.context-menu-item:hover,
.context-menu-item:focus-visible {
    background: #f0f1f3;
    outline: none;
}

.context-menu-item.danger {
    color: #cf222e;
}

.context-menu-item.danger:hover,
.context-menu-item.danger:focus-visible {
    background: #fff1f0;
}

.context-menu-separator {
    height: 1px;
    margin: 4px 6px;
    background: #e5e7eb;
}

/* ---------- 移动目标弹层 ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 23, 42, 0.35);
}

.modal-card {
    width: min(360px, 100%);
    max-height: min(70vh, 480px);
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
    overflow: hidden;
}

.modal-card h3 {
    margin: 0;
    padding: 14px 16px 10px;
    font-size: 15px;
    border-bottom: 1px solid #e5e7eb;
}

.modal-body {
    overflow-y: auto;
    padding: 8px;
    -webkit-overflow-scrolling: touch;
}

.modal-option {
    width: 100%;
    display: block;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #1f2329;
    text-align: left;
    padding: 10px 12px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
}

.modal-option:hover,
.modal-option:focus-visible {
    background: #f0f1f3;
    outline: none;
}

.modal-option.current {
    color: #8b949e;
    cursor: default;
}

.modal-option.current:hover {
    background: transparent;
}

.modal-actions {
    padding: 10px 12px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: flex-end;
}

.modal-btn {
    border: 1px solid #d0d7de;
    border-radius: 6px;
    background: #fff;
    color: #3f4751;
    padding: 7px 14px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
}

.modal-btn:hover {
    border-color: #2fb8bd;
    color: #167d82;
}

body.sidebar-resizing {
    cursor: col-resize;
    user-select: none;
}

body.sidebar-resizing iframe,
body.sidebar-resizing #vditor,
body.sidebar-resizing #pdfViewer {
    pointer-events: none;
}

/* ---------- 移动端 ---------- */

@media (hover: none), (pointer: coarse) {
    .tree-more-btn {
        opacity: 0.75;
    }

    .tree-row {
        min-height: 34px;
    }

    .tree-more-btn,
    .icon-btn,
    .workspace-tab,
    .import-action-btn {
        min-height: 32px;
    }
}

@media (max-width: 768px) {
    /* 手机端文件树全宽覆盖，避免半屏侧栏 + 右侧空白导致“什么都没有”的错觉。 */
    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        border-right: none;
        box-shadow: none;
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
        width: 100% !important;
        min-width: 0 !important;
        opacity: 1;
        pointer-events: none;
    }

    .sidebar-resizer {
        display: none;
    }

    .sidebar-expand-btn {
        top: calc(10px + env(safe-area-inset-top, 0px));
        left: calc(8px + env(safe-area-inset-left, 0px));
    }

    .workspace-header {
        padding-top: env(safe-area-inset-top, 0px);
    }

    .editor-toolbar {
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
        padding-right: calc(12px + env(safe-area-inset-right, 0px));
    }

    .mobile-back-btn:not(.hidden) {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        font-size: 20px;
    }

    .editor-toolbar input {
        font-size: 16px; /* 避免 iOS 自动放大 */
    }

    .source-editor {
        font-size: 16px;
        padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px));
    }

    .import-actions {
        flex-wrap: wrap;
    }

    .file-tree,
    .outline-tree {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    /* 未打开笔记时只显示文件树；打开笔记并收起侧栏后全屏编辑。 */
    .workbench:not(.mobile-note-open) .editor-panel {
        visibility: hidden;
    }

    .workbench.mobile-note-open .sidebar,
    .workbench.mobile-note-open .sidebar-expand-btn {
        display: none !important;
    }
}
