:root {
  color-scheme: light;
  --ink: #172634;
  --navy: #1b3c59;
  --navy-2: #254d6d;
  --slate: #405564;
  --muted: #637785;
  --canvas: #e9eef1;
  --surface: #fff;
  --surface-2: #f5f8f9;
  --line: #c9d4dc;
  --line-strong: #9fb1bd;
  --red: #a74640;
  --green: #2c6a57;
  --green-soft: #e8f2ee;
  --amber: #7c5c1f;
  --amber-soft: #f7f0df;
  --red-soft: #f8ecea;
  --blue-soft: #e8f0f5;
  --focus: #2f6f9d;
  --topbar-h: 56px;
  --tabs-h: 48px;
  --z-sticky: 20;
  --z-toast: 60;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; overflow-x: hidden; color: var(--ink); background: var(--canvas); font: 14px/1.62 "Microsoft YaHei", "PingFang SC", system-ui, sans-serif; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 40%, transparent); outline-offset: 2px; }
[hidden] { display: none !important; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 100; padding: 8px 12px; color: #fff; background: var(--ink); transform: translateY(-160%); }
.skip-link:focus { transform: none; }

.topbar { position: sticky; top: 0; z-index: var(--z-sticky); height: var(--topbar-h); padding: 0 max(20px, calc((100vw - 1500px) / 2)); display: flex; align-items: center; justify-content: space-between; gap: 24px; color: #fff; background: var(--ink); border-bottom: 1px solid #3a5264; }
.brand { min-width: 0; display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-mark { flex: 0 0 32px; width: 32px; height: 32px; display: grid; place-items: center; background: var(--red); font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; line-height: 1.25; }
.brand small { color: #c5d1d8; font-size: 10px; }
.top-actions { display: flex; align-items: center; gap: 14px; }
.update-time { color: #c5d1d8; font: 10px Consolas, monospace; }

.primary-nav { position: sticky; top: var(--topbar-h); z-index: calc(var(--z-sticky) - 1); min-height: var(--tabs-h); padding: 0 max(20px, calc((100vw - 1500px) / 2)); display: flex; gap: 2px; background: var(--surface); border-bottom: 1px solid var(--line-strong); overflow-x: auto; }
.nav-item { flex: 0 0 auto; min-height: var(--tabs-h); padding: 0 16px; color: var(--slate); background: transparent; border: 0; border-bottom: 3px solid transparent; font-weight: 700; }
.nav-item:hover { color: var(--ink); background: var(--surface-2); }
.nav-item.is-active { color: var(--navy); border-bottom-color: var(--navy); }

.app-shell { min-height: calc(100vh - var(--topbar-h) - var(--tabs-h)); }
.main { width: min(1500px, calc(100% - 40px)); margin: 0 auto; padding: 22px 0 36px; }
.view-header { margin-bottom: 12px; padding-bottom: 12px; display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line-strong); }
.view-header h1 { margin: 0; color: var(--navy); font-size: 24px; line-height: 1.3; letter-spacing: -.02em; }
.view-header p { max-width: 72ch; margin: 5px 0 0; color: var(--slate); }
.dataset-summary { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.summary-chip { min-height: 30px; padding: 4px 8px; display: inline-flex; align-items: center; color: var(--slate); background: var(--surface); border: 1px solid var(--line); font-size: 11px; }
.summary-chip strong { margin-right: 4px; color: var(--ink); font-size: 14px; }
.boundary-note { margin: 0 0 12px; padding: 8px 11px; color: var(--slate); background: var(--surface-2); border: 1px solid var(--line); font-size: 12px; }
.boundary-note summary { color: var(--navy); font-weight: 700; cursor: pointer; }
.boundary-note p { max-width: 90ch; margin: 7px 0 1px; }

.toolbar { margin-bottom: 10px; padding: 10px; display: grid; grid-template-columns: minmax(260px, 1.4fr) minmax(390px, 2fr) auto; gap: 10px; align-items: end; background: var(--surface); border: 1px solid var(--line); }
.search-field, .filter-field { display: grid; gap: 3px; }
.search-field span, .filter-field span { color: var(--slate); font-size: 11px; font-weight: 700; }
.search-field input, .filter-field select { width: 100%; min-height: 38px; padding: 7px 9px; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 0; }
.search-field input::placeholder { color: #687b88; }
.filter-grid { display: grid; grid-template-columns: repeat(3, minmax(120px, 1fr)); gap: 7px; }
.toolbar-actions { display: flex; gap: 7px; }
.button { min-height: 38px; padding: 7px 10px; border: 1px solid var(--navy); font-weight: 700; white-space: nowrap; }
.button.primary { color: #fff; background: var(--navy); }
.button.primary:hover { background: var(--navy-2); }
.button.secondary { color: var(--navy); background: #fff; }
.button.secondary:hover { background: var(--blue-soft); }
.result-note { min-height: 20px; margin: 0 0 5px; color: var(--muted); font-size: 11px; }

.ledger { height: calc(100vh - 318px); min-height: 500px; display: grid; grid-template-columns: minmax(400px, .82fr) minmax(520px, 1.18fr); background: var(--surface); border: 1px solid var(--line-strong); }
.result-list { min-width: 0; overflow: auto; border-right: 1px solid var(--line-strong); }
.result-row { width: 100%; min-height: 104px; padding: 12px 14px; display: grid; gap: 4px; color: var(--ink); background: #fff; border: 0; border-bottom: 1px solid var(--line); text-align: left; }
.result-row:hover { background: var(--surface-2); }
.result-row[aria-selected="true"] { background: var(--blue-soft); outline: 2px solid var(--navy); outline-offset: -2px; }
.row-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.row-id { color: var(--muted); font: 10px Consolas, monospace; }
.row-title { color: var(--navy); font-size: 15px; line-height: 1.42; }
.row-meta { display: flex; flex-wrap: wrap; gap: 4px; }
.row-summary { display: -webkit-box; color: var(--slate); font-size: 12px; line-height: 1.55; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.badge { min-height: 22px; padding: 2px 6px; display: inline-flex; align-items: center; color: var(--slate); background: #fff; border: 1px solid var(--line); font-size: 10px; line-height: 1.2; }
.badge.core, .badge.strong, .badge.complete, .badge.online { color: var(--green); background: var(--green-soft); border-color: #a8cbbb; }
.badge.support, .badge.partial, .badge.preliminary, .badge.candidate, .badge.progress { color: var(--amber); background: var(--amber-soft); border-color: #dac592; }
.badge.negative, .badge.blocked, .badge.pending, .badge.local { color: #8d3c37; background: var(--red-soft); border-color: #ddb8b4; }
.badge.mixed, .badge.unknown, .badge.control { color: var(--navy); background: var(--blue-soft); border-color: #b4c9d6; }

.systems-layout { grid-template-columns: minmax(430px, .92fr) minmax(540px, 1.08fr); }
.systems-layout .result-list { background: #fff; }
.system-tree { padding: 10px 10px 28px; }
.system-tree > .system-tree-item + .system-tree-item { margin-top: 10px; }
.system-tree-item { min-width: 0; }
.system-node { width: 100%; min-height: 42px; padding: 7px 9px; display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; gap: 9px; align-items: center; color: var(--ink); background: transparent; border: 0; text-align: left; }
.system-node:hover { background: var(--surface-2); }
.system-node[aria-selected="true"] { background: var(--blue-soft); box-shadow: inset 3px 0 0 var(--navy); }
.system-node.is-category { min-height: 48px; margin-top: 2px; background: var(--surface-2); }
.system-node.is-category:hover { background: var(--blue-soft); }
.system-node-copy { min-width: 0; display: grid; gap: 1px; }
.system-node-copy strong { color: var(--ink); font-size: 13px; line-height: 1.4; }
.system-node.is-category .system-node-copy strong { color: var(--navy); font-size: 14px; }
.system-node-copy small { color: var(--muted); font-size: 10px; line-height: 1.35; }
.system-status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.system-status-dot.complete { background: var(--green); }
.system-status-dot.partial, .system-status-dot.preliminary, .system-status-dot.candidate { background: var(--amber); }
.system-status-dot.pending, .system-status-dot.blocked { background: var(--red); }
.system-status-dot.control { background: var(--navy); }
.system-result { max-width: 92px; color: var(--muted); font-size: 10px; line-height: 1.35; text-align: right; }
.system-result.core, .system-result.strong { color: var(--green); }
.system-result.support { color: var(--amber); }
.system-result.negative { color: #8d3c37; }
.system-result.mixed { color: var(--navy); }
.system-children { margin-left: 13px; padding: 2px 0 2px 15px; border-left: 1px solid var(--line); }
.system-children .system-node { min-height: 39px; }

.system-progress-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.system-child-index { border-top: 1px solid var(--line); }
.system-child-index button { width: 100%; min-height: 42px; padding: 8px 2px; display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--ink); background: transparent; border: 0; border-bottom: 1px solid var(--line); text-align: left; }
.system-child-index button:hover { color: var(--navy); background: var(--surface-2); }
.system-child-index small { color: var(--muted); white-space: nowrap; }
.gap-list, .linked-records { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.gap-list li, .linked-records li { margin: 0; border-bottom: 1px solid var(--line); }
.gap-list button { width: 100%; min-height: 42px; padding: 7px 2px; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--ink); background: transparent; border: 0; text-align: left; }
.gap-list button:hover { color: var(--navy); background: var(--surface-2); }
.gap-section { padding: 10px 12px; background: var(--amber-soft); }
.boundary-section { padding: 11px 12px; background: var(--surface-2); border: 1px solid var(--line); }
.empty-inline { color: var(--muted) !important; }
.linked-record { width: 100%; min-height: 54px; padding: 8px 2px; display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--ink); background: transparent; border: 0; text-align: left; }
.linked-record:hover { color: var(--navy); background: var(--surface-2); }
.linked-record > span:first-child { min-width: 0; display: grid; gap: 2px; }
.linked-record b { font-size: 12px; line-height: 1.45; }
.linked-record small { color: var(--muted); font-size: 10px; }
.linked-record-state { flex: 0 0 auto; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.linked-record-id { color: var(--muted); font: 10px Consolas, monospace; }
.linked-record.is-missing { padding: 9px 2px; display: flex; gap: 8px; color: var(--red); }

.inspector { min-width: 0; padding: 23px 26px 44px; overflow: auto; }
.detail-head { padding-bottom: 15px; border-bottom: 1px solid var(--line-strong); }
.detail-kicker { margin: 0 0 5px; color: var(--muted); font: 10px Consolas, monospace; }
.detail-head h2 { margin: 0; color: var(--navy); font-size: 22px; line-height: 1.4; text-wrap: balance; }
.detail-badges { margin-top: 9px; display: flex; flex-wrap: wrap; gap: 5px; }
.detail-lead { max-width: 72ch; margin: 14px 0 0; color: var(--slate); font-size: 14px; line-height: 1.8; }
.detail-section { margin-top: 22px; }
.detail-section h3 { margin: 0 0 7px; color: var(--ink); font-size: 14px; }
.detail-section p { max-width: 78ch; margin: 0; color: var(--slate); }
.fact-list, .source-list { margin: 0; padding-left: 20px; color: var(--slate); }
.fact-list li, .source-list li { margin: 5px 0; }
.source-list code, .path-box code { font: 11px/1.65 Consolas, "Microsoft YaHei", monospace; overflow-wrap: anywhere; }
.source-entry { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.source-entry a { color: var(--navy); font-weight: 700; }
.path-details { margin-top: 10px; color: var(--muted); font-size: 11px; }
.path-details summary { cursor: pointer; }
.compare-wrap { overflow-x: auto; border: 1px solid var(--line); }
.compare-table { width: 100%; border-collapse: collapse; min-width: 640px; }
.compare-table th, .compare-table td { padding: 8px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 11px; }
.compare-table th { color: #fff; background: var(--navy); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.detail-field { padding: 10px 11px; background: var(--surface-2); border: 1px solid var(--line); }
.detail-field b { display: block; margin-bottom: 3px; color: var(--navy); font-size: 11px; }
.detail-field span { color: var(--slate); font-size: 12px; }
.detail-actions { margin-top: 22px; display: flex; flex-wrap: wrap; gap: 7px; }
.detail-link, .copy-button, .text-button { min-height: 38px; padding: 7px 11px; display: inline-flex; align-items: center; color: var(--navy); background: #fff; border: 1px solid var(--navy); text-decoration: none; font-weight: 700; }
.detail-link.primary { color: #fff; background: var(--navy); }
.detail-link:hover, .copy-button:hover, .text-button:hover { background: var(--blue-soft); }
.local-reference { width: 100%; padding: 9px 10px; display: grid; grid-template-columns: minmax(120px, auto) 1fr auto; gap: 9px; align-items: center; border-top: 1px solid var(--line); }
.local-reference code { overflow-wrap: anywhere; color: var(--muted); }

.ledger.catalog-layout { height: auto; min-height: 0; display: block; }
.catalog-layout .result-list { border: 0; overflow: visible; }
.catalog-layout .inspector { display: none; }
.catalog-row { min-height: 112px; padding: 17px 18px; display: grid; grid-template-columns: 210px minmax(0, 1fr) auto; gap: 24px; align-items: center; border-bottom: 1px solid var(--line); }
.catalog-row:last-child { border-bottom: 0; }
.catalog-row:hover { background: var(--surface-2); }
.catalog-meta { display: grid; gap: 5px; align-content: center; }
.catalog-pair { color: var(--navy); font-weight: 700; }
.catalog-kind { color: var(--muted); font-size: 11px; }
.catalog-body h2 { margin: 0 0 5px; color: var(--ink); font-size: 17px; line-height: 1.4; }
.catalog-body p { max-width: 78ch; margin: 0; color: var(--slate); font-size: 13px; }
.catalog-actions { min-width: 134px; display: grid; gap: 7px; }
.catalog-actions a { min-height: 38px; padding: 7px 11px; display: inline-flex; align-items: center; justify-content: center; color: var(--navy); background: #fff; border: 1px solid var(--navy); text-decoration: none; font-weight: 700; white-space: nowrap; }
.catalog-actions a.primary { color: #fff; background: var(--navy); }
.catalog-actions a:hover { background: var(--blue-soft); }
.catalog-actions a.primary:hover { background: var(--navy-2); }

.empty-state { padding: 44px 24px; text-align: center; color: var(--slate); }
.empty-state h2 { margin: 0 0 5px; color: var(--ink); font-size: 18px; }
.dataset-version { margin: 10px 0 0; color: var(--muted); font: 10px Consolas, monospace; text-align: right; white-space: pre-line; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: var(--z-toast); max-width: 360px; padding: 9px 13px; color: #fff; background: var(--ink); border: 1px solid #5c7180; }

@media (max-width: 1120px) {
  .toolbar { grid-template-columns: 1fr; }
  .toolbar-actions { justify-content: flex-end; }
  .ledger { height: auto; min-height: 0; grid-template-columns: 1fr; }
  .result-list { max-height: 500px; border-right: 0; border-bottom: 1px solid var(--line-strong); }
  .inspector { min-height: 480px; }
  .catalog-layout .result-list { max-height: none; border-bottom: 0; }
  .catalog-row { grid-template-columns: 180px minmax(0, 1fr) auto; gap: 18px; }
  .systems-layout { grid-template-columns: 1fr; }
  .systems-layout .result-list { max-height: 560px; }
}

@media (max-width: 760px) {
  .topbar { position: static; height: auto; min-height: 56px; padding: 8px 14px; }
  .update-time { display: none; }
  .primary-nav { position: static; padding: 0 10px; }
  .nav-item { padding: 0 12px; }
  .main { width: calc(100% - 24px); padding-top: 16px; }
  .view-header { display: block; }
  .view-header h1 { font-size: 21px; }
  .dataset-summary { margin-top: 9px; justify-content: flex-start; }
  .toolbar { padding: 9px; }
  .filter-grid { grid-template-columns: 1fr; }
  .toolbar-actions { display: grid; grid-template-columns: 1fr; }
  .button { width: 100%; white-space: normal; }
  .result-list { max-height: 440px; }
  .inspector { min-height: 0; padding: 19px 16px 32px; }
  .detail-head h2 { font-size: 20px; }
  .detail-grid, .local-reference { grid-template-columns: 1fr; }
  .catalog-row { padding: 15px 14px; grid-template-columns: 1fr; gap: 9px; }
  .catalog-meta { display: flex; flex-wrap: wrap; gap: 7px; }
  .catalog-actions { min-width: 0; grid-template-columns: 1fr; }
  .systems-layout .result-list { max-height: 52vh; }
  .system-tree { padding: 7px 6px 22px; }
  .system-node { grid-template-columns: 8px minmax(0, 1fr); }
  .system-result { grid-column: 2; max-width: none; text-align: left; }
  .system-children { margin-left: 8px; padding-left: 10px; }
  .system-progress-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .linked-record { align-items: flex-start; }
  .linked-record-state { max-width: 125px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}

@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; font-size: 10pt; }
  .skip-link, .top-actions, .primary-nav, .toolbar, .result-list, .toast, .boundary-note, .dataset-version { display: none !important; }
  .topbar { position: static; height: auto; min-height: 0; padding: 0 0 8mm; color: #000; background: #fff; border-bottom: 1px solid #555; }
  .brand-mark { display: none; }
  .brand strong { font-size: 15pt; }
  .brand small { color: #444; }
  .main { width: auto; padding: 7mm 0 0; }
  .view-header { display: block; }
  .dataset-summary { margin-top: 4mm; justify-content: flex-start; }
  .ledger { display: block; height: auto; min-height: 0; border: 0; }
  .inspector { padding: 0; overflow: visible; }
  .detail-head, .detail-section { break-inside: avoid; }
  .detail-actions { display: none; }
  .compare-wrap { overflow: visible; }
  .compare-table { min-width: 0; }
  .catalog-layout .result-list { display: block !important; }
  .catalog-row { break-inside: avoid; grid-template-columns: 33mm 1fr; padding: 4mm 0; }
  .catalog-actions { display: none; }
}
