* { box-sizing: border-box; }
html { overflow-x: hidden; }
body {
  margin: 0;
  overflow-x: hidden;
  color: var(--tools-text);
  background: var(--tools-bg);
  font-family: var(--tools-sans);
}
button, input, select, textarea { font: inherit; }
button, select, input[type="file"], input[type="checkbox"], input[type="radio"] { cursor: pointer; }
button:disabled, select:disabled, input:disabled, textarea:disabled { cursor: not-allowed; opacity: .58; }

main {
  width: min(1040px, calc(100% - 40px));
  margin: 0 auto;
}
.hero {
  max-width: 850px;
  margin: 42px auto 54px;
  text-align: center;
}
.eyebrow, .step-label {
  margin: 0 0 12px;
  color: var(--tools-green-strong);
  font: 700 .72rem/1.3 var(--tools-mono);
  letter-spacing: .12em;
  text-transform: uppercase;
}
.hero h1 {
  margin: 0 auto;
  font-family: var(--tools-serif);
  font-size: clamp(2.65rem, 6vw, 4.8rem);
  font-weight: 500;
  line-height: .98;
  letter-spacing: -.055em;
}
.hero-copy {
  max-width: 700px;
  margin: 27px auto 0;
  color: var(--tools-muted);
  font-size: clamp(1rem, 2vw, 1.14rem);
  line-height: 1.72;
}
.hero-proof {
  margin: 22px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px 20px;
  color: var(--tools-green-strong);
  font-size: .77rem;
  font-weight: 750;
  list-style: none;
}
.hero-proof li { display: inline-flex; align-items: center; gap: 7px; }
.hero-proof svg { width: 15px; height: 15px; flex: 0 0 auto; }

.workspace {
  margin-bottom: 54px;
  overflow: hidden;
  border: 1px solid var(--tools-line);
  border-radius: 24px;
  background: color-mix(in srgb, var(--tools-surface) 95%, transparent);
  box-shadow: var(--tools-shadow);
}
.workspace-section {
  padding: clamp(28px, 5vw, 46px);
  border-top: 1px solid var(--tools-line);
}
.workspace-section:first-child { border-top: 0; }
.section-heading { max-width: 760px; margin-bottom: 24px; }
.section-heading h2 {
  margin: 0;
  font-family: var(--tools-serif);
  font-size: clamp(2rem, 4vw, 2.85rem);
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -.04em;
}
.section-heading > p:not(.step-label) {
  margin: 11px 0 0;
  color: var(--tools-muted);
  line-height: 1.65;
}
.compact-heading h2 { font-size: clamp(1.8rem, 3.5vw, 2.45rem); }
.compact-heading > p:not(.step-label) { font-size: .85rem; }

.source-choice {
  margin: 0 0 18px;
  padding: 0;
  display: flex;
  gap: 8px;
  border: 0;
}
.source-choice legend {
  width: 100%;
  margin-bottom: 9px;
  color: var(--tools-muted);
  font-size: .73rem;
  font-weight: 800;
}
.source-choice label {
  min-height: 44px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--tools-line);
  border-radius: 10px;
  background: var(--tools-surface);
  font-size: .78rem;
  font-weight: 750;
}
.source-choice label.selected {
  border-color: var(--tools-green);
  box-shadow: inset 0 0 0 1px var(--tools-green);
}
.source-choice input { width: 18px; height: 18px; margin: 0; accent-color: var(--tools-green); }

.source-panel > label, .control-field > span, .column-selector legend {
  display: block;
  margin-bottom: 8px;
  color: var(--tools-text);
  font-size: .76rem;
  font-weight: 800;
}
.source-panel textarea {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  padding: 14px 15px;
  border: 1px solid var(--tools-line);
  border-radius: 12px;
  outline: 0;
  color: var(--tools-text);
  background: var(--tools-surface-soft);
  font: 600 .82rem/1.55 var(--tools-mono);
  tab-size: 4;
}
.source-panel textarea::placeholder { color: color-mix(in srgb, var(--tools-muted) 72%, transparent); }
.file-panel {
  padding: 20px;
  border: 1px solid var(--tools-line);
  border-radius: 13px;
  background: var(--tools-surface-soft);
}
.file-panel input[type="file"] {
  width: 100%;
  min-height: 44px;
  color: var(--tools-muted);
  font-size: .78rem;
}
.file-panel input[type="file"]::file-selector-button {
  min-height: 44px;
  margin-right: 12px;
  padding: 0 14px;
  border: 1px solid var(--tools-line);
  border-radius: 9px;
  color: var(--tools-green-strong);
  background: var(--tools-surface);
  font-weight: 800;
}
.file-state { margin: 11px 0 0; font-size: .75rem; font-weight: 750; overflow-wrap: anywhere; }
.field-hint, .control-field small, .switch-row small {
  display: block;
  margin-top: 7px;
  color: var(--tools-muted);
  font-size: .7rem;
  font-weight: 500;
  line-height: 1.5;
}

.load-controls, .choice-grid, .export-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 16px;
}
.choice-grid, .export-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.control-field { min-width: 0; }
.control-field select {
  width: 100%;
  min-height: 46px;
  padding: 0 38px 0 12px;
  border: 1px solid var(--tools-line);
  border-radius: 10px;
  outline: 0;
  color: var(--tools-text);
  background: var(--tools-surface);
  font-size: .8rem;
  font-weight: 700;
}
:where(.button-primary, .workspace button) {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--tools-line);
  border-radius: 10px;
  color: var(--tools-text);
  background: var(--tools-surface);
  font-size: .76rem;
  font-weight: 800;
}
.button-primary {
  min-height: 48px;
  font-size: .95rem;
  padding-inline: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-color: var(--tools-action);
  color: var(--tools-on-action);
  background: var(--tools-action);
}
.button-primary svg, .download-button svg { width: 18px; height: 18px; }
.privacy-note {
  margin: 14px 0 0;
  color: var(--tools-muted);
  font-size: .7rem;
  line-height: 1.55;
}

.operation-banner, .message {
  margin: 0 clamp(28px, 5vw, 46px) 0;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 1px solid var(--tools-line);
  border-radius: 12px;
  background: var(--tools-surface-soft);
}
.operation-banner { margin-bottom: clamp(28px, 5vw, 46px); }
.operation-banner strong { min-width: 0; flex: 1; font-size: .78rem; }
.operation-banner button { flex: 0 0 auto; }
.busy-indicator {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border: 2px solid var(--tools-line);
  border-top-color: var(--tools-green);
  border-radius: 50%;
  animation: csv-spin .8s linear infinite;
}
.message { margin-bottom: 0; border-radius: 0; border-inline: 0; }
.message svg { width: 18px; height: 18px; flex: 0 0 auto; }
.message p { margin: 0; font-size: .76rem; line-height: 1.5; }
.message-error { color: var(--tools-red); background: color-mix(in srgb, var(--tools-red) 8%, var(--tools-surface)); }
.message-status { color: var(--tools-green-strong); background: color-mix(in srgb, var(--tools-green) 8%, var(--tools-surface)); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.stat-grid > div {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--tools-line);
  border-radius: 12px;
  background: var(--tools-surface-soft);
}
.stat-grid strong, .stat-grid span { display: block; }
.stat-grid strong { font: 700 1.35rem/1.1 var(--tools-mono); }
.stat-grid span { margin-top: 5px; color: var(--tools-muted); font-size: .67rem; line-height: 1.4; }
.source-diagnostics {
  margin-top: 14px;
  padding: 14px 16px;
  border-left: 3px solid var(--tools-green);
  background: color-mix(in srgb, var(--tools-green) 6%, transparent);
}
.source-diagnostics p { margin: 0; font-size: .75rem; line-height: 1.55; }
.source-diagnostics p + p { margin-top: 4px; }
.warning-text { color: color-mix(in srgb, #8a6412 86%, var(--tools-text)); }

.switch-row, .option-card {
  min-height: 58px;
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border: 1px solid var(--tools-line);
  border-radius: 12px;
  background: var(--tools-surface-soft);
}
.switch-row { margin-top: 15px; }
.switch-row input, .option-card input {
  width: 20px;
  height: 20px;
  margin: 1px 0 0;
  flex: 0 0 auto;
  accent-color: var(--tools-green);
}
.switch-row > span, .option-card > span { min-width: 0; }
.switch-row strong, .option-card strong { display: block; font-size: .77rem; }
.switch-row small, .option-card small { margin-top: 4px; }
.recovery-actions, .cleaning-actions, .preview-actions {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.option-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.choice-grid { margin-top: 16px; }
.column-selector {
  margin: 18px 0 0;
  padding: 0;
  border: 0;
}
.column-selector > div {
  max-height: 250px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  overflow: auto;
  border: 1px solid var(--tools-line);
  border-radius: 12px;
  background: var(--tools-surface-soft);
}
.column-selector label {
  min-height: 44px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 9px;
  border-radius: 8px;
  font-size: .73rem;
  overflow-wrap: anywhere;
}
.column-selector input { width: 18px; height: 18px; flex: 0 0 auto; accent-color: var(--tools-green); }
.order-note {
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid var(--tools-line);
  border-radius: 12px;
  background: var(--tools-surface);
}
.order-note strong { font-size: .75rem; }
.order-note p { margin: 5px 0 0; color: var(--tools-muted); font-size: .72rem; line-height: 1.6; }

.change-summary {
  padding: 17px;
  border: 1px solid var(--tools-green);
  border-radius: 13px;
  background: color-mix(in srgb, var(--tools-green) 7%, var(--tools-surface));
}
.change-summary h3, .removed-preview h3 { margin: 0; font-size: .86rem; }
.change-summary ul {
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 18px;
  color: var(--tools-muted);
  font-size: .73rem;
  list-style: none;
}
.unchanged-state, .empty-preview, .export-blocked {
  padding: 16px;
  border: 1px solid var(--tools-line);
  border-radius: 12px;
  background: var(--tools-surface-soft);
}
.unchanged-state strong { font-size: .8rem; }
.unchanged-state p { margin: 5px 0 0; color: var(--tools-muted); font-size: .73rem; line-height: 1.55; }
.change-legend, .preview-note { margin: 16px 0 8px; color: var(--tools-muted); font-size: .7rem; line-height: 1.5; }

.table-shell {
  width: 100%;
  max-width: 100%;
  margin-top: 12px;
  overflow: auto;
  border: 1px solid var(--tools-line);
  border-radius: 12px;
  background: var(--tools-surface);
  overscroll-behavior-inline: contain;
}
table {
  width: 100%;
  min-width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .72rem;
}
th, td {
  max-width: 280px;
  padding: 10px 12px;
  border-right: 1px solid var(--tools-line);
  border-bottom: 1px solid var(--tools-line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}
th:last-child, td:last-child { border-right: 0; }
tbody tr:last-child > * { border-bottom: 0; }
thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: var(--tools-text);
  background: var(--tools-surface-soft);
  font-weight: 800;
}
.row-number {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 64px;
  color: var(--tools-muted);
  background: var(--tools-surface-soft);
  font: 700 .7rem/1.4 var(--tools-mono);
}
thead .row-number { z-index: 3; }
td { min-width: 130px; font-family: var(--tools-mono); white-space: pre-wrap; }
.cell-placeholder { color: var(--tools-muted); font-style: italic; font-family: var(--tools-sans); }
.missing-cell { background: color-mix(in srgb, var(--tools-muted) 4%, var(--tools-surface)); }
.changed-cell { box-shadow: inset 3px 0 0 var(--tools-green); background: color-mix(in srgb, var(--tools-green) 8%, var(--tools-surface)); }
.change-badge {
  width: fit-content;
  margin-top: 5px;
  padding: 2px 5px;
  display: block;
  border: 1px solid color-mix(in srgb, var(--tools-green) 55%, var(--tools-line));
  border-radius: 5px;
  color: var(--tools-green-strong);
  font: 700 .6rem/1.3 var(--tools-sans);
}
.empty-preview { color: var(--tools-muted); font-size: .75rem; }

.pagination {
  margin-top: 13px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}
.pagination span { min-width: 0; color: var(--tools-muted); font-size: .68rem; text-align: center; line-height: 1.45; }
.removed-preview {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--tools-line);
}
.removed-preview > p { margin: 6px 0 0; color: var(--tools-muted); font-size: .71rem; line-height: 1.5; }
.removed-preview ul { margin: 13px 0 0; padding: 0; border-top: 1px solid var(--tools-line); list-style: none; }
.removed-preview li {
  min-height: 58px;
  padding: 10px 0;
  display: grid;
  grid-template-columns: minmax(130px, .4fr) minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--tools-line);
}
.removed-label strong, .removed-label small { display: block; }
.removed-label strong { font-size: .73rem; }
.removed-label small { margin-top: 3px; color: var(--tools-muted); font-size: .65rem; }
.removed-values { min-width: 0; display: flex; flex-wrap: wrap; gap: 5px; }
.removed-values code {
  max-width: 100%;
  padding: 4px 6px;
  overflow: hidden;
  border: 1px solid var(--tools-line);
  border-radius: 6px;
  color: var(--tools-text);
  background: var(--tools-surface-soft);
  font: 600 .66rem/1.4 var(--tools-mono);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.export-grid { margin-top: 0; }
.safe-count, .raw-warning {
  margin: 9px 0 0;
  padding-left: 4px;
  color: var(--tools-muted);
  font-size: .71rem;
  line-height: 1.5;
}
.raw-warning { color: color-mix(in srgb, #8a6412 88%, var(--tools-text)); }
.export-blocked { margin-top: 15px; color: var(--tools-muted); font-size: .73rem; line-height: 1.5; }
.download-button { margin-top: 17px; }

.toast {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: 24px;
  max-width: calc(100% - 32px);
  padding: 11px 15px;
  border-radius: 10px;
  color: #fff;
  background: #171a18;
  box-shadow: var(--tools-shadow);
  transform: translateX(-50%);
  font-size: .8rem;
  font-weight: 750;
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--tools-green) 58%, transparent);
  outline-offset: 3px;
}
textarea:focus-visible, select:focus-visible, .table-shell:focus-visible { border-color: var(--tools-green); }

@media (hover: hover) and (pointer: fine) {
  .workspace button:not(:disabled):hover,
  .source-choice label:hover,
  .column-selector label:hover,
  .file-panel input[type="file"]::file-selector-button:hover {
    border-color: color-mix(in srgb, var(--tools-green) 58%, var(--tools-line));
    background: color-mix(in srgb, var(--tools-green) 5%, var(--tools-surface));
  }
  .workspace .button-primary:not(:disabled):hover { border-color: var(--tools-action-hover); background: var(--tools-action-hover); }
}
.workspace button:not(:disabled):active, .source-choice label:active { transform: scale(.985); }

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

@media (prefers-color-scheme: dark) {
  .warning-text, .raw-warning { color: #e4c36f; }
  .toast { color: #111; background: #f2f4ef; }
}

@media (max-width: 820px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .choice-grid, .export-grid { grid-template-columns: 1fr; }
  .column-selector > div { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  main { width: min(100% - 28px, 1040px); }
  .hero { margin: 32px auto 38px; }
  .hero h1 { font-size: clamp(2.3rem, 12vw, 3.35rem); }
  .hero-copy { font-size: .94rem; line-height: 1.58; }
  .workspace { border-radius: 18px; }
  .workspace-section { padding: 26px 18px; }
  .load-controls { grid-template-columns: 1fr; align-items: stretch; }
  .load-controls .button-primary { width: 100%; }
  .option-grid { grid-template-columns: 1fr; }
  .operation-banner { margin-inline: 18px; }
  .pagination { grid-template-columns: 1fr 1fr; }
  .pagination span { grid-column: 1 / -1; grid-row: 1; }
  .pagination button:first-child { grid-column: 1; }
  .pagination button:last-child { grid-column: 2; }
  .removed-preview li { grid-template-columns: 1fr; gap: 7px; }
}

@media (max-width: 380px) {
  main { width: min(100% - 20px, 1040px); }
  .workspace-section { padding-inline: 14px; }
  .source-choice { display: grid; grid-template-columns: 1fr; }
  .source-choice label { width: 100%; }
  .stat-grid { grid-template-columns: 1fr; }
  .change-summary ul { grid-template-columns: 1fr; }
  .operation-banner { margin-inline: 14px; flex-wrap: wrap; }
  .operation-banner button { width: 100%; }
  .recovery-actions button, .cleaning-actions button, .preview-actions button { width: 100%; }
  .download-button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
  .busy-indicator { animation: none; border-top-color: var(--tools-green); }
  .workspace button:not(:disabled):active, .source-choice label:active { transform: none; }
}
