/* ==========================================================================
   Auto Email tab (lists, queue, templates). Everything is scoped under .ae.
   ========================================================================== */

.ae {
  --ae-soft: color-mix(in srgb, var(--text-primary) 5%, var(--bg-surface));
  --ae-softer: color-mix(in srgb, var(--text-primary) 2.5%, var(--bg-surface));
  --ae-ok: #15803d;
  --ae-warn: #b45309;
  --ae-bad: #b91c1c;
  --ae-info: #1d4ed8;
  --ae-ai: #6d28d9;
  max-width: 1120px;
  margin: 0 auto;
  padding-bottom: 4rem;
}

.theme-dark .ae {
  --ae-ok: #4ade80;
  --ae-warn: #fbbf24;
  --ae-bad: #f87171;
  --ae-info: #93c5fd;
  --ae-ai: #c4b5fd;
}

.ae [hidden] { display: none !important; }

/* ---------- Buttons (local variants) ---------- */
.ae .btn-link {
  background: none;
  border: none;
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 0.45rem 0.4rem;
  font-weight: 600;
}

.ae .btn-link:hover { color: var(--text-secondary); }
.ae .btn:disabled { opacity: 0.45; cursor: not-allowed; }
.theme-dark .ae .btn-primary { background: #f0f0f0; color: #0a0a0a; }
.theme-dark .ae .btn-primary:hover:not(:disabled) { background: #fff; }

.ae .ae-btn-danger { background: var(--ae-bad); color: #fff; }
.ae .ae-btn-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--ae-bad) 85%, #000); }
.theme-dark .ae .ae-btn-danger { background: var(--ae-bad); color: #0a0a0a; }

.ae-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.ae-icon-btn:hover { background: var(--ae-soft); color: var(--text-primary); border-color: var(--border-color); }
.ae-icon-btn:focus-visible,
.ae button:focus-visible,
.ae [tabindex]:focus-visible { outline: 2px solid var(--text-primary); outline-offset: 2px; }
.ae-icon-btn.is-danger:hover { color: var(--ae-bad); }

/* ---------- Banner ---------- */
.ae-banner {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid color-mix(in srgb, var(--ae-warn) 35%, var(--border-color));
  background: color-mix(in srgb, var(--ae-warn) 8%, var(--bg-surface));
  color: var(--text-primary);
  font-size: 0.88rem;
}

.ae-banner > i { color: var(--ae-warn); font-size: 1.1rem; }
.ae-banner div { flex: 1; display: flex; flex-direction: column; gap: 0.1rem; }
.ae-banner span { color: var(--text-secondary); font-size: 0.82rem; }

/* ---------- Header & tabs ---------- */
.ae-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.1rem;
}

.ae-tabs { display: flex; gap: 0.25rem; }

.ae-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.65rem 0.9rem;
  margin-bottom: -1px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.ae-tab:hover { color: var(--text-primary); }
.ae-tab.active { color: var(--text-primary); border-bottom-color: var(--text-primary); }

.ae-count {
  font-size: 0.72rem;
  font-weight: 700;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--ae-soft);
  color: var(--text-secondary);
  text-align: center;
}

.ae-count:empty { display: none; }
.ae-tab.active .ae-count { background: var(--text-primary); color: var(--bg-surface); }
.ae-head-actions { padding-bottom: 0.5rem; display: flex; gap: 0.5rem; }

/* ---------- Toolbar, chips, search ---------- */
.ae-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}

.ae-toolbar-right { display: flex; align-items: center; gap: 0.5rem; }
.ae-chips { display: flex; gap: 0.35rem; flex-wrap: wrap; }

.ae-chip {
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 0.32rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.ae-chip span { font-weight: 700; margin-left: 0.15rem; }
.ae-chip span:empty { display: none; }
.ae-chip:hover { color: var(--text-primary); border-color: var(--text-muted); }
.ae-chip.active { background: var(--text-primary); color: var(--bg-surface); border-color: var(--text-primary); }

.ae-search { position: relative; width: 240px; }
.ae-search i { position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 0.78rem; }
.ae-search .form-control { padding: 0.45rem 0.7rem 0.45rem 2rem; border-radius: 999px; width: 100%; font-size: 0.84rem; }

.ae .form-control { border-radius: var(--radius-sm); width: 100%; }
.ae .form-control:focus { border-color: var(--text-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--text-primary) 10%, transparent); }
.ae .ae-select-sm { width: auto; padding: 0.35rem 0.6rem; font-size: 0.82rem; max-width: 240px; }

/* ---------- List cards ---------- */
.ae-stack { display: flex; flex-direction: column; gap: 0.7rem; }

.ae-list-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: var(--transition);
}

.ae-list-card:hover { border-color: var(--text-muted); box-shadow: var(--shadow-md); }
.ae-list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.3rem; }

.ae-list-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-weight: 650;
  font-size: 0.98rem;
  color: var(--text-primary);
}

.ae-meta { font-size: 0.8rem; color: var(--text-secondary); }
.ae-meta .sep { margin: 0 0.35rem; color: var(--text-muted); }

.ae-next-step {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.ae-next-step i { color: var(--text-muted); font-size: 0.72rem; }
.ae-list-actions { display: flex; align-items: center; gap: 0.35rem; flex-shrink: 0; }

/* Status pill */
.ae-status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--ae-soft);
  color: var(--text-secondary);
  white-space: nowrap;
}

.ae-status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.ae-status.is-active { color: var(--ae-ok); background: color-mix(in srgb, var(--ae-ok) 12%, var(--bg-surface)); }
.ae-status.is-active::before { animation: aePulse 1.6s ease-in-out infinite; }
.ae-status.is-paused { color: var(--ae-warn); background: color-mix(in srgb, var(--ae-warn) 12%, var(--bg-surface)); }
.ae-status.is-completed { color: var(--text-primary); }
.ae-status.is-failed { color: var(--ae-bad); background: color-mix(in srgb, var(--ae-bad) 10%, var(--bg-surface)); }
.ae-status.is-sending { color: var(--ae-info); background: color-mix(in srgb, var(--ae-info) 10%, var(--bg-surface)); }

.ae-tag {
  display: inline-flex;
  white-space: nowrap;
  flex-shrink: 0;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.ae-tag.is-ai { color: var(--ae-ai); border-color: color-mix(in srgb, var(--ae-ai) 35%, var(--border-color)); }

@keyframes aePulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* Progress */
.ae-progress { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.15rem; }

.ae-bar {
  flex: 1;
  max-width: 320px;
  height: 6px;
  border-radius: 999px;
  background: var(--ae-soft);
  overflow: hidden;
  display: flex;
}

.ae-bar-sent { background: var(--text-primary); }
.ae-bar-failed { background: var(--ae-bad); }
.ae-progress-label { font-size: 0.78rem; color: var(--text-secondary); white-space: nowrap; }

/* Kebab menu */
.ae-menu { position: relative; }

.ae-menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 170px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  z-index: 30;
}

.ae-menu-list button {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 0.84rem;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
}

.ae-menu-list button i { width: 14px; color: var(--text-secondary); }
.ae-menu-list button:hover { background: var(--ae-soft); }
.ae-menu-list button.is-danger,
.ae-menu-list button.is-danger i { color: var(--ae-bad); }

/* ---------- Empty states ---------- */
.ae-empty {
  text-align: center;
  padding: 2.5rem 1.5rem;
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-secondary);
}

.ae-empty-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--ae-soft);
  display: grid;
  place-items: center;
  margin: 0 auto 0.85rem;
  font-size: 1.15rem;
  color: var(--text-primary);
}

.ae-empty h3 { font-size: 1rem; color: var(--text-primary); margin-bottom: 0.3rem; }
.ae-empty p { font-size: 0.86rem; max-width: 420px; margin: 0 auto 1rem; line-height: 1.5; }

.ae-steps {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin: 0 auto 1.25rem;
  flex-wrap: wrap;
  font-size: 0.82rem;
  color: var(--text-secondary);
  list-style: none;
  padding: 0;
}

.ae-steps li { display: flex; align-items: center; gap: 0.45rem; }

.ae-steps b {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  display: inline-grid;
  place-items: center;
  font-size: 0.72rem;
  color: var(--text-primary);
}

/* ---------- Detail ---------- */
.ae-back {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0;
}

.ae-back:hover { color: var(--text-primary); }

.ae-detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin: 0.5rem 0 1.1rem;
  flex-wrap: wrap;
}

.ae-detail-head h2 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  color: var(--text-primary);
}

.ae-detail-head .ae-meta { margin-top: 0.3rem; }
.ae-detail-actions { display: flex; align-items: center; gap: 0.45rem; }

.ae-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1rem;
}

.ae-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.ae-card-head h3 { font-size: 0.98rem; font-weight: 650; color: var(--text-primary); }
.ae-card-head p { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.15rem; }

.ae-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.ae-stat {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.8rem 0.95rem;
}

.ae-stat-label { font-size: 0.74rem; color: var(--text-secondary); display: block; }
.ae-stat-value { font-size: 1.25rem; font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.ae-stat.is-bad .ae-stat-value { color: var(--ae-bad); }

.ae-email-preview {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--ae-softer);
  padding: 0.85rem 1rem;
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text-primary);
}

.ae-email-preview .ae-email-subject { font-weight: 650; margin-bottom: 0.5rem; }
.ae-email-preview .ae-email-body { white-space: pre-wrap; word-break: break-word; color: var(--text-secondary); max-height: 220px; overflow: auto; }

.ae-segment {
  display: inline-flex;
  background: var(--ae-soft);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.ae-segment button {
  border: none;
  background: transparent;
  padding: 0.38rem 0.8rem;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.ae-segment button.active { background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-sm); }

/* ---------- Rows (professors, queue) ---------- */
.ae-rows {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.ae-card .ae-rows { border-radius: var(--radius-sm); }

.ae-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-color);
}

.ae-row:first-child { border-top: none; }
.ae-row.has-time { grid-template-columns: 92px minmax(0, 1fr) auto; }
.ae-row-main { min-width: 0; }

.ae-row-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.ae-row-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.ae-row-error { font-size: 0.78rem; color: var(--ae-bad); margin-top: 2px; }
.ae-row-actions { display: flex; align-items: center; gap: 0.15rem; }

.ae-time { font-size: 0.8rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; line-height: 1.3; }
.ae-time strong { display: block; color: var(--text-primary); font-size: 0.86rem; }

.ae-rows-empty { padding: 1.75rem 1rem; text-align: center; color: var(--text-secondary); font-size: 0.86rem; }

/* ---------- Emails open in place under a row ---------- */
.ae-row.is-expandable .ae-row-main { cursor: pointer; }
.ae-row.is-expandable:hover { background: var(--ae-softer); }
.ae-row.is-open { background: var(--ae-softer); }
.ae-expand-btn i { transition: transform 0.18s ease; }
.ae-row.is-open .ae-expand-btn i { transform: rotate(180deg); }

.ae-row-panel {
  padding: 0.25rem 1rem 1rem;
  background: var(--ae-softer);
  border-top: 1px dashed var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.ae-row.has-time + .ae-row-panel { padding-left: calc(92px + 2rem); }
.ae-row-panel .ae-field { margin: 0; }
.ae-row-panel textarea.form-control { min-height: 180px; }
.ae-panel-meta { font-size: 0.78rem; color: var(--text-secondary); padding-top: 0.5rem; }
.ae-panel-loading { font-size: 0.82rem; color: var(--text-secondary); padding: 0.75rem 0 0.25rem; }
.ae-panel-actions { display: flex; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap; }
.ae-email-preview.is-inline { background: var(--bg-surface); }
.ae-email-preview.is-inline .ae-email-body { max-height: 360px; }
.ae-email-attachments { margin-top: 0.6rem; font-size: 0.78rem; color: var(--text-secondary); }

@media (max-width: 640px) {
  .ae-row.has-time + .ae-row-panel { padding-left: 1rem; }
}

/* ---------- Queue "next" card ---------- */
.ae-next {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.15rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.ae-next-count {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 84px;
  font-variant-numeric: tabular-nums;
}

.ae-next-main { flex: 1; min-width: 200px; }
.ae-next-label { font-size: 0.74rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.ae-next-title { font-weight: 650; color: var(--text-primary); margin-top: 0.1rem; }
.ae-next-sub { font-size: 0.8rem; color: var(--text-secondary); }

.ae-quota {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: right;
  border-left: 1px solid var(--border-color);
  padding-left: 1rem;
}

.ae-quota strong { color: var(--text-primary); font-size: 0.95rem; display: block; }

/* ---------- Templates ---------- */
.ae-template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.85rem;
}

.ae-template {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ae-template-head { display: flex; justify-content: space-between; gap: 0.5rem; align-items: flex-start; }
.ae-template h3 { font-size: 0.95rem; font-weight: 650; color: var(--text-primary); }
.ae-template-subject { font-size: 0.82rem; color: var(--text-primary); font-weight: 500; }

.ae-template-body {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-line;
  flex: 1;
}

.ae-template-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  border-top: 1px solid var(--border-color);
  padding-top: 0.6rem;
  margin-top: 0.2rem;
}

/* ---------- Editor ---------- */
.ae-editor-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.ae-editor-head h2 { font-size: 1.25rem; font-weight: 700; color: var(--text-primary); }

.ae-editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.ae-field { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1rem; border: none; padding: 0; min-width: 0; }
.ae-field:last-child { margin-bottom: 0; }
.ae-field-narrow { max-width: 320px; }
.ae-field label,
.ae-field legend { font-size: 0.82rem; font-weight: 600; color: var(--text-primary); margin-bottom: 0.4rem; }
.ae-field label { margin-bottom: 0; }
.ae-optional { font-weight: 500; color: var(--text-muted); }
.ae-help { font-size: 0.76rem; color: var(--text-secondary); line-height: 1.45; }
.ae textarea.form-control { resize: vertical; line-height: 1.55; }
.ae-label-row { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.ae-placeholders { display: flex; gap: 0.25rem; flex-wrap: wrap; }

.ae-placeholders button {
  border: 1px dashed var(--border-color);
  background: none;
  border-radius: 6px;
  padding: 1px 7px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.ae-placeholders button:hover { color: var(--text-primary); border-color: var(--text-muted); }
.ae-placeholders button::before { content: '+ '; }

.ae-choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.ae-choice { position: relative; cursor: pointer; }
.ae-choice input { position: absolute; opacity: 0; pointer-events: none; }

.ae-choice > span {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  height: 100%;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.ae-choice strong { font-size: 0.86rem; color: var(--text-primary); display: flex; gap: 0.45rem; align-items: center; }
.ae-choice small { font-size: 0.76rem; color: var(--text-secondary); line-height: 1.4; }
.ae-choice input:checked + span { border-color: var(--text-primary); box-shadow: inset 0 0 0 1px var(--text-primary); }
.ae-choice input:focus-visible + span { outline: 2px solid var(--text-primary); outline-offset: 2px; }
.ae-choice input:disabled + span { opacity: 0.55; cursor: not-allowed; }

.ae-locked-note {
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--ae-soft);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.85rem;
}

.ae-preview {
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.ae-preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.95rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ae-preview-head .form-control { text-transform: none; letter-spacing: 0; font-weight: 500; }
.ae-preview-mail { padding: 0.9rem 1rem; }

.ae-preview-line {
  display: flex;
  gap: 0.6rem;
  font-size: 0.82rem;
  padding-bottom: 0.4rem;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid var(--border-color);
}

.ae-preview-line span { width: 54px; color: var(--text-muted); flex-shrink: 0; }
.ae-preview-line strong { color: var(--text-primary); font-weight: 600; min-width: 0; overflow-wrap: anywhere; }

.ae-preview-body {
  margin-top: 0.7rem;
  font-size: 0.85rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-primary);
  max-height: 460px;
  overflow: auto;
}

.ae-preview-body mark {
  background: color-mix(in srgb, var(--ae-warn) 22%, transparent);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

.ae-editor-footer {
  position: sticky;
  bottom: -1.2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding: 0.85rem 0;
  background: linear-gradient(to top, var(--bg-primary) 75%, transparent);
  z-index: 5;
}

.ae-spacer { flex: 1; }

/* ---------- Dialog ---------- */
.ae-dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1100;
  display: grid;
  place-items: center;
  padding: 1rem;
  animation: aeFade 0.15s ease;
}

.ae-dialog {
  width: min(640px, 100%);
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.ae-dialog.is-small { width: min(460px, 100%); }

.ae-dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.ae-dialog-head h3 { font-size: 1.02rem; font-weight: 650; color: var(--text-primary); }
.ae-dialog-body { padding: 1.1rem 1.25rem; overflow: auto; font-size: 0.88rem; color: var(--text-primary); line-height: 1.5; }

.ae-dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border-color);
  background: var(--ae-softer);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.ae-dialog-foot:empty { display: none; }

.ae-facts { display: grid; grid-template-columns: auto 1fr; gap: 0.45rem 1rem; font-size: 0.86rem; margin-bottom: 0.9rem; }
.ae-facts dt { color: var(--text-secondary); }
.ae-facts dd { color: var(--text-primary); font-weight: 600; margin: 0; }

.ae-note {
  font-size: 0.82rem;
  color: var(--text-secondary);
  background: var(--ae-soft);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  display: flex;
  gap: 0.5rem;
}

.ae-note.is-warn { color: var(--text-primary); background: color-mix(in srgb, var(--ae-warn) 10%, var(--bg-surface)); }
.ae-note.is-warn i { color: var(--ae-warn); }

@keyframes aeFade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Toast ---------- */
.ae-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--bg-surface);
  padding: 0.7rem 1.1rem;
  border-radius: var(--radius-md);
  font-size: 0.86rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 1200;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  max-width: calc(100vw - 2rem);
}

.ae-toast.is-error { background: var(--ae-bad); color: #fff; }

/* ---------- Dashboard "Your Mail Lists" widget (outside .ae, shares its pieces) ---------- */
.ae-dash-lists { display: flex; flex-direction: column; gap: 0.5rem; }

.ae-dash-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  width: 100%;
  text-align: left;
  padding: 0.75rem 0.85rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-primary);
  font: inherit;
  transition: var(--transition);
}

.ae-dash-list:hover { border-color: var(--text-muted); }
.ae-dash-list-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.ae-dash-list strong { font-size: 0.9rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ae-dash-list .ae-meta { font-size: 0.78rem; color: var(--text-secondary); }

.ae-dash-list .ae-status,
.ae-dash-list .ae-bar,
.ae-dash-list .ae-progress { --ae-soft: color-mix(in srgb, var(--text-primary) 6%, var(--bg-surface)); --ae-ok: #15803d; --ae-warn: #b45309; }
.theme-dark .ae-dash-list .ae-status { --ae-ok: #4ade80; --ae-warn: #fbbf24; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .ae-editor-grid { grid-template-columns: 1fr; }
  .ae-preview { position: static; }
  .ae-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .ae-head { flex-direction: column; align-items: stretch; gap: 0.25rem; }
  .ae-head-actions { justify-content: flex-end; }
  .ae-search { width: 100%; }
  .ae-list-card { flex-direction: column; align-items: stretch; }
  .ae-list-actions { justify-content: flex-end; }
  .ae-choice-grid { grid-template-columns: 1fr; }
  .ae-row.has-time { grid-template-columns: minmax(0, 1fr) auto; }
  .ae-row.has-time .ae-time { grid-column: 1 / -1; }
  .ae-quota { border-left: none; padding-left: 0; text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  .ae *, .ae-toast, .ae-dialog-backdrop { animation: none !important; transition: none !important; }
}

/* AI list: writing progress, and the review confirmation when starting */
.ae-drafting { margin-top: 0.85rem; padding: 0.75rem 0.9rem; border-radius: 10px; background: var(--primary-light, rgba(99, 102, 241, 0.08)); display: flex; flex-direction: column; gap: 0.45rem; }
.ae-drafting-top { display: flex; justify-content: space-between; align-items: center; font-size: 0.86rem; }
.ae-drafting-top i { color: var(--primary); margin-right: 0.3rem; }
.ae-drafting .ae-bar { height: 8px; }
.ae-drafting .ae-bar-sent { transition: width 0.4s ease; }
.ae-drafting small { font-size: 0.78rem; color: var(--text-secondary); }
.ae-drafting-stopped { margin-top: 0.85rem; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.ae-drafting-stopped span { flex: 1; min-width: 200px; }
.ae-confirm { display: flex; gap: 0.6rem; align-items: flex-start; margin-top: 0.85rem; padding: 0.7rem 0.8rem; border: 1px solid var(--border-color); border-radius: 10px; font-size: 0.86rem; line-height: 1.5; cursor: pointer; }
.ae-confirm input { margin-top: 0.2rem; width: 16px; height: 16px; flex: none; accent-color: var(--primary); }
