/* ── Reset & Variables ─────────────────────────────────────────────────────── */
:root {
  --primary:      #2563eb;
  --primary-dark: #1d4ed8;
  --success:      #16a34a;
  --error:        #dc2626;
  --warning:      #d97706;
  --bg:           #f1f5f9;
  --card:         #ffffff;
  --border:       #e2e8f0;
  --text:         #1e293b;
  --text-muted:   #64748b;
  --radius:       10px;
  --shadow:       0 1px 4px rgba(0,0,0,.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
header {
  background: var(--primary);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.header-title { display: flex; align-items: center; gap: 10px; font-size: 1rem; font-weight: 600; }
.header-sub   { opacity: .65; font-size: .8rem; }

/* ── Steps Nav ───────────────────────────────────────────────────────────────── */
.steps-nav {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 4px;
}
.step-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px;
  cursor: default;
  user-select: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  transition: color .2s, border-color .2s;
}
.step-item.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 500;
}
.step-item.done { color: var(--success); }
.step-num {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 700;
  transition: background .2s, color .2s;
}
.step-item.active .step-num { background: var(--primary); color: #fff; }
.step-item.done  .step-num  { background: var(--success);  color: #fff; }
.step-sep { color: var(--border); font-size: .9rem; padding: 0 4px; }
.step-label { font-size: .82rem; }

/* ── Layout ──────────────────────────────────────────────────────────────────── */
main {
  max-width: 960px;
  margin: 24px auto;
  padding: 0 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.step-panel         { display: none; flex-direction: column; gap: 16px; }
.step-panel.active  { display: flex; }

/* ── Card ────────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card h2 {
  font-size: .9rem; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
  padding: 18px 20px 0;
  color: var(--text);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
}
.card-header h2 { padding: 0; }
.toggle-arrow { color: var(--text-muted); transition: transform .2s; }
.card-header.open .toggle-arrow { transform: rotate(180deg); }
.card-body { padding: 0 20px 20px; }
.card-body.hidden { display: none; }
.card-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: #fafbfc;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.card-footer.between { justify-content: space-between; }

/* ── Form ────────────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 12px 16px;
  align-items: center;
  margin-bottom: 16px;
}
.form-grid label { font-weight: 500; color: var(--text-muted); }

input[type="text"],
input[type="url"],
input[type="password"] {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .875rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  background: #fff;
}
input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.input-with-badge { display: flex; align-items: center; gap: 8px; }
.input-with-badge input { flex: 1; }
.env-badge {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: .7rem; font-weight: 700;
  background: #dcfce7; color: #15803d;
  white-space: nowrap;
}
.env-badge.preprod { background: #fef3c7; color: #92400e; }

.test-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }

/* Auth result block */
#testResult { margin-top: 4px; }
.auth-result {
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 12px 14px;
  font-size: .82rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.auth-result.ok   { background: #f0fdf4; border-color: #86efac; }
.auth-result.warn { background: #fffbeb; border-color: #fcd34d; }
.auth-result.fail { background: #fff5f5; border-color: #fca5a5; flex-direction: row; align-items: center; gap: 8px; color: var(--error); font-weight: 500; }

.auth-icon { font-size: 1rem; flex-shrink: 0; }
.auth-result.ok   .auth-icon { color: var(--success); }
.auth-result.warn .auth-icon { color: var(--warning); }

.auth-user {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-weight: 600; font-size: .875rem;
}
.auth-id { color: var(--text-muted); font-weight: 400; font-size: .78rem; }
.auth-badge {
  padding: 2px 7px; border-radius: 10px; font-size: .7rem; font-weight: 600;
}
.auth-badge.err { background: #fee2e2; color: #b91c1c; }

.auth-rights {
  display: flex; flex-wrap: wrap; gap: 5px;
}
.auth-right {
  padding: 2px 8px; border-radius: 10px; font-size: .72rem; font-weight: 500;
  background: var(--bg); color: var(--text-muted); border: 1px solid var(--border);
}
.auth-right.has     { background: #dcfce7; color: #15803d; border-color: #86efac; font-weight: 700; }
.auth-right.missing { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; font-weight: 700; }
.auth-right.dim     { opacity: .65; font-size: .68rem; }

.auth-warn-msg {
  font-size: .8rem; color: #92400e;
  padding: 6px 10px; background: #fef3c7; border-radius: 6px;
  line-height: 1.5;
}

/* ── Dropzone ────────────────────────────────────────────────────────────────── */
#dropzone {
  margin: 16px 20px 0;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 24px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .2s;
  position: relative;
}
#dropzone input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%;
}
#dropzone:hover, #dropzone.over {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary);
}
#dropzone svg { margin-bottom: 10px; opacity: .5; }
#dropzone p { margin-bottom: 4px; font-size: .875rem; }
.drop-sub  { font-size: .8rem; opacity: .7; }
.drop-link { color: var(--primary); text-decoration: underline; }

/* ── File List ───────────────────────────────────────────────────────────────── */
#fileList { padding: 8px 20px 0; display: flex; flex-direction: column; gap: 6px; }
.file-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 6px;
  font-size: .82rem;
}
.file-item .fname { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .fsize { color: var(--text-muted); white-space: nowrap; }
.file-remove {
  background: none; border: none; cursor: pointer;
  color: var(--error); font-size: 1.1rem; line-height: 1; padding: 0 2px;
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px;
  border: none; border-radius: 6px;
  font-size: .85rem; font-weight: 500;
  cursor: pointer;
  transition: background .15s, opacity .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }
.btn.primary  { background: var(--primary); color: #fff; }
.btn.primary:hover  { background: var(--primary-dark); }
.btn.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--border); }
.btn.danger   { background: var(--error); color: #fff; }
.btn.danger:hover { background: #b91c1c; }
.btn.sm { padding: 6px 12px; font-size: .8rem; }

/* ── Stats ───────────────────────────────────────────────────────────────────── */
.stats-row { display: flex; gap: 12px; padding: 16px 20px; flex-wrap: wrap; }
.stat-box {
  flex: 1; min-width: 100px;
  display: flex; flex-direction: column; align-items: center;
  padding: 14px;
  border-radius: 8px;
  background: var(--bg);
}
.stat-box.valid  { background: #dcfce7; }
.stat-box.error  { background: #fee2e2; }
.stat-box.info   { background: #dbeafe; }
.stat-num {
  font-size: 2rem; font-weight: 700; line-height: 1;
}
.stat-box.valid  .stat-num { color: #15803d; }
.stat-box.error  .stat-num { color: #b91c1c; }
.stat-box.info   .stat-num { color: #1d4ed8; }
.stat-lbl { font-size: .75rem; color: var(--text-muted); margin-top: 4px; }

/* ── Filter Bar ──────────────────────────────────────────────────────────────── */
.filter-bar { display: flex; gap: 8px; padding: 0 20px 12px; }
.filter-btn {
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text-muted);
  font-size: .78rem; font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Table ───────────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow: auto;
  max-height: 420px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
table { width: 100%; border-collapse: collapse; font-size: .8rem; }
thead { position: sticky; top: 0; z-index: 1; background: #f8fafc; }
th {
  padding: 9px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 7px 14px; border-bottom: 1px solid var(--border); font-family: 'Menlo', 'Courier New', monospace; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
tr.row-invalid td { background: #fff5f5; }
tr.row-invalid:hover td { background: #fef2f2; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px;
  font-size: .73rem; font-weight: 600;
}
.badge.valid     { background: #dcfce7; color: #15803d; }
.badge.invalid   { background: #fee2e2; color: #b91c1c; }
.badge.pending   { background: #f1f5f9; color: #64748b; }
.badge.processing{ background: #fef3c7; color: #92400e; }
.badge.success   { background: #dcfce7; color: #15803d; }
.badge.error     { background: #fee2e2; color: #b91c1c; }
.err-hint { display: block; font-size: .7rem; color: var(--error); font-family: sans-serif; margin-top: 2px; }

/* ── Import Options ──────────────────────────────────────────────────────────── */
.options-grid { padding: 16px 20px; display: flex; gap: 32px; flex-wrap: wrap; }
.option-block { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 10px; }
.option-label { font-weight: 600; font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

.radio-item {
  display: flex; align-items: flex-start; gap: 10px;
  cursor: pointer; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  transition: border-color .15s, background .15s;
}
.radio-item:hover { border-color: var(--primary); background: #f0f7ff; }
.radio-item input[type="radio"] { display: none; }
.radio-custom {
  width: 16px; height: 16px; flex-shrink: 0;
  border: 2px solid var(--border); border-radius: 50%;
  margin-top: 2px;
  transition: border-color .15s;
  position: relative;
}
.radio-item input:checked ~ .radio-custom {
  border-color: var(--primary);
}
.radio-item input:checked ~ .radio-custom::after {
  content: '';
  position: absolute; inset: 2px;
  background: var(--primary); border-radius: 50%;
}
.radio-item input:checked ~ span strong { color: var(--primary); }
.radio-item span strong { display: block; font-size: .875rem; }
.radio-item span em { font-style: normal; font-size: .78rem; color: var(--text-muted); }

.range-row { display: flex; align-items: center; gap: 12px; }
input[type="range"] { flex: 1; accent-color: var(--primary); }
.range-val { font-weight: 600; font-size: .85rem; min-width: 52px; text-align: right; }
.range-hint { font-size: .75rem; color: var(--text-muted); }

/* ── Progress ────────────────────────────────────────────────────────────────── */
.progress-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 20px 8px;
  font-size: .875rem; font-weight: 500;
}
.progress-pct { font-size: 1.1rem; font-weight: 700; color: var(--primary); }
.progress-track {
  margin: 0 20px 16px;
  height: 8px; background: var(--border); border-radius: 4px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--primary); border-radius: 4px;
  width: 0%; transition: width .3s ease;
}
.progress-fill.done-ok  { background: var(--success); }
.progress-fill.done-err { background: var(--warning); }

.progress-stats {
  display: flex; gap: 12px; padding: 0 20px 16px; flex-wrap: wrap;
}
.pstat {
  padding: 6px 14px; border-radius: 6px;
  font-size: .82rem; font-weight: 600;
  background: var(--bg);
}
.pstat.success { background: #dcfce7; color: #15803d; }
.pstat.error   { background: #fee2e2; color: #b91c1c; }
.pstat.info    { background: #dbeafe; color: #1d4ed8; }

.job-controls { display: flex; gap: 8px; padding: 0 20px 16px; }

/* ── Log Panel ───────────────────────────────────────────────────────────────── */
.log-panel { border-top: 1px solid var(--border); }
.log-header {
  padding: 8px 16px; background: #1e293b; color: #94a3b8;
  font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
}
.log-body {
  background: #0f172a; padding: 8px 12px;
  height: 180px; overflow-y: auto;
  font-family: 'Menlo', 'Courier New', monospace; font-size: .75rem;
}
.log-entry { padding: 1px 4px; color: #94a3b8; }
.log-entry.ok   { color: #4ade80; }
.log-entry.err  { color: #f87171; }
.log-entry.info { color: #60a5fa; }
.log-entry.warn { color: #fbbf24; }

/* ── Results ─────────────────────────────────────────────────────────────────── */
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  padding: 20px;
}
.result-item {
  text-align: center; padding: 20px 12px;
  border-radius: 8px; background: var(--bg);
}
.result-item .rnum { font-size: 2.2rem; font-weight: 700; line-height: 1; }
.result-item .rlbl { font-size: .75rem; color: var(--text-muted); margin-top: 6px; }
.result-item.ri-ok   .rnum { color: var(--success); }
.result-item.ri-err  .rnum { color: var(--error);   }
.result-item.ri-info .rnum { color: var(--primary);  }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  main { padding: 0 12px 32px; }
  .form-grid { grid-template-columns: 1fr; }
  .options-grid { flex-direction: column; }
}
