/* ==================== 全局重置与基础样式 ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* 界面色彩 */
    --primary-100: #EBF5FF;
    --primary-500: #007AFF;
    --primary-700: #0056B3;
    
    --neutral-0: #F8F9FA;
    --neutral-100: #FFFFFF;
    --neutral-400: #DEE2E6;
    --neutral-600: #6C757D;
    --neutral-900: #212529;
    
    --success: #28A745;
    --warning: #FFC107;
    --error: #DC3545;
    
    /* 间距 */
    --space-xs: 8px;
    --space-sm: 16px;
    --space-md: 24px;
    --space-lg: 32px;
    --space-xl: 48px;
    --space-xxl: 64px;
    
    /* 圆角 */
    --radius-sm: 8px;
    --radius-md: 12px;
    
    /* 阴影 */
    --shadow-sm: 0 2px 4px rgba(0, 122, 255, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 122, 255, 0.12);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
    
    /* 字体 */
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-code: 'JetBrains Mono', 'Courier New', monospace;
    --font-serif: 'Source Serif Pro', Georgia, serif;
}

body {
    font-family: var(--font-ui);
    font-size: 16px;
    line-height: 1.6;
    color: var(--neutral-900);
    background-color: var(--neutral-0);
    overflow: hidden;
}

/* ==================== 工具栏样式 ==================== */
.toolbar {
    height: 56px;
    background-color: var(--neutral-100);
    border-bottom: 1px solid var(--neutral-400);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-sm);
    gap: var(--space-sm);
    position: relative;
    z-index: 100;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.toolbar-center {
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
}

.toolbar-center::-webkit-scrollbar {
    display: none;
}

.app-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--neutral-900);
    white-space: nowrap;
}

/* 工具栏分隔线 */
.toolbar-divider {
    width: 1px;
    height: 24px;
    background-color: var(--neutral-400);
    margin: 0 4px;
    flex-shrink: 0;
}

.toolbar-btn {
    min-width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--neutral-600);
    transition: all 200ms ease-out;
    flex-shrink: 0;
    padding: 0 8px;
    gap: 4px;
}

.toolbar-btn:hover {
    background-color: var(--primary-100);
    color: var(--primary-500);
}

.toolbar-btn:active,
.toolbar-btn.active {
    background-color: var(--primary-100);
    color: var(--primary-700);
}

.toolbar-btn svg {
    flex-shrink: 0;
}

.export-btn {
    width: auto;
    padding: 0 var(--space-sm);
    gap: var(--space-xs);
    background-color: var(--primary-500);
    color: white;
    font-weight: 600;
}

.export-btn:hover {
    background-color: var(--primary-700);
    color: white;
}

/* ==================== 工具栏下拉菜单 ==================== */
.toolbar-dropdown {
    position: relative;
}

.dropdown-trigger {
    gap: 2px;
}

.dropdown-trigger .chevron-small {
    transition: transform 200ms ease-out;
}

.toolbar-dropdown.active .dropdown-trigger .chevron-small {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    background-color: var(--neutral-100);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    padding: var(--space-xs);
    opacity: 0;
    transform: scale(0.95) translateY(-5px);
    pointer-events: none;
    transition: all 150ms ease-out;
    z-index: 1000;
}

.toolbar-dropdown.active .dropdown-menu {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: all;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    width: 100%;
    height: 36px;
    padding: 0 var(--space-sm);
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--neutral-900);
    font-size: 14px;
    text-align: left;
    transition: background-color 150ms ease-out;
}

.dropdown-item:hover {
    background-color: var(--primary-100);
    color: var(--primary-700);
}

.dropdown-item svg {
    color: var(--neutral-600);
}

.dropdown-item:hover svg {
    color: var(--primary-500);
}

/* 标题菜单特殊样式 */
.heading-menu .dropdown-item[data-action="h1"] { font-size: 18px; font-weight: 700; }
.heading-menu .dropdown-item[data-action="h2"] { font-size: 16px; font-weight: 700; }
.heading-menu .dropdown-item[data-action="h3"] { font-size: 15px; font-weight: 600; }
.heading-menu .dropdown-item[data-action="h4"] { font-size: 14px; font-weight: 600; }
.heading-menu .dropdown-item[data-action="h5"] { font-size: 13px; font-weight: 600; }
.heading-menu .dropdown-item[data-action="h6"] { font-size: 12px; font-weight: 600; }

/* 更多工具菜单 */
.more-tools .dropdown-menu {
    right: 0;
    left: auto;
    min-width: 180px;
}

/* ==================== 主题切换器 ==================== */
.theme-switcher {
    position: relative;
}

.theme-trigger {
    width: auto;
    padding: 0 12px;
    gap: 6px;
}

.theme-name {
    font-size: 14px;
    font-weight: 500;
}

.theme-trigger .chevron {
    transition: transform 200ms ease-out;
}

.theme-switcher.active .theme-trigger .chevron {
    transform: rotate(180deg);
}

.theme-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background-color: var(--neutral-100);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    padding: var(--space-xs);
    opacity: 0;
    transform: scale(0.95) translateY(-5px);
    pointer-events: none;
    transition: all 150ms ease-out;
    z-index: 1000;
}

.theme-switcher.active .theme-dropdown {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: all;
}

.theme-option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 10px var(--space-sm);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color 150ms ease-out;
    color: var(--neutral-900);
    position: relative;
}

.theme-option span {
    font-weight: 600;
    font-size: 14px;
}

.theme-option small {
    font-size: 12px;
    color: var(--neutral-600);
    margin-top: 2px;
}

.theme-option:hover {
    background-color: var(--neutral-0);
}

.theme-option .check-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary-500);
    opacity: 0;
}

.theme-option.active .check-icon {
    opacity: 1;
}

/* ==================== 移动端标签 ==================== */
.mobile-tabs {
    display: none;
    background-color: var(--neutral-100);
    border-bottom: 1px solid var(--neutral-400);
}

.mobile-tab {
    flex: 1;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--neutral-600);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 200ms ease-out;
}

.mobile-tab.active {
    color: var(--primary-500);
    border-bottom-color: var(--primary-500);
}

/* ==================== 主内容区 ==================== */
.main-content {
    display: flex;
    height: calc(100vh - 56px);
    gap: var(--space-lg);
    padding: var(--space-lg);
    overflow: hidden;
}

.editor-container,
.preview-container {
    flex: 1;
    background-color: var(--neutral-100);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ==================== 编辑器样式 ==================== */
.editor {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    resize: none;
    padding: var(--space-xl);
    font-family: var(--font-code);
    font-size: 15px;
    line-height: 1.7;
    color: var(--neutral-900);
    background-color: var(--neutral-100);
    caret-color: var(--primary-500);
    tab-size: 4;
}

.editor::placeholder {
    color: var(--neutral-600);
}

/* 自定义滚动条 */
.editor::-webkit-scrollbar,
.preview::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.editor::-webkit-scrollbar-track,
.preview::-webkit-scrollbar-track {
    background: transparent;
}

.editor::-webkit-scrollbar-thumb,
.preview::-webkit-scrollbar-thumb {
    background-color: var(--neutral-400);
    border-radius: 4px;
}

.editor::-webkit-scrollbar-thumb:hover,
.preview::-webkit-scrollbar-thumb:hover {
    background-color: var(--neutral-600);
}

/* ==================== 预览区基础样式 ==================== */
.preview {
    width: 100%;
    height: 100%;
    padding: var(--space-xl);
    overflow-y: auto;
    overflow-x: hidden;
    word-wrap: break-word;
}

/* ==================== 提示消息 ==================== */
.toast {
    position: fixed;
    bottom: var(--space-lg);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: var(--neutral-900);
    color: white;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    font-size: 14px;
    z-index: 2000;
    opacity: 0;
    transition: all 300ms ease-out;
    pointer-events: none;
}

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

.toast.success {
    background-color: var(--success);
}

.toast.error {
    background-color: var(--error);
}

/* ==================== 响应式设计 ==================== */
@media (max-width: 768px) {
    .toolbar {
        padding: 0 var(--space-xs);
    }
    
    .app-title {
        font-size: 14px;
    }
    
    .theme-name {
        display: none;
    }
    
    .toolbar-divider {
        display: none;
    }
    
    .mobile-tabs {
        display: flex;
    }
    
    .main-content {
        padding: var(--space-sm);
        gap: 0;
        height: calc(100vh - 56px - 44px);
    }
    
    .editor-container {
        display: block;
    }
    
    .preview-container {
        display: none;
    }
    
    .main-content.preview-mode .editor-container {
        display: none;
    }
    
    .main-content.preview-mode .preview-container {
        display: block;
    }
    
    .editor,
    .preview {
        padding: var(--space-md);
    }
}

/* ==================== 打印样式 ==================== */
@media print {
    .toolbar,
    .mobile-tabs,
    .toast {
        display: none;
    }
    
    .main-content {
        height: auto;
        padding: 0;
    }
    
    .editor-container {
        display: none;
    }
    
    .preview-container {
        box-shadow: none;
        border-radius: 0;
    }
}
