:root {
  --primary: #2e7d5b;
  --primary-dark: #1f5c42;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #22302b;
  --muted: #8a9a94;
  --border: #e2e8e5;
  --danger: #c0392b;
  --warn: #b9770e;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  overflow: hidden;
}
#app { height: 100%; }
.layout { display: flex; height: 100%; }

/* 左侧菜单 */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--primary-dark), var(--primary));
  color: #fff;
  display: flex;
  flex-direction: column;
}
.brand { padding: 20px 16px 16px; border-bottom: 1px solid rgba(255,255,255,.15); display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.brand-logo { width: 54px; height: 54px; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,.25); object-fit: cover; }
.brand-title h1 { font-size: 20px; letter-spacing: 1px; }
.brand-title span { font-size: 12px; opacity: .8; display: block; margin-top: 3px; }
.menu { flex: 1; padding: 14px 10px; overflow-y: auto; }
.menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; margin-bottom: 4px; border-radius: 10px;
  cursor: pointer; color: rgba(255,255,255,.85); font-size: 15px;
  transition: background .15s;
}
.menu-item:hover { background: rgba(255,255,255,.12); }
.menu-item.active { background: rgba(255,255,255,.22); color: #fff; font-weight: 600; }
.menu-icon { font-size: 18px; }
.user-bar { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.15); display: flex; align-items: center; gap: 8px; }
.user-name { color: #fff; font-size: 13px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.logout { background: rgba(255,255,255,.18); color: #fff; }

/* 登录页 */
.login-wrap { display: flex; align-items: center; justify-content: center; height: 100vh; background: linear-gradient(135deg, #1f5c42, #2e7d5b); }
.login-card { width: 320px; background: #fff; border-radius: 12px; padding: 32px 28px; box-shadow: 0 8px 30px rgba(0,0,0,.25); text-align: center; }
.login-logo { width: 76px; height: 76px; border-radius: 16px; margin: 0 auto 10px; display: block; box-shadow: 0 4px 16px rgba(0,0,0,.12); object-fit: cover; }
.login-card h1 { font-size: 22px; color: var(--primary); margin-bottom: 6px; }
.login-card .muted { color: var(--muted); font-size: 12px; margin-bottom: 20px; }
.login-card input { margin-bottom: 12px; }
.login-card .btn.block { margin-top: 6px; }
.login-card .error { color: var(--danger); font-size: 13px; margin-top: 8px; }

/* 右侧内容 */
.content { flex: 1; overflow-y: auto; padding: 20px; }
.view { max-width: 80%; margin: 0 auto; }

.panel { background: var(--card); border-radius: 12px; padding: 16px; margin-bottom: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.panel-actions { display: inline-flex; align-items: center; gap: 10px; }
.panel-head h2 { font-size: 16px; }

.btn {
  background: var(--primary); color: #fff; border: none; border-radius: 8px;
  padding: 9px 16px; font-size: 14px; cursor: pointer;
  white-space: nowrap; flex-shrink: 0;
}
.btn:disabled { background: #b9cbc3; cursor: not-allowed; }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 5px 12px; font-size: 13px; }
.btn.xs { padding: 3px 9px; font-size: 12px; border-radius: 6px; }
.btn.block { width: 100%; margin-bottom: 12px; }

input, textarea, select {
  width: 100%; border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; font-size: 14px; margin-bottom: 10px; font-family: inherit;
  background: #fff; color: var(--text);
}
.graph-search select { flex-shrink: 0; width: auto; margin-bottom: 0; }
.graph-search .limit-input { flex-shrink: 0; width: 80px; margin-bottom: 0; }
textarea { resize: vertical; }
label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }

/* 问诊 */
.chat-messages { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; max-height: 52vh; overflow-y: auto; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg .bubble { max-width: 80%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; line-height: 1.55; }
.msg.user .bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--card); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg .typing { color: var(--muted); }
.bubble.markdown { white-space: normal; }
.bubble.markdown h1, .bubble.markdown h2, .bubble.markdown h3, .bubble.markdown h4 { margin: 8px 0 3px; font-size: 15px; font-weight: 600; }
.bubble.markdown h1:first-child, .bubble.markdown h2:first-child, .bubble.markdown h3:first-child { margin-top: 0; }
.bubble.markdown p { margin: 3px 0; }
.bubble.markdown ul, .bubble.markdown ol { margin: 3px 0; padding-left: 20px; }
.bubble.markdown li { margin: 2px 0; }
.bubble.markdown li > p { margin: 0; }
.bubble.markdown strong { font-weight: 600; color: #1f5c42; }
.bubble.markdown code { background: #eef1f0; padding: 1px 5px; border-radius: 3px; font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

.diag-card { background: #eef6f2; border: 1px solid #d6e8df; border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-size: 13px; }
.diag-card-head { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.diag-summary { flex: 1; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diag-toggle { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.diag-card-body { padding-top: 4px; }
.diag-row { display: flex; padding: 4px 0; }
.diag-row .label { width: 64px; color: var(--muted); flex-shrink: 0; }
.diag-row .val { flex: 1; }
.badge { color: var(--primary); font-weight: 600; }
.img-upload { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.img-upload label { margin-bottom: 0; cursor: pointer; display: inline-flex; }
.diag-imgs { display: inline-flex; gap: 8px; align-items: center; }
.diag-thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; }

.chat-input { display: flex; align-items: flex-end; gap: 8px; }
.chat-input textarea { flex: 1; margin-bottom: 0; resize: none; max-height: 160px; overflow-y: auto; line-height: 1.5; }
.chat-input .send-btn { background: var(--primary); color: #fff; border: none; border-radius: 20px; padding: 10px 22px; font-size: 14px; cursor: pointer; flex-shrink: 0; transition: background .15s; }
.chat-input .send-btn:hover:not(:disabled) { background: var(--primary-dark); }
.chat-input .send-btn:disabled { background: #b9cbc3; cursor: not-allowed; }

.mention-list { margin-top: 4px; border: 1px solid var(--border); border-radius: 8px; background: #fff; max-height: 200px; overflow-y: auto; }
.mention-item { padding: 8px 12px; cursor: pointer; display: flex; gap: 8px; align-items: center; border-bottom: 1px solid var(--border); }
.mention-item:last-child { border-bottom: none; }
.mention-item:hover { background: #eef6f2; }
.mention-item b { color: var(--primary); }
.mention-item .muted { font-size: 12px; }
.new-session { margin-top: 10px; background: none; border: none; color: var(--muted); font-size: 13px; cursor: pointer; text-decoration: underline; }

/* 知识库 */
.dir-tree { list-style: none; margin-bottom: 12px; }
.dir-tree li { display: flex; justify-content: space-between; align-items: center; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.dir-tree li.selected { background: #eef6f2; color: var(--primary); font-weight: 600; }
.upload-box { display: flex; gap: 8px; align-items: center; }
.upload-box input[type=file] { margin-bottom: 0; font-size: 12px; flex: 1; min-width: 0; }

.doc-item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.doc-name { font-size: 14px; margin-bottom: 6px; }
.progress { height: 8px; background: #eef0ef; border-radius: 4px; overflow: hidden; }
.progress .bar { height: 100%; background: var(--primary); transition: width .5s; }
.progress .bar.failed { background: var(--danger); }
.progress .bar.done { background: #27ae60; }
.doc-meta { display: flex; gap: 12px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }
.doc-stage { display: flex; align-items: center; gap: 10px; margin-top: 6px; font-size: 13px; }
.stage-text { color: var(--primary); font-weight: 600; }

.session-item { padding: 10px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.session-item:hover { background: #f7faf8; }
.session-head { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.session-id { font-weight: 600; color: var(--primary); font-family: monospace; }
.patient-tag { color: var(--primary); font-weight: 600; font-size: 12px; background: #eef6f2; padding: 2px 8px; border-radius: 10px; }
.badge-done { color: #27ae60; }
.badge-active { color: var(--warn); }
.session-actions { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; }
.patient-bind { position: relative; display: inline-flex; }
.patient-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 10px; font-size: 12px; cursor: pointer; border: 1px solid #d6e8df; background: #eef6f2; color: var(--primary); font-weight: 600; white-space: nowrap; }
.patient-chip.unbound { background: transparent; color: var(--muted); border: 1px dashed var(--border); font-weight: 400; }
.patient-chip .caret { font-size: 9px; opacity: .7; }
.bind-menu { position: absolute; top: calc(100% + 4px); left: 0; z-index: 40; min-width: 160px; max-height: 280px; overflow-y: auto; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.14); text-align: left; }
.bind-menu-head { padding: 8px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); }
.bind-menu-item { padding: 8px 12px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.bind-menu-item:hover { background: #eef6f2; }
.bind-menu-item.active { color: var(--primary); font-weight: 600; }
.bind-menu-item.danger { color: var(--danger); }
.patient-sessions { margin-top: 8px; padding: 8px 0 0; border-top: 1px dashed var(--border); }
.session-summary { margin-top: 4px; font-size: 12px; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; }
.session-detail { margin: 0 0 12px; padding: 12px; background: #fafbfa; border: 1px solid var(--border); border-radius: 10px; }
.chunk-panel { margin: 0 0 12px; padding: 12px; background: #fafbfa; border: 1px solid var(--border); border-radius: 10px; }

.patient-item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.patient-head { display: flex; align-items: center; gap: 10px; font-size: 14px; flex-wrap: wrap; }
.patient-name { font-weight: 600; color: var(--text); }
.patient-detail { margin-top: 4px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-bottom: 12px; }
.form-grid input, .form-grid select { margin-bottom: 0; }
.detail-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.detail-head h3 { font-size: 14px; }
.status-processing { color: var(--warn); }
.status-done { color: #27ae60; }
.status-failed { color: var(--danger); }
.error { color: var(--danger); font-size: 12px; margin-top: 4px; }

.chunk { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.chunk-head { margin-bottom: 6px; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.chunk-head .muted { color: var(--muted); font-size: 12px; }
.chunk-actions { margin-left: auto; display: inline-flex; gap: 6px; }
.chunk-text { font-size: 13px; line-height: 1.6; color: #45504b; white-space: pre-wrap; max-height: 120px; overflow-y: auto; }

.pager { display: flex; align-items: center; justify-content: center; gap: 6px; padding-top: 8px; flex-wrap: wrap; }
.pager-info { font-size: 13px; color: var(--muted); }
.pager .btn.active { background: var(--primary-dark); }

/* 图谱 */
.graph-search { display: flex; gap: 8px; }
.graph-search input { flex: 1; margin-bottom: 0; }
.graph-presets { display: flex; align-items: center; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.graph-presets .muted { font-size: 12px; color: var(--muted); }
.graph-stats { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; align-items: center; }
.stat b { font-size: 22px; color: var(--primary); }
.stat span { font-size: 12px; color: var(--muted); }
.stat-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { color: #fff; font-size: 12px; padding: 3px 9px; border-radius: 12px; cursor: pointer; user-select: none; }
.tag.off { opacity: .35; text-decoration: line-through; }
.graph-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; padding: 8px 2px; }
.legend-item { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: #556; cursor: pointer; user-select: none; padding: 2px 6px; border-radius: 6px; }
.legend-item:hover { background: #f0f4f2; }
.legend-item.off { opacity: .35; text-decoration: line-through; }
.legend-item .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.graph-canvas { width: 100%; height: 520px; }
.graph-canvas:fullscreen { height: 100vh; width: 100vw; background: #fff; }

/* 模型/提示词 */
.health { margin-top: 4px; }
.health-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.health-row .ok { color: #27ae60; }
.health-row .warn { color: var(--warn); }

/* 免登录 token 访问布局 */
.token-layout { height: 100vh; height: 100dvh; display: flex; flex-direction: column; background: var(--bg); }
.token-header { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--primary); color: #fff; flex-shrink: 0; }
.token-header-logo { width: 28px; height: 28px; border-radius: 6px; }
.token-header span { font-size: 15px; font-weight: 600; }
.token-layout .view.chat { max-width: 760px; margin: 0 auto; width: 100%; flex: 1; display: flex; flex-direction: column; padding: 12px; overflow: hidden; }
.token-layout .chat-messages { flex: 1; max-height: none; overflow-y: auto; }
.token-error { text-align: center; padding: 60px 20px; }
.token-error h2 { margin: 12px 0 8px; }
.token-error p { color: var(--muted); }

.access-usage { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.access-usage h3 { font-size: 14px; margin-bottom: 8px; }
.usage-link { color: var(--primary); font-family: monospace; word-break: break-all; }
.token-gen-row { display: flex; gap: 8px; align-items: center; }
.token-gen-row input { flex: 1; margin-bottom: 0; }

/* 全局弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-card { width: 100%; max-width: 380px; background: #fff; border-radius: 14px; padding: 20px; box-shadow: 0 12px 40px rgba(0,0,0,.2); }
.modal-head { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 12px; }
.modal-logo { width: 24px; height: 24px; border-radius: 6px; }
.modal-body { font-size: 14px; color: #45504b; white-space: pre-wrap; word-break: break-word; line-height: 1.6; margin-bottom: 14px; }
.modal-input { margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-actions .btn { margin-bottom: 0; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.modal-fade-enter-active, .modal-fade-leave-active { transition: opacity .2s; }
.modal-fade-enter-from, .modal-fade-leave-to { opacity: 0; }

/* 图片查看器（点击缩略图放大） */
.lightbox-mask { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 110; padding: 24px; }
.lightbox-img { max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: 0 8px 40px rgba(0,0,0,.5); object-fit: contain; }
.lightbox-title { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); color: #fff; font-size: 14px; background: rgba(0,0,0,.4); padding: 4px 12px; border-radius: 20px; }
.lightbox-close { position: absolute; top: 12px; right: 18px; color: #fff; font-size: 26px; cursor: pointer; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; }

/* 移动端 token 问诊：触屏适配 */
.token-layout.mobile { background: #fff; }
.token-layout.mobile .token-header { padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
.token-layout.mobile .view.chat { padding: 10px; }
.token-layout.mobile .diag-card { padding: 8px 12px; margin-bottom: 8px; }
.token-layout.mobile .diag-card-head { min-height: 28px; }
.token-layout.mobile .img-upload { gap: 10px; }
.token-layout.mobile .img-upload .btn { padding: 12px 16px; font-size: 15px; border-radius: 12px; }
.token-layout.mobile .chat-input textarea { font-size: 16px; padding: 12px; }
.token-layout.mobile .send-btn { padding: 12px 22px; font-size: 16px; }
.token-layout.mobile .diag-thumb { width: 64px; height: 64px; }
.token-layout.mobile .bubble { max-width: 92%; }
.token-layout.mobile .chat-input { padding-bottom: env(safe-area-inset-bottom, 0px); }

/* 移动端：侧栏收窄为图标条 */
@media (max-width: 720px) {
  .sidebar { width: 60px; }
  .brand { padding: 12px 6px; text-align: center; }
  .brand-logo { width: 36px; height: 36px; border-radius: 8px; }
  .brand-title { display: none; }
  .menu { padding: 10px 6px; }
  .menu-item { justify-content: center; padding: 12px 6px; }
  .menu-label { display: none; }
  .menu-icon { font-size: 22px; }
  .content { padding: 12px; }
}
