:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #f1f4f8;
  --text: #17202a;
  --muted: #586575;
  --line: #d8e0e8;
  --accent: #1f5fbf;
  --accent-strong: #17488f;
  --ok: #176b45;
  --warn: #8a5200;
  --error: #ad2e24;
  --focus: rgba(31, 95, 191, 0.2);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: 0;
}

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

button {
  touch-action: manipulation;
}

button:focus-visible,
textarea:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

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

.app-shell {
  width: min(100%, 680px);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--surface);
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 68px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
}

.topbar-copy {
  min-width: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
}

h2 {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
}

.status-text {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.status-text[data-tone="ok"] { color: var(--ok); }
.status-text[data-tone="warn"] { color: var(--warn); }
.status-text[data-tone="error"] { color: var(--error); }

.scope-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.scope-band > div:first-child {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.scope-band strong {
  overflow-wrap: anywhere;
}

.scope-count {
  display: flex;
  align-items: baseline;
  gap: 3px;
  flex: none;
  color: var(--accent);
}

.scope-count strong {
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

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

.workspace-section {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.field textarea {
  width: 100%;
  min-height: 124px;
  resize: vertical;
  border: 1px solid #bcc7d3;
  border-radius: 6px;
  padding: 11px 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
}

.field textarea:focus {
  border-color: var(--accent);
}

.field textarea:disabled {
  resize: none;
  background: var(--surface-soft);
  color: var(--muted);
}

.primary-btn,
.secondary-btn {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease, opacity 180ms ease;
}

.primary-btn {
  background: var(--accent);
  color: #ffffff;
}

.primary-btn:hover:not(:disabled) {
  background: var(--accent-strong);
}

.secondary-btn {
  border-color: #bcc7d3;
  background: var(--surface);
  color: var(--text);
}

.secondary-btn:hover:not(:disabled) {
  border-color: #8fa0b3;
  background: var(--surface-soft);
}

.compact-btn {
  min-width: 64px;
  flex: none;
}

.start-btn {
  width: 100%;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border-radius: 4px;
  padding: 4px 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.status-chip[data-tone="ok"] { background: #e8f4ed; color: var(--ok); }
.status-chip[data-tone="warn"] { background: #fff2dc; color: var(--warn); }
.status-chip[data-tone="error"] { background: #fbe9e7; color: var(--error); }

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: #dfe6ee;
}

.progress-bar {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 200ms ease;
}

.progress-list {
  min-height: 24px;
}

.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.progress-row span {
  overflow-wrap: anywhere;
}

.progress-row strong {
  flex: none;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.batch-controls {
  display: flex;
  gap: 8px;
}

.batch-controls > button {
  flex: 1 1 0;
}

.candidate-summary {
  display: grid;
  border-top: 1px solid var(--line);
}

.summary-group {
  display: grid;
  grid-template-columns: minmax(88px, 0.8fr) repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
  min-height: 54px;
  border-bottom: 1px solid var(--line);
}

.summary-group > strong {
  min-width: 0;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.summary-metric {
  display: grid;
  gap: 1px;
  min-width: 0;
  text-align: right;
}

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

.summary-metric strong {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.summary-metric[data-tone="warn"] strong {
  color: var(--warn);
}

.summary-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.exception-panel {
  min-width: 0;
}

.exception-panel > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  cursor: pointer;
  list-style: none;
}

.exception-panel > summary::-webkit-details-marker {
  display: none;
}

.exception-panel > summary > span:first-child {
  min-width: 0;
}

.exception-panel > summary strong {
  display: block;
  overflow-wrap: anywhere;
}

.exception-content {
  display: grid;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.results-list,
.result-detail {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.results-list {
  max-height: 320px;
  overflow: auto;
}

.result-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 9px 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.result-row:last-child {
  border-bottom: 0;
}

.result-row:hover {
  background: var(--surface-soft);
}

.result-row-main,
.result-row-meta {
  min-width: 0;
}

.result-row-main strong,
.result-row-main span,
.result-row-meta {
  display: block;
  overflow-wrap: anywhere;
}

.result-row-main span,
.result-row-meta {
  color: var(--muted);
  font-size: 12px;
}

.result-row-meta {
  max-width: 108px;
  text-align: right;
}

.result-state {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  font-weight: 700;
}

.result-state[data-tone="ok"] { color: var(--ok); background: #e8f4ed; }
.result-state[data-tone="warn"] { color: var(--warn); background: #fff2dc; }
.result-state[data-tone="error"] { color: var(--error); background: #fbe9e7; }
.result-state[data-tone="neutral"] { color: var(--muted); background: var(--surface-soft); }

.result-detail {
  padding: 10px;
}

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

.detail-grid span,
.detail-block span,
.detail-block li {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

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

.detail-block {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.detail-block h3 {
  margin: 0 0 5px;
  font-size: 13px;
}

.detail-list {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 18px;
}

.candidate-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.candidate-line {
  padding: 8px;
  border-left: 3px solid var(--line);
  background: var(--surface-soft);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.candidate-line[data-gap="true"] {
  border-left-color: var(--warn);
}

.field-details > summary {
  min-height: 44px;
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  line-height: 44px;
}

.action-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.action-row > button {
  flex: 1 1 0;
}

.empty {
  padding: 16px 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

@media (max-width: 420px) {
  .topbar,
  .scope-band,
  .workspace-section {
    padding-right: 12px;
    padding-left: 12px;
  }

  .summary-group {
    grid-template-columns: minmax(76px, 0.9fr) repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .summary-metric span {
    font-size: 10px;
  }

  .batch-controls {
    flex-wrap: wrap;
  }

  .batch-controls > button {
    flex: 1 1 92px;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
