:root {
  --ink: #1c2b26;
  --muted: #60706a;
  --paper: #f5f2ea;
  --card: #fffdf8;
  --line: #e2dbcc;
  --green: #1f4d3a;
  --green-2: #2f6b52;
  --gold: #b98a3c;
  --red: #a83232;
  --amber: #b4761f;
  --shadow: 0 10px 30px rgba(28, 43, 38, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 10% -10%, #e9e3d5 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #e4ece5 0%, transparent 55%),
    var(--paper);
  color: var(--ink);
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.65;
}

h1, h2, h3 { font-family: "Noto Serif SC", "Songti SC", "SimSun", serif; font-weight: 700; margin: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,253,248,.95), rgba(255,253,248,.7));
  backdrop-filter: blur(6px); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; gap: 14px; align-items: center; }
.seal {
  width: 46px; height: 46px; border-radius: 10px; background: var(--green); color: #f7f1e3;
  display: grid; place-items: center; font-family: "Songti SC", serif; font-size: 24px;
  box-shadow: inset 0 0 0 2px rgba(247,241,227,.35);
}
.topbar h1 { font-size: 22px; letter-spacing: 3px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.status { display: flex; gap: 8px; align-items: center; }
.badge { padding: 4px 10px; border-radius: 999px; background: var(--gold); color: #fff; font-size: 12px; }
.badge.ghost { background: transparent; color: var(--green); border: 1px solid var(--line); }

.grid {
  display: grid; grid-template-columns: 320px minmax(420px, 1fr) 360px;
  gap: 18px; padding: 20px 24px 8px; align-items: start;
}
@media (max-width: 1280px) { .grid { grid-template-columns: 320px 1fr; } .col:last-child { grid-column: 1 / -1; } }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

.col { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 16px 18px; box-shadow: var(--shadow);
}
.card h2 { font-size: 16px; letter-spacing: 1px; margin-bottom: 12px; color: var(--green); }
.card h2::before { content: ""; display: inline-block; width: 4px; height: 14px; background: var(--gold); margin-right: 8px; border-radius: 2px; vertical-align: -2px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); flex: 1; }
label.full { width: 100%; margin: 8px 0; }
label.checkline { flex-direction: row; align-items: center; gap: 6px; margin: 6px 0; color: var(--ink); }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%; outline: none;
}
input[type="checkbox"] { width: auto; accent-color: var(--green); }
.row button { flex: 0 0 auto; white-space: nowrap; }
input:focus, select:focus, textarea:focus { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(47,107,82,.12); }
.row { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 8px; }

button {
  font: inherit; cursor: pointer; border-radius: 9px; padding: 9px 14px; border: 1px solid transparent;
  transition: transform .06s ease, background .15s ease;
}
button:active { transform: translateY(1px); }
button.primary { background: var(--green); color: #f7f1e3; width: 100%; margin-top: 10px; }
button.primary:hover { background: var(--green-2); }
button.ghost { background: #fff; border-color: var(--line); color: var(--green); }
button.ghost:hover { background: #f2efe6; }
button:disabled { opacity: .45; cursor: not-allowed; }
.actions { display: flex; gap: 8px; margin-top: 10px; }
.actions button { flex: 1; }

.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.tiny { color: var(--muted); font-size: 11px; }
.hidden { display: none !important; }

.preview { margin-top: 10px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.preview img { display: block; width: 100%; }

/* 分值区 */
.scorecard { min-height: 420px; }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.empty-icon {
  width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 50%; border: 1px dashed var(--gold);
  display: grid; place-items: center; font-family: "Songti SC", serif; font-size: 28px; color: var(--gold);
}
.scorehead { display: flex; gap: 18px; align-items: center; }
.ringwrap { position: relative; width: 150px; height: 150px; flex: 0 0 auto; }
.ring { width: 150px; height: 150px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring-bg { stroke: #ece6d8; }
.ring-fg { stroke: var(--green); stroke-linecap: round; stroke-dasharray: 327; stroke-dashoffset: 327; transition: stroke-dashoffset .9s ease, stroke .4s; }
.ringtext { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ringtext span { font-size: 40px; font-weight: 700; font-family: "Noto Serif SC", serif; color: var(--green); line-height: 1; }
.ringtext small { color: var(--muted); font-size: 12px; margin-top: 4px; }
.scoremeta { flex: 1; }
.metaRow { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--line); padding: 5px 0; font-size: 12px; color: var(--muted); }
.metaRow b { color: var(--ink); }
.issues { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.issue { font-size: 12px; color: var(--amber); }

.dims { margin-top: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; }
@media (max-width: 700px) { .dims { grid-template-columns: 1fr; } }
.dim { font-size: 12px; }
.dimtop { display: flex; justify-content: space-between; color: var(--muted); }
.dimtop b { color: var(--ink); }
.bar { height: 7px; background: #eee8da; border-radius: 999px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--green-2); transition: width .7s ease; }
.dim .ev { color: var(--muted); font-size: 11px; margin-top: 3px; }

.hints { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.hints-title { font-size: 12px; color: var(--muted); margin-right: 8px; }
.chips { display: inline-flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { background: #eef3ee; color: var(--green); border: 1px solid #d8e3d9; border-radius: 999px; padding: 2px 10px; font-size: 12px; }
.narrative { margin-top: 14px; background: #faf7ef; border-left: 3px solid var(--gold); padding: 10px 12px; border-radius: 0 8px 8px 0; }
.narrative p { margin: 0 0 8px; font-size: 13px; }
.explain { margin-top: 10px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 13px; white-space: pre-wrap; }
.rawbox { margin-top: 14px; font-size: 12px; color: var(--muted); }
.rawbox pre { max-height: 260px; overflow: auto; background: #fbf9f3; border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 11px; }

/* 聊天 */
.chatcard { display: flex; flex-direction: column; min-height: 420px; }
.chatlog { flex: 1; overflow-y: auto; max-height: 340px; display: flex; flex-direction: column; gap: 8px; padding: 4px 2px; }
.msg { padding: 8px 11px; border-radius: 10px; font-size: 13px; max-width: 92%; white-space: pre-wrap; }
.msg.sys { background: #f2efe6; color: var(--muted); align-self: center; font-size: 12px; }
.msg.patient { background: var(--green); color: #f7f1e3; align-self: flex-end; }
.msg.assistant { background: #fff; border: 1px solid var(--line); align-self: flex-start; }
.msg.doctor { background: #f6efe1; border: 1px solid #e7d9bd; align-self: flex-start; }
.chatinput { margin-top: 10px; }
.chatinput input { flex: 1; }
.chatinput button { width: auto; margin: 0; }

/* 结果 */
.result { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.sx { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fff; }
.sx h3 { font-size: 14px; margin-bottom: 4px; }
.sx .conf { float: right; font-size: 11px; color: var(--gold); }
.sx ul { margin: 4px 0 0 16px; padding: 0; color: var(--muted); font-size: 12px; }
.principle { background: #eef3ee; border-radius: 8px; padding: 8px 10px; color: var(--green); font-weight: 600; }
table.herbs { width: 100%; border-collapse: collapse; font-size: 12px; }
table.herbs th, table.herbs td { border-bottom: 1px solid var(--line); padding: 5px 4px; text-align: left; }
table.herbs th { color: var(--muted); font-weight: 500; }
.safety { border-radius: 8px; padding: 8px 10px; font-size: 12px; }
.safety.block { background: #fbeeee; color: var(--red); border: 1px solid #f0d3d3; }
.safety.warn { background: #fdf6e8; color: var(--amber); border: 1px solid #f0e2c4; }
.safety.info { background: #f4f4ef; color: var(--muted); border: 1px solid var(--line); }
.rec dl { display: grid; grid-template-columns: 74px 1fr; gap: 4px 10px; margin: 0; font-size: 12px; }
.rec dt { color: var(--muted); }
.kb { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.kbhit { border-left: 3px solid var(--gold); padding-left: 8px; font-size: 12px; }
.kbhit b { color: var(--green); }
.kbhit span { color: var(--muted); }

.sign { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.sign button { width: 100%; margin: 0; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 18px 24px 28px; }
.foot p { margin: 2px 0; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #22352e; color: #f7f1e3; padding: 10px 16px; border-radius: 10px;
  font-size: 13px; box-shadow: var(--shadow); max-width: 80vw; z-index: 50;
}
.toast.error { background: #6b2323; }

/* ===================== 管理后台 ===================== */
body.admin { background: var(--paper); }
.login-mask { position: fixed; inset: 0; background: rgba(20, 30, 26, .55); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 100; }
.login-card { background: var(--card); padding: 28px; border-radius: 16px; width: 380px; max-width: 92vw; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-card .seal { margin: 0 auto; }
.login-card h1 { font-size: 20px; letter-spacing: 2px; }
.login-card label { text-align: left; }
.admin-layout { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 18px; padding: 18px 24px 40px; align-items: start; }
.admin-nav { position: sticky; top: 84px; display: flex; flex-direction: column; gap: 6px; }
.navitem { text-align: left; background: transparent; border: 1px solid transparent; color: var(--muted); padding: 9px 12px; border-radius: 9px; }
.navitem:hover { background: #efeade; }
.navitem.active { background: var(--green); color: #f7f1e3; }
.admin-main { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.tab-panel { display: none; flex-direction: column; gap: 16px; }
.tab-panel.active { display: flex; }
.kv-grid { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 8px 12px; font-size: 13px; }
.kv-k { color: var(--muted); }
.kv-v { word-break: break-all; }
.endpoint { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; background: #fff; }
.endpoint-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.endpoint .row.tight { gap: 8px; }
.tasks { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 0 8px; font-size: 12px; color: var(--muted); }
textarea.code { width: 100%; min-height: 430px; font-family: Consolas, "Cascadia Mono", monospace; font-size: 12px; line-height: 1.5; background: #fbf9f3; }
pre.code { background: #fbf9f3; border: 1px solid var(--line); border-radius: 10px; padding: 10px; max-height: 240px; overflow: auto; font-size: 12px; }
pre.code.small { max-height: 180px; font-size: 11px; }
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
table.tbl th, table.tbl td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
table.tbl th { color: var(--muted); font-weight: 500; background: #faf7ef; }
button.small { padding: 5px 10px; font-size: 12px; }
button.inline { width: auto; margin: 0; }
button.danger { color: var(--red); border-color: #efd4d4; }
.rubric-head { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.sub-title { font-size: 13px; color: var(--green); margin: 18px 0 8px; }
.inline-row { margin: 6px 0 10px; }
label.wide { flex: 2; }
@media (max-width: 900px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-nav { position: static; flex-direction: row; overflow-x: auto; }
  .navitem { white-space: nowrap; }
}
.rubric-head button { width: auto; margin: 0; }
