:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7785;
  --line: #e3e8ef;
  --brand: #1f5fbf;
  --brand-d: #16468f;
  --accent: #c8902a;
  --ok: #1f9d55;
  --err: #d2483b;
  --pri: #8a5cc9;
  --nor: #3a8fbd;
  --shadow: 0 2px 10px rgba(31, 41, 51, .06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

/* Header */
.app-header {
  background: linear-gradient(120deg, var(--brand-d), var(--brand));
  color: #fff;
  padding: 18px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
/* ===== 侠律 品牌标识 ===== */
.brand { display: flex; align-items: center; gap: 14px; }
.brandmark {
  width: 54px; height: 54px;
  flex: 0 0 54px;
  border-radius: 12px;
  background: linear-gradient(145deg, #d0453a, #a52a22);
  border: 1px solid rgba(255,255,255,.35);
  box-shadow: 0 2px 8px rgba(0,0,0,.22), inset 0 0 0 2px rgba(255,255,255,.13);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  line-height: 1.02;
}
.bm-char {
  font-size: 21px; font-weight: 700; color: #fff;
  letter-spacing: 0; font-family: "KaiTi", "STKaiti", "PingFang SC", "Microsoft YaHei", serif;
}
.bm-char.bm-top { margin-bottom: -1px; }
.bm-char.bm-bot { margin-top: -1px; }

.brand-text { min-width: 0; }
.brand-line { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.brand-name {
  font-size: 22px; font-weight: 700; letter-spacing: 4px;
  color: #fff;
  font-family: "KaiTi", "STKaiti", "PingFang SC", "Microsoft YaHei", serif;
  text-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.brand-divider {
  width: 1px; height: 20px;
  background: rgba(255,255,255,.45);
  align-self: center;
}
.app-header h1 { margin: 0; font-size: 20px; letter-spacing: .5px; display: flex; align-items: center; gap: 8px; }
.region-tag {
  font-size: 12px; font-weight: 600; letter-spacing: 0;
  background: rgba(255,255,255,.2);
  border: 1px solid rgba(255,255,255,.4);
  padding: 2px 8px; border-radius: 999px;
  white-space: nowrap;
}
.region-tag.small { font-size: 11px; padding: 1px 7px; }
.subtitle { margin: 3px 0 0; font-size: 12px; opacity: .85; }

/* ===== 页脚 ===== */
.app-footer {
  margin-top: 26px;
  border-top: 1px solid var(--line);
  background: #fff;
}
.foot-inner {
  max-width: 1180px; margin: 0 auto;
  padding: 22px 28px 28px;
}
.foot-brand { display: flex; align-items: center; gap: 12px; }
.foot-mark {
  width: 42px; height: 42px; flex: 0 0 42px;
  border-radius: 10px;
  background: linear-gradient(145deg, #d0453a, #a52a22);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 700; letter-spacing: 1px;
  font-family: "KaiTi", "STKaiti", "PingFang SC", "Microsoft YaHei", serif;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.foot-title { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.foot-title .region-tag { background: #eef2f8; border-color: #d3dced; color: var(--brand-d); }
.foot-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.foot-note {
  margin: 12px 0 0; font-size: 12px; color: var(--muted);
  line-height: 1.7; border-left: 3px solid var(--line); padding-left: 10px;
}
@media (max-width: 640px) {
  .brand-line { gap: 6px; }
  .app-header h1 { font-size: 17px; }
  .brand-name { font-size: 19px; letter-spacing: 2px; }
}

.tabs { display: flex; gap: 6px; }
.tab {
  background: rgba(255,255,255,.12);
  border: none; color: #fff;
  padding: 8px 16px; border-radius: 8px;
  cursor: pointer; font-size: 14px;
  transition: background .15s;
}
.tab:hover { background: rgba(255,255,255,.22); }
.tab.active { background: #fff; color: var(--brand-d); font-weight: 600; }

main { padding: 22px 28px; max-width: 1180px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Layout */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 14px; font-size: 16px; }

/* Steps */
.step { display: flex; align-items: center; gap: 10px; margin: 18px 0 10px; }
.step:first-child { margin-top: 4px; }
.step-no {
  background: var(--brand); color: #fff;
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.step h3 { margin: 0; font-size: 15px; }

/* Controls */
.control {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 9px;
  font-size: 14px; color: var(--ink); background: #fff;
}
.control:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31,95,191,.12); }
.control.slim { width: 100%; }
select.control { cursor: pointer; }

.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; white-space: pre-line; }
.muted { color: var(--muted); }

.field-row { margin-top: 14px; }
.field-row label { display: block; font-size: 13px; margin-bottom: 5px; }
.fields { margin-top: 6px; display: flex; flex-direction: column; gap: 12px; }
.field-check { display: flex; align-items: center; gap: 8px; font-size: 13px; }

/* Circumstances */
.circ-filter { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.circ-filter input[type=text] { flex: 1; }
.circ-filter label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }

.circ-list { display: flex; flex-direction: column; gap: 8px; max-height: 360px; overflow-y: auto; padding-right: 4px; }
.circ-item {
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; background: #fbfcfe;
}
.circ-item.on { border-color: var(--brand); background: #f3f8ff; }
.circ-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.circ-name { font-size: 13.5px; font-weight: 600; display: flex; align-items: center; gap: 7px; cursor: pointer; }
.circ-pct { font-size: 13px; font-weight: 700; color: var(--brand-d); white-space: nowrap; }
.tag { font-size: 10.5px; padding: 1px 7px; border-radius: 20px; color: #fff; font-weight: 600; }
.tag.pri { background: var(--pri); }
.tag.nor { background: var(--nor); }
.circ-slider { width: 100%; margin: 8px 0 4px; accent-color: var(--brand); }
.circ-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.circ-desc { font-size: 11.5px; color: var(--muted); flex: 1; min-width: 160px; }
.mit { font-size: 11.5px; color: var(--accent); display: flex; align-items: center; gap: 4px; cursor: pointer; white-space: nowrap; }

/* Buttons */
.primary-btn {
  width: 100%; margin-top: 18px;
  background: var(--brand); color: #fff; border: none;
  padding: 12px; border-radius: 10px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.primary-btn:hover { background: var(--brand-d); }
.primary-btn.slim, .ghost-btn.slim { width: auto; margin-top: 0; padding: 8px 16px; font-size: 13px; }
.ghost-btn {
  background: #fff; color: var(--brand-d);
  border: 1px solid var(--brand); border-radius: 9px;
  padding: 8px 16px; font-size: 13px; cursor: pointer;
}
.ghost-btn:hover { background: #f0f6ff; }

/* Result */
.result-box.empty { color: var(--muted); text-align: center; padding: 40px 10px; font-size: 14px; }
.res-step { padding: 12px 0; border-bottom: 1px dashed var(--line); }
.res-step:last-child { border-bottom: none; }
.res-title { font-weight: 700; color: var(--brand-d); margin-bottom: 7px; font-size: 14px; }
.res-val { font-size: 14px; }
.add-list { margin: 4px 0 8px; padding-left: 18px; }
.add-list li { font-size: 13px; margin: 3px 0; }
.adj-row { font-size: 13px; margin: 6px 0; padding-left: 6px; border-left: 3px solid #dbe6f7; padding: 4px 0 4px 10px; }
.final { background: #f3f8ff; border-radius: 10px; padding: 16px; border: 1px solid #d4e4fb; }
.final-val { font-size: 30px; font-weight: 800; color: var(--brand-d); text-align: center; margin: 8px 0; }
.note { font-size: 12.5px; color: var(--accent); background: #fff7e8; border-radius: 7px; padding: 6px 9px; margin: 6px 0; }
.note.warn { color: #a33a2c; background: #fdf0ef; white-space: pre-line; }

/* Data tab */
.data-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.data-msg { font-size: 13px; }
.data-msg.ok { color: var(--ok); }
.data-msg.err { color: var(--err); }
.data-editor {
  width: 100%; min-height: 320px; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; font-family: "SFMono-Regular", Consolas, "Courier New", monospace;
  font-size: 12.5px; line-height: 1.5; resize: vertical; color: var(--ink); background: #fbfcfe;
}
.schema { margin-top: 14px; }
.schema summary { cursor: pointer; color: var(--brand); font-size: 13px; }
.schema pre {
  background: #1f2933; color: #e6edf3; padding: 14px; border-radius: 10px;
  overflow: auto; font-size: 12px; line-height: 1.5;
}

/* Help tab */
.method { padding-left: 20px; }
.method li, .tab-panel ul { margin: 7px 0; }
.method b { color: var(--brand-d); }
.formula-box {
  background: #f3f8ff; border: 1px solid #d4e4fb; border-radius: 10px;
  padding: 12px 16px; margin: 10px 0 16px;
}
.formula-box p { margin: 6px 0; }
.formula-box code {
  background: #1f2933; color: #e6edf3; padding: 3px 8px; border-radius: 5px;
  font-size: 12.5px; font-family: Consolas, "Courier New", monospace;
}
.formula-box .flist { font-size: 12.5px; color: var(--muted); margin: 2px 0 10px 14px; }

/* 罪名范围清单（方法说明页） */
.tab-panel .flist { font-size: 12.5px; color: var(--muted); margin: 4px 0 10px 14px; line-height: 1.75; }
.crime-scope { margin: 8px 0 4px; padding-left: 20px; }
.crime-scope li { margin: 5px 0; font-size: 13px; line-height: 1.7; }
.crime-scope b { color: var(--brand-d); }

/* Source banner */
.src-banner {
  background: #eef6ff; border: 1px solid #cfe3fb; border-radius: 10px;
  padding: 10px 14px; margin-bottom: 16px; font-size: 12.5px; color: #24507f;
  display: flex; gap: 8px; align-items: flex-start;
}
.src-banner .ico { font-size: 15px; }
.disclaimer {
  margin-top: 16px; background: #fff7e8; border: 1px solid #f0d9a8;
  color: #8a5a00; padding: 12px 14px; border-radius: 10px; font-size: 13px; line-height: 1.7;
}

/* ===== 计算结果操作区 ===== */
.result-actions {
  margin-top: 16px; padding-top: 14px;
  border-top: 1px dashed var(--line);
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.btn-print-hint { font-size: 12px; color: var(--muted); }

/* ===== 历史记录 ===== */
.hist-list { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.hist-item {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 13px 15px; background: #fcfdff;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.hist-item:hover { border-color: #c3d4ea; box-shadow: var(--shadow); }
.hist-main { min-width: 0; flex: 1; }
.hist-head { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.hist-crime { font-size: 15px; font-weight: 600; color: var(--brand-d); }
.hist-tier {
  font-size: 12px; color: var(--muted);
  background: #eef2f8; border-radius: 6px; padding: 1px 8px;
}
.hist-time { font-size: 11.5px; color: #9aa5b1; margin-left: auto; }
.hist-nums { margin-top: 7px; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.hist-final { font-size: 13px; color: var(--ink); }
.hist-final b { font-size: 17px; color: #b8352c; letter-spacing: .5px; }
.hist-sub { font-size: 12px; color: var(--muted); }
.hist-circ {
  margin-top: 5px; font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.hist-ops { display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; }
.hist-ops .ghost-btn { min-width: 62px; }
.ghost-btn.danger { color: var(--err); border-color: #f0c6c1; }
.ghost-btn.danger:hover { background: #fdf1ef; }
@media (max-width: 640px) {
  .hist-item { flex-direction: column; }
  .hist-ops { flex-direction: row; flex-wrap: wrap; }
}

/* ===== 打印 / 导出为 PDF ===== */
@media print {
  body { background: #fff; font-size: 12px; }
  .app-header, .tabs, .app-footer, .result-actions,
  .card.inputs, .src-banner { display: none !important; }
  main { padding: 0 !important; max-width: none !important; }
  .grid { display: block !important; }
  .tab-panel { display: none !important; }
  #tab-calc { display: block !important; }
  .card.result { border: none; box-shadow: none; padding: 0; }
  .card.result h3 { display: none; }
  .res-step, .note, .final-val { break-inside: avoid; }
  .final-val { color: #000 !important; }
}

/* 档次级说明（折减档的前提条件等） */
.tier-tip { margin: 0 0 10px; padding: 8px 10px; border-radius: 8px;
  font-size: 12px; line-height: 1.65; white-space: pre-line;
  background: #fbf3e2; border: 1px solid #ecd9b0; color: #8a6d3b; }

/* 档次错配提醒（数额已达更重档 / 未达本档） */
.tier-warn { margin: 0 0 10px; padding: 9px 11px; border-radius: 8px;
  font-size: 12.5px; line-height: 1.7; white-space: pre-line;
  background: #fdf0ef; border: 1px solid #f0c3bd; color: #a33a2c; }
.tier-warn b { color: #8f2d21; }
.tier-warn .warn-act { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tier-warn button { font-size: 12px; padding: 4px 10px; border-radius: 6px; cursor: pointer;
  border: 1px solid #cf7a6d; background: #fff; color: #a33a2c; }
.tier-warn button:hover { background: #f7d9d4; }
.tier-warn.mild { background: #fbf3e2; border-color: #ecd9b0; color: #8a6d3b; }
.tier-warn.mild b { color: #6f5528; }
.tier-warn.mild button { border-color: #d9bb84; color: #7a5c2b; }
.tier-warn.mild button:hover { background: #f3e6c8; }

/* ===== 江苏版 / 全国版 口径切换 ===== */
.region-switch {
  display: inline-flex;
  align-items: center;
  margin-left: 14px;
  border: 1px solid rgba(255, 255, 255, .55);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, .12);
}
.region-switch button {
  appearance: none;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, .85);
  font: inherit;
  font-size: 12.5px;
  padding: 4px 14px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.region-switch button:hover { color: #fff; background: rgba(255, 255, 255, .12); }
.region-switch button.active {
  background: #fff;
  color: var(--brand-d);
  font-weight: 600;
}
/* 全国版说明块（tier-tip 的蓝色变体） */
.tier-tip.nat {
  background: #eaf2fd;
  border: 1px solid #bfd4f2;
  color: #27517f;
}
