/* ============================================================================
 * 工作空间（Workspace）
 * 文件管理 + 统一对话入口的一站式页面
 * ==========================================================================*/

#opc-workspace-panel { padding: 0; overflow: hidden; }

.ws-topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface); flex: none;
}
.ws-title { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.ws-stat { font-size: 11px; color: var(--text-secondary); }
.ws-stat b { color: var(--text-primary); font-size: 12.5px; margin-right: 3px; }
.ws-flex { flex: 1; }
.ws-ws-select {
  padding: 5px 10px; font-size: 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg-input); color: var(--text-primary);
  cursor: pointer; outline: none; min-width: 160px;
}
.ws-ws-select:focus { border-color: var(--accent); }
.ws-topbar .ws-hint { font-size: 11px; color: var(--text-muted); }

.ws-mini-btn {
  padding: 5px 11px; font-size: 11.5px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary);
  font-weight: 500;
}
.ws-mini-btn:hover { color: var(--accent); border-color: var(--accent); }
.ws-mini-btn.danger { color: #ef4444; border-color: rgba(239,68,68,.4); }
.ws-mini-btn.danger:hover { background: rgba(239,68,68,.08); }
.ws-mini-btn.primary { border: none; background: var(--accent); color: #fff; font-weight: 600; }
.ws-mini-btn.primary:hover { filter: brightness(1.08); }

.ws-body { flex: 1; display: flex; min-height: 0; overflow: hidden; }

/* ---------------- 左侧：文件管理 ---------------- */
.ws-side {
  width: 280px; flex: none; display: flex; flex-direction: column;
  border-right: 1px solid var(--border); background: var(--bg-secondary, var(--surface));
  min-height: 0;
}
.ws-side-head {
  padding: 10px; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 7px;
}
.ws-side-head .ws-row {
  display: flex; gap: 6px; align-items: center;
}
.ws-side-head .ws-row .ws-mini-btn { flex: 1; font-size: 11px; padding: 5px 8px; }
/* 多选删除模式操作条（进入多选时替换按钮行显示） */
.ws-side-head .ws-multi-bar {
  display: flex; gap: 6px; align-items: center;
}
.ws-side-head .ws-multi-bar .ws-mini-btn { flex: 1; font-size: 11px; padding: 5px 8px; }
.ws-file-list { flex: 1; overflow-y: auto; padding: 6px; min-height: 0; }
.ws-empty {
  padding: 24px 14px; font-size: 12px; color: var(--text-muted);
  text-align: center; line-height: 1.7;
}
.ws-empty b { color: var(--text-secondary); }

.ws-file-item {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 9px; border-radius: 7px; cursor: pointer;
  margin-bottom: 2px; font-size: 12px; border: 1px solid transparent;
}
.ws-file-item:hover { background: var(--bg-hover); }
.ws-file-item.selected { background: var(--accent-bg); border-color: var(--accent); }
.ws-file-icon { font-size: 15px; flex: none; width: 22px; text-align: center; }
.ws-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-primary); }
.ws-file-size { font-size: 10.5px; color: var(--text-muted); flex: none; }
.ws-file-meta { font-size: 10px; color: var(--text-muted); flex: none; }
.ws-file-del {
  flex: none; cursor: pointer; font-size: 13px; color: var(--text-muted);
  padding: 2px 5px; border-radius: 4px; visibility: hidden;
}
.ws-file-item:hover .ws-file-del { visibility: visible; }
.ws-file-del:hover { color: #ef4444; background: rgba(239,68,68,.1); }
/* 多选删除模式：勾选行样式，隐藏单删 ✕ */
.ws-file-item.multi { padding-left: 5px; }
.ws-file-item.multi .ws-file-del { display: none; }
.ws-file-chk {
  flex: none; width: 18px; text-align: center; font-size: 14px;
  color: var(--text-muted); user-select: none; line-height: 1;
}
.ws-file-item.multi.checked { background: var(--accent-bg); border-color: var(--accent); }
.ws-file-item.multi.checked .ws-file-chk { color: var(--accent); font-weight: 700; }

.ws-side-foot { padding: 8px 10px; border-top: 1px solid var(--border); font-size: 10.5px; color: var(--text-muted); line-height: 1.5; }

/* ---------------- 右侧：对话区 ---------------- */
.ws-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ws-main-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 7px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface); flex: none; font-size: 11.5px;
}
/* 会话下拉与「＋新会话」按钮（多会话能力，对齐治理模块的 govSessionSelect） */
.ws-session-select {
  flex: none; max-width: 260px; min-width: 120px;
  background: var(--bg-elevated); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 5px 8px; font-size: 12px;
}
.ws-new-session-btn {
  flex: none; padding: 5px 10px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-primary); font-size: 12px; cursor: pointer; white-space: nowrap;
}
.ws-new-session-btn:hover { color: var(--accent); border-color: var(--accent); }
.ws-main-head .ws-route-label { color: var(--text-muted); }
.ws-main-head .ws-route-agent { font-weight: 600; color: var(--accent); }
.ws-main-head .ws-route-strategy { font-size: 10.5px; padding: 1px 7px; border-radius: 5px; background: var(--accent-bg); color: var(--accent); }

/* 对话消息区 */
.ws-chat { flex: 1; overflow-y: auto; padding: 16px; min-height: 0; }
.ws-msg { margin-bottom: 12px; font-size: 12.5px; line-height: 1.75; }
.ws-msg.user {
  margin-left: auto; max-width: 78%; padding: 8px 12px; border-radius: 10px;
  background: var(--accent-bg); color: var(--text-primary); width: fit-content; border-bottom-right-radius: 3px;
}
.ws-msg.assistant { color: var(--text-primary); }
.ws-msg.assistant .markdown-body { font-size: 12.5px; }
.ws-msg.system { font-size: 11px; color: var(--text-muted); text-align: center; padding: 6px 0; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
/* 长任务静默期的等待提示：临时占位，去掉 system 的下边框/大间距，避免被误认为分隔线 */
.ws-msg.system.ws-waiting { border-bottom: 0; margin-bottom: 8px; opacity: .85; font-style: normal; }
.ws-msg.error { font-size: 12px; color: #ef4444; white-space: pre-wrap; }
.ws-msg.error .ws-login-btn {
  display: inline-block; margin-top: 8px; padding: 6px 14px; font-size: 12px;
  border: none; border-radius: 8px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600;
}
.ws-msg.error .ws-login-btn:hover { opacity: .9; }
.ws-msg.tool {
  font-size: 11px; color: var(--text-secondary); padding: 5px 9px;
  background: var(--bg-input); border-radius: 7px; border-left: 2px solid var(--accent);
  white-space: pre-wrap; word-break: break-all; margin-bottom: 8px;
}
.ws-thinking { font-size: 11.5px; color: var(--accent); margin-bottom: 10px; animation: wsPulse 1.2s ease-in-out infinite; }
@keyframes wsPulse { 0%,100% { opacity:1; } 50% { opacity:.5; } }

.ws-welcome { padding: 8px 0; }
.ws-welcome-title { font-size: 14px; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; }
.ws-welcome-desc { font-size: 12px; color: var(--text-secondary); line-height: 1.8; margin-bottom: 12px; }
.ws-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.ws-chip {
  padding: 6px 11px; font-size: 11.5px; border-radius: 20px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary);
}
.ws-chip:hover { border-color: var(--accent); color: var(--accent); }

/* 文件查看器（承载于第三列 .ws-stage，见文件末尾） */
.ws-viewer-name {
  font-weight: 600; color: var(--text-primary);
  max-width: 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ws-viewer-size { color: var(--text-muted); }
.ws-viewer-code {
  flex: 1; min-height: 0; margin: 0;
  padding: 12px 16px; font-size: 12px; line-height: 1.65; white-space: pre-wrap;
  word-break: break-all; font-family: var(--mono), monospace;
  color: var(--text-primary); overflow: auto;
}
/* 二进制文档（docx/xlsx/pptx 等）经 /api/file/parse 解析为 Markdown 后的渲染样式 */
.ws-viewer-code.markdown-body {
  font-family: var(--sans, -apple-system, "Segoe UI", system-ui, sans-serif);
  white-space: normal; word-break: normal; font-size: 13px; line-height: 1.75;
  color: var(--text-primary);
}
.ws-viewer-code.markdown-body h1 { font-size: 18px; border-bottom: 2px solid var(--border); padding-bottom: 4px; margin: 16px 0 8px; }
.ws-viewer-code.markdown-body h2 { font-size: 16px; border-bottom: 1px solid var(--border); padding-bottom: 3px; margin: 14px 0 8px; }
.ws-viewer-code.markdown-body h3 { font-size: 14px; margin: 12px 0 6px; }
.ws-viewer-code.markdown-body h4 { font-size: 13px; opacity: 0.9; margin: 10px 0 6px; }
.ws-viewer-code.markdown-body p { margin: 8px 0; }
.ws-viewer-code.markdown-body ul, .ws-viewer-code.markdown-body ol { margin: 8px 0; padding-left: 22px; }
.ws-viewer-code.markdown-body li { margin: 4px 0; }
.ws-viewer-code.markdown-body table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 12px; overflow-x: auto; display: block; }
.ws-viewer-code.markdown-body th, .ws-viewer-code.markdown-body td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; white-space: nowrap; }
.ws-viewer-code.markdown-body th { background: var(--bg-hover); font-weight: 600; color: var(--text-primary); }
.ws-viewer-code.markdown-body td { color: var(--text-secondary); }
.ws-viewer-code.markdown-body pre { background: var(--bg-secondary, var(--surface)); border: 1px solid var(--border); border-radius: 6px; padding: 10px 14px; overflow: auto; font-family: var(--mono), monospace; font-size: 11.5px; }
.ws-viewer-code.markdown-body code { font-family: var(--mono), monospace; background: var(--bg-secondary, var(--surface)); padding: 1px 5px; border-radius: 4px; font-size: 11.5px; }
.ws-viewer-code.markdown-body blockquote { border-left: 3px solid var(--border); margin: 8px 0; padding: 4px 12px; color: var(--text-secondary); }
.ws-viewer-code.markdown-body a { color: var(--accent); text-decoration: underline; }
.ws-viewer-code.markdown-body img { max-width: 100%; border-radius: 4px; }

/* ---------------- 文件预览列（工作空间独有，独立第三列） ----------------
   Agent 的 ui_* 结果渲染不在此处，而是统一收口到全局 #mainRenderDock
   （工作空间 / Agent 工作室 / 治理 共用），见 unified_render.js。
   独立成列而非堆叠在对话列内：此前文件预览(38vh) 与渲染区(42vh) 是
   .ws-main 下的并列兄弟，同开会吃掉 80% 竖向空间、把对话挤压到不可用。 */
.ws-stage {
  flex: none; width: 38%; min-width: 280px; max-width: 640px;
  display: none; flex-direction: column; min-height: 0;
  border-left: 1px solid var(--border); background: var(--bg-card);
}
.ws-stage.open { display: flex; }
.ws-stage-bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  font-size: 11px; color: var(--text-secondary);
  border-bottom: 1px solid var(--border); background: var(--bg-secondary, var(--surface));
  flex: none;
}
.ws-stage-title { font-weight: 600; color: var(--text-primary); }

/* 窄屏：收窄文件预览列，让出对话列宽度（.ws-main 为 flex:1 自适应） */
@media (max-width: 1100px) {
  .ws-stage { width: 40%; min-width: 240px; }
}

/* ---------------- 输入区 ---------------- */
.ws-composer {
  flex: none; display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 16px; border-top: 1px solid var(--border); background: var(--surface);
}
.ws-composer textarea {
  flex: 1; resize: none; padding: 9px 12px; font-size: 12.5px; line-height: 1.6;
  border: 1px solid var(--border); border-radius: 9px; outline: none;
  background: var(--bg-input); color: var(--text-primary); font-family: inherit;
  min-height: 22px; max-height: 140px;
}
.ws-composer textarea:focus { border-color: var(--accent); }
.ws-composer .ws-send-btn {
  padding: 9px 16px; font-size: 12px; font-weight: 600; border-radius: 9px; cursor: pointer;
  border: none; background: var(--accent); color: #fff;
}
.ws-composer .ws-send-btn:disabled { opacity: .5; cursor: not-allowed; }

/* 上传提示条 */
.ws-upload-bar {
  display: flex; align-items: center; gap: 8px;
  margin: 4px 16px 0; padding: 8px 12px; font-size: 12px;
  border: 1px dashed var(--border); border-radius: 8px;
  background: var(--bg-input); color: var(--text-secondary);
}
.ws-upload-bar .ws-progress { flex: 1; height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.ws-upload-bar .ws-progress div { height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.ws-upload-ok { color: #10b981; font-weight: 600; }
.ws-upload-err { color: #ef4444; }

/* Dialog 弹窗 */
.ws-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.ws-dialog {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px 24px; width: 380px; max-width: 90vw; box-shadow: 0 12px 35px rgba(0,0,0,.2);
}
.ws-dialog-title { font-size: 13.5px; font-weight: 600; color: var(--text-primary); margin-bottom: 16px; }
.ws-dialog input {
  width: 100%; box-sizing: border-box; padding: 8px 12px; font-size: 12.5px;
  border: 1px solid var(--border); border-radius: 8px; outline: none;
  background: var(--bg-input); color: var(--text-primary);
}
.ws-dialog input:focus { border-color: var(--accent); }
.ws-dialog-actions { margin-top: 16px; display: flex; gap: 10px; justify-content: flex-end; }
.ws-dialog-actions button {
  padding: 7px 14px; font-size: 12px; border-radius: 8px; cursor: pointer;
}
.ws-dialog-actions .ws-cancel-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary); }
.ws-dialog-actions .ws-confirm-btn { border: none; background: var(--accent); color: #fff; font-weight: 600; }
.ws-dialog-actions .ws-confirm-btn.danger { background: #ef4444; }

/* 上传对话框 - 文件选择 + 拖拽 */
.ws-upload-dialog { width: 460px; }
.ws-upload-drop {
  border: 2px dashed var(--border); border-radius: 12px;
  padding: 32px 20px; margin: 12px 0; text-align: center;
  cursor: pointer; color: var(--text-muted); font-size: 12px;
  transition: border-color .2s, background .2s;
}
.ws-upload-drop:hover, .ws-upload-drop.drag { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); }
.ws-upload-info { font-size: 10.5px; color: var(--text-muted); margin-top: 8px; line-height: 1.5; }

/* 文件类型图标颜色 */
.ws-icon-code { color: #3b82f6; }   /* .py .js .ts .rs .go .java .c .cpp .h */
.ws-icon-doc  { color: #8b5cf6; }   /* .md .txt .yaml .json .toml .xml .csv */
.ws-icon-img  { color: #10b981; }   /* .png .jpg .gif .svg .webp */
.ws-icon-data { color: #f59e0b; }   /* .pdf .zip .tar .gz .xlsx .docx */
.ws-icon-other{ color: var(--text-muted); }

/* ── 路由规则管理面板（左侧边栏） ── */
.ws-rules {
  flex: none; max-height: 34%; display: flex; flex-direction: column;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.ws-rules-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.ws-section-title { font-size: 11.5px; font-weight: 600; color: var(--text-primary); }

/* 新增规则对话框表单 */
.ws-field { margin-bottom: 12px; }
.ws-field label { display: block; font-size: 11.5px; color: var(--text-secondary); margin-bottom: 5px; }
.ws-input {
  width: 100%; box-sizing: border-box; padding: 8px 12px; font-size: 12.5px;
  border: 1px solid var(--border); border-radius: 8px; outline: none;
  background: var(--bg-input); color: var(--text-primary); font-family: inherit;
}
.ws-input:focus { border-color: var(--accent); }
.ws-dialog select.ws-input { cursor: pointer; }
.ws-hint-tip { font-size: 10.5px; color: var(--text-muted); line-height: 1.5; margin-top: 4px; }
