:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-soft: #eef3f0;
  --ink: #1e2622;
  --muted: #65716a;
  --border: #dce3df;
  --border-strong: #c7d1cb;
  --accent: #0f766e;
  --accent-dark: #0a5a54;
  --accent-soft: #e4f2ef;
  --diagnosis: #245ea8;
  --diagnosis-soft: #eaf1fb;
  --procedure: #a83257;
  --procedure-soft: #faeaf0;
  --amber: #a95d0b;
  --amber-soft: #fff4df;
  --danger: #aa3028;
  --danger-soft: #fdecea;
  --shadow: 0 16px 40px rgba(26, 38, 31, 0.12);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
}

body {
  min-width: 320px;
  overflow: hidden;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.2);
  outline-offset: 1px;
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.8;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.identity-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #edf1ef;
}

.identity-panel {
  width: min(560px, 100%);
  padding: 34px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-line,
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  font-weight: 700;
}

.brand-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: #ffffff;
  background: var(--accent);
  border-radius: 6px;
}

.brand-icon-small {
  width: 34px;
  height: 34px;
}

.identity-panel h1 {
  margin: 38px 0 20px;
  font-size: 26px;
  line-height: 1.2;
}

.identity-options {
  display: grid;
  gap: 10px;
}

.identity-option {
  min-height: 82px;
  width: 100%;
  display: grid;
  grid-template-columns: 46px 1fr 24px;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  text-align: left;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

.identity-option:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.identity-option-adjudicator {
  border-left: 3px solid var(--amber);
}

.identity-number {
  color: var(--accent);
  font-size: 19px;
  font-weight: 750;
}

.identity-copy {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.identity-copy strong {
  font-size: 16px;
}

.identity-copy span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.sample-stamp {
  margin-top: 22px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: 58px 1fr;
}

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-brand > div:last-child {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.topbar-brand strong,
.topbar-brand span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-brand span {
  color: var(--muted);
  font-size: 11px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.save-state {
  min-width: 66px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.save-state.dirty {
  color: var(--amber);
}

.save-state.error {
  color: var(--danger);
}

.icon-button,
.icon-text-button,
.secondary-button,
.primary-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border-radius: 6px;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.icon-button {
  width: 38px;
  padding: 0;
  background: transparent;
  color: var(--muted);
}

.icon-button:hover {
  color: var(--ink);
  background: var(--surface-soft);
}

.icon-text-button,
.secondary-button {
  padding: 0 13px;
  background: #ffffff;
  border: 1px solid var(--border-strong);
}

.icon-text-button:hover,
.secondary-button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.primary-button {
  padding: 0 18px;
  color: #ffffff;
  background: var(--accent);
}

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

.text-button {
  min-height: 32px;
  padding: 0 8px;
  color: var(--muted);
  background: transparent;
}

.text-button:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.workspace {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
}

.task-pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) 48px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.progress-section,
.filters-section {
  padding: 15px 16px;
  border-bottom: 1px solid var(--border);
}

.progress-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.progress-heading > div {
  display: grid;
  gap: 5px;
}

.progress-heading strong {
  font-size: 19px;
}

.progress-heading > span {
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
}

.section-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.progress-track {
  height: 6px;
  margin-top: 12px;
  overflow: hidden;
  background: #e6ebe8;
  border-radius: 3px;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 250ms ease;
}

.progress-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 11px;
}

.progress-counts b {
  color: var(--ink);
}

.progress-counts em {
  font-style: normal;
}

.filters-section {
  display: grid;
  gap: 10px;
}

.search-control {
  position: relative;
  display: block;
}

.search-control svg {
  position: absolute;
  top: 10px;
  left: 11px;
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}

.search-control input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 36px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.filter-row select,
.form-grid select,
.form-grid input,
.form-grid textarea,
.comment-section textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: #ffffff;
}

.filter-row select {
  height: 36px;
  padding: 0 9px;
  color: var(--muted);
  font-size: 12px;
}

.task-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.task-item {
  width: 100%;
  min-height: 76px;
  display: grid;
  grid-template-columns: 4px 1fr;
  gap: 12px;
  padding: 11px 14px 11px 0;
  text-align: left;
  background: #ffffff;
  border-bottom: 1px solid #edf0ee;
}

.task-item:hover {
  background: #f7f9f8;
}

.task-item.active {
  background: var(--accent-soft);
}

.task-item-marker {
  width: 4px;
  height: 100%;
  background: transparent;
}

.task-item.active .task-item-marker {
  background: var(--accent);
}

.task-item-content {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.task-item-top {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 10px;
}

.task-item-top span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-item-text {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.task-status-dot {
  width: 7px;
  height: 7px;
  margin-left: auto;
  flex: 0 0 auto;
  background: #b5bdb9;
  border-radius: 50%;
}

.task-status-dot.in_progress { background: var(--amber); }
.task-status-dot.ai_prefilled { background: var(--diagnosis); }
.task-status-dot.auto_approved_exact { background: var(--accent); }
.task-status-dot.completed { background: var(--accent); }
.task-status-dot.needs_clarification { background: var(--danger); }

.list-empty {
  padding: 42px 20px;
  color: var(--muted);
  text-align: center;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-top: 1px solid var(--border);
}

.pagination span {
  min-width: 64px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.editor-pane {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  background: var(--bg);
}

.mobile-editor-bar {
  display: none;
}

.empty-editor {
  min-height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: var(--muted);
}

.empty-editor svg {
  width: 32px;
  height: 32px;
}

.annotation-form {
  width: min(1120px, 100%);
  min-height: 100%;
  margin: 0 auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.component-section,
.context-section,
.mapping-section,
.fields-section,
.ai-prefill-explanation,
.comment-section {
  padding: 22px 28px;
  border-bottom: 1px solid var(--border);
}

.component-section {
  background: #ffffff;
}

.policy-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: -4px 0 18px;
  padding: 11px 13px;
  color: #72501d;
  background: var(--amber-soft);
  border-left: 3px solid var(--amber);
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.5;
}

.policy-banner svg {
  width: 16px;
  height: 16px;
  margin-top: 1px;
  flex: 0 0 auto;
}

.prefill-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: -4px 0 18px;
  padding: 11px 13px;
  color: #244c77;
  background: var(--diagnosis-soft);
  border-left: 3px solid var(--diagnosis);
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.5;
}

.prefill-banner svg {
  width: 16px;
  height: 16px;
  margin-top: 1px;
  flex: 0 0 auto;
}

.component-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.type-badge,
.status-badge,
.priority-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
}

.priority-badge {
  color: #ffffff;
  background: var(--danger);
}

.priority-badge.priority-p1 { background: var(--amber); }
.priority-badge.priority-p2 { background: var(--muted); }

.type-badge.diagnosis {
  color: var(--diagnosis);
  background: var(--diagnosis-soft);
}

.type-badge.procedure {
  color: var(--procedure);
  background: var(--procedure-soft);
}

.status-badge {
  margin-left: auto;
  color: var(--muted);
  background: var(--surface-soft);
}

.status-badge.in_progress {
  color: var(--amber);
  background: var(--amber-soft);
}

.status-badge.ai_prefilled {
  color: var(--diagnosis);
  background: var(--diagnosis-soft);
}

.status-badge.auto_approved_exact {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.status-badge.completed {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.status-badge.needs_clarification {
  color: var(--danger);
  background: var(--danger-soft);
}

.comparison-section {
  padding: 22px 28px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
}

.difference-count {
  color: var(--muted);
  font-size: 12px;
}

.issue-callout {
  margin-bottom: 14px;
  padding: 10px 12px;
  color: var(--danger);
  background: var(--danger-soft);
  border-left: 3px solid var(--danger);
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.55;
}

.comparison-head,
.comparison-row {
  display: grid;
  grid-template-columns: minmax(130px, 0.65fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 1px;
  background: var(--border);
  border-right: 1px solid var(--border);
  border-left: 1px solid var(--border);
}

.comparison-head {
  color: var(--muted);
  background: #edf1ef;
  border-top: 1px solid var(--border);
  border-radius: 5px 5px 0 0;
  font-size: 11px;
}

.comparison-head > *,
.comparison-row > * {
  min-width: 0;
  padding: 10px 12px;
  background: #ffffff;
}

.comparison-head > * {
  background: #f1f4f2;
}

.comparison-head strong:nth-child(2) { color: var(--diagnosis); }
.comparison-head strong:nth-child(3) { color: var(--procedure); }

.comparison-row:last-child {
  border-bottom: 1px solid var(--border);
  border-radius: 0 0 5px 5px;
  overflow: hidden;
}

.comparison-field {
  color: #435049;
  font-size: 12px;
  font-weight: 700;
}

.comparison-value {
  color: var(--ink);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.comparison-value.empty {
  color: #9aa49f;
  font-style: italic;
}

.adjudication-resolution {
  grid-template-columns: repeat(3, 1fr);
}

.component-section h1 {
  margin: 16px 0 10px;
  font-size: 23px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.normalized-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
}

.normalized-row code {
  color: #44504a;
  font-family: Consolas, "Microsoft YaHei", monospace;
  overflow-wrap: anywhere;
}

.context-section {
  display: grid;
  gap: 18px;
  background: #f8faf9;
}

.context-primary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.context-primary > div + div {
  padding-left: 24px;
  border-left: 1px solid var(--border);
}

.context-primary p {
  margin: 0;
  font-size: 14px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.context-facts {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  overflow: hidden;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.context-facts > div {
  min-width: 0;
  padding: 9px 10px;
  background: #ffffff;
}

.context-facts dt {
  color: var(--muted);
  font-size: 10px;
}

.context-facts dd {
  margin: 4px 0 0;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.section-heading h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  min-height: 42px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
}

.segmented-control button {
  min-width: 0;
  padding: 8px 10px;
  background: #ffffff;
  border-right: 1px solid var(--border-strong);
  font-size: 13px;
}

.segmented-control button:last-child {
  border-right: 0;
}

.segmented-control button:hover {
  background: var(--surface-soft);
}

.segmented-control button.selected {
  color: #ffffff;
  background: var(--accent);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-grid label,
.comment-section label {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 7px;
}

.form-grid label > span {
  color: #39443e;
  font-size: 12px;
  font-weight: 650;
}

.form-grid input,
.form-grid select {
  height: 40px;
  padding: 0 11px;
}

.form-grid textarea,
.comment-section textarea {
  min-height: 74px;
  padding: 10px 11px;
  line-height: 1.45;
  resize: vertical;
}

.form-grid input:hover,
.form-grid select:hover,
.form-grid textarea:hover,
.comment-section textarea:hover {
  border-color: #aebbb4;
}

.span-2 {
  grid-column: span 2;
}

.comment-section textarea {
  min-height: 92px;
}

.ai-prefill-explanation {
  background: #f7f9fc;
}

.ai-prefill-explanation p {
  margin: 0;
  color: #354a60;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.action-bar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  background: rgba(255, 255, 255, 0.97);
  border-top: 1px solid var(--border);
  box-shadow: 0 -8px 24px rgba(33, 46, 39, 0.06);
}

.action-bar-left,
.action-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.action-bar-left span {
  min-width: 62px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.task-pane-backdrop {
  display: none;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 82px;
  z-index: 80;
  max-width: min(380px, calc(100vw - 40px));
  padding: 11px 14px;
  color: #ffffff;
  background: #29342e;
  border-radius: 6px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 150ms ease, transform 150ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: var(--danger);
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 300px minmax(0, 1fr);
  }

  .context-facts {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .component-section,
  .context-section,
  .mapping-section,
  .fields-section,
  .ai-prefill-explanation,
  .comparison-section,
  .comment-section {
    padding-right: 20px;
    padding-left: 20px;
  }
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: 100dvh;
  }

  .topbar {
    padding: 0 12px;
  }

  .topbar-actions .icon-text-button span,
  .save-state {
    display: none;
  }

  .topbar-actions .icon-text-button {
    width: 38px;
    padding: 0;
  }

  .workspace {
    display: block;
    min-height: 0;
  }

  .task-pane {
    position: fixed;
    top: 58px;
    bottom: 0;
    left: 0;
    z-index: 60;
    width: min(340px, 88vw);
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

  .task-pane.open {
    transform: translateX(0);
  }

  .task-pane-backdrop {
    position: fixed;
    top: 58px;
    right: 0;
    bottom: 0;
    left: min(340px, 88vw);
    z-index: 50;
    display: block;
    background: rgba(20, 29, 24, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
  }

  .task-pane-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .editor-pane {
    height: calc(100dvh - 58px);
  }

  .mobile-editor-bar {
    position: sticky;
    top: 0;
    z-index: 11;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: #ffffff;
    border-bottom: 1px solid var(--border);
  }

  .mobile-editor-bar span {
    color: var(--muted);
    font-size: 12px;
  }

  .annotation-form {
    border: 0;
  }

  .component-section,
  .context-section,
  .mapping-section,
  .fields-section,
  .ai-prefill-explanation,
  .comparison-section,
  .comment-section {
    padding: 18px 16px;
  }

  .component-section h1 {
    font-size: 20px;
  }

  .context-primary,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .context-primary > div + div {
    padding-top: 14px;
    padding-left: 0;
    border-top: 1px solid var(--border);
    border-left: 0;
  }

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

  .span-2 {
    grid-column: span 1;
  }

  .segmented-control {
    grid-template-columns: repeat(2, 1fr);
  }

  .adjudication-resolution {
    grid-template-columns: 1fr;
  }

  .adjudication-resolution button {
    border-right: 0;
    border-bottom: 1px solid var(--border-strong);
  }

  .adjudication-resolution button:last-child {
    border-bottom: 0;
  }

  .comparison-head {
    display: none;
  }

  .comparison-row {
    grid-template-columns: 1fr;
    margin-bottom: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 5px;
  }

  .comparison-row > * {
    border-bottom: 1px solid var(--border);
  }

  .comparison-row > *:last-child {
    border-bottom: 0;
  }

  .segmented-control button:nth-child(2) {
    border-right: 0;
  }

  .segmented-control button:nth-child(-n+2) {
    border-bottom: 1px solid var(--border-strong);
  }

  .action-bar {
    align-items: stretch;
    flex-direction: column;
    padding: 10px 12px;
  }

  .action-bar-left {
    justify-content: center;
  }

  .action-bar-right {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .action-bar-right .primary-button {
    grid-column: span 2;
  }
}

@media (max-width: 480px) {
  .identity-shell {
    padding: 12px;
  }

  .identity-panel {
    padding: 24px 18px;
  }

  .identity-panel h1 {
    margin-top: 30px;
    font-size: 23px;
  }

  .identity-option {
    grid-template-columns: 38px 1fr 20px;
    gap: 10px;
    padding: 12px;
  }

  .topbar-brand > div:last-child strong {
    max-width: 118px;
  }

  .context-facts {
    grid-template-columns: 1fr 1fr;
  }
}
