:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --ink-2: #4b5866;
  --ink-3: #8794a3;
  --line: #e6eaf0;
  --brand: #0f7b6c;
  --brand-soft: #e6f4f1;
  --warn: #c2410c;
  --warn-soft: #fff1e8;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --ok: #067647;
  --ok-soft: #e7f6ee;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}
button { font-family: inherit; }
.app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- 左侧导航 ---------- */
.rail {
  width: 224px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 0 6px 18px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #12907f, #0b5f55);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 18px;
}
.brand-name { font-weight: 700; letter-spacing: .5px; }
.brand-sub { font-size: 11px; color: var(--ink-3); letter-spacing: 1px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 0; border-radius: 9px;
  background: transparent; color: var(--ink-2);
  font-size: 13.5px; cursor: pointer; text-align: left; width: 100%;
}
.nav-item span { width: 16px; opacity: .65; font-size: 13px; }
.nav-item:hover { background: #f2f5f8; color: var(--ink); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item.active span { opacity: 1; }
.rail-foot { margin-top: auto; }
.rail-note { font-size: 11px; color: var(--ink-3); padding: 10px 12px 0; }

/* ---------- 主区 ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 20px 28px 14px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.topbar h1 { margin: 0; font-size: 19px; letter-spacing: .3px; }
.topbar-actions { display: flex; gap: 8px; }
.muted { color: var(--ink-3); margin: 4px 0 0; font-size: 12.5px; }
.view { flex: 1; overflow: auto; padding: 22px 28px 40px; }

/* ---------- 通用组件 ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 14px; border-radius: 9px; cursor: pointer; font-size: 13px;
}
.btn:hover { border-color: #cfd8e3; background: #fbfcfd; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #0c6a5d; }
.btn.ghost { background: #fff; }
.btn.sm { padding: 6px 10px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; cursor: pointer; color: var(--ink-3); font-size: 14px; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }
.card h3 { margin: 0 0 12px; font-size: 14.5px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.stat { padding: 16px 18px; }
.stat .k { font-size: 12px; color: var(--ink-3); }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: .5px; }
.stat .v small { font-size: 13px; font-weight: 500; color: var(--ink-3); margin-left: 4px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
}
.badge.won { background: var(--ok-soft); color: var(--ok); }
.badge.lost { background: var(--danger-soft); color: var(--danger); }
.badge.unknown { background: #eef1f5; color: var(--ink-2); }
.badge.new { background: #eef1f5; color: var(--ink-2); }
.badge.transcribed { background: var(--warn-soft); color: var(--warn); }
.badge.analyzed { background: var(--brand-soft); color: var(--brand); }

table.list { width: 100%; border-collapse: collapse; }
table.list th {
  text-align: left; font-size: 12px; color: var(--ink-3); font-weight: 500;
  padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.list td { padding: 12px; border-bottom: 1px solid #f1f4f8; font-size: 13px; }
table.list tr:hover td { background: #fbfcfd; }
table.list tr { cursor: pointer; }
.empty { padding: 44px; text-align: center; color: var(--ink-3); }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.input, .select, textarea {
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px;
  font-size: 13px; background: #fff; color: var(--ink); font-family: inherit; outline: none;
}
.input:focus, .select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; line-height: 1.65; width: 100%; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--ink-3); line-height: 1.6; margin-top: 6px; }

/* ---------- 详情 ---------- */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.detail-head h2 { margin: 0 0 6px; font-size: 17px; }
.meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; color: var(--ink-3); font-size: 12.5px; }
.detail-grid { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 16px; align-items: start; }
.script-lines { max-height: 520px; overflow: auto; padding: 6px 2px; }
.line { display: flex; gap: 8px; padding: 7px 8px; border-radius: 8px; align-items: flex-start; }
.line:hover { background: #f7f9fb; }
.line .who {
  flex: none; width: 58px; font-size: 11.5px; padding: 3px 0; text-align: center;
  border-radius: 6px; cursor: pointer; user-select: none;
}
.line.consultant .who { background: var(--brand-soft); color: var(--brand); }
.line.doctor .who { background: #e8f0fb; color: #1d4ed8; }
.line.patient .who { background: var(--warn-soft); color: var(--warn); }
.line.unknown .who { background: #eef1f5; color: var(--ink-3); }
.line .txt { line-height: 1.7; font-size: 13px; color: var(--ink); }
.line .ts { margin-left: auto; font-size: 11px; color: var(--ink-3); flex: none; }
.visit-row > td { background: #f6faf9; border-top: 1px solid #e2ece9; }
.visit-row .v-name { font-weight: 600; font-size: 13.5px; color: var(--ink); }
.visit-row .v-meta { color: var(--ink-3); font-size: 12px; margin-left: 6px; }
.seg-chip { display: inline-block; padding: 1px 7px; border-radius: 999px; background: #eef1f5; color: var(--ink-3); font-size: 11.5px; }
.visit-sep { margin: 14px 0 8px; padding: 6px 10px; border-radius: 8px; background: #eef6f4; color: #2f6b60; font-size: 12px; font-weight: 600; }

.section-title { display: flex; align-items: center; gap: 8px; margin: 20px 0 10px; font-size: 13.5px; font-weight: 600; }
.section-title i { width: 3px; height: 14px; background: var(--brand); border-radius: 2px; display: inline-block; }
.kv-list { display: flex; flex-direction: column; gap: 8px; }
.chip { display: inline-block; background: #f2f5f8; border-radius: 7px; padding: 5px 9px; font-size: 12.5px; margin: 0 6px 6px 0; line-height: 1.5; }
.chip.hot { background: var(--warn-soft); color: var(--warn); }
.quote { border-left: 3px solid var(--line); padding: 2px 0 2px 10px; color: var(--ink-2); font-size: 12.5px; margin: 6px 0; line-height: 1.65; }
.rewrite { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.rewrite .old { color: var(--ink-3); text-decoration: line-through; font-size: 12.5px; line-height: 1.65; }
.rewrite .new { color: var(--ink); font-size: 13px; line-height: 1.7; margin-top: 6px; }
.rewrite .why { color: var(--ink-3); font-size: 12px; margin-top: 6px; line-height: 1.6; }

.prob { display: flex; align-items: center; gap: 10px; }
.prob-bar { flex: 1; height: 7px; border-radius: 999px; background: #eef1f5; overflow: hidden; }
.prob-bar i { display: block; height: 100%; background: linear-gradient(90deg, #d97706, #0f7b6c); }

/* ---------- 洞察 ---------- */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 180px 1fr 34px; gap: 10px; align-items: center; font-size: 12.5px; }
.bar-track { height: 8px; background: #eef1f5; border-radius: 999px; overflow: hidden; }
.bar-track i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.bar-track.lost i { background: #e0724a; }

/* ---------- 弹窗 / 提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(14px);
  background: #17202a; color: #fff; padding: 10px 16px; border-radius: 9px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .22s; max-width: 70vw; z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }
.modal-wrap {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .38);
  display: grid; place-items: center; z-index: 50; padding: 24px;
}
.modal-wrap[hidden] { display: none; }
.modal {
  background: #fff; border-radius: 14px; width: min(620px, 100%);
  max-height: 86vh; display: flex; flex-direction: column; box-shadow: 0 24px 64px rgba(16,24,40,.24);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 18px; overflow: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.spinner {
  width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { color: var(--ink-3); font-size: 13px; padding: 20px 0; }

/* ---------- 登录页 ---------- */
.login-wrap {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  background: linear-gradient(160deg, #f3f7f6 0%, #eaf1ef 60%, #e6eeec 100%);
}
.login-wrap[hidden] { display: none; }
.login-card {
  width: min(380px, calc(100vw - 40px));
  background: #fff; border-radius: 16px; padding: 30px 26px 22px;
  box-shadow: 0 18px 50px rgba(15, 60, 50, .13);
  display: flex; flex-direction: column; gap: 14px;
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.login-brand .logo {
  width: 40px; height: 40px; border-radius: 11px; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-size: 20px; font-weight: 700;
}
.login-card .field { display: flex; flex-direction: column; gap: 6px; }
.login-card .field span { font-size: 12.5px; color: var(--ink-3); }
.login-card input {
  height: 38px; border-radius: 9px; border: 1px solid #d5dfdc;
  padding: 0 11px; font-size: 14px; outline: none; background: #fbfdfc;
}
.login-card input:focus { border-color: var(--brand); background: #fff; }
.login-err { min-height: 16px; font-size: 12.5px; color: var(--danger); }
.login-card .btn { height: 40px; font-size: 14px; }
.login-hint { font-size: 11.5px; color: var(--ink-3); text-align: center; margin: 0; }

/* 左下角当前用户 */
.rail-user {
  margin: 8px 10px 0; padding: 8px 10px; border-radius: 9px;
  background: #f4f8f7; font-size: 12px; color: var(--ink-2);
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
.rail-user b { font-weight: 600; color: var(--ink); }
.rail-user .role { font-size: 11px; color: var(--brand); }
.rail-user button { border: 0; background: none; color: var(--ink-3); cursor: pointer; font-size: 11.5px; padding: 2px 4px; }
.rail-user button:hover { color: var(--danger); }

/* 账号管理 */
.user-row td { vertical-align: middle; }
.role-badge { font-size: 11.5px; padding: 2px 8px; border-radius: 20px; background: #eef4f2; color: #2f6b60; }
.role-badge.admin { background: #eef2ff; color: #3b4bb0; }
.role-badge.supervisor { background: #fff5e8; color: #9a6212; }

/* 卡片标题行（列表页统一用） */
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 15px 16px 6px;
}
.card-head h3 { margin: 0; }
.card > table.list { margin-bottom: 2px; }
.card > .muted { padding: 4px 16px 14px; }

.rail-user { align-items: center; }
.rail-user > span { display: flex; flex-direction: column; gap: 1px; min-width: 0; line-height: 1.35; }
.rail-user b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-user .role { font-size: 10.5px; color: var(--ink-3); white-space: nowrap; }
.rail-user button { flex: 0 0 auto; white-space: nowrap; border-left: 1px solid #e3ebe9 !important; padding-left: 8px !important; }
