/* ============ 页面工坊 · 编辑器界面 ============ */

:root {
  --bg: #0b0e14;
  --panel: #141922;
  --panel-2: #191f2a;
  --panel-3: #1f2634;
  --line: #242b39;
  --line-2: #2f3747;
  --text: #e8ecf5;
  --muted: #8d97ab;
  --muted-2: #6b7488;
  --accent: #5b8cff;
  --accent-2: #a78bfa;
  --ok: #3ddc97;
  --danger: #ff7085;
  --radius: 10px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 13px;
}

.hidden { display: none !important; }

/* ---------- 布局 ---------- */
.app {
  display: grid;
  grid-template-rows: 54px minmax(0, 1fr);
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: linear-gradient(180deg, #171c26, #111620);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-right: 4px;
}

.brand .logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, #5b8cff, #a78bfa 60%, #41d1c0);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 15px;
  box-shadow: 0 6px 16px rgba(91, 140, 255, .35);
}

.brand-txt {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-txt b { font-size: 14px; letter-spacing: .3px; }
.brand-txt i {
  font-style: normal;
  font-size: 10px;
  color: var(--muted-2);
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.tb-sep {
  width: 1px;
  height: 22px;
  background: var(--line-2);
}

.tb-grow { flex: 1; }

.name-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #0f141c;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 10px;
  height: 32px;
}

.name-label {
  font-size: 11px;
  color: var(--muted-2);
  letter-spacing: .5px;
}

.page-name {
  width: 150px;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text);
  font-size: 13px;
}

.page-name::placeholder { color: var(--muted-2); }

.devices {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: #0f141c;
  border: 1px solid var(--line);
  border-radius: 9px;
}

.devices button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 4px 9px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 11px;
  transition: .16s;
  white-space: nowrap;
}

.devices button:hover { color: var(--text); background: #1b2230; }
.devices button.on { background: var(--panel-3); color: #fff; box-shadow: inset 0 0 0 1px var(--line-2); }

.btn {
  height: 32px;
  padding: 0 13px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: .16s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn.ghost {
  border-color: var(--line-2);
  background: #141a24;
  color: #c5cddd;
}

.btn.ghost:hover { background: #1c2431; color: #fff; border-color: #3b465c; }
.btn.ghost:disabled { opacity: .4; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(135deg, #5b8cff, #7c6cf6);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(91, 140, 255, .3);
}

.btn.primary:hover { filter: brightness(1.08); transform: translateY(-1px); }

/* 打开菜单 */
.menu-wrap { position: relative; }

.menu {
  position: absolute;
  top: 38px;
  right: 0;
  width: 260px;
  max-height: 320px;
  overflow: auto;
  background: #171d28;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 40;
}

.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.menu-item:hover { background: #212938; }
.menu-item b { font-size: 13px; font-weight: 500; }
.menu-item span { font-size: 11px; color: var(--muted-2); white-space: nowrap; }
.menu-empty { padding: 14px; color: var(--muted-2); text-align: center; }

/* ---------- 三栏 ---------- */
.workspace {
  display: grid;
  grid-template-columns: 254px minmax(0, 1fr) 330px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 8px;
  font-size: 12px;
  letter-spacing: .5px;
  color: #cfd7e6;
}

.panel-head .count {
  font-size: 11px;
  color: var(--muted-2);
  background: #0f141c;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
}

.search { padding: 4px 12px 10px; }

.search input {
  width: 100%;
  height: 32px;
  background: #0f141c;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 10px;
  color: var(--text);
  outline: none;
  transition: .16s;
}

.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 140, 255, .14); }
.search input::placeholder { color: var(--muted-2); }

.pal-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 12px;
}

.pal-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 12px 2px 7px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .6px;
}

.pal-group span { color: var(--muted-2); }

.pal-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  margin-bottom: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: grab;
  transition: .16s;
  user-select: none;
}

.pal-item:hover {
  border-color: #3f5178;
  background: #1d2534;
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, .3);
}

.pal-item:active { cursor: grabbing; }

.pal-item .ico {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 8px;
  background: linear-gradient(160deg, #26314a, #1c2434);
  border: 1px solid #2f3a52;
  display: grid;
  place-items: center;
  color: #9db4ff;
  font-size: 12px;
  font-weight: 700;
}

.pal-item .meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.pal-item .meta b { font-size: 12.5px; font-weight: 500; color: #e2e8f4; }
.pal-item .meta i {
  font-style: normal;
  font-size: 10px;
  color: var(--muted-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pal-item .drag-dots { color: #3d475c; font-size: 12px; margin-left: auto; }
.pal-item:hover .drag-dots { color: var(--accent); }

.pal-empty { padding: 24px 12px; text-align: center; color: var(--muted-2); font-size: 12px; }

.panel-foot {
  border-top: 1px solid var(--line);
  padding: 10px 14px;
  font-size: 11px;
  color: var(--muted-2);
  line-height: 1.6;
  display: flex;
  gap: 6px;
  align-items: flex-start;
}

.panel-foot .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 5px;
  flex: 0 0 auto;
  box-shadow: 0 0 8px var(--accent);
}

/* ---------- 画布 ---------- */
.stage {
  position: relative;
  min-height: 0;
  overflow: auto;
  background: #090c12;
  background-image: radial-gradient(#1a2130 1px, transparent 1px);
  background-size: 22px 22px;
  padding: 46px 24px 90px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.stage-hint {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: #5d6679;
  letter-spacing: .5px;
  pointer-events: none;
  white-space: nowrap;
}

.canvas {
  position: relative;
  width: 1200px;
  flex: 0 0 auto;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55), 0 0 0 1px rgba(255, 255, 255, .06);
  transition: width .22s ease;
  overflow: visible;
}

.canvas .page-root {
  border-radius: 4px;
  overflow: hidden;
}

.canvas .page-inner {
  position: relative;
  min-height: 520px;
}

/* 组件包裹层 */
.blk {
  position: relative;
  outline: 1px dashed transparent;
  outline-offset: -1px;
  transition: outline-color .15s;
}

.blk:hover { outline-color: rgba(91, 140, 255, .5); }
.blk.selected { outline: 2px solid var(--accent); outline-offset: -2px; }

.blk-tools {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(17, 22, 32, .94);
  border: 1px solid rgba(120, 140, 180, .3);
  border-radius: 9px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .35);
  opacity: 0;
  transform: translateY(-4px);
  transition: .16s;
  z-index: 30;
}

.blk:hover .blk-tools,
.blk.selected .blk-tools { opacity: 1; transform: none; }

.blk-tools .tool {
  width: 26px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #b8c2d6;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: .14s;
}

.blk-tools .tool:hover { background: #2a3446; color: #fff; }
.blk-tools .tool.danger:hover { background: rgba(255, 112, 133, .18); color: var(--danger); }
.blk-tools .handle { cursor: grab; }
.blk-tools .handle:active { cursor: grabbing; }

.blk-label {
  position: absolute;
  top: 4px;
  left: 4px;
  padding: 1px 7px;
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  letter-spacing: .4px;
  opacity: 0;
  pointer-events: none;
  transition: .16s;
  z-index: 29;
}

.blk.selected .blk-label { opacity: 1; }

.blk.dragging { opacity: .35; }

.drop-line {
  position: absolute;
  left: 6px;
  right: 6px;
  height: 3px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(91, 140, 255, .9);
  display: none;
  z-index: 40;
  pointer-events: none;
}

.canvas-empty {
  min-height: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #9aa4b8;
  border: 2px dashed #d8dee9;
  border-radius: 14px;
  margin: 40px;
  background: #fafbff;
}

.canvas-empty .ce-ico { font-size: 30px; color: #9db4ff; }
.canvas-empty p { margin: 0; font-size: 14px; color: #4f5a70; }
.canvas-empty span { font-size: 12px; color: #98a2b8; }

body.dragging .canvas-empty { border-color: var(--accent); background: #f2f6ff; }

/* ---------- 右侧参数面板 ---------- */
.insp-head {
  padding: 13px 14px 10px;
  border-bottom: 1px solid var(--line);
}

.insp-title-wrap { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.insp-title-wrap b { font-size: 14px; }
.insp-title-wrap i {
  font-style: normal;
  font-size: 10.5px;
  color: var(--muted-2);
  letter-spacing: .3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 3px;
  margin: 10px 14px 0;
  padding: 3px;
  background: #0f141c;
  border: 1px solid var(--line);
  border-radius: 9px;
}

.tabs button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 0;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  transition: .16s;
}

.tabs button:hover { color: #fff; }
.tabs button.on {
  background: linear-gradient(135deg, #37456a, #2c3554);
  color: #fff;
  box-shadow: inset 0 0 0 1px #44527a;
}

.insp-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
}

.field { margin-bottom: 14px; }

.f-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 11.5px;
  color: #aeb8ca;
}

.f-label code {
  margin-left: auto;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  color: #56617a;
  background: #0f141c;
  border: 1px solid #212936;
  border-radius: 5px;
  padding: 0 5px;
  flex: 0 0 auto;
}

.f-hint {
  margin: 6px 0 0;
  font-size: 10.5px;
  line-height: 1.6;
  color: #66708a;
}

.f-input {
  width: 100%;
  min-height: 32px;
  background: #0f141c;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 7px 10px;
  outline: none;
  transition: .16s;
  line-height: 1.5;
}

.f-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 140, 255, .14); }
.f-input::placeholder { color: #4e576c; }

textarea.f-input { resize: vertical; min-height: 76px; }

textarea.f-input.code {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.7;
  min-height: 150px;
  background: #0c1118;
  color: #a8e6c9;
  border-color: #1d2735;
  tab-size: 2;
}

select.f-input { appearance: none; cursor: pointer; }

.f-color { display: flex; gap: 8px; align-items: center; }

.f-color input[type="color"] {
  width: 38px;
  height: 32px;
  flex: 0 0 38px;
  padding: 2px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: #0f141c;
  cursor: pointer;
}

.f-color input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.f-color input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 5px; }

.f-range { display: flex; align-items: center; gap: 10px; }
.f-range input[type="range"] { flex: 1; accent-color: var(--accent); }
.f-range output {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  color: #9db4ff;
  min-width: 40px;
  text-align: right;
}

.f-switch { display: flex; align-items: center; gap: 9px; cursor: pointer; font-size: 12px; color: #b9c3d5; }
.f-switch input { display: none; }
.f-switch span {
  width: 34px;
  height: 19px;
  border-radius: 999px;
  background: #2a3242;
  position: relative;
  transition: .18s;
}
.f-switch span::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #8c96ab;
  transition: .18s;
}
.f-switch input:checked + span { background: rgba(91, 140, 255, .35); }
.f-switch input:checked + span::after { transform: translateX(15px); background: #fff; }

.insp-empty { padding: 30px 10px; text-align: center; color: var(--muted-2); font-size: 12px; line-height: 1.8; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 14px);
  padding: 9px 16px;
  background: #1b2331;
  border: 1px solid #33405a;
  border-radius: 10px;
  color: #dfe6f3;
  font-size: 12.5px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .45);
  opacity: 0;
  pointer-events: none;
  transition: .22s;
  z-index: 900;
  max-width: 70vw;
}

.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(255, 112, 133, .5); color: #ffd0d8; }
.toast.ok { border-color: rgba(61, 220, 151, .45); color: #c9f7e4; }

/* ---------- 代码弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, .72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 4vh 4vw;
}

.modal-dialog {
  width: min(1000px, 100%);
  height: min(760px, 100%);
  background: #10151e;
  border: 1px solid #2a3446;
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #151b26;
}

.modal-head b { font-size: 13.5px; }

.code-tabs {
  display: flex;
  gap: 3px;
  padding: 3px;
  background: #0b0f16;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.code-tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 4px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11.5px;
  font-family: ui-monospace, Consolas, monospace;
}

.code-tabs button.on { background: var(--accent); color: #fff; }

.modal-close {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: #141a24;
  color: var(--muted);
  cursor: pointer;
}

.modal-close:hover { color: #fff; background: #1e2635; }

.code-pre {
  margin: 0;
  flex: 1;
  overflow: auto;
  padding: 16px 18px;
  background: #0b0f15;
  color: #b7e2cc;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.75;
  tab-size: 2;
  white-space: pre;
}

/* 滚动条 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2b3446; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #3a465c; }
::-webkit-scrollbar-corner { background: transparent; }
