/* 涨飞工作台 v3 · 共用样式
 * 视觉规范：底色 #F4F6F9 / 面板 #FFFFFF / 边框 #E2E6EE / 主文字 #1B2230 / 次文字 #5C6675
 * 门店版强调色 #2F6FB3（蓝）；母体版强调色 #1F6B5E（墨绿）。
 * 蓝色只表示操作与选中，不表示业务好坏：涨跌用中文字与箭头，不用颜色替代判断。
 */

:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #fafbfd;
  --line: #e2e6ee;
  --line-strong: #cfd6e2;
  --ink: #1b2230;
  --ink-2: #5c6675;
  --ink-3: #8b94a3;
  --accent: #2f6fb3;
  --accent-soft: #eaf2fb;
  --ok-bg: #e8f5ec;  --ok-ink: #1d6b36;
  --warn-bg: #fdf4e3; --warn-ink: #8a5a00;
  --bad-bg: #fdecec;  --bad-ink: #a02222;
  --info-bg: #eef2f8; --info-ink: #3c4a60;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .05), 0 8px 24px rgba(20, 30, 50, .05);
  --sidebar-w: 232px;
  --topbar-h: 58px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px;
}

body[data-product="mother"] {
  --accent: #1f6b5e;
  --accent-soft: #e7f3f0;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/22px -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
        "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h1 { font-size: 22px; line-height: 30px; letter-spacing: -.2px; }
h2 { font-size: 16px; line-height: 24px; }
h3 { font-size: 14px; line-height: 22px; }
button { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.muted { color: var(--ink-2); }
.tiny { font-size: 12px; line-height: 18px; color: var(--ink-2); }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- 登录 / 初始化 */
.auth-wrap {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr;
  background: var(--bg);
}
.auth-hero {
  padding: 56px 56px 40px; display: flex; flex-direction: column; justify-content: space-between;
  background: linear-gradient(160deg, #12305a 0%, #1f4f7f 55%, #2f6fb3 100%);
  color: #fff;
}
body[data-product="mother"] .auth-hero {
  background: linear-gradient(160deg, #0e332c 0%, #17483f 55%, #1f6b5e 100%);
}
.auth-hero .brandline { display: flex; align-items: center; gap: 10px; font-size: 15px;
  letter-spacing: .5px; opacity: .92; }
.auth-hero .dot { width: 9px; height: 9px; border-radius: 50%; background: #8fd0ff; }
body[data-product="mother"] .auth-hero .dot { background: #7fd8c4; }
.auth-hero h1 { font-size: 34px; line-height: 44px; margin: 40px 0 12px; font-weight: 600; }
.auth-hero p { color: rgba(255,255,255,.78); max-width: 460px; font-size: 14px; line-height: 24px; }
.auth-hero ul { margin: 28px 0 0; padding: 0; list-style: none; display: grid; gap: 12px;
  max-width: 460px; }
.auth-hero li { position: relative; padding-left: 20px; color: rgba(255,255,255,.86);
  font-size: 13px; }
.auth-hero li::before { content: ""; position: absolute; left: 0; top: 8px; width: 6px;
  height: 6px; border-radius: 2px; background: rgba(255,255,255,.5); }
.auth-foot { font-size: 12px; color: rgba(255,255,255,.55); }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 40px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { font-size: 22px; margin-bottom: 6px; }
.auth-card .sub { color: var(--ink-2); margin-bottom: 24px; font-size: 13px; }
.auth-card .form { gap: 14px; }
.auth-card .btn-primary { width: 100%; height: 42px; margin-top: 6px; }
.auth-msg { margin-top: 14px; font-size: 13px; }
.auth-msg.err { color: var(--bad-ink); background: var(--bad-bg); padding: 10px 12px;
  border-radius: var(--radius-sm); }
.auth-switch { margin-top: 18px; font-size: 13px; color: var(--ink-2); }

/* ---------------------------------------------------------------- 骨架 */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar-head { padding: 16px 18px 12px; border-bottom: 1px solid var(--line); }
.product-name { display: flex; align-items: center; gap: 8px; font-size: 15px;
  font-weight: 600; letter-spacing: .2px; }
.product-name .mark {
  width: 22px; height: 22px; border-radius: 7px; background: var(--accent);
  color: #fff; font-size: 12px; display: grid; place-items: center; font-weight: 600;
}
.tenant-name { margin-top: 6px; font-size: 12px; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { flex: 1; overflow-y: auto; padding: 10px 10px 20px; }
.nav-group { margin-top: 12px; }
.nav-group:first-child { margin-top: 4px; }
.nav-title { font-size: 11px; letter-spacing: .8px; color: var(--ink-3);
  padding: 6px 10px; text-transform: uppercase; }
.nav-item {
  display: block; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--ink);
  font-size: 13.5px; margin: 1px 0; border-left: 2px solid transparent;
}
.nav-item:hover { background: var(--panel-2); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-foot { border-top: 1px solid var(--line); padding: 12px 14px; font-size: 12px;
  color: var(--ink-2); display: grid; gap: 6px; }
.sidebar-foot .row { display: flex; justify-content: space-between; gap: 8px; }

.main { min-width: 0; display: flex; flex-direction: column; }

/* #view 必须能收缩：它是 flex 子项，默认 min-width:auto，
   里面一放宽表格就会把整列撑出视口，右侧列被裁掉而且页面不出现滚动条。
   加上 min-width:0 之后，宽表格由 .table-wrap 自己横向滚动。 */
#view { flex: 1; min-width: 0; }

/* 授权横幅：贴在顶栏下方，不遮挡内容，不弹窗打断操作 */
.lic-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 9px 20px; font-size: 13px; border-bottom: 1px solid var(--line);
}
.lic-bar > span { flex: 1; min-width: 240px; }
.lic-bar.warn { background: var(--warn-bg); color: var(--warn-ink); }
.lic-bar.bad { background: var(--bad-bg); color: var(--bad-ink); }
.lic-bar .btn { background: #fff; border-color: currentColor; color: inherit; }

/* 授权页的状态条 */
.lic-hero {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 18px 20px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--panel);
}
.lic-hero .lic-days { font-size: 30px; font-weight: 600; line-height: 1.1; }
.lic-hero.ok { border-color: #bfe0cb; background: linear-gradient(180deg, #f6fbf7, #fff); }
.lic-hero.warn { border-color: #f0d8a8; background: linear-gradient(180deg, #fffaf0, #fff); }
.lic-hero.bad { border-color: #f0c2c2; background: linear-gradient(180deg, #fff5f5, #fff); }
.lic-code {
  font: 12px/18px ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all; background: var(--panel-2); border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm); padding: 10px 12px; color: var(--ink-2);
}

.topbar {
  height: var(--topbar-h); background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; padding: 0 20px;
  position: sticky; top: 0; z-index: 20;
}
.topbar .crumbs { font-size: 13px; color: var(--ink-2); display: flex; gap: 6px;
  align-items: center; }
.topbar .spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--panel-2);
  font-size: 12.5px; color: var(--ink-2); cursor: pointer;
}
.chip:hover { border-color: var(--line-strong); }
.chip .k { color: var(--ink); font-weight: 600; }
.chip.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: #f0ddb4; }
.chip.bad { background: var(--bad-bg); color: var(--bad-ink); border-color: #f3c8c8; }
.chip.ok { background: var(--ok-bg); color: var(--ok-ink); border-color: #c6e5d0; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent); display: grid; place-items: center; font-size: 12px;
  font-weight: 600; border: none; cursor: pointer;
}
.page { padding: 22px 24px 48px; max-width: 1320px; width: 100%; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.page-head .titles { flex: 1; min-width: 0; }
.page-head p { margin: 6px 0 0; color: var(--ink-2); font-size: 13px; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------- 组件 */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.card.tight { padding: 14px; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.card-head h2 { flex: 1; }
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); }
@media (max-width: 1180px) { .grid.c4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid.c3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid.side { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; width: 260px; transform: translateX(-100%);
    transition: transform .2s ease; }
  .sidebar.open { transform: none; box-shadow: 0 10px 40px rgba(0,0,0,.18); }
  .grid.c4, .grid.c3, .grid.c2 { grid-template-columns: 1fr; }
  .page { padding: 16px 14px 40px; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
}

.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.kpi .label { font-size: 12.5px; color: var(--ink-2); display: flex; align-items: center;
  gap: 6px; }
.kpi .value { font-size: 26px; line-height: 32px; font-weight: 600; letter-spacing: -.5px;
  font-variant-numeric: tabular-nums; }
.kpi .value .unit { font-size: 13px; font-weight: 500; color: var(--ink-2);
  margin-left: 4px; letter-spacing: 0; }
.kpi .foot { font-size: 12px; color: var(--ink-3); display: flex; gap: 8px;
  align-items: center; }
.kpi.degraded { border-style: dashed; }
.delta-up { color: #a02222; }
.delta-down { color: #1d6b36; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap; }
th { background: var(--panel-2); color: var(--ink-2); font-weight: 500; font-size: 12px;
  position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
td.wrap, th.wrap { white-space: normal; min-width: 220px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #fbfcfe; }

.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px;
  border-radius: 999px; font-size: 12px; background: var(--info-bg); color: var(--info-ink); }
.badge.ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge.bad { background: var(--bad-bg); color: var(--bad-ink); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink);
  cursor: pointer; font-size: 13px; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); border-color: var(--accent); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--panel-2); color: var(--ink); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-danger { color: var(--bad-ink); border-color: #f3c8c8; background: var(--bad-bg); }

.form { display: grid; gap: 12px; }
.field { display: grid; gap: 6px; }
.field > label { font-size: 12.5px; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--ink-3); }
.input, select.input, textarea.input {
  height: 36px; padding: 0 10px; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--panel); color: var(--ink);
  font-size: 13.5px; width: 100%;
}
textarea.input { height: auto; min-height: 96px; padding: 8px 10px; line-height: 21px;
  resize: vertical; }
.input:focus { border-color: var(--accent); outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft); }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline > .input, .inline > select.input { width: auto; min-width: 120px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab { padding: 8px 12px; font-size: 13px; color: var(--ink-2); border: none;
  background: none; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.empty { padding: 40px 20px; text-align: center; color: var(--ink-2); }
.empty .title { font-size: 14px; color: var(--ink); margin-bottom: 6px; font-weight: 600; }
.empty .desc { font-size: 13px; max-width: 520px; margin: 0 auto 16px; line-height: 22px; }
.empty .actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.notice { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius-sm);
  font-size: 13px; line-height: 21px; align-items: flex-start; }
.notice.info { background: var(--info-bg); color: var(--info-ink); }
.notice.warn { background: var(--warn-bg); color: var(--warn-ink); }
.notice.bad { background: var(--bad-bg); color: var(--bad-ink); }
.notice.ok { background: var(--ok-bg); color: var(--ok-ink); }
.notice .icon { font-weight: 700; }

.bar-list { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 90px; gap: 10px;
  align-items: center; font-size: 13px; }
.bar-track { height: 8px; border-radius: 999px; background: var(--panel-2);
  overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--accent); opacity: .75; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; }

.chart { width: 100%; height: 200px; display: block; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); }

/* ---------------------------------------------------------------- 抽屉 / 弹窗 / 提示 */
.drawer-mask, .modal-mask {
  position: fixed; inset: 0; background: rgba(20, 28, 40, .34); z-index: 60;
  display: flex; justify-content: flex-end;
}
.modal-mask { justify-content: center; align-items: center; padding: 24px; }
.drawer {
  width: min(680px, 94vw); background: var(--panel); height: 100%;
  display: flex; flex-direction: column; box-shadow: -8px 0 40px rgba(0,0,0,.14);
}
.drawer-head, .modal-head {
  padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex;
  align-items: center; gap: 12px;
}
.drawer-head h2, .modal-head h2 { flex: 1; font-size: 16px; }
.drawer-body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex;
  justify-content: flex-end; gap: 8px; }
.modal { background: var(--panel); border-radius: var(--radius); width: min(560px, 96vw);
  max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal .form { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 12px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }

.toast-wrap { position: fixed; right: 20px; bottom: 20px; z-index: 90; display: grid;
  gap: 8px; }
.toast { background: #1b2230; color: #fff; padding: 10px 14px; border-radius: 10px;
  font-size: 13px; box-shadow: var(--shadow); max-width: 420px; line-height: 20px;
  animation: slidein .16s ease; }
.toast.err { background: #8d1f1f; }
.toast.ok { background: #1d5c33; }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } }

.skeleton { background: linear-gradient(90deg, #eef1f6 25%, #f6f8fb 37%, #eef1f6 63%);
  background-size: 400% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; font-size: 13px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; word-break: break-all; }

.chat { display: flex; flex-direction: column; height: calc(100vh - 190px); min-height: 420px; }
.chat-log { flex: 1; overflow-y: auto; display: grid; gap: 12px; padding: 4px 2px 16px; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 12px; font-size: 13.5px;
  line-height: 22px; white-space: pre-wrap; }
.msg.user { background: var(--accent); color: #fff; justify-self: end; border-bottom-right-radius: 4px; }
.msg.bot { background: var(--panel-2); border: 1px solid var(--line);
  border-bottom-left-radius: 4px; }
.chat-input { display: flex; gap: 8px; align-items: flex-end; border-top: 1px solid var(--line);
  padding-top: 12px; }
.chat-input textarea { flex: 1; min-height: 44px; max-height: 120px; }
.trace { margin-top: 8px; font-size: 12px; color: var(--ink-3); }
.trace code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }

/* ---------------------------------------------------------------- 抽屉
 * 为什么要抽屉：同一个指标可能命中很多条（几十个患者、几个咨询师），
 * 平铺成一张表时，页面上全是同一个指标名，看不出"这是几个问题"。
 * 收成一行一个指标、点开才展开，先看全局再看细节。
 */
.drawer {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.drawer > summary {
  list-style: none;
  cursor: pointer;
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--ink);
}
.drawer > summary::-webkit-details-marker { display: none; }
.drawer > summary::after {
  content: '▾';
  margin-left: auto;
  color: var(--ink-3);
  transition: transform .15s ease;
}
.drawer[open] > summary { background: var(--panel-2); border-bottom: 1px solid var(--line); }
.drawer[open] > summary::after { transform: rotate(180deg); }
.drawer-body { padding: 14px 16px; }
.drawer-sub { color: var(--ink-2); font-weight: 400; font-size: 12px; }

/* 四步：发现异常 → 归因 → 建议 → 下达 */
.step { padding: 2px 0 14px; }
.step + .step { border-top: 1px dashed var(--line); padding-top: 14px; }
.step-h { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 600; }
.step-n {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; flex: none;
}
.step-note { color: var(--ink-2); font-weight: 400; font-size: 12px; }

/* details.drawer 和侧滑 .drawer 同名：侧滑那套有 width:680px/height:100%，
 * 折叠卡片会因此被撑成固定宽高。这里用更具体的选择器把尺寸收回来。 */
details.drawer {
  width: auto; height: auto; position: static;
  box-shadow: none; display: block;
}

/* 指标分析：一行一个指标（名称 / 数值 / 达标线），点开看详情 */
.metric-row {
  display: grid;
  grid-template-columns: 1fr auto 120px;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
}
.metric-row:last-child { border-bottom: 0; }
.metric-row:hover { background: var(--panel-2); }
.metric-name { font-size: 13px; display: flex; align-items: center; gap: 8px; }
.metric-val { font-variant-numeric: tabular-nums; font-weight: 600; }
.metric-val .unit { color: var(--ink-3); font-weight: 400; font-size: 12px; margin-left: 2px; }
.metric-meta { color: var(--ink-3); font-size: 12px; text-align: right; }
.tag-accent {
  font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
