:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --surface: #ffffff;
  --surface-soft: #f4f7fb;
  --navy: #17497d;
  --blue: #1463d6;
  --blue-soft: #eaf2ff;
  --green: #087a55;
  --green-soft: #e9f7f1;
  --red: #b4233b;
  --red-soft: #fff0f2;
  --amber: #8a5b00;
  --amber-soft: #fff8e7;
  --radius: 12px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; color: var(--ink); background: #f7f9fc; }
button, input, textarea, select { font: inherit; }
button, a, input, textarea, select { outline-offset: 3px; }
:focus-visible { outline: 3px solid rgba(20, 99, 214, .34); }

.site-header { border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .96); }
.header-inner { width: min(1160px, calc(100% - 32px)); min-height: 72px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: var(--navy); color: #fff; font-weight: 700; }
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: .08em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 12px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.mode-badge, .count-badge, .boundary-status { display: inline-flex; align-items: center; min-height: 30px; padding: 0 10px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.mode-badge { color: var(--navy); background: var(--blue-soft); }

main { width: min(1160px, calc(100% - 32px)); margin: 0 auto; padding: 36px 0 64px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(30px, 4vw, 46px); line-height: 1.12; letter-spacing: -.03em; }
h2 { margin-bottom: 0; font-size: 24px; letter-spacing: -.02em; }
.eyebrow, .section-index { margin-bottom: 8px; color: var(--green); font-size: 12px; font-weight: 700; letter-spacing: .12em; }
.lead, .page-heading p { max-width: 720px; color: var(--muted); line-height: 1.7; }

.login-shell { min-height: calc(100vh - 172px); display: grid; place-items: center; }
.login-panel { width: min(680px, 100%); padding: 38px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.login-panel form { margin-top: 26px; }
label { display: block; margin-bottom: 7px; color: #344054; font-size: 14px; font-weight: 600; }
.input-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
input, textarea, select { width: 100%; border: 1px solid #b8c3d2; border-radius: 8px; color: var(--ink); background: #fff; }
input, select { min-height: 44px; padding: 0 12px; }
textarea { padding: 12px; resize: vertical; line-height: 1.6; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(20, 99, 214, .12); }
.login-note { margin-top: 24px; padding: 14px 16px; border-left: 4px solid var(--green); background: var(--green-soft); }
.login-note strong, .login-note span { display: block; }
.login-note span { margin-top: 4px; color: #35584c; font-size: 14px; line-height: 1.55; }

.button { min-height: 42px; padding: 0 16px; border: 1px solid transparent; border-radius: 8px; cursor: pointer; font-weight: 650; transition: background .15s ease, border-color .15s ease, transform .15s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: .58; transform: none; }
.button-primary { color: #fff; background: var(--blue); }
.button-secondary { color: var(--navy); border-color: #aac1df; background: #fff; }
.button-success { color: #fff; background: var(--green); }
.button-danger { color: var(--red); border-color: #f0a9b5; background: var(--red-soft); }
.button-quiet { min-height: 34px; padding: 0 10px; color: var(--muted); border-color: var(--line); background: #fff; }

.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.boundary-banner { margin: 24px 0 32px; padding: 16px 18px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border: 1px solid #b7dccf; border-left: 5px solid var(--green); background: var(--green-soft); }
.boundary-banner strong, .boundary-banner span { display: block; }
.boundary-banner div > span { margin-top: 4px; color: #35584c; font-size: 14px; line-height: 1.5; }
.boundary-status { flex: 0 0 auto; color: #fff; background: var(--green); }
.section-heading { margin: 28px 0 14px; padding-bottom: 10px; display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.section-heading.compact { margin-top: 0; }
.section-index { margin-bottom: 5px; }
.section-note { margin-bottom: 0; color: var(--muted); font-size: 13px; }

.ingest-panel { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.privacy-note { margin-bottom: 16px; padding: 12px 14px; border-left: 4px solid var(--amber); background: var(--amber-soft); }
.privacy-note strong, .privacy-note span { display: block; }
.privacy-note span { margin-top: 3px; color: #684d18; font-size: 13px; line-height: 1.5; }
.ingest-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.ingest-actions { margin-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.ingest-actions .form-error { flex: 1; margin: 0; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric-card { min-height: 132px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.metric-card span, .metric-card small { display: block; color: var(--muted); }
.metric-card strong { display: block; margin: 10px 0 8px; color: var(--blue); font-size: 30px; letter-spacing: -.02em; }
.metric-card small { font-size: 12px; }
.decision-strip { margin-top: 10px; display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); background: var(--surface); }
.decision-strip span { padding: 11px 14px; color: var(--muted); font-size: 13px; text-align: center; }
.decision-strip span + span { border-left: 1px solid var(--line); }
.decision-strip strong { color: var(--ink); }

.work-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(360px, .95fr); gap: 24px; align-items: start; }
.candidate-list, .history-list { display: grid; gap: 10px; }
.candidate-card, .history-card, .empty-state { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.candidate-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 7px; }
.tag { padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 650; }
.tag-risk-low { color: var(--green); background: var(--green-soft); }
.tag-risk-high { color: var(--red); background: var(--red-soft); }
.tag-handoff { color: var(--amber); background: var(--amber-soft); }
.candidate-time { color: var(--muted); font-size: 12px; }
.message-block { margin: 14px 0; }
.message-block span, .review-context span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; font-weight: 650; }
.message-block p { margin-bottom: 0; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-block.ai { padding: 12px; border-left: 3px solid var(--blue); background: var(--surface-soft); }
.message-block.context, .review-context.context { padding: 12px; border-left: 3px solid var(--amber); background: var(--amber-soft); }
.candidate-card .button { width: 100%; }
.empty-state { color: var(--muted); line-height: 1.6; text-align: center; }

.review-panel { position: sticky; top: 16px; padding: 20px; border: 1px solid #b8cbe3; border-radius: var(--radius); background: var(--surface); }
.timer { color: var(--navy); font-variant-numeric: tabular-nums; font-weight: 700; }
.review-context { margin-bottom: 16px; padding: 12px; background: var(--surface-soft); }
.review-context p { margin-bottom: 0; line-height: 1.6; }
.field-grid { margin-top: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.review-actions { margin-top: 14px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.panel-footnote { margin: 14px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.form-error { min-height: 20px; margin: 8px 0 0; color: var(--red); font-size: 13px; }

.history-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.history-card header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.history-status { font-weight: 700; }
.history-status.accepted, .history-status.edited { color: var(--green); }
.history-status.rejected { color: var(--red); }
.history-status.pending { color: var(--amber); }
.history-card dl { margin: 12px 0 0; display: grid; grid-template-columns: 76px 1fr; gap: 8px 10px; font-size: 13px; }
.history-card dt { color: var(--muted); }
.history-card dd { margin: 0; overflow-wrap: anywhere; }
.count-badge { color: var(--navy); background: var(--blue-soft); }

.toast { position: fixed; right: 22px; bottom: 22px; max-width: min(420px, calc(100% - 44px)); padding: 12px 16px; border-radius: 8px; color: #fff; background: #17324f; box-shadow: 0 12px 32px rgba(23, 32, 51, .18); }

@media (max-width: 900px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .work-grid { grid-template-columns: 1fr; }
  .review-panel { position: static; }
}

@media (max-width: 640px) {
  .header-inner, main { width: min(100% - 24px, 1160px); }
  .mode-badge { display: none; }
  main { padding-top: 24px; }
  .login-panel { padding: 24px 18px; }
  .input-row, .ingest-grid, .field-grid, .review-actions, .history-list { grid-template-columns: 1fr; }
  .ingest-actions { align-items: stretch; flex-direction: column; }
  .page-heading, .boundary-banner, .section-heading { align-items: flex-start; flex-direction: column; }
  .metric-grid { grid-template-columns: 1fr; }
  .decision-strip { grid-template-columns: repeat(2, 1fr); }
  .decision-strip span + span { border-left: 0; }
  .decision-strip span:nth-child(even) { border-left: 1px solid var(--line); }
  .decision-strip span:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .boundary-status { align-self: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
