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

// ─────────────────────────────────────────────
// Recurring Email Wizard Layout
// ─────────────────────────────────────────────
.rw-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

// ── Step Bar ──
.rw-stepbar {
  display: flex;
  align-items: center;
  justify-content: center;
  background: v.$white;
  border-bottom: 1px solid v.$border-color;
  height: 54px;
  position: relative;
  flex-shrink: 0;
}

.rw-stepbar-back {
  position: absolute;
  left: 20px;
  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; }
}

.rw-stepbar-title {
  position: absolute;
  right: 20px;
  font-size: v.$font-size-sm;
  font-weight: 600;
  color: v.$gray-700;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rw-steps { display: flex; align-items: center; gap: 0; }

.rw-step-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
  height: 54px;
  font-size: v.$font-size-sm;
  font-weight: 500;
  color: v.$gray-400;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  user-select: none;
  transition: color v.$transition-base;

  &.is-active {
    color: v.$gray-800;
    border-bottom-color: v.$info;

    .rw-step-num { background: v.$info; color: v.$white; }
  }

  &.is-done {
    color: v.$success;

    .rw-step-num  { display: none; }
    .rw-step-check { display: block; }
  }
}

.rw-step-num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: v.$border-color;
  font-size: v.$font-size-2xs;
  font-weight: 700;
  color: v.$gray-500;
  flex-shrink: 0;
}

.rw-step-check { display: none; width: 18px; height: 18px; color: v.$success; }

.rw-step-sep { width: 24px; height: 1px; background: v.$border-color; flex-shrink: 0; }

// ── Step Panels ──
.rw-step-panel {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;

  &[hidden] { display: none !important; }
}

// ── Compose Step (Editor) ──
.rw-editor-toolbar {
  height: 48px;
  background: v.$white;
  border-bottom: 1px solid v.$border-color;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 8px;
  flex-shrink: 0;
}

.rw-toolbar-left  { display: flex; align-items: center; gap: 6px; }
.rw-toolbar-right { display: flex; align-items: center; gap: 6px; }

.rw-tbtn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px;
  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;
  transition: background v.$transition-base;

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

.rw-tbtn-icon { width: 28px; height: 28px; padding: 0; }

.rw-tbtn-sep { width: 1px; height: 24px; background: v.$border-color; margin: 0 4px; }

.rw-tbtn-save {
  background: v.$success;
  color: v.$white;
  border-color: v.$success;

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

.rw-tbtn-next {
  background: v.$info;
  color: v.$white;
  border-color: v.$info;

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

.rw-editor-body { flex: 1; display: flex; overflow: hidden; }

// Block Palette
.rw-palette {
  width: 160px;
  background: #f8fafc;
  border-right: 1px solid v.$border-color;
  padding: 12px 8px;
  overflow-y: auto;
  flex-shrink: 0;
}

.rw-palette-label {
  font-size: 10px;
  font-weight: 700;
  color: v.$gray-400;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin: 8px 4px 6px;
}

.rw-palette-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 6px;
  border-radius: 6px;
  border: 1px solid v.$border-color;
  background: v.$white;
  cursor: grab;
  font-size: v.$font-size-2xs;
  font-weight: 500;
  color: v.$gray-700;
  text-align: center;
  margin-bottom: 6px;
  user-select: none;
  transition: border-color v.$transition-base, box-shadow v.$transition-base;

  &:hover { border-color: v.$info-border; box-shadow: 0 2px 8px rgba(37, 99, 235, .1); }
  &:active { cursor: grabbing; }
  svg { width: 20px; height: 20px; color: v.$gray-500; }
}

// Canvas
.rw-canvas-wrap {
  flex: 1;
  overflow-y: auto;
  background: #e9ecef;
  padding: 24px;
  display: flex;
  justify-content: center;
}

.rw-email-frame {
  width: 620px;
  background: v.$white;
  min-height: 480px;
  box-shadow: 0 2px 16px rgba(0, 0, 0, .12);
  border-radius: 2px;
  position: relative;
}

.rw-drop-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px 24px;
  color: v.$gray-400;
  font-size: v.$font-size-sm;
  text-align: center;
  border: 2px dashed v.$gray-300;
  margin: 16px;
  border-radius: 6px;

  svg { width: 32px; height: 32px; color: v.$gray-300; }
}

.rw-email-footer {
  padding: 16px;
  text-align: center;
  font-size: v.$font-size-2xs;
  color: v.$gray-400;
  border-top: 1px solid v.$gray-100;
  margin-top: 8px;
}

// Email Blocks (shared with campaign wizard)
.rw-email-block {
  position: relative;
  border: 2px solid transparent;
  transition: border-color v.$transition-base;

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

.eb-inline-toolbar {
  position: absolute;
  top: -40px;
  left: 0;
  background: v.$gray-800;
  border-radius: 6px;
  padding: 4px;
  display: none;
  align-items: center;
  gap: 2px;
  z-index: 10;
  white-space: nowrap;
}

.email-block.is-selected .eb-inline-toolbar { display: flex; }

.eb-tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: v.$border-color;
  cursor: pointer;

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

// Settings Panel
.rw-settings {
  width: 260px;
  border-left: 1px solid v.$border-color;
  background: v.$white;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.rw-settings-header {
  padding: 12px 16px;
  border-bottom: 1px solid v.$gray-100;
  font-size: v.$font-size-xs;
  font-weight: 600;
  color: v.$gray-700;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rw-settings-body    { padding: 14px 16px; flex: 1; overflow-y: auto; }
.rw-settings-section { margin-bottom: 18px; }

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

.rw-prop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.rw-prop-label  { font-size: v.$font-size-2xs; color: v.$gray-500; }

.rw-prop-select {
  font-size: v.$font-size-2xs;
  padding: 4px 6px;
  border: 1px solid v.$border-color;
  border-radius: 4px;
  color: v.$gray-700;
}

.rw-pad-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.rw-pad-field {
  display: flex;
  flex-direction: column;
  gap: 2px;

  label { font-size: 9px; color: v.$gray-400; text-transform: uppercase; }
  input {
    font-size: v.$font-size-2xs;
    padding: 4px 6px;
    border: 1px solid v.$border-color;
    border-radius: 4px;
    width: 100%;
  }
}

.rw-color-swatches { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }

.rw-swatch {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid transparent;

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

// ── Content Area (non-editor steps) ──
.rw-content-area {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

.rw-content-card {
  background: v.$white;
  border: 1px solid v.$border-color;
  border-radius: v.$radius-md;
  padding: 28px 32px;
  margin-bottom: 20px;
  max-width: 780px;
  margin-left: auto;
  margin-right: auto;

  h3 {
    font-size: v.$font-size-md;
    font-weight: 700;
    color: v.$gray-900;
    margin: 0 0 20px;
    display: flex;
    align-items: center;
    gap: 8px;

    svg { width: 18px; height: 18px; color: v.$info; }
  }
}

.rw-step-footer {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
}

.rw-step-back-link {
  font-size: v.$font-size-sm;
  color: v.$gray-500;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;

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

// ── Schedule Step ──
.freq-pills { display: flex; gap: 8px; margin-bottom: 20px; }

.freq-pill {
  flex: 1;
  padding: 10px 8px;
  text-align: center;
  border: 2px solid v.$border-color;
  border-radius: v.$radius;
  font-size: v.$font-size-sm;
  font-weight: 500;
  color: v.$gray-500;
  cursor: pointer;
  transition: all v.$transition-base;

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

.day-pills { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }

.day-pill {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid v.$border-color;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: v.$font-size-2xs;
  font-weight: 600;
  color: v.$gray-500;
  cursor: pointer;
  transition: all v.$transition-base;

  &.is-active { border-color: v.$info; background: v.$info; color: v.$white; }
}

.time-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.date-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.end-opts { display: flex; flex-direction: column; gap: 10px; }

.end-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: v.$font-size-sm;
  color: v.$gray-700;

  input[type=radio] { accent-color: v.$info; }
}

// ── Recipients Step ──
.rw-recip-card {
  background: v.$white;
  border: 1px solid v.$border-color;
  border-radius: v.$radius-md;
  margin-bottom: 16px;
  max-width: 780px;
  margin-left: auto;
  margin-right: auto;
  overflow: hidden;
}

.rw-recip-card-header {
  padding: 16px 24px;
  border-bottom: 1px solid v.$gray-100;
  display: flex;
  align-items: center;
  justify-content: space-between;

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

.rw-recip-table {
  width: 100%;
  border-collapse: collapse;

  td {
    padding: 10px 16px;
    border-bottom: 1px solid v.$gray-100;
    font-size: v.$font-size-sm;
    vertical-align: middle;

    &:last-child { width: 80px; }
  }
}

.rw-contact-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  font-size: v.$font-size-xs;
  font-weight: 500;
  color: #15803d;
  margin: 12px 24px;
}

// ── Review Step ──
.rw-review-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid v.$gray-100;

  &:last-child { border-bottom: none; }
}

.rw-review-label {
  width: 140px;
  flex-shrink: 0;
  font-size: v.$font-size-xs;
  font-weight: 600;
  color: v.$gray-400;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding-top: 2px;
}

.rw-review-value { flex: 1; font-size: v.$font-size-sm; color: v.$gray-700; }

.rw-review-edit {
  margin-left: auto;
  flex-shrink: 0;
  font-size: v.$font-size-xs;
  font-weight: 500;
  color: v.$info;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.rw-preview-box {
  border: 2px dashed #fbbf24;
  border-radius: v.$radius;
  background: #fffbeb;
  padding: 20px;
  text-align: center;
}

.rw-schedule-radio { display: flex; flex-direction: column; gap: 10px; }

.rw-radio-opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border: 1px solid v.$border-color;
  border-radius: v.$radius;
  cursor: pointer;

  &.is-selected { border-color: v.$info; background: #eff6ff; }

  input[type=radio] { accent-color: v.$info; margin-top: 1px; }
}

.rw-radio-opt-body { flex: 1; }
.rw-radio-opt-title { font-size: v.$font-size-sm; font-weight: 600; color: v.$gray-900; margin-bottom: 2px; }
.rw-radio-opt-desc  { font-size: v.$font-size-xs; color: v.$gray-500; }
