:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #171a2b;
  --muted: #6b7088;
  --border: #e3e5ee;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;
  --ok: #138a52;
  --ok-soft: #e6f6ee;
  --bad: #c62a3a;
  --bad-soft: #fdecee;
  --warn: #9a6400;
  --warn-soft: #fff6e0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 24, 50, .04), 0 2px 8px rgba(20, 24, 50, .04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .35em; line-height: 1.25; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .9em; }
.center { text-align: center; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .8rem 1.5rem; background: var(--card); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 650; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand .logo { color: var(--primary); display: flex; }
.topbar-right { display: flex; align-items: center; gap: .75rem; }

.container { max-width: 1120px; margin: 0 auto; padding: 1.75rem 1.25rem 4rem; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.4rem 1.5rem; box-shadow: var(--shadow); margin-bottom: 1.25rem;
}
.card.narrow { max-width: 440px; margin: 3rem auto; }
.card.empty { padding: 3rem 1.5rem; }
.page-head { margin-bottom: 1.25rem; }
.page-head h1 { margin-top: .25rem; }
.row-between { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.25rem; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + .card, .stats + .card { margin-top: 1.25rem; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }

label { font-weight: 550; font-size: .9rem; display: block; margin-bottom: .3rem; }
input[type=text], input[type=password], input[type=email], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px;
  font: inherit; background: #fff; color: var(--text); transition: border-color .15s, box-shadow .15s;
}
::placeholder { color: #a3a7ba; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; margin-bottom: .75rem; }
.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 500; margin-top: 1.9rem; }
.input-prefix { display: flex; align-items: stretch; }
.input-prefix span {
  display: flex; align-items: center; padding: 0 .6rem; background: var(--bg); border: 1px solid var(--border);
  border-right: 0; border-radius: 8px 0 0 8px; color: var(--muted); font-family: var(--mono); font-size: .9em;
}
.input-prefix input { border-radius: 0 8px 8px 0; }
.pin-input { font-size: 1.6rem; letter-spacing: .5em; text-align: center; font-family: var(--mono); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1.05rem; border-radius: 8px; border: 1px solid transparent; cursor: pointer;
  font: inherit; font-weight: 600; text-decoration: none !important; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--primary-soft); color: var(--primary); }
.btn-secondary:hover { background: #e1e4ff; }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); background: var(--bg); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }
.btn-block { width: 100%; }
.link-button { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; }
.link-button:hover { color: var(--text); }
.icon-btn {
  background: none; border: 1px solid transparent; border-radius: 6px; cursor: pointer;
  color: var(--muted); width: 28px; height: 28px; font-size: .9rem;
}
.icon-btn:hover { background: var(--bg); border-color: var(--border); color: var(--text); }
.icon-btn.danger:hover { color: var(--bad); }
.form-actions { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: 1rem; flex-wrap: wrap; }
.form-actions .btn:last-child { margin-left: auto; }

.flash { padding: .7rem .95rem; border-radius: 8px; margin: .5rem 0 1rem; font-size: .92rem; }
.flash-error { background: var(--bad-soft); color: var(--bad); }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-warn { background: var(--warn-soft); color: var(--warn); }

.badge {
  display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .72rem; font-weight: 650;
  background: var(--bg); color: var(--muted); border: 1px solid var(--border); vertical-align: middle;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-required { background: var(--primary-soft); color: var(--primary); border-color: transparent; }

.table-wrap { overflow-x: auto; margin: 0 -.25rem; }
.table-wrap.tall { max-height: 70vh; overflow-y: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .6rem .7rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; background: #fafbfd; position: sticky; top: 0; }
.table.compact th, .table.compact td { padding: .4rem .6rem; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .rownum { color: var(--muted); font-variant-numeric: tabular-nums; width: 1%; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fafbff; }

.steps { display: flex; list-style: none; padding: 0; margin: 0 0 1.5rem; gap: .5rem; flex-wrap: wrap; }
.steps li { display: flex; align-items: center; gap: .45rem; color: var(--muted); font-size: .9rem; font-weight: 550; }
.steps li + li::before { content: ""; width: 28px; height: 1px; background: var(--border); margin-right: .1rem; }
.step-num {
  display: inline-flex; width: 24px; height: 24px; border-radius: 50%; align-items: center; justify-content: center;
  background: var(--card); border: 1px solid var(--border); font-size: .8rem;
}
.steps li.current { color: var(--text); }
.steps li.current .step-num { background: var(--primary); color: #fff; border-color: var(--primary); }
.steps li.done .step-num { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem;
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 2.4rem 1rem; margin: 1rem 0;
  cursor: pointer; text-align: center; font-weight: 500; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.dropzone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone-icon { font-size: 1.6rem; color: var(--primary); }
.dropzone-title { font-size: 1.02rem; }
.dropzone .link { color: var(--primary); }
.dropzone-file { font-family: var(--mono); font-size: .85rem; color: var(--ok); font-weight: 600; }

.map-table td { vertical-align: middle; }
.map-table select { min-width: 220px; }
.map-table tr.is-mapped td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
.map-table .arrow { color: var(--muted); width: 1%; }
.samples { max-width: 380px; }
.sample {
  display: inline-block; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: .05rem .45rem; margin: .1rem .25rem .1rem 0;
  font-family: var(--mono); font-size: .8rem;
}

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; box-shadow: var(--shadow); }
.stat-value { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-ok .stat-value { color: var(--ok); }
.stat-bad .stat-value { color: var(--bad); }

.grid-table td { min-width: 120px; }
.grid-table td.rownum, .grid-table td.center { min-width: 0; }
.cell-error { background: var(--bad-soft); }
.cell-error input, .cell-error select { border-color: #f1b3ba; background: #fff; padding: .35rem .5rem; }
.cell-msg { color: var(--bad); font-size: .75rem; margin-top: .2rem; }

.importer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.importer-card { color: var(--text); margin: 0; transition: border-color .15s, transform .15s; }
.importer-card:hover { text-decoration: none; border-color: var(--primary); transform: translateY(-1px); }
.importer-card p { margin: .2rem 0 0; }

.field-list { display: flex; flex-direction: column; gap: .75rem; margin-top: 1rem; }
.field-row {
  display: flex; gap: .75rem; align-items: flex-start; border: 1px solid var(--border); border-radius: 10px;
  padding: .85rem; background: #fcfcfe;
}
.field-handle { display: flex; flex-direction: column; gap: .15rem; }
.field-main { flex: 1; min-width: 0; }
.field-grid { display: grid; grid-template-columns: 2fr 1.4fr 1.3fr 1fr 1fr; gap: .6rem; }
.field-grid-2 { grid-template-columns: 1fr 1fr 1fr; margin-top: .6rem; }
.field-grid label { margin: 0; font-weight: 500; }
.field-grid label span { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: .2rem; }
.field-grid input, .field-grid select { padding: .4rem .55rem; font-size: .9rem; }
.field-row:not(.is-select) [data-options-wrap] { opacity: .4; }

.copy-field { display: flex; gap: .5rem; margin-bottom: .75rem; }
.danger-zone { border-color: #f3c9ce; }
.lock-icon, .success-icon { font-size: 2rem; text-align: center; margin-bottom: .5rem; }
.success-icon {
  width: 56px; height: 56px; margin: 0 auto 1rem; border-radius: 50%; background: var(--ok-soft); color: var(--ok);
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}

@media (max-width: 760px) {
  .field-grid, .field-grid-2 { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: 1fr; }
  .container { padding: 1.25rem .85rem 3rem; }
  .card { padding: 1.1rem; }
  .steps .step-name { display: none; }
  .steps li.current .step-name { display: inline; }
}
