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

// ─────────────────────────────────────────────
// Sequence Builder Layout
// ─────────────────────────────────────────────

// ── Top Bar ──
.sb-topbar {
  display: flex;
  align-items: center;
  background: v.$white;
  border-bottom: 1px solid v.$border-color;
  height: 54px;
  padding: 0 20px;
  gap: 12px;
  position: relative;
  flex-shrink: 0;
}

.sb-topbar-back {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: v.$font-size-sm;
  font-weight: 500;
  color: v.$gray-500;
  text-decoration: none;

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

.sb-topbar-divider { width: 1px; height: 20px; background: v.$border-color; }

.sb-topbar-name {
  font-size: v.$font-size-base;
  font-weight: 600;
  color: v.$gray-900;
  min-width: 200px;

  input {
    font-size: v.$font-size-base;
    font-weight: 600;
    color: v.$gray-900;
    border: none;
    outline: none;
    background: transparent;
    width: 260px;

    &:focus { background: v.$gray-50; border-radius: 4px; padding: 2px 6px; }
  }
}

.sb-topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: v.$font-size-2xs;
  font-weight: 600;
  background: v.$warning-light;
  color: v.$warning;
}

.sb-topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sb-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 14px;
  border-radius: 6px;
  border: 1px solid v.$border-color;
  background: v.$white;
  font-size: v.$font-size-xs;
  font-weight: 500;
  color: v.$gray-700;
  cursor: pointer;
  font-family: inherit;
  transition: background v.$transition-base;

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

.sb-btn-primary {
  background: v.$info;
  color: v.$white;
  border-color: v.$info;

  &:hover { background: #1d4ed8; }
}

.sb-btn-success {
  background: v.$success;
  color: v.$white;
  border-color: v.$success;

  &:hover { background: #15803d; }
}

// ── Main Layout ──
.sb-layout { display: flex; height: calc(100vh - 54px); overflow: hidden; }

// ── Left Config Panel ──
.sb-config {
  width: 300px;
  background: v.$white;
  border-right: 1px solid v.$border-color;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sb-config-header {
  padding: 16px 20px;
  border-bottom: 1px solid v.$gray-100;

  h3 { font-size: v.$font-size-sm; font-weight: 700; color: v.$gray-900; margin: 0 0 2px; }
  p  { font-size: v.$font-size-2xs; color: v.$gray-400; margin: 0; }
}

.sb-config-body { padding: 16px 20px; flex: 1; overflow-y: auto; }

.sb-field {
  margin-bottom: 16px;

  label {
    display: block;
    font-size: v.$font-size-2xs;
    font-weight: 600;
    color: v.$gray-500;
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 5px;
  }

  input, select, textarea {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid v.$border-color;
    border-radius: 6px;
    font-size: v.$font-size-sm;
    color: v.$gray-700;
    font-family: inherit;
    outline: none;
    background: v.$white;

    &:focus { border-color: v.$info-border; }
  }

  textarea { resize: vertical; min-height: 68px; line-height: 1.5; }
}

.sb-stat-row { display: flex; gap: 8px; margin-bottom: 16px; }

.sb-stat {
  flex: 1;
  background: v.$gray-50;
  border: 1px solid v.$gray-100;
  border-radius: v.$radius;
  padding: 10px 12px;
}

.sb-stat-val   { font-size: 20px; font-weight: 700; color: v.$gray-900; }
.sb-stat-label { font-size: 10px; color: v.$gray-400; font-weight: 500; margin-top: 1px; }

.sb-section-label {
  font-size: 10px;
  font-weight: 700;
  color: v.$gray-400;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
}

.sb-tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }

.sb-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 20px;
  font-size: v.$font-size-2xs;
  font-weight: 500;
  color: v.$info;

  button {
    border: none;
    background: none;
    cursor: pointer;
    font-size: v.$font-size-base;
    color: v.$info-border;
    padding: 0;
    line-height: 1;
  }
}

// ── Builder Canvas ──
.sb-canvas {
  flex: 1;
  overflow-y: auto;
  padding: 28px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sb-canvas-inner { width: 100%; max-width: 560px; }

// Trigger Block
.sb-trigger-block {
  background: v.$white;
  border: 2px solid v.$info;
  border-radius: v.$radius-lg;
  padding: 18px 20px;
  margin-bottom: 0;
  position: relative;
}

.sb-trigger-block-label {
  font-size: 10px;
  font-weight: 700;
  color: v.$info;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;

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

.sb-trigger-title { font-size: v.$font-size-base; font-weight: 600; color: v.$gray-900; margin-bottom: 6px; }
.sb-trigger-desc  { font-size: v.$font-size-xs; color: v.$gray-500; }
.sb-trigger-edit  { position: absolute; top: 14px; right: 14px; }

// Connector Line
.sb-connector {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  position: relative;
  margin: 0;
}

.sb-connector-line { width: 2px; background: v.$gray-300; flex: 1; min-height: 16px; }
.sb-connector-dot  { width: 8px; height: 8px; border-radius: 50%; background: v.$gray-400; flex-shrink: 0; }

// Delay Pill
.sb-delay-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: v.$gray-50;
  border: 1px solid v.$border-color;
  border-radius: 20px;
  padding: 5px 12px 5px 8px;
  font-size: v.$font-size-xs;
  color: v.$gray-700;
  cursor: pointer;
  position: relative;
  z-index: 1;
  margin: 4px 0;
  white-space: nowrap;

  &:hover { border-color: v.$info-border; background: #eff6ff; }
  svg { width: 13px; height: 13px; color: v.$gray-400; }
}

.sb-delay-pill-val { font-weight: 600; color: v.$gray-800; }

// Email Step Card
.sb-email-step {
  background: v.$white;
  border: 1px solid v.$border-color;
  border-radius: v.$radius-lg;
  padding: 16px 20px;
  width: 100%;
  position: relative;
  transition: border-color v.$transition-base, box-shadow v.$transition-base;

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

  &:hover .sb-step-remove { opacity: 1; }
}

.sb-step-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 700;
  color: v.$info;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;

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

.sb-step-subject {
  font-size: v.$font-size-base;
  font-weight: 600;
  color: v.$gray-900;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;

  input {
    font-size: v.$font-size-base;
    font-weight: 600;
    color: v.$gray-900;
    border: none;
    outline: none;
    background: transparent;
    flex: 1;
    font-family: inherit;

    &:focus { background: v.$gray-50; border-radius: 4px; padding: 0 4px; }
  }
}

.sb-step-meta    { font-size: v.$font-size-2xs; color: v.$gray-400; margin-bottom: 12px; }
.sb-step-actions { display: flex; gap: 8px; }

.sb-step-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 5px;
  border: 1px solid v.$border-color;
  background: v.$white;
  font-size: v.$font-size-2xs;
  font-weight: 500;
  color: v.$gray-700;
  cursor: pointer;
  font-family: inherit;
  transition: background v.$transition-base;

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

.sb-step-btn-primary {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: v.$info;

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

.sb-step-remove {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 26px;
  height: 26px;
  border-radius: 5px;
  border: none;
  background: v.$danger-light;
  color: #ef4444;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity v.$transition-base;

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

// Condition Block
.sb-condition-block {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: v.$radius-lg;
  padding: 14px 18px;
  width: 100%;
  position: relative;
}

.sb-condition-label {
  font-size: 10px;
  font-weight: 700;
  color: v.$warning;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.sb-condition-title { font-size: v.$font-size-sm; font-weight: 600; color: #92400e; margin-bottom: 4px; }

.sb-condition-branches { display: flex; gap: 12px; margin-top: 12px; }

.sb-branch {
  flex: 1;
  padding: 10px 12px;
  border-radius: v.$radius;
  border: 1px dashed v.$gray-300;
  text-align: center;
  font-size: v.$font-size-xs;
  color: v.$gray-400;
  cursor: pointer;
  transition: border-color v.$transition-base;

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

.sb-branch-yes { border-color: #a7f3d0; background: #ecfdf5; color: #059669; font-weight: 600; }
.sb-branch-no  { border-color: #fecaca; background: #fef2f2; color: v.$danger; font-weight: 600; }

// Add Step Button
.sb-add-step {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  border: 2px dashed v.$gray-300;
  border-radius: v.$radius-md;
  background: transparent;
  font-size: v.$font-size-sm;
  font-weight: 500;
  color: v.$gray-400;
  cursor: pointer;
  font-family: inherit;
  transition: all v.$transition-base;
  margin-top: 4px;

  &:hover { border-color: v.$info; color: v.$info; background: #eff6ff; }
  svg { width: 16px; height: 16px; }
}

// Add Step Dropdown
.sb-add-menu {
  background: v.$white;
  border: 1px solid v.$border-color;
  border-radius: v.$radius;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
  padding: 6px;
  display: none;
  min-width: 200px;
  position: absolute;
  z-index: 100;

  &.is-open { display: block; }
}

.sb-add-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  font-size: v.$font-size-sm;
  color: v.$gray-700;
  cursor: pointer;
  transition: background .1s;

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

.sb-add-menu-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

// ── Right Details Panel ──
.sb-details {
  width: 280px;
  background: v.$white;
  border-left: 1px solid v.$border-color;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: width .2s;
}

.sb-details-header {
  padding: 14px 18px;
  border-bottom: 1px solid v.$gray-100;
  display: flex;
  align-items: center;
  justify-content: space-between;

  h4 { font-size: v.$font-size-sm; font-weight: 700; color: v.$gray-900; margin: 0; }
}

.sb-details-close {
  border: none;
  background: none;
  cursor: pointer;
  color: v.$gray-400;
  padding: 2px;

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

.sb-details-body    { padding: 16px 18px; overflow-y: auto; flex: 1; }
.sb-details-section { margin-bottom: 18px; }

.sb-details-section-title {
  font-size: 10px;
  font-weight: 700;
  color: v.$gray-400;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
}

// Progress bar on steps
.sb-step-stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.sb-step-stat-label { font-size: v.$font-size-2xs; color: v.$gray-500; width: 60px; flex-shrink: 0; }
.sb-step-stat-bar   { flex: 1; height: 4px; background: v.$gray-100; border-radius: 2px; }
.sb-step-stat-fill  { height: 100%; border-radius: 2px; background: v.$info; }
.sb-step-stat-val   { font-size: v.$font-size-2xs; font-weight: 600; color: v.$gray-700; width: 36px; text-align: right; }
