:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef5f4;
  --text: #162526;
  --muted: #647375;
  --line: #d8e1e2;
  --accent: #08736d;
  --accent-strong: #075b58;
  --gold: #d99a2b;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --ok: #137333;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 22px auto;
}

.topbar {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.app-icon {
  width: 48px;
  height: 48px;
  display: block;
}

.title-group {
  min-width: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.25;
  font-weight: 700;
}

h2 {
  font-size: 15px;
  line-height: 1.35;
  margin: 0 0 12px;
}

.topbar p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent);
  border-radius: 8px;
  cursor: pointer;
  font-size: 20px;
}

.status-strip,
.result-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.result-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 14px;
}

.status-strip > div,
.result-grid > div {
  min-width: 0;
  padding: 13px 14px;
  background: var(--surface);
}

.label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 17px;
  line-height: 1.25;
}

.workspace {
  display: block;
  margin-top: 16px;
}

.side-panel {
  min-width: 0;
  display: grid;
  gap: 12px;
}

.main-panel {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.hidden-status-panel {
  display: none;
}

.workflow-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.card-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
}

.card-heading h2 {
  margin: 0;
}

.card-heading span,
.template-subhead {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.template-subhead {
  margin: 14px 0 7px;
  font-weight: 700;
}

.template-list {
  display: grid;
  gap: 7px;
  margin: 0;
}

.template-card {
  width: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  color: var(--text);
  text-align: left;
  padding: 10px;
}

.template-select-button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
  padding: 0;
}

.template-card-topline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
}

.template-card strong {
  font-size: 13px;
  line-height: 1.35;
}

.template-card em {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border: 1px solid #c6dedc;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--accent);
  font-style: normal;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.template-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.template-card-meta b,
.template-card-meta i {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border-radius: 6px;
  background: #eef2f2;
  color: var(--muted);
  font-style: normal;
  font-weight: 700;
  font-size: 12px;
}

.template-card-detail {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.template-card code {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.template-delete-button,
.template-pause-button {
  width: 100%;
  min-height: 30px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.template-delete-button {
  border: 1px solid #f0b8b2;
  background: var(--danger-bg);
  color: var(--danger);
}

.template-pause-button {
  border: 1px solid #d8c8a3;
  background: #fff8e6;
  color: #7c5200;
}

.template-card-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin-top: 8px;
}

.template-default-button {
  width: 100%;
  min-height: 30px;
  border: 1px solid #c6dedc;
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.template-default-button:disabled {
  cursor: default;
  color: var(--muted);
  background: #eef2f2;
}

.field-source-details {
  margin-top: 8px;
}

.field-source-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.field-source-panel summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 10px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.field-source-panel summary::marker {
  color: var(--muted);
}

.field-source-panel summary em,
.field-source-row-head span {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  font-style: normal;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
}

.field-source-panel summary small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field-source-table {
  display: grid;
  gap: 7px;
  padding: 0 10px 10px;
}

.field-source-row {
  display: grid;
  gap: 7px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.field-source-row-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.field-source-row-head b {
  min-width: 0;
  color: var(--text);
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.field-source-row dl {
  display: grid;
  grid-template-columns: minmax(0, 64px) minmax(0, 1fr);
  gap: 5px 8px;
  margin: 0;
}

.field-source-row dt {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.field-source-row dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.field-source-row p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.source-ok {
  border-color: #d9e7df;
  background: #f6fbf8;
  color: #28724d;
}

.source-warning {
  border-color: #e7d5a9;
  background: #fffaf0;
  color: #7a5a14;
}

.source-error {
  border-color: #e4b8b8;
  background: #fff6f6;
  color: #9b2d2d;
}

.template-card.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  background: var(--surface-soft);
}

.template-card.paused {
  border-color: #d5dbdf;
  background: #f1f3f4;
  color: #6f7a83;
  box-shadow: none;
}

.template-card.paused strong,
.template-card.paused .template-card-detail {
  color: #6f7a83;
}

.template-card.paused em {
  border-color: #d5dbdf;
  background: #e6eaed;
  color: #66727c;
}

.template-card.paused .template-default-button:disabled {
  border-color: #d7dde1;
  background: #e9edf0;
  color: #8a949c;
}

.field-row {
  display: grid;
  gap: 7px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
}

.field-row input,
.field-row textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: #fff;
}

.field-row input {
  min-height: 38px;
  padding: 0 10px;
}

.field-row textarea {
  resize: vertical;
  min-height: 96px;
  padding: 9px 10px;
  line-height: 1.45;
}

.selected-records {
  display: grid;
  gap: 6px;
  min-height: 58px;
  margin-bottom: 10px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.selected-records strong {
  font-size: 15px;
}

.selected-records span,
.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.debug-panel {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.record-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.side-result-summary {
  display: grid;
  gap: 8px;
  min-height: 58px;
  margin-top: 12px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.side-result-summary.running {
  border-color: #c6dedc;
  background: var(--surface-soft);
}

.side-result-summary.ok {
  border-color: #cce8d4;
  background: #edf7ee;
}

.side-result-summary.error {
  border-color: #ffd0cc;
  background: var(--danger-bg);
}

.side-result-summary strong {
  font-size: 15px;
}

.side-result-summary span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.side-summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}

.side-summary-grid div {
  min-width: 0;
  padding: 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.72);
}

.side-summary-grid span,
.side-summary-grid b {
  display: block;
  text-align: center;
}

.side-summary-grid b {
  margin-top: 2px;
  color: var(--text);
  font-size: 15px;
}

.side-result-summary .danger-text {
  color: var(--danger);
}

.retry-button {
  min-height: 32px;
  width: fit-content;
  padding: 0 10px;
}

.debug-panel summary,
.upload-panel summary {
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  user-select: none;
}

.upload-panel {
  padding: 12px;
  border: 1px solid #c6dedc;
  border-radius: 8px;
  background: var(--surface-soft);
}

.upload-panel .field-row,
.debug-panel .field-row {
  margin-top: 10px;
}

.upload-primary {
  width: 100%;
}

.upload-result {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.upload-result.error {
  color: var(--danger);
}

.upload-result strong {
  display: inline;
  font-size: 13px;
}

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

.precheck-item {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.precheck-item b {
  color: var(--text);
}

.auto-rule-list {
  margin-bottom: 8px;
}

.auto-rule-item {
  border-color: #c6dedc;
  background: var(--surface-soft);
}

.precheck-item span {
  display: block;
  margin-top: 3px;
}

.precheck-item .business-field-hint {
  color: var(--text);
  font-size: 12px;
}

.mapping-row {
  display: grid;
  gap: 5px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.field-option-hint {
  color: var(--muted);
  line-height: 1.35;
}

.field-option-hint.warning {
  color: var(--gold);
  font-weight: 700;
}

.mapping-select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
}

.same-base-source-hint {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 7px 8px;
  border: 1px solid #b8d9d5;
  border-radius: 7px;
  background: #edf8f6;
  color: var(--text);
  line-height: 1.35;
}

.same-base-source-hint span {
  display: inline-flex;
  margin: 0;
  padding: 2px 6px;
  border-radius: 999px;
  background: #d8efec;
  color: var(--accent-strong);
  font-weight: 700;
}

.same-base-source-hint b {
  font-weight: 700;
}

.same-base-source-hint mark {
  padding: 2px 6px;
  border-radius: 6px;
  background: #ffe7a8;
  color: #513600;
  font-weight: 700;
}

.same-base-source-hint small {
  color: var(--muted);
}

.field-search-input,
.rule-options-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
}

.field-search-input {
  min-height: 32px;
  padding: 0 9px;
}

.rule-options-input {
  resize: vertical;
  min-height: 92px;
  padding: 8px 9px;
  line-height: 1.45;
}

.rule-editor {
  margin-top: 8px;
}

.inline-action {
  margin-top: 10px;
}

.primary,
.secondary {
  width: 100%;
  min-height: 40px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

.primary {
  margin-top: 10px;
  border: 0;
  background: var(--accent);
  color: #fff;
}

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

.secondary {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent);
}

.template-repair-note,
.template-issue-panel {
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}

.template-repair-note {
  border: 1px solid #c9e7d0;
  background: #edf7ee;
  color: var(--ok);
}

.template-issue-panel {
  border: 1px solid #f2c7c5;
  background: var(--danger-bg);
  color: var(--danger);
}

.template-issue-panel strong {
  display: block;
  margin-bottom: 6px;
}

.template-issue-panel ul {
  margin: 0;
  padding-left: 18px;
}

.message {
  min-height: 42px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.message.error {
  background: var(--danger-bg);
  color: var(--danger);
}

.message.ok {
  background: #edf7ee;
  color: var(--ok);
}

.result-summary {
  min-height: 160px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.summary-grid > div {
  min-width: 0;
  padding: 12px;
  background: var(--surface);
}

.summary-grid strong {
  font-size: 19px;
}

.summary-text {
  margin-top: 12px;
}

.summary-text p {
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.danger-text p {
  color: var(--danger);
}

.table-wrap {
  max-height: 56vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
  line-height: 1.35;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fbfcfc;
  color: var(--muted);
  font-weight: 700;
}

td a {
  color: var(--accent);
  text-decoration: none;
}

.file-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid #c6dedc;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}

.empty-row {
  color: var(--muted);
}

th:nth-child(1),
td:nth-child(1) {
  width: 136px;
}

th:nth-child(2),
td:nth-child(2) {
  width: 130px;
}

th:nth-child(3),
td:nth-child(3),
th:nth-child(4),
td:nth-child(4) {
  width: 150px;
}

th:nth-child(5),
td:nth-child(5) {
  width: auto;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100vw - 20px, 1180px);
    margin: 16px auto;
  }

  .status-strip,
  .result-grid,
  .summary-grid,
  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .app-shell {
    width: 100%;
    margin: 0;
    padding: 12px;
  }

  .topbar {
    grid-template-columns: 42px minmax(0, 1fr) 36px;
    gap: 10px;
  }

  .app-icon {
    width: 42px;
    height: 42px;
  }

  h1 {
    font-size: 21px;
  }

  .topbar p {
    font-size: 12px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

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

  .status-strip > div,
  .result-grid > div,
  .side-panel,
  .main-panel {
    padding: 12px;
  }

  strong {
    font-size: 16px;
  }

  table {
    min-width: 680px;
  }
}
