/* ============================================================
   Funnel Creator — list-view admin for multi-page quiz funnels
   Loaded only from admin/index.html. Hidden until mode-funnel is active.
   Uses existing color variables (--color-navy-950, --color-gold-400, etc.)
   from admin.css. No Tailwind rebuild needed.
   ============================================================ */

/* Mode visibility: hide the single-page form & tab bar when in funnel mode,
   and vice-versa. The mode switcher itself stays visible in both. */
body.mode-funnel #tab-bar,
body.mode-funnel #config-form,
body.mode-funnel #compliance-banner,
body.mode-funnel #success-banner { display: none !important; }
body:not(.mode-funnel) #funnel-tab { display: none !important; }
body.mode-funnel #funnel-tab { display: block !important; }

/* Hide the header's single-page-only action buttons while in funnel mode.
   Funnel mode has its own Save & Build button inside the tab. */
body.mode-funnel #deploy-btn,
body.mode-funnel #save-draft-btn,
body.mode-funnel #save-status,
body.mode-funnel #demo-god-btn { display: none !important; }

/* Mode switcher tab buttons */
.mode-tab {
  padding: 5px 12px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.mode-tab:hover { color: #fff; }
.mode-tab.active {
  background: var(--color-gold-400, #D4A843);
  color: var(--color-navy-950, #0F0D2E);
}

/* ---------- Funnel Tab container ---------- */
/* Take full desktop width — this surface benefits from every pixel since
   paths + steps + (eventually) canvas all live side-by-side. */
.funnel-tab {
  max-width: none;
  width: 100%;
  margin: 0;
  padding: 24px 24px 80px;
  color: var(--color-navy-800, #1A1A2E);
}
/* Admin <main> constrains its children; push funnel-tab out of that box */
body.mode-funnel .admin-main {
  max-width: none !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
}

.funnel-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--color-border, #E5E7EB);
}
.funnel-toolbar-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 280px;
  flex: 1 1 280px;
}
.funnel-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.funnel-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-navy-600, #1E2235);
}
.funnel-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border-strong, #D1D5DB);
  border-radius: 6px;
  background: #fff;
  font-size: 14px;
  color: var(--color-navy-900, #12112A);
}
.funnel-select:focus {
  outline: none;
  border-color: var(--color-gold-400, #D4A843);
  box-shadow: 0 0 0 3px rgba(212, 168, 67, 0.2);
}

.funnel-dirty {
  font-size: 12px;
  font-weight: 600;
  color: #B45309;
}

.funnel-banner {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
  line-height: 1.5;
}
.funnel-banner.ok { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }
.funnel-banner.err { background: #FEF2F2; color: #991B1B; border: 1px solid #FCA5A5; white-space: pre-wrap; }

/* ---------- Two-column grid ----------
   Paths panel stays a compact fixed width; steps panel expands to fill
   the rest of the viewport. On wide desktops this gives the step list
   enough room to show the full question and monospace sub-line without
   any horizontal scroll at all. */
.funnel-grid {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 820px) {
  .funnel-grid { grid-template-columns: 1fr; }
}

.funnel-paths,
.funnel-steps {
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border, #E5E7EB);
  border-radius: 10px;
  overflow: hidden;
}
.funnel-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border, #E5E7EB);
  background: var(--color-page, #F9FAFB);
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  scrollbar-width: none;
}
.funnel-panel-header::-webkit-scrollbar { display: none; }
.funnel-panel-header > * { flex-shrink: 0; }
.funnel-panel-header h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-navy-800, #1A1A2E);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.funnel-panel-header .btn-compact { margin-left: auto; flex-shrink: 0; }
/* When content overflows, the auto margin collapses and items scroll horizontally */
.funnel-selected-path {
  font-size: 12px;
  color: var(--color-navy-600, #1E2235);
  font-weight: 500;
  white-space: nowrap;
}
.funnel-selected-path:empty { display: none; }

/* ---------- Path list ---------- */
.funnel-path-list,
.funnel-step-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 560px;
  overflow-y: auto;
}
.funnel-path-list li,
.funnel-step-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border, #E5E7EB);
  cursor: pointer;
  transition: background 120ms ease;
}
.funnel-path-list li:hover,
.funnel-step-list li:hover {
  background: #FAFAFA;
}
.funnel-path-list li.active,
.funnel-step-list li.active {
  background: #FEF8E7;
  border-left: 3px solid var(--color-gold-400, #D4A843);
}
.funnel-path-list li.indent {
  padding-left: 32px;
  background: linear-gradient(90deg, #FAFAFA 0%, #fff 24px);
}
.funnel-path-list li.empty,
.funnel-step-list li.funnel-empty,
.funnel-path-list li.funnel-empty {
  cursor: default;
  color: #6B7280;
  font-size: 13px;
  font-style: italic;
  justify-content: center;
}

.funnel-row-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
}
/* Horizontal scroll for title + sub instead of truncation or wrap */
.funnel-row-title,
.funnel-row-sub {
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  max-width: 100%;
}
.funnel-row-title::-webkit-scrollbar,
.funnel-row-sub::-webkit-scrollbar { display: none; }
.funnel-row-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-navy-900, #12112A);
  display: flex;
  align-items: center;
  gap: 8px;
}
.funnel-row-sub {
  font-size: 11px;
  color: #6B7280;
  font-family: ui-monospace, SFMono-Regular, monospace;
}
.funnel-row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0.4;
  transition: opacity 120ms ease;
}
.funnel-path-list li:hover .funnel-row-actions,
.funnel-step-list li:hover .funnel-row-actions,
.funnel-path-list li.active .funnel-row-actions,
.funnel-step-list li.active .funnel-row-actions {
  opacity: 1;
}
.funnel-icon-btn {
  background: transparent;
  border: 1px solid var(--color-border, #E5E7EB);
  border-radius: 4px;
  width: 26px;
  height: 26px;
  font-size: 13px;
  cursor: pointer;
  color: var(--color-navy-600, #1E2235);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.funnel-icon-btn:hover {
  background: var(--color-gold-400, #D4A843);
  color: var(--color-navy-950, #0F0D2E);
  border-color: var(--color-gold-400, #D4A843);
}
.funnel-icon-btn.danger:hover {
  background: #DC2626;
  color: #fff;
  border-color: #DC2626;
}

/* ---------- Badges ---------- */
.funnel-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.funnel-badge.main    { background: #DBEAFE; color: #1E40AF; }
.funnel-badge.alt     { background: #FEF3C7; color: #92400E; }
.funnel-badge.next    { background: #E5E7EB; color: #374151; }
.funnel-badge.redirect{ background: #FCE7F3; color: #9D174D; }
.funnel-badge.alternate { background: #DDD6FE; color: #5B21B6; }

/* ---------- Buttons reused (defensive fallbacks) ---------- */
.btn-primary {
  background: var(--color-gold-400, #D4A843);
  color: var(--color-navy-950, #0F0D2E);
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary:hover:not(:disabled) { background: var(--color-gold-500, #C9993E); }
.btn-secondary {
  background: #fff;
  color: var(--color-navy-800, #1A1A2E);
  border: 1px solid var(--color-border-strong, #D1D5DB);
  padding: 7px 13px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--color-navy-600, #1E2235);
}
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-compact { padding: 5px 10px; font-size: 12px; }

/* ---------- Modal ---------- */
.funnel-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.funnel-modal[hidden] { display: none !important; }
.funnel-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 13, 46, 0.55);
  backdrop-filter: blur(2px);
}
.funnel-modal-panel {
  position: relative;
  background: #fff;
  border-radius: 12px;
  width: min(720px, 94vw);
  max-height: 88vh;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.funnel-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border, #E5E7EB);
}
.funnel-modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--color-navy-900, #12112A);
}
.funnel-modal-close {
  background: transparent;
  border: none;
  font-size: 26px;
  line-height: 1;
  color: #6B7280;
  cursor: pointer;
  padding: 0 4px;
}
.funnel-modal-close:hover { color: var(--color-navy-900, #12112A); }
.funnel-modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1 1 auto;
}
.funnel-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--color-border, #E5E7EB);
  background: var(--color-page, #F9FAFB);
}

/* ---------- Form rows in the modal ---------- */
.funnel-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.funnel-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-navy-600, #1E2235);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.funnel-field input[type="text"],
.funnel-field input[type="url"],
.funnel-field textarea,
.funnel-field select {
  padding: 8px 10px;
  border: 1px solid var(--color-border-strong, #D1D5DB);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--color-navy-900, #12112A);
}
.funnel-field textarea { min-height: 60px; resize: vertical; }
.funnel-field input:focus,
.funnel-field textarea:focus,
.funnel-field select:focus {
  outline: none;
  border-color: var(--color-gold-400, #D4A843);
  box-shadow: 0 0 0 3px rgba(212, 168, 67, 0.18);
}

.funnel-field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 520px) { .funnel-field-grid { grid-template-columns: 1fr; } }

/* Repeater rows (options, qualifying_rules) */
.funnel-repeater {
  border: 1px dashed var(--color-border-strong, #D1D5DB);
  border-radius: 8px;
  padding: 10px;
  background: #FAFAFA;
}
.funnel-repeater-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.funnel-repeater-row input,
.funnel-repeater-row select {
  padding: 6px 8px;
  border: 1px solid var(--color-border, #E5E7EB);
  border-radius: 4px;
  font-size: 13px;
  min-width: 0;
  flex: 1 1 auto;
}
.funnel-repeater-row .funnel-icon-btn { flex: 0 0 auto; }
.funnel-repeater-add {
  background: #fff;
  border: 1px solid var(--color-border-strong, #D1D5DB);
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  color: var(--color-navy-700, #1E2235);
  font-weight: 600;
}
.funnel-repeater-add:hover { border-color: var(--color-gold-400, #D4A843); }
.funnel-repeater-empty { font-size: 12px; color: #9CA3AF; font-style: italic; padding: 4px 0; }

.funnel-dq-sub {
  margin-top: 8px;
  padding: 10px;
  background: #F3F4F6;
  border-radius: 6px;
  border-left: 3px solid var(--color-gold-400, #D4A843);
}

/* Ensure help-trigger (?) buttons render correctly inline in the funnel tab
   (help.js uses absolute positioning assumptions in label context — we reset them). */
.funnel-tab .help-trigger,
#mode-switcher .help-trigger,
.funnel-modal .help-trigger {
  position: static !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #E5E7EB;
  color: #4B5563;
  border: none;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  margin: 0;
}
.funnel-tab .help-trigger:hover,
#mode-switcher .help-trigger:hover,
.funnel-modal .help-trigger:hover {
  background: var(--color-gold-400, #D4A843);
  color: var(--color-navy-950, #0F0D2E);
}
