:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --text: #17201a;
  --muted: #65706a;
  --line: #d7ded8;
  --accent: #176b5b;
  --accent-2: #2f6f9f;
  --warn: #b25121;
  --danger: #a62632;
  --shadow: 0 14px 36px rgba(29, 47, 37, 0.12);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

#app {
  flex: 1;
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  padding: 24px;
}

.site-footer {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  border-top: 1px solid var(--line);
  padding: 12px 20px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.site-footer a {
  color: inherit;
  text-decoration: none;
}

.site-footer a:hover,
.site-footer a:focus-visible {
  color: var(--accent);
  text-decoration: underline;
}

.topbar,
.section-heading,
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.flash {
  max-width: 1200px;
  margin: 0 auto 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px 13px;
}

.flash.success {
  border-color: #8ebba8;
  background: #e9f5ef;
  color: #174f43;
}

.flash.error {
  border-color: #d69ca1;
  background: #fff0f1;
  color: var(--danger);
}

.access-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  max-width: 960px;
  margin: 40px auto;
}

.access-panel,
.admin-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 22px;
  box-shadow: var(--shadow);
}

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

.stack-form {
  display: grid;
  gap: 8px;
}

.stack-form label,
.inline-form label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  padding: 9px 11px;
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.topbar {
  margin: 0 auto 18px;
  max-width: 1440px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(24px, 3vw, 38px);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
}

h3 {
  margin-bottom: 5px;
  font-size: 16px;
}

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

.segmented button,
.primary-button,
.ghost-button,
.task-confirm {
  min-height: 38px;
  border-radius: 7px;
  border: 1px solid transparent;
  padding: 0 14px;
  white-space: nowrap;
}

.segmented button {
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: var(--accent);
  color: white;
}

.patient-layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.85fr) minmax(420px, 1.15fr);
  gap: 18px;
  max-width: 1440px;
  margin: 0 auto;
}

.pathway-panel,
.chat-panel,
.doctor-layout,
.research-layout {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.pathway-panel,
.chat-panel {
  min-height: calc(100vh - 130px);
}

.pathway-panel {
  padding: 20px;
  overflow: hidden;
}

.status-pill {
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--accent);
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
}

.metro-line {
  position: relative;
  display: grid;
  gap: 12px;
  margin: 20px 0 0;
  padding: 0;
  list-style: none;
}

.metro-node {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
}

.node-marker {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
}

.metro-node.done .node-marker {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.metro-node.current .node-marker {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: white;
}

.metro-node.pending_confirmation .node-marker {
  background: var(--warn);
  border-color: var(--warn);
  color: white;
}

.pending-confirm {
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px dashed var(--warn);
  border-radius: 8px;
  background: #fbf1ea;
}

.pending-confirm p {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--warn);
}

.pending-actions {
  display: flex;
  gap: 8px;
}

.node-body {
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.node-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

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

.node-body p {
  color: var(--muted);
  font-size: 14px;
}

.task-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.task {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  border-radius: 7px;
  background: var(--surface-2);
  padding: 7px 9px;
  font-size: 13px;
}

.task.done {
  background: #e9f5ef;
}

.task-confirm,
.ghost-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--accent);
}

.primary-button {
  background: var(--accent);
  color: white;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  padding: 20px;
}

.patient-summary,
.metric-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.patient-summary div,
.metric {
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 12px;
}

.patient-summary span,
.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.patient-summary strong,
.metric strong {
  display: block;
  margin-top: 6px;
}

.notice {
  border-left: 4px solid var(--warn);
  background: #fff5ec;
  color: #683716;
  padding: 11px 12px;
  border-radius: 6px;
  font-size: 14px;
}

.messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-height: 310px;
  max-height: 50vh;
  margin: 16px 0;
  overflow: auto;
}

.message {
  max-width: 78%;
  border-radius: 8px;
  padding: 11px 13px;
}

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

.ai-label {
  display: inline-block;
  margin-bottom: 5px;
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 700;
}

.message.agent {
  align-self: flex-start;
  background: var(--surface-2);
}

.message.patient {
  align-self: flex-end;
  background: #deeee9;
}

.chat-form {
  display: grid;
  gap: 10px;
}

textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.doctor-layout,
.research-layout,
.admin-layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 22px;
}

.admin-layout {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 18px 0;
}

.admin-section {
  box-shadow: none;
}

.audit-summary {
  margin-bottom: 0;
}

.inline-form {
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto;
  align-items: end;
  gap: 10px;
  margin: 18px 0;
}

.export-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  white-space: nowrap;
}

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

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

.risk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.risk-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface);
}

.risk-card.grade-3 {
  border-color: var(--warn);
}

.risk-card.grade-4 {
  border-color: var(--danger);
}

.risk-topline {
  display: flex;
  justify-content: space-between;
}

.risk-topline span {
  border-radius: 999px;
  background: #ffe7e1;
  color: var(--danger);
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}

dl {
  display: grid;
  gap: 7px;
}

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

dd {
  margin: 0;
  font-weight: 700;
}

.export-box {
  overflow: auto;
  max-height: 56vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10201b;
  color: #dff4ec;
  padding: 18px;
}

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

  .topbar,
  .section-heading,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .patient-layout {
    grid-template-columns: 1fr;
  }

  .pathway-panel,
  .chat-panel {
    min-height: auto;
  }

  .patient-summary,
  .metric-row,
  .access-layout,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .access-layout {
    margin: 16px auto;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
    min-width: 0;
    padding: 0 7px;
    font-size: 12px;
  }
}
