:root {
  --bg: #0d1117;
  --surface: #141a22;
  --surface-2: #1a212b;
  --surface-3: #202936;
  --text: #eef2f7;
  --muted: #98a4b3;
  --faint: #697586;
  --border: #293342;
  --border-strong: #3a4657;
  --accent: #d3a75b;
  --accent-strong: #efc673;
  --accent-soft: rgba(211, 167, 91, 0.13);
  --danger: #ef7c79;
  --success: #73c69a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --radius: 12px;
  --topbar: 72px;
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

:root[data-theme="light"] {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef1f5;
  --text: #1b2430;
  --muted: #657182;
  --faint: #8b95a3;
  --border: #dce1e8;
  --border-strong: #c8d0da;
  --accent: #9a681f;
  --accent-strong: #7e5014;
  --accent-soft: rgba(154, 104, 31, 0.1);
  --danger: #b94f4c;
  --success: #2d8054;
  --shadow: 0 18px 44px rgba(39, 47, 58, 0.12);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}

button, input, select { font: inherit; }
button, select { color: inherit; }
button { cursor: pointer; }

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  height: 100%;
  display: grid;
  grid-template-rows: var(--topbar) 52px 38px minmax(0, 1fr);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 230px) minmax(320px, 560px) 42px;
  gap: 18px;
  align-items: center;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  width: fit-content;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--accent);
  border-radius: 9px;
  color: var(--accent-strong);
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 22px;
  line-height: 1;
}

.brand-copy { display: grid; line-height: 1.2; }
.brand-copy strong { font-size: 16px; letter-spacing: .04em; }
.brand-copy small { margin-top: 5px; color: var(--muted); font-size: 11px; letter-spacing: .08em; }

.version-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
}

.version-field select {
  width: 100%;
  height: 38px;
  padding: 0 34px 0 12px;
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  color: var(--text);
  background-color: var(--surface-2);
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 16px, calc(100% - 10px) 16px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.global-search,
.list-search {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--muted);
}

.global-search { height: 40px; padding: 0 11px; }
.global-search:focus-within,
.list-search:focus-within,
.version-field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.global-search input,
.list-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}
.global-search input { height: 38px; padding: 0 10px; font-size: 13px; }
.global-search input::placeholder,
.list-search input::placeholder { color: var(--faint); }
.global-search kbd {
  border: 1px solid var(--border);
  border-bottom-color: var(--border-strong);
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--faint);
  background: var(--surface);
  font: 10px/1.5 system-ui, sans-serif;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--muted);
  background: var(--surface-2);
}
.icon-button:hover { color: var(--accent-strong); border-color: var(--border-strong); }

.tabs {
  display: flex;
  align-items: end;
  gap: 2px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.tabs button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 18px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 650;
}
.tabs button::after {
  content: "";
  position: absolute;
  right: 16px;
  bottom: -1px;
  left: 16px;
  height: 2px;
  background: transparent;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent-strong); }
.tabs button.active::after { background: var(--accent); }
.tabs b { color: var(--faint); font-size: 11px; font-weight: 600; }
.tabs button.active b { color: var(--accent); }

.contextbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}
.contextbar button { border: 0; color: var(--accent); background: transparent; font-size: 11px; }
.contextbar button:hover { color: var(--accent-strong); }
.context-actions { display: flex; align-items: center; gap: 14px; }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 320px minmax(480px, 1fr) 330px;
  background: var(--bg);
}

.list-panel,
.detail-panel,
.relation-panel { min-width: 0; min-height: 0; }

.list-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.panel-heading { padding: 20px 18px 13px; }
.panel-heading h2 { margin: 0; font-size: 15px; letter-spacing: .02em; }
.panel-heading p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }

.list-search { height: 36px; margin: 0 14px 12px; padding: 0 10px; }
.list-search svg { width: 16px; height: 16px; }
.list-search input { height: 34px; padding-left: 8px; font-size: 12px; }

.entity-list { overflow: auto; padding: 0 8px 16px; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.entity-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  text-align: left;
  background: transparent;
}
.entity-row:hover { color: var(--text); background: var(--surface-2); }
.entity-row.selected { color: var(--text); border-color: var(--border); background: var(--accent-soft); }
.entity-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; font-weight: 600; }
.entity-row span { color: var(--faint); font-size: 10px; white-space: nowrap; }
.entity-row.selected span { color: var(--accent); }

.detail-panel { overflow: auto; padding: 28px clamp(24px, 3vw, 46px) 56px; }

.empty-state {
  min-height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  color: var(--muted);
}
.empty-mark {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin-bottom: 18px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  color: var(--accent);
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 30px;
}
.empty-state h1 { margin: 0; color: var(--text); font-size: 20px; font-weight: 650; }
.empty-state p { margin: 8px 0 0; font-size: 12px; }

.detail-header { padding-bottom: 22px; border-bottom: 1px solid var(--border); }
.detail-header .eyeline { margin: 0 0 8px; color: var(--accent); font-size: 11px; letter-spacing: .08em; }
.detail-header h1 { margin: 0; font-size: clamp(26px, 3vw, 38px); line-height: 1.25; font-weight: 680; letter-spacing: -.03em; }
.detail-header .description { max-width: 760px; margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.meta-line { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 14px; color: var(--faint); font-size: 11px; }
.meta-line span { display: inline-flex; align-items: center; gap: 5px; }
.meta-line b { color: var(--muted); font-weight: 600; }

.detail-section { margin-top: 26px; }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-bottom: 12px; }
.section-heading h2 { margin: 0; font-size: 14px; font-weight: 650; }
.section-heading span { color: var(--faint); font-size: 10px; }

.property-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
}
.property {
  min-height: 72px;
  padding: 13px 15px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.property dt { margin: 0; color: var(--faint); font-size: 10px; }
.property dd { margin: 6px 0 0; overflow-wrap: anywhere; color: var(--text); font-size: 13px; font-weight: 600; }

.data-table { width: 100%; border-collapse: collapse; border: 1px solid var(--border); background: var(--surface); }
.data-table th,
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.data-table th { color: var(--faint); background: var(--surface-2); font-size: 10px; font-weight: 600; }
.data-table td { color: var(--muted); font-size: 11px; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table strong { color: var(--text); font-weight: 600; }
.source-ref { color: var(--accent); font-family: Consolas, "Microsoft YaHei UI", monospace; font-size: 10px; }

.notice {
  padding: 13px 15px;
  border-left: 2px solid var(--accent);
  color: var(--muted);
  background: var(--accent-soft);
  font-size: 11px;
}

.relation-panel {
  overflow: auto;
  padding: 22px 18px 40px;
  background: var(--surface);
  border-left: 1px solid var(--border);
}
.relation-empty { display: grid; place-content: center; min-height: 100%; text-align: center; color: var(--faint); }
.relation-empty span { font-family: "STKaiti", "KaiTi", serif; color: var(--accent); font-size: 24px; }
.relation-empty p { max-width: 190px; margin: 8px 0; font-size: 11px; }
.relation-group + .relation-group { margin-top: 24px; }
.relation-group h3 { margin: 0 0 9px; color: var(--muted); font-size: 11px; font-weight: 650; letter-spacing: .04em; }
.relation-link {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 9px 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-align: left;
  background: transparent;
}
.relation-link:hover strong { color: var(--accent-strong); }
.relation-link strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 600; }
.relation-link span { color: var(--faint); font-size: 9px; }
.relation-note { color: var(--muted); font-size: 10px; }

dialog {
  width: min(900px, calc(100vw - 40px));
  max-height: min(760px, calc(100vh - 40px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(3, 6, 10, .72); backdrop-filter: blur(3px); }
.dialog-shell { display: grid; grid-template-rows: auto minmax(0, 1fr); max-height: inherit; }
.dialog-shell > header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.dialog-shell h2 { margin: 0; font-size: 17px; }
.dialog-shell header p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.global-results,
.meta-content { overflow: auto; padding: 20px 22px 28px; }
.result-section + .result-section { margin-top: 22px; }
.result-section h3 { margin: 0 0 9px; color: var(--muted); font-size: 11px; }
.result-row { width: 100%; display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border: 0; border-bottom: 1px solid var(--border); color: var(--text); text-align: left; background: transparent; }
.result-row:hover strong { color: var(--accent-strong); }
.result-row strong { font-size: 12px; }
.result-row span { color: var(--faint); font-size: 10px; }

.meta-block + .meta-block { margin-top: 24px; }
.meta-block h3 { margin: 0 0 10px; font-size: 13px; }
.meta-block pre { margin: 0; padding: 14px; overflow: auto; border: 1px solid var(--border); color: var(--muted); background: var(--surface-2); font: 11px/1.7 Consolas, monospace; white-space: pre-wrap; }
.warning-list { margin: 0; padding-left: 18px; color: var(--muted); font-size: 11px; }
.warning-list li + li { margin-top: 5px; }

.loading,
.error-state { display: grid; place-items: center; min-height: 180px; padding: 30px; color: var(--muted); text-align: center; font-size: 12px; }
.error-state { color: var(--danger); }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: 360px;
  padding: 10px 14px;
  transform: translateY(16px);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  color: var(--text);
  background: var(--surface-3);
  box-shadow: var(--shadow);
  font-size: 11px;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }

@media (max-width: 1120px) {
  .topbar { grid-template-columns: minmax(210px, 1fr) 190px minmax(260px, 420px) 42px; gap: 12px; padding: 0 16px; }
  .workspace { grid-template-columns: 290px minmax(430px, 1fr); }
  .relation-panel { display: none; }
}

@media (max-width: 760px) {
  body { overflow: auto; }
  .app-shell { min-height: 100%; height: auto; grid-template-rows: auto auto auto minmax(0, 1fr); }
  .topbar { grid-template-columns: 1fr 42px; padding: 14px; }
  .version-field { grid-column: 1 / -1; grid-row: 2; }
  .global-search { grid-column: 1 / -1; grid-row: 3; }
  .tabs { overflow-x: auto; padding: 0 8px; }
  .tabs button { flex: 0 0 auto; padding: 0 14px; }
  .contextbar { padding: 0 14px; }
  .workspace { display: block; }
  .list-panel { height: 390px; border-right: 0; border-bottom: 1px solid var(--border); }
  .detail-panel { min-height: 600px; padding: 24px 16px 44px; }
  .property-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .brand-copy small { display: none; }
}

@media (max-width: 430px) {
  .property-grid { grid-template-columns: 1fr; }
  .contextbar #context-title { max-width: 58%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .context-actions { gap: 8px; }
}

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