:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --accent: #0ea5e9;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
}
h1,h2,h3 { margin: 0; }

/* 顶栏 */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(100deg, #1e3a8a, #2563eb);
  color: #fff; padding: 16px 28px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 32px; }
.topbar h1 { font-size: 20px; font-weight: 600; }
.topbar .sub { margin: 2px 0 0; font-size: 12px; opacity: .82; }
.ai-status { font-size: 12px; padding: 6px 12px; border-radius: 20px; background: rgba(255,255,255,.15); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-box { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user-box .btn.tiny { background: rgba(255,255,255,.16); color: #fff; border-color: rgba(255,255,255,.25); }
.user-box .btn.tiny:hover { background: rgba(255,255,255,.28); }
#userInfo { opacity: .92; }

/* 登录页 */
.login-overlay {
  position: fixed; inset: 0; z-index: 500; display: none;
  align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
}
.login-overlay.show { display: flex; }
.login-box {
  background: #fff; border-radius: 16px; padding: 40px 36px; width: min(380px, 90vw);
  text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.login-logo { font-size: 48px; }
.login-box h2 { font-size: 20px; margin: 10px 0 4px; }
.login-sub { color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.login-box input {
  width: 100%; padding: 12px 14px; margin-bottom: 12px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px;
}
.btn.block { width: 100%; padding: 12px; font-size: 15px; margin-top: 4px; }
.login-err { color: var(--red); font-size: 13px; min-height: 18px; margin: 10px 0 0; }
.login-tip { color: var(--muted); font-size: 12px; margin-top: 14px; line-height: 1.6; }

/* 筛选条 */
.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  padding: 14px 28px; background: var(--card); border-bottom: 1px solid var(--line);
}
.filters { align-items: center; }
.filters select, .filters input {
  height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 13px; background: #fff; color: var(--ink);
}
.filters input { min-width: 220px; flex: 1; max-width: 320px; }
.filters input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.filters .btn { height: 36px; display: inline-flex; align-items: center; }

/* 多选筛选 */
.ms-wrap { display: flex; gap: 8px; flex-wrap: wrap; }
.ms { position: relative; }
.ms-btn {
  display: inline-flex; align-items: center; justify-content: space-between; gap: 8px;
  min-width: 116px; height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 9px; background: #fff;
  font-size: 13px; cursor: pointer; color: #374151; transition: .15s;
  text-align: left;
}
.ms-btn .ms-txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.ms-btn .ms-caret { color: #9ca3af; font-size: 11px; transition: transform .2s; }
.ms-btn:hover { border-color: var(--primary); background: #f8fafc; }
.ms.open .ms-btn { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.ms.open .ms-caret { transform: rotate(180deg); }
.ms.active .ms-btn { border-color: var(--primary); color: var(--primary-d); background: #eff6ff; font-weight: 600; }

.ms-panel {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; z-index: 60;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 28px rgba(0,0,0,.14), 0 2px 6px rgba(0,0,0,.06);
  width: max-content; min-width: 200px; max-width: 340px; padding: 8px; animation: msIn .14s ease;
}
@keyframes msIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.ms.open .ms-panel { display: block; }

.ms-actions { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 8px; margin-bottom: 6px; border-bottom: 1px solid var(--line); }
.ms-title { font-size: 12px; font-weight: 600; color: var(--muted); }
.ms-acts { display: flex; gap: 6px; }
.ms-acts a { color: var(--primary); font-size: 12px; cursor: pointer; padding: 2px 8px; border-radius: 6px; background: #eff6ff; }
.ms-acts a:hover { background: #dbeafe; }

.ms-opts { max-height: 280px; overflow-y: auto; display: flex; flex-direction: column; align-items: stretch; gap: 2px; }
.ms-opts::-webkit-scrollbar { width: 8px; }
.ms-opts::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
.ms-panel label {
  display: flex; flex-direction: row; align-items: center; justify-content: flex-start;
  gap: 8px; padding: 8px 12px; font-size: 13px; cursor: pointer; border-radius: 8px;
  white-space: normal; color: #374151; transition: .12s; width: 100%;
}
.ms-panel label:hover { background: #f3f4f6; }
.ms-panel label input { flex: 0 0 auto; width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; margin: 0; }
.ms-panel label > span { flex: 1 1 auto; text-align: left; line-height: 1.45; word-break: break-word; }
.ms-panel label:has(input:checked) { background: #eff6ff; color: var(--primary-d); font-weight: 600; }

.btn {
  padding: 8px 16px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink); cursor: pointer; font-size: 13px;
  transition: .15s;
}
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-d); }
.btn.tiny { padding: 4px 10px; font-size: 12px; }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 14px; padding: 18px 28px; }
.kpi {
  background: var(--card); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}
.kpi { cursor: pointer; transition: transform .12s, box-shadow .12s; position: relative; }
.kpi:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,.1); }
.kpi::after { content: "🔍下钻"; position: absolute; top: 10px; right: 12px; font-size: 10px; color: #cbd5e1; opacity: 0; transition: .12s; }
.kpi:hover::after { opacity: 1; }
.kpi .label { font-size: 12px; color: var(--muted); }
/* 下钻弹窗内容 */
.drill-sec { margin-bottom: 18px; }
.drill-sec h4 { font-size: 14px; margin: 0 0 8px; color: var(--ink); border-left: 3px solid var(--primary); padding-left: 8px; }
#drillBody table.grid { margin-bottom: 4px; }
#drillBody .bar-cell { position: relative; }
#drillBody .bar-cell i { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(37,99,235,.1); z-index: 0; }
#drillBody .bar-cell span { position: relative; z-index: 1; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 6px; letter-spacing: -.5px; }
.kpi .extra { font-size: 11px; color: var(--muted); margin-top: 4px; }
.kpi:nth-child(2){border-color:var(--green);}
.kpi:nth-child(3){border-color:var(--accent);}
.kpi:nth-child(4){border-color:var(--amber);}
.kpi:nth-child(5){border-color:#8b5cf6;}
.kpi:nth-child(6){border-color:#ec4899;}
.kpi:nth-child(7){border-color:#14b8a6;}
.kpi:nth-child(8){border-color:#f97316;}

/* 标签页 */
.tabs { display: flex; gap: 4px; padding: 0 28px; border-bottom: 1px solid var(--line); background: var(--card); }
.tab {
  padding: 12px 18px; border: none; background: none; cursor: pointer;
  font-size: 14px; color: var(--muted); border-bottom: 3px solid transparent;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.panel { display: none; padding: 22px 28px; }
.panel.active { display: block; }

/* 卡片与图表 */
.card { background: var(--card); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card h3 { font-size: 15px; margin-bottom: 14px; color: var(--ink); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-head h3 { margin-bottom: 0; }
.chart-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.chart-grid .wide { grid-column: span 2; }
.chart { width: 100%; height: 320px; }

/* 表格 */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { padding: 9px 11px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.grid th { background: #f8fafc; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
table.grid tr:hover td { background: #f8fafc; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-subtotal td { background: #eff6ff !important; font-weight: 600; }
.row-total td { background: #dbeafe !important; font-weight: 700; }
.row-year { cursor: pointer; }
.row-year td:first-child::before { content: "▶ "; color: var(--primary); }
.row-year.open td:first-child::before { content: "▼ "; }
.row-month td:first-child { padding-left: 28px; color: var(--muted); }
.row-detail td { background: #f0f7ff !important; padding: 0 !important; }
.ct-detail { padding: 12px 18px; line-height: 1.9; font-size: 12.5px; color: #334155; }
.ct-detail b { color: var(--primary); }

.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.tag.ai { background: #ede9fe; color: #6d28d9; }
.tag.imported { background: #d1fae5; color: #047857; }
.tag.manual { background: #e0e7ff; color: #3730a3; }
.check-yes { color: var(--green); font-weight: 700; }
.check-no { color: #d1d5db; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 16px; }
.pager span { color: var(--muted); }

/* 上传区 */
.upload-zone {
  border: 2px dashed var(--primary); border-radius: 12px; padding: 40px;
  text-align: center; color: var(--primary); cursor: pointer; background: #f0f7ff;
  transition: .15s; margin: 12px 0;
}
.upload-zone:hover, .upload-zone.drag { background: #dbeafe; }
.upload-zone.small { padding: 22px; }
.hint { color: var(--muted); font-size: 13px; }
.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; margin-top: 8px; }

/* 解析结果 */
.parse-card { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-top: 14px; }
.parse-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px 18px; margin: 12px 0; }
.parse-grid .f { display: flex; flex-direction: column; }
.parse-grid .f label { font-size: 11px; color: var(--muted); }
.parse-grid .f input { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }
.conf-bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.conf-bar i { display: block; height: 100%; background: var(--green); }

/* 报告 */
.report-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.report-controls input[type=text] { padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; }
.report-controls select { padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; }
.report-body { line-height: 1.7; margin-top: 14px; }
.report-body h1 { font-size: 22px; margin: 18px 0 10px; }
.report-body h2 { font-size: 18px; margin: 18px 0 8px; border-left: 4px solid var(--primary); padding-left: 10px; }
.report-body h3 { font-size: 15px; margin: 12px 0 6px; }
.report-body ul { margin: 6px 0; }
.report-body table { border-collapse: collapse; margin: 10px 0; }
.report-body th, .report-body td { border: 1px solid var(--line); padding: 6px 10px; }

/* 弹窗 */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; align-items: center; justify-content: center; }
.modal.show { display: flex; }
.modal-box { background: #fff; border-radius: 12px; width: min(720px, 92vw); max-height: 88vh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.close { cursor: pointer; font-size: 24px; color: var(--muted); line-height: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 12px 16px; }
.form-grid .f { display: flex; flex-direction: column; }
.form-grid .f.full { grid-column: span 2; }
.form-grid label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.form-grid input, .form-grid select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }

/* toast */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: #1f2937; color: #fff; padding: 12px 22px; border-radius: 8px; z-index: 200;
  transition: .3s; opacity: 0;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
.spinner { display:inline-block; width:14px; height:14px; border:2px solid #fff; border-top-color:transparent; border-radius:50%; animation:spin .7s linear infinite; vertical-align:middle; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3,1fr); }
  .chart-grid { grid-template-columns: 1fr; }
  .chart-grid .wide { grid-column: span 1; }
}
@media print {
  .topbar,.filters,.tabs,.kpis,.card-head .report-controls { display: none !important; }
  .panel { display: none !important; }
  #tab-report { display: block !important; }
}
