/* Conv Builder — hell, HoPla-Builder-orientiert (Header + horizontale Nav + Liste links) */

:root {
  --cb-head-h: 56px;
  --cb-nav-h: 48px;
  --cb-sidebar-w: minmax(240px, 300px);
  --cb-preview-w: minmax(300px, 420px);
  --cb-border: var(--c-border, #e5e5e5);
  --cb-surface: #fff;
  --cb-surface-muted: #fafafa;
  --cb-text: #111;
  --cb-text-muted: #666;
  --cb-accent: var(--journey-accent, #0aa37f);
}

.conv-builder-body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f6f6f6 0%, #fff 32%);
  color: var(--cb-text);
}

.conv-builder-body:has(#app-shell:not(.hidden)) {
  height: 100vh;
  overflow: hidden;
}

.hidden,
.cb-login-error.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* ——— Login ——— */
.cb-login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #f5f5f5 0%, #fff 100%);
}

.cb-login-card {
  width: 100%;
  max-width: 420px;
  background: var(--cb-surface);
  padding: 40px 44px;
  border-radius: var(--radius, 14px);
  box-shadow: 0 4px 28px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--cb-border);
}

.cb-login-head {
  text-align: center;
  margin-bottom: 28px;
}

.cb-login-head h1 {
  margin: 0 0 8px;
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--cb-text);
}

.cb-login-head p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--cb-text-muted);
}

.cb-login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cb-login-form label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #333;
}

.cb-login-form input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--cb-border);
  border-radius: var(--radius, 12px);
  font: inherit;
  font-size: 0.95rem;
  background: #fff;
  box-sizing: border-box;
}

.cb-login-form input:focus {
  outline: none;
  border-color: #000;
}

.cb-login-error {
  padding: 10px 12px;
  background: #fff0f0;
  border: 1px solid #fcc;
  border-radius: var(--radius, 10px);
  color: #b00;
  font-size: 0.9rem;
  text-align: center;
}

.cb-login-foot {
  margin: 20px 0 0;
  text-align: center;
}

.cb-login-foot small {
  color: #999;
  font-size: 0.8rem;
}

/* ——— Dialog (Neuer Flow / Sequence) ——— */
.cb-dialog {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.cb-dialog.hidden {
  display: none !important;
}

.cb-dialog__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.cb-dialog__card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: var(--cb-surface);
  border: 1px solid var(--cb-border);
  border-radius: var(--radius, 14px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  padding: 24px 26px;
}

.cb-dialog__title {
  margin: 0 0 18px;
  font-size: 1.2rem;
  font-weight: 700;
}

.cb-dialog__form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cb-dialog__form label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #333;
}

.cb-dialog__input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--cb-border);
  border-radius: 10px;
  font: inherit;
  font-size: 0.95rem;
  box-sizing: border-box;
}

.cb-dialog__input:focus {
  outline: none;
  border-color: #000;
}

.cb-dialog__hint {
  margin: -4px 0 6px;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--cb-text-muted);
}

.cb-dialog__hint code {
  font-size: 0.76rem;
}

.cb-dialog__error {
  padding: 10px 12px;
  background: #fff0f0;
  border: 1px solid #fcc;
  border-radius: 10px;
  color: #b00;
  font-size: 0.88rem;
}

.cb-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

/* ——— Buttons ——— */
.cb-btn {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.cb-btn--sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.cb-btn--primary {
  background: var(--btn-bg, #000);
  color: var(--btn-fg, #fff);
}

.cb-btn--primary:hover {
  opacity: 0.88;
}

.cb-btn--ghost {
  background: transparent;
  color: var(--cb-text-muted);
  border-color: var(--cb-border);
}

.cb-btn--ghost:hover {
  color: var(--cb-text);
  border-color: #ccc;
  background: #f5f5f5;
}

.cb-btn--danger {
  background: #fff;
  color: #a00;
  border-color: #eaa;
}

.cb-btn--danger:hover {
  background: #fff5f5;
}

/* ——— App shell ——— */
.cb-app {
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--cb-surface-muted);
}

.cb-header {
  flex-shrink: 0;
  height: var(--cb-head-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: var(--cb-surface);
  border-bottom: 1px solid var(--cb-border);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
}

.cb-header__brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cb-header__brand strong {
  font-size: 1.05rem;
}

.cb-header__tag {
  font-size: 0.78rem;
  color: var(--cb-text-muted);
}

/* Horizontale Bereichswahl (wie HoPla builder-nav) */
.cb-topnav {
  flex-shrink: 0;
  height: var(--cb-nav-h);
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0 12px;
  background: var(--cb-surface);
  border-bottom: 1px solid var(--cb-border);
}

.cb-topnav__btn {
  display: flex;
  align-items: center;
  padding: 0 18px;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 0.9rem;
  color: var(--cb-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.cb-topnav__btn:hover {
  color: var(--cb-text);
  background: #f7f7f7;
}

.cb-topnav__btn.active {
  color: var(--cb-text);
  font-weight: 600;
  border-bottom-color: #000;
}

/* 3-Spalten: Liste | Editor | Preview */
.cb-workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--cb-sidebar-w) 1fr var(--cb-preview-w);
  gap: 0;
}

.cb-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--cb-surface-muted);
  border-right: 1px solid var(--cb-border);
}

.cb-pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
}

.cb-pane.hidden {
  display: none;
}

.cb-pane__toolbar {
  flex-shrink: 0;
}

.cb-pane__toolbar--stack .cb-upload {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cb-pane__head {
  font-weight: 700;
  font-size: 0.9rem;
}

.cb-pane__hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--cb-text-muted);
  line-height: 1.4;
}

.cb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--cb-surface);
  border: 1px solid var(--cb-border);
  border-radius: 10px;
}

.cb-list li {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid #eee;
  font-size: 0.88rem;
}

.cb-list li:last-child {
  border-bottom: none;
}

.cb-list li:hover {
  background: #f7f7f7;
}

.cb-list li.active {
  background: rgba(10, 163, 127, 0.1);
  box-shadow: inset 3px 0 0 0 var(--cb-accent);
}

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

.cb-editor__sheet {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 10px;
}

.cb-editor__sheet.hidden {
  display: none;
}

.cb-editor__empty {
  margin: 0;
  color: var(--cb-text-muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

#flow-json {
  flex: 1;
  min-height: 200px;
  resize: none;
  font-family: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.45;
  padding: 12px;
  border: 1px solid var(--cb-border);
  border-radius: 10px;
  background: #fff;
  color: #1a1a1a;
}

/* —— Sequence Builder (grafisch) —— */
.seq-builder {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.seq-builder--idle .seq-builder__grid {
  opacity: 0.55;
  pointer-events: none;
}

.seq-builder__meta {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px 16px;
  align-items: end;
}

@media (max-width: 800px) {
  .seq-builder__meta {
    grid-template-columns: 1fr;
  }
}

.seq-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.seq-field__label,
.seq-field > label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--cb-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.seq-field--id {
  align-items: flex-start;
}

.seq-input,
.seq-textarea {
  font: inherit;
  font-size: 0.9rem;
  padding: 8px 10px;
  border: 1px solid var(--cb-border);
  border-radius: 8px;
  background: #fff;
  color: #1a1a1a;
}

.seq-textarea {
  resize: vertical;
  min-height: 80px;
}

.seq-id-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 6px 10px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.82rem;
  background: #f0f4f2;
  border-radius: 8px;
  border: 1px solid var(--cb-border);
}

.seq-builder__grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(200px, 280px) 1fr;
  gap: 14px;
}

@media (max-width: 900px) {
  .seq-builder__grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
}

.seq-builder__rail {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: hidden;
  padding: 12px;
  background: linear-gradient(165deg, #fafcfb 0%, #f3f6f4 100%);
  border: 1px solid var(--cb-border);
  border-radius: 12px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.seq-rail__hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--cb-text-muted);
  line-height: 1.45;
}

.seq-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.seq-step {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #e2e8e4;
  background: #fff;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.seq-step:hover {
  border-color: var(--cb-accent);
}

.seq-step--active {
  border-color: var(--cb-accent);
  box-shadow: 0 0 0 1px var(--cb-accent);
}

.seq-step__badge {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--cb-accent);
}

.seq-step__txt {
  font-size: 0.82rem;
  color: #333;
  line-height: 1.35;
  word-break: break-word;
}

.seq-builder__add {
  padding-top: 8px;
  border-top: 1px dashed var(--cb-border);
}

.seq-builder__add-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--cb-text-muted);
  margin-bottom: 8px;
}

.seq-builder__add-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.seq-builder__add-btns--grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 8px;
}

.seq-builder__add-btns--grid .cb-btn {
  justify-self: stretch;
  text-align: center;
}

.seq-step-panel {
  min-height: 0;
  padding: 14px 16px;
  border: 1px solid var(--cb-border);
  border-radius: 12px;
  background: #fff;
  overflow-y: auto;
}

.seq-panel__head h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.seq-panel__sub {
  margin: 0 0 14px;
  font-size: 0.82rem;
  color: var(--cb-text-muted);
  line-height: 1.45;
}

.seq-panel__sub code {
  font-size: 0.78rem;
}

.seq-panel__empty {
  margin: 0;
  color: var(--cb-text-muted);
  font-size: 0.9rem;
}

.seq-panel__rowact {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid #eee;
}

.seq-field--row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.seq-field--row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.seq-field--row4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

@media (max-width: 900px) {
  .seq-field--row4 {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 700px) {
  .seq-field--row2 {
    grid-template-columns: 1fr;
  }
}

.seq-field--check label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.seq-textarea--code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  line-height: 1.4;
}

.seq-optrow {
  display: grid;
  grid-template-columns: 1fr 100px auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
  padding: 10px;
  background: #fafafa;
  border-radius: 8px;
  border: 1px solid #eee;
}

@media (max-width: 700px) {
  .seq-field--row {
    grid-template-columns: 1fr;
  }
}

.seq-btnrow {
  display: grid;
  grid-template-columns: 1fr 120px 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  margin-bottom: 10px;
  background: #fafafa;
  border-radius: 10px;
  border: 1px solid #eee;
}

@media (max-width: 900px) {
  .seq-btnrow {
    grid-template-columns: 1fr 1fr;
  }

  .seq-btnrow .sf-b-remove {
    grid-column: 1 / -1;
    justify-self: start;
  }
}

.seq-json-details {
  flex-shrink: 0;
  border: 1px solid var(--cb-border);
  border-radius: 10px;
  padding: 8px 12px;
  background: #fafafa;
}

.seq-json-details summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--cb-text-muted);
}

.seq-json-details[open] summary {
  margin-bottom: 8px;
}

#seq-json {
  width: 100%;
  min-height: 140px;
  max-height: 36vh;
  resize: vertical;
  font-family: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.45;
  padding: 12px;
  border: 1px solid var(--cb-border);
  border-radius: 8px;
  background: #fff;
  color: #1a1a1a;
  box-sizing: border-box;
}

.cb-editor__actions {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.cb-save-status {
  font-size: 0.85rem;
  color: var(--cb-text-muted);
}

.cb-save-status--ok {
  color: var(--cb-accent);
}

.cb-save-status--err {
  color: #a00;
}

.cb-analytics {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 12px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.45;
  background: #fafafa;
  border: 1px solid var(--cb-border);
  border-radius: 10px;
}

.cb-preview {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: #ececec;
}

.cb-preview__bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--cb-surface);
  border-bottom: 1px solid var(--cb-border);
  font-size: 0.88rem;
  font-weight: 600;
}

.cb-preview__bar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.cb-preview__device-switch {
  display: inline-flex;
  border: 1px solid var(--cb-border);
  border-radius: 8px;
  overflow: hidden;
}

.cb-preview-device-btn {
  padding: 5px 10px;
  border: none;
  background: #fff;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--cb-text-muted);
}

.cb-preview-device-btn + .cb-preview-device-btn {
  border-left: 1px solid var(--cb-border);
}

.cb-preview-device-btn.is-active {
  background: #111;
  color: #fff;
}

.cb-preview__viewport {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
}

.cb-preview__viewport > .preview-viewport-root {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: linear-gradient(165deg, #e6e9f0 0%, #dce1ea 48%, #d5dae6 100%);
}

.preview-viewport-scaler {
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
}

.preview-viewport--mobile .preview-viewport-device {
  box-sizing: border-box;
  width: 410px;
  height: 864px;
  padding: 10px;
  background: #1c1c1e;
  border-radius: 40px;
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.06) inset,
    0 24px 56px rgba(0, 0, 0, 0.22);
}

.preview-viewport--mobile .cb-preview-iframe {
  display: block;
  width: 390px;
  height: 844px;
  border: none;
  border-radius: 28px;
  background: #fff;
}

.preview-viewport--desktop.preview-viewport-root {
  position: relative;
  align-items: stretch;
  justify-content: stretch;
}

.preview-viewport--desktop .preview-viewport-scaler {
  position: absolute;
  inset: 0;
  width: auto !important;
  height: auto !important;
}

.preview-viewport--desktop .preview-viewport-device {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  padding: 0 !important;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  transform: none !important;
}

.preview-viewport--desktop .cb-preview-iframe {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  background: #fff;
}

.seq-json-details textarea {
  max-height: 28vh;
  overflow: auto;
}

@media (max-width: 1100px) {
  .cb-workspace {
    grid-template-columns: 220px 1fr 300px;
  }
}

@media (max-width: 900px) {
  .cb-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr 280px;
  }

  .cb-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--cb-border);
    max-height: 280px;
  }

  .cb-editor {
    border-right: none;
    min-height: 360px;
  }
}
