:root {
  color-scheme: light;
  --ink: #172321;
  --muted: #65716e;
  --line: #d9dfdc;
  --line-strong: #c6cfcb;
  --canvas: #f3f6f4;
  --surface: #ffffff;
  --surface-soft: #edf2ef;
  --green: #176b57;
  --green-dark: #0f503f;
  --green-soft: #e2f0ea;
  --amber: #ae7417;
  --amber-soft: #fbf0da;
  --red: #b13b3b;
  --red-soft: #fae8e6;
  --blue: #315f85;
  --shadow: 0 8px 28px rgba(23, 35, 33, 0.08);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--canvas); color: var(--ink); }
body { font-size: 14px; line-height: 1.5; }
button, input { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }
svg { width: 18px; height: 18px; stroke-width: 1.8; flex: 0 0 auto; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: #182321;
  color: #fff;
  border-bottom: 1px solid #2b3735;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand img { border-radius: 6px; }
.brand strong { display: block; font-size: 15px; font-weight: 650; white-space: nowrap; }
.brand span { display: block; color: #aebbb7; font-size: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 20px; }
.catalog-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #42504d;
  background: #24312f;
  color: #dfe7e4;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.catalog-state:hover { background: #2d3b38; }
.server-state { display: inline-flex; align-items: center; gap: 7px; color: #bdc8c5; font-size: 12px; white-space: nowrap; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #c18b3a; }
.status-dot.online { background: #54c798; box-shadow: 0 0 0 3px rgba(84, 199, 152, 0.12); }
.status-dot.offline { background: #df6d6d; }

.app-shell { display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: calc(100vh - 64px); }
.step-sidebar {
  position: sticky;
  top: 64px;
  align-self: start;
  height: calc(100vh - 64px);
  padding: 28px 18px;
  background: #eef2f0;
  border-right: 1px solid var(--line);
  overflow: auto;
}
.step-heading { padding: 0 10px 12px; color: var(--muted); font-size: 12px; font-weight: 650; }
#step-nav { display: grid; gap: 5px; }
.step-link {
  width: 100%;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.step-link:hover:not(:disabled) { background: #e4ebe7; }
.step-link.active { background: var(--surface); border-color: var(--line); box-shadow: 0 2px 8px rgba(23, 35, 33, 0.05); }
.step-link:disabled { opacity: 0.52; cursor: default; }
.step-number {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.step-link.active .step-number, .step-link.done .step-number { background: var(--green); border-color: var(--green); color: #fff; }
.step-link b { display: block; font-size: 13px; font-weight: 650; }
.step-link small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.sidebar-rule { margin: 34px 10px 0; padding-top: 18px; border-top: 1px solid var(--line); }
.sidebar-rule > span { color: var(--muted); font-size: 11px; }
.sidebar-rule dl { margin: 10px 0 0; }
.sidebar-rule dl div { display: flex; justify-content: space-between; padding: 5px 0; }
.sidebar-rule dt { color: var(--muted); }
.sidebar-rule dd { margin: 0; font-weight: 650; }

.workspace { width: 100%; max-width: 1440px; padding: 34px 42px 46px; overflow: hidden; }
.step-panel { display: none; }
.step-panel.active { display: block; animation: panel-in 180ms ease-out; }
@keyframes panel-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.section-head { min-height: 58px; display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.eyebrow { display: block; color: var(--green); font-size: 11px; font-weight: 700; text-transform: uppercase; }
h1 { margin: 4px 0 0; font-size: 25px; line-height: 1.2; font-weight: 680; }
h2 { margin: 0; font-size: 16px; font-weight: 670; }
.file-limit, .catalog-version { color: var(--muted); font-size: 12px; padding-top: 25px; }
.section-head-actions { display: flex; align-items: center; gap: 12px; }
.section-head-actions .button { margin-top: 17px; white-space: nowrap; }

.upload-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.upload-tile {
  position: relative;
  min-height: 230px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--surface);
  border: 1px dashed #b5c2bd;
  border-radius: 7px;
  cursor: pointer;
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
.upload-tile:hover, .upload-tile.dragging { border-color: var(--green); background: #fbfdfc; box-shadow: var(--shadow); }
.upload-tile.selected { border-style: solid; border-color: var(--green); }
.upload-tile input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
.upload-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 7px; background: var(--green-soft); color: var(--green); }
.upload-icon.customs { background: var(--amber-soft); color: var(--amber); }
.upload-icon svg { width: 24px; height: 24px; }
.upload-tile strong { font-size: 16px; }
.upload-file { max-width: 90%; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-action { display: inline-flex; align-items: center; gap: 6px; margin-top: 3px; color: var(--green); font-size: 12px; font-weight: 650; }
.upload-action svg { width: 15px; height: 15px; }

.source-rules { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 24px; background: #e8eeeb; border: 1px solid var(--line); border-radius: 6px; }
.source-rules div { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 2px 9px; align-items: center; padding: 14px 16px; border-right: 1px solid var(--line); }
.source-rules div:last-child { border-right: 0; }
.source-rules svg { grid-row: 1 / 3; color: var(--green); }
.source-rules span { color: var(--muted); font-size: 11px; }
.source-rules b { font-size: 12px; }

.form-actions { display: flex; align-items: center; margin-top: 28px; }
.form-actions.end { justify-content: flex-end; }
.form-actions.split { justify-content: space-between; }
.button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 15px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 650;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, opacity 120ms ease;
}
.button.primary { min-width: 130px; background: var(--green); color: #fff; }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { background: var(--surface); border-color: var(--line-strong); }
.button.secondary:hover { background: var(--surface-soft); }
.button.small { min-height: 32px; padding: 5px 10px; font-size: 12px; }
.button:disabled { opacity: 0.55; cursor: not-allowed; }
.button.loading svg { animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.notice { display: flex; gap: 9px; margin-bottom: 18px; padding: 12px 14px; border: 1px solid; border-radius: 6px; }
.notice.warning { background: var(--amber-soft); border-color: #e6c98f; color: #765018; }
.notice.hidden, .hidden { display: none !important; }
.document-refs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.document-ref { display: inline-flex; align-items: center; gap: 7px; padding: 6px 9px; background: var(--surface-soft); border-radius: 5px; color: var(--muted); font-size: 12px; }
.document-ref b { color: var(--ink); }
.customs-note-panel { margin-bottom: 18px; padding: 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.customs-note-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.customs-note-head h2 { margin-top: 2px; font-size: 17px; }
.customs-field-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 12px; }
.customs-field-grid label, .customs-note-output { min-width: 0; }
.customs-field-grid label span, .customs-note-output > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.customs-field-grid input, .customs-note-output textarea, .result-note textarea { width: 100%; border: 1px solid var(--line-strong); border-radius: 4px; background: #fff; color: var(--ink); outline: none; }
.customs-field-grid input { height: 34px; padding: 6px 8px; }
.customs-field-grid input:focus { border-color: var(--green); box-shadow: 0 0 0 2px rgba(23,107,87,0.1); }
.customs-field-wide { grid-column: span 2; }
.customs-note-output { display: block; margin-top: 12px; }
.customs-note-output textarea, .result-note textarea { min-height: 88px; padding: 9px 10px; resize: vertical; font: inherit; line-height: 1.65; }
.customs-note-output textarea[readonly], .result-note textarea[readonly] { background: var(--surface-soft); }
.summary-pills { display: flex; gap: 8px; padding-top: 18px; }
.summary-pill { padding: 5px 9px; border-radius: 5px; background: var(--surface-soft); color: var(--muted); font-size: 12px; white-space: nowrap; }
.summary-pill b { color: var(--ink); }

.table-toolbar { height: 42px; display: flex; align-items: center; justify-content: space-between; }
.table-title { display: inline-flex; align-items: center; gap: 8px; font-weight: 650; }
.table-title svg { color: var(--green); }
.data-table-wrap { width: 100%; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.data-table { width: 100%; min-width: 920px; border-collapse: collapse; table-layout: fixed; }
.data-table th { height: 42px; padding: 8px 10px; background: #edf2ef; border-bottom: 1px solid var(--line); color: #52615d; font-size: 11px; text-align: left; font-weight: 650; }
.data-table td { height: 50px; padding: 6px 9px; border-bottom: 1px solid #e8ecea; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fbfcfb; }
.data-table input { width: 100%; height: 34px; border: 1px solid transparent; border-radius: 4px; padding: 6px 7px; background: transparent; color: var(--ink); outline: none; }
.data-table input:hover { border-color: var(--line); background: #fff; }
.data-table input:focus { border-color: var(--green); box-shadow: 0 0 0 2px rgba(23,107,87,0.1); background: #fff; }
.data-table input.invalid { border-color: var(--red); background: var(--red-soft); }
.data-table .status-column { width: 72px; }
.data-table .number-column { width: 120px; text-align: right; }
.data-table .number-column input { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .icon-column { width: 48px; }
.row-status { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; }
.row-status.ok { color: var(--green); }
.row-status.warn { color: var(--amber); }
.row-status svg { width: 14px; height: 14px; }
.icon-button { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 5px; background: transparent; cursor: pointer; color: var(--muted); }
.icon-button:hover { background: var(--red-soft); color: var(--red); }
.icon-button svg { width: 16px; height: 16px; }

.tax-table { min-width: 980px; }
.tax-table th:nth-child(1) { width: 180px; }
.tax-table th:nth-child(2) { width: 150px; }
.tax-table th:nth-child(3) { width: 290px; }
.tax-table th:nth-child(5) { width: 100px; }
.tax-code-control { display: grid; grid-template-columns: minmax(0, 1fr) 34px; gap: 5px; }
.tax-code-control button { border: 1px solid var(--line); background: var(--surface); border-radius: 4px; cursor: pointer; color: var(--green); }
.tax-code-control button:hover { background: var(--green-soft); }
.match-chip { display: inline-flex; align-items: center; padding: 4px 7px; border-radius: 4px; font-size: 11px; white-space: nowrap; }
.match-chip.high { background: var(--green-soft); color: var(--green-dark); }
.match-chip.low { background: var(--amber-soft); color: #765018; }
.match-chip.ai { background: #e9eef8; color: #385889; }
.match-chip.none { background: var(--red-soft); color: var(--red); }

.review-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 24px; align-items: start; }
.rule-band { display: grid; grid-template-columns: repeat(4, 1fr); background: #182321; color: #fff; border-radius: 6px; overflow: hidden; }
.rule-band div { min-height: 86px; display: flex; flex-direction: column; justify-content: center; padding: 15px 18px; border-right: 1px solid #34413e; }
.rule-band div:last-child { border-right: 0; }
.rule-band span { color: #aebbb7; font-size: 11px; }
.rule-band strong { margin-top: 3px; font-size: 20px; }
.validation-list { margin-top: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.validation-row { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-bottom: 1px solid #e8ecea; }
.validation-row:last-child { border-bottom: 0; }
.validation-row svg { margin-top: 1px; color: var(--green); }
.validation-row.error svg { color: var(--red); }
.validation-row b { display: block; font-size: 12px; }
.validation-row span { color: var(--muted); font-size: 11px; }
.review-summary { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 18px; }
.review-summary h2 { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.review-summary dl { margin: 10px 0 16px; }
.review-summary dl div { display: flex; justify-content: space-between; padding: 7px 0; }
.review-summary dt { color: var(--muted); }
.review-summary dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; }
.catalog-panel { padding: 12px; background: var(--surface-soft); border-radius: 5px; font-size: 11px; color: var(--muted); }
.catalog-panel b { display: block; margin-bottom: 4px; color: var(--ink); font-size: 12px; }

.success-mark { display: inline-flex; align-items: center; gap: 7px; color: var(--green); font-weight: 650; padding-top: 20px; }
.result-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 28px; align-items: start; }
.download-list { display: grid; gap: 10px; }
.download-row { min-height: 76px; display: grid; grid-template-columns: 48px minmax(0,1fr) 24px; gap: 13px; align-items: center; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.download-row:hover { border-color: var(--green); box-shadow: var(--shadow); }
.download-row > svg { color: var(--green); }
.download-row strong { display: block; overflow-wrap: anywhere; }
.download-row small { display: block; margin-top: 3px; color: var(--muted); }
.download-row.primary-download { background: var(--green-soft); border-color: #a8cabc; }
.file-type { display: grid; place-items: center; width: 43px; height: 32px; border-radius: 4px; background: var(--green-soft); color: var(--green-dark); font-size: 10px; font-weight: 800; }
.file-type.amber { background: var(--amber-soft); color: #765018; }
.file-type.dark { background: #22302d; color: #fff; }
.result-visual { overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.result-visual img { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; object-position: left top; border-bottom: 1px solid var(--line); }
.result-visual div { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 10px; padding: 12px; align-items: center; }
.result-visual span { color: var(--muted); font-size: 11px; }
.result-note { margin-top: 20px; padding: 16px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }

.catalog-dialog { width: min(760px, calc(100vw - 28px)); max-height: min(720px, calc(100vh - 40px)); padding: 0; border: 1px solid var(--line-strong); border-radius: 7px; box-shadow: 0 24px 80px rgba(23,35,33,0.25); }
.catalog-dialog::backdrop { background: rgba(13,22,20,0.5); }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin-top: 3px; }
.catalog-search { display: grid; grid-template-columns: 22px minmax(0,1fr) auto; gap: 8px; align-items: center; margin: 16px 20px; padding: 5px 5px 5px 10px; border: 1px solid var(--line-strong); border-radius: 6px; }
.catalog-search svg { color: var(--muted); }
.catalog-search input { width: 100%; height: 32px; border: 0; outline: 0; }
.catalog-results { max-height: 480px; overflow: auto; border-top: 1px solid var(--line); }
.catalog-result { width: 100%; display: grid; grid-template-columns: 190px minmax(0,1fr) 76px; gap: 14px; padding: 13px 20px; border: 0; border-bottom: 1px solid #e8ecea; background: #fff; text-align: left; cursor: pointer; }
.catalog-result:hover { background: var(--green-soft); }
.catalog-result code { font-family: Consolas, monospace; color: var(--green-dark); }
.catalog-result strong { display: block; }
.catalog-result small { display: block; margin-top: 3px; color: var(--muted); }
.catalog-result em { align-self: center; justify-self: end; color: var(--muted); font-size: 11px; font-style: normal; }
.empty-result { padding: 34px 20px; color: var(--muted); text-align: center; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 80; max-width: min(520px, calc(100vw - 32px)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 10px 14px; border-radius: 5px; background: #172321; color: #fff; box-shadow: var(--shadow); transition: opacity 160ms ease, transform 160ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #8f3030; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .step-sidebar { position: sticky; top: 64px; z-index: 20; height: auto; padding: 9px 14px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .step-heading, .sidebar-rule, .step-link small { display: none; }
  #step-nav { display: flex; min-width: 620px; }
  .step-link { min-height: 42px; padding: 5px 8px; justify-content: center; }
  .step-number { width: 24px; height: 24px; }
  .workspace { padding: 28px 24px 40px; }
  .review-layout, .result-layout { grid-template-columns: 1fr; }
  .customs-field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .review-summary { order: -1; }
}

@media (max-width: 640px) {
  .topbar { height: 58px; padding: 0 14px; }
  .brand img { width: 32px; height: 32px; }
  .brand strong { font-size: 13px; }
  .brand span, .server-state { display: none; }
  .catalog-state span { display: none; }
  .catalog-state { width: 34px; height: 34px; justify-content: center; padding: 0; }
  .step-sidebar { top: 58px; padding: 7px 8px; }
  #step-nav { min-width: 500px; gap: 2px; }
  .step-link { min-height: 36px; gap: 5px; padding: 3px 5px; }
  .step-link b { font-size: 11px; }
  .step-number { width: 22px; height: 22px; font-size: 10px; }
  .workspace { padding: 22px 14px 32px; }
  .section-head { min-height: 50px; margin-bottom: 18px; align-items: flex-start; }
  h1 { font-size: 21px; }
  .file-limit, .catalog-version, .summary-pills { display: none; }
  .section-head-actions { flex: 0 0 auto; }
  .section-head-actions .button { margin-top: 7px; }
  .upload-grid { grid-template-columns: 1fr; gap: 12px; }
  .upload-tile { min-height: 166px; }
  .customs-field-grid { grid-template-columns: 1fr; }
  .customs-field-wide { grid-column: auto; }
  .source-rules { grid-template-columns: 1fr; }
  .source-rules div { border-right: 0; border-bottom: 1px solid var(--line); }
  .source-rules div:last-child { border-bottom: 0; }
  .button { min-height: 40px; }
  .form-actions.split { gap: 10px; }
  .form-actions.split .button { flex: 1; min-width: 0; }
  .rule-band { grid-template-columns: repeat(2, 1fr); }
  .rule-band div { border-bottom: 1px solid #34413e; }
  .rule-band div:nth-child(2) { border-right: 0; }
  .rule-band div:nth-child(3), .rule-band div:nth-child(4) { border-bottom: 0; }
  .result-visual { display: none; }
  .download-row { grid-template-columns: 42px minmax(0,1fr) 20px; padding: 11px; }
  .download-row strong { font-size: 12px; }
  .catalog-result { grid-template-columns: 1fr; gap: 4px; }
  .catalog-result em { justify-self: start; }
}
