/* ==========================================================================
   workspace.css —— AI 助学工作台(/ask 四区:文件区 / 分析台 / 对话区 / 关联材料区)
   ========================================================================== */

.ws-page {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* 导航是 position:fixed,给工作台留出顶部空间 */
  padding-top: 72px;
  box-sizing: border-box;
}

.ws {
  flex: 1;
  min-height: 0;
  display: grid;
  /* 覆盖 theme.css 给 main 的 1180px 居中限制,让工作台占满浏览器宽度 */
  max-width: none;
  width: 100%;
  margin: 0;
  /* 文件区贴左边界、关联材料贴右边界、对话区占满中间(约 6 份宽) */
  grid-template-columns: minmax(200px, 1fr) minmax(200px, 1fr) minmax(0, 6fr) minmax(240px, 1.3fr);
  gap: 6px;
  padding: 8px;   /* 左右只留一点缝,上下也留一点 */
}

.ws-col {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-solid);
  overflow: hidden;
}

.ws-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(154, 118, 52, .05), transparent);
}
.ws-title { font-size: 12.5px; font-weight: 700; color: var(--white); letter-spacing: .04em; }
.ws-hint { font-size: 10.5px; color: var(--ink-3); }
.ws-count { font-size: 10.5px; color: var(--ink-3); margin-left: 4px; }

.ws-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 4px;
}

/* ---------------- 文件区 ---------------- */

.ws-switch { display: flex; border: 1px solid var(--line-2); border-radius: 999px; overflow: hidden; }
.ws-switch button {
  border: 0;
  background: transparent;
  color: var(--ink-3);
  font-size: 10.5px;
  padding: 3px 8px;
  cursor: pointer;
}
.ws-switch button.is-on { background: var(--gold-dim); color: var(--gold); }

.ws-folder-head {
  display: flex; align-items: center; gap: 5px;
  width: 100%;
  border: 0; background: transparent;
  color: var(--ink-2);
  font-size: 12px;
  padding: 6px 8px;
  cursor: pointer;
  text-align: left;
}
.ws-folder-head:hover { background: rgba(154, 118, 52, .05); }
.ws-caret { width: 12px; color: var(--gold-2); font-size: 10px; transition: transform .15s; }
.ws-folder.is-open > .ws-folder-head .ws-caret { transform: rotate(90deg); }
.ws-folder-body { display: none; padding-left: 12px; }
.ws-folder.is-open > .ws-folder-body { display: block; }
.ws-folder-sub { padding-left: 14px; }

.ws-file {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px 5px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--ink);
}
.ws-file:hover { background: rgba(154, 118, 52, .06); }
.ws-file.is-active { background: var(--gold-dim); box-shadow: inset 2px 0 0 var(--gold-2); }
.ws-file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-file-meta { font-size: 9.5px; color: var(--ink-3); white-space: nowrap; }

.ws-tag {
  flex: 0 0 auto;
  font-size: 9.5px;
  line-height: 1.6;
  padding: 0 6px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  color: var(--ink-3);
  white-space: nowrap;
}
.ws-tag--针灸 { color: #8A5A2B; border-color: rgba(138, 90, 43, .35); background: rgba(154, 118, 52, .08); }
.ws-tag--推拿 { color: #5B4A8A; border-color: rgba(91, 74, 138, .32); background: rgba(107, 74, 158, .07); }
.ws-tag--耳穴手诊 { color: #3F7560; border-color: rgba(63, 117, 96, .32); background: rgba(94, 140, 116, .08); }
.ws-tag--中成药 { color: #9A4A3C; border-color: rgba(154, 74, 60, .32); background: rgba(154, 74, 60, .07); }
.ws-tag--未分类 { color: var(--ink-3); }
.ws-tag--外部 { color: #8A6A2B; border-style: dashed; }

.ws-empty { padding: 14px 10px; font-size: 11.5px; color: var(--ink-3); line-height: 1.8; text-align: center; }
.ws-empty a { color: var(--gold); }

/* ---------------- 分析台 ---------------- */

.ws-analyze { display: grid; grid-template-rows: 1fr 1fr; gap: 0; }
.ws-analyze > section { display: flex; flex-direction: column; min-height: 0; }
.ws-analyze > section + section { border-top: 1px solid var(--line); }

.ws-chat.is-over { outline: 2px dashed var(--gold-2); outline-offset: -4px; background: rgba(154, 118, 52, .04); }
.ws-drop.is-over { background: rgba(154, 118, 52, .08); outline: 2px dashed var(--gold-2); outline-offset: -4px; }

.ws-import-item, .ws-related-item {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.ws-import-item:hover, .ws-related-item:hover { background: rgba(154, 118, 52, .06); }
.ws-import-item.is-active, .ws-related-item.is-active { background: var(--gold-dim); }
.ws-import-del {
  flex: 0 0 auto;
  border: 0; background: transparent;
  color: var(--ink-3);
  font-size: 13px;
  line-height: 1;
  padding: 1px 3px;
  cursor: pointer;
  border-radius: 4px;
}
.ws-import-del:hover { color: var(--danger); background: rgba(255, 122, 147, .12); }

.ws-preview { padding: 10px 12px; font-size: 12.5px; line-height: 1.85; color: var(--ink); }
.ws-preview h4 { margin: 0 0 8px; font-size: 13px; color: var(--white); }
.ws-preview .ws-preview-meta { font-size: 10.5px; color: var(--ink-3); margin-bottom: 10px; }
.ws-preview p { margin: 0 0 8px; }
.ws-preview .ws-preview-label { color: var(--gold); font-weight: 700; margin-right: 4px; }
.ws-preview pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  font-family: var(--font-sans);
  font-size: 12px;
  line-height: 1.8;
  color: var(--ink);
}
.ws-preview img { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); }
.ws-preview .ws-preview-tag { display: inline-block; margin-left: 6px; }

/* ---------------- 对话区 ---------------- */

.ws-chat .ws-msgs {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ws-chat .xgai-bubble { max-width: 88%; }
/* AI 消息改成竖向排列:气泡在上,快捷操作在气泡「下方」,不再跑到右侧 */
.ws-chat .xgai-msg--ai { flex-direction: column; align-items: flex-start; }
.ws-chat .ws-ai-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; padding-left: 2px; }
.ws-chat .ws-ai-actions button {
  border: 1px dashed var(--line-2);
  background: transparent;
  color: var(--ink-3);
  font-size: 9.5px;
  line-height: 1.5;
  border-radius: 999px;
  padding: 0 6px;
  cursor: not-allowed;
}
.ws-chat .xgai-form { border-top: 1px solid var(--line); }
.ws-chat .xgai-note { padding: 0 12px 6px; }

/* ---------------- 关联材料区 ---------------- */

.ws-related-item { flex-direction: column; align-items: stretch; gap: 3px; padding: 7px 8px; cursor: grab; }
.ws-related-item .ws-related-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.ws-related-item .ws-related-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.ws-related-item .ws-related-snippet { font-size: 10.5px; color: var(--ink-3); line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------------- 窄屏 ---------------- */

@media (max-width: 1100px) {
  .ws-page { height: auto; overflow: visible; }
  .ws {
    height: auto;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: 460px 620px auto;
    grid-template-areas:
      "files analyze"
      "chat chat"
      "related related";
  }
  .ws-files { grid-area: files; }
  .ws-analyze { grid-area: analyze; }
  .ws-chat { grid-area: chat; }
  .ws-related { grid-area: related; min-height: 200px; }
  .ws-chat .ws-msgs { min-height: 360px; }
}

@media (max-width: 640px) {
  .ws { display: flex; flex-direction: column; padding: 8px; gap: 8px; }
  .ws-col { min-height: 320px; }
  .ws-chat { min-height: 520px; }
  .ws-analyze { min-height: 560px; }
}
