/* 灵鼠 · 网页控制台样式
   设计方向：Cursor/VS Code 中性灰 + 靛蓝品牌色（只用于主操作/品牌/选中）。
   分区规则（docs/UI_GUIDELINES.md）：仅左右两条竖向分区线，其余靠表面色阶；
   组件圆角 6-9px，浮层 9-13px；无多余直线。
   方法论：~/.zcode/skills/frontend-design（两遍工作法）。 */

/* ---------- Design tokens：浅色（默认） ---------- */
:root {
  --panel: #f8f8f8;           /* 铬区（Cursor Light 侧栏色） */
  --panel-2: #ececec;         /* 悬停底 */
  --inset: #ffffff;           /* 输入框底 */
  --c-bg: #ffffff;            /* 内容井：编辑器 + 运行日志 */
  --border: #e5e5e5;          /* 主分区线：只用于大区域之间（Cursor 式） */
  --text: #333333;
  --text-dim: #6f6f6f;
  --text-faint: #9a9a9a;
  --accent: #4338ca;          /* 品牌靛蓝（文本用） */
  --accent-fill: #4f46e5;     /* 品牌靛蓝（按钮底，白字 AA） */
  --accent-strong: #4f46e5;
  --accent-soft: #eef2ff;     /* 补全/提示选中底色 */
  --ok: #1a7f37;
  --ok-strong: #2da44e;
  --danger: #cf222e;
  --danger-strong: #e5534b;
  --warn: #9a6700;
  --sel: rgba(79, 70, 229, .24);
  --shadow: 0 6px 20px rgba(90, 96, 112, .22);
  --edge: #d0d0d0;            /* 仅输入框/浮层使用 */
  --btn-bg: #ffffff; --btn-bg-hover: #f0f0f0; --btn-bg-active: #e8e8e8;
  --btn-edge: #d0d0d0; --btn-edge-hover: #bdbdbd;
  --danger-soft: #f0c6c9;
  /* 代码高亮：API 命令是主角（琥珀加粗） */
  --c-text: #383a42;
  --c-gutter: #9aa0ac;
  --c-kw: #a626a4;
  --c-str: #50a14f;
  --c-com: #7d838f;
  --c-num: #c18401;
  --c-api: #a16207;
  --c-fn: #4078f2;
  --c-bi: #0184bc;
}

/* ---------- Design tokens：深色 ---------- */
:root[data-theme="dark"] {
  --panel: #181818;           /* 铬区（Cursor Dark 侧栏色） */
  --panel-2: #212121;         /* 悬停底 */
  --inset: #212121;           /* 输入框底 */
  --c-bg: #1e1e1e;            /* 编辑器/日志（VSCode Dark+ 编辑区色） */
  --border: #2a2a2a;          /* 主分区线 */
  --text: #cccccc;
  --text-dim: #9d9d9d;
  --text-faint: #6e6e6e;
  --accent: #a5b4fc;
  --accent-fill: #4f46e5;
  --accent-strong: #818cf8;
  --accent-soft: #2e3350;
  --ok: #3fb950;
  --ok-strong: #4dce69;
  --danger: #f85149;
  --danger-strong: #ff6e66;
  --warn: #d29922;
  --sel: rgba(99, 102, 241, .40);
  --shadow: 0 8px 24px rgba(0, 0, 0, .5);
  --edge: #3a3a3a;
  --btn-bg: #262626; --btn-bg-hover: #303030; --btn-bg-active: #383838;
  --btn-edge: #3a3a3a; --btn-edge-hover: #4a4a4a;
  --danger-soft: #6e3538;
  --c-text: #dcdfe8;
  --c-gutter: #4c515f;
  --c-kw: #c678dd;
  --c-str: #98c379;
  --c-com: #767c8a;
  --c-num: #d19a66;
  --c-api: #f5b94e;
  --c-fn: #61afef;
  --c-bi: #56b6c2;
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  background: var(--panel); color: var(--text);
  font: 13px/1.5 -apple-system, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", sans-serif;
  overflow: hidden;
}
.muted { color: var(--text-faint); font-size: 12px; }
.grow { flex: 1; min-width: 0; }
.mono, #st-mouse, #st-screen {
  font-family: Menlo, "SF Mono", Consolas, "PingFang SC", monospace;
  font-variant-numeric: tabular-nums;
}

/* ---------- 按钮（GitHub Primer 范式）：次级=软填充+细描边，主操作=琥珀实底 ----------
   组件轮廓≠结构线：结构分区禁止描边，按钮形状必须一眼可辨 */
button {
  background: var(--btn-bg); color: var(--text-dim);
  border: 1px solid var(--btn-edge);
  border-radius: 7px; padding: 3px 11px; min-height: 26px;
  cursor: pointer; font-size: 12.5px; line-height: 1.2;
  white-space: nowrap; flex: 0 0 auto;
  transition: background-color .12s, border-color .12s, color .12s;
}
button:hover { background: var(--btn-bg-hover); color: var(--text); border-color: var(--btn-edge-hover); }
button:active { background: var(--btn-bg-active); }
button:disabled { color: var(--text-faint); background: var(--btn-bg); border-color: var(--btn-edge); opacity: .6; cursor: default; }
button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent-strong); outline-offset: 1px;
}
/* 主操作 = 运行 / 连接 / 模态确认：全站唯一实底 */
button.success { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; font-weight: 600; }
button.success:hover { background: #4338ca; border-color: #4338ca; color: #fff; }
button.success:disabled { background: var(--btn-bg); border-color: var(--btn-edge); color: var(--text-faint); opacity: .6; }
button.danger { color: var(--danger-strong); border-color: var(--danger-soft); font-weight: 600; }
button.danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger:disabled { color: var(--text-faint); border-color: var(--btn-edge); background: var(--btn-bg); opacity: .6; }
button.ghost { background: transparent; border-color: transparent; color: var(--text-faint); }
button.ghost:hover { background: var(--panel-2); border-color: transparent; color: var(--text); }
#btn-theme { min-width: 32px; padding: 4px 7px; }

/* ---------- 工具栏（无底线，靠色阶） ---------- */
#toolbar {
  display: flex; align-items: center; gap: 4px; flex-wrap: nowrap;
  background: var(--panel);
  padding: 6px 10px;
  overflow-x: auto; scrollbar-width: none;  /* 窄窗口横向滚动，绝不挤压按钮换行 */
}
#toolbar::-webkit-scrollbar { display: none; }
#toolbar [hidden] { display: none !important; }
/* 品牌 lockup：琥珀牌上的光标点 */
.brand {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 700; margin-right: 10px; white-space: nowrap;
}
.brand::before {
  content: "";
  width: 20px; height: 20px; border-radius: 6px;
  background:
    radial-gradient(circle 3.5px at 62% 64%, rgba(255, 255, 255, .95) 98%, transparent 100%),
    var(--accent-fill);
}
/* 分组用空隙而不是分隔线 */
.gap { width: 14px; flex: 0 0 auto; }
#script-name {
  min-width: 0; max-width: 260px; overflow: hidden; white-space: nowrap;
  text-overflow: ellipsis; text-align: right;
}

/* ---------- 主体：三区靠色阶，无边框 ---------- */
#main { flex: 1; display: flex; min-height: 0; }
aside { background: var(--panel); }
#left { width: 200px; display: flex; flex-direction: column; padding: 8px; gap: 6px; border-right: 1px solid var(--border); }
#right { width: 296px; display: flex; flex-direction: column; border-left: 1px solid var(--border); }
#center { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--c-bg); }
.panel-title {
  color: var(--text-faint); font-size: 12px; font-weight: 600;
  margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center;
  white-space: nowrap;
}
/* 面板标题行内嵌小按钮（Cursor 文件区的新建） */
.panel-title button { min-height: 22px; padding: 1px 8px; font-size: 12px; }

/* ---------- 脚本列表 ---------- */
#script-list { flex: 1; margin: 0; padding: 0 4px; list-style: none; overflow-y: auto; }
#script-list li {
  display: flex; align-items: center; gap: 4px;
  padding: 2px 4px 2px 8px; border-radius: 6px; cursor: pointer; color: var(--text-dim); font-size: 13px;
  transition: background-color .12s, color .12s;
}
#script-list li:hover { background: var(--panel-2); color: var(--text); }
#script-list li.active { background: var(--btn-bg); color: var(--text); }
#script-list li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#script-list li .hk { color: var(--text-faint); font-size: 11px; font-family: Menlo, "SF Mono", Consolas, monospace; }
/* 行内图标按钮：静默常驻，悬停浮起；删除悬停转警示色 */
.icon-btn {
  flex: 0 0 auto; width: 22px; height: 22px; min-height: 22px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border-color: transparent; border-radius: 5px;
  color: var(--text-faint);
}
.icon-btn:hover { background: transparent; border-color: transparent; color: var(--text); }
.icon-btn.del:hover { color: var(--danger-strong); }
.icon-btn svg { width: 13px; height: 13px; fill: currentColor; }
/* 左栏脚注（ZCode 式底部锚定）：列表短时把空区留给中间，信息沉底 */
#left-foot {
  margin-top: auto; padding-top: 10px;
  color: var(--text-dim); font-size: 12px; line-height: 1.8; white-space: nowrap;
}
#lf-mode { color: var(--text-dim); }
#lf-mode.on { color: var(--ok); }
/* 编辑器空态水印（VSCode watermark）：代码少时的视觉锚点，堆叠式快捷键提示 */
#watermark {
  position: absolute; left: 14px; z-index: 1;
  color: var(--text-faint); opacity: .55;
  font: 12px/2.1 Menlo, "SF Mono", Consolas, "PingFang SC", monospace;
  pointer-events: none; white-space: nowrap;
}

/* ---------- 编辑器标题栏（铬区色，无底线） ---------- */
#editor-title {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel);
  padding: 5px 12px; font-size: 12px; color: var(--text-dim);
  white-space: nowrap;
}
#st-pos { font-size: 11px; color: var(--text-faint); }
#ed-name { font-weight: 600; color: var(--text); }
#ed-name.dirty::after {
  content: "●"; color: var(--warn); font-size: 9px; margin-left: 5px;
  vertical-align: 2px;
}

/* ---------- 编辑器：内容井最深处 ---------- */
#editor-wrap { flex: 1 1 auto; position: relative; display: flex; min-height: 200px; background: var(--c-bg); }
#gutter {
  width: 38px; padding: 10px 8px 10px 0; text-align: right; overflow: hidden;
  color: var(--c-gutter); background: var(--c-bg); user-select: none; white-space: pre;
  font-family: Menlo, "SF Mono", Consolas, "PingFang SC", monospace;
  font-size: 12px;
  line-height: 20.8px; /* 必须与 #editor 的 13px×1.6 严格一致，行号才能对齐 */
}
#editor-scroll { flex: 1; position: relative; overflow: hidden; }
#hl, #editor {
  margin: 0; padding: 10px 14px;
  font: 13px/1.6 Menlo, "SF Mono", Consolas, "PingFang SC", monospace;
  white-space: pre; overflow: auto; tab-size: 4;
}
#hl { position: absolute; inset: 0; pointer-events: none; color: var(--c-text); }
#hl code { font: inherit; }
#editor {
  position: absolute; inset: 0; width: 100%; height: 100%;
  background: transparent; color: transparent; caret-color: var(--accent-strong);
  border: none; resize: none;
}
/* 编辑器不用浏览器默认焦点环（黑框）：琥珀光标就是焦点指示 */
#editor:focus, #editor:focus-visible { outline: none; }
#editor::selection { background: var(--sel); }
.tok-kw { color: var(--c-kw); } .tok-str { color: var(--c-str); }
.tok-com { color: var(--c-com); font-style: italic; }
.tok-num { color: var(--c-num); } .tok-api { color: var(--c-api); font-weight: 700; }
.tok-fn { color: var(--c-fn); } .tok-bi { color: var(--c-bi); }

/* ---------- 浮层：描边与阴影只属于这里 ---------- */
#findbar {
  position: absolute; top: 8px; right: 14px; display: flex; gap: 6px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--edge);
  border-radius: 9px; padding: 5px 8px; z-index: 5; box-shadow: var(--shadow);
}
#findbar input { width: 240px; background: var(--c-bg); border: none; border-radius: 7px; padding: 4px 8px; color: var(--text); }
#calltip {
  position: absolute; z-index: 6; max-width: 420px;
  background: var(--panel-2); border: 1px solid var(--edge); border-radius: 9px;
  padding: 6px 10px; font-size: 12px; color: var(--text); pointer-events: none;
  white-space: pre-wrap; box-shadow: var(--shadow);
}
#ac-popup {
  position: absolute; z-index: 7; min-width: 200px; max-height: 220px; overflow-y: auto;
  background: var(--panel-2); border: 1px solid var(--edge); border-radius: 9px;
  padding: 2px; display: none; box-shadow: var(--shadow);
}
#ac-popup .item { padding: 4px 10px; border-radius: 4px; cursor: pointer; white-space: nowrap; }
#ac-popup .item.active { background: var(--accent-soft); }

/* ---------- 运行日志：同一口内容井 ---------- */
/* 日志高度跟随内容、封顶滚动（IDE 终端行为）：几行就多高，跑起来才长高，
   绝不把空区摊给日志井——编辑器才是主角 */
#console-panel { flex: 0 0 auto; display: flex; flex-direction: column; background: var(--c-bg); }
#console-head {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel);
  padding: 3px 10px 3px 12px;
  color: var(--text-dim); font-size: 12px; font-weight: 600; white-space: nowrap;
}
#console-head button { min-height: 22px; padding: 1px 8px; font-size: 12px; }
#st-mouse { color: var(--text-faint); font-weight: 400; font-size: 11px; }
body.log-collapsed #console { display: none; }
#console { overflow-y: auto; max-height: 38vh; padding: 4px 14px 8px; font: 12px/1.7 Menlo, "SF Mono", Consolas, "PingFang SC", monospace; }
#console .line { white-space: pre-wrap; word-break: break-all; }
#console .time { color: var(--text-faint); margin-right: 6px; font-variant-numeric: tabular-nums; }
.lv-info { color: var(--c-text); } .lv-ok { color: var(--ok); }
.lv-warn { color: var(--warn); } .lv-error { color: var(--danger-strong); }
.lv-head { color: var(--accent); } .lv-muted { color: var(--text-faint); }

/* ---------- 右侧面板 ---------- */
.tabs { display: flex; gap: 4px; padding: 10px 10px 6px; background: var(--panel); }
/* 分段控件（Cursor 设置页样式）：激活=内容底色浮起，无下划线 */
.tab {
  flex: 1 1 0; background: transparent; border: none;
  padding: 3px 8px; min-height: 26px; border-radius: 6px;
  color: var(--text-dim); font-size: 12px;
}
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.active { background: var(--c-bg); color: var(--text); font-weight: 600; box-shadow: inset 0 0 0 1px var(--border); }
#tab-docs, #tab-assets { flex: 1; overflow-y: auto; padding: 12px; }
#doc-search {
  width: 100%; margin-bottom: 8px; background: var(--inset);
  border: 1px solid var(--edge); border-radius: 7px; padding: 6px 10px; color: var(--text);
}
details { margin-bottom: 4px; }
summary { cursor: pointer; font-weight: 600; color: var(--text-dim); padding: 5px 4px; border-radius: 4px; }
summary:hover { background: var(--panel-2); color: var(--text); }
.doc-item { padding: 4px 8px 4px 16px; border-radius: 4px; cursor: pointer; color: var(--text-dim); font-size: 12.5px; }
.doc-item:hover { background: var(--panel-2); color: var(--text); }
#asset-images { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
#asset-images img { width: 100%; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--edge); cursor: pointer; background: var(--panel-2); }
#asset-images img:hover { border-color: var(--accent-strong); }
#asset-colors { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 30px; height: 30px; border-radius: 15px; border: 2px solid var(--edge); cursor: pointer; }

/* ---------- 状态灯（日志标题行内） ---------- */
#st-state {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 600; color: var(--text-dim); white-space: nowrap;
  font-size: 11px;
}
#st-state::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint);
}
#st-state.run { color: var(--ok); } #st-state.run::before { background: var(--ok); animation: breathe 1.6s ease-in-out infinite; }
#st-state.rec { color: var(--danger-strong); } #st-state.rec::before { background: var(--danger-strong); animation: breathe .9s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) {
  #st-state.run::before, #st-state.rec::before { animation: none; }
}

/* ---------- 弹窗 ---------- */
/* 显式 display 的元素（flex 等）会让 hidden 属性失效，空层会整页拦截点击，必须压回 none */
#modal[hidden], #findbar[hidden], #calltip[hidden] { display: none !important; }
#modal {
  position: fixed; inset: 0; background: rgba(20, 21, 25, .4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  backdrop-filter: blur(2px);
}
#modal-card {
  background: var(--panel-2); border: 1px solid var(--edge);
  border-radius: 13px; min-width: 380px; max-width: 520px; padding: 18px;
  box-shadow: var(--shadow);
}
#modal-title { font-weight: 700; font-size: 15px; margin-bottom: 10px; }
#modal-body { white-space: pre-wrap; color: var(--text-dim); max-height: 50vh; overflow-y: auto; }
#modal-actions { margin-top: 14px; display: flex; gap: 8px; justify-content: flex-end; }
.modal-input {
  width: 100%; margin-top: 8px; background: var(--inset);
  border: 1px solid var(--edge); border-radius: 7px;
  padding: 7px 10px; color: var(--text); font: inherit;
}
.modal-input:focus { outline: 2px solid var(--accent-strong); outline-offset: -1px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--panel-2); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
::-webkit-scrollbar-corner { background: transparent; }
