/**
 * CCOS Canvas · 编辑器外壳样式
 * 编辑器自身固定深色（专业工具惯例）；画布内的部件由 css/ccos.css + --cc-* 令牌渲染，
 * 因此「编辑器长什么样」与「产物长什么样」完全解耦。
 */

:root {
  --sh-bg: #070c1a;
  --sh-panel: #0b1220;
  --sh-panel2: #101a2e;
  --sh-panel3: #16223a;
  --sh-line: rgba(255, 255, 255, 0.08);
  --sh-line2: rgba(255, 255, 255, 0.14);
  --sh-ink: #e8eef9;
  --sh-ink2: #93a1bc;
  --sh-ink3: #5f6c8c;
  --sh-pri: #2be3a4;
  --sh-blue: #5ba2ff;
  --sh-danger: #ff6b7d;
  --sh-warn: #ffb454;
  --sh-r: 10px;
  --sh-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--sh-bg);
  color: var(--sh-ink);
  font-family: 'PingFang SC', 'HarmonyOS Sans SC', -apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

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

::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 6px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.24);
}
::-webkit-scrollbar-track {
  background: transparent;
}

#app {
  display: grid;
  grid-template-rows: 52px 1fr 26px;
  height: 100vh;
}

/* ==================== 顶栏 ==================== */
.tb {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: linear-gradient(180deg, #0d1526, #0a1220);
  border-bottom: 1px solid var(--sh-line);
  min-width: 0;
}

.tb-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-right: 10px;
  flex: none;
}
.tb-logo {
  width: 26px;
  height: 26px;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--sh-pri), var(--sh-blue));
  box-shadow: 0 4px 14px rgba(43, 227, 164, 0.3);
  position: relative;
}
.tb-logo::after {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: rgba(7, 12, 26, 0.85);
}
.tb-brandtxt {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.tb-brandtxt strong {
  font-size: 13px;
  letter-spacing: 0.2px;
}
.tb-brandtxt span {
  font-size: 10px;
  color: var(--sh-ink3);
}

.tb-doc {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  flex: none;
}
.tb-title {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 5px 9px;
  width: 178px;
  font-weight: 600;
  outline: none;
}
.tb-title:hover {
  border-color: var(--sh-line);
}
.tb-title:focus {
  border-color: rgba(43, 227, 164, 0.5);
  background: rgba(255, 255, 255, 0.04);
}
.tb-dirty {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sh-pri);
  opacity: 0;
  transition: opacity 0.3s;
}
.tb-dirty.is-on {
  opacity: 0.9;
}

.tb-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}
.tb-sep {
  width: 1px;
  height: 20px;
  background: var(--sh-line);
  margin: 0 2px;
}
.tb-spacer {
  flex: 1 1 auto;
  min-width: 8px;
}

.tbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--sh-line);
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s, border-color 0.14s, transform 0.1s;
}
.tbtn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--sh-line2);
}
.tbtn:active {
  transform: translateY(1px);
}
.tbtn:disabled {
  opacity: 0.34;
  cursor: default;
}
.tbtn.is-active {
  background: rgba(43, 227, 164, 0.16);
  border-color: rgba(43, 227, 164, 0.45);
  color: #c9fff0;
}
.tbtn-primary {
  background: linear-gradient(150deg, rgba(43, 227, 164, 0.9), rgba(77, 159, 255, 0.85));
  border-color: transparent;
  color: #04140f;
  font-weight: 700;
}
.tbtn-primary:hover {
  filter: brightness(1.08);
}
.tbtn-danger:hover {
  background: rgba(255, 107, 125, 0.18);
  border-color: rgba(255, 107, 125, 0.45);
}
.tbtn-zoom {
  min-width: 54px;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}
.tbtn svg {
  display: block;
}
.tb-swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  background: #f1f4fa;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.tsel {
  height: 30px;
  padding: 0 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--sh-line);
  border-radius: 9px;
  cursor: pointer;
  outline: none;
}
.tsel option {
  background: #0b1220;
}
.tsel.sm {
  height: 26px;
  border-radius: 7px;
}

/* ==================== 主体 ==================== */
.stage {
  display: grid;
  grid-template-columns: 262px 1fr 322px;
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  background: var(--sh-panel);
  min-height: 0;
  min-width: 0;
}
.pane-left {
  border-right: 1px solid var(--sh-line);
}
.pane-right {
  border-left: 1px solid var(--sh-line);
}

.pane-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 0;
  flex: none;
}
.ptab {
  flex: 1;
  height: 28px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px 8px 0 0;
  color: var(--sh-ink3);
  cursor: pointer;
  font-size: 12px;
}
.ptab:hover {
  color: var(--sh-ink2);
}
.ptab.is-active {
  color: var(--sh-ink);
  background: var(--sh-panel2);
  border-color: var(--sh-line);
  border-bottom-color: transparent;
  font-weight: 600;
}

.pane-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px;
}
.pane-body.is-hidden {
  display: none;
}

/* ---------------- 部件库 ---------------- */
.lib-search {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 10px;
  background: var(--sh-panel2);
  border: 1px solid var(--sh-line);
  border-radius: 9px;
  margin-bottom: 10px;
}
.lib-search input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
}
.lib-search svg {
  color: var(--sh-ink3);
  flex: none;
}

.lib-group {
  margin-bottom: 14px;
}
.lib-group h4 {
  margin: 0 0 7px;
  font-size: 11px;
  color: var(--sh-ink3);
  font-weight: 600;
  letter-spacing: 0.4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.lib-group h4 em {
  font-style: normal;
  color: var(--sh-ink3);
  opacity: 0.7;
}
.lib-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.lib-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 8px;
  background: var(--sh-panel2);
  border: 1px solid var(--sh-line);
  border-radius: 9px;
  cursor: grab;
  text-align: left;
  transition: background 0.14s, border-color 0.14s;
  min-width: 0;
}
.lib-item:hover {
  background: var(--sh-panel3);
  border-color: rgba(43, 227, 164, 0.35);
}
.lib-item:active {
  cursor: grabbing;
}
.lib-item i {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  color: var(--sh-pri);
  flex: none;
}
.lib-item span {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lib-empty {
  padding: 24px 8px;
  text-align: center;
  color: var(--sh-ink3);
  font-size: 12px;
}

/* ---------------- 图层树 ---------------- */
.layer-tools {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.layer-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.layer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 7px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  min-width: 0;
}
.layer-row:hover {
  background: rgba(255, 255, 255, 0.05);
}
.layer-row.is-sel {
  background: rgba(43, 227, 164, 0.14);
  border-color: rgba(43, 227, 164, 0.4);
}
.layer-row.is-hidden {
  opacity: 0.45;
}
.layer-row i {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  color: var(--sh-blue);
  flex: none;
}
.layer-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}
.layer-kind {
  font-size: 10px;
  color: var(--sh-ink3);
  font-variant-numeric: tabular-nums;
}
.layer-btn {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  color: var(--sh-ink3);
  flex: none;
}
.layer-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--sh-ink);
}
.layer-btn.is-on {
  color: var(--sh-warn);
}

/* ==================== 画布 ==================== */
.viewport {
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at 50% 0%, #131e34 0%, #080e1c 62%);
  outline: none;
  min-width: 0;
}
.viewport::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.07) 1px, transparent 1px);
  background-size: 22px 22px;
  pointer-events: none;
  opacity: 0.55;
}
.scene {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.artboard-frame {
  position: relative;
  border-radius: 44px;
  overflow: hidden;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.1);
  background: #000;
}
.artboard-frame.is-blob::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 44px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14), inset 0 22px 40px rgba(255, 255, 255, 0.08);
  pointer-events: none;
  z-index: 5;
}
#artboard[data-bg='plain']::before,
#artboard[data-bg='plain']::after,
#artboard[data-bg='grid']::before,
#artboard[data-bg='grid']::after {
  display: none;
}
#artboard[data-bg='grid'] {
  background-image: linear-gradient(rgba(120, 160, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 160, 255, 0.08) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* 节点层 */
/* 部件层必须压在 .cc-artboard 的弥散光斑伪元素之上（z-index:1），浮层再上一层 */
.cv-nodes {
  position: absolute;
  inset: 0;
  z-index: 1;
}
.cv-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
}
.cv-node {
  position: absolute;
  cursor: move;
}
.cv-node-inner {
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
}
.cv-node.is-locked .cv-node-inner {
  opacity: 0.6;
}
.cv-node.is-hidden {
  display: none;
}
.cv-node:hover::before {
  content: '';
  position: absolute;
  inset: -1px;
  border: 1px dashed rgba(91, 162, 255, 0.75);
  border-radius: 3px;
  pointer-events: none;
  z-index: 20;
}
.cv-node.is-sel::after {
  content: '';
  position: absolute;
  inset: -1px;
  border: 1.6px solid var(--sh-pri);
  border-radius: 3px;
  pointer-events: none;
  z-index: 21;
}
.cv-node.is-sel.is-primary::after {
  box-shadow: 0 0 0 3px rgba(43, 227, 164, 0.18);
}
.cv-node.is-dragging {
  cursor: grabbing;
}

.cv-tag {
  position: absolute;
  top: -19px;
  left: -1px;
  height: 17px;
  padding: 0 6px;
  border-radius: 5px 5px 0 0;
  background: var(--sh-pri);
  color: #04140f;
  font-size: 10px;
  font-weight: 700;
  line-height: 17px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 22;
}

.cv-handle {
  position: absolute;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  background: #fff;
  border: 1.6px solid #10a877;
  border-radius: 2px;
  z-index: 23;
  pointer-events: auto;
}
.cv-handle[data-h='nw'],
.cv-handle[data-h='se'] {
  cursor: nwse-resize;
}
.cv-handle[data-h='ne'],
.cv-handle[data-h='sw'] {
  cursor: nesw-resize;
}
.cv-handle[data-h='n'],
.cv-handle[data-h='s'] {
  cursor: ns-resize;
}
.cv-handle[data-h='w'],
.cv-handle[data-h='e'] {
  cursor: ew-resize;
}

.cv-marquee {
  position: absolute;
  border: 1px solid var(--sh-pri);
  background: rgba(43, 227, 164, 0.1);
  pointer-events: none;
  z-index: 30;
}

.cv-guide {
  position: absolute;
  background: #ff5a6e;
  pointer-events: none;
  z-index: 29;
}
.cv-guide.is-x {
  width: 1px;
}
.cv-guide.is-y {
  height: 1px;
}
.cv-guide-tag {
  position: absolute;
  padding: 1px 5px;
  border-radius: 4px;
  background: #ff5a6e;
  color: #fff;
  font-size: 9px;
  line-height: 14px;
  white-space: nowrap;
  z-index: 31;
  pointer-events: none;
}

.vp-corner {
  position: absolute;
  right: 12px;
  bottom: 12px;
  padding: 5px 9px;
  border-radius: 8px;
  background: rgba(11, 18, 32, 0.82);
  border: 1px solid var(--sh-line);
  color: var(--sh-ink2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(8px);
}
.vp-hint {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(11, 18, 32, 0.82);
  border: 1px solid var(--sh-line);
  color: var(--sh-ink3);
  font-size: 11px;
  backdrop-filter: blur(8px);
}
kbd {
  display: inline-block;
  padding: 1px 5px;
  margin: 0 1px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--sh-line2);
  font-family: inherit;
  font-size: 10px;
  color: var(--sh-ink2);
}

/* ==================== 属性面板 ==================== */
.insp-section {
  margin-bottom: 14px;
  border: 1px solid var(--sh-line);
  border-radius: 12px;
  background: var(--sh-panel2);
  overflow: hidden;
}
.insp-head {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--sh-line);
  font-size: 12px;
  font-weight: 600;
}
.insp-head em {
  font-style: normal;
  font-size: 10px;
  color: var(--sh-ink3);
  margin-left: auto;
}
.insp-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.insp-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.insp-row > label {
  width: 76px;
  flex: none;
  font-size: 11px;
  color: var(--sh-ink3);
}
.insp-row .grow {
  flex: 1;
  min-width: 0;
}
.insp-grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.f-inp,
.f-sel,
.f-num {
  width: 100%;
  height: 30px;
  padding: 0 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--sh-line);
  border-radius: 8px;
  outline: none;
}
.f-inp:focus,
.f-sel:focus,
.f-num:focus {
  border-color: rgba(43, 227, 164, 0.5);
  background: rgba(43, 227, 164, 0.06);
}
textarea.f-inp {
  height: 66px;
  padding: 7px 8px;
  resize: vertical;
  line-height: 1.5;
}
.f-num {
  font-variant-numeric: tabular-nums;
}
.f-num-unit {
  position: relative;
  flex: 1;
  min-width: 0;
}
.f-num-unit .f-num {
  padding-right: 26px;
}
.f-num-unit em {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-style: normal;
  font-size: 10px;
  color: var(--sh-ink3);
  pointer-events: none;
}
.f-sel option {
  background: #0b1220;
}
.f-sw {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--sh-line);
  position: relative;
  cursor: pointer;
  flex: none;
}
.f-sw::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.16s;
}
.f-sw.is-on {
  background: rgba(43, 227, 164, 0.55);
  border-color: rgba(43, 227, 164, 0.6);
}
.f-sw.is-on::after {
  transform: translateX(18px);
}
.f-color {
  display: flex;
  align-items: center;
  gap: 7px;
}
.f-color input[type='color'] {
  width: 34px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--sh-line2);
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
}
.f-color input[type='range'] {
  flex: 1;
  min-width: 0;
  accent-color: var(--sh-pri);
}
.f-color .alpha-val {
  width: 38px;
  text-align: right;
  font-size: 10px;
  color: var(--sh-ink3);
  font-variant-numeric: tabular-nums;
}
.f-ico {
  display: flex;
  align-items: center;
  gap: 7px;
}
.f-ico .ico-preview {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--sh-line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  flex: none;
  color: var(--sh-pri);
}

.insp-empty {
  padding: 26px 14px;
  text-align: center;
  color: var(--sh-ink3);
  line-height: 1.7;
}
.insp-empty strong {
  display: block;
  color: var(--sh-ink2);
  margin-bottom: 4px;
  font-size: 12px;
}
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(91, 162, 255, 0.16);
  border: 1px solid rgba(91, 162, 255, 0.3);
  color: #bcd6ff;
  font-size: 10px;
}
.tag.pri {
  background: rgba(43, 227, 164, 0.14);
  border-color: rgba(43, 227, 164, 0.32);
  color: #b6f7dd;
}
.tag.warn {
  background: rgba(255, 180, 84, 0.14);
  border-color: rgba(255, 180, 84, 0.32);
  color: #ffd9a3;
}
.tag.danger {
  background: rgba(255, 107, 125, 0.14);
  border-color: rgba(255, 107, 125, 0.32);
  color: #ffc0c8;
}
.mono {
  font-family: 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--sh-ink2);
  word-break: break-all;
}
.hintline {
  font-size: 11px;
  color: var(--sh-ink3);
  line-height: 1.6;
}
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.mini {
  height: 26px;
  padding: 0 9px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--sh-line);
  border-radius: 7px;
  cursor: pointer;
  font-size: 11px;
}
.mini:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--sh-line2);
}
.mini.pri {
  background: rgba(43, 227, 164, 0.14);
  border-color: rgba(43, 227, 164, 0.34);
  color: #b6f7dd;
}
.mini.danger:hover {
  background: rgba(255, 107, 125, 0.18);
  border-color: rgba(255, 107, 125, 0.4);
}

/* 令牌面板 */
.tok-group {
  margin-bottom: 12px;
}
.tok-group h4 {
  margin: 0 0 8px;
  font-size: 11px;
  color: var(--sh-ink3);
  letter-spacing: 0.4px;
}
.tok-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}
.tok-row > label {
  width: 92px;
  flex: none;
  font-size: 11px;
  color: var(--sh-ink2);
}
.tok-row .is-changed {
  color: var(--sh-pri);
}
.tok-reset {
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--sh-ink3);
  border-radius: 5px;
  cursor: pointer;
  flex: none;
}
.tok-reset:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--sh-ink);
}

/* 校验 */
.lint-item {
  display: flex;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--sh-line);
  border-radius: 10px;
  background: var(--sh-panel2);
  margin-bottom: 7px;
  cursor: pointer;
}
.lint-item:hover {
  border-color: var(--sh-line2);
}
.lint-item i {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-style: normal;
  font-weight: 700;
}
.lint-item.pass i {
  background: rgba(43, 227, 164, 0.2);
  color: var(--sh-pri);
}
.lint-item.info i {
  background: rgba(91, 162, 255, 0.2);
  color: var(--sh-blue);
}
.lint-item.warn i {
  background: rgba(255, 180, 84, 0.2);
  color: var(--sh-warn);
}
.lint-item.error i {
  background: rgba(255, 107, 125, 0.2);
  color: var(--sh-danger);
}
.lint-item div {
  min-width: 0;
}
.lint-item strong {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 2px;
}
.lint-item span {
  font-size: 11px;
  color: var(--sh-ink3);
  line-height: 1.5;
}

/* ==================== 状态栏 ==================== */
.sb {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: #0a1220;
  border-top: 1px solid var(--sh-line);
  color: var(--sh-ink3);
  font-size: 11px;
  gap: 12px;
}
.sb-left,
.sb-right {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-right {
  color: var(--sh-ink2);
  font-variant-numeric: tabular-nums;
}

/* ==================== 弹层 ==================== */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: rgba(4, 7, 15, 0.62);
  backdrop-filter: blur(6px);
  padding: 24px;
}
/* 修复：display:grid 会盖过 UA 的 [hidden]{display:none}，导致整层暗罩常驻、阻挡整站鼠标点击。
   显式补一条，使 openModal() 设的 root.hidden = true 真的能关掉。 */
.modal-root[hidden] { display: none; }
.modal {
  width: min(940px, 96vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--sh-panel);
  border: 1px solid var(--sh-line2);
  border-radius: 16px;
  box-shadow: var(--sh-shadow);
  overflow: hidden;
}
.modal.sm {
  width: min(560px, 94vw);
}
.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--sh-line);
}
.modal-head strong {
  font-size: 14px;
}
.modal-head em {
  font-style: normal;
  font-size: 11px;
  color: var(--sh-ink3);
}
.modal-head .x {
  margin-left: auto;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--sh-line);
  background: transparent;
  color: var(--sh-ink2);
  cursor: pointer;
}
.modal-head .x:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}
.modal-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 14px 15px;
}
.modal-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 15px;
  border-top: 1px solid var(--sh-line);
}
.modal-foot .right {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}
.tpl-card {
  text-align: left;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--sh-line);
  background: var(--sh-panel2);
  cursor: pointer;
}
.tpl-card:hover {
  border-color: rgba(43, 227, 164, 0.5);
  background: var(--sh-panel3);
}
.tpl-card strong {
  display: block;
  font-size: 12px;
  margin-bottom: 5px;
}
.tpl-card span {
  font-size: 11px;
  color: var(--sh-ink3);
}
.tpl-thumb {
  height: 92px;
  border-radius: 9px;
  margin-bottom: 9px;
  overflow: hidden;
  position: relative;
  background: #0f1729;
  border: 1px solid var(--sh-line);
}
.tpl-thumb i {
  position: absolute;
  display: block;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.14);
}
.tpl-thumb i.pri {
  background: rgba(43, 227, 164, 0.5);
}

.code-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.code-tabs button {
  height: 28px;
  padding: 0 11px;
  border-radius: 8px;
  border: 1px solid var(--sh-line);
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  font-size: 12px;
}
.code-tabs button.is-active {
  background: rgba(43, 227, 164, 0.16);
  border-color: rgba(43, 227, 164, 0.42);
  color: #c9fff0;
}
.code-box {
  background: #060a14;
  border: 1px solid var(--sh-line);
  border-radius: 10px;
  padding: 12px;
  font-family: 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  color: #cfe3ff;
  max-height: 52vh;
  overflow: auto;
}
.share-row {
  display: flex;
  gap: 8px;
}
.share-row input {
  flex: 1;
  height: 32px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--sh-line);
  border-radius: 9px;
  outline: none;
  font-size: 11.5px;
}

/* 右键菜单 */
.ctx-menu {
  position: fixed;
  z-index: 300;
  min-width: 176px;
  padding: 5px;
  background: var(--sh-panel);
  border: 1px solid var(--sh-line2);
  border-radius: 11px;
  box-shadow: var(--sh-shadow);
}
.ctx-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 29px;
  padding: 0 9px;
  border: none;
  background: transparent;
  border-radius: 7px;
  cursor: pointer;
  text-align: left;
  font-size: 12px;
}
.ctx-menu button:hover {
  background: rgba(255, 255, 255, 0.09);
}
.ctx-menu button.danger:hover {
  background: rgba(255, 107, 125, 0.18);
  color: #ffc0c8;
}
.ctx-menu hr {
  border: none;
  border-top: 1px solid var(--sh-line);
  margin: 4px 2px;
}
.ctx-menu .k {
  margin-left: auto;
  font-size: 10px;
  color: var(--sh-ink3);
}

/* Toast */
.toast-root {
  position: fixed;
  left: 50%;
  bottom: 44px;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  padding: 9px 15px;
  border-radius: 11px;
  background: rgba(16, 26, 46, 0.95);
  border: 1px solid var(--sh-line2);
  box-shadow: var(--sh-shadow);
  font-size: 12px;
  animation: toastIn 0.2s ease;
  max-width: 70vw;
}
.toast.ok {
  border-color: rgba(43, 227, 164, 0.5);
  color: #c9fff0;
}
.toast.err {
  border-color: rgba(255, 107, 125, 0.5);
  color: #ffc0c8;
}
@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ==================== AI 生成弹层 ==================== */
.ai-flow {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ai-step {
  padding: 12px;
  border: 1px solid var(--sh-line);
  border-radius: 12px;
  background: var(--sh-panel2);
}
.ai-step-h {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
  font-size: 12px;
  color: var(--sh-ink2);
}
.ai-step-h b {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: rgba(43, 227, 164, 0.16);
  border: 1px solid rgba(43, 227, 164, 0.42);
  color: #c9fff0;
  font-size: 11px;
}
.ai-input,
.ai-json {
  width: 100%;
  padding: 9px 11px;
  background: rgba(4, 7, 15, 0.5);
  border: 1px solid var(--sh-line);
  border-radius: 10px;
  outline: none;
  resize: vertical;
  line-height: 1.6;
}
.ai-input:focus,
.ai-json:focus {
  border-color: rgba(43, 227, 164, 0.45);
}
.ai-input {
  min-height: 54px;
  margin-bottom: 8px;
}
.ai-json {
  min-height: 190px;
  font-family: 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
  font-size: 11.5px;
  color: #cfe3ff;
}
.ai-check {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 9px;
  font-size: 12px;
  color: var(--sh-ink2);
  cursor: pointer;
}
.ai-check input {
  accent-color: var(--sh-pri);
}
.ai-promptbox {
  margin-top: 9px;
  max-height: 30vh;
}
.ai-out {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.ai-mini-wrap {
  flex: 0 0 auto;
  width: 132px;
}
.ai-mini {
  position: relative;
  width: 132px;
  border-radius: 12px;
  border: 1px solid var(--sh-line2);
  background: linear-gradient(170deg, #0e1730, #060a14);
  overflow: hidden;
}
.ai-mini i {
  position: absolute;
  display: block;
  border-radius: 2px;
  background: rgba(147, 161, 188, 0.5);
}
.ai-mini i.pri {
  background: rgba(43, 227, 164, 0.55);
}
.ai-mini-meta {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--sh-ink2);
  word-break: break-word;
}
.ai-mini-meta span {
  color: var(--sh-ink3);
}
.ai-report {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 34vh;
  overflow: auto;
}
.ai-line {
  padding: 6px 9px;
  border-left: 2px solid var(--sh-line2);
  border-radius: 0 7px 7px 0;
  background: rgba(255, 255, 255, 0.04);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--sh-ink2);
}
.ai-line.ok {
  border-left-color: var(--sh-pri);
  color: #c9fff0;
}
.ai-line.warn {
  border-left-color: var(--sh-warn);
  color: #ffe0b8;
}
.ai-line.err {
  border-left-color: var(--sh-danger);
  color: #ffc0c8;
}
.ai-line.info {
  border-left-color: var(--sh-blue);
}
