/* =========================================================================
   TextForge 样式 —— 借鉴 Midnight-Green 配色体系
   层次：bg → bg-1(面板) → bg-2(次级面板/步骤) → bg-3(悬停/输入) → bg-4(按压)
   主色：绿色 accent；语义色：orange / blue / purple / red / yellow / cyan
   ========================================================================= */

:root {
  --bg: #0a0e13;
  --bg-1: #0f141b;
  --bg-2: #151b24;
  --bg-3: #1c2430;
  --bg-4: #242e3d;
  --fg: #e2e8f0;
  --fg-2: #94a3b8;
  --fg-3: #64748b;
  --fg-4: #475569;
  --border: rgba(148,163,184,0.08);
  --border-2: rgba(148,163,184,0.15);
  --border-3: rgba(148,163,184,0.25);
  --accent: #84e16c;
  --accent-d: #5fb84a;
  --accent-glow: rgba(132,225,108,0.12);
  --on-accent: #0a0e13;
  --orange: #ff7849;
  --blue: #5eb3ff;
  --purple: #c084fc;
  --red: #ff5470;
  --yellow: #fbbf24;
  --cyan: #22d3ee;
  --header-bg: rgba(15,20,27,0.6);
  --shadow-panel: 0 -8px 32px rgba(0,0,0,0.4);
  --shadow-toast: 0 8px 24px rgba(0,0,0,0.4);

  /* 语义映射 */
  --panel: var(--bg-1);
  --panel-2: var(--bg-2);
  --bg-soft: var(--bg-3);
  --text: var(--fg);
  --text-2: var(--fg-2);
  --text-3: var(--fg-3);
  --success: var(--accent);
  --success-soft: var(--accent-glow);
  --danger: var(--red);
  --danger-soft: color-mix(in srgb, var(--red) 14%, transparent);
  --warn: var(--yellow);
  --warn-soft: color-mix(in srgb, var(--yellow) 14%, transparent);
  --shadow: 0 1px 2px rgba(0,0,0,0.24), 0 8px 24px rgba(0,0,0,0.22);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.5);
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, "Cascadia Code", Consolas, "JetBrains Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* ===== 亮色主题 ===== */
html[data-theme="light"] {
  --bg: #f3f4ef;
  --bg-1: #fbfcfa;
  --bg-2: #edefe8;
  --bg-3: #e2e5db;
  --bg-4: #ccd1c3;
  --fg: #21282e;
  --fg-2: #56616b;
  --fg-3: #87919b;
  --fg-4: #b6bec6;
  --border: rgba(33,40,46,0.10);
  --border-2: rgba(33,40,46,0.18);
  --border-3: rgba(33,40,46,0.32);
  --accent: #2f8f27;
  --accent-d: #257a1e;
  --accent-glow: rgba(47,143,39,0.18);
  --on-accent: #ffffff;
  --orange: #d95a18;
  --blue: #2378cc;
  --purple: #7c4ce0;
  --red: #d92c50;
  --yellow: #c78a04;
  --cyan: #0a8ea8;
  --header-bg: rgba(251,252,250,0.72);
  --shadow-panel: 0 -8px 32px rgba(40,50,30,0.12);
  --shadow-toast: 0 8px 24px rgba(40,50,30,0.14);

  --danger-soft: color-mix(in srgb, var(--red) 12%, transparent);
  --warn-soft: color-mix(in srgb, var(--yellow) 16%, transparent);
  --shadow: 0 1px 2px rgba(40,50,30,0.08), 0 8px 24px rgba(40,50,30,0.10);
  --shadow-lg: 0 12px 40px rgba(40,50,30,0.18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* ============ Lucide 图标通用 ============ */
svg.icon { flex: none; display: inline-block; vertical-align: -2px; }
.icon-btn svg.icon { display: block; }
.icon-spin { animation: iconSpin 0.9s linear infinite; }
@keyframes iconSpin { to { transform: rotate(360deg); } }

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

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body.no-scroll { overflow: hidden; }

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

::selection { background: var(--accent-glow); color: var(--fg); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--bg-4);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--fg-4); background-clip: content-box; border: 2px solid transparent; }
::-webkit-scrollbar-track { background: transparent; }

/* ============ 顶栏（玻璃拟态） ============ */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 14px;
  background: var(--header-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 60;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  color: var(--fg);
  text-decoration: none;
  margin-right: 6px;
  white-space: nowrap;
}

.brand-icon { display: inline-flex; color: var(--accent); }
.brand-icon svg { display: block; }

.brand-name {
  background: linear-gradient(120deg, var(--accent), var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.topbar-spacer { flex: 1; }

.mode-switch {
  display: flex;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.mode-switch button {
  border: none;
  background: transparent;
  color: var(--fg-3);
  padding: 5px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.mode-switch button:hover { color: var(--fg); }

.mode-switch button.active {
  background: var(--bg-1);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  border: 1px solid var(--border-2);
  margin: -1px;
}

.icon-btn {
  border: none;
  background: transparent;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-3);
  text-decoration: none;
  transition: all 0.15s;
  flex: none;
}

.icon-btn:hover { background: var(--bg-3); color: var(--fg); }

.menu-btn { display: none; }

/* ============ 收藏栏 ============ */
.favbar-wrap {
  background: var(--header-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 6px 14px;
  position: sticky;
  top: 52px;
  z-index: 55;
}

.favbar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  align-items: center;
  scrollbar-width: thin;
  min-height: 32px;
}

.favbar::-webkit-scrollbar { height: 5px; }

.fav-label {
  color: var(--fg-3);
  font-size: 12px;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.fav-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  flex: none;
  transition: all 0.15s;
  user-select: none;
}

html[data-theme="light"] .fav-chip { color: var(--accent-d); }

.fav-chip:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.fav-chip .fav-x {
  display: inline-flex;
  width: 15px;
  height: 15px;
  padding: 0;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 11px;
  opacity: 0.55;
  transition: all 0.15s;
}

.fav-chip .fav-x:hover { opacity: 1; background: var(--danger-soft); color: var(--danger); }

.fav-empty { color: var(--fg-3); font-size: 12.5px; }

/* ============ 布局 ============ */
.layout {
  display: flex;
  min-height: calc(100dvh - 52px - 45px);
}

.sidebar {
  width: 264px;
  flex: none;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 97px;
  height: calc(100dvh - 97px);
}

.sidebar-head {
  display: flex;
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-icon { opacity: 0.6; flex: none; }
.search-icon svg { display: block; }

.search-wrap input {
  border: none;
  outline: none;
  background: transparent;
  padding: 7px 0;
  width: 100%;
  font-size: 13px;
  color: var(--fg);
  min-width: 0;
}

.search-wrap input::placeholder { color: var(--fg-4); }

.sidebar-close { display: none; }

.sidebar-scroll { flex: 1; overflow-y: auto; padding: 8px; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 8px 10px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.sidebar-foot .btn { flex: 1; white-space: nowrap; }

/* ---- 侧边栏分组 ---- */
.side-group { margin-bottom: 4px; }

.side-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg);
  cursor: pointer;
  border-radius: var(--radius-sm);
  user-select: none;
  letter-spacing: 0.02em;
}

.side-group-head:hover { background: var(--bg-2); }

.side-group-head .g-name {
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.side-group-head .g-count {
  margin-left: auto;
  background: var(--bg-3);
  border-radius: 999px;
  font-size: 11px;
  padding: 1px 7px;
  color: var(--fg-3);
  font-weight: 500;
}

.side-group-head .g-caret { font-size: 10px; color: var(--fg-4); transition: transform 0.15s; }
.side-group-head .g-caret svg { display: block; }
.side-group.collapsed .g-caret { transform: rotate(-90deg); }
.side-group.collapsed .side-group-list { display: none; }

/* 缩进列表：图标列与分类名对齐；虚线引导线与分类箭头对齐 */
.side-group-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-left: 20px;
  background-image: linear-gradient(180deg, var(--fg) 3px, transparent 3px);
  background-position: 13.5px 0;
  background-size: 1px 6px;
  background-repeat: repeat-y;
}

.proc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: background 0.12s;
  position: relative;
}

.proc-item:hover { background: var(--bg-3); }
.proc-item:active { background: var(--bg-4); }

/* 图标弱化：让名称成为第一视觉，悬停时恢复 */
.proc-icon {
  font-size: 13px;
  flex: none;
  width: 18px;
  text-align: center;
  opacity: 0.25;
  filter: saturate(0.7);
  transition: opacity 0.18s, filter 0.18s;
}

.proc-item:hover .proc-icon { opacity: 1; filter: none; }

.proc-name {
  font-size: 13px;
  color: var(--fg-2);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.12s;
}

.proc-item:hover .proc-name { color: var(--fg); }

.proc-star {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: var(--fg-4);
  opacity: 0;
  padding: 2px;
  border-radius: 5px;
  flex: none;
  transition: all 0.15s;
}

.proc-star svg { display: block; }
.proc-item:hover .proc-star { opacity: 1; }
.proc-star.starred { opacity: 1; color: var(--yellow); }
.proc-star.starred svg { fill: var(--yellow); }
.proc-star:hover { transform: scale(1.2); }

.proc-mini-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  color: var(--fg-3);
  opacity: 0;
  padding: 2px 4px;
  border-radius: 5px;
  flex: none;
}

.proc-item:hover .proc-mini-btn { opacity: 1; }
.proc-mini-btn:hover { color: var(--blue); background: var(--bg-4); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  top: 0;
  background: rgba(4, 6, 9, 0.55);
  z-index: 89;
  backdrop-filter: blur(2px);
}

/* ============ 主区 ============ */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.workbench {
  display: flex;
  gap: 12px;
  padding: 12px;
  flex: 1;
  min-height: 0;
  align-items: stretch;
}

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

.pane.io-pane { flex: 1; }
.chain-pane { width: 340px; flex: none; }

.pane-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  flex: none;
}

.pane-title {
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  color: var(--fg);
}

.pane-title .muted { color: var(--fg-3); font-weight: 400; font-size: 12px; }

.head-actions {
  margin-left: auto;
  display: flex;
  gap: 2px;
  align-items: center;
}

.head-actions .icon-btn { width: 29px; height: 29px; font-size: 14px; }

.io-textarea {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 12px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  background: var(--bg-1);
  color: var(--fg);
  min-height: 180px;
  tab-size: 4;
}

#outputText { background: var(--bg-2); }

.io-textarea::placeholder { color: var(--fg-4); }

.badge {
  background: var(--bg-3);
  color: var(--fg-2);
  font-size: 11px;
  border-radius: 999px;
  padding: 1px 8px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge.gray { background: var(--bg-3); color: var(--fg-3); }
.badge.green { background: var(--accent-glow); color: var(--accent-d); }
.badge.red { background: var(--danger-soft); color: var(--danger); }

/* ---- 统计面板 ---- */
.stats-panel {
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  max-height: 280px;
  overflow-y: auto;
  flex: none;
}

.stats-tabs { display: flex; gap: 4px; padding: 8px 12px 0; }

.stats-tabs button {
  border: 1px solid var(--border);
  background: var(--bg-1);
  border-radius: 999px;
  padding: 2px 12px;
  font-size: 12px;
  color: var(--fg-3);
  cursor: pointer;
  transition: all 0.15s;
}

.stats-tabs button:hover { color: var(--fg); }

.stats-tabs button.active {
  color: var(--accent-d);
  border-color: var(--accent);
  font-weight: 600;
  background: var(--accent-glow);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 6px;
  padding: 10px 12px 6px;
}

.stat-cell {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

.stat-cell .s-val { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--fg); }
.stat-cell .s-key { font-size: 11px; color: var(--fg-3); }

.word-freq { padding: 4px 12px 12px; display: flex; flex-wrap: wrap; gap: 6px; }

.wf-chip {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  color: var(--fg-2);
}

.wf-chip b { color: var(--blue); margin-left: 4px; }

/* ============ 处理链 ============ */
.chain-body { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }

.chain-empty {
  border: 1.5px dashed var(--border-2);
  border-radius: var(--radius);
  color: var(--fg-3);
  font-size: 12.5px;
  text-align: center;
  padding: 26px 14px;
  line-height: 1.9;
}
.chain-empty svg { display: inline-block; color: var(--fg-4); }

.step {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--fg-4);
  border-radius: var(--radius-sm);
  overflow: visible;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.step:hover { border-color: var(--border-2); border-left-color: var(--accent-d); }

.step.selected {
  border-color: var(--accent);
  border-left-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.step.has-error { border-left-color: var(--red); }
.step.has-error .step-no { background: var(--red); }

.step-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  cursor: pointer;
  user-select: none;
}

.step-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  overflow: hidden;
  white-space: nowrap;
}

.step-title .st-name { overflow: hidden; text-overflow: ellipsis; }

.step-no {
  background: var(--accent);
  color: var(--on-accent);
  font-size: 10.5px;
  border-radius: 999px;
  min-width: 17px;
  height: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  font-weight: 700;
}

.step-tools { display: flex; gap: 1px; opacity: 0; transition: opacity 0.15s; }
.step:hover .step-tools, .step.dragging .step-tools { opacity: 1; }

.step-tools button {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--fg-3);
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.step-tools button:hover { background: var(--bg-4); color: var(--fg); }
.step-tools .t-del:hover { color: var(--red); background: var(--danger-soft); }

.step-body { padding: 2px 10px 10px; border-top: 1px dashed var(--border); }
.step.collapsed .step-body { display: none; }

.step-arrow {
  text-align: center;
  color: var(--fg-4);
  line-height: 1;
  user-select: none;
}
.step-arrow svg { display: block; margin: 0 auto; }

.chain-foot {
  border-top: 1px solid var(--border);
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  background: var(--bg-2);
}

.chain-foot .check { font-size: 12.5px; color: var(--fg-2); display: flex; align-items: center; gap: 5px; cursor: pointer; }

.chain-foot .btn { margin-left: auto; }

/* ---- 小型分段切换（处理链：单步/链式） ---- */
.seg {
  display: flex;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.seg button {
  border: none;
  background: transparent;
  color: var(--fg-3);
  padding: 2px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  transition: all 0.15s;
}

.seg button:hover { color: var(--fg); }

.seg button.active {
  background: var(--bg-1);
  color: var(--accent-d);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* ---- 表单字段 ---- */
.field { display: flex; flex-direction: column; gap: 3px; padding: 6px 0 2px; }

.field-label { font-size: 11.5px; color: var(--fg-2); }

.field input[type="text"], .field input[type="number"], .field input[type="password"], .field select, .field textarea {
  border: 1px solid var(--border-2);
  background: var(--bg-1);
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 12.5px;
  outline: none;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
  color: var(--fg);
}

.field textarea { font-family: var(--mono); resize: vertical; min-height: 70px; }

.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.field input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

.field .hint { font-size: 11px; color: var(--fg-3); }

.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.check-line { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--fg-2); cursor: pointer; padding: 4px 0; }
.check-line input { accent-color: var(--accent); width: 14px; height: 14px; }

/* ---- 错误横幅 ---- */
.err-banner {
  background: var(--danger-soft);
  color: var(--danger);
  border-bottom: 1px solid var(--danger);
  font-size: 12px;
  padding: 6px 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ============ 按钮（主次分明） ============ */
.btn {
  border: 1px solid var(--border-2);
  background: var(--bg-3);
  color: var(--fg);
  padding: 7px 14px;
  border-radius: 9px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  white-space: nowrap;
}

.btn:hover { background: var(--bg-4); border-color: var(--border-3); }
.btn:active { transform: translateY(1px); }

/* 主操作：绿底 + 辉光 */
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  box-shadow: 0 2px 14px var(--accent-glow);
}

.btn.primary:hover {
  background: var(--accent-d);
  border-color: var(--accent-d);
  color: var(--on-accent);
  box-shadow: 0 4px 18px var(--accent-glow);
}

/* 亮色：加深主按钮与激活文字，保证对比度 ≥ AA */
html[data-theme="light"] .btn.primary {
  background: var(--accent-d);
  border-color: var(--accent-d);
}

html[data-theme="light"] .btn.primary:hover { filter: brightness(1.08); }

html[data-theme="light"] .mode-switch button.active { color: var(--accent-d); }

/* 次主操作：描边强调 */
.btn.success {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent-d);
  font-weight: 600;
}

.btn.success:hover { background: var(--accent-glow); color: var(--accent-d); }

.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }

.btn.ghost { background: transparent; border-color: transparent; color: var(--fg-2); }
.btn.ghost:hover { background: var(--bg-3); color: var(--fg); border-color: transparent; }

.btn.small { padding: 4px 10px; font-size: 12px; border-radius: 7px; }

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

kbd {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 5px;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--fg-2);
}

/* ============ 批量模式 ============ */
.batch-wrap { padding: 12px; display: flex; flex-direction: column; gap: 12px; flex: 1; }

.batch-grid { display: grid; grid-template-columns: 1fr 340px; gap: 12px; align-items: start; }
.batch-left { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.dropzone {
  border: 2px dashed var(--border-3);
  border-radius: var(--radius);
  background: var(--bg-1);
  padding: 34px 16px;
  text-align: center;
  color: var(--fg-2);
  cursor: pointer;
  transition: all 0.2s;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--accent-d);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

.dz-icon { margin-bottom: 8px; color: var(--fg-3); }
.dz-icon svg { display: block; margin: 0 auto; }

.dropzone .dz-hint { font-size: 12px; color: var(--fg-3); margin-top: 8px; }

.file-list { display: flex; flex-direction: column; gap: 8px; }

.file-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
}

.file-icon { font-size: 20px; flex: none; }

.file-main { flex: 1; min-width: 0; }

.file-name { font-size: 13px; font-weight: 600; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.file-meta { font-size: 11.5px; color: var(--fg-3); display: flex; gap: 10px; flex-wrap: wrap; }

.file-preview-text {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 480px;
}

.file-status { flex: none; }

.file-ops { display: flex; gap: 2px; flex: none; }

.batch-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  position: sticky;
  bottom: 8px;
  z-index: 10;
}

.batch-actions .spacer { flex: 1; }

.batch-summary { font-size: 12px; color: var(--fg-2); }

/* ============ 弹窗 ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 9, 0.55);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(3px);
}

.modal-card {
  background: var(--bg-1);
  border: 1px solid var(--border-2);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: min(560px, 100%);
  max-height: min(86dvh, 780px);
  display: flex;
  flex-direction: column;
  animation: modalIn 0.18s ease;
}

.modal-card.wide { width: min(760px, 100%); }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: center;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 15px; font-weight: 700; flex: 1; color: var(--fg); }

.modal-body { padding: 12px 16px; overflow-y: auto; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  background: var(--bg-2);
}

.list-row .lr-main { flex: 1; min-width: 0; }
.list-row .lr-title { font-size: 13px; font-weight: 600; color: var(--fg); }
.list-row .lr-sub { font-size: 11.5px; color: var(--fg-3); }

/* ============ Toast ============ */
.toast-wrap {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--bg-1);
  color: var(--fg);
  border: 1px solid var(--border-3);
  border-radius: 10px;
  padding: 9px 18px;
  font-size: 13px;
  box-shadow: var(--shadow-toast);
  animation: toastIn 0.2s ease;
  max-width: min(480px, 90vw);
}

.toast.ok { border-color: var(--accent); }
.toast.err { border-color: var(--red); color: var(--danger); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ============ Tooltip（即时悬浮提示） ============ */
.tooltip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 300;
  background: var(--bg-4);
  color: var(--fg);
  border: 1px solid var(--border-3);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  line-height: 1.5;
  max-width: 280px;
  box-shadow: var(--shadow-toast);
  pointer-events: none;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.tooltip.show {
  opacity: 1;
  transform: none;
}

/* ============ 管理后台 ============ */
.admin-root { min-height: 100dvh; background: var(--bg); }

.admin-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: 52px;
  background: var(--header-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.admin-title { font-weight: 700; font-size: 15px; flex: 1; color: var(--fg); display: inline-flex; align-items: center; gap: 8px; }

.admin-tabs { display: flex; gap: 4px; padding: 12px 16px 0; flex-wrap: wrap; }

.admin-tabs button {
  border: 1px solid var(--border);
  background: var(--bg-1);
  padding: 6px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  color: var(--fg-2);
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.admin-tabs button:hover { color: var(--fg); border-color: var(--border-2); }

.admin-tabs button.active {
  color: var(--accent-d);
  border-color: var(--accent);
  font-weight: 600;
  background: var(--accent-glow);
}

.admin-body { padding: 14px 16px 30px; }

.admin-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.admin-card h3 { margin: 0 0 10px; font-size: 14px; color: var(--fg); }

.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  background: var(--bg-1);
  border: 1px solid var(--border-2);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 30px 28px;
  width: min(380px, 100%);
}

.login-card .lc-icon { color: var(--accent); }
.login-card .lc-icon svg { display: block; margin: 0 auto; }

.login-card h2 { text-align: center; margin: 6px 0 4px; font-size: 18px; color: var(--fg); }
.login-card .lc-sub { text-align: center; color: var(--fg-3); font-size: 12.5px; margin-bottom: 18px; }

.table-wrap { overflow-x: auto; }

table.grid-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }

.grid-table th, .grid-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }

.grid-table th { color: var(--fg-3); font-weight: 600; font-size: 12px; white-space: nowrap; }

.grid-table tbody tr { transition: background 0.1s; }
.grid-table tbody tr:hover td { background: var(--bg-2); }
.grid-table tbody tr:last-child td { border-bottom-color: var(--border-2); }

.grid-table td .cell-actions { display: flex; gap: 2px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { min-width: 120px; }

.stat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }

.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}

.stat-card .sc-val { font-size: 26px; font-weight: 800; color: var(--accent-d); font-variant-numeric: tabular-nums; }
.stat-card .sc-key { font-size: 12px; color: var(--fg-2); margin-top: 2px; }

.mono { font-family: var(--mono); font-size: 12px; color: var(--fg-2); }

.filter-bar { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; align-items: center; }

.filter-bar select, .filter-bar input {
  border: 1px solid var(--border-2);
  background: var(--bg-1);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
  color: var(--fg);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.filter-bar input:focus, .filter-bar select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ============ 空状态 / 其他 ============ */
.empty-tip { text-align: center; color: var(--fg-3); font-size: 13px; padding: 26px 0; }

.divider { height: 1px; background: var(--border); margin: 10px 0; }

.muted { color: var(--fg-3); }

.shortcut-list { display: flex; flex-direction: column; gap: 8px; }
.shortcut-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; gap: 20px; color: var(--fg-2); }

/* ============ 响应式 ============ */
@media (max-width: 1180px) {
  .workbench { flex-direction: column; }
  .chain-pane { width: 100%; }
  .io-textarea { min-height: 160px; }
  .batch-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .menu-btn { display: inline-flex; }
  .brand-name { display: none; }
  .topbar { padding: 0 8px; gap: 4px; }
  .mode-switch button { padding: 5px 8px; font-size: 12.5px; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100dvh;
    z-index: 95;
    width: min(300px, 86vw);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-lg);
    background: var(--bg-1);
  }

  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .sidebar-close { display: inline-flex; }

  .sidebar-scroll { padding-bottom: 20px; }

  .workbench { padding: 8px; gap: 8px; }
  .batch-wrap { padding: 8px; }

  .batch-actions { position: static; flex-wrap: wrap; }
  .batch-actions .btn { flex: 1; min-width: 120px; }

  .file-card { flex-wrap: wrap; }
  .file-ops { margin-left: auto; }

  .modal-card { width: 100%; border-radius: 14px; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-card { max-height: 92dvh; border-radius: 14px 14px 0 0; }

  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(95px, 1fr)); }
}

@media (max-width: 480px) {
  .favbar-wrap { top: 52px; }
  .io-textarea { font-size: 12.5px; min-height: 140px; }
  .admin-body { padding: 10px 8px 24px; }
  .admin-tabs { padding: 8px 8px 0; }
}

/* ============ v2 新增组件 ============ */

/* 字号（A-/A+ 调节） */
:root { --tf-fs: 13px; }
.io-textarea { font-size: var(--tf-fs); }

/* 编辑器行号 */
.editor-wrap { position: relative; flex: 1; display: flex; min-height: 0; overflow: hidden; }
.editor-wrap .gutter {
  flex: none;
  width: 44px;
  overflow: hidden;
  padding: 12px 8px 12px 0;
  text-align: right;
  font-family: var(--mono);
  font-size: calc(var(--tf-fs) - 1px);
  line-height: 1.6;
  color: var(--fg-4);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  user-select: none;
  scrollbar-width: none;
}
.editor-wrap .gutter::-webkit-scrollbar { display: none; }
.editor-wrap .gutter div { white-space: pre; }
.editor-wrap .io-textarea { min-height: 0; }

/* 语法高亮视图 */
.code-view {
  flex: 1;
  margin: 0;
  padding: 12px;
  overflow: auto;
  font-family: var(--mono);
  font-size: var(--tf-fs);
  line-height: 1.6;
  background: var(--bg-2);
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-all;
  tab-size: 2;
}
.tok-key { color: var(--cyan); }
.tok-str { color: var(--accent-d); }
html[data-theme="dark"] .tok-str { color: var(--accent); }
.tok-num { color: var(--orange); }
.tok-kw { color: var(--purple); }
.tok-com { color: var(--fg-3); font-style: italic; }

/* Diff 视图 */
.diff-view { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.diff-legend { display: flex; gap: 6px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--border); background: var(--bg-2); flex: none; }
.diff-legend .chip { font-size: 11px; border-radius: 999px; padding: 1px 8px; font-weight: 700; }
.diff-legend .chip.add { background: var(--accent-glow); color: var(--accent-d); }
.diff-legend .chip.del { background: var(--danger-soft); color: var(--danger); }
.diff-rows { flex: 1; overflow: auto; font-family: var(--mono); font-size: calc(var(--tf-fs) - 1px); line-height: 1.6; padding: 6px 0; }
.diff-row { display: flex; gap: 8px; padding: 0 10px; white-space: pre-wrap; word-break: break-all; }
.diff-row .dl-no { flex: none; width: 36px; text-align: right; color: var(--fg-4); user-select: none; }
.diff-row .dl-txt { flex: 1; min-width: 0; color: var(--fg-2); }
.diff-row.del { background: var(--danger-soft); }
.diff-row.del .dl-txt { color: var(--danger); }
.diff-row.add { background: var(--accent-glow); }
.diff-row.add .dl-txt { color: var(--accent-d); }
html[data-theme="dark"] .diff-row.add .dl-txt { color: var(--accent); }
.diff-row .dl-txt b { background: color-mix(in srgb, currentColor 26%, transparent); border-radius: 3px; font-weight: 700; }
.diff-row.empty .dl-txt { opacity: 0.4; }

/* 步骤旁路 */
.step.skipped { opacity: 0.45; border-left-color: var(--border-3); border-style: dashed; }
.step.skipped .step-no { background: var(--fg-4); }
.step-tools .t-skip-on { color: var(--warn); background: var(--warn-soft); }

/* Lucide 处理器图标 */
.proc-icon-svg { width: 18px; flex: none; display: inline-flex; justify-content: center; }
.proc-icon-svg svg { display: block; opacity: 0.5; }
.proc-item:hover .proc-icon-svg svg, .step-title .proc-icon-svg svg, .fav-chip .proc-icon-svg svg { opacity: 1; }

/* 统计可视化 */
.stats-viz { padding: 6px 12px 4px; }
.viz-label { font-size: 11px; color: var(--fg-3); margin-bottom: 5px; }
.stack-bar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: var(--bg-3); }
.stack-seg { height: 100%; min-width: 2px; }
.viz-legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--fg-3); margin-top: 5px; }
.viz-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }
.bar-chart { display: flex; align-items: flex-end; gap: 3px; height: 46px; padding: 0 2px; }
.bar-chart .bar { flex: 1; min-width: 4px; max-width: 22px; background: color-mix(in srgb, var(--accent) 55%, var(--bg-3)); border-radius: 3px 3px 0 0; cursor: default; }
.wf-bars { display: flex; flex-direction: column; gap: 3px; max-width: 480px; }
.wf-row { display: flex; align-items: center; gap: 8px; font-size: 11.5px; }
.wf-word { flex: none; width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg-2); text-align: right; }
.wf-track { flex: 1; height: 10px; background: var(--bg-3); border-radius: 6px; overflow: hidden; }
.wf-fill { display: block; height: 100%; background: var(--accent-d); border-radius: 6px; }
html[data-theme="dark"] .wf-fill { background: var(--accent); }
.wf-count { flex: none; width: 36px; color: var(--fg-3); font-variant-numeric: tabular-nums; }

/* 对比模式 */
.compare-wrap { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: stretch; }
.cmp-actions { display: flex; flex-direction: column; gap: 10px; justify-content: center; width: 130px; }
.cmp-result { grid-column: 1 / -1; min-height: 220px; display: flex; }
.cmp-result .pane { flex: 1; }
@media (max-width: 1180px) {
  .compare-wrap { grid-template-columns: 1fr; }
  .cmp-actions { width: 100%; flex-direction: row; align-items: center; }
  .cmp-result { grid-column: auto; }
}

/* 小型分段切换（输出视图）与超小按钮 */
.seg.seg-xs { padding: 2px; }
.seg.seg-xs button { padding: 1px 8px; font-size: 11.5px; }
.icon-btn.icon-btn-xs { width: 26px; height: 26px; }

/* 批量：下拉与编码选择 */
.tf-select, .enc-select {
  border: 1px solid var(--border-2);
  background: var(--bg-1);
  color: var(--fg);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  outline: none;
}
.enc-select { padding: 1px 4px; font-size: 11px; border-radius: 6px; }
.enc-select:focus { border-color: var(--accent); }

/* 图标选择器网格 */
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; max-height: 340px; overflow-y: auto; }
.icon-cell {
  border: 1px solid var(--border);
  background: var(--bg-2);
  border-radius: 8px;
  height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--fg-2);
  cursor: pointer;
  transition: all 0.12s;
}
.icon-cell:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-glow); }

/* 管理表格拖拽 */
.drag-td { width: 30px; }
.drag-handle { cursor: grab; color: var(--fg-4); display: inline-flex; }
.drag-handle:active { cursor: grabbing; }
.grid-table tr.dragging { opacity: 0.5; }
.grid-table tr.dragging td { background: var(--accent-glow) !important; }

/* 收藏拖动 */
.fav-chip.dragging { z-index: 50; box-shadow: 0 4px 16px rgba(0,0,0,0.35); border-color: var(--accent); cursor: grabbing; }
.favbar.drag-mode .fav-chip { user-select: none; }

/* ============ 小屏"更多"面板 ============ */
.more-panel {
  position: fixed;
  top: 56px;
  right: 8px;
  z-index: 90;
  background: var(--panel);
  border: 1px solid var(--border-2);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  min-width: 208px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: modalIn 0.14s ease;
}

.more-row { display: flex; }

.more-row .icon-btn {
  width: 100%;
  min-height: 40px;
  justify-content: flex-start;
  gap: 12px;
  padding: 0 14px;
  border-radius: 8px;
  font-size: 16px;
}

.more-row .icon-btn svg.icon { display: block; flex: none; }
.more-row .icon-btn:hover { background: var(--bg-3); }
.more-label { flex: 1; text-align: left; font-size: 13px; color: var(--fg-2); }
.more-row .icon-btn:hover .more-label { color: var(--fg); }
