:root {
  --ink: #0d1b2a;
  --navy: #0f2437;
  --navy-2: #16324a;
  --green: #00a651;
  --green-dark: #008a43;
  --green-soft: #e7f7ee;
  --bg: #f4f6f8;
  --card: #ffffff;
  --line: #e3e8ee;
  --muted: #6b7785;
  --amber: #d97706;
  --red: #dc2626;
  --blue: #2563eb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 36, 55, 0.04), 0 8px 24px rgba(15, 36, 55, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.65;
}
a { color: inherit; text-decoration: none; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: 64px; padding: 0 28px;
  display: flex; align-items: center; gap: 28px;
  background: var(--navy);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,0.06);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 250px; }
.brand img { width: 36px; height: 36px; border-radius: 9px; box-shadow: 0 0 0 1px rgba(255,255,255,0.12); }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15px; letter-spacing: 1.2px; }
.brand-text em { font-style: normal; font-size: 11px; color: #9fb3c8; letter-spacing: 0.4px; margin-top: 3px; }
.topnav { display: flex; gap: 6px; }
.topnav a {
  padding: 7px 14px; border-radius: 8px; color: #cfe0ee; font-size: 13px;
  transition: background .15s, color .15s;
}
.topnav a:hover, .topnav a.active { background: rgba(255,255,255,0.09); color: #fff; }
.topsearch { margin-left: auto; }
.topsearch input {
  width: 300px; max-width: 34vw; height: 36px;
  padding: 0 14px; border-radius: 9px; border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.07); color: #fff; outline: none; font-size: 13px;
}
.topsearch input::placeholder { color: #8fa6ba; }
.topsearch input:focus { border-color: var(--green); background: rgba(255,255,255,0.1); }

/* ---------- Layout ---------- */
main { max-width: 1440px; margin: 0 auto; padding: 26px 28px 60px; }
.footer {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 18px 28px; color: #8a97a5; font-size: 12px;
  border-top: 1px solid var(--line);
}

/* ---------- Hero ---------- */
.hero {
  position: relative; overflow: hidden;
  border-radius: 18px; padding: 38px 40px;
  background: linear-gradient(120deg, #0d1b2a 0%, #14324a 62%, #0c3b2a 100%);
  color: #fff; box-shadow: var(--shadow);
}
.hero::after {
  content: ""; position: absolute; right: -80px; top: -80px;
  width: 360px; height: 360px; border-radius: 50%;
  background: radial-gradient(circle, rgba(0,166,81,0.35), rgba(0,166,81,0) 68%);
}
.hero h1 { margin: 0 0 8px; font-size: 30px; letter-spacing: 0.5px; }
.hero p { margin: 0; color: #b9cbda; max-width: 720px; }
.hero .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.chip {
  padding: 5px 12px; border-radius: 20px; font-size: 12px;
  background: rgba(255,255,255,0.09); border: 1px solid rgba(255,255,255,0.16); color: #e7f2ea;
}
.hero-stats { display: flex; flex-wrap: wrap; gap: 26px; margin-top: 26px; }
.hero-stats div { display: flex; flex-direction: column; }
.hero-stats b { font-size: 24px; font-weight: 700; color: #fff; }
.hero-stats span { font-size: 12px; color: #9fb3c8; }

/* ---------- Cards ---------- */
.grid { display: grid; gap: 18px; }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px;
}
.card h3 { margin: 0 0 6px; font-size: 17px; }
.card .muted { color: var(--muted); font-size: 12.5px; }
.model-card { display: flex; flex-direction: column; gap: 14px; transition: transform .15s, box-shadow .15s; }
.model-card:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(15,36,55,0.12); }
.model-card .top { display: flex; align-items: center; gap: 14px; }
.model-card .top img { width: 52px; height: 52px; border-radius: 12px; }
.model-card .meta { display: flex; flex-wrap: wrap; gap: 8px; }
.model-card .stats { display: flex; gap: 18px; padding-top: 12px; border-top: 1px dashed var(--line); }
.model-card .stats b { display: block; font-size: 18px; }
.model-card .stats span { font-size: 11.5px; color: var(--muted); }
.empty-card {
  display: flex; align-items: center; justify-content: center; min-height: 190px;
  border: 1.5px dashed #c8d2dc; border-radius: var(--radius); color: var(--muted);
  background: rgba(255,255,255,0.55); font-size: 13px; flex-direction: column; gap: 6px;
}
.empty-card:hover { border-color: var(--green); color: var(--green-dark); }

/* ---------- Section titles ---------- */
.section-head { display: flex; align-items: baseline; gap: 12px; margin: 34px 0 16px; }
.section-head h2 { margin: 0; font-size: 20px; }
.section-head .muted { color: var(--muted); font-size: 12.5px; }

/* ---------- Model layout ---------- */
.model-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 22px; align-items: start; }
.sidebar {
  position: sticky; top: 84px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.sidebar h4 { margin: 6px 8px 10px; font-size: 12px; color: var(--muted); letter-spacing: 1px; }
.sidebar a {
  display: flex; align-items: center; gap: 9px; padding: 8px 9px; border-radius: 8px;
  color: #24384a; font-size: 13px; transition: background .12s;
}
.sidebar a:hover { background: #f0f4f7; }
.sidebar a.active { background: var(--green-soft); color: var(--green-dark); font-weight: 600; }
.code-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 38px; padding: 2px 6px; border-radius: 5px;
  background: #eef2f6; color: #3c5165; font-size: 10.5px; font-weight: 700; letter-spacing: 0.4px;
}
.sidebar a.active .code-badge { background: var(--green); color: #fff; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.kpi span { display: block; font-size: 11.5px; color: var(--muted); }
.kpi b { display: block; margin-top: 4px; font-size: 20px; color: var(--navy); }
.kpi small { color: var(--muted); font-size: 11px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.p0 { background: #fee2e2; color: #b91c1c; }
.p1 { background: #fef3c7; color: #b45309; }
.p2 { background: #dbeafe; color: #1d4ed8; }
.b-open { background: #fee2e2; color: #b91c1c; }
.b-progress { background: #fef3c7; color: #b45309; }
.b-closed { background: #dcfce7; color: #15803d; }
.b-type { background: #eef2f6; color: #475569; }
.b-green { background: var(--green-soft); color: var(--green-dark); }
.b-amber { background: #fef3c7; color: #b45309; }

/* ---------- Alerts ---------- */
.alert {
  border-radius: 12px; padding: 14px 18px; margin: 14px 0; font-size: 13px;
  border: 1px solid; display: flex; gap: 12px; align-items: flex-start;
}
.alert b { display: block; margin-bottom: 3px; }
.alert.warn { background: #fff8eb; border-color: #f4d9a6; color: #7c4a03; }
.alert.danger { background: #fef2f2; border-color: #f5c2c2; color: #8f1d1d; }
.alert.info { background: #eef6ff; border-color: #c9dff7; color: #1d4f86; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 12.8px; }
thead th {
  position: sticky; top: 0; z-index: 2;
  background: #f1f5f9; color: #33475b; text-align: left; font-weight: 600;
  padding: 11px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid #eef2f6; vertical-align: top; }
tbody tr:hover { background: #f8fbfd; }
tbody tr:last-child td { border-bottom: none; }
td.id { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 11.8px; white-space: nowrap; color: #31506b; }
td.center { text-align: center; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 20px 0 18px; }
.tabs button {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  padding: 10px 16px; font-size: 13.5px; color: var(--muted); border-bottom: 2px solid transparent;
  font-family: inherit;
}
.tabs button.active { color: var(--green-dark); border-bottom-color: var(--green); font-weight: 600; }
.tabs button span { color: #9aa7b4; font-size: 11px; margin-left: 4px; }
.tabpanel { display: none; }
.tabpanel.active { display: block; }

/* ---------- Markdown / content ---------- */
.doc { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 30px 36px; box-shadow: var(--shadow); }
.doc h1 { font-size: 24px; margin: 0 0 6px; }
.doc h2 { font-size: 19px; margin: 32px 0 12px; padding-left: 12px; border-left: 4px solid var(--green); }
.doc h3 { font-size: 15.5px; margin: 26px 0 10px; color: var(--navy-2); }
.doc h4 { font-size: 14px; margin: 18px 0 8px; }
.doc p { margin: 10px 0; color: #26394a; }
.doc ul, .doc ol { padding-left: 22px; }
.doc li { margin: 4px 0; }
.doc code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.doc pre { background: #0f2437; color: #dbe7f1; padding: 16px 18px; border-radius: 10px; overflow: auto; font-size: 12.4px; line-height: 1.6; }
.doc pre code { background: transparent; padding: 0; color: inherit; }
.doc blockquote { margin: 12px 0; padding: 10px 16px; border-left: 3px solid var(--green); background: var(--green-soft); color: #1d4d36; }
.doc table { margin: 14px 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.doc th { background: #f1f5f9; }
.math-block { overflow-x: auto; padding: 6px 0; }
.katex { font-size: 1.02em; }

.principle { border: 1px solid var(--line); border-radius: 12px; padding: 4px 22px 18px; margin: 16px 0; background: #fcfdfe; }
.principle h3 { margin-top: 18px; }
.anchor-link { color: #9aa7b4; font-size: 11px; margin-left: 8px; }

/* ---------- Progress ---------- */
.bar { height: 7px; border-radius: 6px; background: #e8edf2; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--green), #37c97f); border-radius: 6px; }

/* ---------- Trace ---------- */
.trace-summary { display: flex; align-items: center; gap: 22px; margin-bottom: 18px; }
.trace-summary .big { font-size: 34px; font-weight: 700; color: var(--green-dark); }
.trace-summary .bar { flex: 1; }

/* ---------- Search ---------- */
.search-box { display: flex; gap: 10px; margin: 18px 0; }
.search-box input {
  flex: 1; height: 44px; border-radius: 10px; border: 1px solid var(--line);
  padding: 0 16px; font-size: 14px; outline: none; background: #fff;
}
.search-box input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(0,166,81,0.12); }
.result { display: flex; gap: 14px; padding: 14px 16px; border-bottom: 1px solid #eef2f6; align-items: flex-start; }
.result:last-child { border-bottom: 0; }
.result .id { font-family: "SF Mono", Menlo, monospace; font-size: 12px; color: #31506b; white-space: nowrap; }
.result .body { min-width: 0; }
.result .body b { display: block; }
.result .body span { color: var(--muted); font-size: 12.5px; }

/* ---------- Admin ---------- */
.form { display: grid; gap: 14px; max-width: 560px; }
.form label { display: grid; gap: 6px; font-size: 12.5px; color: #33475b; }
.form input, .form select, .form textarea {
  height: 40px; border-radius: 9px; border: 1px solid var(--line); padding: 0 12px;
  font-size: 13.5px; font-family: inherit; outline: none; background: #fff;
}
.form input:focus, .form select:focus { border-color: var(--green); }
.btn {
  height: 40px; padding: 0 18px; border-radius: 9px; border: 0; cursor: pointer;
  background: var(--green); color: #fff; font-size: 13.5px; font-weight: 600; font-family: inherit;
}
.btn:hover { background: var(--green-dark); }
.btn.ghost { background: #eef2f6; color: #33475b; }
.btn.small { height: 30px; padding: 0 12px; font-size: 12px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.login { max-width: 420px; margin: 60px auto; }

/* ---------- Footer stats ---------- */
.hidden { display: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .model-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; display: grid; grid-template-columns: repeat(2, 1fr); }
  .sidebar h4 { grid-column: 1 / -1; }
  .topsearch input { width: 190px; }
  .brand { min-width: 0; }
  .brand-text em { display: none; }
}
@media (max-width: 640px) {
  .topbar { padding: 0 14px; gap: 12px; }
  .topnav a { padding: 6px 8px; }
  .topsearch { display: none; }
  main { padding: 16px 14px 40px; }
  .hero { padding: 26px 22px; }
  .hero h1 { font-size: 23px; }
  .doc { padding: 20px 18px; }
}

/* ---------- Print (A4) ---------- */
@media print {
  @page { size: A4; margin: 16mm 14mm; }
  body { background: #fff; font-size: 10.5pt; }
  .topbar, .footer, .sidebar, .tabs, .toolbar, .no-print { display: none !important; }
  main { max-width: none; padding: 0; }
  .model-layout { display: block; }
  .doc, .card, .table-wrap { box-shadow: none; border: 0; padding: 0; }
  .tabpanel { display: block !important; }
  .tabpanel[data-tab="principles"], .tabpanel[data-tab="tests"], .tabpanel[data-tab="conclusion"] {
    page-break-before: always;
  }
  .doc h2 { page-break-after: avoid; }
  table { page-break-inside: auto; font-size: 9pt; }
  tr { page-break-inside: avoid; }
  thead { display: table-header-group; }
  .principle { break-inside: avoid; border: 0; padding: 0; }
  .hero, .kpis, .section-head { display: none !important; }
}

/* ---------- P4 内容编辑器 ---------- */
.section-editor { margin-top: 22px; }
.editor-area {
  width: 100%; border: 1px solid var(--line); border-radius: 9px;
  padding: 12px 14px; font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.7; background: #fcfdfe; outline: none; resize: vertical;
}
.editor-area:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(0,166,81,0.10); }
.edit-table td { padding: 5px 6px; }
.edit-table input {
  width: 100%; min-width: 80px; height: 34px; border: 1px solid var(--line);
  border-radius: 6px; padding: 0 8px; font: inherit; font-size: 12.5px; background: #fff; outline: none;
}
.edit-table input:focus { border-color: var(--green); }
.principle-edit { border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; margin: 12px 0; background: #fcfdfe; }
.principle-edit input {
  height: 34px; border: 1px solid var(--line); border-radius: 6px; padding: 0 8px; font: inherit; font-size: 12.5px;
}
.principle-edit textarea { margin-top: 10px; }
.preview { max-height: 520px; overflow: auto; }
.form .btn { justify-self: start; }
