:root {
  --blue: #0077b5;
  --blue2: #0081c8;
  --green: #6ebf5d;
  --red: #e4105b;
  --amber: #b45309;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f5f7fa;
  --card: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,.07);
  --font: Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  --sidebar-w: 190px;
  --header-h: 52px;
  --detail-head-h: 48px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font); color: var(--text); background: var(--bg); }
button, input, select { font: inherit; }
a { color: var(--blue2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ── */
#app-header {
  height: var(--header-h); padding: 0 24px; display: flex; align-items: center; gap: 14px;
  background: var(--card); border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 5;
}
.logo { height: 26px; }
.title { font-weight: 700; color: var(--blue); font-size: .92rem; }
.crumb { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 420px; }
.spacer { flex: 1; }
.button {
  border: 1px solid var(--blue2); color: #fff; background: var(--blue2);
  border-radius: 6px; padding: 7px 12px; cursor: pointer; font-weight: 600; font-size: .82rem;
}
.button.secondary { background: var(--green); border-color: var(--green); }
.button.ghost { background: #fff; color: var(--blue2); }
.button:disabled { opacity: .55; cursor: not-allowed; }

#app-root { min-height: calc(100vh - var(--header-h)); }

/* ── Home Page ── */
.home { padding: 24px; max-width: 1500px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; margin-bottom: 18px; }
h1 { margin: 0 0 5px; font-size: 1.45rem; }
h2 { margin: 0 0 12px; font-size: 1.25rem; }
h3 { margin: 16px 0 8px; color: var(--blue); font-size: .95rem; }
p { line-height: 1.6; }
.page-head p { margin: 0; color: var(--muted); font-size: .88rem; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(110px, 1fr)); gap: 10px; }
.stats div, .metric-row div {
  background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px;
}
.stats strong, .metric-row strong { display: block; font-size: 1.1rem; }
.stats span, .metric-row span { display: block; margin-top: 3px; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .4px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; }
.toolbar select, .toolbar input {
  border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; background: #fff;
}
.toolbar input { flex: 1; }
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th { text-align: left; padding: 11px 13px; color: var(--muted); font-size: .74rem; text-transform: uppercase; background: #f8fafc; border-bottom: 1px solid var(--line); }
td { padding: 12px 13px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f8fbff; }
td small { display: block; color: var(--muted); margin-top: 4px; overflow-wrap: anywhere; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .68rem; font-weight: 700; text-transform: capitalize; }
.badge.green { background: rgba(110,191,93,.16); color: #287a1f; }
.badge.red { background: rgba(228,16,91,.12); color: var(--red); }
.badge.amber { background: rgba(180,83,9,.12); color: var(--amber); }
.badge.grey { background: rgba(0,0,0,.06); color: var(--muted); }
.muted { color: var(--muted); }
.doc-tags { display: grid; gap: 5px; max-width: 310px; }
.doc-tags .badge { width: fit-content; }
.doc-tags strong {
  display: block; font-size: .82rem; line-height: 1.35; overflow-wrap: anywhere;
}
.doc-tags small {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ── Detail Header (compact) ── */
.analytics-page { padding: 24px; max-width: 1600px; margin: 0 auto; }
.analytics-stats { grid-template-columns: repeat(4, minmax(115px, 1fr)); }
.analytics-section {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 16px;
}
.analytics-card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 10px; margin: 8px 0 14px; }
.analytics-card {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 12px;
}
.analytics-card strong { display: block; font-size: 1.35rem; color: var(--text); }
.analytics-card span { display: block; margin-top: 3px; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .4px; }
.analytics-card small { display: block; margin-top: 6px; color: var(--muted); font-size: .75rem; }
.analytics-two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin: 10px 0 14px; }
.analytics-panel { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fbfdff; }
.analytics-panel h3 { margin-top: 0; }
.analytics-bar-row {
  display: grid; grid-template-columns: minmax(90px, 1fr) 2fr auto; gap: 8px; align-items: center;
  font-size: .82rem; margin: 8px 0;
}
.analytics-bar-row > span { overflow-wrap: anywhere; }
.analytics-bar-row div { height: 8px; background: #e8eef5; border-radius: 999px; overflow: hidden; }
.analytics-bar-row i { display: block; height: 100%; background: var(--blue2); border-radius: inherit; }
.analytics-bar-row strong { font-size: .78rem; color: var(--muted); }
.analytics-table tbody tr { cursor: default; }
.analytics-table tbody tr:hover { background: inherit; }
.analytics-section .table-wrap { overflow-x: auto; }
.analytics-table { min-width: 760px; }
.tag-chart-legend { display: flex; gap: 12px; flex-wrap: wrap; margin: 4px 0 12px; color: var(--muted); font-size: .78rem; }
.tag-chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.tag-chart-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.top-tag-chart { display: grid; gap: 10px; }
.top-tag-row {
  display: grid; grid-template-columns: minmax(190px, 290px) minmax(180px, 1fr) 48px;
  gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfdff;
}
.top-tag-label strong { display: block; font-size: .88rem; overflow-wrap: anywhere; }
.top-tag-label small { display: block; color: var(--muted); margin-top: 3px; line-height: 1.35; }
.top-tag-track { height: 18px; background: #e8eef5; border-radius: 999px; overflow: hidden; }
.top-tag-total { height: 100%; display: flex; min-width: 2px; border-radius: inherit; overflow: hidden; }
.top-tag-total i { display: block; height: 100%; }
.top-tag-count { text-align: right; color: var(--text); font-size: .9rem; }

.detail-head {
  padding: 8px 20px; background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; min-height: var(--detail-head-h);
}
.detail-head h1 { font-size: .95rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 520px; }
.detail-head .meta-badges { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.detail-head .meta-badges .badge { font-size: .64rem; }
.detail-head .doc-id-label { color: var(--muted); font-size: .72rem; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 280px; }

/* ── Three-column split layout ── */
.split {
  display: grid;
  grid-template-columns: minmax(320px, 40vw) var(--sidebar-w) 1fr;
  height: calc(100vh - var(--header-h) - var(--detail-head-h));
  min-height: 500px;
}

/* ── PDF Viewer (left) ── */
#viewer { min-width: 0; border-right: 1px solid var(--line); display: flex; flex-direction: column; background: #e8edf3; }
.viewer-tools { padding: 8px 10px; display: grid; gap: 6px; background: var(--card); border-bottom: 1px solid var(--line); }
.viewer-tools select { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 7px; background: #fff; font-size: .8rem; }
.pdf-stage { flex: 1; overflow: auto; padding: 12px; display: flex; align-items: flex-start; justify-content: center; }
.pdf-stage.interactive { padding: 0; align-items: stretch; justify-content: stretch; background: #fff; }
.pdf-frame { width: 100%; height: 100%; border: 0; background: #fff; }

/* ── Tab Sidebar (middle) ── */
.tab-sidebar {
  background: var(--card); border-right: 1px solid var(--line);
  overflow-y: auto; padding: 6px 0; display: flex; flex-direction: column;
}
.tab-group { margin-bottom: 2px; }
.tab-group-header {
  padding: 8px 14px; font-size: .66rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 6px; transition: color .15s;
}
.tab-group-header:hover { color: var(--blue); }
.tab-group-header .chevron {
  display: inline-block; font-size: .6rem; transition: transform .2s;
}
.tab-group-header.collapsed .chevron { transform: rotate(-90deg); }
.tab-group-items { overflow: hidden; }
.tab-group-header.collapsed + .tab-group-items { display: none; }
.tab-item {
  display: block; width: 100%; border: 0; background: transparent;
  text-align: left; padding: 7px 14px 7px 22px; font-size: .78rem;
  color: var(--text); cursor: pointer; transition: all .12s;
  border-left: 3px solid transparent; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.tab-item:hover { background: #f0f4f8; color: var(--blue); }
.tab-item.active {
  background: #eef5fb; color: var(--blue); font-weight: 700;
  border-left-color: var(--green);
}

/* ── Right Content Panel ── */
.right { min-width: 0; overflow: auto; padding: 16px 20px; }

/* Legacy horizontal tabs — hidden now but kept for fallback */
.tabs { display: none; }
.tab { border: 0; background: transparent; padding: 11px 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tab.active { color: var(--blue); border-color: var(--green); font-weight: 700; }

/* ── Panels & Content ── */
.panel, .copy, .object {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 14px; margin-bottom: 12px;
}
.copy { max-width: 820px; }
.copy .deck { border-left: 3px solid var(--blue2); padding-left: 12px; color: #4b5563; font-weight: 600; }
.copy p { font-size: .94rem; }
.review-copy { max-width: 960px; }
.article-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-bottom: 10px; }
details { margin-top: 12px; }
summary { cursor: pointer; color: var(--blue); font-weight: 700; font-size: .84rem; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; font-family: Consolas, monospace; font-size: .8rem; line-height: 1.5; }
.text-pre, .json-pre { background: #f8fafc; border: 1px solid var(--line); border-radius: 6px; padding: 12px; }
.tag-line { color: var(--muted); margin-bottom: 12px; font-weight: 700; }
.tag-card { border: 1px solid var(--line); border-radius: 7px; padding: 13px; margin-bottom: 12px; background: #fff; }
.tag-card header { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 7px; }
.tag-card header strong { color: var(--blue); }
.tag-card header span { color: var(--muted); margin-right: auto; }
.source-list { display: grid; gap: 10px; }
.source-card { border: 1px solid var(--line); border-radius: 7px; padding: 12px; background: #fff; }
.source-card header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.source-card strong { color: var(--blue); overflow-wrap: anywhere; }
.source-meta { display: flex; flex-wrap: wrap; gap: 12px; color: var(--muted); font-size: .8rem; margin-bottom: 10px; }
blockquote { margin: 10px 0 0; border-left: 3px solid var(--green); padding: 8px 10px; background: #f8fafc; }
blockquote strong { display: block; color: var(--muted); font-size: .78rem; margin-bottom: 4px; }
blockquote p { margin: 0 0 5px; }
blockquote small { color: var(--muted); }
.metric-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 12px 0; }
.evaluation-grid { display: grid; grid-template-columns: 1fr; gap: 14px; align-items: start; }
.evaluation-card { background: #fff; border: 1px solid var(--line); border-radius: 7px; padding: 16px; margin: 0 0 14px; }
.metric-table { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; display: table; }
.metric-table th { width: 55%; background: #f8fafc; border-bottom: 1px solid var(--line); text-align: left; }
.metric-table td { text-align: right; font-variant-numeric: tabular-nums; }
.object div { display: grid; grid-template-columns: 170px 1fr; gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); }
.object strong { color: var(--muted); font-size: .78rem; text-transform: uppercase; }
.object span { white-space: pre-wrap; overflow-wrap: anywhere; }
.json-links { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.empty { padding: 42px 16px; text-align: center; color: var(--muted); }
.empty.compact { padding: 18px 12px; background: #f8fafc; border: 1px solid var(--line); border-radius: 6px; }
.job { margin: 0 0 14px; padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: 6px; }

/* ── Accordion Field Cards ── */
.field-list { display: grid; gap: 4px; }

.field-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 6px;
  box-shadow: none; transition: box-shadow .15s, border-color .15s;
  overflow: hidden;
}
.field-card:hover { border-color: #c8d0da; }

/* Collapsed header row */
.field-card > header {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; cursor: pointer; user-select: none;
  transition: background .12s;
}
.field-card > header:hover { background: #f8fafc; }
.field-card > header .fc-chevron {
  flex-shrink: 0; font-size: .7rem; color: var(--muted);
  transition: transform .2s; width: 14px; text-align: center;
}
.field-card > header .fc-label {
  font-weight: 600; font-size: .85rem; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.field-card > header .fc-preview {
  flex: 1; min-width: 0; font-size: .8rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: right; padding-left: 12px;
}
.field-card > header .fc-badges {
  flex-shrink: 0; display: flex; gap: 4px; align-items: center;
}
.field-card h3 { margin: 0; }
.field-card code {
  display: none; /* hidden in collapsed state */
}

/* Expanded state */
.field-card.expanded {
  border-color: #b0bec5; box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.field-card.expanded > header { background: #f4f7fa; border-bottom: 1px solid var(--line); }
.field-card.expanded > header .fc-chevron { transform: rotate(90deg); }
.field-card.expanded > header .fc-preview { display: none; }

/* Expandable body */
.field-card-body {
  display: none; padding: 12px; 
}
.field-card.expanded .field-card-body { display: block; }

.field-card-body .fc-path {
  display: block; color: var(--muted); font-size: .7rem; margin-bottom: 10px;
  font-family: Consolas, monospace; overflow-wrap: anywhere;
}

.field-workbench-stack { display: grid; gap: 10px; }
.field-value-box {
  border: 1px solid var(--line); border-radius: 7px; background: #fff; padding: 10px;
}
.field-section-label {
  display: block; margin-bottom: 6px; color: var(--blue); font-size: .76rem; text-transform: uppercase; font-weight: 700;
}
.structured-preview {
  border: 1px solid var(--line); border-radius: 6px; background: #f8fafc;
  padding: 8px; margin-bottom: 8px;
}
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-list span {
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 8px; font-size: .76rem;
}
.array-preview { display: grid; gap: 8px; }
.array-item {
  background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 9px;
}
.array-item header { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.array-item p { margin: 6px 0; color: var(--muted); font-size: .82rem; }
.array-item dl, .object-preview { display: grid; gap: 5px; margin: 8px 0 0; }
.array-item dl div, .object-preview div {
  display: grid; grid-template-columns: minmax(120px, 28%) 1fr; gap: 8px; align-items: start;
}
.array-item dt, .object-preview dt {
  color: var(--muted); font-size: .72rem; text-transform: uppercase;
}
.array-item dd, .object-preview dd { margin: 0; overflow-wrap: anywhere; }
.array-item small, .object-preview small { color: var(--muted); }
.field-input {
  width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 8px;
  background: #fff; color: var(--text); resize: vertical; line-height: 1.45; font-size: .84rem;
}
.json-edit { font-family: Consolas, monospace; font-size: .82rem; }
.field-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.field-actions .button { font-size: .76rem; padding: 5px 10px; }
.button.mini { padding: 5px 8px; font-size: .76rem; }
.regen-candidates { display: grid; gap: 10px; margin-top: 10px; }
.regen-candidate {
  border: 1px solid #f5c26b; border-radius: 7px; background: #fffaf0; padding: 10px;
}
.regen-candidate header { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.regen-candidate pre {
  max-height: 180px; overflow: auto; background: #fff; border: 1px solid var(--line);
  border-radius: 5px; padding: 8px;
}
.regen-candidate p { margin: 8px 0; color: var(--muted); }
.regen-candidate small { display: block; color: var(--muted); overflow-wrap: anywhere; }
.regen-history { margin-top: 4px; }
.regen-history-item { padding: 7px 0; border-top: 1px solid var(--line); }

/* Nested details inside field body */
.field-box {
  border: 1px solid var(--line); border-radius: 7px; background: #f8fafc; padding: 0;
  overflow: hidden;
}
.field-box > summary,
.field-box > strong {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; color: var(--blue); font-size: .78rem; text-transform: uppercase;
  font-weight: 700; cursor: pointer; user-select: none;
}
.field-box > summary { list-style: none; }
.field-box > summary::-webkit-details-marker { display: none; }
.field-box > summary .box-chevron {
  font-size: .6rem; transition: transform .2s; color: var(--muted);
}
.field-box[open] > summary .box-chevron { transform: rotate(90deg); }
.field-box-content { padding: 0 10px 10px; }
.field-box p { margin: 0; font-size: .82rem; color: var(--muted); }
.field-box details { margin: 6px 0; }
.field-box summary { font-size: .82rem; }
.field-box code { margin: 5px 0; }
.field-box pre {
  max-height: 220px; overflow: auto; background: #fff; border: 1px solid var(--line);
  border-radius: 5px; padding: 8px; margin: 6px 0 0;
}
.evidence-box { background: #fff; }
.evidence-count { margin-bottom: 2px !important; }
.evidence-item {
  border: 1px solid var(--line); border-radius: 6px; background: #f8fafc;
  padding: 10px; margin-top: 8px;
}
.evidence-item header { color: var(--muted); font-size: .78rem; font-weight: 700; margin-bottom: 6px; }
.evidence-item p { margin: 0 0 8px; color: var(--text); font-size: .9rem; }
.evidence-item blockquote {
  margin: 0; border-left: 3px solid var(--green); padding: 8px 10px; background: #fff; white-space: pre-wrap;
}
.more-evidence summary { color: var(--blue); font-weight: 700; cursor: pointer; margin-top: 8px; }
.prompt-box details { border: 1px solid var(--line); border-radius: 6px; padding: 8px; background: #fff; }
.feedback-box .field-box-content textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 8px;
  resize: vertical; margin: 6px 0;
}
.latest-feedback { background: #fff; border-left: 3px solid var(--blue2); padding: 7px 8px; margin-bottom: 7px !important; }
.versions { margin-top: 8px; }
.version-list { display: grid; gap: 8px; margin-top: 8px; }
.version-item { border: 1px solid var(--line); border-radius: 6px; padding: 8px; background: #fff; }
.version-item header { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .78rem; }
.version-item pre { max-height: 150px; overflow: auto; background: #f8fafc; border: 1px solid var(--line); padding: 8px; border-radius: 5px; }
.editorial-panel p { margin-top: 0; color: var(--muted); }
.editorial-meta-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  margin-bottom: 14px;
}
.editorial-meta-head h3 { margin: 0 0 6px; color: var(--blue); }
.editorial-meta-head p { max-width: 720px; }
.editorial-metadata-panel .rich-meta-group { margin-bottom: 10px; }
.editorial-group-description {
  margin: 0; padding: 10px 12px 0; color: var(--muted); font-size: .86rem;
}
.editorial-sections { display: grid; gap: 8px; padding: 10px 12px 12px; }
.editorial-section-group {
  border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: #fff;
}
.editorial-section-group > summary {
  cursor: pointer; padding: 9px 11px; font-weight: 700; color: var(--blue);
  background: #f8fafc; border-bottom: 1px solid var(--line);
}
.editorial-section-group .rich-meta-children { padding: 6px 8px 8px; }
.bottom-actions { margin-top: 12px; }

/* Judge result readable layout */
.judge-list-item { padding: 10px 0; border-top: 1px solid var(--line); }
.judge-list-item strong { color: var(--blue); font-size: .86rem; display: block; margin-bottom: 4px; }
.judge-list-item p { margin: 0; font-size: .86rem; line-height: 1.55; }
.judge-kv { display: grid; grid-template-columns: minmax(120px, 30%) 1fr; gap: 8px; padding: 3px 0; font-size: .84rem; }
.judge-kv-key { color: var(--muted); font-size: .76rem; text-transform: uppercase; font-weight: 600; }
.judge-kv span:last-child { line-height: 1.5; overflow-wrap: anywhere; }
.eval-list-block { border: 1px solid var(--line); border-radius: 7px; margin: 8px 0; overflow: hidden; }
.eval-list-block > summary { padding: 10px 12px; font-weight: 700; font-size: .86rem; color: var(--blue); cursor: pointer; background: #f8fafc; }
.eval-list-body { padding: 0 12px 8px; }

/* SME attach */
.sme-attach { display: flex; gap: 8px; align-items: center; margin-top: 8px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  overflow-y: auto;
}
.modal { width: min(560px, 100%); background: #fff; border-radius: 8px; box-shadow: 0 16px 35px rgba(0,0,0,.18); max-height: calc(100vh - 40px); display: flex; flex-direction: column; overflow: hidden; }
.modal.large { width: min(1120px, 96vw); height: auto; max-height: none; overflow: visible; align-self: flex-start; margin: 16px 0; }
.modal header, .modal footer { padding: 16px 18px; display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.modal footer { border-top: 1px solid var(--line); border-bottom: 0; justify-content: flex-end; }
.modal main { padding: 18px; display: grid; gap: 10px; overflow-y: auto; min-height: 0; flex: 1 1 auto; overscroll-behavior: contain; }
.modal.large main { overflow: visible; flex: 0 0 auto; }
.modal h2 { margin: 0; }
.modal .close { border: 0; background: transparent; font-size: 1.1rem; cursor: pointer; color: var(--muted); }
.modal label { font-weight: 700; color: var(--muted); font-size: .82rem; }
.modal input, .modal select { border: 1px solid var(--line); border-radius: 6px; padding: 9px; background: #fff; width: 100%; }
.modal textarea { border: 1px solid var(--line); border-radius: 6px; padding: 9px; background: #fff; width: 100%; resize: vertical; }
.modal-preview { max-height: 220px; overflow: auto; background: #f8fafc; border: 1px solid var(--line); border-radius: 6px; padding: 10px; }
.modal-prompt { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; min-height: 0; }
.modal-prompt[open] { display: block; max-height: none; }
.modal-prompt > summary { padding: 8px 10px; font-weight: 600; font-size: .82rem; cursor: pointer; background: #f8fafc; flex-shrink: 0; }
.modal-prompt[open] .regen-context-formatted,
.modal-prompt[open] pre { max-height: none; overflow-y: visible; padding: 10px; min-height: 0; }
.modal-prompt[open] .regen-context-formatted { flex: 1; overflow: visible; }
.modal-field-card { border: 0; box-shadow: none; overflow: visible; }
.modal-field-card .field-card-body { display: block; padding: 0; }
.modal-field-card .field-workbench-stack { grid-template-columns: minmax(0, 1.3fr) minmax(300px, .7fr); align-items: start; }
.modal-field-card .field-value-box { grid-row: span 3; }
.modal-field-card .field-input { min-height: 180px; font-size: .92rem; }
.modal-field-card .field-box { max-height: 360px; overflow: auto; }
.modal-field-card .versions { margin-top: 14px; }
.muted { color: var(--muted); font-size: .86rem; }

/* ── Content Tag Accordions ── */
.tag-list { display: grid; gap: 4px; padding: 8px 0; }
.tag-accordion { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; }
.tag-accordion > summary {
  padding: 9px 12px; cursor: pointer; display: flex; align-items: center; gap: 8px;
  font-size: .84rem; list-style: none; transition: background .12s;
}
.tag-accordion > summary::-webkit-details-marker { display: none; }
.tag-accordion > summary strong { color: var(--blue); font-size: .88rem; }
.tag-accordion > summary .tag-topic { color: var(--muted); font-size: .8rem; margin-right: auto; }
.tag-accordion[open] > summary { background: #f4f7fa; border-bottom: 1px solid var(--line); }
.tag-accordion-body { padding: 10px 14px; }
.tag-accordion-body p { margin: 4px 0; font-size: .86rem; line-height: 1.55; }
.tag-evidence { margin-top: 8px; }

/* ── QA Table ── */
.qa-table { width: 100%; }
.qa-table th { text-transform: uppercase; font-size: .76rem; letter-spacing: .03em; }
.qa-sub { display: inline-block; padding: 2px 8px; background: #f0f4f8; border-radius: 4px; font-size: .82rem; margin-right: 6px; }
.qa-sub strong { color: var(--blue); }

/* ── JSON Edit Toggle ── */
.json-edit-toggle { margin-top: 6px; }
.json-edit-toggle summary { font-size: .78rem; }

/* ── Rich Metadata Hierarchy ── */
.rich-meta-panel { padding: 8px 14px; }
.rich-meta-group { border: 1px solid var(--line); border-radius: 7px; margin-bottom: 6px; overflow: hidden; }
.rich-meta-group > summary {
  padding: 10px 12px; font-weight: 700; font-size: .88rem; color: var(--blue);
  cursor: pointer; background: #f8fafc; display: flex; align-items: center; gap: 8px;
}
.rich-meta-group > summary .muted { font-weight: 400; font-size: .76rem; }
.rich-meta-children { padding: 4px 8px 8px; display: grid; gap: 3px; }
.rich-meta-child { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.rich-meta-child > summary {
  padding: 8px 10px; cursor: pointer; display: flex; align-items: center; gap: 8px;
  font-size: .84rem; list-style: none;
}
.rich-meta-child > summary::-webkit-details-marker { display: none; }
.rich-meta-child > summary .fc-label { font-weight: 600; }
.rich-meta-child > summary .fc-preview { flex: 1; text-align: right; color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rich-meta-child[open] > summary { background: #f4f7fa; border-bottom: 1px solid var(--line); }

.article-participants {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 10px;
}
.article-participants p {
  margin: 6px 0;
  font-size: .92rem;
  line-height: 1.55;
}
.generated-meta-grid {
  display: grid;
  gap: 10px;
  padding: 8px;
}
.generated-meta-block {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 12px;
}
.generated-meta-block h4 {
  color: var(--blue);
  margin: 0 0 8px;
}
.metadata-node {
  border-top: 1px solid var(--line);
  padding: 9px 0;
}
.metadata-node:first-of-type { border-top: 0; padding-top: 0; }
.metadata-node p { margin: 4px 0; line-height: 1.5; }
.metadata-node ul { margin: 6px 0 0; padding-left: 18px; }
.metadata-node li { margin: 6px 0; line-height: 1.45; }
.metadata-evidence {
  margin-top: 6px;
  padding: 8px 10px;
  border-left: 3px solid var(--blue2);
  background: #f8fafc;
  border-radius: 0 6px 6px 0;
  color: var(--muted);
  font-size: .82rem;
}
.metadata-evidence-label {
  display: block;
  color: var(--blue);
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 3px;
}

/* ── Regeneration Context (formatted for lawyers) ── */
.regen-context-formatted { padding: 8px 0; }
.regen-section { margin-bottom: 12px; }
.regen-section > strong { display: block; font-size: .82rem; color: var(--blue); text-transform: uppercase; margin-bottom: 4px; }
.regen-section > p { margin: 0; font-size: .86rem; }
.regen-guidance-item { border-left: 3px solid var(--blue2); padding: 6px 10px; margin: 6px 0; background: #f8fafc; border-radius: 0 6px 6px 0; }
.regen-guidance-item em { display: block; color: var(--muted); font-size: .76rem; font-style: normal; text-transform: uppercase; margin-bottom: 2px; }
.regen-guidance-item p { margin: 0; font-size: .84rem; line-height: 1.5; white-space: pre-wrap; }
.regen-evidence-item { margin: 6px 0; }
.regen-evidence-item em { display: block; color: var(--muted); font-size: .78rem; font-style: normal; margin-bottom: 2px; }
.regen-evidence-item blockquote { margin: 4px 0 0; font-size: .84rem; }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; height: auto; }
  #viewer { height: 44vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .tab-sidebar { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .tab-group { display: flex; }
  .tab-group-header { display: none; }
  .tab-group-items { display: flex !important; }
  .tab-item { white-space: nowrap; border-left: 0; border-bottom: 2px solid transparent; padding: 10px 14px; }
  .tab-item.active { border-bottom-color: var(--green); border-left-color: transparent; }
  .right { overflow: visible; }
  .evaluation-grid { grid-template-columns: 1fr; }
  .modal-field-card .field-workbench-stack { grid-template-columns: 1fr; }
}
@media (max-width: 950px) {
  .page-head { flex-direction: column; }
  .stats { width: 100%; }
  .analytics-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  #app-header { padding: 0 12px; gap: 8px; }
  .analytics-page { padding: 14px; }
  .analytics-stats { grid-template-columns: 1fr; }
  .analytics-card-grid { grid-template-columns: 1fr; }
  .top-tag-row { grid-template-columns: 1fr auto; gap: 8px; }
  .top-tag-track { grid-column: 1 / -1; }
}
