@font-face {
  font-family: "XMBiaoHei";
  src: url("XM_BiaoHei%20(2).ttf") format("truetype");
  font-display: swap;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px; color: #222; background: #f6f7f9;
}
.hidden { display: none !important; }

#topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 18px; background: #1f2937; color: #f4f4f5;
}
#topbar .title { font-weight: 600; }
#topbar .who { font-size: 13px; color: #cbd5e1; }
#topbar a { color: #93c5fd; margin-left: 8px; }

/* ---------- setup ---------- */
#setup { max-width: 1100px; margin: 24px auto; padding: 0 18px; }
.setup-grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px;
}
.dropzone { transition: background .12s, border-color .12s; }
.dropzone.dragover { background: #dbeafe; border-color: #2563eb; }
.up {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
  padding: 14px; display: flex; flex-direction: column; gap: 6px;
}
.up .num {
  display: inline-block; width: 22px; height: 22px; border-radius: 50%;
  background: #1f2937; color: #fff; text-align: center; line-height: 22px;
  font-weight: 700; margin-right: 6px; font-size: 12px;
}
.status { color: #6b7280; font-style: normal; font-size: 12px; }
.status.ok { color: #047857; }
.status.err { color: #b91c1c; }

#dashboard {
  margin-top: 18px; background: #fff; border: 1px solid #e5e7eb;
  border-radius: 8px; padding: 14px;
  display: flex; flex-direction: column; gap: 14px;
}
#dash-stats {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px;
}
.stat { text-align: center; }
.stat .big { font-size: 28px; font-weight: 700; color: #1f2937; }
.stat .lab { font-size: 11px; color: #6b7280; text-transform: uppercase; letter-spacing: .04em; }

#dash-controls {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 18px;
  align-items: end; border-top: 1px solid #e5e7eb; padding-top: 14px;
}
.ctrl { display: flex; flex-direction: column; gap: 4px; }
.ctrl label {
  font-size: 11px; font-weight: 700; color: #374151;
  text-transform: uppercase; letter-spacing: .04em;
}
.ctrl-row { display: flex; gap: 8px; align-items: center; }
.ctrl-row input[type="range"] { flex: 1; }
.ctrl-row input[type="number"] {
  width: 70px; font: inherit; padding: 4px 6px;
  border: 1px solid #d1d5db; border-radius: 4px;
}
.ctrl select {
  font: inherit; padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 4px;
  background: #fff;
}
.ctrl-hint { font-size: 11px; color: #9ca3af; font-style: normal; }
.ctrl-actions { display: flex; gap: 8px; align-self: end; grid-column: 1 / -1; justify-content: flex-end; }

button {
  font: inherit; padding: 8px 14px; border-radius: 6px; border: 1px solid #d1d5db;
  background: #fff; cursor: pointer;
}
button:hover { background: #f3f4f6; }
button.primary { background: #2563eb; color: #fff; border-color: #2563eb; }
button.primary:hover { background: #1d4ed8; }
button.danger { background: #fff; color: #b91c1c; border-color: #fca5a5; }
button.danger:hover { background: #fee2e2; }
button.warn { background: #fff; color: #92400e; border-color: #fcd34d; }
button.warn:hover { background: #fef3c7; }

/* ---------- review ---------- */
#review { max-width: 1800px; margin: 18px auto; padding: 0 18px; }
#review-body {
  display: flex; gap: 14px; align-items: flex-start;
}
#review-right { flex: 1; min-width: 0; }
#review-header {
  display: flex; gap: 14px; align-items: center;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
  padding: 10px 14px; margin-bottom: 14px;
}
#progress { font-weight: 700; font-size: 16px; min-width: 80px; }
#slot-meta { color: #6b7280; flex: 1; font-family: ui-monospace, monospace; font-size: 12px; }

#card {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
  padding: 18px; display: grid; grid-template-columns: 180px 1fr; gap: 14px;
  margin-bottom: 12px;
}
#image-pane {
  display: flex; align-items: center; justify-content: center;
  background: #f3f4f6; border-radius: 6px; min-height: 180px; padding: 8px;
}
#crop-img { max-width: 100%; max-height: 280px; image-rendering: -webkit-optimize-contrast; }
.missing { color: #b91c1c; font-style: italic; }

#streams {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
  align-items: stretch;
}
.stream {
  border: 2px solid #e5e7eb; border-radius: 8px; padding: 12px;
  display: flex; flex-direction: column; gap: 8px; cursor: pointer;
  background: #fff; transition: border-color .12s, background .12s;
  min-height: 220px;
}
.stream:hover:not(.override-stream) { border-color: #93c5fd; background: #eff6ff; }
.stream.selected { border-color: #2563eb; background: #dbeafe; }
.stream.user-picked { border-color: #047857; background: #d1fae5; box-shadow: 0 0 0 2px #10b981; }
.stream.agent-of-record { box-shadow: inset 0 0 0 1px #fbbf24; }
.stream.user-picked.agent-of-record { box-shadow: 0 0 0 2px #10b981, inset 0 0 0 1px #fbbf24; }

/* Agreement between 2-of-3 or all-3 model boxes — soft blue tint so it's
   visible at a glance but doesn't fight the user-pick/agent highlights. */
.stream.agree-pair { background: #e0f2fe; border-color: #7dd3fc; }
.stream.agree-all  { background: #bae6fd; border-color: #0ea5e9; }
.stream.user-picked.agree-pair,
.stream.user-picked.agree-all { background: #d1fae5; }   /* user-pick wins visually */
.agree-chip {
  display: inline-block; margin-left: 4px; padding: 1px 6px;
  border-radius: 10px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
}
.agree-chip.agree-pair { background: #0284c7; color: #fff; }
.agree-chip.agree-all  { background: #0369a1; color: #fff; }
.picked-tag {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  background: #047857; color: #fff; border-radius: 10px;
  font-size: 10px; font-weight: 700;
}
.stream.override-stream { cursor: default; }
.stream.override-stream:hover { background: #fff; border-color: #e5e7eb; }
.src-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: #6b7280; font-weight: 700;
}
.agent-badge {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  background: #fbbf24; color: #78350f; border-radius: 10px;
  font-size: 10px; font-weight: 700;
}
.conf-chip {
  display: inline-block; margin-left: 4px; padding: 1px 7px;
  border-radius: 10px; font-size: 12px; font-weight: 800;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  vertical-align: baseline;
}
.conf-chip.conf-high { background: #10b981; color: #fff; }
.conf-chip.conf-mid  { background: #fbbf24; color: #78350f; }
.conf-chip.conf-low  { background: #ef4444; color: #fff; }
.roman {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 18px; font-weight: 600; word-break: break-all;
}
.manchu {
  font-family: "XMBiaoHei", "Noto Sans Mongolian", serif;
  writing-mode: vertical-lr;
  font-size: 32px; line-height: 1; min-height: 90px;
  align-self: center;
}
.gloss {
  font-size: 11px; line-height: 1.35; color: #4b5563;
  border-top: 1px dashed #e5e7eb; padding-top: 6px; margin-top: 4px;
  max-height: 96px; overflow-y: auto;
}
.gloss:empty { display: none; }
.gloss .gloss-line { margin-bottom: 3px; }
.gloss .gloss-line:last-child { margin-bottom: 0; }
.gloss b { color: #1f2937; font-weight: 600; }
.gloss.hit-exact { background: #ecfdf5; border-color: #a7f3d0; }
.gloss.hit-partial { background: #fef3c7; border-color: #fde68a; }
.gloss.hit-stem { background: #f3f4f6; border-color: #d1d5db; font-style: italic; }

.gloss-tag {
  display: inline-block; font-size: 9px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
  padding: 1px 6px; border-radius: 3px; margin-bottom: 4px;
}
.gloss-tag.tag-exact   { background: #047857; color: #fff; }
.gloss-tag.tag-partial { background: #b45309; color: #fff; }
.gloss-tag.tag-stem    { background: #6b7280; color: #fff; }

.hint { font-size: 10px; color: #9ca3af; margin-top: auto; }
kbd {
  font-family: ui-monospace, monospace; font-size: 11px;
  background: #f3f4f6; border: 1px solid #d1d5db; border-bottom-width: 2px;
  border-radius: 3px; padding: 1px 5px;
}

#override-input {
  font: inherit; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 18px; padding: 8px 10px; border: 1px solid #d1d5db;
  border-radius: 4px; width: 100%;
}
#override-input:focus { outline: 2px solid #2563eb; outline-offset: 1px; }

#actions {
  display: flex; gap: 10px; align-items: center;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
  padding: 10px 14px; margin-bottom: 12px;
}

#agent-info {
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px;
  padding: 12px 14px; font-size: 13px; line-height: 1.5;
}
#agent-info .ai-row { margin-bottom: 4px; }
#agent-info .ai-row:last-child { margin-bottom: 0; }
#ai-source-tag { color: #92400e; font-family: ui-monospace, monospace; font-size: 11px; }

#current-decision-banner {
  background: #d1fae5; border: 1px solid #10b981; border-radius: 8px;
  padding: 10px 14px; margin-bottom: 12px; font-size: 14px;
  display: flex; gap: 10px; align-items: center;
}
.cd-label { font-weight: 700; color: #065f46; }
#cd-kind {
  background: #047857; color: #fff; padding: 2px 8px; border-radius: 4px;
  font-size: 12px; font-weight: 700; text-transform: uppercase;
}
#cd-token {
  font-family: ui-monospace, monospace; font-size: 16px; font-weight: 600;
  color: #064e3b;
}
#cd-meta { color: #065f46; font-size: 12px; margin-left: auto; }

/* Red variant for "deleted as artifact" decisions. */
#current-decision-banner.danger { background: #fee2e2; border-color: #ef4444; }
#current-decision-banner.danger .cd-label { color: #7f1d1d; }
#current-decision-banner.danger #cd-kind { background: #b91c1c; }
#current-decision-banner.danger #cd-token { color: #7f1d1d; }
#current-decision-banner.danger #cd-meta { color: #7f1d1d; }

#manchu-override {
  min-height: 60px; font-size: 24px; align-self: center;
}

#pdf-panel {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
  padding: 8px 10px;
  /* Sticky so the page stays in view as the right column scrolls. Height
     fits the viewport minus a little chrome above. */
  position: sticky; top: 8px;
  flex: 0 0 auto;
  display: flex; flex-direction: column;
  height: calc(100vh - 32px);
  width: clamp(360px, 42vw, 720px);
  min-width: 0;
}
#pdf-panel.collapsed {
  width: auto; height: auto; align-self: flex-start;
}
#pdf-panel.collapsed #pdf-canvas-wrap { display: none; }
#pdf-panel.collapsed #pdf-meta { display: none; }
#pdf-header {
  display: flex; gap: 8px; align-items: center; margin-bottom: 6px;
  flex: 0 0 auto;
}
#pdf-meta { color: #6b7280; font-family: ui-monospace, monospace; font-size: 11px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdf-status {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  background: #eff6ff; color: #1d4ed8; font-size: 11px; font-weight: 700;
}
.pdf-status.error { background: #fee2e2; color: #b91c1c; }
#pdf-canvas-wrap {
  text-align: center; flex: 1 1 auto; min-height: 0;
  overflow: auto;
  background: #f3f4f6; border-radius: 6px; padding: 8px;
  display: flex; align-items: flex-start; justify-content: center;
}
#pdf-canvas { max-width: 100%; height: auto; box-shadow: 0 2px 8px rgba(0,0,0,.12); }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 6px;
  font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.18);
  z-index: 100;
}
