/* ===== CSV Sanitizer — styles ===== */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #1c2430;
  --ink-soft: #5b6572;
  --ink-faint: #8a94a1;
  --line: #e2e6ec;
  --line-strong: #cdd4dd;
  --accent: #4f46e5;
  --accent-ink: #4338ca;
  --accent-soft: #eef0fe;
  --good: #0e9f6e;
  --good-soft: #e6f6f0;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --hl-change: #fff3c4;
  --hl-add: #dff3e6;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { font-size: 26px; }
.brand h1 { font-size: 18px; margin: 0; line-height: 1.2; }
.tagline { margin: 0; font-size: 12.5px; color: var(--ink-soft); }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.privacy-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--good); background: var(--good-soft);
  border: 1px solid #bfe6d6; border-radius: 999px; padding: 4px 12px;
  white-space: nowrap;
}

/* ---- buttons / inputs ---- */
.btn {
  font: inherit; border-radius: 8px; cursor: pointer; border: 1px solid transparent;
  padding: 8px 14px; background: none; color: var(--ink);
  transition: background .12s ease, border-color .12s ease, transform .05s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-outline { border-color: var(--line-strong); background: var(--surface); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { color: var(--ink-soft); }
.btn-ghost:hover { color: var(--accent-ink); background: var(--accent-soft); }
.btn-lg { padding: 12px 22px; font-size: 16px; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-sub { opacity: .75; font-size: 12px; font-weight: 400; margin-left: 4px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.select, .text-input {
  font: inherit; color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 7px 10px; background: var(--surface); width: 100%;
}
.select-sm { width: auto; padding: 5px 8px; font-size: 13px; }
.text-input:focus, .select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}

/* toggle switch */
.switch { position: relative; display: inline-block; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch-track {
  pointer-events: none;
  display: block; width: 40px; height: 22px; border-radius: 999px;
  background: var(--line-strong); position: relative; transition: background .15s ease;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow); transition: left .15s ease;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { left: 21px; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- main layout ---- */
#main { max-width: 1560px; margin: 0 auto; padding: 20px; }
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) 300px minmax(0, 1.25fr);
  gap: 16px;
  align-items: start;
}
.pane {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px 16px; min-width: 0;
}
.pane-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px; flex-wrap: wrap; margin-bottom: 10px;
}
.pane-head h2 { font-size: 15.5px; margin: 0; display: flex; align-items: center; gap: 8px; }
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%; font-size: 12.5px;
  background: var(--accent-soft); color: var(--accent-ink); flex: none;
}
.pane-head-meta { font-size: 12.5px; color: var(--ink-soft); }
.pane-controls { position: sticky; top: 76px; }

/* ---- empty state ---- */
.empty-state { padding: 48px 16px 24px; }
.empty-hero { max-width: 640px; margin: 0 auto; text-align: center; }
.empty-hero h2 { font-size: 30px; line-height: 1.25; margin: 0 0 14px; letter-spacing: -.01em; }
.lede { color: var(--ink-soft); font-size: 16px; margin: 0 0 24px; }
.empty-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.hint { color: var(--ink-faint); font-size: 13px; margin-top: 18px; }
.empty-paste {
  width: 100%; max-width: 640px; min-height: 150px; margin-top: 16px; resize: vertical;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.5;
  border: 1px dashed var(--line-strong); border-radius: 8px; padding: 10px;
  background: var(--surface); color: var(--ink);
  white-space: pre; overflow: auto;
}
.empty-paste:focus { border-style: solid; }

/* ---- input pane ---- */
.input-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar-note { font-size: 12.5px; color: var(--ink-faint); }
#raw-input {
  width: 100%; min-height: 190px; resize: vertical;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.5;
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 10px;
  background: #fafbfc; color: var(--ink);
  white-space: pre; overflow: auto;
}

.preview-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 14px 0 6px;
}
.preview-head h3 { font-size: 13.5px; margin: 0; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }
.count-chip { font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* ---- tables ---- */
.table-wrap {
  overflow: auto; max-height: 460px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
table.data {
  border-collapse: collapse; font-family: var(--mono); font-size: 12px; width: 100%;
}
table.data th, table.data td {
  border: 1px solid var(--line); padding: 4px 8px; text-align: left;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  vertical-align: top;
}
table.data thead th {
  position: sticky; top: 0; background: #f0f2f5; z-index: 2;
  font-family: inherit; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-soft); white-space: nowrap;
}
table.data th.rownum {
  position: sticky; left: 0; background: #f7f8fa; color: var(--ink-faint);
  font-size: 10.5px; text-align: right; min-width: 34px; z-index: 1;
}
table.data thead th.rownum { z-index: 3; }
table.data tr.row-removed td { background: var(--bad-soft); color: #9b2c2c; text-decoration: line-through; }
table.data tr.row-removed td .cell-text { opacity: .75; }
td.cell-changed { background: var(--hl-change); }
td.cell-added { background: var(--hl-add); }
.reason-chip {
  display: inline-block; font-family: inherit; font-size: 10.5px; font-style: normal;
  text-decoration: none; background: #fff; border: 1px solid #f3c2c2; color: var(--bad);
  border-radius: 999px; padding: 1px 8px; white-space: nowrap;
}
tr.row-removed th.rownum { text-decoration: none; }
th.rownum .reason-chip { display: block; margin-top: 2px; text-align: left; }
.empty-cell { color: var(--ink-faint); font-style: italic; }
.show-more { width: 100%; margin-top: 8px; }

/* ---- controls pane ---- */
.control-group { margin-bottom: 16px; }
.control-label { font-size: 13px; font-weight: 600; display: block; margin-bottom: 6px; }
.control-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.control-note { font-size: 12px; color: var(--ink-faint); margin: 6px 0 0; }
.detected-badge {
  font-size: 12px; color: var(--accent-ink); background: var(--accent-soft);
  border-radius: 6px; padding: 4px 8px; margin-bottom: 6px; display: none;
}
.detected-badge.visible { display: block; }
.encoding-info { font-size: 12.5px; color: var(--ink-soft); }
.encoding-info .enc-name { font-weight: 600; color: var(--ink); }
.encoding-info ul { margin: 6px 0 0; padding-left: 18px; }
.encoding-info li { margin: 2px 0; }

.steps { border-top: 1px solid var(--line); padding-top: 14px; display: grid; gap: 14px; }
.step-label { display: block; cursor: pointer; }
.step-label small { display: block; color: var(--ink-faint); font-size: 12px; margin-top: 2px; }
.step-stat { font-size: 12.5px; color: var(--ink-soft); margin-top: 6px; min-height: 18px; font-variant-numeric: tabular-nums; }
.step-stat .stat-strong { color: var(--ink); font-weight: 600; }
.step-stat .stat-good { color: var(--good); font-weight: 600; }

/* ---- after pane ---- */
.stats-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.stat-chip {
  background: var(--accent-soft); color: var(--accent-ink); border-radius: 8px;
  padding: 6px 10px; font-size: 12.5px; font-variant-numeric: tabular-nums;
}
.stat-chip b { font-size: 14px; }
.stat-chip.good { background: var(--good-soft); color: var(--good); }
.stat-chip.warn { background: var(--warn-soft); color: var(--warn); }

.export-card { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 14px; }
.export-card h3 { font-size: 13.5px; margin: 0 0 10px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }
.export-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.export-label { font-size: 13px; color: var(--ink-soft); flex: none; }
.export-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---- alerts ---- */
#alerts { display: grid; gap: 8px; margin-bottom: 16px; }
#alerts:empty { display: none; }
.alert {
  border-radius: 8px; padding: 10px 14px; font-size: 13.5px;
  display: flex; gap: 10px; align-items: flex-start;
  border: 1px solid;
}
.alert-error { background: var(--bad-soft); border-color: #f3c2c2; color: #8a1f1f; }
.alert-warning { background: var(--warn-soft); border-color: #eed9b5; color: #7c4a03; }
.alert-info { background: var(--accent-soft); border-color: #d3d8fb; color: var(--accent-ink); }
.alert .alert-x { margin-left: auto; background: none; border: 0; font-size: 15px; cursor: pointer; color: inherit; opacity: .6; }
.alert .alert-x:hover { opacity: 1; }

/* ---- overlays ---- */
#drop-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(79,70,229,.14);
  backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.drop-overlay-card {
  background: var(--surface); border: 2px dashed var(--accent); border-radius: 16px;
  padding: 40px 60px; text-align: center; font-size: 18px; font-weight: 600; color: var(--accent-ink);
  box-shadow: 0 12px 40px rgba(16,24,40,.18);
}
.drop-overlay-icon { font-size: 40px; margin-bottom: 8px; }

#processing {
  position: fixed; inset: 0; z-index: 90; background: rgba(244,245,247,.7);
  backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center;
}
.processing-card {
  background: var(--surface); border-radius: 14px; box-shadow: 0 12px 40px rgba(16,24,40,.18);
  padding: 26px 34px; text-align: center; min-width: 260px;
}
.processing-card p { margin: 10px 0; font-weight: 600; }
.spinner {
  width: 30px; height: 30px; margin: 0 auto;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-track { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 999px; transition: width .2s ease; }

/* ---- footer ---- */
.footer { text-align: center; color: var(--ink-faint); font-size: 12.5px; padding: 28px 16px 20px; }

/* ---- responsive ---- */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 280px minmax(0, 1fr); }
}
@media (max-width: 1020px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .pane-controls { position: static; }
  .empty-hero h2 { font-size: 24px; }
}
@media (max-width: 640px) {
  #main { padding: 12px; }
  .topbar { padding: 10px 12px; }
  .brand h1 { font-size: 16px; }
  .privacy-badge { font-size: 11px; padding: 3px 9px; }
  .empty-state { padding: 28px 8px 16px; }
  .empty-hero h2 { font-size: 21px; }
  .lede { font-size: 14.5px; }
  .btn-lg { padding: 10px 16px; font-size: 15px; width: 100%; }
  .empty-actions { flex-direction: column; align-items: stretch; }
  #raw-input { min-height: 140px; font-size: 12px; }
  .table-wrap { max-height: 320px; }
  .export-actions { flex-direction: column; }
  .export-actions .btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 1.6s; }
  * { transition: none !important; }
}
