:root {
  --ink: #18231f;
  --muted: #66736e;
  --line: #dce3df;
  --paper: #ffffff;
  --wash: #f3f6f4;
  --accent: #176b52;
  --accent-soft: #e4f2ed;
  --warn: #9a6400;
  --danger: #a43b35;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--wash);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; }
button, input, textarea { font: inherit; }

.topbar {
  height: 60px;
  padding: 9px 20px;
  background: #173c31;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.eyebrow { margin: 0 0 1px; color: #a9d3c5; font-size: 9px; font-weight: 800; letter-spacing: .13em; }
h1 { margin: 0; font-size: 19px; }
.summary { display: grid; text-align: right; }
.summary strong { font-size: 21px; line-height: 1; }
.summary span { margin-top: 3px; color: #bcd7ce; font-size: 10px; }

.message {
  position: fixed;
  top: 70px;
  right: 18px;
  z-index: 20;
  max-width: min(520px, calc(100vw - 36px));
  padding: 10px 14px;
  border-radius: 9px;
  color: white;
  background: var(--accent);
  box-shadow: 0 8px 24px rgba(17, 48, 38, .2);
}
.message.error { background: var(--danger); }

.layout {
  height: calc(100vh - 60px);
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 0;
}
.sidebar {
  min-height: 0;
  padding: 12px 9px;
  border-right: 1px solid var(--line);
  background: #eaf0ed;
  display: flex;
  flex-direction: column;
}
.sidebar-title { padding: 0 8px 8px; color: var(--muted); font-size: 11px; font-weight: 800; }
.queue { min-height: 0; display: grid; align-content: start; gap: 6px; overflow-y: auto; }
.queue button {
  width: 100%;
  padding: 9px 10px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 9px;
  background: rgba(255,255,255,.68);
  color: var(--ink);
  cursor: pointer;
}
.queue button.active { border-color: var(--accent); background: white; box-shadow: 0 3px 12px rgba(19,54,43,.08); }
.queue .number { color: var(--muted); font-size: 9px; }
.queue .queue-title { display: block; margin: 3px 0 4px; font-size: 12px; font-weight: 750; line-height: 1.35; }
.queue .queue-state { font-size: 9px; color: var(--warn); }
.queue .queue-state.done { color: var(--accent); }

.content {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 12px 16px 10px;
  display: flex;
  flex-direction: column;
}
.card-head {
  flex: 0 0 auto;
  min-height: 52px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.card-head h2 { margin: 5px 0 2px; font-size: 21px; line-height: 1.2; }
.head-actions { display: flex; gap: 6px; }
.status-row { display: flex; align-items: center; gap: 5px; }
.muted, .boundary { color: var(--muted); }
.muted { margin: 0; font-size: 10px; }
.candidate-notice { margin: 1px 0 3px; color: var(--warn); font-size: 10px; font-weight: 700; }
.boundary { margin: 3px 0 8px; font-size: 10px; }
.pill { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 9px; font-weight: 800; }
.pill.pending { color: var(--warn); background: #fff2d4; }
.pill.done { color: var(--accent); background: var(--accent-soft); }
.pill.candidate { color: #6f4b00; background: #f6e8be; }
.pill.recommended { color: #28508a; background: #e5eefc; }

.outline-summary {
  flex: 0 0 auto;
  min-height: 30px;
  margin: 5px 0 9px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255,255,255,.72);
  color: #40504a;
  font-size: 11px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.outline-summary b { color: var(--accent); }

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(480px, 1.18fr) minmax(430px, .82fr);
  gap: 10px;
}
.panel {
  margin: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--paper);
  box-shadow: 0 2px 10px rgba(18,42,34,.035);
}
.panel h3 { margin: 0 0 8px; font-size: 14px; }
.panel-title-row { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.answer-progress {
  flex: none;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--warn);
  background: #fff2d4;
  font-size: 10px;
  font-weight: 800;
}
.answer-progress.complete { color: var(--accent); background: var(--accent-soft); }

.answers-panel { min-height: 0; overflow-y: auto; }
.questions { display: grid; gap: 8px; }
.question-item { padding: 9px 10px; border-radius: 9px; background: var(--wash); }
.question-item.recommended-prefill { box-shadow: inset 3px 0 0 #79a3df; }
.question-title { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 5px; align-items: start; }
.question-number {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--accent);
  font-size: 10px;
  font-weight: 800;
}
.question-text { font-size: 12px; font-weight: 750; line-height: 1.45; }
.question-item textarea { min-height: 48px; margin-top: 6px; resize: vertical; }

.right-column { min-height: 0; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.decision-panel { flex: 0 0 auto; }
.decision-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.decision-options button {
  min-height: 44px;
  padding: 8px 9px;
  border: 1px solid #c9d3ce;
  border-radius: 8px;
  color: var(--ink);
  background: #f8faf9;
  cursor: pointer;
  text-align: left;
}
.decision-options button strong { display: block; margin-bottom: 2px; font-size: 11px; }
.recommended-badge { display: inline-block; margin-left: 5px; padding: 1px 5px; border-radius: 999px; color: #28508a; background: #e5eefc; font-size: 8px; vertical-align: 1px; }
.decision-options button.selected .recommended-badge { color: #174a3b; background: #d5eee6; }
.decision-options button span {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.3;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.decision-options button.selected { border-color: var(--accent); color: white; background: var(--accent); }
.decision-options button.selected span { color: #d5eee6; }

.form-grid { display: grid; gap: 7px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.compact-fields { margin-top: 7px; }
label { display: grid; gap: 4px; margin-top: 7px; color: #42504b; font-size: 10px; font-weight: 700; }
input, textarea {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid #c8d2cd;
  border-radius: 7px;
  color: var(--ink);
  background: white;
  outline: none;
  font-size: 11px;
}
textarea { line-height: 1.4; }
.decision-panel textarea { min-height: 34px; resize: vertical; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.outline { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.outline div { padding: 7px; border-radius: 7px; background: var(--wash); font-size: 10px; }
.outline b { display: block; margin-bottom: 3px; color: var(--muted); font-size: 9px; }
.evidence-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.evidence-grid h3 { font-size: 11px; }
.evidence-item { margin: 6px 0; padding: 7px; border-radius: 7px; background: var(--wash); font-size: 9px; line-height: 1.45; overflow-wrap: anywhere; }
.evidence-item code { display: block; }
.evidence-kind-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.source-kind { color: #40504a; font-weight: 800; }
.source-link { color: var(--accent); font-weight: 800; text-decoration: none; }
.source-link:hover { text-decoration: underline; }
.source-unavailable { color: var(--danger); font-weight: 700; }
.copy { margin-top: 5px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; background: white; cursor: pointer; font-size: 9px; }

.review-dialog {
  width: min(720px, calc(100vw - 40px));
  max-height: min(720px, calc(100vh - 40px));
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--ink);
  background: white;
  box-shadow: 0 18px 60px rgba(10, 35, 27, .25);
  overflow: auto;
}
.wide-dialog { width: min(980px, calc(100vw - 40px)); }
.review-dialog::backdrop { background: rgba(10, 25, 20, .55); backdrop-filter: blur(2px); }
.dialog-head { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.dialog-head h3 { margin: 0 0 3px; font-size: 17px; }
.dialog-head p { margin: 0; color: var(--muted); font-size: 11px; }

.savebar {
  flex: 0 0 auto;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 9px;
  padding: 8px 10px 8px 13px;
  border: 1px solid #b9ccc4;
  border-radius: 10px;
  background: rgba(248,252,250,.98);
  box-shadow: 0 5px 18px rgba(17,58,45,.1);
}
.savebar p { margin: 0; color: var(--muted); font-size: 10px; }
button.primary, button.ghost { padding: 8px 13px; border-radius: 7px; cursor: pointer; font-size: 11px; }
button.primary { border: 0; color: white; background: var(--accent); font-weight: 800; }
button.primary:disabled { opacity: .5; cursor: wait; }
button.ghost { border: 1px solid var(--line); background: white; }

@media (max-height: 760px) and (min-width: 981px) {
  .question-item { padding: 7px 9px; }
  .question-item textarea { min-height: 38px; }
  .panel { padding: 10px; }
  .decision-panel { padding: 8px 10px; }
  .decision-panel h3 { margin-bottom: 5px; }
  .decision-options button { min-height: 36px; padding: 6px 8px; }
  .decision-options button span { -webkit-line-clamp: 1; }
  .decision-panel textarea { min-height: 28px; padding: 5px 7px; }
  .decision-panel input { padding: 5px 7px; }
  .compact-fields { margin-top: 4px; }
  label { margin-top: 3px; }
}

@media (max-width: 980px) {
  body { overflow: auto; }
  .layout { height: auto; min-height: calc(100vh - 60px); grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .queue { grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; }
  .content { height: auto; min-height: 0; padding: 12px; }
  .workspace { grid-template-columns: 1fr; }
  .answers-panel, .right-column { overflow: visible; }
  .outline-summary { white-space: normal; }
}

@media (max-width: 620px) {
  .queue, .form-grid.two, .decision-options, .outline, .evidence-grid { grid-template-columns: 1fr; }
  .card-head { align-items: flex-start; }
}
