/* ═══════════════════════════════════════════════════════════════
   FORM BUILDER — CSS
   Clean, responsive, light-themed with blue accent
═══════════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent:       #2563eb;
  --accent-hover: #1d4ed8;
  --bg:           #f5f5f5;
  --surface:      #ffffff;
  --surface2:     #f0f0f0;
  --surface3:     #e8e8e8;
  --border:       #d0d0d0;
  --text:         #1a1a1a;
  --text-muted:   #6b6b6b;
  --success:      #16a34a;
  --danger:       #dc2626;
  --radius:       10px;
  --shadow:       0 4px 24px rgba(0,0,0,.08);
  --transition:   .18s ease;
}

html { font-size: 16px; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ── TOP NAV ──────────────────────────────────────────────────── */
.topnav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topnav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 1.4rem; }
.brand-name { font-weight: 700; font-size: 1.05rem; color: var(--accent); }
.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: .9rem;
  transition: color var(--transition);
}
.nav-link:hover { color: var(--accent); }

/* ── PAGE WRAPPER ─────────────────────────────────────────────── */
.page-wrapper {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

/* ── CARD ─────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

/* ── STEP ─────────────────────────────────────────────────────── */
.step { display: none; }
.step.active { display: block; }
.step.hidden { display: none !important; }

.step-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 28px;
}
.step-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.step-title { font-size: 1.4rem; font-weight: 700; }
.step-desc  { color: var(--text-muted); font-size: .9rem; margin-top: 2px; }

.back-step-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .85rem;
  transition: all var(--transition);
  align-self: center;
  white-space: nowrap;
}
.back-step-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── LOADER ───────────────────────────────────────────────────── */
.loader-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 40px 0;
  color: var(--text-muted);
}
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── ALERT ────────────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: .9rem;
}
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: #dc2626; }
.alert button {
  margin-left: auto;
  background: none;
  border: 1px solid currentColor;
  color: inherit;
  padding: 4px 12px;
  border-radius: 5px;
  cursor: pointer;
}
.hidden { display: none !important; }

/* ── NEW FORM BANNER ──────────────────────────────────────────── */
.new-form-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding: 20px 24px;
  border: 2px dashed var(--accent);
  background: rgba(37,99,235,.04);
}
.new-form-info { display: flex; align-items: center; gap: 14px; }
.new-form-icon { font-size: 1.6rem; flex-shrink: 0; }
.new-form-title { font-weight: 700; font-size: 1rem; }
.new-form-desc  { font-size: .82rem; color: var(--text-muted); margin-top: 2px; }

/* ── EXISTING FORMS LIST ──────────────────────────────────────── */
.existing-forms-list { display: flex; flex-direction: column; gap: 12px; }

.existing-form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: border-color var(--transition);
}
.existing-form-card:hover { border-color: var(--accent); }

.efc-icon { font-size: 1.4rem; flex-shrink: 0; }
.efc-info { flex: 1; min-width: 0; }
.efc-title {
  font-weight: 700;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.efc-meta { font-size: .78rem; color: var(--text-muted); margin-top: 3px; }
.efc-link {
  font-size: .75rem;
  color: var(--accent);
  font-family: monospace;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}
.efc-actions { display: flex; gap: 8px; flex-shrink: 0; }

.no-existing-forms {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: .9rem;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

@media (max-width: 600px) {
  .new-form-banner { flex-direction: column; align-items: flex-start; }
  .existing-form-card { flex-wrap: wrap; }
  .efc-actions { width: 100%; justify-content: flex-end; }
}

/* ── DATABASE GRID ────────────────────────────────────────────── */
.db-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.db-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.db-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.db-card-icon { font-size: 1.8rem; }
.db-card-name { font-weight: 600; font-size: 1rem; }
.db-card-meta { font-size: .78rem; color: var(--text-muted); }

/* ── BUILDER META ─────────────────────────────────────────────── */
.builder-meta { margin-bottom: 24px; }
.form-row { margin-bottom: 16px; }
.form-row:last-child { margin-bottom: 0; }
.form-label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.optional { font-weight: 400; text-transform: none; letter-spacing: 0; }
.text-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: .95rem;
  font-family: inherit;
  transition: border-color var(--transition);
}
.text-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.textarea { resize: vertical; min-height: 64px; }
.select-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: .95rem;
  cursor: pointer;
  transition: border-color var(--transition);
}
.select-input:focus { outline: none; border-color: var(--accent); }

/* ── BUILDER COLUMNS ──────────────────────────────────────────── */
.builder-columns {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 20px;
  align-items: start;
  margin-bottom: 24px;
}
@media (max-width: 768px) {
  .builder-columns { grid-template-columns: 1fr; }
}

.col-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.col-hint {
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* ── AVAILABLE PROPS ──────────────────────────────────────────── */
.prop-list { display: flex; flex-direction: column; gap: 6px; }
.prop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}
.prop-item:hover { border-color: var(--accent); background: var(--surface3); }
.prop-item.added {
  opacity: .45;
  cursor: default;
  pointer-events: none;
}
.prop-icon { font-size: 1rem; flex-shrink: 0; }
.prop-name { font-size: .9rem; font-weight: 500; flex: 1; }
.prop-type-badge {
  font-size: .7rem;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--surface3);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* Relation hint badge in prop list */
.prop-rel-hint {
  font-size: .7rem;
  padding: 2px 7px;
  border-radius: 20px;
  background: rgba(37,99,235,.10);
  color: var(--accent);
  border: 1px solid rgba(37,99,235,.25);
  white-space: nowrap;
}

/* ── FORM FIELDS BUILDER ──────────────────────────────────────── */
.fields-drop-zone {
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.empty-drop-hint {
  flex: 1;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: .9rem;
}

/* ── FIELD CARD (in builder) ──────────────────────────────────── */
.field-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: border-color var(--transition);
}
.field-card:hover { border-color: var(--accent); }
.field-card-drag {
  color: var(--text-muted);
  cursor: grab;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.field-card-drag:active { cursor: grabbing; }
.field-card-info { flex: 1; min-width: 0; }
.field-card-label {
  font-size: .9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.field-card-meta {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.field-card-required {
  font-size: .7rem;
  color: var(--accent);
  font-weight: 700;
  margin-left: 4px;
}
.field-card-actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

/* Relation DB badge inside field card meta */
.rel-db-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: .68rem;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(37,99,235,.08);
  color: var(--accent);
  border: 1px solid rgba(37,99,235,.22);
  margin-left: 4px;
  vertical-align: middle;
}
.rel-db-badge.warn {
  background: rgba(220,38,38,.08);
  color: var(--danger);
  border-color: rgba(220,38,38,.22);
}

/* ── FIELD CONFIG PANEL ───────────────────────────────────────── */
.field-config-panel {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0;
  margin-bottom: 24px;
  overflow: hidden;
  animation: slideDown .2s ease;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fcp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: rgba(37,99,235,.06);
  border-bottom: 1px solid var(--border);
}
.fcp-header h3 { font-size: 1rem; font-weight: 700; }
.fcp-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color var(--transition);
}
.fcp-close:hover { color: var(--danger); }
.fcp-body { padding: 20px; }
.fcp-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

/* Relation info box inside field config */
.fcp-relation-info { margin-bottom: 0; }
.rel-info-box {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(37,99,235,.05);
  border: 1px solid rgba(37,99,235,.22);
  border-radius: 7px;
  font-size: .85rem;
}
.rel-info-box.warn {
  background: rgba(220,38,38,.05);
  border-color: rgba(220,38,38,.22);
}
.rel-info-box code {
  font-family: monospace;
  font-size: .8rem;
  color: var(--accent);
  word-break: break-all;
}
.rel-info-box.warn code { color: var(--danger); }

/* ── TOGGLE ───────────────────────────────────────────────────── */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-size: .9rem;
}
.toggle-cb { display: none; }
.toggle-track {
  width: 42px;
  height: 24px;
  background: var(--surface3);
  border-radius: 12px;
  border: 1px solid var(--border);
  position: relative;
  transition: background var(--transition);
  flex-shrink: 0;
}
.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: all var(--transition);
}
.toggle-cb:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle-cb:checked + .toggle-track .toggle-thumb { left: 21px; background: #fff; }

/* ── BUTTONS ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 7px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-outline { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-outline:hover { background: rgba(37,99,235,.08); }
.btn-lg { padding: 12px 28px; font-size: 1rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── SAVE BAR ─────────────────────────────────────────────────── */
.save-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  padding: 16px 0 0;
  border-top: 1px solid var(--border);
}
.save-status { font-size: .85rem; color: var(--text-muted); }
.save-status.ok  { color: var(--success); }
.save-status.err { color: var(--danger); }

/* ── DONE CARD ────────────────────────────────────────────────── */
.done-card {
  max-width: 560px;
  margin: 0 auto;
  text-align: center;
  padding: 48px 32px;
}
.done-icon { font-size: 3.5rem; margin-bottom: 16px; }
.done-title { font-size: 1.6rem; font-weight: 800; margin-bottom: 10px; }
.done-desc { color: var(--text-muted); margin-bottom: 28px; }

.link-box {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}
.link-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--accent);
  font-size: .9rem;
  font-family: monospace;
}
.link-input:focus { outline: none; border-color: var(--accent); }

.done-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── DRAG OVER ────────────────────────────────────────────────── */
.field-card.dragging { opacity: .4; }
.fields-drop-zone.drag-over { background: rgba(37,99,235,.04); border-radius: 8px; }

/* ── RESPONSIVE ───────────────────────────────────────────────── */
@media (max-width: 600px) {
  .page-wrapper { padding: 20px 14px 60px; }
  .step-header { flex-wrap: wrap; }
  .save-bar { flex-direction: column; align-items: stretch; }
  .save-bar .btn-lg { width: 100%; justify-content: center; }
  .done-card { padding: 32px 20px; }
  .link-box { flex-direction: column; }
  .topnav-inner { padding: 0 14px; }
}

/* ── Copy Link Button ─────────────────────────────────────────── */
.efc-link-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}
.copy-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 4px 6px;
  border-radius: 5px;
  cursor: pointer;
  transition: all var(--transition);
}
.copy-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ══════════════════════════════════════════════════════════════
   RELATION CONFIG BLOCK (inside field-config panel)
══════════════════════════════════════════════════════════════ */

/* Wrapper block */
.relation-config-block {
  background: rgba(37,99,235,.04);
  border: 1px solid rgba(37,99,235,.18);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.relation-config-block.relation-config-warn {
  background: rgba(220,38,38,.04);
  border-color: rgba(220,38,38,.22);
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  color: var(--danger);
  font-size: .88rem;
}
.relation-config-block.relation-config-warn strong {
  display: block;
  margin-bottom: 2px;
}
.relation-config-block.relation-config-warn .rc-hint {
  color: var(--text-muted);
  font-size: .8rem;
}

/* Header row: icon + label + badge */
.rc-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.rc-icon  { font-size: 1rem; }
.rc-badge {
  font-size: .65rem;
  background: rgba(37,99,235,.12);
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 20px;
  font-weight: 700;
  letter-spacing: .04em;
  margin-left: auto;
}

/* Description text */
.rc-desc {
  font-size: .82rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

/* Loading spinner inside config block */
.rc-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: .85rem;
  padding: 4px 0;
}
.rc-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  flex-shrink: 0;
}

/* Select wrapper with custom arrow */
.rc-select-wrap {
  position: relative;
}
.rc-select {
  width: 100%;
  padding: 10px 36px 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: .9rem;
  appearance: none;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.rc-select:hover { border-color: var(--accent); }
.rc-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.rc-select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: .8rem;
  color: var(--text-muted);
  pointer-events: none;
}

/* Preview pill — shows what will be displayed */
.rc-preview { margin-top: 2px; }
.rc-preview-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(37,99,235,.06);
  border: 1px solid rgba(37,99,235,.18);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: .78rem;
}
.rc-preview-label { color: var(--text-muted); }
.rc-preview-field { font-weight: 700; color: var(--accent); }
.rc-preview-type  {
  background: rgba(37,99,235,.10);
  color: var(--accent);
  border-radius: 10px;
  padding: 1px 7px;
  font-size: .7rem;
  font-weight: 600;
}

/* ── Field-card relation badges ───────────────────────────────── */
.rel-display-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(37,99,235,.08);
  color: var(--accent);
  border: 1px solid rgba(37,99,235,.22);
  border-radius: 12px;
  font-size: .7rem;
  font-weight: 600;
  padding: 2px 8px;
}
.rel-warn-pill {
  display: inline-flex;
  align-items: center;
  background: rgba(220,38,38,.08);
  color: var(--danger);
  border: 1px solid rgba(220,38,38,.22);
  border-radius: 12px;
  font-size: .7rem;
  font-weight: 600;
  padding: 2px 8px;
}
.rel-config-pill {
  display: inline-flex;
  align-items: center;
  background: rgba(37,99,235,.04);
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: 12px;
  font-size: .7rem;
  padding: 2px 8px;
  cursor: pointer;
}
