/* ========== Doc Modal Styles ========== */
.doc-modal-content {
  width: min(90vw, 700px);
}

.doc-detail-info {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.doc-editor {
  width: 100%;
  min-height: 150px;
  max-height: 300px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  padding: 16px;
  font: 14px/1.6 var(--font-mono);
  color: var(--text);
  transition: all var(--transition-base);
}

.doc-editor:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
  background: var(--panel-strong);
}

.doc-rendered {
  width: 100%;
  min-height: 150px;
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  padding: 16px;
  color: var(--text);
}

.doc-rendered:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.doc-rendered table {
  display: block;
  overflow-x: auto;
}

.doc-view-info {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.doc-meta-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
}

.doc-meta-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  min-width: 80px;
}

.doc-meta-value {
  font-size: 13px;
  color: var(--text);
}

/* ========== 可折叠面板 ========== */
.collapsible {
  background: var(--bg-subtle);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.collapsible.collapsed .collapsible-content {
  display: none;
}

.collapsible.collapsed .toggle-icon {
  transform: rotate(-90deg);
}

.collapsible-content {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ========== 工作区面板 ========== */
.workspace-panel {
  flex-shrink: 0;
}

/* ========== 文件编辑器面板 ========== */
.editor-panel {
  /* 已移至 workspace-modal */
}

.editor-panel .collapsible-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.editor-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.select {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel-strong);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition-base);
}

.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.file-editor {
  flex: 1;
  min-height: 100px;
  max-height: 100%;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel-strong);
  padding: 16px;
  margin: 16px;
  font: 14px/1.6 var(--font-mono);
  color: var(--text);
  overflow: auto;
  transition: all var(--transition-base);
}

.file-editor:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

.file-editor:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 16px 16px;
  font-size: 12px;
}

/* ========== 设置栏 ========== */
.settings-bar {
  display: grid;
  grid-template-columns: repeat(3, 34px);
  justify-content: center;
  justify-items: center;
  align-items: center;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  margin-top: 10px;
}

.settings-bar .button,
.settings-bar .theme-toggle {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-md);
}

.settings-bar #language-toggle {
  font-size: 12px;
  font-weight: 500;
}

/* ========== 弹窗 ========== */
.settings-bar .icon-help {
  width: 18px;
  height: 18px;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  animation: modal-appear var(--transition-base) ease-out;
}

@keyframes modal-appear {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.sidebar-drawer-modal {
  --sidebar-drawer-left: clamp(208px, 20vw, 292px);
  --sidebar-drawer-gap: 24px;
  --sidebar-drawer-width: calc(100vw - var(--sidebar-drawer-left) - var(--sidebar-drawer-gap));
}

.modal.sidebar-drawer-modal.active {
  display: block;
}

.modal.sidebar-drawer-modal .modal-overlay {
  opacity: 0;
  background: rgba(20, 20, 19, 0.18);
  backdrop-filter: blur(2px);
  transition: opacity 340ms cubic-bezier(0.16, 1, 0.3, 1);
}

.modal.sidebar-drawer-modal.active:not(.closing):not(.opening) .modal-overlay {
  opacity: 1;
}

.modal.sidebar-drawer-modal.opening .modal-overlay,
.modal.sidebar-drawer-modal.closing .modal-overlay {
  opacity: 0;
}

.modal.sidebar-drawer-modal .modal-content {
  position: absolute;
  top: 50%;
  left: var(--sidebar-drawer-left);
  width: min(76vw, var(--sidebar-drawer-width));
  max-height: min(86vh, 760px);
  opacity: 0;
  animation: none;
  transform: translate(calc(-100% - 28px), -50%) scale(0.98);
  transform-origin: left center;
  transition:
    transform 460ms cubic-bezier(0.16, 1, 0.3, 1),
    opacity 320ms cubic-bezier(0.16, 1, 0.3, 1);
}

.modal.sidebar-drawer-modal.active:not(.closing):not(.opening) .modal-content {
  opacity: 1;
  transform: translate(0, -50%) scale(1);
}

.modal.sidebar-drawer-modal.opening .modal-content,
.modal.sidebar-drawer-modal.closing .modal-content {
  opacity: 0;
  transform: translate(calc(-100% - 28px), -50%) scale(0.98);
}

#tools-modal.sidebar-drawer-modal .modal-content,
#skills-modal.sidebar-drawer-modal .modal-content {
  width: min(520px, var(--sidebar-drawer-width));
}

#knowledge-modal.sidebar-drawer-modal .modal-content {
  width: min(1080px, var(--sidebar-drawer-width));
}

#workspace-modal.sidebar-drawer-modal .modal-content {
  width: min(760px, var(--sidebar-drawer-width));
}

@media (max-width: 760px) {
  .modal.sidebar-drawer-modal {
    --sidebar-drawer-left: 12px;
    --sidebar-drawer-gap: 24px;
  }

  .modal.sidebar-drawer-modal .modal-content {
    top: 12px;
    left: var(--sidebar-drawer-left);
    width: var(--sidebar-drawer-width);
    max-height: calc(100vh - 24px);
    transform: translate(calc(-100% - 18px), 0) scale(0.98);
    transform-origin: left top;
  }

  .modal.sidebar-drawer-modal.active:not(.closing):not(.opening) .modal-content {
    transform: translate(0, 0) scale(1);
  }

  .modal.sidebar-drawer-modal.opening .modal-content,
  .modal.sidebar-drawer-modal.closing .modal-content {
    transform: translate(calc(-100% - 18px), 0) scale(0.98);
  }
}

/* 详情弹窗层级 - 显示在列表弹窗之上 */
#skill-modal.active,
#tool-modal.active,
#doc-modal.active,
#doc-view-modal.active {
  z-index: 1100;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
}

[data-theme="dark"] .modal-overlay {
  background: rgba(0, 0, 0, 0.7);
}

.modal-content {
  position: relative;
  width: min(90vw, 600px);
  max-height: 85vh;
  background: var(--panel-strong);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-slide var(--transition-slow) ease-out;
}

@keyframes modal-slide {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0;
}

.modal-body {
  flex: 1;
  overflow: auto;
  padding: 20px 24px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
}

/* ========== 工具列表弹窗 ========== */
.tools-modal-content,
.skills-modal-content {
  width: min(90vw, 500px);
}

.modal-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.modal-list-item:hover {
  background: var(--panel-strong);
  border-color: var(--accent);
}

.cowork-panel .section-header {
  cursor: pointer;
}

.cowork-panel .compact-stats {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.cowork-panel #cowork-session-count {
  color: var(--accent);
  font-weight: 700;
}

.cowork-page {
  display: none;
}

.cowork-page.active {
  display: flex;
}

.cowork-page-active {
  overflow: hidden;
}

.cowork-page-active .shell {
  display: grid;
}

.shell:has(> #cowork-modal.active) {
  grid-template-columns: 248px minmax(0, 1fr) 0;
}

.shell.sidebar-collapsed:has(> #cowork-modal.active) {
  grid-template-columns: 68px minmax(0, 1fr) 0;
}

.shell:has(> #cowork-modal.active) .chat-panel,
.shell:has(> #cowork-modal.active) .inspector-panel {
  display: none;
}

.shell:has(> #cowork-modal.active) #cowork-modal,
.cowork-page-active #cowork-modal {
  grid-column: 2 / 3;
  grid-row: 1;
  position: relative;
  inset: auto;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: color-mix(in srgb, var(--bg) 86%, var(--accent-soft));
}

.shell:has(> #cowork-modal.active) #cowork-modal .modal-overlay,
.cowork-page-active #cowork-modal .modal-overlay {
  display: none;
}

.cowork-page-active #cowork-modal-close {
  display: none;
}

.cowork-page-content {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
  min-width: 0;
  background: var(--panel-strong);
}

.cowork-modal-content {
  width: min(96vw, 1280px);
  max-height: 90vh;
}

.shell:has(> #cowork-modal.active) .cowork-modal-content,
.cowork-page-active .cowork-modal-content {
  width: 100%;
  min-height: 0;
  height: 100%;
  max-height: none;
  border: 0;
  border-radius: 0;
}

.shell:has(> #cowork-modal.active) .cowork-modal-body,
.cowork-page-active .cowork-modal-body {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow: auto;
}

.cowork-modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: calc(90vh - 84px);
  overflow: auto;
  padding: 18px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--bg) 72%, var(--panel-strong)), var(--bg));
}

.cowork-page-header {
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--panel-strong);
}

.cowork-title-block {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.cowork-title-block h2 {
  margin: 0;
  color: var(--text);
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1.08;
  letter-spacing: 0;
}

.cowork-title-block p:not(.eyebrow) {
  margin: 0;
  max-width: 720px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

.cowork-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.cowork-create,
.cowork-session-pane,
.cowork-detail-pane,
.cowork-grid > section {
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: var(--radius-sm);
  background: var(--panel-strong);
}

.cowork-create {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.cowork-create-copy {
  display: grid;
  align-content: start;
  gap: 6px;
}

.cowork-create-copy p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
}

.cowork-create-input {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.cowork-goal-input {
  min-height: 88px;
  resize: vertical;
}

.cowork-mode-label {
  display: grid;
  grid-template-columns: minmax(72px, max-content) minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.cowork-toolbar,
.cowork-message-row,
.cowork-task-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.cowork-create-actions {
  justify-content: flex-end;
}

.cowork-blueprint-editor {
  border: 1px solid var(--cowork-line);
  border-radius: 8px;
  padding: 8px;
}

.cowork-blueprint-editor summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--cowork-muted);
}

.cowork-blueprint-input {
  margin-top: 8px;
  min-height: 132px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.82rem;
}

.cowork-blueprint-actions {
  margin-top: 8px;
}

.cowork-workspace {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  gap: 16px;
  flex: 1;
  min-height: 0;
}

.cowork-session-pane,
.cowork-detail-pane {
  min-width: 0;
  min-height: 0;
  padding: 16px;
}

.cowork-session-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
}

.cowork-pane-header h3,
.cowork-detail-header h3,
.cowork-grid h4 {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

.cowork-pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cowork-session-list,
.cowork-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cowork-session-item {
  display: grid;
  gap: 5px;
  width: 100%;
  padding: 11px 12px;
  text-align: left;
  background: var(--panel-strong);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast), color var(--transition-fast);
}

.cowork-session-item:hover,
.cowork-session-item.active,
.cowork-card.active {
  border-color: color-mix(in srgb, var(--accent) 48%, var(--border));
  background: color-mix(in srgb, var(--accent-soft) 56%, var(--panel-strong));
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.cowork-session-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 650;
}

.cowork-session-meta,
.cowork-card small,
.cowork-event span {
  color: var(--text-muted);
  font-size: 11px;
}

.cowork-detail-pane {
  display: grid;
  grid-template-areas:
    "header header"
    "focus focus"
    "main rail"
    "composer composer";
  grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
  align-content: start;
  gap: 14px;
}

.cowork-detail-header {
  grid-area: header;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(0, max-content);
  align-items: start;
  gap: 12px;
}

.cowork-active-heading {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.cowork-active-heading h3 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 20px;
  line-height: 1.2;
}

.cowork-goal-text {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

.cowork-branch-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.cowork-branch-chip {
  display: inline-grid;
  gap: 2px;
  max-width: 210px;
  padding: 6px 8px;
  text-align: left;
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.cowork-branch-chip strong,
.cowork-branch-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cowork-branch-chip strong {
  font-size: 12px;
  font-weight: 650;
}

.cowork-branch-chip span {
  color: var(--text-muted);
  font-size: 11px;
}

.cowork-branch-chip:hover,
.cowork-branch-chip.active {
  border-color: color-mix(in srgb, var(--accent) 48%, var(--border));
  background: color-mix(in srgb, var(--accent-soft) 56%, var(--panel-strong));
}

.cowork-branch-chip:disabled {
  cursor: default;
}

.cowork-focus-strip {
  grid-area: focus;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.cowork-focus-card {
  display: grid;
  gap: 5px;
  min-width: 0;
  min-height: 78px;
  padding: 11px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--bg-subtle) 64%, var(--panel-strong));
}

.cowork-focus-card span,
.cowork-panel-note {
  overflow: hidden;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.cowork-focus-card strong {
  overflow: hidden;
  color: var(--text);
  font-size: 18px;
  font-weight: 750;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cowork-focus-card small {
  overflow: hidden;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cowork-primary-column {
  grid-area: main;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 12px;
  min-width: 0;
}

.cowork-graph-panel,
.cowork-conversation-panel,
.cowork-ops-panel,
.cowork-inspector-panel {
  min-width: 0;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: var(--radius-sm);
  background: var(--panel-strong);
}

.cowork-graph-panel,
.cowork-conversation-panel,
.cowork-ops-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
}

.cowork-graph-header,
.cowork-panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.cowork-graph-header h4,
.cowork-panel-heading h4,
.cowork-conversation-panel h4,
.cowork-inspector-panel h4 {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0;
}

.cowork-graph-header p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.4;
}

.cowork-graph-controls,
.cowork-trace-toolbar {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.cowork-graph-stage {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(color-mix(in srgb, var(--accent-soft) 18%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--accent-soft) 18%, transparent) 1px, transparent 1px),
    color-mix(in srgb, var(--bg-subtle) 72%, var(--panel-strong));
  background-size: 24px 24px;
}

.cowork-graph-stage:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cowork-graph-svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 360px;
}

.cowork-graph-inspector {
  min-height: 32px;
  overflow: hidden;
  padding: 8px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  background: var(--bg-subtle);
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cowork-conversation-panel {
  min-height: 280px;
}

.cowork-observability-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.cowork-secondary-tabs {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.cowork-secondary-tab,
.cowork-trace-mode-button,
.cowork-mode-tab {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}

.cowork-secondary-tab:hover,
.cowork-trace-mode-button:hover,
.cowork-mode-tab:hover {
  color: var(--text);
  background: var(--panel-strong);
}

.cowork-secondary-tab:focus-visible,
.cowork-trace-mode-button:focus-visible,
.cowork-mode-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cowork-secondary-tab.active,
.cowork-trace-mode-button.active,
.cowork-mode-tab.active {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 42%, var(--border));
  background: color-mix(in srgb, var(--accent-soft) 70%, var(--panel-strong));
  box-shadow: 0 0 0 1px var(--accent-soft);
}

.cowork-page[data-cowork-secondary-tab="trace"] [data-cowork-panel]:not([data-cowork-panel="trace"]),
.cowork-page[data-cowork-secondary-tab="tasks"] [data-cowork-panel]:not([data-cowork-panel="tasks"]),
.cowork-page[data-cowork-secondary-tab="mailbox"] [data-cowork-panel]:not([data-cowork-panel="mailbox"]),
.cowork-page[data-cowork-secondary-tab="outputs"] [data-cowork-panel]:not([data-cowork-panel="outputs"]) {
  display: none;
}

.cowork-run-panel,
.cowork-swarm-summary-panel,
.cowork-trace-panel,
.cowork-ops-panel:has(.cowork-final-draft:not([hidden])) {
  grid-column: 1 / -1;
}

.cowork-filter-input {
  min-height: 38px;
}

.cowork-filter-select {
  min-height: 34px;
  padding: 6px 28px 6px 10px;
  font-size: 12px;
}

.cowork-trace-mode-tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.cowork-projection-list {
  max-height: 320px;
  overflow: auto;
  padding-right: 2px;
}

.cowork-action-rail {
  grid-area: rail;
  align-self: start;
  min-width: 0;
  position: sticky;
  top: 16px;
}

.cowork-inspector-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.cowork-selected-inspector {
  display: grid;
  gap: 8px;
  min-height: 130px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.cowork-selected-inspector h5 {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cowork-selected-inspector p {
  margin: 0;
}

.cowork-selected-inspector pre {
  max-height: 220px;
  overflow: auto;
  margin: 6px 0 0;
  padding: 10px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  font-size: 11px;
}

.cowork-inspector-row {
  display: grid;
  grid-template-columns: minmax(72px, 0.45fr) minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
}

.cowork-inspector-row span {
  color: var(--text-muted);
  font-size: 11px;
}

.cowork-inspector-row strong {
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cowork-task-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.cowork-task-controls .config-input,
.cowork-task-controls .config-select {
  min-width: 0;
  min-height: 38px;
}

.cowork-task-controls .config-input {
  grid-column: 1 / -1;
}

.cowork-create.cowork-composer {
  grid-area: composer;
  grid-template-columns: minmax(0, 1fr);
  padding: 10px;
}

.cowork-composer .cowork-create-input {
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: end;
}

.cowork-composer .cowork-mode-tabs,
.cowork-composer .cowork-blueprint-editor,
.cowork-composer .cowork-mode-label,
.cowork-composer .cowork-create-actions,
.cowork-composer .error-text {
  grid-column: 1 / -1;
}

.cowork-composer .cowork-goal-input {
  min-height: 44px;
  max-height: 180px;
  resize: vertical;
}

.cowork-composer .cowork-create-actions {
  display: flex;
  justify-content: flex-end;
}

.cowork-composer .composer-send {
  width: 44px;
  min-width: 44px;
  height: 44px;
}

.cowork-mode-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 3px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.cowork-mode-tab {
  flex: 0 0 auto;
  padding: 0 10px;
  white-space: nowrap;
}

.cowork-observation-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.cowork-observation-list > strong {
  color: var(--text);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.cowork-observation-item {
  padding: 7px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--bg-subtle) 70%, var(--panel-strong));
}

.cowork-observation-item summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
}

.cowork-observation-item summary span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 650;
}

.cowork-observation-body {
  display: grid;
  gap: 6px;
  margin-top: 7px;
}

.cowork-observation-body p,
.cowork-observation-detail p {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.cowork-observation-detail {
  display: grid;
  gap: 6px;
}

.cowork-branch-result-card {
  gap: 8px;
}

.cowork-branch-result-choice {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 7px;
}

.cowork-branch-result-choice input {
  flex: 0 0 auto;
}

.cowork-branch-result-choice strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cowork-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.cowork-metric {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--bg-subtle) 68%, var(--panel-strong));
}

.cowork-metric span {
  color: var(--text);
  font-size: 20px;
  font-weight: 750;
  line-height: 1;
}

.cowork-metric small {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
}

.cowork-artifact-panel {
  display: grid;
  gap: 6px;
}

.cowork-artifact-panel[hidden] {
  display: none;
}

.cowork-artifact-panel p {
  overflow-wrap: anywhere;
}

.cowork-artifact-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cowork-artifact-list span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 7px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: color-mix(in srgb, var(--bg-subtle) 76%, var(--panel-strong));
  font-size: 11px;
  font-weight: 650;
}

.cowork-command-strip {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 0.9fr);
  gap: 10px;
}

.cowork-message-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
}

.cowork-task-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(132px, 0.54fr) max-content;
}

.cowork-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  grid-template-rows: minmax(160px, 0.8fr) minmax(160px, 0.85fr) minmax(128px, 0.68fr) minmax(120px, 0.58fr);
  gap: 12px;
  min-height: 0;
  flex: 1;
}

.cowork-grid > section {
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-width: 0;
  min-height: 0;
  padding: 13px;
}

.cowork-team-chat {
  grid-column: 1;
  grid-row: 1 / 5;
}

.cowork-agents-section {
  grid-column: 2;
  grid-row: 1;
  overflow: auto;
}

.cowork-tasks-section {
  grid-column: 2;
  grid-row: 2;
  overflow: auto;
}

.cowork-mailbox-section {
  grid-column: 2;
  grid-row: 3;
  overflow: auto;
}

.cowork-threads-section {
  grid-column: 2;
  grid-row: 4;
  overflow: auto;
}

.cowork-chat-list {
  flex: 1;
  gap: 10px;
  overflow: auto;
  padding: 4px 4px 4px 0;
}

.cowork-card,
.cowork-event,
.cowork-empty {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--panel-strong);
  padding: 10px;
}

.cowork-card {
  display: grid;
  gap: 6px;
  min-height: 76px;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.cowork-card[tabindex] {
  cursor: pointer;
}

.cowork-card[tabindex]:hover {
  border-color: color-mix(in srgb, var(--accent) 34%, var(--border));
  background: color-mix(in srgb, var(--accent-soft) 34%, var(--panel-strong));
}

.cowork-card-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center;
  gap: 8px;
}

.cowork-card strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.cowork-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.cowork-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cowork-mailbox-card {
  min-height: 68px;
}

.cowork-status {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 7px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 650;
  color: var(--text-muted);
  background: var(--bg);
}

.cowork-limit-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.cowork-limit-input {
  width: 58px;
  min-height: 32px;
  padding: 4px 6px;
}

.cowork-lane-label {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.cowork-message-card p {
  color: var(--text);
}

.cowork-chat-message {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.cowork-chat-message.from-user {
  grid-template-columns: minmax(0, 1fr) 34px;
}

.cowork-chat-message.from-user .cowork-chat-avatar {
  grid-column: 2;
  grid-row: 1;
}

.cowork-chat-message.from-user .cowork-chat-bubble {
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent), transparent 72%);
}

.cowork-chat-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent-soft) 72%, var(--panel-strong));
  border: 1px solid var(--border-subtle);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.cowork-chat-bubble {
  max-width: min(720px, 100%);
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--panel-strong);
}

.cowork-chat-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 6px;
}

.cowork-chat-meta strong {
  font-size: 12px;
}

.cowork-chat-meta span {
  color: var(--text-muted);
  font-size: 11px;
}

.cowork-chat-body {
  overflow-wrap: anywhere;
}

.cowork-chat-body.is-plain {
  white-space: pre-wrap;
}

.cowork-chat-body > :first-child {
  margin-top: 0;
}

.cowork-chat-body > :last-child {
  margin-bottom: 0;
}

.cowork-chat-body p,
.cowork-chat-body li {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}

.cowork-chat-body p,
.cowork-chat-body ul,
.cowork-chat-body ol,
.cowork-chat-body blockquote,
.cowork-chat-body pre {
  margin: 0 0 9px;
}

.cowork-chat-body ul,
.cowork-chat-body ol {
  padding-left: 19px;
}

.cowork-chat-body h1,
.cowork-chat-body h2,
.cowork-chat-body h3,
.cowork-chat-body h4 {
  margin: 12px 0 7px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

.cowork-chat-body code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--bg-subtle);
  font-size: 12px;
}

.cowork-chat-body pre {
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.cowork-chat-body pre code {
  padding: 0;
  background: transparent;
}

.cowork-chat-event {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.cowork-chat-event strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--text-muted);
}

.cowork-chat-event small {
  grid-column: 2;
  color: var(--text-muted);
  font-size: 11px;
}

.cowork-status-active,
.cowork-status-running,
.cowork-status-in_progress,
.cowork-status-delivered,
.cowork-status-read {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent), transparent 68%);
}

.cowork-status-completed,
.cowork-status-replied {
  color: var(--success);
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success), transparent 68%);
}

.cowork-status-failed,
.cowork-status-blocked,
.cowork-status-expired {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger), transparent 68%);
}

.cowork-status-paused,
.cowork-status-pending,
.cowork-status-idle,
.cowork-status-queued {
  color: var(--warning);
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning), transparent 68%);
}

.cowork-event {
  display: grid;
  gap: 4px;
}

.cowork-event strong {
  font-size: 12px;
}

.cowork-empty {
  color: var(--text-muted);
  font-size: 12px;
}

.modal-list-item-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-list-item-desc {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.tool-risk-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  padding: 1px 6px;
  border: 1px solid color-mix(in srgb, var(--warning) 38%, var(--border-subtle));
  border-radius: var(--radius-full);
  background: var(--warning-soft);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 650;
}

.modal-header-buttons {
  display: flex;
  gap: 8px;
  margin-right: 16px;
}

/* ========== 工具详情弹窗 ========== */
.tool-modal-content {
  width: min(90vw, 500px);
}

.detail-value {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

.detail-text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
}

.schema-display {
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 12px;
  font-family: var(--font-mono);
  overflow: auto;
  max-height: 300px;
  white-space: pre-wrap;
}

/* ========== 知识库弹窗 ========== */
.knowledge-modal-content {
  width: min(96vw, 1180px);
  max-height: 90vh;
}

.knowledge-modal-content .modal-body {
  max-height: calc(90vh - 84px);
  overflow: auto;
}

.knowledge-modal-content .knowledge-stats {
  margin-bottom: 16px;
}

.knowledge-modal-content .knowledge-docs-panel {
  margin-bottom: 16px;
}

.knowledge-modal-content .docs-list {
  max-height: 52vh;
}

.knowledge-modal-content .query-results {
  max-height: 46vh;
}

.knowledge-modal-content .knowledge-query-panel {
  background: var(--panel-strong);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

@media (max-width: 900px) {
  .knowledge-overview-grid,
  .knowledge-graph-workspace {
    grid-template-columns: 1fr;
  }

  .knowledge-graph-inspector {
    border-left: none;
    border-top: 1px solid var(--border-subtle);
  }

  .knowledge-tabs {
    overflow-x: auto;
  }

  .knowledge-tab {
    min-width: 120px;
  }
}

/* ========== 工作区弹窗 ========== */
.workspace-modal-content {
  width: min(90vw, 700px);
  height: min(85vh, 600px);
}

.workspace-modal-content .modal-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.workspace-modal-content .editor-toolbar {
  flex-shrink: 0;
  margin-bottom: 12px;
}

.workspace-modal-content .file-editor {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 12px;
  border-radius: var(--radius-md);
  resize: none;
}

.workspace-modal-content .editor-footer {
  flex-shrink: 0;
  padding: 8px 0 0 0;
}
