/* ============================================================
   VisualLaTeX — 学术暖白主题
   设计令牌驱动，纯原生 CSS，零依赖
   ============================================================ */

/* 设计令牌 */
:root {
    /* 底色 */
    --bg: #f6f4ef;            /* 暖纸底色 */
    --surface: #ffffff;       /* 面板 */
    --surface-soft: #faf8f3;  /* 次级面板 */
    --border: #e6e1d6;        /* 暖边框 */
    --border-strong: #d6cfc0;

    /* 文字 */
    --text: #26231d;          /* 墨色正文 */
    --text-secondary: #6f695c;

    /* 强调色（氧化红） */
    --accent: #9d4432;
    --accent-hover: #83392a;
    --accent-soft: #f5e9e4;

    /* 成功（导出类按钮） */
    --success: #3f7a54;
    --success-hover: #346647;

    /* 暖深色（预览区 / 状态栏 / 弹窗头） */
    --ink-dark: #2b2822;

    /* 形状与投影 */
    --radius: 6px;
    --radius-lg: 10px;
    --shadow-sm: 0 1px 2px rgba(38, 35, 29, 0.06);
    --shadow-modal: 0 20px 60px rgba(38, 35, 29, 0.25);

    /* 动效 */
    --transition: all 0.18s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* 主容器 */
.container {
    max-width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 顶部标题栏（纸白 + 下边线） */
.header {
    background: var(--surface);
    color: var(--text);
    padding: 16px 30px;
    border-bottom: 3px solid var(--accent);
}

.header h1 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.header p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* 工具栏 */
.toolbar {
    background: var(--surface);
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar button {
    padding: 7px 14px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    transition: var(--transition);
    font-weight: 500;
}

.toolbar button:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

.toolbar button:active {
    transform: translateY(0);
    background: #eedcd4;
}

.toolbar button.primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.toolbar button.primary:hover {
    background: var(--accent-hover);
    color: #fff;
}

.toolbar button.success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

.toolbar button.success:hover {
    background: var(--success-hover);
    color: #fff;
}

.toolbar .separator {
    width: 1px;
    height: 26px;
    background: var(--border);
    margin: 0 6px;
}

/* 主内容区域 - 双栏布局 */
.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* 左侧编辑区 */
.editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.panel-header {
    background: var(--surface-soft);
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 0.4px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.editor-area {
    flex: 1;
    padding: 30px 36px;
    overflow-y: auto;
    outline: none;
    font-size: 16px;
    line-height: 1.8;
}

.editor-area:focus {
    background: #fdfcfa;
}

/* 编辑器内容样式 */
.editor-area h1 {
    font-size: 21px;
    font-weight: 700;
    margin: 20px 0 15px 0;
    color: var(--text);
}

.editor-area h2 {
    font-size: 19px;
    font-weight: 600;
    margin: 18px 0 12px 0;
    color: var(--text);
}

.editor-area h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 15px 0 10px 0;
    color: var(--text);
}

.editor-area p {
    margin: 10px 0;
    text-align: justify;
}

.editor-area ul, .editor-area ol {
    margin: 10px 0;
    padding-left: 30px;
}

.editor-area li {
    margin: 5px 0;
}

/* 行内公式（暖黄纸底） */
.editor-area .formula-inline {
    background: #faf3dd;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    color: #7a5c1e;
}

/* 行间公式（暖纸底 + 强调色左边线） */
.editor-area .formula-block {
    background: var(--surface-soft);
    padding: 12px;
    border-radius: var(--radius);
    margin: 15px 0;
    text-align: center;
    font-family: 'Courier New', monospace;
    color: var(--text);
    border-left: 4px solid var(--accent);
}

/* 原样保留块：表格/文献/代码清单等未可视化支持的 LaTeX 结构 */
.editor-area .raw-tex {
    background: #efece5;
    padding: 10px 12px;
    border-radius: var(--radius);
    margin: 15px 0;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    color: var(--text-secondary);
    border-left: 4px solid var(--border-strong);
    white-space: pre-wrap;
    word-break: break-word;
}

/* 行内 LaTeX 命令（\cite、\ref 等，只读原样保留） */
.editor-area .tex-cmd {
    background: #ece7dd;
    padding: 1px 5px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    color: var(--text-secondary);
}

.editor-area img {
    max-width: 100%;
    height: auto;
    margin: 15px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* 右侧预览区 */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface-soft);
}

.preview-area {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    font-family: 'Courier New', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    background: var(--ink-dark);
    color: #d8d3c8;
}

/* 状态栏 */
.status-bar {
    background: var(--ink-dark);
    color: #a39d8f;
    padding: 8px 20px;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-bar .status-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
}

/* 键盘焦点环（可访问性） */
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: var(--surface-soft);
}

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: #b5ab98;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }

    .editor-panel {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .toolbar {
        padding: 8px 10px;
    }

    .toolbar button {
        padding: 6px 10px;
        font-size: 13px;
    }
}

/* 动效克制：用户偏好减弱动画时关闭过渡 */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}

/* 加载动画 */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

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

/* ===== 公式输入弹窗 ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(38, 35, 29, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.show {
    display: flex;
}

.modal-dialog {
    width: 720px;
    max-width: 92vw;
    max-height: 85vh;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-modal);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--ink-dark);
    color: #fff;
}

.modal-title {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    flex: 1;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    transition: var(--transition);
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* 公式输入面板 */
.formula-mode-row {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
}

.mode-option {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 14px;
}

.mode-option code {
    background: var(--surface-soft);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    border: 1px solid var(--border);
}

.symbol-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    max-height: 130px;
    overflow-y: auto;
}

.symbol-palette button {
    padding: 4px 10px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    font-family: 'Courier New', monospace;
    color: var(--text);
    transition: var(--transition);
}

.symbol-palette button:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

#formulaInput {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font-family: 'Courier New', monospace;
    font-size: 14px;
    resize: vertical;
    min-height: 90px;
    box-sizing: border-box;
    color: var(--text);
    background: var(--surface);
}

#formulaInput:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-actions {
    margin-top: 12px;
    display: flex;
    justify-content: flex-end;
}

.btn-insert {
    padding: 10px 28px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-insert:hover {
    background: var(--accent-hover);
}
