/* ==========================================================================
   LakexEditor Lab · 站点样式
   设计约束：
   1) 目标是「编辑器效果测试」，站点自身 UI 尽量克制，把视觉主体留给编辑区；
   2) 兼容性基线 Chrome 62+ / Firefox 100+ / Safari 13+，
      因此只用 flex 布局 + 普通 CSS 变量，不使用 :has()、aspect-ratio 等新特性；
   3) 层级：z-index 统一在 1~100 区间，避免与编辑器内部浮层冲突。
   ========================================================================== */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e3e6ea;
  --border-strong: #d2d7de;
  --text: #1f2329;
  --text-2: #5b6472;
  --text-3: #8b949e;
  --brand: #1677ff;
  --brand-weak: #e8f1ff;
  --danger: #d4380d;
  --ok: #1a7f37;
  --warn: #bc8b00;
  --radius: 6px;
  --sidebar-w: 232px;
  --settings-w: 320px;
  --topbar-h: 52px;
  --status-h: 28px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --mono: SFMono-Regular, Menlo, Consolas, "Liberation Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------ 通用控件 ------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn:active { background: #eef0f3; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: #0e5fd6; border-color: #0e5fd6; }
.btn-mini { height: 24px; padding: 0 8px; font-size: 12px; }
.btn-icon { width: 28px; padding: 0; }
.btn-block { display: block; width: 100%; }
.btn-row { display: flex; gap: 6px; margin-top: 6px; }
.btn-row.wrap { flex-wrap: wrap; }
.btn-danger { color: var(--danger); border-color: #f2c9bd; }
.btn-danger:hover { background: #fff3f0; }

.select {
  height: 28px;
  padding: 0 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}
.select-block { width: 100%; margin-top: 6px; }
.textarea {
  width: 100%;
  margin-top: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 12px;
  color: var(--text);
  resize: vertical;
}
.file-input { width: 100%; margin-top: 6px; font-size: 12px; }
select[size] { height: auto; min-height: 150px; }

.hint { margin-top: 6px; color: var(--text-3); font-size: 12px; line-height: 1.6; }
.empty-hint { padding: 16px 12px; color: var(--text-3); font-size: 12px; line-height: 1.7; }

/* ------------------------------ 启动遮罩 ------------------------------ */
.boot {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.boot.is-hidden { display: none; }
.boot-card {
  width: min(520px, calc(100vw - 32px));
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(20, 25, 35, .08);
}
.boot-title { font-size: 16px; font-weight: 600; }
.boot-sub { margin-top: 6px; color: var(--text-2); font-size: 13px; }
.boot-bar {
  height: 4px;
  margin: 14px 0 10px;
  border-radius: 2px;
  background: #eef0f3;
  overflow: hidden;
}
.boot-bar > i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--brand);
  transition: width .25s ease;
}
.boot-log {
  margin: 0;
  padding: 0;
  max-height: 168px;
  overflow: auto;
  list-style: none;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-2);
  line-height: 1.8;
}
.boot-log li::before { content: "· "; color: var(--text-3); }
.boot-log li.is-error { color: var(--danger); }
.boot-log li.is-ok::before { content: "✓ "; color: var(--ok); }
.boot-error {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #f2c9bd;
  border-radius: var(--radius);
  background: #fff3f0;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* ------------------------------ 顶栏 ------------------------------ */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.topbar-center { display: flex; align-items: center; gap: 8px; }
.topbar-right { display: flex; align-items: center; gap: 6px; flex: 1; justify-content: flex-end; }

.brand { font-weight: 600; font-size: 14px; white-space: nowrap; }
.brand-dot {
  margin-left: 4px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--brand-weak);
  color: var(--brand);
  font-size: 11px;
  font-weight: 500;
}

.title-input {
  width: min(360px, 42vw);
  height: 30px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
}
.title-input:hover { border-color: var(--border); }
.title-input:focus { outline: none; border-color: var(--brand); background: var(--surface); }

.save-flag { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-3); }
.save-flag > i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); }
.save-flag.is-dirty > i { background: var(--warn); }
.save-flag.is-saved > i { background: var(--ok); }
.save-flag.is-saving > i { background: var(--brand); }

/* 分段控件 */
.seg { display: inline-flex; padding: 2px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface-2); }
.seg-btn {
  height: 24px;
  padding: 0 12px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  cursor: pointer;
}
.seg-btn.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .06); font-weight: 500; }

/* ------------------------------ 主体三栏 ------------------------------ */
.layout {
  display: flex;
  height: calc(100% - var(--topbar-h) - var(--status-h));
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}
.doc-list { flex: 1; margin: 0; padding: 6px; list-style: none; overflow: auto; }
.doc-item {
  padding: 7px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
}
.doc-item:hover { background: var(--surface-2); }
.doc-item.is-active { background: var(--brand-weak); border-color: #cfe2ff; }
.doc-item-title { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 3px;
  color: var(--text-3);
  font-size: 11px;
}
.doc-del {
  padding: 0 4px;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--danger);
  font-size: 11px;
  cursor: pointer;
  opacity: 0;
}
.doc-item:hover .doc-del { opacity: 1; }
.doc-del:hover { background: #fff3f0; }
.side-foot { padding: 10px 12px; border-top: 1px solid var(--border); }
.side-tip { margin-bottom: 8px; color: var(--text-3); font-size: 11px; }

/* ------------------------------ 舞台 ------------------------------ */
.stage { display: flex; flex-direction: column; flex: 1; min-width: 0; background: var(--bg); }
.stage-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 36px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.stage-label { font-size: 12px; color: var(--text-2); font-weight: 500; }
.stage-spacer { flex: 1; }

.switch { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--text-2); }
.switch input { margin: 0; }
.switch label { cursor: pointer; }
.switch-line { display: flex; align-items: center; gap: 6px; padding: 5px 0; font-size: 12.5px; color: var(--text-2); }
.switch-line input { margin: 0; }
.switch-line label { cursor: pointer; }

.panes { display: flex; flex: 1; min-height: 0; }
.pane { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.pane + .pane { border-left: 1px solid var(--border); }

/* 编辑区滚动容器 —— 同时作为编辑器的 scrollNode */
.doc-scroll, .view-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 18px 0 120px;
}
/* 编辑器画布本体 */
#editor-host, #viewer-host {
  min-height: 420px;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(20, 25, 35, .06);
}

/* 源码区 */
.source-bar { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.source-bar span { font-size: 12px; color: var(--text-2); }
.source-view {
  flex: 1;
  margin: 0;
  padding: 14px;
  overflow: auto;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  color: #24292e;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ------------------------------ 右侧面板 ------------------------------ */
.settings {
  display: flex;
  flex-direction: column;
  width: var(--settings-w);
  flex: 0 0 var(--settings-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  transition: margin-right .18s ease;
}
body.panel-hidden .settings { margin-right: calc(-1 * var(--settings-w)); }

.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1;
  height: 36px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  cursor: pointer;
}
.tab.is-active { color: var(--text); border-bottom-color: var(--brand); font-weight: 500; }

.tab-body { flex: 1; overflow: auto; }
.tab-pane { display: none; padding: 12px; }
.tab-pane.is-active { display: block; }

.field { margin-bottom: 18px; }
.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.field-head label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.radio-row { display: flex; gap: 10px; flex-wrap: wrap; }
.radio-row label { font-size: 12.5px; cursor: pointer; }
.rdo { display: inline-flex; align-items: center; gap: 4px; }
.rdo input { margin: 0; }

.item-list { display: flex; flex-wrap: wrap; gap: 4px; max-height: 190px; overflow: auto; }
.item-list.compact { max-height: 160px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.chip label { cursor: pointer; }
.chip input { margin: 0; }
.chip.is-on { border-color: #b6d4ff; background: var(--brand-weak); color: #0b4fa8; }

.outline-list { padding: 2px 0; }
.outline-item {
  display: block;
  width: 100%;
  padding: 5px 8px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.outline-item:hover { background: var(--surface-2); color: var(--text); }
.outline-item[data-level="1"] { font-weight: 600; color: var(--text); padding-left: 8px; }
.outline-item[data-level="2"] { padding-left: 18px; }
.outline-item[data-level="3"] { padding-left: 28px; }
.outline-item[data-level="4"] { padding-left: 38px; }
.outline-item[data-level="5"] { padding-left: 48px; }
.outline-item[data-level="6"] { padding-left: 58px; }

.kv { display: flex; flex-wrap: wrap; margin: 0; font-size: 12px; }
.kv dt { width: 88px; color: var(--text-3); }
.kv dd { margin: 0 0 4px; width: calc(100% - 88px); word-break: break-all; }

/* ------------------------------ 状态栏 ------------------------------ */
.statusbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--status-h);
  padding: 0 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-3);
}
.statusbar b { font-weight: 600; color: var(--text-2); }
.st-spacer { flex: 1; }

/* ------------------------------ 图片预览浮层 ------------------------------ */
.lb { position: fixed; inset: 0; z-index: 95; }
.lb-mask { position: absolute; inset: 0; background: rgba(0, 0, 0, .72); }
.lb-img {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: 84vw;
  max-height: 82vh;
  transform: translate(-50%, -50%);
  border-radius: 4px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .4);
}
.lb-btn {
  position: absolute;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.lb-btn:hover { background: rgba(255, 255, 255, .3); }
.lb-prev { left: 24px; top: 50%; margin-top: -19px; }
.lb-next { right: 24px; top: 50%; margin-top: -19px; }
.lb-close { right: 24px; top: 24px; font-size: 16px; }

/* ------------------------------ 注入编辑器的自定义 header ------------------------------ */
.lake-custom-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font);
}
.lch-row { display: flex; align-items: center; gap: 8px; }
.lch-title { font-size: 15px; font-weight: 600; color: var(--text); }
.lch-tag {
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--brand-weak);
  color: var(--brand);
  font-size: 11px;
}
.lch-meta { margin-top: 4px; color: var(--text-3); font-size: 11.5px; }

/* ------------------------------ 提示 ------------------------------ */
.toast-wrap {
  position: fixed;
  right: 16px;
  bottom: 44px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}
.toast {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(20, 25, 35, .1);
  font-size: 12.5px;
  color: var(--text);
  animation: toast-in .18s ease;
}
.toast.is-error { border-color: #f2c9bd; background: #fff3f0; color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ------------------------------ 暗色外观（站点外壳） ------------------------------ */
body.is-dark { background: #14161a; }
body.is-dark .topbar,
body.is-dark .sidebar,
body.is-dark .statusbar,
body.is-dark .stage-toolbar,
body.is-dark .source-bar,
body.is-dark .settings { background: #1b1e23; border-color: #2b2f36; }
body.is-dark .stage { background: #14161a; }
body.is-dark,
body.is-dark .tab,
body.is-dark .stage-label,
body.is-dark .hint { color: #b6bdc6; }
body.is-dark .btn { background: #23272e; border-color: #343a42; color: #d6dbe1; }
body.is-dark .btn:hover { background: #2b3038; }
body.is-dark .select,
body.is-dark .textarea,
body.is-dark .title-input { background: #23272e; border-color: #343a42; color: #e4e8ec; }
body.is-dark .chip { background: #23272e; border-color: #343a42; color: #d6dbe1; }
body.is-dark .seg { background: #23272e; border-color: #343a42; }
body.is-dark .seg-btn { color: #a8b0ba; }
body.is-dark .seg-btn.is-active { background: #2f353d; color: #e4e8ec; }
body.is-dark .doc-item:hover,
body.is-dark .outline-item:hover { background: #23272e; }
body.is-dark .doc-item.is-active { background: #16324f; border-color: #22496f; }
body.is-dark .source-view { background: #1b1e23; color: #c9cdd3; }
body.is-dark .boot-card { background: #1b1e23; border-color: #2b2f36; }
body.is-dark .toast { background: #23272e; border-color: #343a42; color: #e4e8ec; }

/* ------------------------------ 窄屏降级 ------------------------------ */
@media (max-width: 1180px) {
  .settings { position: absolute; top: var(--topbar-h); right: 0; bottom: var(--status-h); z-index: 40; box-shadow: -8px 0 24px rgba(20, 25, 35, .1); }
  body.panel-hidden .settings { margin-right: calc(-1 * var(--settings-w) - 8px); }
}
@media (max-width: 900px) {
  .sidebar { display: none; }
  .panes { flex-direction: column; }
  .pane + .pane { border-left: none; border-top: 1px solid var(--border); }
}
