:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #1f2933;
  --muted: #617080;
  --blue: #1f6feb;
  --blue-dark: #1554b3;
  --green: #2f855a;
  --amber: #b7791f;
  --red: #c53030;
  --shadow: 0 8px 24px rgba(30, 42, 62, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: var(--blue);
}

button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

button.primary:hover {
  background: var(--blue-dark);
}

button.secondary {
  background: #fff;
}

button.full {
  width: 100%;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace {
  display: grid;
  grid-template-columns: 280px minmax(480px, 1fr) 360px;
  gap: 14px;
  padding: 14px;
  flex: 1;
  min-height: 0;
}

.sidebar,
.detail-pane,
.main-stage {
  min-width: 0;
}

.panel,
.visual-area,
.trend-area,
.stats-strip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 14px;
  margin-bottom: 14px;
}

.panel.fixed {
  max-height: 42vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel h2,
.visual-header h2 {
  margin: 0 0 10px;
  font-size: 15px;
  line-height: 1.3;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-heading h2 {
  margin: 0;
}

.visual-header p,
.panel small,
.empty {
  color: var(--muted);
  font-size: 12px;
}

label {
  display: block;
  margin: 12px 0 6px;
  color: #334155;
  font-size: 13px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.check-row input {
  width: auto;
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

input[type="file"] {
  display: none;
}

input[type="number"],
input[type="text"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
}

.file-drop {
  border: 1px dashed #aab4c2;
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfe;
  cursor: pointer;
}

.file-drop span {
  display: block;
  font-weight: 700;
}

.file-drop small {
  display: block;
  margin-top: 4px;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 14px;
}

.stats-strip div {
  padding: 12px 14px;
  background: #fff;
}

.stats-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stats-strip strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.visual-area,
.trend-area {
  padding: 14px;
}

.visual-area {
  min-height: 590px;
}

.trend-area {
  margin-top: 14px;
}

.visual-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.visual-header.compact {
  margin-bottom: 6px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.segmented button {
  border: 0;
  border-radius: 0;
  min-width: 74px;
}

.segmented button.active {
  background: #e8f1ff;
  color: var(--blue-dark);
  font-weight: 700;
}

.cloud-canvas {
  min-height: 520px;
  border: 1px solid #e5e9f0;
  border-radius: 8px;
  background: #fbfcfe;
  overflow: hidden;
}

.cloud-canvas svg,
.trend-canvas svg {
  display: block;
  width: 100%;
  height: auto;
}

.cloud-word {
  cursor: pointer;
  dominant-baseline: middle;
  text-anchor: middle;
  transition: opacity 0.15s ease, filter 0.15s ease;
  paint-order: stroke;
}

.cloud-word:hover,
.cloud-word.active {
  filter: brightness(0.78);
  text-decoration: underline;
}

.trend-canvas {
  min-height: 170px;
  border: 1px solid #e5e9f0;
  border-radius: 8px;
  background: #fbfcfe;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 8px 6px;
  border-bottom: 1px solid #edf0f5;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
  color: var(--muted);
  font-weight: 700;
}

tr[data-term] {
  cursor: pointer;
}

tr[data-term]:hover,
tr.active {
  background: #eef6ff;
}

.context-panel {
  max-height: calc(58vh - 28px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.context-list {
  overflow: auto;
  padding-right: 4px;
}

.context-item {
  border-bottom: 1px solid #edf0f5;
  padding: 10px 0;
}

.context-item mark {
  background: #fff1a8;
  padding: 0 2px;
}

.context-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  background: #e8f1ff;
  color: var(--blue-dark);
  font-size: 12px;
}

.badge.warn {
  background: #fff3cd;
  color: var(--amber);
}

.badge.bad {
  background: #fee2e2;
  color: var(--red);
}

.badge.ready {
  background: #e6f4ea;
  color: var(--green);
}

.review-panel {
  max-height: calc(58vh - 28px);
  overflow: auto;
}

.review-summary {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid #edf0f5;
  border-radius: 8px;
  background: #fbfcfe;
}

.review-summary span,
.check-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.review-summary strong,
.check-item strong {
  display: block;
  margin-top: 2px;
  font-size: 13px;
}

.checklist {
  margin-top: 12px;
  display: grid;
  gap: 6px;
}

.check-item {
  border-left: 4px solid var(--line);
  padding: 8px 10px;
  background: #fbfcfe;
}

.check-item.ok {
  border-left-color: var(--green);
}

.check-item.warn {
  border-left-color: var(--amber);
}

.check-item.bad {
  border-left-color: var(--red);
}

.risk-list,
.dh-request {
  margin-top: 12px;
}

.risk-list h3,
.dh-request h3 {
  margin: 0 0 6px;
  font-size: 13px;
}

.risk-list ul,
.dh-request ul {
  margin: 0;
  padding-left: 18px;
  color: #334155;
  font-size: 12px;
}

.risk-list li,
.dh-request li {
  margin: 5px 0;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 260px 1fr;
  }

  .detail-pane {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }

  .panel.fixed,
  .context-panel,
  .review-panel {
    max-height: 360px;
  }
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .detail-pane {
    grid-template-columns: 1fr;
  }

  .stats-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* AI 文本洞察面板 */
.ai-panel .panel-heading { display: flex; align-items: center; justify-content: space-between; }
.ai-body { font-size: 12.5px; line-height: 1.6; max-height: 320px; overflow: auto; }
.ai-sec { margin: 8px 0; }
.ai-sec h4 { margin: 0 0 4px; font-size: 12.5px; color: #2563eb; }
.ai-sec p { margin: 0; }
.ai-sec ul { margin: 0; padding-left: 18px; }
.ai-theme { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; }
.ai-theme strong { flex-shrink: 0; }
.ai-theme span { color: #475569; font-size: 12px; }
.ai-loading { color: #64748b; }
.ai-note { color: #94a3b8; font-size: 11.5px; margin: 8px 0 0; }

/* 共现网络 SVG */
.net-svg { width: 100%; height: 100%; display: block; }
.net-node text { paint-order: stroke; stroke: #ffffff; stroke-width: 3px; stroke-linejoin: round; }
.net-node:hover circle { fill-opacity: 1; }

/* 差异词比较 散点 */
.diff-svg { width: 100%; height: 100%; display: block; }
.diff-pt:hover { fill-opacity: 1; }
.diff-label { paint-order: stroke; stroke: #fff; stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
#freqTable tr.selected td { background: #eef4ff; font-weight: 600; }
.diff-ctx { margin-bottom: 10px; padding: 8px 10px; border-radius: 8px; border: 1px solid #e2e8f0; }
.diff-ctx.a { border-left: 3px solid #1f6feb; }
.diff-ctx.b { border-left: 3px solid #c05621; }
.diff-ctx .context-meta { font-weight: 600; margin-bottom: 4px; }
.diff-ctx mark { background: #fde68a; padding: 0 1px; }

/* 原文阅读器 */
.reader-overlay { position: fixed; inset: 0; z-index: 200; background: rgba(15,23,42,.55); display: flex; align-items: center; justify-content: center; padding: 28px; }
.reader-overlay.hidden { display: none; }
.reader-modal { width: min(860px, 96vw); max-height: 90vh; display: flex; flex-direction: column; background: #ffffff; border-radius: 14px; box-shadow: 0 24px 70px rgba(0,0,0,.4); overflow: hidden; }
.reader-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 16px 20px; border-bottom: 1px solid #e2e8f0; }
.reader-head h2 { margin: 0; font-size: 17px; }
.reader-head p { margin: 3px 0 0; color: #64748b; font-size: 12.5px; }
.reader-nav { display: flex; align-items: center; gap: 8px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.reader-count { font-size: 12.5px; color: #475569; margin-right: 4px; }
.reader-body { padding: 20px 22px; overflow: auto; line-height: 2; font-size: 15px; color: #1e293b; white-space: pre-wrap; word-break: break-word; }
.reader-body .rd-hit { background: #fde68a; border-radius: 2px; padding: 0 1px; }
.reader-body .rd-hit.active { background: #f59e0b; color: #fff; box-shadow: 0 0 0 2px rgba(245,158,11,.35); }
.context-item { cursor: pointer; }
.context-item:hover { background: #f1f5f9; }
.ctx-open { float: right; color: #1f6feb; font-size: 11.5px; }
