/* ===========================================================================
   云编辑器 · 在线网页编辑器  —  样式表
   设计：浅色 / 深色双主题，整体现代、紧凑、好用。
   =========================================================================== */

:root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --panel-2: #fafbfc;
    --border: #e3e6ea;
    --text: #2b2f36;
    --text-dim: #8a9099;
    --accent: #3b82f6;
    --accent-soft: #e8f0fe;
    --danger: #ef4444;
    --ok: #16a34a;
    --shadow: 0 1px 3px rgba(0, 0, 0, .08);
    --tree-hover: #eef2f7;
    --tab-active: #ffffff;
    --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

body.dark {
    --bg: #1e1e1e;
    --panel: #252526;
    --panel-2: #2d2d2e;
    --border: #3a3a3c;
    --text: #d4d4d4;
    --text-dim: #858585;
    --accent: #4ea1ff;
    --accent-soft: #1f3a5f;
    --danger: #f87171;
    --ok: #4ade80;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    --tree-hover: #2a2d2e;
    --tab-active: #1e1e1e;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---------- 顶栏 ---------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 14px;
    height: 48px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
}
.brand {
    font-weight: 700;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
.brand .logo {
    width: 22px; height: 22px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    border-radius: 6px;
    display: inline-block;
}
.topbar .spacer { flex: 1; }

.btn {
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    transition: all .12s ease;
    white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.icon { padding: 6px 9px; }

/* ---------- 主体布局 ---------- */
.main {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* 侧边栏：文件树 */
.sidebar {
    width: 260px;
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width .15s ease;
}
.sidebar.collapsed { width: 0; overflow: hidden; }
.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 13px;
}
.sidebar-head .actions { display: flex; gap: 4px; }
.tree {
    flex: 1;
    overflow: auto;
    padding: 6px 4px;
}
.tree-empty { color: var(--text-dim); padding: 16px; font-size: 13px; }

/* 树节点 */
.node {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 5px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    font-size: 13px;
}
.node:hover { background: var(--tree-hover); }
.node.active { background: var(--accent-soft); color: var(--accent); }
.node .twist {
    width: 14px; text-align: center; color: var(--text-dim);
    flex-shrink: 0; font-size: 10px;
}
.node .ico { flex-shrink: 0; opacity: .85; }
.node .label { overflow: hidden; text-overflow: ellipsis; }
.node .dirty-dot {
    margin-left: auto; width: 7px; height: 7px; border-radius: 50%;
    background: var(--accent); flex-shrink: 0;
}
.children { padding-left: 14px; }

/* 编辑器区 */
.editor-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg);
}

.tabs {
    display: flex;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    flex-shrink: 0;
    min-height: 38px;
}
.tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px 0 14px;
    height: 38px;
    border-right: 1px solid var(--border);
    cursor: pointer;
    white-space: nowrap;
    background: var(--panel-2);
    color: var(--text-dim);
    max-width: 220px;
}
.tab.active {
    background: var(--tab-active);
    color: var(--text);
    box-shadow: inset 0 -2px 0 var(--accent);
}
.tab .tname { overflow: hidden; text-overflow: ellipsis; }
.tab .tclose {
    width: 18px; height: 18px; border-radius: 4px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 14px; color: var(--text-dim);
}
.tab .tclose:hover { background: var(--danger); color: #fff; }
.tab .dirty { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

.editor-area { flex: 1; min-height: 0; position: relative; }

/* 编辑 / 预览 分栏 */
.panes { flex: 1; display: flex; min-height: 0; }
.preview {
    width: 0;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--panel);
    border-left: 1px solid var(--border);
    position: relative;
}
.preview.open { width: 45%; min-width: 320px; }
.preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    height: 36px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    flex-shrink: 0;
}
.preview-head .actions { display: flex; gap: 4px; }
.preview-frame { flex: 1; width: 100%; border: none; background: #fff; display: block; }
.preview-empty {
    display: none;
    position: absolute;
    top: 36px; left: 0; right: 0; bottom: 0;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    color: var(--text-dim);
    font-size: 13px;
    white-space: pre-line;
    background: var(--panel);
}
.preview-empty.loading { color: var(--accent); }

/* 命令面板 */
.palette {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    width: 520px;
    max-width: 92vw;
    box-shadow: var(--shadow);
    overflow: hidden;
}
.palette input[type=text] {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 12px 14px;
    font-size: 14px;
    background: var(--panel);
    color: var(--text);
    outline: none;
}
.palette-list { max-height: 52vh; overflow: auto; padding: 6px; }
.palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
.palette-item.active { background: var(--accent-soft); color: var(--accent); }
.palette-item .pi-ico { flex-shrink: 0; }
.palette-item .pi-path { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item .pi-lang { color: var(--text-dim); font-size: 11px; flex-shrink: 0; }
.palette-empty { color: var(--text-dim); padding: 14px; font-size: 13px; text-align: center; }

.CodeMirror { height: 100%; font-family: var(--mono); font-size: 14px; }

.editor-empty {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: var(--text-dim); gap: 8px; text-align: center; padding: 20px;
}
.editor-empty h2 { margin: 0; color: var(--text); font-weight: 600; }

/* 状态栏 */
.statusbar {
    display: flex;
    align-items: center;
    gap: 18px;
    height: 28px;
    padding: 0 14px;
    background: var(--panel);
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-dim);
    flex-shrink: 0;
}
.statusbar .spacer { flex: 1; }
.statusbar .pill { display: inline-flex; align-items: center; gap: 4px; }
.statusbar .ok { color: var(--ok); }
.statusbar .warn { color: var(--danger); }

/* ---------- 通用弹窗 ---------- */
.overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, .35);
    display: none;
    align-items: center; justify-content: center;
    z-index: 100;
}
.overlay.show { display: flex; }
.modal {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px;
    width: 360px;
    max-width: 90vw;
    box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 12px; font-size: 15px; }
.modal label { display: block; font-size: 12px; color: var(--text-dim); margin: 10px 0 4px; }
.modal input[type=text], .modal select {
    width: 100%; padding: 8px 10px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--panel-2); color: var(--text); font-size: 13px;
}
.modal .row { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.modal .row label { margin: 0; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* 右键菜单 */
.ctx {
    position: fixed;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 4px;
    display: none;
    z-index: 200;
    min-width: 160px;
}
.ctx.show { display: block; }
.ctx-item {
    padding: 7px 10px; border-radius: 5px; cursor: pointer; font-size: 13px;
    display: flex; align-items: center; gap: 8px;
}
.ctx-item:hover { background: var(--tree-hover); }
.ctx-item.danger { color: var(--danger); }
.ctx-sep { height: 1px; background: var(--border); margin: 4px 0; }

.hint { font-size: 12px; color: var(--text-dim); }
kbd {
    background: var(--panel-2); border: 1px solid var(--border);
    border-radius: 4px; padding: 1px 5px; font-size: 11px; font-family: var(--mono);
}

/* 滚动条 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
