/* ============================================
   公众号 Markdown 编辑器 - 主样式
   风格参考 markdown.com.cn (mdnice)
   ============================================ */

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: #f5f5f5;
    color: #1d1d1f;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========== 顶部导航条 ========== */
.topbar {
    height: 48px;
    background: #fff;
    border-bottom: 1px solid #e8e8e8;
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    z-index: 10;
    position: relative;
}

.topbar-left { flex-shrink: 0; }

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 15px;
    color: #1d1d1f;
}

.logo-icon { font-size: 20px; }

.topbar-center {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    justify-content: center;
}

.topbar-right { flex-shrink: 0; }

.topbar-tip {
    color: #999;
    font-size: 12px;
}

/* 导航按钮 - 仿 mdnice 简洁风格 */
.topbar-btn {
    height: 32px;
    padding: 0 12px;
    border: none;
    background: transparent;
    color: #555;
    cursor: pointer;
    font-size: 13px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s;
}

.topbar-btn:hover {
    background: #f5f5f5;
    color: #1d1d1f;
}

.topbar-btn.toggle.active {
    background: #07c160;
    color: #fff;
}

.caret {
    font-size: 10px;
    opacity: 0.6;
    margin-left: 2px;
}

/* ========== 下拉菜单 ========== */
.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 36px;
    left: 0;
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.12), 0 2px 4px rgba(0,0,0,0.08);
    padding: 6px 0;
    min-width: 140px;
    z-index: 100;
    display: none;
    border: 1px solid #e8e8e8;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-menu a {
    display: block;
    padding: 8px 16px;
    color: #333;
    text-decoration: none;
    font-size: 13px;
    transition: background 0.15s;
}

.dropdown-menu a:hover {
    background: #f5f5f5;
}

.dropdown-menu a.active {
    color: #07c160;
    font-weight: 500;
    background: #e8f7ee;
}

.dropdown-menu a.danger {
    color: #ff4d4f;
}

.dropdown-menu a.danger:hover {
    background: #fff1f0;
}

.dropdown-divider {
    height: 1px;
    background: #f0f0f0;
    margin: 6px 0;
}

/* ========== 编辑区工具条 ========== */
.editor-toolbar {
    height: 36px;
    background: #fafafa;
    border-bottom: 1px solid #e8e8e8;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 2px;
    overflow-x: auto;
}

.et-btn {
    min-width: 32px;
    height: 28px;
    padding: 0 8px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: #555;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
    white-space: nowrap;
}

.et-btn:hover {
    background: #fff;
    border-color: #d9d9d9;
    color: #1d1d1f;
}

.et-btn:active {
    transform: scale(0.95);
}

.et-divider {
    width: 1px;
    height: 18px;
    background: #e8e8e8;
    margin: 0 6px;
}

/* ========== 工作区 ========== */
.workspace {
    height: calc(100vh - 48px - 36px - 28px); /* 减去顶栏/工具条/状态栏 */
    display: flex;
    overflow: hidden;
}

.pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    min-width: 0;
    overflow: hidden;
}

.pane-header {
    height: 32px;
    padding: 0 16px;
    background: #fafafa;
    border-bottom: 1px solid #e8e8e8;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: #666;
    font-weight: 500;
    flex-shrink: 0;
}

.stats { color: #999; font-weight: normal; }
.hint { color: #999; font-weight: normal; }

/* 编辑器 */
#editor {
    flex: 1;
    width: 100%;
    padding: 20px;
    border: none;
    outline: none;
    resize: none;
    font-family: "SF Mono", Monaco, Consolas, monospace;
    font-size: 14px;
    line-height: 1.7;
    color: #1d1d1f;
    background: #fff;
    tab-size: 4;
}

/* 分隔条 */
.splitter {
    width: 4px;
    background: #f0f0f0;
    cursor: col-resize;
    flex-shrink: 0;
    transition: background 0.2s;
}

.splitter:hover, .splitter.dragging {
    background: #07c160;
}

/* 预览区 */
.preview-wrapper {
    flex: 1;
    overflow: auto;
    padding: 24px;
    background: #f5f5f5;
    transition: padding 0.2s;
}

.preview-content {
    max-width: 720px;
    margin: 0 auto;
    padding: 32px 24px;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    min-height: 100%;
    transition: max-width 0.2s, padding 0.2s, border-radius 0.2s;
}

/* 手机预览模式 - 仿公众号阅读体验 */
.preview-wrapper.preview-mobile {
    padding: 24px 12px;
    background: #e8e8e8;
}

.preview-wrapper.preview-mobile .preview-content {
    max-width: 375px;
    padding: 20px 14px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* MathJax 公式 SVG 在预览区表现 */
.preview-content mjx-container,
.preview-content .math {
    margin: 0.5em 0;
}
.preview-content mjx-container[display="true"] {
    display: block;
    text-align: center;
}

/* ========== 底部状态栏 ========== */
.status-bar {
    height: 28px;
    background: #fff;
    border-top: 1px solid #e8e8e8;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    font-size: 12px;
    color: #666;
}

.footer-tip { color: #999; font-size: 11px; }

/* ========== 右侧悬浮按钮栏 (仿 mdnice) ========== */
.sidebar-actions {
    position: fixed;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 50;
}

.sidebar-btn {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 12px;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    color: #fff;
}

.sidebar-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.sidebar-btn:active { transform: scale(0.95); }

.sb-icon { font-size: 20px; }
.sb-label { font-size: 11px; font-weight: 500; }

.sidebar-wechat { background: #07c160; }
.sidebar-zhihu  { background: #0084ff; }
.sidebar-juejin { background: #1e80ff; }

/* ========== 查找替换面板 ========== */
.search-panel {
    position: fixed;
    top: 100px;
    right: 90px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 200;
    border: 1px solid #e8e8e8;
}

.search-panel input {
    height: 28px;
    padding: 0 10px;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    font-size: 13px;
    outline: none;
    width: 200px;
}

.search-panel input:focus { border-color: #07c160; }

.search-panel button {
    height: 28px;
    padding: 0 10px;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    background: #fff;
    color: #555;
    cursor: pointer;
    font-size: 12px;
}

.search-panel button:hover {
    background: #f5f5f5;
}

#searchCloseBtn { background: #ff4d4f; color: #fff; border-color: #ff4d4f; }

/* ========== Toast 提示 ========== */
.toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: rgba(0,0,0,0.85);
    color: #fff;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 13px;
    pointer-events: none;
    opacity: 0;
    transition: all 0.25s ease;
    z-index: 1000;
    max-width: 80%;
    text-align: center;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.error { background: rgba(255, 77, 79, 0.95); }
.toast.success { background: rgba(7, 193, 96, 0.95); }

/* ========== 自定义 CSS 面板 ========== */
.css-panel {
    position: fixed;
    right: 16px;
    bottom: 48px;
    width: 480px;
    max-width: calc(100vw - 32px);
    height: 360px;
    max-height: calc(100vh - 100px);
    background: #1f1f1f;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    z-index: 200;
    overflow: hidden;
}

.css-panel-header {
    height: 40px;
    padding: 0 12px;
    background: #2a2a2a;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.css-panel-header span {
    font-size: 13px;
    font-weight: 500;
}

.css-panel-header button {
    height: 26px;
    padding: 0 12px;
    margin-left: 6px;
    border: none;
    border-radius: 4px;
    background: #3a3a3a;
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
}

.css-panel-header button:hover {
    background: #4a4a4a;
}

#cssApplyBtn { background: #07c160 !important; }
#cssApplyBtn:hover { background: #06a050 !important; }
#cssCloseBtn { background: #ff4d4f !important; width: 28px; }
#cssCloseBtn:hover { background: #ff7875 !important; }

#customCssText {
    flex: 1;
    width: 100%;
    padding: 12px;
    border: none;
    outline: none;
    background: #1f1f1f;
    color: #d4d4d4;
    font-family: "SF Mono", Consolas, Monaco, monospace;
    font-size: 13px;
    line-height: 1.5;
    resize: none;
    tab-size: 2;
}

.css-panel-tip {
    height: 28px;
    padding: 0 12px;
    background: #2a2a2a;
    color: #999;
    font-size: 11px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* ========== 响应式 ========== */
@media (max-width: 1024px) {
    .topbar { flex-wrap: wrap; height: auto; min-height: 48px; padding: 6px 12px; }
    .topbar-center { order: 3; width: 100%; justify-content: flex-start; overflow-x: auto; margin-top: 6px; gap: 0; }
    .topbar-right { display: none; }
    .sidebar-actions { right: 8px; }
    .sidebar-btn { width: 48px; height: 48px; }
    .sb-label { display: none; }
}

@media (max-width: 768px) {
    .workspace { flex-direction: column; }
    .splitter { width: 100%; height: 4px; cursor: row-resize; }
    .editor-toolbar { padding: 0 8px; gap: 0; }
    .et-btn { min-width: 28px; padding: 0 6px; font-size: 12px; }
}

/* ========== 滚动条 ========== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d0d0d5; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a0a0a5; }