/* ── Design tokens ── */
:root {
  --bg: #f1f5f9;
  --bg-elevated: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --accent: #0ea5e9;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.06);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(79, 70, 229, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(14, 165, 233, 0.06), transparent);
  min-height: 100vh;
}

/* ── Page shell ── */
.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px 32px;
  margin-bottom: 24px;
}

.page-header__brand {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.page-header__icon {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, #6366f1 100%);
  color: #fff;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

.page-header__icon svg {
  width: 26px;
  height: 26px;
}

.title {
  margin: 0 0 4px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.desc {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
  max-width: 420px;
}

/* ── Workflow steps ── */
.workflow-steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px 10px;
  box-shadow: var(--shadow-sm);
}

.workflow-step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.workflow-step--active {
  color: var(--primary);
  font-weight: 600;
}

.workflow-step__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--border);
  color: var(--text-secondary);
}

.workflow-step--active .workflow-step__num {
  background: var(--primary);
  color: #fff;
}

.workflow-step__divider {
  width: 24px;
  height: 1px;
  background: var(--border);
  margin: 0 2px;
}

/* ── Layout & panels ── */
.layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-md);
}

.panel__head {
  margin-bottom: 18px;
}

.panel__head--row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
}

.panel__title-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
}

.panel__badge {
  display: inline-block;
  padding: 3px 10px;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 999px;
}

.panel__badge--accent {
  color: #0369a1;
  background: #e0f2fe;
}

.panel__title {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
}

.panel__subtitle {
  margin: 6px 0 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.summary {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.panel__head--compact {
  margin-bottom: 14px;
}

/* ── 阶段 1：双栏 ── */
.stage1-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  min-height: 420px;
}

@media (max-width: 960px) {
  .stage1-columns {
    grid-template-columns: 1fr;
    min-height: 0;
  }
}

.stage1-column {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fafbfc;
  overflow: hidden;
}

.stage1-column--staging {
  background: #f8fafc;
}

.stage1-column__head {
  flex-shrink: 0;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.stage1-column__title {
  display: block;
  margin: 0 0 4px;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
  cursor: default;
}

label.stage1-column__title {
  cursor: pointer;
}

.stage1-column__desc {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.stage1-column__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px 16px;
  min-height: 0;
}

.stage1-column__body--fill {
  padding: 0;
  flex: 1;
  min-height: 0;
}

.stage1-column__body--fill .code-textarea {
  flex: 1;
  min-height: 0;
  height: 100%;
  border: none;
  border-radius: 0;
  resize: none;
}

.stage1-column--upload .parse-log-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 140px;
}

.stage1-column--upload .parse-log-list {
  flex: 1;
  min-height: 80px;
}

.stage1-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.code-textarea {
  width: 100%;
  min-height: 320px;
  padding: 12px 14px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.75rem;
  line-height: 1.6;
  color: #334155;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.code-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

/* ── Drop zone ── */
.drop-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 16px;
  color: var(--text-secondary);
  background: linear-gradient(180deg, #fafbff 0%, #f8fafc 100%);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}

.drop-zone:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.drop-zone:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

.drop-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: scale(1.01);
}

.drop-zone__icon {
  width: 44px;
  height: 44px;
  margin-bottom: 10px;
  color: var(--primary);
  opacity: 0.9;
}

.drop-zone__icon svg {
  width: 100%;
  height: 100%;
}

.drop-zone__title {
  margin: 0 0 4px;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.drop-zone__hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── Parse log ── */
.parse-log-panel {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #fafbfc;
}

.parse-log-title {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  background: #fff;
}

.parse-log-title__text {
  color: var(--text-secondary);
  font-weight: 500;
}

.parse-log-title__actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.parse-log-list {
  max-height: 160px;
  overflow: auto;
  background: #fff;
}

.parse-log-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.8125rem;
}

.parse-log-item:last-child {
  border-bottom: none;
}

.parse-log-name {
  color: #334155;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.parse-log-meta {
  color: var(--text-muted);
  white-space: nowrap;
  font-size: 0.75rem;
}

.toolbar__hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn__icon {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: linear-gradient(180deg, #6366f1 0%, var(--primary) 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.35);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #6366f1 0%, var(--primary-hover) 100%);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
}

.btn-primary:disabled {
  background: #e2e8f0;
  color: #94a3b8;
  box-shadow: none;
  cursor: not-allowed;
}

.btn-secondary {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--primary-soft);
  border-color: var(--primary);
}

.btn-secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 6px 12px;
  font-weight: 500;
}

.btn-ghost:hover:not(:disabled) {
  background: #f1f5f9;
  color: var(--text);
}

.btn-ghost:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

/* ── Tags & loading ── */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  margin-right: 6px;
}

.tag-pending { background: #f1f5f9; color: #475569; }
.tag-running { background: #dbeafe; color: #1d4ed8; }
.tag-success { background: var(--success-bg); color: var(--success-text); }
.tag-failed { background: var(--danger-bg); color: var(--danger-text); }

.inline-loading {
  display: none;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 500;
}

.inline-loading.active {
  display: inline-flex;
}

.loading-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #c7d2fe;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.muted {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

/* ── Tables ── */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: auto;
  background: #fff;
}

.table-wrap--main {
  margin-bottom: 12px;
}

.table-wrap--compact {
  border: none;
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
}

.result-table {
  table-layout: fixed;
  min-width: 1180px;
}

.result-table th,
.result-table td {
  border-bottom: 1px solid #f1f5f9;
  padding: 10px 12px;
  font-size: 0.8125rem;
  text-align: left;
  vertical-align: top;
}

.result-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: #475569;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: none;
  letter-spacing: 0.01em;
  white-space: nowrap;
  box-shadow: 0 1px 0 var(--border);
}

.result-table tbody tr:hover td {
  background: #fafbff;
}

.result-table tr:last-child td {
  border-bottom: none;
}

.result-table .checkbox-cell { width: 40px; text-align: center; }
.result-table .col-status { width: 88px; }
.result-table .col-narrow { width: 96px; }
.result-table .col-date { width: 140px; }
.result-table .col-amount { width: 100px; }
.result-table .doc-cell { width: 168px; }
.result-table .reason-col { width: 300px; }

.file-meta-table,
.unmatched-table {
  min-width: 100%;
}

.file-meta-table th,
.file-meta-table td,
.unmatched-table th,
.unmatched-table td {
  padding: 8px 12px;
  font-size: 0.8125rem;
  border-bottom: 1px solid #f1f5f9;
  text-align: left;
}

.file-meta-table thead th,
.unmatched-table thead th {
  background: #f8fafc;
  color: #64748b;
  font-weight: 600;
  font-size: 0.75rem;
}

.file-meta-table tr:last-child td,
.unmatched-table tr:last-child td {
  border-bottom: none;
}

/* ── Status badges ── */
.status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-green { background: var(--success-bg); color: var(--success-text); }
.status-yellow { background: var(--warn-bg); color: var(--warn-text); }
.status-red { background: var(--danger-bg); color: var(--danger-text); }

.status-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 10px 14px;
  margin-bottom: 20px;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.75rem;
}

.status-legend__label {
  font-weight: 600;
  color: var(--text-secondary);
  margin-right: 4px;
}

.status-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

/* ── Form fields in table ── */
.field-input,
.field-select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 0.8125rem;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field-input:focus,
.field-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.12);
}

.field-input.amount { max-width: 110px; }

.doc-cell .field-select { width: 100%; }

.payment-item + .payment-item { margin-top: 8px; }

.doc-meta {
  margin-top: 4px;
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.reason-cell {
  color: #475569;
  min-width: 300px;
  word-break: break-word;
  white-space: normal;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.unmatched-reason {
  color: #b45309;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.checkbox-cell {
  text-align: center;
}

/* ── Auxiliary cards ── */
.aux-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 4px;
}

@media (max-width: 768px) {
  .aux-grid {
    grid-template-columns: 1fr;
  }

  .workflow-steps {
    width: 100%;
    flex-wrap: wrap;
    justify-content: center;
  }

  .workflow-step__divider {
    display: none;
  }
}

.aux-card {
  padding: 16px;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.aux-card--warn {
  background: #fffbeb;
  border-color: #fde68a;
}

.aux-card__title {
  margin: 0 0 4px;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.aux-card__desc {
  margin: 0 0 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.aux-card .table-wrap {
  background: #fff;
  border: 1px solid var(--border);
}
