/* Universal AI refine ("sparkle") — floating chrome anchored to the focused
   textarea / Trix editor by ai_refine_controller.js. Everything is
   position:fixed and re-anchored on scroll/resize; when the field lives in
   an open <dialog> the nodes are re-parented into it (top layer). Colors are
   tokens so the dark theme adapts for free. */

/* Just the sparkles glyph — no chip, no halo. The icon itself is the
   affordance, in the app's gold "act on this" accent, with a slow glow
   pulse to give it life without demanding attention. */
.ai-refine-btn {
  position: fixed;
  z-index: 1052; /* above the area-interview overlay + dictate FAB (1051) */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  padding: 4px;
  margin: 0;
  cursor: pointer;
  color: var(--gold);
  font-size: 1.05rem;
  line-height: 1;
  transition: transform 120ms ease, color 120ms ease;
  animation: ai-refine-glow 5s ease-in-out infinite;
}

.ai-refine-btn:hover {
  transform: scale(1.15);
  color: var(--gold-dark);
}

.ai-refine-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
  border-radius: 4px;
}

@keyframes ai-refine-glow {
  0%, 100% { filter: brightness(1)    drop-shadow(0 0 0 rgba(223, 154, 50, 0)); }
  50%      { filter: brightness(1.2) drop-shadow(0 0 6px rgba(223, 154, 50, 0.45)); }
}

.ai-refine-menu {
  position: fixed;
  z-index: 1053;
  display: flex;
  flex-direction: column;
  min-width: 240px;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 0.4rem;
  box-shadow: 0 18px 44px rgba(19, 19, 19, 0.18), 0 2px 8px rgba(19, 19, 19, 0.08);
  color: var(--text-dark);
  font-size: calc(0.9rem + var(--text-bump));
}

.ai-refine-menu-header {
  font-family: var(--font-ui);
  font-size: calc(0.72rem + var(--text-bump));
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  padding: 0.4rem 0.6rem 0.5rem;
}

.ai-refine-menu-header .bi {
  margin-right: 0.35rem;
  color: var(--gold);
}

.ai-refine-menu > button {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  background: transparent;
  border: none;
  color: inherit;
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  font-size: calc(0.9rem + var(--text-bump));
  cursor: pointer;
  transition: background 100ms ease, color 100ms ease;
}

.ai-refine-menu > button .bi {
  width: 1.1rem;
  text-align: center;
  color: var(--text-muted);
}

.ai-refine-menu > button:hover {
  background: var(--teal-light);
  color: var(--navy-primary);
}

.ai-refine-menu > button:hover .bi {
  color: var(--teal-accent);
}

.ai-refine-hint {
  margin-left: auto;
  font-size: calc(0.72rem + var(--text-bump));
  color: var(--text-muted);
}

.ai-refine-menu-divider {
  height: 1px;
  background: var(--border-light);
  margin: 0.3rem 0.2rem;
}

/* "Reword to at most [10][25][50][100] words" — the roadmap-box move.
   Chips run inline so the whole row reads as one sentence. */
.ai-refine-fit-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0.45rem 0.6rem 0.5rem;
}

.ai-refine-fit-label {
  font-size: calc(0.8rem + var(--text-bump));
  color: var(--text-muted);
}

.ai-refine-chips {
  display: inline-flex;
  gap: 0.25rem;
}

.ai-refine-chip {
  border: 1px solid var(--border-light);
  background: var(--bg-secondary);
  color: var(--text-dark);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: calc(0.8rem + var(--text-bump));
  font-weight: 600;
  cursor: pointer;
  transition: background 100ms ease, border-color 100ms ease, color 100ms ease;
}

.ai-refine-chip:hover {
  background: var(--gold-light);
  border-color: var(--gold);
  color: var(--gold-dark);
}

/* Custom word limit: type a number, press Enter. Same chip silhouette. */
.ai-refine-chip-input {
  width: 3.2em;
  text-align: center;
  cursor: text;
  -moz-appearance: textfield;
  appearance: textfield;
}

.ai-refine-chip-input::-webkit-outer-spin-button,
.ai-refine-chip-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.ai-refine-chip-input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.ai-refine-chip-input:focus {
  outline: none;
  border-color: var(--gold);
  background: var(--bg-primary);
}

/* Status strip below the field: loading note, Keep/Undo decision, or error. */
.ai-refine-status {
  position: fixed;
  z-index: 1053;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.7rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  color: var(--text-dark);
  font-size: calc(0.82rem + var(--text-bump));
  box-shadow: 0 8px 24px rgba(19, 19, 19, 0.14);
  animation: ai-refine-status-in 200ms ease-out;
}

@keyframes ai-refine-status-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ai-refine-status-msg { flex: 1; }

.ai-refine-status-spinner {
  color: var(--gold);
  animation: ai-refine-glow 1.2s ease-in-out infinite;
}

.ai-refine-status-keep,
.ai-refine-status-undo,
.ai-refine-status-close {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.2rem 0.65rem;
  font-size: calc(0.78rem + var(--text-bump));
  font-weight: 600;
  cursor: pointer;
}

/* Keep is the primary action — filled gold so the eye lands there first. */
.ai-refine-status-keep {
  background: var(--gold);
  border-color: var(--gold);
  color: #fff;
}

.ai-refine-status-keep:hover {
  background: var(--gold-dark);
  border-color: var(--gold-dark);
}

.ai-refine-status-undo {
  color: var(--text-dark);
}

.ai-refine-status-undo:hover {
  border-color: var(--border-light);
  background: var(--bg-secondary);
}

.ai-refine-status-close {
  color: var(--text-muted);
  padding: 0.2rem 0.4rem;
}

.ai-refine-status--loading { border-color: var(--gold); }

.ai-refine-status--success { border-color: var(--teal-accent); }

.ai-refine-status--error {
  border-color: #c0392b;
}

.ai-refine-status--error .ai-refine-status-msg {
  color: #c0392b;
}

/* Faint gold shimmer on the field while the rewrite is in flight. */
textarea.ai-refine-active,
trix-editor.ai-refine-active {
  background-image: linear-gradient(110deg,
    rgba(223, 154, 50, 0) 0%,
    rgba(223, 154, 50, 0.05) 45%,
    rgba(223, 154, 50, 0.16) 50%,
    rgba(223, 154, 50, 0.05) 55%,
    rgba(223, 154, 50, 0) 100%);
  background-size: 220% 100%;
  animation: ai-refine-shimmer 1.6s linear infinite;
}

@keyframes ai-refine-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}
