:root {
  --navy: #10233f;
  --blue: #1769e0;
  --blue-dark: #0f4fac;
  --sky: #eaf3ff;
  --bg: #f1f5fa;
  --card: #fff;
  --ink: #1c2738;
  --muted: #687589;
  --line: #dde5ef;
  --green: #138a50;
  --green-bg: #edfaf3;
  --orange: #c66a08;
  --orange-bg: #fff7e8;
  --red: #d72d2d;
  --red-bg: #fff0f0;
  --purple: #7452cf;
  --teal: #087f78;
  --shadow: 0 9px 30px rgba(24, 49, 83, .09);
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font: 15px/1.65 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p { margin-top: 0; }

.topbar {
  min-height: 72px;
  padding: 10px max(20px, calc((100vw - 1180px) / 2));
  color: #fff;
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  box-shadow: 0 3px 16px rgba(5, 20, 40, .22);
  position: sticky;
  top: 0;
  z-index: 50;
}
.doctor-topbar { background: #102d36; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  font-size: 20px; font-weight: 800;
  background: linear-gradient(135deg, #2d83f7, #24b2ca);
}
.brand b { display: block; font-size: 16px; }
.brand small { display: block; color: #adc0d8; font-size: 11px; }
.test-mark {
  color: #ffe09a; border: 1px solid rgba(255, 224, 154, .4);
  background: rgba(255, 224, 154, .1); border-radius: 999px;
  padding: 4px 11px; font-size: 12px; white-space: nowrap;
}

.page { width: min(1180px, 100%); margin: 0 auto; padding: 30px 22px 72px; }
.page.narrow { width: min(820px, 100%); }
.patient-page { width: min(920px, 100%); }
.card {
  background: var(--card); border: 1px solid rgba(215, 225, 237, .85);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px;
}
.card + .card { margin-top: 18px; }
.hero { text-align: center; padding: 18px 0 24px; }
.hero h1 { margin-bottom: 8px; font-size: clamp(25px, 5vw, 36px); line-height: 1.25; }
.hero p { margin: 0; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.eyebrow { color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 18px; }
.section-head h2 { margin-bottom: 2px; font-size: 22px; }
.section-head p { margin: 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.stack { display: grid; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }

.btn {
  border: 1px solid transparent; border-radius: 10px; padding: 10px 18px;
  font-weight: 700; transition: .16s ease; display: inline-flex;
  align-items: center; justify-content: center; gap: 7px;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { cursor: not-allowed; opacity: .52; }
.btn-primary { color: #fff; background: var(--blue); }
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn-secondary { color: var(--blue); background: #fff; border-color: var(--blue); }
.btn-light { color: var(--ink); background: #eef3f9; border-color: var(--line); }
.btn-danger { color: #fff; background: var(--red); }
.btn-sm { padding: 6px 11px; border-radius: 8px; font-size: 13px; }
.btn-block { width: 100%; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 700; }
.field input, .field select, .field textarea {
  width: 100%; color: var(--ink); background: #fff;
  border: 1px solid #cfd9e7; border-radius: 10px; padding: 10px 12px;
  outline: none;
}
.field textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 105, 224, .11);
}
.checkline { display: flex; align-items: flex-start; gap: 9px; color: #39465a; }
.checkline input { margin-top: 6px; }
.hint { padding: 10px 12px; background: #f5f8fc; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: 12.5px; }
.error-box { padding: 13px 15px; color: #8f2020; background: var(--red-bg); border: 1px solid #efbcbc; border-radius: 10px; }

.agreement-grid { display: grid; gap: 12px; margin: 18px 0; }
.agreement-item { padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #fbfdff; }
.agreement-item h3 { font-size: 15px; margin-bottom: 6px; }
.agreement-item p { margin: 0; color: #46546a; font-size: 13px; }
.stepper { display: flex; justify-content: center; gap: 7px; margin-bottom: 18px; }
.stepper span { width: 42px; height: 5px; border-radius: 999px; background: #d7e0eb; }
.stepper span.on { background: var(--blue); }

.chat-shell { min-height: calc(100vh - 120px); display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; padding: 0; }
.chat-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.chat-head h2 { font-size: 19px; margin: 0; }
.chat-head p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.avatar-head-actions, .avatar-tags { display: flex; flex-wrap: wrap; gap: 7px; }
.avatar-head-actions { flex: none; }
.avatar-tags { margin: 14px 0; }
.avatar-section-title { font-size: 17px; margin: 28px 0 6px; }
.public-doctors { margin-top: 32px; border-top: 1px solid var(--line); }
.public-doctors > .muted { max-width: 920px; line-height: 1.6; }
.public-doctors > .muted a, .public-doctor-source a { color: var(--blue); text-decoration: underline; }
.public-doctor-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 16px; }
.public-doctor { min-width: 0; padding: 17px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.public-doctor-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.public-doctor-title h3 { margin: 0; font-size: 16px; }
.public-doctor p { margin: 9px 0; font-size: 13px; overflow-wrap: anywhere; }
.public-specialty { line-height: 1.65; }
.public-doctor-source { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.risk-banner { background: var(--red); color: #fff; padding: 12px 20px; font-weight: 800; text-align: center; }
.message-list { min-height: 430px; max-height: calc(100vh - 270px); overflow-y: auto; padding: 22px; background: linear-gradient(#f7faff, #f4f7fb); }
.empty-state { padding: 50px 20px; text-align: center; color: var(--muted); }
.empty-state .icon { display: block; font-size: 38px; margin-bottom: 8px; }
.message-row { display: flex; margin: 0 0 14px; }
.message-row.patient { justify-content: flex-end; }
.bubble { max-width: min(76%, 650px); padding: 12px 14px; border-radius: 5px 16px 16px; background: #fff; box-shadow: 0 3px 12px rgba(27, 54, 91, .08); }
.message-row.patient .bubble { color: #fff; background: linear-gradient(135deg, var(--blue), #3689ef); border-radius: 16px 5px 16px 16px; }
.bubble.followup { border-top: 4px solid var(--teal); }
.bubble.clarification { border-top: 4px solid var(--purple); }
.bubble.education { border-top: 4px solid var(--green); background: #fcfffd; }
.bubble.refusal { border-top: 4px solid var(--orange); background: var(--orange-bg); }
.bubble.red_flag { border: 2px solid var(--red); background: var(--red-bg); box-shadow: 0 5px 18px rgba(215, 45, 45, .15); }
.bubble.error { color: #962828; border: 1px solid #efbcbc; background: var(--red-bg); }
.bubble.thinking { color: var(--muted); font-style: italic; }
.bubble-label { display: inline-block; margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 800; }
.bubble.red_flag .bubble-label { color: var(--red); }
.assistant-identity { display: inline-block; margin: 0 8px 5px 0; color: var(--muted); font-size: 11px; }
.assistant-notice { margin-top: 4px; color: var(--muted); font-size: 11px; }
.demo-badge { display: inline-block; margin: 0 0 5px; padding: 2px 7px; border-radius: 999px; color: #8a5a00; background: #fff4d6; font-size: 10px; font-weight: 700; }
.citation-box { margin-top: 11px; padding-top: 9px; border-top: 1px dashed #cbd9cf; color: #506057; font-size: 12px; }
.citation-box summary { cursor: pointer; color: var(--green); font-weight: 800; }
.citation-list { padding-top: 7px; }
.citation-item + .citation-item { margin-top: 4px; }
.pending-box { padding: 14px 22px; background: #fff; border-top: 1px solid var(--line); }
.pending-label { margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.option-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.option-btn { border: 1px solid #b9c9de; color: var(--blue-dark); background: #fff; border-radius: 999px; padding: 7px 13px; }
.option-btn.selected { color: #fff; background: var(--blue); border-color: var(--blue); }
.chat-compose { padding: 14px 18px 18px; display: flex; gap: 10px; background: #fff; border-top: 1px solid var(--line); }
.chat-compose input { flex: 1; min-width: 0; border: 1px solid #ccd8e6; border-radius: 12px; padding: 11px 13px; outline: none; }
.chat-compose input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 105, 224, .1); }
.chat-locked { flex: 1; padding: 11px; text-align: center; color: var(--red); background: var(--red-bg); border-radius: 10px; font-weight: 700; }
.thinking-dots::after { content: '…'; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75%, 100% { content: '...'; } }

.summary-status { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.status-cell { padding: 13px; border: 1px solid var(--line); border-radius: 11px; background: #fafcff; }
.status-cell b { display: block; font-size: 18px; color: var(--blue-dark); }
.status-cell span { color: var(--muted); font-size: 12px; }
.data-list { display: grid; gap: 8px; }
.data-row { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.data-row:last-child { border-bottom: 0; }
.data-row strong { text-align: right; }
.tag { display: inline-flex; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; background: #edf2f8; color: #4f6075; }
.tag.green { color: var(--green); background: var(--green-bg); }
.tag.orange { color: var(--orange); background: var(--orange-bg); }
.tag.red { color: var(--red); background: var(--red-bg); }
.tag.blue { color: var(--blue); background: var(--sky); }

.doctor-layout { width: min(1260px, 100%); margin: 0 auto; padding: 24px 20px 70px; }
.doctor-nav { display: flex; gap: 6px; overflow-x: auto; padding: 7px; margin-bottom: 20px; background: #fff; border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); }
.doctor-nav a { flex: none; padding: 8px 14px; border-radius: 8px; color: var(--muted); font-size: 13px; font-weight: 700; }
.doctor-nav a.active { color: #fff; background: var(--teal); }
.doctor-title { display: flex; justify-content: space-between; gap: 15px; margin-bottom: 16px; align-items: flex-start; }
.doctor-title h1 { font-size: 24px; margin-bottom: 3px; }
.operator-pill { padding: 6px 11px; border-radius: 999px; color: var(--teal); background: #eaf8f6; font-size: 12px; font-weight: 800; }
.role-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 24px; }
.role-card { text-align: left; border: 2px solid transparent; background: #fff; border-radius: 15px; padding: 22px; box-shadow: var(--shadow); }
.role-card:hover { border-color: var(--teal); transform: translateY(-2px); }
.role-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 13px; background: #eaf8f6; font-size: 23px; }
.role-card h3 { margin: 12px 0 4px; }
.role-card p { color: var(--muted); font-size: 13px; margin: 0; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { min-height: 145px; }
.kpi .value { font-size: 31px; line-height: 1.2; font-weight: 800; color: var(--navy); margin-top: 14px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi.fail { border-color: #efbcbc; background: var(--red-bg); }
.panel-title { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 13px; }
.panel-title h2, .panel-title h3 { margin: 0; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; background: #fff; }
.table { width: 100%; border-collapse: collapse; min-width: 760px; }
.table th, .table td { padding: 12px 13px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.table th { color: #526176; background: #f6f9fc; font-size: 12px; white-space: nowrap; }
.table td { font-size: 13px; }
.table tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.tabs { display: flex; gap: 7px; margin-bottom: 16px; }
.tab { border: 1px solid var(--line); border-radius: 9px; padding: 8px 13px; background: #fff; color: var(--muted); font-weight: 700; }
.tab.active { color: #fff; background: var(--teal); border-color: var(--teal); }
.json-preview { max-width: 340px; white-space: pre-wrap; word-break: break-word; color: var(--muted); font-size: 11px; }

.modal-mask { position: fixed; inset: 0; z-index: 80; background: rgba(7, 24, 43, .52); }
.modal { position: fixed; z-index: 81; top: 5vh; left: 50%; transform: translateX(-50%); width: min(760px, calc(100% - 28px)); max-height: 90vh; overflow-y: auto; border-radius: 16px; background: #fff; box-shadow: 0 25px 70px rgba(0, 0, 0, .28); }
.modal-head, .modal-foot { padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.modal-foot { border-top: 1px solid var(--line); border-bottom: 0; justify-content: flex-end; }
.modal-body { padding: 20px; }
.dialog-record { display: grid; gap: 8px; padding: 12px; background: #f6f8fb; border-radius: 10px; max-height: 280px; overflow-y: auto; }
.dialog-line { padding: 8px 10px; border-radius: 8px; background: #fff; font-size: 13px; }
.dialog-line.patient { margin-left: 18%; background: var(--sky); }
.dialog-line b { display: block; color: var(--muted); font-size: 11px; }

.loading-card { display: grid; place-items: center; min-height: 220px; color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 3px solid #d8e3f0; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast-wrap { position: fixed; top: 84px; left: 50%; transform: translateX(-50%); z-index: 120; display: grid; gap: 8px; width: min(520px, calc(100% - 28px)); pointer-events: none; }
.toast { color: #fff; background: rgba(16, 35, 63, .96); padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); text-align: center; }
.toast.error { background: rgba(170, 32, 32, .97); }
.toast.success { background: rgba(13, 116, 67, .97); }

@media (max-width: 900px) {
  .grid-2, .grid-3, .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .role-grid { grid-template-columns: 1fr; }
  .public-doctor-grid { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .topbar { min-height: 62px; padding: 9px 13px; }
  .brand-logo { width: 36px; height: 36px; }
  .brand b { font-size: 14px; }
  .brand small, .test-mark { display: none; }
  .page, .doctor-layout { padding: 20px 12px 56px; }
  .card { padding: 17px; border-radius: 13px; }
  .form-grid, .grid-2, .grid-3, .kpi-grid, .summary-status { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .chat-shell { min-height: calc(100vh - 90px); }
  .chat-head, .message-list, .pending-box { padding-left: 13px; padding-right: 13px; }
  .chat-head { flex-wrap: wrap; }
  .message-list { max-height: calc(100vh - 235px); }
  .bubble { max-width: 90%; }
  .chat-compose { padding: 10px; flex-wrap: wrap; }
  .chat-compose input { flex-basis: 100%; }
  .chat-compose .btn { flex: 1; }
  .section-head, .doctor-title { flex-direction: column; }
}
