:root {
  color: #17202a;
  background: #f7f8fa;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  --surface: #ffffff;
  --muted: #66717f;
  --border: #dce1e7;
  --accent: #1367d1;
  --accent-hover: #0f55ae;
  --success: #18794e;
  --success-bg: #eaf7f0;
  --danger: #b42318;
  --danger-bg: #fff0ee;
  --warning: #8a4b08;
  --warning-bg: #fff6e5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: #f7f8fa;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

.shell {
  width: min(820px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 56px;
}

.page-header,
.section-heading,
.action-row,
.candidate-main,
.candidate-metrics {
  display: flex;
  align-items: center;
}

.page-header {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.brand {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 32px;
  line-height: 1.2;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.3;
  letter-spacing: 0;
}

.run-state {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.run-state[data-state="running"] {
  border-color: #b8d4f5;
  color: var(--accent);
}

.run-state[data-state="done"] {
  border-color: #b9dfca;
  color: var(--success);
}

.run-state[data-state="error"] {
  border-color: #f1b9b4;
  color: var(--danger);
}

.notice {
  margin-bottom: 20px;
  padding: 16px 18px;
  border-left: 4px solid #d9780d;
  background: var(--warning-bg);
  color: #5f390f;
}

.notice p {
  margin: 6px 0 12px;
  color: #795226;
  font-size: 14px;
  line-height: 1.6;
}

.confirm-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  font-size: 14px;
  font-weight: 600;
}

.confirm-row input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.route-confirmation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

button.copy-rules {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid #d5b273;
  background: #ffffff;
  color: #5f390f;
  white-space: nowrap;
}

.route-feedback {
  display: block;
  min-height: 20px;
  margin-top: 6px;
  color: #795226;
  font-size: 13px;
}

.controls,
.results {
  border: 1px solid var(--border);
  background: var(--surface);
}

.controls {
  padding: 18px;
  border-radius: 8px 8px 0 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.field-row label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.field-row input,
.field-row select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid #bfc7d1;
  border-radius: 6px;
  outline: none;
  background: #ffffff;
  color: #17202a;
}

.field-row input:focus,
.field-row select:focus,
button:focus-visible {
  outline: 3px solid rgba(19, 103, 209, 0.22);
  outline-offset: 1px;
}

.action-row {
  gap: 14px;
}

button {
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

button.primary {
  flex: 0 0 auto;
  background: var(--accent);
  color: #ffffff;
}

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

button.primary[data-mode="stop"] {
  background: #3d4652;
}

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

.progress-text {
  min-width: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

progress {
  display: block;
  width: 100%;
  height: 7px;
  margin-top: 14px;
  border: 0;
  border-radius: 4px;
  overflow: hidden;
  background: #e8ebef;
}

progress::-webkit-progress-bar {
  background: #e8ebef;
}

progress::-webkit-progress-value {
  background: var(--accent);
}

progress::-moz-progress-bar {
  background: var(--accent);
}

.results {
  border-top: 0;
  border-radius: 0 0 8px 8px;
}

.section-heading {
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.section-heading span {
  color: var(--muted);
  font-size: 14px;
}

.candidate-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.candidate-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid #e7eaee;
}

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

.candidate-main {
  min-width: 0;
  gap: 12px;
}

.candidate-index {
  display: grid;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 6px;
  background: #eef2f6;
  color: #4b5663;
  font-size: 13px;
  font-weight: 700;
}

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

.candidate-name,
.candidate-host {
  display: block;
  overflow-wrap: anywhere;
}

.candidate-name {
  margin-bottom: 4px;
  font-weight: 700;
}

.candidate-host {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.candidate-metrics {
  justify-content: flex-end;
  gap: 8px;
  min-width: 210px;
  color: var(--muted);
  font-size: 13px;
}

.metric {
  white-space: nowrap;
}

.status {
  min-width: 58px;
  padding: 5px 8px;
  border-radius: 5px;
  background: #eef2f6;
  color: #596473;
  text-align: center;
  font-weight: 700;
}

.candidate-row[data-state="running"] .status {
  background: #eaf2fd;
  color: var(--accent);
}

.candidate-row[data-state="success"] .status {
  background: var(--success-bg);
  color: var(--success);
}

.candidate-row[data-state="failed"] .status {
  background: var(--danger-bg);
  color: var(--danger);
}

.empty-state {
  padding: 28px 18px;
  color: var(--muted);
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.scope-note {
  margin: 16px 2px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

@media (max-width: 620px) {
  .shell {
    width: min(100% - 24px, 820px);
    padding-top: 24px;
  }

  h1 {
    font-size: 28px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .route-confirmation {
    align-items: stretch;
    flex-direction: column;
  }

  button.copy-rules {
    width: 100%;
  }

  button.primary {
    width: 100%;
  }

  .candidate-row {
    grid-template-columns: 1fr;
  }

  .candidate-metrics {
    justify-content: flex-start;
    min-width: 0;
    padding-left: 44px;
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: no-preference) {
  progress::-webkit-progress-value {
    transition: width 180ms ease;
  }
}
