:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d9dee7;
  --soft: #eef2f7;
  --brand: #176b87;
  --brand-soft: #e4f2f6;
  --danger: #c2413a;
  --danger-soft: #fae8e6;
  --warn: #b7791f;
  --warn-soft: #fff3d7;
  --ok: #237a57;
  --ok-soft: #e2f3eb;
  --shadow: 0 16px 45px rgba(24, 39, 75, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
  line-height: 1.3;
}

.status-pill,
.count,
.tag,
.drug-letter,
.tone-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.status-pill {
  height: 34px;
  padding: 0 12px;
  border: 1px solid #b9dfe9;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

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

.panel,
.results-panel,
.sources-band {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.composer-panel {
  padding: 18px;
  position: sticky;
  top: 18px;
}

.panel-head,
.summary-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.icon-btn,
.remove-btn {
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--ink);
  cursor: pointer;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
}

.drug-list {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}

.drug-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 8px;
  position: relative;
}

.suggest-list {
  position: absolute;
  top: 44px;
  left: 42px;
  right: 42px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  max-height: 240px;
  overflow-y: auto;
  z-index: 50;
}

.suggest-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.suggest-item:last-child { border-bottom: 0; }
.suggest-item:hover, .suggest-item.active { background: var(--brand-soft); }
.suggest-item .pinyin {
  color: rgba(0, 0, 0, 0.4);
  font-size: 12px;
  font-family: monospace;
}

.drug-letter {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 800;
  font-size: 13px;
}

.drug-row input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fbfcfe;
  outline: none;
}

.drug-row input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.14);
}

.remove-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
}

.primary-btn {
  width: 100%;
  height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.primary-btn span {
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 12px;
}

.quick-pick {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.section-title {
  color: #374151;
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 10px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #394150;
  cursor: pointer;
  font-size: 13px;
}

.results-panel {
  min-height: 640px;
  overflow: hidden;
}

.summary-strip {
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.summary-strip h2 {
  font-size: 20px;
}

.counts {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.count {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
}

.count.danger {
  color: var(--danger);
  background: var(--danger-soft);
}

.count.warn {
  color: var(--warn);
  background: var(--warn-soft);
}

.count.ok {
  color: var(--ok);
  background: var(--ok-soft);
}

.matrix-wrap,
.pair-section,
.sources-band {
  padding: 18px;
}

.viz-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.viz-head .section-title {
  margin-bottom: 0;
}

.segmented {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.seg-btn {
  min-width: 58px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.seg-btn.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(24, 39, 75, 0.08);
}

.matrix-scroll {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.matrix {
  display: grid;
  min-width: 520px;
  width: max-content;
}

.matrix-row {
  display: grid;
  grid-template-columns: 168px repeat(var(--cols), 58px);
  min-height: 54px;
}

.matrix-row + .matrix-row {
  border-top: 1px solid var(--line);
}

.matrix-cell,
.matrix-label {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-left: 1px solid var(--line);
  background: #fff;
}

.matrix-label {
  justify-content: flex-start;
  gap: 8px;
  border-left: 0;
  color: #344054;
  font-size: 13px;
  overflow: hidden;
}

.matrix-label span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.matrix-head .matrix-cell,
.matrix-head .matrix-label {
  min-height: 38px;
  background: #f1f4f8;
  color: var(--muted);
  font-weight: 800;
}

.tone-mark {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  cursor: default;
  font-size: 13px;
  font-weight: 900;
}

button.tone-mark {
  cursor: pointer;
}

.tone-mark.danger {
  background: var(--danger);
}

.tone-mark.warn {
  background: var(--warn);
}

.tone-mark.ok {
  background: var(--ok);
}

.tone-mark.neutral {
  background: #9aa4b2;
}

.tone-mark.diag {
  background: #d9dee7;
}

.ring-view {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  min-height: 450px;
  overflow: hidden;
}

.ring-shell {
  position: relative;
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.ring-shell svg {
  display: block;
  width: 100%;
  height: auto;
}

.ring-line {
  stroke-width: 5;
  stroke-linecap: round;
  opacity: 0.84;
  cursor: pointer;
}

.ring-line.danger {
  stroke: var(--danger);
}

.ring-line.warn {
  stroke: var(--warn);
}

.ring-line.ok {
  stroke: var(--ok);
}

.ring-node circle {
  fill: var(--brand-soft);
  stroke: #fff;
  stroke-width: 5;
  filter: drop-shadow(0 2px 5px rgba(24, 39, 75, 0.16));
}

.ring-node-letter {
  fill: var(--brand);
  font-size: 15px;
  font-weight: 900;
}

.ring-node-label {
  fill: #344054;
  font-size: 12px;
  font-weight: 700;
}

.ring-empty {
  position: absolute;
  inset: auto 20px 20px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.pair-list {
  display: grid;
  gap: 10px;
}

.pair-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.pair-card-head {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: stretch;
  padding: 14px 14px 12px 0;
}

.stripe.danger {
  background: var(--danger);
}

.stripe.warn {
  background: var(--warn);
}

.stripe.ok {
  background: var(--ok);
}

.stripe.neutral {
  background: #9aa4b2;
}

.pair-title {
  font-weight: 850;
  line-height: 1.4;
}

.pair-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.level {
  align-self: start;
  padding: 5px 9px;
  border-radius: 8px;
  background: var(--soft);
  color: #344054;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.detail-btn {
  align-self: start;
  min-width: 58px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: #344054;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.pair-advice {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  color: #344054;
  background: #fbfcfe;
  font-size: 14px;
  line-height: 1.6;
}

.empty-state {
  padding: 26px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfe;
  text-align: center;
}

.sources-band {
  margin-top: 18px;
}

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

.source-item {
  min-height: 108px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.source-title {
  font-size: 14px;
  font-weight: 800;
  line-height: 1.4;
}

.source-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.toast {
  color: var(--danger);
}

body.modal-open {
  overflow: hidden;
}

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

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

.detail-modal {
  width: min(920px, 100%);
  max-height: min(860px, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
  overflow: hidden;
}

.detail-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.detail-modal-body {
  overflow: auto;
  padding: 18px;
}

.detail-banner {
  border: 1px solid;
  border-radius: 8px;
  padding: 16px;
}

.detail-banner.danger {
  background: var(--danger-soft);
  border-color: #f1beb9;
}

.detail-banner.warn {
  background: var(--warn-soft);
  border-color: #ecd39d;
}

.detail-banner.ok {
  background: var(--ok-soft);
  border-color: #aadbc4;
}

.detail-banner.neutral {
  background: var(--soft);
  border-color: var(--line);
}

.detail-banner-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.detail-banner h3,
.detail-section h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.4;
}

.detail-banner p,
.detail-section p {
  margin: 12px 0 0;
  color: #344054;
  font-size: 14px;
  line-height: 1.7;
}

.detail-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.detail-kv {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 10px 14px;
  margin-top: 12px;
}

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

.detail-v {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}

.detail-note,
.detail-empty {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.source-ref {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr);
  gap: 12px;
  padding: 12px 0;
}

.source-ref + .source-ref {
  border-top: 1px solid var(--line);
}

.source-ref-spine {
  border-radius: 999px;
}

.source-ref-spine.danger {
  background: var(--danger);
}

.source-ref-spine.warn {
  background: var(--warn);
}

.source-ref-spine.ok {
  background: var(--ok);
}

.source-ref-spine.neutral {
  background: #9aa4b2;
}

.source-ref-title,
.literature-title {
  font-size: 14px;
  font-weight: 850;
  line-height: 1.5;
}

.source-ref-meta,
.literature-meta,
.reaction-item small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.source-ref-body {
  margin-top: 8px;
  color: #344054;
  font-size: 13px;
  line-height: 1.6;
}

.reaction-shared,
.reaction-item,
.literature-item {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.reaction-shared {
  display: grid;
  gap: 6px;
}

.reaction-shared.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.reaction-shared.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.reaction-panel {
  margin-top: 12px;
}

.reaction-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 850;
}

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

.reaction-item {
  color: #344054;
  font-size: 13px;
  line-height: 1.6;
}

.mini-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 8px;
  background: var(--soft);
  color: #344054;
  font-size: 12px;
  font-weight: 800;
}

.mini-pill.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.mini-pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.mini-pill.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.literature-item {
  background: #fbfcfe;
}

@media (max-width: 960px) {
  .app-shell {
    padding: 14px;
  }

  .toolbar,
  .summary-strip {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .composer-panel {
    position: static;
  }

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

@media (max-width: 560px) {
  h1 {
    font-size: 24px;
  }

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

  .matrix-row {
    grid-template-columns: 136px repeat(var(--cols), 48px);
  }
}
