@use '../variables' as v;
@use '../mixins' as m;

// ── Automation funnel builder ─────────────────────────────────────────

.af-main {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

// ── Top bar ──

.af-topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid v.$border-color;
  background: #fff;
  gap: 12px;
  z-index: 10;
}

.af-topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.af-topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.af-breadcrumb-link {
  font-size: 13px;
  font-weight: 600;
  color: v.$gray-700;
  text-decoration: none;
  &:hover { color: v.$info; }
}

.af-breadcrumb-sep {
  color: v.$gray-400;
  font-size: 13px;
}

.af-funnel-name {
  font-size: 14px;
  font-weight: 600;
  color: v.$gray-900;
}

.af-draft-badge {
  font-size: 12px;
  font-weight: 700;
  color: #dc2626;
  padding: 1px 0;
}

.af-name-input {
  font-size: 14px;
  font-weight: 600;
  color: v.$gray-900;
  border: 1px solid v.$info;
  border-radius: 4px;
  padding: 2px 8px;
  outline: none;
  font-family: inherit;
}

.af-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid v.$border-color;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  color: v.$gray-500;
  transition: background .12s, color .12s;

  svg { width: 15px; height: 15px; }
  &:hover { background: v.$gray-50; color: v.$gray-800; }
}

.af-flag-btn { border-color: transparent; background: none; }

// ── Toggle switches ──

.af-toggle-group,
.af-status-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.af-toggle-label {
  font-size: 12px;
  color: v.$gray-600;
  font-weight: 500;
}

.af-toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  cursor: pointer;

  input { display: none; }
}

.af-toggle-thumb {
  position: absolute;
  inset: 0;
  background: v.$gray-200;
  border-radius: 10px;
  transition: background .2s;

  &::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    top: 2px;
    left: 2px;
    transition: transform .2s;
    box-shadow: 0 1px 3px rgba(0,0,0,.15);
  }
}

.af-toggle-switch input:checked + .af-toggle-thumb {
  background: v.$info;
  &::after { transform: translateX(16px); }
}

// ── Workspace ──

.af-workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

// ── Canvas ──

.af-canvas {
  flex: 1;
  min-width: 0;
  overflow: auto;
  background-color: #f5f6f8;
  background-image: radial-gradient(circle, #d1d5db 1px, transparent 1px);
  background-size: 22px 22px;
  padding: 40px 60px 80px;
  @include m.scrollbar-thin;
}

.af-flow {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 700px;
}

// ── Connector (vertical line + add button) ──

.af-connector {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.af-connector-line {
  width: 2px;
  height: 24px;
  background: v.$gray-400;
}

.af-add-circle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid v.$gray-500;
  background: #fff;
  cursor: pointer;
  font-size: 18px;
  font-weight: 300;
  line-height: 1;
  color: v.$gray-600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, color .15s, background .15s;
  position: relative;
  z-index: 2;

  &:hover {
    border-color: v.$info;
    color: v.$info;
    background: v.$info-light;
  }
}

// ── Flow nodes ──

.af-node {
  position: relative;
  width: 280px;
  padding: 16px 20px;
  border-radius: 8px;
  border: 1.5px solid transparent;
  cursor: pointer;
  text-align: center;
  transition: box-shadow .15s, border-color .15s;

  &:hover { box-shadow: 0 4px 14px rgba(0,0,0,.1); }

  &.is-selected {
    border-color: v.$info !important;
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
  }

  // Trigger
  &--trigger {
    background: #fef9c3;
    border-color: #f5e05a;
  }

  // Condition
  &--condition {
    background: #fee2e2;
    border-color: #fca5a5;
  }

  // Tag action
  &--tag {
    background: #ede9fe;
    border-color: #c4b5fd;
    text-align: left;
    width: 100%;
    border-radius: 6px;
  }

  // Email action
  &--email {
    background: #ccfbf1;
    border-color: #5eead4;
    text-align: left;
    width: 100%;
    border-radius: 6px;
  }

  // Wait
  &--wait {
    background: #fff;
    border-color: v.$border-color;
    text-align: left;
    width: 100%;
    border-radius: 6px;
  }

  // End funnel
  &--end {
    background: #fef3c7;
    border-color: #fcd34d;
    text-align: center;
    width: 100%;
    border-radius: 6px;
  }
}

.af-node-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin: 0 auto 6px;
  color: v.$gray-500;

  svg { width: 18px; height: 18px; }

  &--wait { color: v.$gray-400; }
}

.af-node--tag .af-node-icon,
.af-node--email .af-node-icon,
.af-node--wait .af-node-icon {
  margin: 0 auto 4px;
}

.af-node-title {
  font-size: 13px;
  font-weight: 700;
  color: v.$gray-900;
  line-height: 1.3;
  margin-bottom: 3px;
}

.af-node-sub {
  font-size: 11px;
  color: v.$gray-500;
  line-height: 1.3;
}

.af-node-collapse {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 2px;

  button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: 1px solid #fca5a5;
    border-radius: 3px;
    background: #fff;
    cursor: pointer;
    font-size: 10px;
    color: v.$gray-500;
    &:hover { background: v.$gray-50; }
  }
}

// ── Branch layout ──

.af-branch-root {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.af-branch-hline {
  width: 60%;
  height: 2px;
  background: v.$gray-400;
  position: relative;
  margin-top: 0;
}

.af-branch-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  width: 100%;
  max-width: 800px;
}

.af-branch-col {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.af-branch-vline-top {
  width: 2px;
  height: 20px;
  background: v.$gray-400;
}

.af-branch-vline {
  width: 2px;
  height: 16px;
  background: v.$gray-400;
}

.af-branch-pill {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  z-index: 2;

  &--no {
    border: 2px solid #f87171;
    color: #ef4444;
    background: #fff;
  }

  &--yes {
    border: 2px solid v.$gray-700;
    color: v.$gray-800;
    background: #fff;
  }
}

.af-branch-box {
  width: 100%;
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;

  &--no {
    border: 1.5px solid #fca5a5;
    background: rgba(255,241,242,.3);
  }

  &--yes {
    border: 1.5px solid v.$gray-700;
    background: rgba(249,250,251,.5);
  }
}

.af-branch-inner-line {
  width: 2px;
  height: 14px;
  background: v.$gray-300;
  flex-shrink: 0;
}

// ── Add Action button (in branches) ──

.af-add-action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 10px 16px;
  border: 1.5px dashed v.$border-color;
  border-radius: 6px;
  background: rgba(255,255,255,.7);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: v.$info;
  justify-content: center;
  transition: background .12s, border-color .12s;

  svg { width: 12px; height: 12px; }

  &:hover {
    background: v.$info-light;
    border-color: v.$info;
  }
}

// ── Right panel ──

.af-panel {
  width: 400px;
  flex-shrink: 0;
  border-left: 1px solid v.$border-color;
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.af-panel-content {
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.af-panel-hdr {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid v.$border-color;
  flex-shrink: 0;
}

.af-panel-title {
  font-size: 14px;
  font-weight: 700;
  color: v.$gray-900;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  line-height: 1.3;
}

.af-panel-badge {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;

  &--trigger { background: #ede9fe; color: #7c3aed; }
  &--action  { background: #dbeafe; color: v.$info; }
  &--condition { background: #fee2e2; color: #dc2626; }
}

.af-panel-desc {
  font-size: 12px;
  color: v.$gray-500;
  margin-top: 4px;
  line-height: 1.4;
}

.af-panel-close {
  flex-shrink: 0;
  font-size: 18px;
  line-height: 1;
  color: v.$gray-400;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 2px;
  &:hover { color: v.$gray-700; }
}

.af-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  @include m.scrollbar-thin;
}

.af-panel-footer {
  flex-shrink: 0;
  padding: 12px 18px;
  border-top: 1px solid v.$border-color;
  display: flex;
  align-items: center;
  gap: 10px;
  background: v.$gray-50;
}

// ── Panel form elements ──

.af-form-group { display: flex; flex-direction: column; gap: 5px; }

.af-form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.af-label {
  font-size: 12px;
  font-weight: 600;
  color: v.$gray-600;
}

.af-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid v.$border-color;
  border-radius: v.$radius;
  font-size: 13px;
  color: v.$gray-800;
  font-family: inherit;
  outline: none;
  @include m.focus-ring;
}

.af-textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid v.$border-color;
  border-radius: v.$radius;
  font-size: 13px;
  color: v.$gray-800;
  font-family: inherit;
  outline: none;
  resize: vertical;
  @include m.focus-ring;
}

.af-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid v.$border-color;
  border-radius: v.$radius;
  font-size: 13px;
  color: v.$gray-800;
  font-family: inherit;
  outline: none;
  background: #fff;
  @include m.focus-ring;
}

.af-settings-card {
  border: 1px solid v.$border-color;
  border-radius: v.$radius-md;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.af-settings-card-title {
  font-size: 12px;
  font-weight: 700;
  color: v.$gray-700;
  margin-bottom: 2px;
}

.af-checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: v.$gray-700;
  cursor: pointer;

  input { margin-top: 2px; flex-shrink: 0; }
}

.af-radio-group { display: flex; flex-direction: column; gap: 8px; }

.af-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.af-radio-label {
  font-size: 13px;
  color: v.$gray-700;
  &--active { color: v.$info; font-weight: 600; }
}

.af-condition-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;

  .af-select { flex: 1; min-width: 80px; }
  .af-input  { flex: 0 0 80px; }
}

.af-add-condition-btn {
  font-size: 12px;
  color: v.$info;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-weight: 600;
  text-align: left;
  &:hover { text-decoration: underline; }
}

.af-delete-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid #fee2e2;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  color: #ef4444;
  margin-left: auto;
  &:hover { background: #fee2e2; }
}

// ── Tag selector ──

.af-tag-selector {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.af-tag-selected {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 8px;
  border: 1px solid v.$border-color;
  border-radius: v.$radius;
  min-height: 38px;
  align-items: center;
}

.af-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: v.$gray-200;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  color: v.$gray-700;

  button {
    background: none;
    border: none;
    cursor: pointer;
    color: v.$gray-500;
    font-size: 12px;
    padding: 0;
    line-height: 1;
  }
}

.af-tag-input {
  border: none;
  outline: none;
  font-size: 12px;
  color: v.$gray-700;
  flex: 1;
  min-width: 80px;
  font-family: inherit;
}

.af-tag-add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  border: 1px solid v.$border-color;
  border-radius: v.$radius;
  background: v.$gray-600;
  color: #fff;
  font-size: 20px;
  font-weight: 300;
  cursor: pointer;
  &:hover { background: v.$gray-800; }
}

// ── Add Action panel (block picker) ──

.af-add-search-wrap {
  padding: 12px 18px;
  border-bottom: 1px solid v.$border-color;
  flex-shrink: 0;
}

.af-add-search {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid v.$border-color;
  border-radius: v.$radius;
  font-size: 13px;
  color: v.$gray-700;
  font-family: inherit;
  outline: none;
  @include m.focus-ring;
}

.af-add-tabs {
  display: flex;
  border-bottom: 2px solid v.$border-color;
  flex-shrink: 0;
}

.af-add-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 10px 8px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: v.$gray-500;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .12s;

  svg { width: 13px; height: 13px; }

  &:hover { color: v.$gray-800; }

  &.is-active {
    color: v.$info;
    border-bottom-color: v.$info;
    font-weight: 600;
  }
}

.af-add-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  @include m.scrollbar-thin;
}

.af-add-section-label {
  font-size: 14px;
  font-weight: 700;
  color: v.$gray-900;
  margin-bottom: 6px;
}

.af-add-section-desc {
  font-size: 12px;
  color: v.$gray-500;
  line-height: 1.4;
  margin-bottom: 16px;
}

.af-add-group-label {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: v.$gray-600;
  border: 1px solid v.$border-color;
  border-radius: 4px;
  padding: 2px 8px;
  margin-bottom: 12px;
}

.af-block-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
  padding: 14px;
  border: 1px solid v.$border-color;
  border-radius: 8px;

  &--dark {
    background: v.$gray-700;
    border-color: v.$gray-700;
  }
}

.af-block-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 16px 12px;
  border: 1.5px solid v.$border-color;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s;

  &:hover {
    border-color: v.$info;
    box-shadow: 0 2px 8px rgba(37,99,235,.1);
  }

  &--active {
    border-color: v.$info;
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
  }

  &--goal {
    background: #fef9c3;
    border-color: #f5e05a;
    &:hover { border-color: #d97706; }
  }

  &--cond {
    background: #fee2e2;
    border-color: #fca5a5;
    &:hover { border-color: #dc2626; }
  }

  &--white {
    background: #fff;
  }
}

.af-block-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: v.$gray-100;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  color: v.$gray-600;

  svg { width: 16px; height: 16px; }
}

.af-block-name {
  font-size: 13px;
  font-weight: 700;
  color: v.$gray-900;
  margin-bottom: 5px;
  line-height: 1.2;
}

.af-block-desc {
  font-size: 11px;
  color: v.$gray-500;
  line-height: 1.4;
}

// ── Add step popup (floating) ──

.af-add-popup {
  position: fixed;
  z-index: 9999;
  background: #fff;
  border: 1px solid v.$border-color;
  border-radius: v.$radius-md;
  box-shadow: v.$shadow;
  padding: 6px;
  min-width: 280px;
}

.af-add-popup-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: v.$radius;
  background: none;
  cursor: pointer;
  text-align: left;
  transition: background .1s;

  &:hover { background: v.$gray-50; }
}

.af-add-popup-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: v.$gray-100;
  display: flex;
  align-items: center;
  justify-content: center;
  color: v.$gray-600;

  svg { width: 15px; height: 15px; }
}

.af-add-popup-title {
  font-size: 13px;
  font-weight: 700;
  color: v.$gray-900;
  margin-bottom: 2px;
}

.af-add-popup-desc {
  font-size: 11px;
  color: v.$gray-500;
  line-height: 1.4;
}

// ── Automation list page: create funnel modal ──

.af-template-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  padding: 4px 0;

  @include m.max-md { grid-template-columns: repeat(2, 1fr); }
}

.af-template-card {
  border: 1.5px solid v.$border-color;
  border-radius: 10px;
  padding: 20px 16px;
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, box-shadow .15s;
  background: #fff;

  &:hover {
    border-color: v.$info;
    box-shadow: 0 4px 12px rgba(37,99,235,.1);
  }

  &--scratch {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-style: dashed;
  }
}

.af-template-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid v.$border-color;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  color: v.$gray-500;
  font-size: 18px;
  font-weight: 300;

  svg { width: 18px; height: 18px; }
}

.af-template-name {
  font-size: 13px;
  font-weight: 700;
  color: v.$gray-900;
  margin-bottom: 6px;
  line-height: 1.3;
}

.af-template-desc {
  font-size: 11px;
  color: v.$gray-500;
  line-height: 1.4;
}
