/* ============================================================
   云网页 CloudPage · IDE 工作台样式（文件树 / 预览 / AI 面板）
   依赖 theme.css 的 CSS 变量
   ============================================================ */

/* ---------------- 登录 / 注册视图 ---------------- */
#auth-view {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--canvas);
  background-image:
    linear-gradient(rgba(0,0,0,.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,.028) 1px, transparent 1px);
  background-size: 30px 30px;
}
.auth-card {
  width: 380px; padding: 32px 28px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-3);
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-brand .mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--o), #ff9a3d);
  display: grid; place-items: center; color: #fff; font-weight: 800;
  box-shadow: 0 3px 10px rgba(255,105,0,.32);
}
.auth-brand b { font-size: 17px; }
.auth-brand small { display: block; color: var(--e); font-size: 11px; letter-spacing: .4px; }
.auth-tabs { display: flex; gap: 4px; background: var(--b); padding: 3px; border-radius: var(--r-md); margin-bottom: 20px; }
.auth-tab { flex: 1; height: 32px; border-radius: var(--r-sm); font-size: 13px; font-weight: 600; color: var(--f); }
.auth-tab.on { background: var(--w); color: var(--o); box-shadow: var(--sh-1); }
.auth-field { margin-bottom: 14px; }
.auth-field label { display: block; font-size: 12px; color: var(--f); margin-bottom: 6px; }
.auth-field input {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--w); font-size: 13px; transition: border-color var(--dur) var(--ease);
}
.auth-field input:focus { border-color: var(--o); box-shadow: 0 0 0 3px var(--o-soft); }
.auth-submit { width: 100%; height: 40px; margin-top: 6px; font-size: 14px; font-weight: 600; }

/* ---------------- 应用骨架 ---------------- */
.ide-app { display: grid; grid-template-rows: var(--topbar-h) 1fr; height: 100vh; overflow: hidden; }
.ide-topbar {
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 30;
}
.ide-body { display: grid; grid-template-columns: 264px 1fr 340px; min-height: 0; overflow: hidden; }
.ide-body.no-chat { grid-template-columns: 264px 1fr 0; }
.ide-body.no-chat .chat-panel { display: none; }

/* AI 面板最大化：让出中间预览区，AI 对话占据主区域；左侧文件树/历史对话保留 */
.ide-body.chat-max { grid-template-columns: 264px 1fr; }
.ide-body.chat-max .center-panel { display: none; }
.ide-body.chat-max .chat-panel { border-left: none; }
.ide-body.chat-max .chat-todo { display: flex; }

/* ---------------- 左：文件树 ---------------- */
.tree-panel {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-right: 1px solid var(--line);
}
.tree-head {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.tree-head b { font-size: 12.5px; }
.tree-head .spacer { flex: 1; }
.tree-head button {
  width: 26px; height: 26px; border-radius: var(--r-sm);
  display: grid; place-items: center; color: var(--f);
  font-size: 15px; line-height: 1;
  transition: all var(--dur) var(--ease);
}
.tree-head button:hover { background: var(--b); color: var(--o); }
.proj-list { border-bottom: 1px solid var(--line); max-height: 34%; overflow-y: auto; padding: 6px; }
.proj-item {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 9px; border-radius: var(--r-sm); cursor: pointer;
  font-size: 12.5px; color: var(--g); transition: background var(--dur) var(--ease);
}
.proj-item:hover { background: var(--a); }
.proj-item.on { background: var(--o-soft); color: var(--o); font-weight: 600; }
.proj-item .proj-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-item .proj-meta { font-size: 10.5px; color: var(--e); font-variant-numeric: tabular-nums; }
.proj-item .proj-del {
  width: 18px; height: 18px; border-radius: 4px; color: var(--e);
  opacity: 0; font-size: 14px; line-height: 1; transition: all var(--dur) var(--ease);
}
.proj-item:hover .proj-del { opacity: 1; }
.proj-item .proj-del:hover { background: var(--red-soft); color: var(--red); }
.file-tree { flex: 1; overflow: auto; padding: 6px 0; min-height: 0; }
.tree-row {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 8px; font-size: 12.5px; color: var(--g);
  cursor: pointer; border-radius: 4px; margin: 0 4px;
  transition: background var(--dur) var(--ease);
}
.tree-row:hover { background: var(--a); }
.tree-row .tw { width: 10px; color: var(--e); font-size: 10px; }
.tree-row .ti { display: inline-flex; color: var(--f); }
.tree-row.dir .ti { color: var(--o); }
.tree-row .tn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .tact { display: none; gap: 2px; }
.tree-row:hover .tact { display: inline-flex; }
.tree-row .tact button {
  width: 20px; height: 20px; border-radius: 4px; color: var(--e);
  font-size: 12px; line-height: 1;
}
.tree-row .tact button:hover { background: var(--b); color: var(--h); }
.tree-empty, .chat-hint { padding: 14px 12px; font-size: 12px; color: var(--e); line-height: 1.7; }
.chat-hint.small { padding: 8px 10px; font-size: 11.5px; }

/* 左侧侧边栏 · 历史对话 */
.side-conv {
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0; max-height: 42%;
}
.side-conv-head {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 12px; border-bottom: 1px solid var(--line-2);
}
.side-conv-head b { font-size: 12.5px; }
.side-conv-head .spacer { flex: 1; }
.side-conv-head button {
  width: 26px; height: 26px; border-radius: var(--r-sm);
  display: grid; place-items: center; color: var(--f);
  font-size: 14px; line-height: 1; transition: all var(--dur) var(--ease);
}
.side-conv-head button:hover { background: var(--b); color: var(--o); }

/* ---------------- 中：预览 / 代码 ---------------- */
.center-panel { display: flex; flex-direction: column; min-height: 0; background: var(--canvas); }
.center-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.center-tabs { display: flex; gap: 3px; background: var(--b); padding: 3px; border-radius: var(--r-sm); }
.center-tabs button { height: 26px; padding: 0 14px; border-radius: 5px; font-size: 12.5px; font-weight: 600; color: var(--f); }
.center-tabs button.on { background: var(--w); color: var(--o); box-shadow: var(--sh-1); }
.center-head .path { font-size: 11.5px; color: var(--e); font-family: var(--mono); margin-left: 4px; }
.center-body { flex: 1; min-height: 0; position: relative; }
.pane { position: absolute; inset: 0; display: flex; flex-direction: column; min-height: 0; }
.pane[hidden] { display: none; }
#preview-frame { flex: 1; width: 100%; border: none; background: #fff; }

/* 代码编辑器：pre 着色 + textarea 输入，两层排版一致 */
.code-tool { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--panel-2); border-bottom: 1px solid var(--line); font-size: 12px; color: var(--f); }
.code-tool #ed-file { font-family: var(--mono); color: var(--h); }
.code-tool .spacer { flex: 1; }
.code-tool #ed-count { font-size: 11px; color: var(--e); font-variant-numeric: tabular-nums; }
.code-tool .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.code-tool .dot.dirty { background: var(--yellow); }
.ed-wrap { flex: 1; display: flex; min-height: 0; background: #fbfbfc; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }
.ed-gutter {
  width: 44px; flex: none; overflow: hidden; text-align: right;
  padding: 10px 8px 40px 0; color: var(--e); background: var(--panel-2);
  border-right: 1px solid var(--line-2); user-select: none;
}
.ed-code { position: relative; flex: 1; min-width: 0; overflow: auto; }
.ed-hl, .ed-in {
  margin: 0; padding: 10px 14px 40px; border: 0; font: inherit;
  white-space: pre; tab-size: 2; min-height: 100%;
}
.ed-hl { position: absolute; top: 0; left: 0; right: 0; pointer-events: none; color: var(--h); }
.ed-in {
  position: relative; width: 100%; min-height: 100%;
  background: transparent; color: transparent; caret-color: var(--h);
  resize: none; display: block; overflow: hidden;
}
.ed-wrap.no-hl .ed-in { color: var(--h); }
.ed-wrap.no-hl .ed-hl { display: none; }
.t-cm { color: #9aa0a6; font-style: italic; }
.t-str { color: #1a7f37; }
.t-num { color: #b45309; }
.t-kw { color: #8250df; font-weight: 600; }
.t-tag { color: #0550ae; }
.t-el { color: #c2410c; }

/* ---------------- 右：AI 面板 ---------------- */
.chat-panel { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 1px solid var(--line); }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.chat-head b { font-size: 12.5px; }
.chat-head .spacer { flex: 1; }
.chat-model-row { padding: 8px 12px; border-bottom: 1px solid var(--line-2); }
.chat-model-row select {
  width: 100%; height: 32px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--w); font-size: 12.5px;
}
.chat-model-row .hint { font-size: 11px; color: var(--e); margin-top: 5px; }
.chat-convs { flex: 1; min-height: 0; overflow-y: auto; padding: 6px; }
.conv-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; border-radius: var(--r-sm); cursor: pointer; font-size: 12px; color: var(--g);
}
.conv-item:hover { background: var(--a); }
.conv-item.on { background: var(--o-soft); color: var(--o); }
.conv-item .conv-t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .conv-del { width: 18px; height: 18px; border-radius: 4px; color: var(--e); opacity: 0; font-size: 13px; }
.conv-item:hover .conv-del { opacity: 1; }
.conv-item .conv-del:hover { background: var(--red-soft); color: var(--red); }
.chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.msg { max-width: 92%; padding: 9px 12px; border-radius: var(--r-lg); font-size: 12.5px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--o); color: #fff; border-bottom-right-radius: 5px; }
.msg.ai { align-self: flex-start; background: var(--b); color: var(--h); border-bottom-left-radius: 5px; }
.msg.ai.err { background: var(--red-soft); color: var(--red); }
.msg.ai.pending { opacity: .7; }
.msg-meta { margin-top: 6px; font-size: 10.5px; color: var(--e); }
.msg-actions { margin-top: 7px; padding-top: 7px; border-top: 1px dashed var(--d); display: flex; flex-direction: column; gap: 3px; }
.act { font-family: var(--mono); font-size: 11px; color: var(--green); }
.msg-read { font-size: 11px; color: var(--e); font-family: var(--mono); }
.chat-input-wrap { border-top: 1px solid var(--line); padding: 10px 12px; }
.chat-input-wrap textarea {
  width: 100%; height: 76px; padding: 9px 11px; resize: none;
  border: 1px solid var(--line); border-radius: var(--r-md);
  font-size: 12.5px; line-height: 1.6; background: var(--w);
}
.chat-input-wrap textarea:focus { border-color: var(--o); box-shadow: 0 0 0 3px var(--o-soft); }
.chat-ft { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.chat-ft .tip { flex: 1; font-size: 10.5px; color: var(--e); }

/* 面板主体：对话主区 + 右侧 To Do List（最大化时显示） */
.chat-body { flex: 1; display: flex; min-height: 0; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }

/* 流式消息：深度思考 / 生成中 / 原始输出 */
.msg.ai { white-space: normal; }
.msg-body { white-space: pre-wrap; }
.think { margin-bottom: 8px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--panel-2); overflow: hidden; }
.think-head, .raw-head {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 9px; font-size: 11px; color: var(--f); background: var(--b);
}
.think-head span::before { content: '✦ '; color: var(--o); }
.think-head .fold, .raw-head .fold { margin-left: auto; font-size: 11px; color: var(--o); }
.think-head .fold:hover, .raw-head .fold:hover { text-decoration: underline; }
.think-body {
  padding: 8px 10px; font-size: 12px; line-height: 1.75; color: var(--g);
  white-space: pre-wrap; word-break: break-word; max-height: 280px; overflow-y: auto;
}
.think.collapsed .think-body { display: none; }
.gen-note { margin-top: 6px; font-size: 11px; color: var(--o); }
.gen-note::after { content: '▍'; animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
.raw-wrap { margin-top: 7px; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.raw-body {
  margin: 0; padding: 8px 10px; background: var(--panel-2);
  font-family: var(--mono); font-size: 11px; line-height: 1.6; color: var(--g);
  white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto;
}
.raw-wrap.collapsed .raw-body { display: none; }
.msg.streaming { border: 1px dashed var(--o-soft-2); }

/* 右侧 To Do List */
.chat-todo {
  display: none; width: 272px; flex: none;
  flex-direction: column; min-height: 0;
  background: var(--panel-2); border-left: 1px solid var(--line);
}
.todo-head { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.todo-head b { font-size: 12.5px; }
.todo-head .spacer { flex: 1; }
.todo-state {
  font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: var(--b); color: var(--f);
}
.todo-list { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.todo-empty { font-size: 11.5px; color: var(--e); line-height: 1.7; }
.todo-item {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 7px 9px; border-radius: var(--r-sm);
  background: var(--w); border: 1px solid var(--line-2);
  font-size: 12px; line-height: 1.5; color: var(--g);
}
.todo-item.sub { margin-left: 6px; }
.td-ico { position: relative; flex: none; width: 14px; height: 14px; margin-top: 1px; border-radius: 50%; border: 1.5px solid var(--d); }
.todo-item.running .td-ico { border-color: var(--o); border-top-color: transparent; animation: spin .7s linear infinite; }
.todo-item.done .td-ico { border-color: var(--green); background: var(--green); }
.todo-item.done .td-ico::after {
  content: ''; position: absolute; left: 4px; top: 1.5px; width: 3px; height: 6px;
  border: solid #fff; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg);
}
.todo-item.failed .td-ico { border-color: var(--red); background: var(--red); }
.todo-item.failed .td-ico::after {
  content: '×'; position: absolute; inset: 0; color: #fff; font-size: 10px; line-height: 14px; text-align: center;
}
.todo-item.done .td-text { color: var(--e); text-decoration: line-through; }
.td-text { flex: 1; word-break: break-word; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- 顶栏扩展 ---------------- */
.user-menu { position: relative; }
.user-menu .menu-pop {
  position: absolute; right: 0; top: 38px; min-width: 180px;
  background: var(--w); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--sh-3); padding: 6px; z-index: 50;
}
.user-menu .menu-pop button, .user-menu .menu-pop a {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; border-radius: var(--r-sm); font-size: 12.5px; color: var(--g);
  text-decoration: none; text-align: left;
}
.user-menu .menu-pop button:hover, .user-menu .menu-pop a:hover { background: var(--b); color: var(--h); }
.credits-chip {
  display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 10px;
  background: var(--o-soft); color: var(--o); border-radius: 999px;
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}

/* ---------------- 个人中心抽屉 ---------------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 420px; z-index: 90;
  background: var(--w); border-left: 1px solid var(--line);
  box-shadow: -12px 0 40px rgba(0,0,0,.12);
  display: flex; flex-direction: column;
  animation: drawer-in .22s var(--ease);
}
.drawer[hidden] { display: none; }
@keyframes drawer-in { from { transform: translateX(24px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-head b { font-size: 14px; }
.drawer-head .spacer { flex: 1; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; }
.pf-card { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r-lg); padding: 14px; margin-bottom: 16px; }
.pf-balance { display: flex; align-items: baseline; gap: 8px; }
.pf-balance .num { font-size: 26px; font-weight: 800; color: var(--o); font-variant-numeric: tabular-nums; }
.pf-balance .unit { font-size: 12px; color: var(--e); }
.pf-quota-line { display: flex; justify-content: space-between; font-size: 12px; color: var(--f); margin: 12px 0 6px; }
.pf-bar { height: 8px; border-radius: 999px; background: var(--c); overflow: hidden; }
.pf-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--o), #ff9a3d); border-radius: 999px; transition: width .3s var(--ease); }
.pf-title { font-size: 12px; font-weight: 700; color: var(--e); letter-spacing: .5px; text-transform: uppercase; margin: 18px 0 10px; display: flex; align-items: center; gap: 8px; }
.pf-title::after { content: ''; flex: 1; height: 1px; background: var(--line-2); }
.tx-item { display: grid; grid-template-columns: 46px 1fr auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line-2); font-size: 12px; }
.tx-type { color: var(--f); font-weight: 600; }
.tx-remark { color: var(--g); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.tx-amt.pos { color: var(--green); }
.tx-amt.neg { color: var(--red); }
.tx-time { grid-column: 2 / 4; font-size: 10.5px; color: var(--e); }
.pf-pager { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; font-size: 11.5px; color: var(--e); }
.pf-field { margin-bottom: 10px; }
.pf-field label { display: block; font-size: 11.5px; color: var(--f); margin-bottom: 5px; }
.pf-field input {
  width: 100%; height: 34px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: var(--r-sm); font-size: 12.5px; background: var(--w);
}
.pf-field input:focus { border-color: var(--o); box-shadow: 0 0 0 3px var(--o-soft); }
.api-item { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px dashed var(--line-2); }
.api-info { flex: 1; min-width: 0; }
.api-info b { font-size: 12.5px; display: block; }
.api-info small { font-size: 10.5px; color: var(--e); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.api-act button { font-size: 11.5px; color: var(--f); padding: 3px 7px; border-radius: 5px; }
.api-act button:hover { background: var(--b); color: var(--o); }

/* ---------------- 属性面板 ---------------- */
.props-panel {
  position: fixed; right: 356px; bottom: 18px; width: 300px; z-index: 80;
  background: var(--w); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--sh-3); overflow: hidden;
  animation: drawer-in .2s var(--ease);
}
.props-panel[hidden] { display: none; }
.pp-head { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.pp-title { flex: 1; font-size: 12.5px; font-weight: 600; }
.pp-title code { color: var(--o); font-family: var(--mono); }
.pp-idx { color: var(--e); font-size: 11px; }
.pp-file { padding: 6px 12px; font-size: 11px; color: var(--e); font-family: var(--mono); background: var(--panel-2); }
.pp-body { max-height: 320px; overflow-y: auto; padding: 10px 12px; }
.pp-row { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 12px; color: var(--f); }
.pp-row input, .pp-row select {
  width: 100%; height: 30px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: var(--r-sm); font-size: 12px; background: var(--w);
}
.pp-row input:focus, .pp-row select:focus { border-color: var(--o); }
.pp-foot { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.pp-note { flex: 1; font-size: 10.5px; color: var(--e); }

/* ---------------- Toast ---------------- */
.toast-wrap { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 10px 16px; border-radius: var(--r-md); font-size: 12.5px;
  background: var(--h); color: #fff; box-shadow: var(--sh-3);
  animation: toast-in .2s var(--ease); max-width: 320px;
}
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
.toast.out { opacity: 0; transform: translateY(6px); transition: all .24s var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.empty-state { padding: 40px; text-align: center; color: var(--e); font-size: 13px; }

@media (max-width: 1180px) {
  .ide-body { grid-template-columns: 220px 1fr 300px; }
  .drawer { width: 100%; }
  .props-panel { right: 18px; }
}