:root {
  --bg: #f5f6f8;
  --bg-paper: #ffffff;
  --bg-soft: #f1f3f5;
  --line: #dfe3e8;
  --line-strong: #c7ced6;
  --text-main: #1f2328;
  --text-body: #2c3e50;
  --text-muted: #5f6b78;
  --muted: #5f6b78;
  --accent: #0056b3;
  --accent-soft: #e7f1ff;
  --success: #2f9e44;
  --warn: #d9822b;
  --danger: #dc3545;
  --danger-soft: #fdecef;
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Inter", "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text-main);
  background: var(--bg);
  line-height: 1.55;
}

.bg-orb {
  display: none;
}

.app-shell {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 340px;
  gap: 16px;
}

.panel {
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow-sm);
}

.sidebar,
.refs {
  padding: 18px;
  height: calc(100vh - 40px);
  position: sticky;
  top: 20px;
  overflow: auto;
}

.main {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand {
  margin: 0;
  color: var(--accent);
  font-size: 1.1rem;
  font-weight: 700;
  border-left: 3px solid var(--accent);
  padding-left: 10px;
}

.subtitle {
  margin: 6px 0 0;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.section-block {
  margin-top: 16px;
}

.section-block h2,
.card h2 {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.section-block p,
.card p {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.constraint-form {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.constraint-form label span,
.constraint-form legend,
.inline-control span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text-main);
  padding: 8px 10px;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 86px;
}

.dual-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

fieldset {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: #fafbfd;
  padding: 4px 8px;
  font-size: 0.78rem;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip input {
  width: auto;
  margin: 0;
  padding: 0;
}

.constraint-summary {
  margin-top: 10px;
  border: 1px dashed var(--line-strong);
  border-radius: 4px;
  background: #fbfcfe;
  padding: 8px;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.history-list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-list li button {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg-paper);
  color: var(--text-main);
  padding: 8px;
  cursor: pointer;
}

.history-list li button:hover {
  border-color: var(--accent);
  background: #fbfdff;
}

.query-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.input-wrap span {
  display: block;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.query-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
}

.inline-control {
  display: flex;
  flex-direction: column;
}

#runButton,
.ghost {
  border-radius: 4px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
}

#runButton {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #ffffff;
}

#runButton:hover {
  background: #004a99;
}

#runButton:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.ghost {
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--text-main);
  margin-top: 10px;
}

.ghost:hover {
  border-color: var(--accent);
}

.notice {
  margin-top: 10px;
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 0.86rem;
}

.run-status {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.82rem;
  border-left: 2px solid var(--line-strong);
  padding-left: 8px;
}

.notice-error {
  border: 1px solid #f1b0b7;
  background: var(--danger-soft);
  color: #9f1d2a;
}

.notice-warn {
  border: 1px solid #f2d3a6;
  background: #fff8ef;
  color: #8b5a16;
}

.workflow-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 12px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 14px;
  background: var(--bg-paper);
}

.card header {
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
  margin-bottom: 10px;
}

.timeline {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.timeline li {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px;
  background: #fcfdff;
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 8px;
}

.timeline .dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  margin-top: 6px;
  background: #96a3b2;
}

.timeline li[data-status="running"] .dot {
  background: var(--warn);
}

.timeline li[data-status="done"] .dot {
  background: var(--success);
}

.timeline li[data-status="error"] .dot {
  background: var(--danger);
}

.timeline strong {
  display: block;
  font-size: 0.88rem;
  color: var(--text-main);
}

.timeline small {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.theme-box,
.task-box {
  margin-top: 10px;
  border: 1px dashed var(--line-strong);
  border-radius: 4px;
  padding: 8px;
  color: var(--text-main);
  font-size: 0.84rem;
  line-height: 1.5;
}

.task-list {
  margin: 6px 0 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.metric-label {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.metric-row strong {
  display: block;
  margin-top: 3px;
  font-size: 1.45rem;
  color: var(--text-main);
}

.meter {
  margin-top: 8px;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  background: #ebedf0;
  border: 1px solid var(--line);
}

.meter-det {
  width: 0;
  background: #6b7b8c;
  transition: width 0.2s ease;
}

.meter-vec {
  width: 0;
  background: #9eb1c2;
  transition: width 0.2s ease;
}

.stream-block {
  margin: 10px 0 0;
  min-height: 108px;
  max-height: 240px;
  overflow: auto;
  background: var(--bg-soft);
  color: #4f5d6b;
  border: 1px solid var(--line);
  border-left: 3px solid #d0d7de;
  border-radius: 4px;
  padding: 10px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.8rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.answer-card .output {
  min-height: 150px;
}

.answer-toolbar {
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fafbfd;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: center;
}

.toolbar-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toolbar-label {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.toolbar-item strong {
  font-size: 0.94rem;
  color: var(--text-main);
}

.toolbar-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 500;
}

.toolbar-switch input {
  width: auto;
  margin: 0;
}

.answer-final {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #ffffff;
  color: #000000;
  padding: 18px;
  font-family: "Noto Serif SC", "Songti SC", "SimSun", serif;
  font-size: 1.12rem;
  line-height: 1.82;
}

.answer-final h1,
.answer-final h2,
.answer-final h3,
.answer-final h4,
.answer-final h5,
.answer-final h6 {
  margin: 1.1em 0 0.5em;
  line-height: 1.35;
  color: #000000;
}

.answer-final p,
.answer-final li,
.answer-final blockquote,
.answer-final code {
  color: #000000;
}

.answer-final h1 {
  font-size: 1.45rem;
}

.answer-final h2 {
  font-size: 1.25rem;
}

.answer-final h3 {
  font-size: 1.12rem;
}

.answer-final p {
  margin: 0.7em 0;
}

.answer-final ul,
.answer-final ol {
  margin: 0.7em 0;
  padding-left: 1.4em;
}

.answer-final li {
  margin: 0.25em 0;
}

.answer-final blockquote {
  margin: 0.9em 0;
  padding: 0.45em 0.8em;
  border-left: 3px solid var(--line-strong);
  background: #fafbfd;
}

.answer-final hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1.1em 0;
}

.answer-final pre {
  margin: 0.9em 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #f8f9fb;
  overflow: auto;
}

.answer-final code {
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.9em;
}

.citation-btn {
  color: var(--accent);
  border: 1px solid #b8d2f5;
  background: var(--accent-soft);
  border-radius: 2px;
  padding: 0 3px;
  margin: 0 1px;
  font-size: 0.76rem;
  font-weight: 600;
  vertical-align: super;
  cursor: pointer;
}

.citation-text {
  color: var(--text-muted);
  font-size: 0.76rem;
  vertical-align: super;
}

.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}

.doc-card {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px;
  background: #fcfdff;
}

.doc-card h3 {
  margin: 0;
  font-size: 0.94rem;
  line-height: 1.35;
}

.doc-meta,
.doc-score {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.42;
}

.raw-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.switch-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.switch-line input {
  width: auto;
  margin: 0;
}

.raw-json {
  margin-top: 10px;
  max-height: 300px;
  overflow: auto;
  border-radius: 4px;
  border: 1px solid var(--line);
  padding: 10px;
  background: #f8f9fb;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.8rem;
}

.reference-list {
  margin: 12px 0 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--text-main);
  font-size: 0.84rem;
  line-height: 1.45;
}

.reference-list li {
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--line);
}

.reference-list li.active {
  background: #edf5ff;
  border-radius: 4px;
  border-bottom-color: transparent;
  padding: 6px;
}

.refs.evidence-disabled {
  opacity: 0.55;
}

@media (max-width: 1360px) {
  .app-shell {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .refs {
    grid-column: 1 / -1;
    height: auto;
    position: static;
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .sidebar,
  .refs {
    position: static;
    height: auto;
  }

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

  .query-controls,
  .answer-toolbar {
    grid-template-columns: 1fr;
  }
}
