:root {
  --teal: #0e7c86;
  --teal-dark: #0a5d65;
  --teal-soft: #e3f2f3;
  --ink: #16232f;
  --muted: #64748b;
  --line: #e3e9ee;
  --bg: #f4f7f9;
  --card: #ffffff;
  --green: #1f9d61;
  --green-soft: #e7f6ee;
  --yellow: #c98a09;
  --yellow-soft: #fdf3dd;
  --red: #d64545;
  --red-soft: #fdeaea;
  --gray-soft: #eef1f4;
  --shadow: 0 1px 2px rgba(16, 35, 47, .05), 0 8px 24px rgba(16, 35, 47, .06);
  --radius: 14px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.6;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: .2px; }
p { margin: 0 0 8px; }
button { font-family: inherit; }
a { color: var(--teal); }

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 180px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--teal), #12a3ad);
  color: #fff; font-weight: 700; font-size: 20px;
  display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(14, 124, 134, .25);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 17px; }
.brand-text span { font-size: 11.5px; color: var(--muted); }

.topbar-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.switch select {
  appearance: none; border: 1px solid var(--line); background: #fff;
  border-radius: 9px; padding: 7px 26px 7px 10px; font-size: 13px; color: var(--ink);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
  cursor: pointer;
}
.switch select:focus { outline: 2px solid rgba(14,124,134,.25); border-color: var(--teal); }

.btn {
  border: 1px solid transparent; border-radius: 10px; cursor: pointer;
  padding: 8px 14px; font-size: 13px; font-weight: 600;
  transition: .15s ease; white-space: nowrap;
}
.btn-primary { background: var(--teal); color: #fff; box-shadow: 0 4px 10px rgba(14,124,134,.2); }
.btn-primary:hover { background: var(--teal-dark); }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: #c9d5de; background: #fbfcfd; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-danger { background: #fff; border-color: #f0c9c9; color: var(--red); }
.btn-danger:hover { background: var(--red-soft); }

/* ---------- 导航 ---------- */
.tabs {
  display: flex; gap: 4px; padding: 0 24px;
  background: #fff; border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; border: 0; background: transparent; cursor: pointer;
  padding: 12px 14px 11px; font-size: 13.5px; color: var(--muted); font-weight: 600;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--teal); }
.tab.active::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 3px;
  background: var(--teal); border-radius: 3px 3px 0 0;
}
.badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px;
  margin-left: 6px; border-radius: 9px; background: var(--red); color: #fff;
  font-size: 11px; vertical-align: 1px;
}
.badge:empty, .badge[data-zero="1"] { display: none; }

/* 同步状态与共享提示 */
.sync {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  font-size: 11.5px; color: var(--muted); background: var(--gray-soft);
  padding: 4px 9px; border-radius: 999px;
}
.sync.ok { background: var(--green-soft); color: var(--green); }
.sync.saving { background: var(--yellow-soft); color: var(--yellow); }
.sync.err { background: var(--red-soft); color: var(--red); }
.banner {
  width: calc(100% - 48px); max-width: 1180px; margin: 12px auto -4px;
  padding: 8px 14px; border-radius: 10px; font-size: 12.5px;
  background: #fff7ec; border: 1px dashed #efc99a; color: #8a6116;
}

/* ---------- 容器 ---------- */
.container { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 22px 24px 40px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.page-head h1 { font-size: 21px; }
.page-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.page-head .actions { display: flex; gap: 8px; }

.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.side { grid-template-columns: 1.55fr 1fr; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { font-size: 15px; }
.card-head .hint { font-size: 12px; color: var(--muted); }
.card + .card { margin-top: 14px; }

.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi .num { font-size: 28px; font-weight: 800; letter-spacing: -.5px; line-height: 1.15; }
.kpi .num small { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .foot { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.kpi.red .num { color: var(--red); }
.kpi.yellow .num { color: var(--yellow); }
.kpi.green .num { color: var(--green); }
.kpi.teal .num { color: var(--teal); }

/* ---------- 状态 ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.yellow { background: var(--yellow-soft); color: var(--yellow); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.none { background: var(--gray-soft); color: var(--muted); }
.pill.plain { background: var(--teal-soft); color: var(--teal-dark); }

.tag {
  display: inline-block; padding: 1px 8px; border-radius: 6px;
  background: var(--gray-soft); color: var(--muted); font-size: 11.5px; margin-right: 4px;
}

/* ---------- 列表 ---------- */
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: 12px; padding: 11px 0;
  border-top: 1px solid var(--line);
}
.list-row:first-child { border-top: 0; }
.avatar {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  display: grid; place-items: center; font-weight: 700; color: var(--teal-dark);
  background: var(--teal-soft);
}
.list-main { flex: 1; min-width: 0; }
.list-main .title { font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-main .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.list-side { display: flex; align-items: center; gap: 12px; }
.metric { text-align: right; line-height: 1.25; }
.metric b { font-size: 15px; }
.metric span { display: block; font-size: 11px; color: var(--muted); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 640px; }
.table th, .table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 700; background: #fafcfd; font-size: 12px; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fbfdfd; }
.table .num { font-variant-numeric: tabular-nums; }
.table .warn { color: var(--red); font-weight: 700; }
.table .attention { color: var(--yellow); font-weight: 700; }

/* ---------- 图表 ---------- */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { font-size: 10.5px; fill: var(--muted); }
.chart .grid-line { stroke: #eef2f5; stroke-width: 1; }
.chart .legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.chart .legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; margin-right: 5px; vertical-align: 2px; }
.chart-empty { color: var(--muted); font-size: 12.5px; padding: 28px 0; text-align: center; }

/* ---------- 报告 ---------- */
.report {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 26px 30px 22px;
}
.report-head { display: flex; justify-content: space-between; gap: 16px; border-bottom: 2px solid var(--teal); padding-bottom: 12px; }
.report-head h2 { font-size: 19px; color: var(--teal-dark); }
.report-head .sub { color: var(--muted); font-size: 12px; }
.report-id { text-align: right; font-size: 12px; color: var(--muted); line-height: 1.7; }
.report-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 16px 0; }
.report-item { background: #f8fbfc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.report-item .k { font-size: 11.5px; color: var(--muted); }
.report-item .v { font-size: 17px; font-weight: 800; margin-top: 2px; }
.report h3 { font-size: 14.5px; margin: 18px 0 8px; color: var(--teal-dark); }
.report ul { margin: 6px 0 0 18px; padding: 0; }
.report li { margin: 4px 0; }
.report .note { background: #fff9ef; border: 1px dashed #efd9a9; border-radius: 10px; padding: 10px 12px; font-size: 12px; color: #7a5a12; }
.sign { display: flex; justify-content: space-between; gap: 20px; margin-top: 26px; padding-top: 14px; border-top: 1px dashed var(--line); font-size: 12px; color: var(--muted); }
.sign div { flex: 1; }
.sign b { color: var(--ink); font-weight: 600; }

/* ---------- 知识库 ---------- */
.kb-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.kb-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kb-card .idx { color: var(--teal); font-weight: 800; font-size: 12px; letter-spacing: 1px; }
.kb-card h3 { font-size: 14.5px; margin: 6px 0 6px; }
.kb-card p { font-size: 12.5px; color: var(--muted); }
.kb-card .src { font-size: 11.5px; color: #8a98a8; margin-top: 8px; }

.rules { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.rules th, .rules td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.rules th { background: #fafcfd; color: var(--muted); font-size: 12px; }
.rules td:first-child { font-weight: 700; white-space: nowrap; }

/* ---------- 空态 ---------- */
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 8px; }

/* ---------- 弹窗 ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(13, 25, 35, .45);
  display: grid; place-items: center; padding: 20px; z-index: 60;
}
.modal-overlay[hidden] { display: none; }
.modal {
  width: min(680px, 100%); max-height: 88vh; display: flex; flex-direction: column;
  background: #fff; border-radius: 16px; box-shadow: 0 24px 60px rgba(10, 25, 35, .25);
  overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 16px; }
.icon-btn { border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; border-radius: 8px; }
.icon-btn:hover { background: var(--gray-soft); color: var(--ink); }
.modal-body { padding: 18px 20px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: #fbfcfd; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; font-size: 13px;
  font-family: inherit; color: var(--ink); background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid rgba(14,124,134,.2); border-color: var(--teal); }
.field.full { grid-column: 1 / -1; }
.form-section { margin: 6px 0 10px; font-size: 12.5px; font-weight: 700; color: var(--teal-dark); display: flex; align-items: center; gap: 8px; }
.form-section::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.hintline { font-size: 11.5px; color: var(--muted); margin-top: 6px; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 16px);
  background: #16232f; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .25s ease; z-index: 80;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 页脚 ---------- */
.footer {
  text-align: center; color: #8a98a8; font-size: 11.5px; padding: 18px 20px 26px;
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
}
.footer .dot { opacity: .5; }

/* ---------- 响应式 ---------- */
@media (max-width: 980px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3, .kb-grid { grid-template-columns: repeat(2, 1fr); }
  .grid.side { grid-template-columns: 1fr; }
  .report-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; padding: 12px 14px; gap: 10px; }
  .brand-text span { display: none; }
  .topbar-tools { width: 100%; justify-content: space-between; }
  .switch span { display: none; }
  .banner { width: calc(100% - 28px); margin: 10px auto 0; font-size: 12px; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    border-top: 1px solid var(--line); border-bottom: 0;
    box-shadow: 0 -6px 20px rgba(16, 35, 47, .08);
    padding: 0 4px; z-index: 45; justify-content: space-around;
  }
  .tab { flex: 1; padding: 8px 4px 12px; font-size: 11.5px; text-align: center; min-width: 0; }
  .tab.active::after { left: 20%; right: 20%; bottom: 2px; height: 3px; }
  .app { padding-bottom: 58px; }
  .container { padding: 16px 14px 96px; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2, .kb-grid { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .report { padding: 18px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .list-row { align-items: flex-start; }
  .list-side { flex-direction: column; align-items: flex-end; gap: 6px; }
  .btn { padding: 9px 14px; }
}

/* ---------- 打印 ---------- */
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; font-size: 11pt; }
  .topbar, .tabs, .footer, .no-print { display: none !important; }
  .container { padding: 0; max-width: none; }
  #view > *:not(#printArea) { display: none !important; }
  .report { border: 0; box-shadow: none; padding: 0; }
  .report-head { border-bottom: 2px solid #0e7c86; }
  .card { box-shadow: none; }
  .chart svg { max-height: 70mm; }
  a { color: inherit; text-decoration: none; }
}
