:root {
  color-scheme: light;
  --page: #f3f8fa;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-solid: #ffffff;
  --surface-muted: #f7fafb;
  --text: #102630;
  --muted: #657b86;
  --line: #d7e5e9;
  --line-strong: #bed3d9;
  --teal: #008f79;
  --teal-hover: #007665;
  --teal-soft: #e5f7f3;
  --red: #b42318;
  --red-soft: #fdecea;
  --red-line: #f2b8b5;
  --shadow: 0 20px 60px rgba(24, 57, 70, 0.08);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #071721;
  --surface: rgba(10, 30, 41, 0.91);
  --surface-solid: #0b1d28;
  --surface-muted: #0e2430;
  --text: #edf8f8;
  --muted: #91a8b2;
  --line: #1d3b48;
  --line-strong: #315363;
  --teal: #51e7c8;
  --teal-hover: #79f1d7;
  --teal-soft: #0d342f;
  --red: #ff938e;
  --red-soft: #3b2022;
  --red-line: #774044;
  --shadow: 0 20px 65px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--page); }
body { margin: 0; background: var(--page); color: var(--text); transition: background-color 240ms ease, color 240ms ease; }
button, input, select { font: inherit; }
a { color: inherit; text-decoration: none; }

.page-shell {
  position: relative;
  display: grid;
  min-height: 100vh;
  grid-template-rows: auto 1fr auto;
  isolation: isolate;
  overflow: hidden;
  background: radial-gradient(circle at 8% 18%, color-mix(in srgb, var(--teal) 11%, transparent), transparent 29rem), radial-gradient(circle at 92% 70%, color-mix(in srgb, #7755cc 8%, transparent), transparent 34rem), var(--page);
}

.circuit-grid {
  position: absolute; z-index: -1; inset: 0; opacity: 0.28;
  background-image: linear-gradient(color-mix(in srgb, var(--line) 45%, transparent) 1px, transparent 1px), linear-gradient(90deg, color-mix(in srgb, var(--line) 45%, transparent) 1px, transparent 1px);
  background-size: 48px 48px; mask-image: linear-gradient(to bottom, black, transparent 62%);
}

.site-header, .workspace, footer { width: min(1480px, calc(100% - 48px)); margin-inline: auto; }
.site-header { display: flex; min-height: 84px; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 15px; }
.brand > strong { color: var(--teal); font-size: 2rem; font-weight: 900; letter-spacing: -0.11em; line-height: 1; }
.brand > span { width: 1px; height: 35px; background: var(--line-strong); }
.brand > div { display: grid; gap: 3px; }
.brand b { font-size: 0.78rem; letter-spacing: 0.15em; }
.brand small { color: var(--muted); font-size: 0.75rem; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.local-badge { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.82rem; }
.local-badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 5px color-mix(in srgb, var(--teal) 12%, transparent); }
.theme-toggle { display: inline-flex; min-height: 40px; align-items: center; gap: 8px; padding: 8px 13px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); cursor: pointer; font-size: 0.8rem; font-weight: 650; }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sun-icon { display: none; }
:root[data-theme="dark"] .moon-icon { display: none; }
:root[data-theme="dark"] .sun-icon { display: block; }

.workspace { padding: 42px 0 70px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 32px; margin-bottom: 28px; }
.back-link { display: inline-block; margin-bottom: 20px; color: var(--muted); font-size: 0.9rem; }
.back-link:hover { color: var(--teal); }
.page-heading p { margin: 0 0 8px; color: var(--teal); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.18em; }
.page-heading h1 { margin: 0; font-size: clamp(2rem, 4vw, 3.2rem); letter-spacing: -0.045em; line-height: 1.08; }
.page-heading > div > span { display: block; margin-top: 12px; color: var(--muted); font-size: 1rem; }
.format-chip { min-width: 170px; padding: 18px 21px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.format-chip span { color: var(--muted); font-size: 0.75rem; }
.format-chip strong { display: block; margin-top: 5px; color: var(--teal); font-size: 1.25rem; }

.import-card { padding: 18px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); transition: padding 220ms ease; }
.drop-zone { display: flex; min-height: 138px; align-items: center; gap: 22px; padding: 24px 26px; border: 1.5px dashed var(--line-strong); border-radius: 18px; background: color-mix(in srgb, var(--teal-soft) 42%, transparent); cursor: pointer; transition: border-color 180ms ease, background 180ms ease, transform 180ms ease; }
.drop-zone:hover, .drop-zone.is-dragging { border-color: var(--teal); background: color-mix(in srgb, var(--teal-soft) 76%, transparent); transform: translateY(-1px); }
.drop-zone:focus-visible { outline: 3px solid color-mix(in srgb, var(--teal) 35%, transparent); outline-offset: 3px; }
.drop-zone.is-processing { opacity: 0.72; pointer-events: none; }
.upload-icon { display: grid; width: 62px; height: 62px; flex: 0 0 auto; place-items: center; border: 1px solid color-mix(in srgb, var(--teal) 35%, var(--line)); border-radius: 18px; background: var(--surface-solid); color: var(--teal); }
.upload-icon svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.drop-copy { display: grid; flex: 1; gap: 7px; }
.drop-copy strong { font-size: 1.22rem; }
.drop-copy span { color: var(--muted); font-size: 0.91rem; line-height: 1.55; }
.primary-button, .secondary-button, .export-button { border: 0; cursor: pointer; font-weight: 700; transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease; }
.primary-button { padding: 12px 22px; border-radius: 12px; background: var(--teal); color: #fff; }
:root[data-theme="dark"] .primary-button { color: #06231e; }
.primary-button:hover, .export-button:hover { transform: translateY(-1px); background: var(--teal-hover); }
.import-settings { display: flex; align-items: center; gap: 12px; padding: 14px 10px 0; }
.import-settings label { color: var(--muted); font-size: 0.82rem; }
.import-settings select { min-height: 36px; padding: 0 34px 0 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-solid); color: var(--text); }
.import-settings p { display: flex; align-items: center; gap: 8px; margin: 0 0 0 auto; color: var(--muted); font-size: 0.78rem; }
.import-settings p i { width: 6px; height: 6px; border-radius: 50%; background: var(--teal); }
.import-card.is-compact .drop-zone { min-height: 86px; }
.import-card.is-compact .upload-icon { width: 48px; height: 48px; border-radius: 14px; }

.result-area { display: grid; gap: 18px; margin-top: 22px; animation: reveal 420ms cubic-bezier(.2,.8,.2,1); }
.is-hidden { display: none !important; }
@keyframes reveal { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

.status-strip { display: flex; align-items: center; justify-content: space-between; gap: 22px; padding: 19px 22px; border: 1px solid var(--line); border-radius: 19px; background: var(--surface); }
.file-summary { display: flex; min-width: 0; align-items: center; gap: 13px; }
.file-icon { display: grid; width: 42px; height: 42px; flex: 0 0 auto; place-items: center; border-radius: 11px; background: var(--teal-soft); color: var(--teal); font-size: 0.66rem; font-weight: 800; }
.file-summary > div { display: grid; min-width: 0; gap: 4px; }
.file-summary strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.93rem; }
.file-summary span { color: var(--muted); font-size: 0.76rem; }
.summary-metrics { display: flex; gap: 12px; }
.summary-metrics > div { min-width: 102px; padding: 10px 16px; border-left: 1px solid var(--line); }
.summary-metrics strong { display: block; color: var(--teal); font-size: 1.28rem; line-height: 1.1; }
.summary-metrics span { display: block; margin-top: 5px; color: var(--muted); font-size: 0.72rem; }
.summary-metrics .warning-metric strong { color: var(--red); }

.mapping-panel { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.mapping-panel summary { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 15px 18px; cursor: pointer; list-style: none; }
.mapping-panel summary::-webkit-details-marker { display: none; }
.mapping-panel summary span { font-size: 0.88rem; font-weight: 700; }
.mapping-panel summary small { color: var(--muted); font-size: 0.72rem; }
.mapping-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding: 0 16px 16px; }
.mapping-item { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 7px; padding: 10px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-muted); font-size: 0.72rem; }
.mapping-item span { overflow: hidden; color: var(--teal); text-overflow: ellipsis; white-space: nowrap; }
.mapping-item i { color: var(--muted); font-style: normal; }
.mapping-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mapping-item.is-missing { border-color: var(--red-line); background: var(--red-soft); }
.mapping-item.is-missing span { color: var(--red); }

.table-card { overflow: hidden; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.table-toolbar > div:first-child { display: grid; gap: 5px; }
.table-toolbar p { margin: 0; font-size: 1rem; font-weight: 750; }
.table-toolbar > div:first-child span { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 0.73rem; }
.legend-missing { width: 10px; height: 10px; border: 1px solid var(--red-line); border-radius: 3px; background: var(--red-soft); }
.toolbar-actions { display: flex; align-items: center; gap: 10px; }
.search-box { display: flex; width: 245px; min-height: 40px; align-items: center; gap: 8px; padding: 0 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-muted); }
.search-box svg { width: 17px; height: 17px; flex: 0 0 auto; fill: none; stroke: var(--muted); stroke-width: 1.8; }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 0.79rem; }
.filter-toggle { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); cursor: pointer; font-size: 0.77rem; white-space: nowrap; }
.filter-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.filter-toggle > span { position: relative; width: 34px; height: 20px; border-radius: 999px; background: var(--line-strong); transition: background 180ms ease; }
.filter-toggle > span::after { position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; content: ""; transition: transform 180ms ease; }
.filter-toggle input:checked + span { background: var(--red); }
.filter-toggle input:checked + span::after { transform: translateX(14px); }
.secondary-button { min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-solid); color: var(--text); font-size: 0.78rem; }
.secondary-button:hover { border-color: var(--teal); color: var(--teal); }
.export-button { display: inline-flex; min-height: 40px; align-items: center; gap: 7px; padding: 0 16px; border-radius: 10px; background: var(--teal); color: #fff; font-size: 0.79rem; }
:root[data-theme="dark"] .export-button { color: #06231e; }
.export-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.table-viewport { position: relative; max-height: 560px; overflow: auto; }
table { width: max(100%, 1500px); border-collapse: separate; border-spacing: 0; font-size: 0.75rem; }
th, td { min-width: 108px; height: 42px; padding: 8px 10px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
th { position: sticky; z-index: 3; top: 0; background: var(--surface-muted); color: var(--text); font-weight: 750; text-align: center; }
th:first-child, td:first-child { position: sticky; left: 0; z-index: 2; min-width: 52px; width: 52px; text-align: center; }
th:first-child { z-index: 4; background: var(--surface-muted); }
td:first-child { background: var(--surface-solid); }
th:nth-child(2), td:nth-child(2) { min-width: 115px; }
th:nth-child(3), td:nth-child(3) { min-width: 150px; }
th:last-child, td:last-child { min-width: 330px; border-right: 0; }
td { background: color-mix(in srgb, var(--surface-solid) 86%, transparent); color: var(--text); }
tbody tr:hover td { background: color-mix(in srgb, var(--teal-soft) 38%, var(--surface-solid)); }
td[contenteditable="true"] { outline: 0; }
td[contenteditable="true"]:focus { position: relative; z-index: 2; box-shadow: inset 0 0 0 2px var(--teal); background: var(--surface-solid); }
.sequence-cell { color: var(--muted); font-family: Consolas, monospace; }
.missing-cell { background: var(--red-soft) !important; color: var(--red); }
.missing-cell::after { content: "缺少"; font-weight: 700; opacity: 0.82; }
.missing-header { background: var(--red-soft); color: var(--red); }
.empty-filter { display: grid; min-height: 220px; place-items: center; color: var(--muted); font-size: 0.86rem; }
.table-footer { display: flex; min-height: 48px; align-items: center; justify-content: space-between; gap: 20px; padding: 0 20px; color: var(--muted); font-size: 0.73rem; }

.toast { position: fixed; z-index: 20; right: 24px; bottom: 24px; max-width: min(420px, calc(100% - 48px)); padding: 13px 17px; border: 1px solid color-mix(in srgb, var(--teal) 42%, var(--line)); border-radius: 12px; background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(14px); transition: opacity 180ms ease, transform 180ms ease; font-size: 0.82rem; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast[data-tone="error"] { border-color: var(--red-line); color: var(--red); }
footer { display: flex; min-height: 66px; align-items: center; justify-content: space-between; gap: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.75rem; }

@media (max-width: 1120px) {
  .mapping-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar-actions { width: 100%; flex-wrap: wrap; }
  .search-box { flex: 1; min-width: 230px; }
}

@media (max-width: 720px) {
  .site-header, .workspace, footer { width: min(100% - 28px, 560px); }
  .site-header { min-height: 74px; }
  .brand > strong { font-size: 1.68rem; }
  .brand b { letter-spacing: 0.08em; }
  .local-badge, .theme-label { display: none; }
  .theme-toggle { width: 40px; padding: 8px; }
  .workspace { padding: 30px 0 48px; }
  .page-heading { align-items: flex-start; flex-direction: column; gap: 18px; }
  .format-chip { display: none; }
  .drop-zone { align-items: flex-start; flex-wrap: wrap; padding: 20px; }
  .drop-copy { min-width: calc(100% - 84px); }
  .primary-button { width: 100%; }
  .import-settings { align-items: flex-start; flex-wrap: wrap; }
  .import-settings p { width: 100%; margin-left: 0; line-height: 1.5; }
  .status-strip { align-items: flex-start; flex-direction: column; }
  .summary-metrics { width: 100%; }
  .summary-metrics > div { min-width: 0; flex: 1; padding-inline: 10px; }
  .mapping-list { grid-template-columns: 1fr; }
  .toolbar-actions { align-items: stretch; flex-direction: column; }
  .search-box { width: 100%; min-width: 0; }
  .filter-toggle { min-height: 38px; }
  .secondary-button, .export-button { justify-content: center; }
  footer { align-items: flex-start; flex-direction: column; justify-content: center; gap: 4px; padding: 16px 0; }
}

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

/* v5: append-only shared history and bounded preview */
[hidden] { display:none !important; }
.operator-settings { display:flex;align-items:center;gap:14px;flex-wrap:wrap;margin-bottom:12px; }
.operator-settings label { font-weight:700; }
.operator-settings label span { color:#b42318; }
.operator-settings input,.sheet-settings select { color:inherit;background:transparent;border:1px solid #94a3b877;border-radius:9px;padding:10px 13px;font:inherit; }
.operator-settings input { min-width:220px; }
#serverStatus,.privacy-notice,.sheet-notice { font-size:12px;line-height:1.7;opacity:.85; }
.privacy-notice { margin:0 0 18px; }
.save-strip { display:flex;align-items:center;justify-content:space-between;gap:16px;border:1px solid #10877755;background:#1087770d;border-radius:12px;padding:14px 18px;margin-bottom:14px;font-size:13px; }
[data-error="true"] { color:#c44831; }
.sheet-settings { display:flex;align-items:center;gap:14px;margin:10px 0; }
.sheet-notice:empty { display:none; }
.history-card { margin-top:28px;padding:24px;border:1px solid #94a3b844;border-radius:18px;background:var(--surface); }
.history-heading,.history-footer { display:flex;align-items:center;justify-content:space-between;gap:18px; }
.history-heading h2 { margin:0 0 6px;font-size:20px; }
.history-heading p { margin:0;font-size:12px;line-height:1.7;opacity:.75; }
.history-viewport { overflow:auto;margin:18px 0; }
.history-table { width:100%;border-collapse:collapse;text-align:left;font-size:12px; }
.history-table th { background:#10877712;white-space:nowrap; }
.history-table th,.history-table td { padding:13px 12px;border-bottom:1px solid #94a3b833; }
.history-table td:nth-child(3) { min-width:210px;max-width:430px;overflow-wrap:anywhere; }
.history-table td:last-child { white-space:nowrap; }
.history-download { color:#087f70;text-decoration:underline;margin-right:12px; }
[data-theme="dark"] .history-download { color:#70d2bd; }
.history-footer { font-size:12px; }
.history-footer>div,.table-footer>div { display:flex;gap:8px; }
button:disabled { opacity:.5;cursor:not-allowed; }
#previewTable td[contenteditable="false"] { cursor:default; }
@media(max-width:760px) { .history-card {padding:16px;} .history-heading,.history-footer,.operator-settings,.save-strip {align-items:flex-start;flex-direction:column;} .operator-settings input {width:100%;} .table-footer {flex-wrap:wrap;gap:10px;} }

