:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-soft: #f6f7f9;
  --border: #e2e6ea;
  --text: #1c2733;
  --text-muted: #66727e;
  --primary: #0b6dc4;
  --primary-hover: #0a5ea8;
  --ok: #1f9d55;
  --ok-soft: #e6f6ec;
  --missing: #d64550;
  --missing-soft: #fbe9ea;
  --chat-bg: #e9e3d8;
  --chat-bubble: #d9f4c8;
  --font: "Salesforce Sans", Arial, sans-serif;
  --radius: 10px;
  --radius-sm: 6px;
  --gap: 20px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: 28px;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

.step {
  display: none;
  flex-direction: column;
  gap: var(--gap);
  max-width: 920px;
  margin: 0 auto;
}

.step.step--active {
  display: flex;
}

.step-header {
  text-align: left;
}

h1 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.step-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.45;
}

/* Step 1 layout */

.step1-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: var(--gap);
  align-items: start;
}

.step1-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.search-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  width: 100%;
}

.search-bar input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s ease;
}

.search-bar input:focus {
  border-color: var(--primary);
}

.search-bar input::placeholder {
  color: #9aa5b1;
}

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-hover);
}

.btn-secondary {
  background-color: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--surface-soft);
}

.templates-panel {
  display: grid;
  gap: 12px;
  min-height: 160px;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.templates-panel .state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 20px 8px;
  color: var(--text-muted);
  font-size: 14px;
}

.templates-panel[data-state="loading"] .state-loading,
.templates-panel[data-state="empty"] .state-empty,
.templates-panel[data-state="error"] .state-error,
.templates-panel[data-state="ready"] .state-ready {
  display: flex;
}

.state-ready {
  align-items: stretch !important;
  width: 100%;
  text-align: left;
}

.state-empty p,
.state-error p {
  margin: 0;
  max-width: 320px;
}

.loading-img {
  width: 40px;
  height: 40px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  text-align: left;
}

#select1 {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  outline: none;
}

#select1:focus {
  border-color: var(--primary);
}

.total {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--text-muted);
  text-align: left;
}

.total span:last-child {
  font-weight: 700;
  color: var(--text);
}

/* Preview / chat bubble */

.preview-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.preview-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.preview-sample-note {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
}

.preview-sample-note[hidden] {
  display: none !important;
}

.preview-sample {
  display: inline;
  padding: 0 3px;
  border-radius: 3px;
  font-weight: 700;
}

.preview-sample--mapped {
  background: rgba(31, 157, 85, 0.18);
  color: #14532d;
}

.preview-sample--unmapped {
  background: rgba(214, 69, 80, 0.12);
  color: #7a1f27;
}

.chat-frame {
  display: flex;
  align-items: flex-start;
  min-height: 220px;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--chat-bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.chat-frame--compact {
  min-height: 96px;
  padding: 14px;
}

.chat-bubble {
  margin: 0;
  padding: 12px 14px;
  border-radius: 0 12px 12px 12px;
  background: var(--chat-bubble);
  color: #1c2b1c;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
  max-width: 100%;
}

/* Step 2 — field mapping (row list + accordion picker) */

.mapping-empty {
  margin: 0;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.45;
  box-shadow: var(--shadow);
}

.mapping-workspace {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mapping-preview {
  margin: 0;
}

.mapping-preview .chat-frame--compact {
  min-height: 72px;
  max-height: 120px;
  overflow-y: auto;
}

.step-subtitle code {
  font-size: 0.95em;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
}

.mapping-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  box-shadow: var(--shadow);
}

.mapping-progress.is-complete {
  border-color: var(--ok);
  background: var(--ok-soft);
  color: #14532d;
}

.mapping-progress.is-incomplete {
  border-color: #f0c4c8;
  background: #fff8f8;
}

.mapping-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mapping-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.mapping-row.is-mapped {
  border-left: 3px solid var(--ok);
}

.mapping-row.is-unmapped {
  border-left: 3px solid var(--missing);
}

.mapping-row.is-open {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(11, 109, 196, 0.2), var(--shadow);
}

.mapping-row-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 0.9fr);
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
}

.mapping-row-meta {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}

.mapping-row-index {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.mapping-row-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.mapping-row-placeholder {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  word-break: break-word;
}

.mapping-row-status {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.mapping-row-status.is-mapped {
  background: var(--ok-soft);
  color: #14532d;
}

.mapping-row-status.is-unmapped {
  background: var(--missing-soft);
  color: #7a1f27;
}

.mapping-row-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.35;
}

.mapping-row-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease, box-shadow 0.12s ease;
}

.mapping-row-trigger:hover {
  border-color: var(--primary);
  background: #edf5fc;
}

.mapping-row.is-open .mapping-row-trigger {
  border-color: var(--primary);
  background: #edf5fc;
  box-shadow: 0 0 0 1px rgba(11, 109, 196, 0.18);
}

.mapping-row-trigger.is-empty {
  color: var(--text-muted);
  font-weight: 600;
}

.mapping-row-trigger-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mapping-row-chevron {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  opacity: 0.55;
  margin-top: -4px;
  transition: transform 0.15s ease;
}

.mapping-row.is-open .mapping-row-chevron {
  transform: rotate(-135deg);
  margin-top: 4px;
}

.mapping-row-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
  background: #fbfdff;
}

.mapping-row-panel[hidden] {
  display: none !important;
}

.mapping-row-panel .field-label {
  margin-top: 12px;
}

.mapping-attr-filter {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
}

.mapping-attr-filter:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 109, 196, 0.12);
}

.mapping-attr-groups {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 260px;
  overflow-y: auto;
}

.mapping-attr-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mapping-attr-group-title {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.mapping-attr-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mapping-attr-option {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.mapping-attr-option:hover {
  background: var(--surface);
  border-color: var(--border);
}

.mapping-attr-option.is-selected {
  background: #edf5fc;
  border-color: rgba(11, 109, 196, 0.35);
  color: var(--primary);
}

.mapping-attr-option-marker {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid #c5ced6;
  background: var(--surface);
  box-shadow: inset 0 0 0 0 var(--primary);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.mapping-attr-option.is-selected .mapping-attr-option-marker {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 4px var(--primary);
}

.mapping-attr-option-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mapping-attr-empty {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.mapping-workspace[hidden],
.mapping-empty[hidden] {
  display: none !important;
}

@media (max-width: 720px) {
  .mapping-row-main {
    grid-template-columns: 1fr;
  }
}

.preview-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.app-version-badge {
  position: fixed;
  right: 12px;
  bottom: 10px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow);
  z-index: 10;
  pointer-events: none;
}

.app-version-badge[hidden] {
  display: none !important;
}

@media (max-width: 720px) {
  .step1-grid,
  .step3-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body {
    padding: 16px;
  }

  .search-bar {
    grid-template-columns: 1fr;
  }

  .btn {
    width: 100%;
  }
}

/* ── Step 0: escolha do provedor ─────────────────────────────────────── */

.providers-panel {
  display: grid;
  gap: 12px;
  min-height: 160px;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.providers-panel .state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 20px 8px;
  color: var(--text-muted);
  font-size: 14px;
}

.providers-panel[data-state="loading"] .state-loading,
.providers-panel[data-state="error"] .state-error,
.providers-panel[data-state="ready"] .state-ready {
  display: flex;
}

.provider-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--gap);
  width: 100%;
}

.provider-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 18px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.provider-card:hover {
  border-color: var(--primary);
}

.provider-card.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 109, 196, 0.15);
}

.provider-card-logo {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
}

.provider-card-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.provider-card-description {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.provider-card-url {
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-all;
}

.provider-card-url code {
  font-size: 11px;
}

.provider-card-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--missing-soft);
  color: var(--missing);
}

/* ── Step audience: clientes / dentistas ─────────────────────────────── */

.audience-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--gap);
  padding: 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.audience-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 18px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.audience-card:hover {
  border-color: var(--primary);
}

.audience-card.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 109, 196, 0.15);
}

.audience-card-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.audience-card-description {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}

.audience-card-description code {
  font-size: 12px;
}

.provider-summary {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.provider-summary code {
  font-size: 12px;
  word-break: break-all;
}

.url-override {
  display: grid;
  gap: 8px;
  margin-top: 4px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.url-override-input,
.test-field-input,
.test-contact-preset {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
}

.url-override-input:focus,
.test-field-input:focus,
.test-contact-preset:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 109, 196, 0.12);
}

.field-label-optional {
  font-weight: 400;
  color: var(--text-muted);
}

.field-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.field-hint code {
  font-size: 11px;
}

.field-required {
  color: var(--missing);
}

/* ── Step 3: teste de envio ──────────────────────────────────────────── */

.step3-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: var(--gap);
  align-items: start;
}

.step3-col {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.test-fields {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.test-field {
  display: grid;
  gap: 6px;
}

.test-field--preset,
.test-field--sandbox {
  padding-bottom: 4px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.test-contact-preset {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23566774' d='M1.4.6L6 5.2 10.6.6 12 2 6 8 0 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

.test-confirm {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  cursor: pointer;
}

.test-confirm input {
  margin-top: 2px;
}

.test-actions {
  display: flex;
  gap: 10px;
}

.test-result {
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-soft);
  font-size: 13px;
  line-height: 1.45;
}

.test-result[data-kind="ok"] {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.test-result[data-kind="error"] {
  border-color: var(--missing);
  background: var(--missing-soft);
}

.test-result[data-kind="pending"] {
  border-color: var(--primary);
  background: #eaf3fb;
}

.test-result-detail {
  margin: 8px 0 0;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.04);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}

.test-payload-panel {
  display: grid;
  gap: 8px;
}

.test-payload-preview {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #1c2733;
  color: #e8eef4;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
  max-height: 320px;
}

@media (max-width: 720px) {
  .step3-grid {
    grid-template-columns: 1fr;
  }
}
