/* Landing Forge · 落地页工坊 —— 界面样式 */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #0f172a;
  --mute: #64748b;
  --line: #e2e8f0;
  --soft: #f8fafc;
  --brand: #2563eb;
  --brand-ink: #ffffff;
  --danger: #dc2626;
  --ok: #059669;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden { display: none !important; }
.grow { flex: 1 1 auto; }
.muted { color: var(--mute); font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.logo {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .5px;
  flex: 0 0 auto;
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 14px; line-height: 1.2; }
.brand-text small { color: var(--mute); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }

/* ---------- 按钮 / 输入 ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, box-shadow .12s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: var(--soft); border-color: #cbd5e1; }
.btn:active { transform: translateY(.5px); }
.btn[disabled] { opacity: .5; cursor: default; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }

.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; border-color: #fca5a5; }

.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 9px; font-size: 12px; border-radius: 7px; }
.btn-block { width: 100%; justify-content: center; }

.select, .input, .textarea {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  width: 100%;
  outline: none;
}
.select:focus, .input:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.select { max-width: 220px; cursor: pointer; }
.textarea { resize: vertical; line-height: 1.45; }

/* ---------- 三栏布局 ---------- */
.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr) 360px;
  gap: 10px;
  padding: 10px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.panel-head h2 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .3px; }
.panel-head .btn { margin-left: auto; }

.panel-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}
.panel-foot .btn { margin-left: auto; }

/* ---------- 模块列表 ---------- */
.module-list { flex: 1 1 auto; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }

.module-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.module-item:hover { border-color: #cbd5e1; background: var(--soft); }
.module-item.active { border-color: var(--brand); background: #eff6ff; box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }
.module-item.is-hidden { opacity: .48; }

.mi-top { display: flex; align-items: center; gap: 6px; }
.mi-idx {
  width: 20px; height: 20px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 5px;
  background: var(--soft);
  color: var(--mute);
  font-size: 11px;
  font-family: var(--mono);
}
.mi-name {
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1 1 auto;
}
.mi-kind {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #eef2ff;
  color: #4338ca;
  flex: 0 0 auto;
}

.mi-ops { display: flex; gap: 3px; margin-top: 6px; flex-wrap: wrap; }
.mi-ops button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--mute);
  border-radius: 6px;
  font-size: 11px;
  padding: 2px 6px;
  cursor: pointer;
  line-height: 1.4;
}
.mi-ops button:hover { color: var(--ink); border-color: #cbd5e1; background: var(--soft); }
.mi-ops button.danger:hover { color: var(--danger); border-color: #fca5a5; background: #fef2f2; }

.empty { padding: 24px 12px; text-align: center; color: var(--mute); font-size: 12px; line-height: 1.7; }

/* ---------- 中间工具栏 ---------- */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.seg { display: inline-flex; background: var(--soft); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg-btn {
  border: 0; background: transparent; color: var(--mute);
  font: inherit; font-size: 12px;
  padding: 4px 10px; border-radius: 6px; cursor: pointer;
  white-space: nowrap;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.active { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(15, 23, 42, .1); }

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--mute); cursor: pointer; user-select: none; }
.switch input { accent-color: var(--brand); }

/* ---------- 舞台 ---------- */
.stage { flex: 1 1 auto; min-height: 0; display: flex; background: #eef1f6; overflow: hidden; }
.frame-wrap { flex: 1 1 auto; min-width: 0; display: flex; justify-content: center; overflow: auto; padding: 10px; }
#previewFrame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, .08);
  transition: width .15s;
}

.code-wrap { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; background: #0f172a; }
.code-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: #111c33;
  border-bottom: 1px solid #1e293b;
  flex-wrap: wrap;
}
.code-bar .seg { background: #1e293b; border-color: #334155; }
.code-bar .seg-btn { color: #94a3b8; }
.code-bar .seg-btn.active { background: #334155; color: #f8fafc; box-shadow: none; }
.code-bar .muted { color: #94a3b8; }
.code-bar .btn { background: #1e293b; border-color: #334155; color: #e2e8f0; }
.code-bar .btn:hover { background: #334155; }
.code-bar .btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }

.code-area {
  flex: 1 1 auto;
  border: 0;
  outline: none;
  resize: none;
  background: #0b1220;
  color: #d6e2f5;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  padding: 12px 14px;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

/* ---------- 右侧面板 ---------- */
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.tab {
  flex: 1 1 0;
  border: 0; background: transparent;
  font: inherit; font-size: 13px; color: var(--mute);
  padding: 10px 6px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 500; }

.tab-body { flex: 1 1 auto; overflow-y: auto; padding: 12px; }

.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12px; font-weight: 500; color: var(--mute); margin-bottom: 5px; }
.field summary { font-size: 12px; font-weight: 500; color: var(--mute); cursor: pointer; }

.row { display: flex; align-items: center; gap: 6px; }
.row.right { justify-content: flex-end; margin-top: 6px; }
.col { display: flex; flex-direction: column; gap: 8px; }

.hint {
  font-size: 12px;
  color: var(--mute);
  background: var(--soft);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 12px;
  line-height: 1.7;
}

.hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.attr-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.attr-row { display: flex; align-items: center; gap: 6px; }
.attr-row .attr-name {
  font-family: var(--mono);
  font-size: 11px;
  color: #4338ca;
  background: #eef2ff;
  border-radius: 5px;
  padding: 3px 6px;
  flex: 0 0 auto;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attr-row .input { flex: 1 1 auto; min-width: 0; }
.attr-row button {
  border: 1px solid var(--line); background: #fff; color: var(--mute);
  border-radius: 6px; width: 26px; height: 28px; cursor: pointer; flex: 0 0 auto;
  font-size: 13px; line-height: 1;
}
.attr-row button:hover { color: var(--danger); border-color: #fca5a5; background: #fef2f2; }
.attr-add { margin-top: 2px; }

.pre {
  background: #0b1220;
  color: #d6e2f5;
  border-radius: 8px;
  padding: 10px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  max-height: 240px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 8px 0 0;
}

/* ---------- 弹层 ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .45);
  display: grid; place-items: center;
  padding: 24px;
  z-index: 100;
}
.modal-box {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, .3);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 18px 20px 16px;
}
.modal-box.modal-wide { max-width: 1000px; }
.modal-box h3 { margin: 0 0 6px; font-size: 16px; }
.modal-box > p { margin: 0 0 14px; font-size: 12px; color: var(--mute); line-height: 1.7; }
.modal-foot { display: flex; align-items: center; gap: 8px; margin-top: 16px; }

/* ---------- 模块库 ---------- */
.lib-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 12px; height: 52vh; min-height: 260px; }
.lib-list { overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.lib-item {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 7px 9px;
  cursor: pointer;
  font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.lib-item:hover { background: var(--soft); }
.lib-item.active { border-color: var(--brand); background: #eff6ff; }
.lib-item .k { font-size: 10px; color: #4338ca; background: #eef2ff; border-radius: 999px; padding: 1px 6px; margin-left: auto; }
.lib-preview { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.lib-preview iframe { width: 100%; height: 100%; border: 0; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translateX(-50%);
  background: #0f172a;
  color: #f8fafc;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .3);
  z-index: 200;
  max-width: 80vw;
  text-align: center;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 220px minmax(0, 1fr) 320px; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto minmax(240px, 1fr) auto; overflow-y: auto; }
  .panel-left, .panel-right { max-height: 40vh; }
  body { overflow: auto; }
}
