/*
 * AI summary block — shared visual treatment for every Phase 4 surface.
 *
 * Lives inside tool result regions (between score and metrics, after
 * the headline). Distinct accent panel so users perceive AI output as
 * "explanatory" rather than "definitive data".
 *
 * Variants:
 *   .ai-summary--loading — spinner + label while fetching
 *   .ai-summary--ready   — header (icon + title + provider badge) + body
 *   .ai-summary--quota   — soft paywall nudge
 *   .ai-summary           hidden by default until JS unhides
 *
 * Plus the EN-only consent modal (.ai-consent-modal *).
 */

/* ── Container ─────────────────────────────────────────────────────── */
.ai-summary {
  margin: var(--space-stack, 20px) 0;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm, 7px);
  color: var(--text);
  font-size: var(--fs-sm, 14px);
  line-height: 1.55;
}

/* Hidden initial state (consumed JS-side). */
.ai-summary.hidden,
[id^="ai"][id$="Summary"].hidden {
  display: none;
}

/* ── Header (icon + title + provider badge + cache badge) ──────────── */
.ai-summary__head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: var(--fs-xs, 12px);
  color: var(--muted2);
}
.ai-summary__icon {
  color: var(--accent);
  flex-shrink: 0;
}
.ai-summary__title {
  font-weight: 600;
  color: var(--text);
  letter-spacing: .02em;
}
.ai-summary__provider {
  padding: 2px 8px;
  background: var(--accent-glow-08, rgba(91, 138, 248, .08));
  border-radius: 999px;
  font-size: var(--fs-2xs, 11px);
  font-weight: 500;
  color: var(--accent);
}
.ai-summary__badge {
  padding: 2px 8px;
  background: rgba(255, 255, 255, .04);
  border-radius: 999px;
  font-size: var(--fs-2xs, 11px);
  color: var(--muted);
}
.ai-summary__badge--cache {
  color: var(--green, #34d399);
}

/* ── Body (paragraph text + light prose styling) ──────────────────── */
.ai-summary__body p {
  margin: 0 0 8px;
}
.ai-summary__body p:last-child {
  margin-bottom: 0;
}
.ai-summary__body strong {
  font-weight: 600;
  color: var(--accent, #5b8af8);
  letter-spacing: .01em;
}
.ai-summary__body code {
  font-family: var(--mono, 'JetBrains Mono', monospace);
  font-size: .88em;
  padding: 2px 6px;
  background: rgba(91, 138, 248, .08);
  border: 1px solid rgba(91, 138, 248, .18);
  border-radius: 4px;
  color: var(--cyan, #22d3ee);
  word-break: break-word;
  white-space: pre-wrap;
}

/* ── Footer disclaimer ───────────────────────────────────────────── */
.ai-summary__foot {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: var(--fs-2xs, 11px);
  color: var(--muted);
}

/* ── Loading state ───────────────────────────────────────────────── */
.ai-summary--loading {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted2);
  font-style: italic;
}
.ai-summary__spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent-glow-20, rgba(91, 138, 248, .2));
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ai-summary-spin .8s linear infinite;
}
@keyframes ai-summary-spin {
  to { transform: rotate(360deg); }
}

/* ── Quota-exceeded soft paywall ──────────────────────────────────── */
.ai-summary--quota {
  border-left-color: var(--yellow, #fbbf24);
}
.ai-summary__nudge {
  color: var(--muted2);
}
.ai-summary__nudge a {
  color: var(--accent);
  font-weight: 600;
}

/* ── EN-only consent modal ───────────────────────────────────────── */
.ai-consent-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .2s ease-out;
  pointer-events: none;
}
.ai-consent-modal.is-open {
  opacity: 1;
  pointer-events: auto;
}
.ai-consent-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .65);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.ai-consent-modal__card {
  position: relative;
  width: min(520px, calc(100vw - 32px));
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px 28px 22px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
.ai-consent-modal__title {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}
.ai-consent-modal__lede {
  margin: 0 0 16px;
  color: var(--text2);
  line-height: 1.5;
}
.ai-consent-modal__bullets {
  margin: 0 0 20px;
  padding-left: 20px;
  font-size: var(--fs-sm, 14px);
  line-height: 1.55;
  color: var(--text2);
}
.ai-consent-modal__bullets li {
  margin-bottom: 8px;
}
.ai-consent-modal__bullets strong {
  color: var(--text);
}
.ai-consent-modal__actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-bottom: 14px;
}
.ai-consent-modal__btn {
  min-height: 40px;
  padding: 8px 18px;
  font-size: var(--fs-sm, 14px);
  font-weight: 600;
  border-radius: var(--radius-sm, 7px);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.ai-consent-modal__btn:hover { transform: translateY(-1px); }
.ai-consent-modal__btn--secondary {
  background: var(--surface2);
  color: var(--text2);
  border-color: var(--border2);
}
.ai-consent-modal__btn--secondary:hover { background: var(--border); }
.ai-consent-modal__btn--primary {
  background: linear-gradient(135deg, #22d3ee 0%, var(--accent) 50%, var(--accent2) 100%);
  color: var(--white, #fff);
}
.ai-consent-modal__note {
  margin: 0;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  font-size: var(--fs-2xs, 11px);
  color: var(--muted);
  line-height: 1.4;
}

/* ── AI quick-jump button (in result-toolbar) ─────────────────────── */
/*
 * The ✨ AI button rendered by `result-toolbar.js` next to JSON/Share
 * gives a one-click scroll to the AI summary block. While AI is still
 * loading (or consent blocked), the button briefly flashes a "pending"
 * tint instead of jumping nowhere.
 */
.ai-jump-btn {
  position: relative;
  color: var(--accent);
}
.ai-jump-btn:hover {
  border-color: var(--accent-glow-25, rgba(91, 138, 248, .3));
  background: var(--accent-glow-08, rgba(91, 138, 248, .08));
}
.ai-jump-btn.is-pending {
  animation: ai-jump-pulse .6s ease-out;
}
@keyframes ai-jump-pulse {
  0%   { background: var(--accent-glow-08, rgba(91, 138, 248, .08)); }
  50%  { background: var(--accent-glow-20, rgba(91, 138, 248, .25)); }
  100% { background: var(--accent-glow-08, rgba(91, 138, 248, .08)); }
}

/* Highlight pulse on the AI block when user jumps to it from the toolbar */
.ai-summary.is-highlight,
[id^="ai"][id$="Summary"].is-highlight .ai-summary {
  animation: ai-block-highlight 1.2s ease-out;
}
@keyframes ai-block-highlight {
  0%   { box-shadow: 0 0 0 0 var(--accent-glow-30, rgba(91, 138, 248, .35)); }
  60%  { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ── Reduced-motion ──────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .ai-summary__spinner { animation: none; }
  .ai-consent-modal { transition: none; }
  .ai-jump-btn.is-pending,
  .ai-summary.is-highlight,
  [id^="ai"][id$="Summary"].is-highlight .ai-summary { animation: none; }
}
