:root {
  --bg: #eef2f4;
  --panel: #ffffff;
  --line: #d7dde4;
  --line-soft: #e6ebf0;
  --text: #152033;
  --muted: #667085;
  --primary: #2166c2;
  --primary-soft: #e9f1ff;
  --green-soft: #e9f8ef;
  --green-line: #bce7cc;
  --orange-soft: #fff3df;
  --orange-line: #f2c986;
  --red-soft: #fff0f0;
  --red: #b42318;
  --code-bg: #111827;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.page {
  width: min(1560px, 100%);
  margin: 0 auto;
  padding: 20px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.25;
}

h2 {
  font-size: 16px;
  line-height: 1.35;
}

h3 {
  margin-bottom: 10px;
  font-size: 14px;
  line-height: 1.35;
}

p {
  color: var(--muted);
  line-height: 1.55;
}

.topbar {
  display: flex;
  gap: 20px;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.topbar p {
  margin-top: 6px;
  max-width: 760px;
  font-size: 13px;
}

.controls,
.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button {
  min-width: 78px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid #c5cfda;
  border-radius: 6px;
  background: #ffffff;
  color: #111827;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}

button:hover {
  background: #f3f6fb;
}

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

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

button.primary:hover {
  background: #1b57a6;
}

button.full {
  width: 100%;
}

.runtime-strip,
.main-nav,
.workspace {
  margin-bottom: 12px;
}

.runtime-strip {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.runtime-title {
  flex: 0 0 auto;
  padding-top: 4px;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

.runtime-inline {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.runtime-chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  max-width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #f8fafc;
  color: #475467;
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.runtime-chip strong {
  flex: 0 0 auto;
  color: #101828;
}

.runtime-chip.wide {
  max-width: 100%;
}

.main-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.nav-tab {
  min-width: 92px;
}

.nav-tab.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.api-layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(360px, 1fr);
  gap: 12px;
  align-items: start;
}

.api-layout .business-panel,
.api-output-panel {
  grid-column: 1 / -1;
}

.panel {
  min-width: 0;
  padding: 14px;
}

.panel-heading {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  min-height: 28px;
  margin-bottom: 12px;
}

.panel-heading.compact {
  margin-top: 18px;
}

.panel-heading .muted {
  text-align: right;
}

.busy-inline {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
}

.intake-panel {
  position: sticky;
  top: 12px;
}

.form-grid {
  display: grid;
  gap: 9px;
  margin-bottom: 12px;
}

.api-form {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

label {
  display: block;
  color: #475467;
  font-size: 12px;
  line-height: 1.35;
}

input,
select,
textarea {
  width: 100%;
  margin-top: 4px;
  padding: 8px 9px;
  border: 1px solid #c5cfda;
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

input[type="file"] {
  padding: 7px 9px;
}

select {
  height: 36px;
}

textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.55;
}

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

.main-stage {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.stage-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1.1fr) minmax(320px, 0.9fr);
  gap: 12px;
  align-items: start;
}

.business-panel {
  grid-column: 1 / -1;
}

.dialogue-panel {
  min-height: 440px;
}

.dialogue {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 560px;
  overflow: auto;
  padding-right: 2px;
}

.empty,
.muted {
  color: var(--muted);
}

.bubble {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 8px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.bubble.status-sending {
  border-style: dashed;
}

.bubble.status-pending {
  opacity: 0.92;
}

.bubble.assistant {
  align-self: flex-start;
  border: 1px solid #b9d5ff;
  background: var(--primary-soft);
}

.bubble.patient {
  align-self: flex-end;
  border: 1px solid var(--green-line);
  background: var(--green-soft);
}

.bubble.system {
  align-self: center;
  border: 1px solid var(--orange-line);
  background: var(--orange-soft);
}

.bubble-label {
  margin-bottom: 4px;
  color: #475467;
  font-size: 12px;
  font-weight: 700;
}

.bubble-text + .attachment-card,
.attachment-card + .bubble-text,
.attachment-card + .bubble-status,
.bubble-text + .bubble-status {
  margin-top: 8px;
}

.bubble-status {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  margin-top: 7px;
  color: #475467;
  font-size: 12px;
}

.bubble-status.done {
  color: #087443;
}

.typing-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.typing-dots i {
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: currentColor;
  animation: typingPulse 1.1s infinite ease-in-out;
}

.typing-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typingPulse {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.attachment-card {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-width: min(360px, 100%);
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.attachment-preview {
  width: 84px;
  height: 72px;
  object-fit: cover;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #ffffff;
}

.attachment-icon {
  display: grid;
  place-items: center;
  width: 84px;
  height: 72px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #f8fafc;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

.attachment-card.pdf .attachment-icon {
  color: #b42318;
}

.attachment-card.text .attachment-icon {
  color: #075985;
}

.attachment-info {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.attachment-info strong,
.attachment-info span,
.attachment-text {
  overflow-wrap: anywhere;
}

.attachment-info strong {
  color: #101828;
  font-size: 13px;
}

.attachment-info span,
.attachment-text {
  color: #667085;
  font-size: 12px;
}

.attachment-text {
  display: -webkit-box;
  max-height: 56px;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.attachment-link {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.attachment-link:hover {
  text-decoration: underline;
}

.progress-box {
  display: grid;
  gap: 12px;
}

.doctor-summary,
.evidence-box {
  display: grid;
  gap: 10px;
}

.business-data,
.business-detail {
  display: grid;
  gap: 12px;
}

.business-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.business-stat,
.business-section {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #f8fafc;
}

.business-stat {
  padding: 9px 10px;
}

.business-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.business-stat strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

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

.business-section {
  min-width: 0;
  padding: 10px;
  overflow: auto;
}

.business-section h3 {
  margin-bottom: 8px;
}

.business-table {
  background: #ffffff;
}

.inline-id {
  display: inline-block;
  margin: 0 4px 4px 0;
  padding: 2px 5px;
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  background: #ffffff;
  color: #475467;
  font-size: 11px;
}

.action-link {
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
}

.action-link:hover {
  text-decoration: underline;
}

.progress-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.progress-top > div,
.field-group,
.summary-line,
.kv-row,
.fact-item {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #f8fafc;
}

.progress-top > div {
  padding: 9px;
}

.progress-top span {
  display: block;
  font-size: 12px;
}

.progress-top strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.progress-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4e7ec;
}

.progress-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.field-group {
  padding: 10px;
}

.field-group > strong {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
}

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

.tag {
  padding: 4px 7px;
  border-radius: 999px;
  background: #e0f2fe;
  color: #075985;
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.tag.missing {
  background: var(--red-soft);
  color: var(--red);
}

.summary-line {
  display: grid;
  gap: 5px;
  padding: 8px;
}

.summary-line + .summary-line {
  margin-top: 6px;
}

.summary-line span {
  color: #344054;
  font-size: 12px;
  font-weight: 700;
}

.summary-text-row {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.summary-text-row p {
  color: #475467;
  font-size: 13px;
  margin: 0;
}

.summary-citation-marks {
  display: inline-flex;
  gap: 3px;
}

.summary-citation-toggle {
  align-items: baseline;
  background: transparent;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  display: inline-flex;
  gap: 3px;
  height: auto;
  min-height: 0;
  padding: 0;
  width: auto;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  vertical-align: super;
}

.summary-citation-toggle:hover {
  text-decoration: underline;
}

.summary-citation-toggle:focus-visible {
  outline: 2px solid rgba(37, 99, 235, 0.35);
  outline-offset: 2px;
}

.summary-evidence-ref {
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #475467;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 5px 7px;
}

.summary-citation-number {
  color: var(--accent);
  font-size: 12px;
}

.summary-evidence-ref span,
.summary-evidence-ref em {
  color: #475467;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.summary-evidence-ref em {
  color: #667085;
  font-style: normal;
}

.summary-evidence-source {
  color: #344054 !important;
  font-weight: 700 !important;
}

.summary-evidence-field {
  background: #eef4ff;
  border-radius: 999px;
  color: #3538cd !important;
  font-size: 11px !important;
  padding: 2px 6px;
}

.citation-modal {
  align-items: center;
  background: rgba(15, 23, 42, 0.42);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 1000;
}

.citation-modal[hidden] {
  display: none;
}

.citation-modal-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.22);
  display: grid;
  gap: 12px;
  max-height: min(560px, calc(100vh - 40px));
  max-width: 680px;
  overflow: auto;
  padding: 14px;
  width: min(680px, 100%);
}

.citation-modal-heading {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.citation-modal-heading h3 {
  color: #101828;
  font-size: 15px;
}

.citation-modal-close {
  align-items: center;
  aspect-ratio: 1;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #344054;
  display: inline-flex;
  font-size: 13px;
  justify-content: center;
  min-height: 30px;
  padding: 0;
  width: 30px;
}

.citation-modal-body {
  display: grid;
  gap: 10px;
}

.citation-modal-kv {
  display: grid;
  gap: 6px;
}

.citation-modal-kv div {
  display: grid;
  gap: 2px;
}

.citation-modal-kv strong {
  color: #667085;
  font-size: 11px;
}

.citation-modal-kv span {
  color: #475467;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.session-list {
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
}

.session-item {
  display: grid;
  width: 100%;
  height: auto;
  min-height: 58px;
  padding: 8px 10px;
  text-align: left;
  border-radius: 6px;
}

.session-item.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.session-item strong,
.session-item span,
.session-item small {
  display: block;
  overflow-wrap: anywhere;
}

.session-item span,
.session-item small {
  color: var(--muted);
  font-size: 12px;
}

.detail-panel {
  min-height: 320px;
}

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

.tab {
  min-width: auto;
  height: 30px;
  padding: 0 10px;
}

.tab.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.detail-box {
  min-height: 180px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.85fr) minmax(360px, 1.15fr) minmax(320px, 1fr);
  gap: 12px;
}

.detail-grid > section,
.state-grid > section {
  min-width: 0;
}

.kv-list {
  display: grid;
  gap: 7px;
}

.kv-row {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 8px;
  padding: 8px 9px;
  font-size: 13px;
}

.kv-row span {
  color: var(--muted);
}

.kv-row strong {
  overflow-wrap: anywhere;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th,
.data-table td {
  padding: 8px;
  border: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.data-table th {
  background: #f8fafc;
  color: #344054;
}

.compact-detail {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #f8fafc;
}

.compact-detail + .compact-detail {
  margin-top: 8px;
}

.compact-detail summary {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.compact-detail summary span {
  color: var(--muted);
  font-weight: 400;
}

.fact-list {
  display: grid;
  gap: 7px;
  padding: 0 10px 10px;
}

.fact-item {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr);
  gap: 4px 8px;
  padding: 8px;
  font-size: 12px;
}

.fact-item strong,
.fact-item span,
.fact-item em {
  overflow-wrap: anywhere;
}

.fact-item em {
  grid-column: 2;
  color: var(--muted);
  font-style: normal;
}

.trace-event {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #f8fafc;
}

.trace-event + .trace-event {
  margin-top: 8px;
}

.trace-event summary {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.trace-event summary span {
  color: var(--muted);
  font-size: 12px;
}

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

.trace-section {
  min-width: 0;
}

.trace-section strong {
  display: block;
  margin-bottom: 6px;
  color: #344054;
  font-size: 12px;
}

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

pre {
  min-height: 220px;
  max-height: 560px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border-radius: 8px;
  background: var(--code-bg);
  color: #e5e7eb;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.trace-section pre {
  min-height: 160px;
  max-height: 420px;
}

.error-text {
  color: var(--red) !important;
}

@media (max-width: 1320px) {
  .stage-grid,
  .business-grid,
  .api-layout,
  .detail-grid,
  .trace-columns {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 980px) {
  .topbar,
  .workspace,
  .stage-grid,
  .business-grid,
  .api-layout,
  .detail-grid,
  .state-grid,
  .trace-columns {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .intake-panel {
    position: static;
  }
}

@media (max-width: 680px) {
  .page {
    padding: 12px;
  }

  .business-stats,
  .business-grid,
  .progress-top {
    grid-template-columns: 1fr;
  }

  .runtime-strip,
  .panel-heading {
    display: grid;
  }

  .panel-heading .muted {
    text-align: left;
  }

  .kv-row,
  .fact-item {
    grid-template-columns: 1fr;
  }

  .fact-item em {
    grid-column: auto;
  }
}
