@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: var(--bg-surface);
  border-bottom: 1px solid var(--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: var(--text-muted);
  text-decoration: none;

  &:hover { color: var(--text-primary); }
}

.rw-stepbar-title {
  position: absolute;
  right: 20px;
  font-size: v.$font-size-sm;
  font-weight: 600;
  color: var(--text-secondary);
  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: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  user-select: none;
  transition: color v.$transition-base;

  &.is-active {
    color: var(--text-primary);
    border-bottom-color: var(--info);

    .rw-step-num { background: var(--info); color: #fff; }
  }

  &.is-done {
    color: var(--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: var(--border-color);
  font-size: v.$font-size-2xs;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

.rw-step-check { display: none; width: 18px; height: 18px; color: var(--success); }

.rw-step-sep { width: 24px; height: 1px; background: var(--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: var(--bg-surface);
  border-bottom: 1px solid var(--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 var(--border-color);
  background: var(--bg-surface);
  font-size: v.$font-size-xs;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background v.$transition-base;

  &:hover { background: var(--bg-hover); }
  svg { width: 14px; height: 14px; }
}

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

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

.rw-tbtn-save {
  background: var(--success);
  color: #fff;
  border-color: var(--success);

  &:hover { background: var(--success-border); }
}

.rw-tbtn-next {
  background: var(--info);
  color: #fff;
  border-color: var(--info);

  &:hover { background: var(--info-border); }
}

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

// Block Palette
.rw-palette {
  width: 160px;
  background: var(--bg-page);
  border-right: 1px solid var(--border-color);
  padding: 12px 8px;
  overflow-y: auto;
  flex-shrink: 0;
}

.rw-palette-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  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 var(--border-color);
  background: var(--bg-surface);
  cursor: grab;
  font-size: v.$font-size-2xs;
  font-weight: 500;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 6px;
  user-select: none;
  transition: border-color v.$transition-base, box-shadow v.$transition-base;

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

// Canvas
.rw-canvas-wrap {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-page);
  padding: 24px;
  display: flex;
  justify-content: center;
}

.rw-email-frame {
  width: 620px;
  background: var(--bg-surface);
  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: var(--text-muted);
  font-size: v.$font-size-sm;
  text-align: center;
  border: 2px dashed var(--border-color);
  margin: 16px;
  border-radius: 6px;

  svg { width: 32px; height: 32px; color: var(--border-color); }
}

.rw-email-footer {
  padding: 16px;
  text-align: center;
  font-size: v.$font-size-2xs;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  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 var(--border-color);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.rw-settings-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  font-size: v.$font-size-xs;
  font-weight: 600;
  color: var(--text-primary);
  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: var(--text-muted);
  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: var(--text-secondary); }

.rw-prop-select {
  font-size: v.$font-size-2xs;
  padding: 4px 6px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-primary);
}

.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: var(--text-muted); text-transform: uppercase; }
  input {
    font-size: v.$font-size-2xs;
    padding: 4px 6px;
    border: 1px solid var(--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: var(--info); }
}

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

.rw-content-card {
  background: var(--bg-surface);
  border: 1px solid var(--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: var(--text-primary);
    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: var(--text-secondary);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;

  &:hover { color: var(--text-primary); }
}

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

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

  &.is-active { border-color: var(--info); background: var(--info-light); color: var(--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 var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: v.$font-size-2xs;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all v.$transition-base;

  &.is-active { border-color: var(--info); background: var(--info); color: #fff; }
}

.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: var(--text-primary);

  input[type=radio] {
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    outline: none !important;
    box-shadow: none !important;
    &:checked {
      border-color: var(--info) !important;
      background-color: var(--info) !important;
    }
  }
}

// ── Recipients Step ──
.rw-recip-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: v.$radius-md;
  margin: 0px;
  margin-bottom: 16px;
  // max-width: 780px;
  margin-left: auto;
  margin-right: auto;
  overflow: visible;
}

.rw-recip-card-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;

  h4 { font-size: v.$font-size-base; font-weight: 600; color: var(--text-primary); margin: 0; }
}

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

  td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: v.$font-size-sm;
    vertical-align: middle;

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

// ── Review Step ──
.rw-review-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-color);

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

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

.rw-review-value { flex: 1; font-size: v.$font-size-sm; color: var(--text-primary); }

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

.rw-preview-box {
  border: 2px dashed var(--warning-border);
  border-radius: v.$radius;
  background: var(--warning-light);
  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 var(--border-color);
  border-radius: v.$radius;
  cursor: pointer;

  &.is-selected { border-color: var(--info); background: var(--info-light); }

  input[type=radio] {
    margin-top: 1px;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    outline: none !important;
    box-shadow: none !important;
    &:checked {
      border-color: var(--info) !important;
      background-color: var(--info) !important;
    }
  }
}

.rw-radio-opt-body { flex: 1; }
.rw-radio-opt-title { font-size: v.$font-size-sm; font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.rw-radio-opt-desc  { font-size: v.$font-size-xs; color: var(--text-muted); }

// ── Responsive Layout Adaptations ──
@media (max-width: 1024px) {
  .rw-editor-body {
    flex-direction: column;
    overflow-y: auto;
    height: auto;
  }
  .rw-palette {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 12px;
    flex-direction: row;
    height: auto;
    flex-shrink: 0;
  }
  .rw-palette-label {
    display: none;
  }
  .rw-palette-item {
    flex-direction: row;
    gap: 6px;
    padding: 6px 12px;
    margin-bottom: 0;
    white-space: nowrap;
    svg { width: 14px; height: 14px; }
  }
  .rw-settings {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border-color);
    max-height: 400px;
  }
}

@media (max-width: 768px) {
  .rw-stepbar {
    height: auto;
    padding: 12px;
    flex-direction: column;
    gap: 8px;
  }
  .rw-stepbar-back, .rw-stepbar-title {
    position: static;
    max-width: none;
    text-align: center;
  }
  .rw-steps {
    flex-wrap: wrap;
    justify-content: center;
  }
  .rw-step-item {
    height: 38px;
    padding: 0 10px;
  }
  .rw-content-card {
    padding: 20px 16px;
  }
  .rw-recip-card-header {
    padding: 12px 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .rw-recip-table td {
    padding: 8px 12px;
  }
  .rw-review-row {
    flex-direction: column;
    gap: 6px;
  }
  .rw-review-label {
    width: 100%;
  }
  .rw-review-edit {
    margin-left: 0;
    margin-top: 4px;
  }
}

@media (max-width: 680px) {
  .rw-email-frame {
    width: 100%;
    min-width: 0;
  }
  .rw-canvas-wrap {
    padding: 12px;
  }
}

@media (max-width: 640px) {
  .rw-step-item {
    span:not(.rw-step-num):not(.rw-step-check) {
      display: none;
    }
  }
}
