:root {
  color-scheme: light;
  --bg: #eef2f5;
  --panel: #ffffff;
  --panel-soft: #f8fafb;
  --line: #d8e1e8;
  --line-strong: #b9c7d3;
  --text: #17202a;
  --muted: #667789;
  --teal: #087f7a;
  --blue: #245da8;
  --amber: #a35b00;
  --red: #b42318;
  --green: #157347;
  --shadow: 0 10px 28px rgba(20, 35, 50, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: var(--blue);
  color: var(--blue);
}

button.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

button.joined {
  border-color: var(--line-strong);
  background: #edf2f7;
  color: var(--muted);
}

input,
select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(320px, 1fr) auto;
  align-items: center;
  gap: 16px;
  min-height: 64px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-weight: 700;
}

.brand strong,
h1,
h2,
h3 {
  margin: 0;
  line-height: 1.3;
}

.brand strong {
  display: block;
  font-size: 17px;
}

.brand span:last-child {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.brand-tool-link {
  flex: 0 0 auto;
  margin-left: 8px;
  border-left: 1px solid var(--line);
  padding-left: 14px;
  color: var(--blue);
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}

.brand-tool-link:hover {
  color: var(--teal);
}

.top-search {
  display: grid;
  grid-template-columns: minmax(220px, 560px) 72px;
  gap: 8px;
  min-width: 0;
}

.status-cluster {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 10px;
  background: #edf2f7;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-dot.ok {
  background: #e8f5ef;
  color: var(--green);
}

.status-dot.warn {
  background: #fff4df;
  color: var(--amber);
}

.status-dot.bad {
  background: #fff0ee;
  color: var(--red);
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  height: calc(100vh - 64px);
  min-height: 640px;
  padding: 10px;
}

.filter-strip,
.knowledge-panel,
.question-stage,
.side-workbench {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.filter-strip {
  display: grid;
  gap: 5px;
  padding: 8px 14px;
}

.filter-strip-head,
.panel-head,
.stage-toolbar,
.basket-title,
.task-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.filter-strip-head h1,
.stage-toolbar h2,
.panel-head h2 {
  font-size: 16px;
}

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

.notice {
  max-width: 46vw;
  color: var(--red);
  font-size: 13px;
  text-align: right;
}

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

.filter-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 6px;
}

.filter-label {
  color: var(--muted);
  font-size: 12px;
  line-height: 26px;
  white-space: nowrap;
}

.filter-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 1px;
}

.filter-chip {
  max-width: 190px;
  min-width: max-content;
  min-height: 26px;
  padding: 0 9px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-chip.active {
  border-color: var(--teal);
  background: #e7f6f3;
  color: var(--teal);
}

.advanced-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px dashed var(--line);
  padding-top: 5px;
}

.ghost-button {
  min-height: 28px;
  background: var(--panel-soft);
  color: var(--muted);
}

.active-filter-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.active-filter-summary span {
  max-width: 220px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.advanced-filters {
  display: grid;
  grid-template-columns: 160px minmax(180px, 1fr) minmax(260px, 1.2fr);
  gap: 8px;
  padding-top: 4px;
}

.advanced-filters[hidden] {
  display: none;
}

.workbench-grid {
  display: grid;
  grid-template-columns: var(--knowledge-col, 210px) 8px minmax(560px, 1fr) 8px var(--side-col, 330px);
  gap: 6px;
  min-height: 0;
}

.column-resizer {
  position: relative;
  min-width: 8px;
  height: 100%;
  border-radius: 999px;
  cursor: col-resize;
  outline: none;
}

.column-resizer::before {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 3px;
  width: 2px;
  border-radius: 999px;
  background: var(--line-strong);
  content: "";
}

.column-resizer:hover::before,
.column-resizer:focus-visible::before,
.is-resizing-workbench .column-resizer::before {
  background: var(--teal);
}

.knowledge-panel,
.question-stage,
.side-workbench {
  display: grid;
  overflow: hidden;
}

.knowledge-panel {
  grid-template-rows: auto minmax(0, 1fr);
}

.panel-head,
.stage-toolbar {
  min-height: 48px;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
}

.scope-note {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.knowledge-tree,
.question-list,
.detail-body,
.basket-items,
.export-tasks {
  min-height: 0;
  overflow: auto;
}

.knowledge-tree {
  padding: 8px;
}

.knowledge-note {
  margin-bottom: 6px;
  border: 1px solid #e8d7a9;
  border-radius: 8px;
  padding: 6px;
  background: #fffaf0;
  color: var(--amber);
  font-size: 11px;
  line-height: 1.45;
}

.knowledge-tree ul {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.knowledge-tree li ul {
  margin-top: 4px;
}

.knowledge-node {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  width: 100%;
  min-height: 24px;
  padding: 0 8px 0 calc(8px + var(--depth) * 14px);
  text-align: left;
}

.knowledge-node span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.knowledge-node em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
}

.knowledge-node.active {
  border-color: var(--teal);
  background: #e7f6f3;
  color: var(--teal);
}

.question-stage {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.question-list {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 10px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  border-top: 1px solid var(--line);
  padding: 8px 10px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
}

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

.pagination-actions button {
  min-height: 28px;
  padding: 0 8px;
}

.question-card {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.question-card:hover,
.question-card.selected {
  border-color: var(--teal);
}

.question-card.selected {
  box-shadow: inset 4px 0 0 var(--teal);
}

.question-card-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.question-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 28px;
  border-radius: 6px;
  background: #edf2f7;
  color: var(--blue);
  font-weight: 700;
}

.card-meta,
.row-actions,
.task-links,
.tag-list,
.evidence-line,
.export-actions,
.workflow-steps {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.card-meta {
  min-width: 0;
}

.source-line {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.question-card-body {
  max-height: 82px;
  overflow: hidden;
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
}

.question-card-body img,
.question-card-body svg {
  max-width: 180px;
  max-height: 62px;
  object-fit: contain;
  vertical-align: middle;
}

.option-preview {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 8px;
  border: 1px solid #edf2f7;
  border-radius: 8px;
  padding: 6px 8px;
  background: var(--panel-soft);
  font-size: 12px;
}

.option-preview.muted {
  display: none;
}

.option-preview span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-list.compact {
  max-height: 24px;
  overflow: hidden;
}

.question-card-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.evidence-line span {
  color: var(--muted);
  font-size: 12px;
}

.pill,
.quality {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 2px 8px;
  background: #edf2f7;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.quality.official {
  background: #e8f5ef;
  color: var(--green);
}

.quality.review {
  background: #fff4df;
  color: var(--amber);
}

.quality.failed {
  background: #fff0ee;
  color: var(--red);
}

.quality.neutral {
  background: #edf2f7;
  color: var(--muted);
}

.side-workbench {
  grid-template-rows: auto minmax(0, 1fr);
}

.workbench-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border-bottom: 1px solid var(--line);
}

.tab-button {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel-soft);
}

.tab-button:last-child {
  border-right: 0;
}

.tab-button.active {
  background: #fff;
  color: var(--teal);
  box-shadow: inset 0 -3px 0 var(--teal);
  font-weight: 700;
}

.tab-panel {
  display: none;
  min-height: 0;
  overflow: hidden;
}

.tab-panel.active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

#basketPanel.active {
  grid-template-rows: auto auto minmax(120px, 1fr) auto;
}

.detail-body,
.basket-items,
.export-tasks {
  padding: 10px;
}

.detail-body.empty,
.basket-items.empty,
.export-tasks.empty,
.empty-state {
  color: var(--muted);
}

.detail-section {
  display: grid;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 0 0 12px;
  margin-bottom: 12px;
}

.detail-section:last-child {
  border-bottom: 0;
  margin-bottom: 0;
}

.detail-section h3 {
  color: var(--muted);
  font-size: 13px;
}

.detail-text,
.answer-block,
.basket-stem {
  overflow-wrap: anywhere;
  line-height: 1.7;
}

.answer-grid {
  grid-template-columns: 1fr;
}

.options {
  display: grid;
  gap: 8px;
}

.option {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: var(--panel-soft);
}

.option > strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.source-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.55;
}

.review-list {
  display: grid;
  gap: 6px;
}

.review-reason {
  border: 1px solid #f1c27d;
  border-radius: 6px;
  padding: 6px 8px;
  background: #fff8eb;
  color: var(--amber);
}

.dirty-blocker {
  display: grid;
  gap: 8px;
  margin: 10px;
  border: 1px solid #f1c27d;
  border-radius: 8px;
  padding: 10px;
  background: #fff8eb;
  color: var(--amber);
}

.dirty-title {
  color: #7a3f00;
  font-weight: 700;
}

.dirty-blocker p {
  margin: 0;
  line-height: 1.55;
}

.dirty-blocker ol {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
}

.dirty-blocker li {
  display: grid;
  gap: 5px;
  line-height: 1.45;
}

.dirty-blocker li em {
  color: var(--muted);
  font-style: normal;
}

.dirty-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dirty-stem,
.dirty-meta,
.task-meta {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.dirty-blocker li button {
  justify-self: start;
  min-height: 28px;
  border-color: #f1c27d;
  color: #7a3f00;
}

.basket-items,
.export-tasks {
  display: grid;
  align-content: start;
  gap: 8px;
}

.basket-item,
.export-task {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.basket-title strong,
.task-title strong {
  min-width: 0;
}

.basket-title button {
  min-height: 28px;
}

.basket-stem {
  max-height: 88px;
  overflow: hidden;
}

.export-panel {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 12px;
  background: var(--panel-soft);
}

.workflow-steps span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.export-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.export-actions:has(.editor-export-action) {
  grid-template-columns: 1fr;
}

.editor-export-action {
  display: inline-flex;
  align-items: center;
  width: 100%;
  justify-content: center;
  font-weight: 700;
}

.quick-export-actions button {
  min-height: 30px;
  color: var(--muted);
}

.export-actions button {
  min-height: 36px;
}

.task-title span {
  color: var(--muted);
  font-size: 12px;
}

.task-links {
  gap: 8px;
}

.task-links a {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  color: var(--blue);
  text-decoration: none;
}

.task-links button {
  min-height: 28px;
  border-color: var(--red);
  color: var(--red);
}

.task-error {
  color: var(--red);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.hidden {
  display: none;
}

.html-render {
  overflow-x: auto;
  overflow-y: hidden;
  line-height: 1.85;
}

.html-render p {
  margin: 0 0 8px;
}

.html-render p:last-child {
  margin-bottom: 0;
}

.html-render img {
  max-width: min(100%, 760px);
  vertical-align: middle;
}

.html-render .mathjax_content {
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  vertical-align: middle;
  line-height: 1;
}

.html-render svg {
  max-width: none;
  height: auto;
  overflow: visible;
  vertical-align: middle;
}

.stem-render {
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  white-space: normal;
}

.stem-render p {
  display: inline;
}

.stem-render .mathjax_content {
  max-width: 100%;
}

.html-render table {
  border-collapse: collapse;
  max-width: 100%;
}

.html-render td,
.html-render th {
  border: 1px solid var(--line);
  padding: 4px 6px;
}

@media (max-width: 1320px) {
  .workbench-grid {
    grid-template-columns: var(--knowledge-col, 180px) 8px minmax(520px, 1fr) 8px var(--side-col, 300px);
  }

  .filter-rows {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

}

@media (max-width: 1080px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .top-search {
    grid-template-columns: minmax(0, 1fr) 72px;
  }

  .status-cluster {
    justify-content: flex-start;
  }

  .app-shell {
    height: auto;
  }

  .workbench-grid {
    grid-template-columns: 1fr;
  }

  .question-stage {
    order: 1;
  }

  .side-workbench {
    order: 2;
  }

  .knowledge-panel {
    order: 3;
  }

  .column-resizer {
    display: none;
  }

  .knowledge-panel,
  .question-stage,
  .side-workbench {
    min-height: 0;
  }

  .knowledge-panel {
    height: min(42vh, 360px);
  }

  .question-stage {
    height: min(74vh, 680px);
  }

  .side-workbench {
    height: min(78vh, 720px);
  }

  .advanced-filters {
    grid-template-columns: 1fr;
  }

  .filter-rows {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 640px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand status"
      "search search";
    gap: 6px 8px;
    min-height: 0;
    padding: 7px 10px;
  }

  .brand {
    grid-area: brand;
    gap: 8px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 7px;
  }

  .brand strong {
    font-size: 15px;
  }

  .brand span:last-child {
    display: none;
  }

  .top-search {
    grid-area: search;
    grid-template-columns: minmax(0, 1fr) 54px;
    gap: 6px;
  }

  .top-search input,
  .top-search button {
    min-height: 30px;
  }

  .status-cluster {
    grid-area: status;
    justify-content: flex-end;
    gap: 4px;
  }

  #healthBadge,
  #dataStateBadge {
    display: none;
  }

  .status-dot {
    min-height: 24px;
    padding: 2px 8px;
    font-size: 11px;
  }

  .app-shell {
    gap: 6px;
    padding: 6px;
  }

  .filter-strip {
    gap: 4px;
    max-height: none;
    overflow: visible;
    padding: 6px 8px;
  }

  .filter-strip-head {
    align-items: center;
    flex-direction: row;
  }

  .filter-strip-head h1 {
    display: none;
  }

  .filter-rows {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .filter-row {
    display: flex;
    flex: 0 0 auto;
    grid-template-columns: none;
    gap: 4px;
  }

  .filter-label {
    display: none;
  }

  .filter-chips {
    flex-wrap: nowrap;
    overflow: visible;
    padding-bottom: 0;
  }

  .filter-chip {
    max-width: 112px;
    min-height: 26px;
    padding: 0 8px;
  }

  .advanced-bar {
    align-items: center;
    flex-direction: row;
    padding-top: 4px;
  }

  .active-filter-summary {
    flex: 1;
    flex-wrap: nowrap;
    justify-content: flex-end;
    overflow: hidden;
  }

  .active-filter-summary span {
    max-width: 120px;
  }

  .advanced-filters {
    gap: 6px;
    padding-top: 2px;
  }

  .filter-strip-head,
  .panel-head,
  .stage-toolbar,
  .question-card-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .notice {
    max-width: 100%;
    text-align: left;
  }

  .option-preview,
  .export-actions {
    grid-template-columns: 1fr;
  }

  .question-stage {
    height: min(76vh, 640px);
  }

  .knowledge-panel {
    height: min(34vh, 260px);
  }

  .side-workbench {
    height: min(78vh, 680px);
  }

  .pagination {
    align-items: flex-start;
    flex-direction: column;
  }

  .pagination-actions {
    width: 100%;
  }

  .pagination-actions button {
    flex: 1 1 calc(50% - 6px);
  }
}
