/* Only available stage actions use the green primary button. */
#optimize-report:disabled,
.report-toolbar[inert] #optimize-report {
  background: #6b7280;
  box-shadow: 0 6px 14px rgba(107, 114, 128, 0.2);
  transform: none;
}

/* New stages retain the original report's dimensions with gentle red marking. */
body[data-state="ai-marking"] .group-stage,
body[data-state="ai-filtering"] .group-stage,
body[data-state="ai-result"] .group-stage,
body[data-state="ai-success"] .group-stage {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
}

body[data-state="ai-marking"] .is-ai-selected,
body[data-state="ai-filtering"] .is-ai-selected {
  color: #ae5660;
  opacity: 1;
  transform: none;
  box-shadow: none;
  animation: ai-word-alert 3000ms ease-in-out infinite;
}

body[data-state="ai-marking"] .group-row__summary.is-ai-selected,
body[data-state="ai-filtering"] .group-row__summary.is-ai-selected {
  color: #a4656c;
  animation-name: ai-group-highlight;
}

body[data-state="ai-filtering"] .is-ai-removable {
  pointer-events: none;
  animation: ai-item-out 550ms ease both;
}

body[data-state="ai-result"] .group-token:hover,
body[data-state="ai-result"] .group-token:focus-visible {
  border-color: #e7a8af;
  background: var(--red-soft);
  color: var(--red-strong);
}

body[data-state="ai-marking"] .status-dot,
body[data-state="ai-filtering"] .status-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(212, 59, 69, 0.12);
  animation: status-pulse 1080ms ease-in-out infinite alternate;
}

body[data-state="ai-result"] .status-dot,
body[data-state="ai-success"] .status-dot {
  background: #3b8b72;
  box-shadow: 0 0 0 4px rgba(59, 139, 114, 0.12);
}

.ai-rules[hidden], .ai-success[hidden] { display: none; }

.ai-rules {
  position: absolute;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
}

.ai-rules__backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  background: rgba(36, 44, 61, 0.24);
  backdrop-filter: blur(2px);
  cursor: default;
}

.ai-rules__panel {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(100%, 740px);
  max-height: 100%;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 18px 60px rgba(43, 56, 80, 0.2);
}

.ai-rules__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 26px;
  border-bottom: 1px solid var(--line);
  background: var(--chrome);
}

.ai-rules__header h2 {
  margin: 0;
  font-size: 25px;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.ai-rules__header .query-context__close { flex: 0 0 36px; }

.ai-rules__fields {
  display: grid;
  grid-auto-rows: max-content;
  gap: 12px;
  padding: 24px 26px;
  overflow-y: auto;
}

.ai-rules__fields label {
  color: #56637a;
  font-size: 15px;
  line-height: 1.48;
}

.ai-rules__fields label strong { color: var(--ink); font-weight: 720; }
.ai-rules__fields label:not(:first-child) { margin-top: 8px; }

.ai-rules__fields textarea {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 13px 15px;
  resize: none;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
}

.ai-rules__fields textarea:focus,
.ai-rules__fields textarea.is-typing {
  border-color: #86bca3;
  outline: 2px solid rgba(22, 125, 77, 0.1);
  outline-offset: 0;
}

.ai-rules__footer {
  display: flex;
  justify-content: flex-end;
  padding: 0 26px 24px;
}

.ai-rules__execute {
  height: 52px;
  min-width: 0;
  font-size: 17px;
  padding: 0 24px;
}

.ai-success {
  position: absolute;
  z-index: 40;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  border: 1px solid #b4d9c7;
  border-radius: 12px;
  background: #effaf4;
  color: #006d40;
  box-shadow: 0 8px 28px rgba(43, 56, 80, 0.14);
  font-size: 17px;
  font-weight: 650;
  transform: translate(-50%, -50%);
}

.ai-success span { font-size: 22px; }

/* One slow tint change, without flashes, fading text, movement or glow. */
@keyframes ai-word-alert {
  0%, 100% { background: rgba(212, 59, 69, 0.04); }
  50% { background: rgba(212, 59, 69, 0.10); }
}

@keyframes ai-group-highlight {
  0%, 100% { background: rgba(212, 59, 69, 0.02); }
  50% { background: rgba(212, 59, 69, 0.06); }
}

@keyframes ai-item-out { to { opacity: 0; transform: translateY(-4px) scale(0.97); } }

@media (max-width: 700px) {
  .ai-rules { padding: 12px; }
  .ai-rules__panel { border-radius: 12px; }
  .ai-rules__header { padding: 15px; gap: 10px; }
  .ai-rules__header h2 { font-size: 20px; }
  .ai-rules__fields { padding: 16px 15px; gap: 10px; }
  .ai-rules__fields label { font-size: 13px; line-height: 1.4; }
  .ai-rules__fields textarea { padding: 10px 12px; font-size: 16px; line-height: 1.4; }
  #ai-unsuitable { height: 224px; }
  .ai-rules__footer { padding: 0 15px 16px; }
  .ai-rules__execute { width: 100%; height: 44px; font-size: 14px; }
  .ai-success { padding: 11px 17px; font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  body[data-state="ai-marking"] .is-ai-selected,
  body[data-state="ai-filtering"] .is-ai-selected {
    animation: none;
    background: rgba(212, 59, 69, 0.07);
  }

  body[data-state="ai-marking"] .group-row__summary.is-ai-selected,
  body[data-state="ai-filtering"] .group-row__summary.is-ai-selected {
    animation: none;
    background: rgba(212, 59, 69, 0.04);
  }
}
