/* ==========================================================================
   OpenFunnel console — Modern Design System.

   Designed for clarity, deference, and depth.
   Clean chrome, refined materials, Inter typography, and responsive workspace layout.
   ========================================================================== */

/* ---- Tokens -------------------------------------------------------------- */
:root {
  color-scheme: light;

  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e2e8f0;
  --line: rgba(15, 23, 42, 0.08);
  --line-soft: rgba(15, 23, 42, 0.04);

  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;

  /* Replaced at runtime with the active funnel's own theme colour. Default: Indigo */
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft: rgba(79, 70, 229, 0.08);
  --accent-line: rgba(79, 70, 229, 0.28);

  --pos: #10b981;
  --neg: #ef4444;

  --shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.03), 0 1px 2px -1px rgba(0, 0, 0, 0.03);
  --shadow-2: 0 4px 20px -2px rgba(0, 0, 0, 0.06), 0 2px 6px -1px rgba(0, 0, 0, 0.03);
  --shadow-3: 0 20px 35px -10px rgba(0, 0, 0, 0.1), 0 8px 16px -4px rgba(0, 0, 0, 0.05);

  --r-sm: 6px;
  --r: 12px;
  --r-lg: 16px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Monaco, Consolas, monospace;

  --bar-1: 56px;
  --bar-2: 45px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0b0f19;
  --surface: #111827;
  --surface-2: #1f2937;
  --surface-3: #374151;
  --line: rgba(255, 255, 255, 0.08);
  --line-soft: rgba(255, 255, 255, 0.04);

  --text: #f8fafc;
  --text-2: #94a3b8;
  --text-3: #64748b;

  --accent: #6366f1;
  --accent-soft: rgba(99, 102, 241, 0.15);
  --accent-line: rgba(99, 102, 241, 0.35);

  --pos: #34d399;
  --neg: #f87171;

  --shadow-1: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 4px 10px -2px rgba(0, 0, 0, 0.2);
  --shadow-3: 0 20px 40px -10px rgba(0, 0, 0, 0.6), 0 8px 16px -4px rgba(0, 0, 0, 0.3);
}

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.47059;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p, figure { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--accent-soft); }

/* Scrollbars: present, but subtle and non-intrusive. */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--text-3); }

/* ---- Structural type ----------------------------------------------------- */
.eyebrow {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-3);
}

.mono { font-family: var(--mono); font-size: 12px; }

/* ---- App bar (row 1: identity + context) --------------------------------- */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 60;
  height: var(--bar-1);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 32px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--line);
}

[data-theme="dark"] .app-bar {
  background: rgba(28, 28, 30, 0.85);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  background: none;
  border: 0;
  padding: 4px 6px 4px 4px;
  margin-left: -4px;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.brand:hover { background: var(--surface-2); }

/* The mark is the product's own idea: a funnel is a sequence that narrows. */
.brand-mark { display: block; width: 22px; height: 22px; color: var(--text); }
.brand-name { font-size: 14px; font-weight: 600; letter-spacing: -0.015em; }

.pro-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 1.5px 5px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-line);
}

.bar-divider { width: 1px; height: 20px; background: var(--line); flex: 0 0 auto; }

/* Funnel switcher — carries the active funnel's colour as a swatch. */
.switcher { position: relative; display: flex; align-items: center; }
.switcher-swatch {
  position: absolute;
  left: 10px;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--accent);
  pointer-events: none;
}
.switcher select {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 6px 28px 6px 26px;
  font-size: 13px;
  font-weight: 500;
  max-width: 240px;
  cursor: pointer;
  transition: background 0.12s var(--ease), border-color 0.12s var(--ease);
}
.switcher select:hover { background: var(--surface-2); border-color: var(--text-3); }
.switcher-caret { position: absolute; right: 9px; pointer-events: none; color: var(--text-3); display: flex; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--pos) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--pos) 30%, transparent);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--pos);
}
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 99px;
  background: var(--pos);
  box-shadow: 0 0 8px var(--pos);
}

.bar-spacer { flex: 1; }
.bar-actions { display: flex; align-items: center; gap: 8px; }

/* ---- App bar (row 2: navigation) ----------------------------------------- */
.tab-bar {
  position: sticky;
  top: var(--bar-1);
  z-index: 59;
  height: var(--bar-2);
  display: flex;
  align-items: stretch;
  gap: 2px;
  padding: 0 32px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
[data-theme="dark"] .tab-bar {
  background: rgba(28, 28, 30, 0.85);
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 0;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.12s var(--ease);
}
.tab::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 2px;
  background: transparent;
  transition: background 0.12s var(--ease);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); font-weight: 600; }
.tab[aria-selected="true"]::after { background: var(--accent); }

.tab-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--text-2);
}
.tab[aria-selected="true"] .tab-badge {
  background: var(--accent-soft);
  color: var(--accent);
}

.avatar-bubble {
  width: 28px;
  height: 28px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border: 1px solid var(--accent-line);
}

.trend-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
}
.trend-pos { background: color-mix(in srgb, var(--pos) 12%, transparent); color: var(--pos); }
.trend-neg { background: color-mix(in srgb, var(--neg) 12%, transparent); color: var(--neg); }

/* The live URL sits opposite the tabs: the funnel is always one click away. */
.live-link {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: center;
  padding: 4px 9px;
  border-radius: var(--r-sm);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-2);
  text-decoration: none;
  border: 1px solid transparent;
  white-space: nowrap;
}
.live-link:hover { color: var(--text); background: var(--surface-2); border-color: var(--line); }

/* ---- Controls ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: all 0.14s var(--ease);
  box-shadow: var(--shadow-1);
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.btn-primary:hover {
  opacity: 0.94;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.22);
}
.btn-primary:active { transform: scale(0.98); }

.btn-ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }

.btn-danger { color: var(--neg); }
.btn-danger:hover { background: color-mix(in srgb, var(--neg) 10%, transparent); border-color: transparent; color: var(--neg); }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; gap: 5px; border-radius: 6px; }
.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }

.btn svg, .tab svg, .live-link svg { flex: 0 0 auto; }

.kbd {
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-3);
  line-height: 1.4;
}

.input, .textarea, .select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 7px 10px;
  font-size: 13px;
  transition: border-color 0.12s var(--ease), box-shadow 0.12s var(--ease);
}
.input:hover, .textarea:hover, .select:hover { border-color: var(--text-3); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.textarea { resize: vertical; min-height: 64px; line-height: 1.55; }
.select { appearance: none; cursor: pointer; padding-right: 26px; }

.select-wrap { position: relative; display: block; }
.select-wrap .select-caret {
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-3);
  display: flex;
}

.input-mono { font-family: var(--mono); font-size: 12px; }

.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search svg { position: absolute; left: 9px; color: var(--text-3); pointer-events: none; }
.search .input { padding-left: 30px; }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > label,
.field-label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 5px;
}
.field-hint { font-size: 11.5px; color: var(--text-3); margin-top: 5px; line-height: 1.45; }
.field-hint code {
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  color: var(--text-2);
}

/* An edited-but-unwritten document is worth one dot, not a banner. */
.btn.is-dirty::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 99px;
  background: currentColor;
  flex: 0 0 auto;
}

/* Switch — replaces the raw checkbox, which never matched anything else.
 *
 * The switch is a <label>, so inside a `.field` it is also matched by
 * `.field > label`, which is MORE specific and forced `display: block` on it.
 * That left `.switch-track` an inline <span> — width/height do not apply to an
 * inline box — so every toggle in the inspector and the modals rendered as a
 * 19px sliver instead of a 36×21 pill. Both halves below are the fix: re-assert
 * the flex container where `.field` clobbers it, and give the track its own
 * block box so it no longer depends on being a flex item to have a size. */
.switch { position: relative; display: inline-flex; flex: 0 0 auto; }
.field > label.switch { display: inline-flex; margin-bottom: 0; }
.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.switch-track {
  display: block;
  flex: 0 0 auto;
  width: 36px;
  height: 21px;
  border-radius: 99px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  transition: background 0.16s var(--ease), border-color 0.16s var(--ease);
  pointer-events: none;
}
.switch-track::after {
  content: "";
  display: block;
  width: 15px;
  height: 15px;
  margin: 2px;
  border-radius: 99px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
  transition: transform 0.16s var(--ease);
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(15px); background: var(--accent-ink); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Surfaces ------------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
}
.card-pad { padding: 18px; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  color: var(--text-2);
  white-space: nowrap;
}

.delta { font-size: 12px; font-weight: 600; }
.delta-pos { color: var(--pos); }
.delta-neg { color: var(--neg); }

/* ---- Workspace ----------------------------------------------------------- */
.workspace { min-height: calc(100vh - var(--bar-1) - var(--bar-2)); }
.view { display: none; }
.view.is-active { display: block; animation: rise 0.18s var(--ease); }
@keyframes rise {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

.view-pad { padding: 28px 32px 56px; max-width: 100%; margin-left: 0; margin-right: auto; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.page-title { font-size: 28px; font-weight: 600; letter-spacing: -0.025em; line-height: 1.15; }
.page-sub { color: var(--text-2); font-size: 13.5px; margin-top: 5px; }
.page-actions { display: flex; align-items: center; gap: 8px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 32px 0 12px;
}
.section-head:first-of-type { margin-top: 0; }

/* ---- Metric strip -------------------------------------------------------- */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px 20px;
  box-shadow: var(--shadow-1);
  transition: transform 0.14s var(--ease), box-shadow 0.14s var(--ease), border-color 0.14s var(--ease);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.metric:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
  border-color: var(--accent-line);
}
.metric-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.metric-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-soft);
}
.metric-value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-top: 10px;
  color: var(--text);
}
.metric-note {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 6px;
}

/* ---- Funnel cards -------------------------------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.funnel-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.14s var(--ease), box-shadow 0.14s var(--ease), transform 0.14s var(--ease);
  overflow: hidden;
}
.funnel-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
  opacity: 0.85;
  transition: opacity 0.14s var(--ease);
}
.funnel-card:hover {
  border-color: var(--accent-line);
  box-shadow: var(--shadow-2);
  transform: translateY(-2px);
}
.funnel-card:hover::before { opacity: 1; }
.funnel-card.is-current { border-color: var(--accent-line); box-shadow: var(--shadow-2); }

.funnel-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.funnel-card-title-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.funnel-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
  line-height: 1.25;
}
.funnel-slug {
  display: inline-flex;
  align-items: center;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-2);
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--line-soft);
  width: fit-content;
}

.funnel-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-2);
  padding: 6px 10px;
  background: var(--surface-2);
  border-radius: 6px;
  border: 1px solid var(--line-soft);
}
.funnel-stat b { font-weight: 600; color: var(--text); }
.stat-dot-sep { color: var(--text-3); font-size: 10px; }

.funnel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  padding-top: 4px;
}

/* ---- Capture feed & table ------------------------------------------------ */
.feed { display: flex; flex-direction: column; }
.feed-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 14px;
  padding: 11px 16px;
  border-top: 1px solid var(--line-soft);
  font-size: 13px;
}
.feed-row:first-child { border-top: 0; }
.feed-who { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-when { font-family: var(--mono); font-size: 11.5px; color: var(--text-3); }

.table-wrap { overflow-x: auto; border-radius: var(--r); }
.table { width: 100%; border-collapse: collapse; }
.table th {
  position: sticky;
  top: 0;
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-3);
  background: var(--surface-2);
  padding: 9px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
  vertical-align: middle;
}
.table tbody tr { cursor: pointer; transition: background 0.1s var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.cell-mono { font-family: var(--mono); font-size: 11.5px; color: var(--text-2); white-space: nowrap; }
.cell-answers {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-2);
  max-width: 380px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-2);
}
.empty-title { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-body { font-size: 13px; max-width: 380px; margin: 0 auto; line-height: 1.6; }
.empty-actions { margin-top: 16px; display: flex; gap: 8px; justify-content: center; }

/* ==========================================================================
   The spine — this app's signature.

   A funnel *is* an ordered sequence, so the numbers are load-bearing: they say
   which screen comes third, and the distance between 02 and 03 is a real
   quantity a marketer acts on. The same rail renders in the builder (to edit a
   step) and in analytics (to measure it), so the object you shaped is the
   object you're reading.
   ========================================================================== */
.spine { position: relative; padding: 4px 0; }
.spine::before {
  content: "";
  position: absolute;
  left: 25px;
  top: 14px;
  bottom: 14px;
  width: 1px;
  background: var(--line);
}
/* Nothing to connect when there are no steps to show. */
.spine:has(.empty)::before { display: none; }

.spine-row {
  position: relative;
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: start;
  gap: 10px;
  width: 100%;
  padding: 8px 10px 8px 10px;
  background: none;
  border: 0;
  border-radius: var(--r-sm);
  text-align: left;
  cursor: pointer;
  transition: background 0.12s var(--ease);
}
.spine-row:hover { background: var(--surface-2); }

.spine-index {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-left: 5px;
  border-radius: 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-3);
  transition: background 0.14s var(--ease), color 0.14s var(--ease), border-color 0.14s var(--ease);
}
.spine-row.is-active .spine-index {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.spine-row.is-active { background: var(--accent-soft); }

.spine-body { min-width: 0; }
.spine-title {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
.spine-meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.spine-type {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-3);
  text-transform: lowercase;
}
.branch {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  padding: 0 4px;
}

.spine-tools { display: flex; gap: 2px; opacity: 0; transition: opacity 0.12s var(--ease); }
.spine-row:hover .spine-tools,
.spine-row:focus-within .spine-tools { opacity: 1; }

/* Analytics variant: same rail, real numbers. */
.spine-measure .spine-row { cursor: default; grid-template-columns: 32px 200px 1fr auto; align-items: center; }
.spine-measure .spine-row:hover { background: none; }
.spine-track {
  display: block;
  height: 22px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
  min-width: 60px;
}
.spine-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.5s var(--ease);
}
.spine-figure {
  display: flex;
  align-items: baseline;
  gap: 10px;
  justify-content: flex-end;
  min-width: 132px;
}
.spine-count { font-size: 14px; font-weight: 600; }
.spine-drop { font-size: 11.5px; font-weight: 600; min-width: 52px; text-align: right; }

/* ---- Builder ------------------------------------------------------------- *
 * Five columns: steps | grip | canvas | grip | inspector.
 *
 * A collapsed pane is `display:none`, which takes it out of grid AUTO-placement
 * — so the remaining children slide one column to the left and the pane's own
 * column stays reserved. Collapsing the inspector left a 348px band of empty
 * background where every step control used to be, and collapsing the steps rail
 * dropped the canvas into the 6px grip column. Both are fixed the same way:
 * every child is placed EXPLICITLY, and a collapsed pane zeroes its own column
 * (and its grip) so the canvas actually takes the space back. */
.builder {
  display: grid;
  --col-left: var(--left-pane-width, 272px);
  --col-right: var(--right-pane-width, 348px);
  --col-grip-left: 6px;
  --col-grip-right: 6px;
  grid-template-columns:
    var(--col-left) var(--col-grip-left) minmax(0, 1fr) var(--col-grip-right) var(--col-right);
  height: calc(100vh - var(--bar-1) - var(--bar-2));
  position: relative;
}
.builder > .pane-left { grid-column: 1; }
.builder > .pane-resizer-left { grid-column: 2; }
.builder > .stage { grid-column: 3; }
.builder > .pane-resizer-right { grid-column: 4; }
.builder > .pane-right { grid-column: 5; }

.builder:has(> .pane-left.is-collapsed) { --col-left: 0px; --col-grip-left: 0px; }
.builder:has(> .pane-right.is-collapsed) { --col-right: 0px; --col-grip-right: 0px; }
.builder:has(> .pane-left.is-collapsed) > .pane-resizer-left,
.builder:has(> .pane-right.is-collapsed) > .pane-resizer-right { display: none; }

.pane-resizer {
  width: 6px;
  background: var(--line);
  cursor: col-resize;
  position: relative;
  z-index: 15;
  transition: background 0.15s var(--ease), box-shadow 0.15s var(--ease);
  user-select: none;
  flex: 0 0 6px;
}
.pane-resizer:hover,
.pane-resizer.is-resizing {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
.pane-resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 24px;
  background: var(--text-3);
  border-radius: 1px;
  opacity: 0.5;
}
.pane-resizer:hover::after,
.pane-resizer.is-resizing::after {
  background: #fff;
  opacity: 1;
}

.pane-left.is-collapsed,
.pane-right.is-collapsed {
  display: none !important;
}

/* The chevron sprite points down, which read as "collapse this section" on both
 * pane heads and gave no hint that the whole sidebar was about to disappear.
 * Aim each one at the edge its pane retreats to. */
.pane-toggle svg { transition: transform 0.18s var(--ease); }
.pane-toggle-left svg { transform: rotate(90deg); }
.pane-toggle-right svg { transform: rotate(-90deg); }

/* Reopen handles for a collapsed pane. Absolutely positioned so they claim no
 * grid column, and hidden until the pane they control is actually collapsed —
 * `.builder` is already `position: relative`. */
.pane-restore {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 64px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  box-shadow: var(--shadow-1, 0 2px 8px rgb(0 0 0 / 12%));
  transition: background 0.15s var(--ease), color 0.15s var(--ease), width 0.15s var(--ease);
}
.pane-restore:hover { background: var(--accent); color: #fff; width: 26px; }
.pane-restore:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.pane-restore-left { left: 0; border-left: 0; border-radius: 0 8px 8px 0; }
.pane-restore-right { right: 0; border-right: 0; border-radius: 8px 0 0 8px; }
.pane-restore-left svg { transform: rotate(-90deg); }
.pane-restore-right svg { transform: rotate(90deg); }

.builder:has(> .pane-left.is-collapsed) > .pane-restore-left,
.builder:has(> .pane-right.is-collapsed) > .pane-restore-right { display: flex; }

.pane { display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.pane-left { border-right: 1px solid var(--line); }
.pane-right { border-left: 1px solid var(--line); }

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 42px;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.pane-body { flex: 1; overflow-y: auto; padding: 8px; }
.pane-body-pad { padding: 16px; }
.pane-foot { flex: 0 0 auto; padding: 10px 12px; border-top: 1px solid var(--line); }

/* Canvas */
.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  background-image: radial-gradient(var(--line) 1px, transparent 1px);
  background-size: 22px 22px;
}
[data-theme="dark"] .stage { background-image: radial-gradient(var(--line-soft) 1px, transparent 1px); }

.stage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 42px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex: 0 0 auto;
}
.stage-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  min-height: 0;
}

.seg { display: inline-flex; padding: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); }
.seg button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 9px;
  border: 0;
  background: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.12s var(--ease), color 0.12s var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-1);
}

/* Device — a bezel, not a toy. No drawn notch, speaker grille, or camera lens;
   the point is the funnel inside it. */
.device {
  position: relative;
  /* Bezel geometry driven by data-chassis */
  --bezel: 14px;
  --screen-r: 40px;

  box-sizing: border-box;
  padding: var(--bezel);
  background: #0b0d10;
  border-radius: calc(var(--screen-r) + var(--bezel));
  box-shadow: var(--shadow-3), 0 24px 70px -16px color-mix(in srgb, var(--accent, #4f46e5) 30%, transparent), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  height: min(788px, calc(100vh - var(--bar-1) - var(--bar-2) - 150px));
  aspect-ratio: 390 / 844;
  transition: aspect-ratio 0.24s var(--ease), height 0.24s var(--ease), border-radius 0.24s var(--ease), box-shadow 0.3s ease;
}
.device-screen {
  width: 100%;
  height: 100%;
  border-radius: var(--screen-r);
  overflow: hidden;
  background: #fff;
}
.device-screen iframe { width: 100%; height: 100%; border: 0; display: block; }

/* On a dark stage the bezel would merge into the background, so give it an edge. */
[data-theme="dark"] .device {
  background: #05070a;
  box-shadow: var(--shadow-3), 0 24px 80px -16px color-mix(in srgb, var(--accent, #6366f1) 35%, transparent), inset 0 0 0 1px rgba(255, 255, 255, 0.14), 0 0 0 1px var(--line);
}

.device[data-chassis="tablet"] { --screen-r: 16px; --bezel: 12px; aspect-ratio: 834 / 1112; }
.device[data-chassis="desktop"] { --screen-r: 8px; --bezel: 10px; aspect-ratio: 16 / 10; height: min(620px, calc(100vh - var(--bar-1) - var(--bar-2) - 150px)); }

.device-label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  flex: 0 0 auto;
}

/* Inspector */
.inspector-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.inspector-section:last-child { border-bottom: 0; }
.inspector-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

/* Segmented Picker & Badge Chips */
.seg-picker {
  display: flex;
  gap: 3px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  width: 100%;
}
.seg-btn {
  flex: 1;
  padding: 6px 10px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  background: transparent;
  border: 0;
  border-radius: calc(var(--r-sm) - 2px);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.seg-btn:hover { color: var(--text-1); background: rgba(255,255,255,0.04); }
.seg-btn.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 4px rgba(0,0,0,0.12), 0 0 0 1px var(--line);
  font-weight: 700;
}

.badge-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}
.badge-chip {
  padding: 2px 7px;
  font-size: 10.5px;
  font-weight: 600;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s ease;
}
.badge-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

/* The landing layout picker has five options, so it wraps rather than squeezing
   each label to three illegible characters. */
.seg-wrap { flex-wrap: wrap; }
.seg-wrap .seg-btn { flex: 1 1 30%; }

/* Two stacked actions under the spine (add landing page / add question). */
.pane-foot-stack { display: flex; flex-direction: column; gap: 6px; }

/* Collapsible groups in the landing panel — it has far more options than fits
   on one screen, so everything past the hero and CTA starts folded. */
.ins-group {
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  margin-bottom: 8px;
}
.ins-group-head {
  padding: 9px 12px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-2);
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ins-group-head::-webkit-details-marker { display: none; }
.ins-group-head::after { content: "+"; font-size: 14px; color: var(--text-3); }
.ins-group[open] .ins-group-head::after { content: "−"; }
.ins-group[open] .ins-group-head { border-bottom: 1px solid var(--line-soft); color: var(--text-1); }
.ins-group-body { padding: 12px; }
.ins-group-body .field:last-child { margin-bottom: 0; }

/* Section (content block) cards + the palette that creates them. */
.block-card { padding-bottom: 4px; }
.block-card-type {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-2);
  letter-spacing: 0.01em;
}
.block-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.block-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  color: var(--text-2);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.block-chip:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.block-chip-glyph { font-size: 12px; opacity: 0.8; }

/* Repeatable rows: choice options, form fields. */
.repeat {
  position: relative;
  padding: 10px 10px 10px 12px;
  margin-bottom: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.repeat:hover {
  border-color: var(--line);
  box-shadow: 0 4px 12px rgba(0,0,0,0.04);
}
.repeat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.repeat-num { font-family: var(--mono); font-size: 10.5px; color: var(--text-3); }
.repeat-grid { display: grid; grid-template-columns: 1fr 62px; gap: 6px; }
.repeat .input { background: var(--surface); }
.repeat-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.repeat-check { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); cursor: pointer; }

.placeholder {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  line-height: 1.6;
}

/* ---- Settings ------------------------------------------------------------ */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.card-title { font-size: 14px; font-weight: 600; }
.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

/* ---- Templates ----------------------------------------------------------- */
/* Same left rule as a funnel card: a coloured rule always means "this is the
   document, and this is the colour a visitor will see". */
.tpl-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 18px 18px 21px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
  transition: border-color 0.14s var(--ease), box-shadow 0.14s var(--ease);
}
.tpl-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 14px;
  bottom: 14px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.tpl-card:hover { border-color: var(--text-3); box-shadow: var(--shadow-2); }
.tpl-name { font-size: 15px; font-weight: 600; letter-spacing: -0.015em; }
.tpl-body { font-size: 13px; color: var(--text-2); line-height: 1.55; flex: 1; }
.tpl-flow { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.tpl-step {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  padding: 1px 5px;
}
.tpl-arrow { color: var(--text-3); display: flex; }

/* ---- Overlays ------------------------------------------------------------ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 20px 20px;
  background: color-mix(in srgb, var(--bg) 62%, rgba(10, 12, 16, 0.55));
  backdrop-filter: blur(3px);
  animation: fade 0.14s var(--ease);
}
.overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 480px;
  max-height: 76vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  animation: pop 0.18s var(--ease);
  overflow: hidden;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(-6px) scale(0.99); }
  to { opacity: 1; transform: none; }
}
.modal-wide { max-width: 620px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  flex: 0 0 auto;
}
.modal-title { font-size: 14px; font-weight: 600; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line-soft);
  background: var(--surface-2);
  flex: 0 0 auto;
}

.code {
  width: 100%;
  height: 320px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.6;
  padding: 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  resize: none;
  white-space: pre;
  overflow: auto;
}

/* Command palette */
.palette { max-width: 540px; padding: 0; }
.palette-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.palette-input-row svg { color: var(--text-3); flex: 0 0 auto; }
.palette-input {
  flex: 1;
  border: 0;
  background: none;
  outline: none;
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
}
.palette-input::placeholder { color: var(--text-3); }
.palette-list { max-height: 360px; overflow-y: auto; padding: 8px 6px; }
.palette-group { padding: 4px 6px; }
.palette-group + .palette-group {
  border-top: 1px solid var(--line-soft);
  margin-top: 6px;
  padding-top: 8px;
}
.palette-header {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 6px 10px 4px;
  user-select: none;
}
.palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s var(--ease);
}
.palette-item svg { color: var(--text-2); flex: 0 0 auto; }
.palette-item .kbd { margin-left: auto; }
.palette-item:hover, .palette-item.is-selected { background: var(--surface-2); }
.palette-item.is-selected { box-shadow: inset 3px 0 0 var(--accent); }
.palette-empty { padding: 28px; text-align: center; color: var(--text-3); font-size: 13px; }

/* Drawer */
.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 180;
  background: rgba(10, 12, 16, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s var(--ease);
}
.drawer-scrim.is-open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 190;
  width: min(420px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-3);
  transform: translateX(100%);
  transition: transform 0.28s var(--ease);
}
.drawer.is-open { transform: none; }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  flex: 0 0 auto;
}
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; }
.drawer-foot { flex: 0 0 auto; padding: 12px 16px; border-top: 1px solid var(--line-soft); background: var(--surface-2); }

.kv { border-top: 1px solid var(--line-soft); padding: 12px 0; }
.kv:first-child { border-top: 0; padding-top: 0; }
.kv-key {
  font-size: 11px;
  font-weight: 600;
  font-stretch: 115%;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-3);
  margin-bottom: 5px;
}
.kv-val { font-size: 13.5px; line-height: 1.55; word-break: break-word; }
.kv-val pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  padding: 10px;
  color: var(--text-2);
}

/* Toasts — replace alert(), which stopped the world for a saved file. */
.toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-2);
  font-size: 13px;
  font-weight: 500;
  animation: toast-in 0.22s var(--ease);
  pointer-events: auto;
}
.toast svg { flex: 0 0 auto; }
.toast.is-error { background: var(--neg); color: #fff; }
.toast.is-leaving { animation: toast-out 0.18s var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

/* Category Pills */
.category-pills {
  display: flex;
  align-items: center;
  gap: 6px;
}
.cat-pill {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s var(--ease);
}
.cat-pill:hover {
  background: var(--surface-2);
  color: var(--text);
}
.cat-pill.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-line);
  font-weight: 600;
}

/* Answer Timeline for Lead Detail Drawer */
.answer-timeline {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}
.timeline-step {
  position: relative;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.timeline-step-num {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.timeline-step-q {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.timeline-step-a {
  font-size: 12.5px;
  color: var(--text-2);
  background: var(--surface);
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--line-soft);
  margin-top: 4px;
  font-weight: 500;
}

/* Visual Conversion Funnel Bars in Analytics */
.analytics-bar-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.analytics-bar-row:last-child { margin-bottom: 0; }
.analytics-bar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
}
.analytics-bar-title { font-weight: 600; color: var(--text); }
.analytics-bar-count { font-family: var(--mono); font-size: 11.5px; color: var(--text-2); }
.analytics-bar-track {
  height: 10px;
  background: var(--surface-3);
  border-radius: 99px;
  overflow: hidden;
  position: relative;
}
.analytics-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.4s var(--ease);
}

/* ---- Responsive ---------------------------------------------------------- */
@media (max-width: 1180px) {
  /* Narrow the rails by moving the WIDTH VARIABLES, never by re-declaring
   * `grid-template-columns`. This rule used to name three columns while every
   * child is explicitly placed into one of five, so columns 4 and 5 became
   * implicit: the 6px right grip inherited the `1fr` and the inspector was
   * pushed past the viewport edge — the customizer looked deleted on any
   * window under 1180px. Re-declaring the template here would bring that back. */
  .builder { --col-left: var(--left-pane-width, 240px); --col-right: var(--right-pane-width, 300px); }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(3) { border-left: 0; }
  .metric:nth-child(n + 3) { border-top: 1px solid var(--line-soft); }
}

@media (max-width: 900px) {
  .view-pad { padding: 22px 18px 48px; }
  /* True single-column stack. `grid-template-columns: 1fr` alone is not enough
   * any more: the children carry explicit `grid-column` values, so they ignore
   * auto-placement and spawn four implicit columns instead of stacking. Every
   * child has to be pulled back to column 1 by hand. */
  .builder {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - var(--bar-1) - var(--bar-2));
  }
  .builder > .pane-left,
  .builder > .stage,
  .builder > .pane-right { grid-column: 1; }
  /* Side-by-side affordances are meaningless once stacked — and a pane collapsed
   * on a wide screen must not stay hidden here, where nothing can reopen it. */
  /* `!important` is load-bearing: the reveal rule is `.builder:has(> .pane-right
   * .is-collapsed) > .pane-restore-right`, which outranks any plain selector
   * that could be written here — so without it a reopen handle floated over the
   * stacked layout pointing at a pane that is already on screen. */
  .builder > .pane-resizer,
  .builder > .pane-restore { display: none !important; }
  .pane-toggle { display: none; }
  .builder > .pane-left.is-collapsed,
  .builder > .pane-right.is-collapsed { display: flex !important; }
  .pane-left, .pane-right { border: 0; border-bottom: 1px solid var(--line); }
  /* The canvas toolbar is a fixed-height, no-wrap row, so on a narrow window its
   * buttons ran off the edge and took the whole page into horizontal scroll.
   * Let it grow a second line instead. */
  .stage-bar { height: auto; min-height: 42px; flex-wrap: wrap; padding: 7px 14px; row-gap: 8px; }
  .stage-bar .page-actions { flex-wrap: wrap; }
  .pane-body { max-height: 320px; }
  .stage { border-bottom: 1px solid var(--line); }
  .device { height: 560px; }
  .spine-measure .spine-row { grid-template-columns: 32px 1fr; row-gap: 6px; }
  .spine-measure .spine-track { grid-column: 1 / -1; }
  .spine-measure .spine-figure { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 640px) {
  .app-bar { gap: 10px; padding: 0 12px; }
  .brand-name, .bar-divider { display: none; }
  .switcher select { max-width: 150px; }
  .page-head { align-items: flex-start; }
  .metrics { grid-template-columns: 1fr; }
  .metric { border-left: 0; }
  .metric:nth-child(n + 2) { border-top: 1px solid var(--line-soft); }
  .overlay { padding: 8vh 12px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  .app-bar, .tab-bar, .page-actions, .toasts { display: none; }
}

/* ---- Drag & Drop Spine & Options ---------------------------------------- */
.spine-row[draggable="true"],
.option-edit-card[draggable="true"],
.block-card[draggable="true"],
.block-chip[draggable="true"] {
  cursor: grab;
}
.spine-row[draggable="true"]:active,
.option-edit-card[draggable="true"]:active,
.block-card[draggable="true"]:active,
.block-chip[draggable="true"]:active {
  cursor: grabbing;
}

.drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: var(--text-3);
  cursor: grab;
  flex: 0 0 auto;
  opacity: 0.6;
  transition: opacity 0.12s var(--ease);
}
.spine-row:hover .drag-handle,
.option-edit-card:hover .drag-handle,
.block-card:hover .drag-handle {
  opacity: 1;
}

/* ---- Inspector Tabs & Clean Drag UI --------------------------------------- */
.inspector-tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  padding: 3px;
  border-radius: var(--r-md);
  margin-bottom: 12px;
  border: 1px solid var(--line);
}

.ins-tab {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  cursor: pointer;
  text-align: center;
  transition: all 0.12s var(--ease);
  white-space: nowrap;
}
.ins-tab:hover {
  color: var(--text);
  background: var(--surface-hover);
}
.ins-tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.drag-handle-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 2px 7px;
  border-radius: 999px;
  cursor: grab;
  user-select: none;
  transition: all 0.12s var(--ease);
}
.drag-handle-pill:hover,
.spine-row:hover .drag-handle-pill,
.option-edit-card:hover .drag-handle-pill,
.block-card:hover .drag-handle-pill {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.block-drop-hint {
  font-size: 11.5px;
  color: var(--text-2);
  background: var(--accent-soft);
  border: 1px dashed var(--accent-line);
  padding: 8px 12px;
  border-radius: var(--r-sm);
  margin-bottom: 12px;
  line-height: 1.4;
}

.spine-row.is-dragging,
.option-edit-card.is-dragging,
.block-card.is-dragging,
.block-chip.is-dragging {
  opacity: 0.45 !important;
  transform: scale(0.98);
  border: 1px dashed var(--accent) !important;
  box-shadow: 0 8px 20px rgba(0,0,0,0.15) !important;
  background: var(--surface-2) !important;
}

/* Drag drop insertion indicators */
.spine-row,
.option-edit-card,
.block-card {
  position: relative;
  transition: transform 0.12s var(--ease), border-color 0.12s var(--ease);
}

.spine-row.drop-before::before,
.option-edit-card.drop-before::before,
.block-card.drop-before::before {
  content: "";
  position: absolute;
  top: -4px;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--accent);
  border-radius: 4px;
  box-shadow: 0 0 10px var(--accent);
  z-index: 20;
}

.spine-row.drop-after::after,
.option-edit-card.drop-after::after,
.block-card.drop-after::after {
  content: "";
  position: absolute;
  bottom: -4px;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--accent);
  border-radius: 4px;
  box-shadow: 0 0 10px var(--accent);
  z-index: 20;
}

/* Alignment Controls UI */
.align-picker {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 2px;
  gap: 2px;
  margin-top: 4px;
}
.align-btn {
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 3px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.12s var(--ease);
}
.align-btn:hover {
  color: var(--text);
  background: var(--surface-hover);
}
.align-btn.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.block-card-type {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ---- Badge & Token Chips ------------------------------------------------ */
.badge-chips,
.token-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.badge-chip,
.token-chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 500;
  padding: 3px 7px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.12s var(--ease);
}
.badge-chip:hover,
.token-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.token-chip {
  font-family: var(--font-mono);
  font-size: 10.5px;
}

/* ---- Step Archetypes Modal ------------------------------------------------ */
.archetype-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (max-width: 600px) {
  .archetype-grid {
    grid-template-columns: 1fr;
  }
}

.archetype-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.archetype-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.archetype-icon {
  font-size: 22px;
  line-height: 1;
  flex: 0 0 auto;
  margin-top: 2px;
}

.archetype-info {
  flex: 1;
  min-width: 0;
}

.archetype-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.archetype-desc {
  font-size: 11.5px;
  color: var(--text-2);
  line-height: 1.35;
}

/* ---- Spine Enhancements --------------------------------------------------- */
.spine-type-badge {
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-3);
  margin-left: auto;
}
.spine-row:hover .spine-type-badge {
  color: var(--text-2);
}
.spine-dup-btn {
  opacity: 0;
  transition: opacity 0.12s var(--ease);
}
.spine-row:hover .spine-dup-btn {
  opacity: 1;
}

/* ---- Symbol & Icon Picker Modal ------------------------------------------ */
.symbol-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
  padding: 4px;
}

.symbol-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 22px;
  cursor: pointer;
  transition: transform 0.12s var(--ease), border-color 0.12s var(--ease), background 0.12s var(--ease);
}
.symbol-btn:hover {
  transform: scale(1.15);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.symbol-btn.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px var(--accent-line);
}


