/* ============================================================
   AI Analyst (Sprint 1.22) — tokens + component styles
   ------------------------------------------------------------
   Scoped to .ai-analyst-* / .ai-overall-box / .ai-section-box /
   .ai-chip / .ai-analyst-cost-footer / .ai-analyst-replay-banner
   so nothing else in the portal is touched. Tokens layer on top
   of --color-action from styles.css; overriding them here keeps
   the AI surface visually distinct from the primary action blue
   if the product ever wants a different accent.
   ============================================================ */

/* Default (dark) + explicit light override mix the accent against the
   themed surface token so the tint reads correctly in either mode.
   Dark mode gets a heavier 16% mix because a 7% blend against the
   near-black --bg-surface (#151820) is almost invisible. */
:root {
  --color-ai-accent:    var(--color-action, #2563eb);
  --color-ai-accent-bg: color-mix(in srgb, var(--color-action, #2563eb) 16%, var(--bg-surface, #151820));
  --color-ai-chip-bg:   var(--color-action, #2563eb);
}

[data-theme="light"] {
  --color-ai-accent-bg: color-mix(in srgb, var(--color-action, #2563eb) 7%, var(--bg-surface, #ffffff));
}

[data-theme="dark"] {
  --color-ai-accent-bg: color-mix(in srgb, var(--color-action, #2563eb) 16%, var(--bg-surface, #151820));
}

/* ------------------------------------------------------------
   Floating Action Button — sits ABOVE the Feedback FAB
   Feedback FAB: right: 24px, bottom: 24px (52×52)
   AI FAB:       right: 24px, bottom: 96px (56×56)
   ------------------------------------------------------------ */
.ai-analyst-fab {
  position: fixed;
  right: 24px;
  bottom: 96px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  /* White FAB so the blue + purple sparkles read cleanly (matches reference).
     A subtle gradient overlay + multi-color halo shadow keeps it from
     blending into light backgrounds. */
  background:
    radial-gradient(circle at 30% 25%, rgba(26, 115, 232, 0.08), transparent 55%),
    radial-gradient(circle at 75% 80%, rgba(139, 92, 246, 0.10), transparent 55%),
    #ffffff;
  color: #1a73e8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 0 0 1px rgba(26, 115, 232, 0.08),
    0 10px 28px rgba(26, 115, 232, 0.22),
    0 4px 12px rgba(139, 92, 246, 0.18);
  z-index: 900;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  cursor: pointer;
  border: 0;
}

.ai-analyst-fab:hover {
  transform: translateY(-1px);
  box-shadow:
    0 0 0 1px rgba(26, 115, 232, 0.14),
    0 18px 40px rgba(26, 115, 232, 0.28),
    0 6px 18px rgba(139, 92, 246, 0.26);
}

.ai-analyst-fab.is-active {
  box-shadow:
    0 0 0 3px rgba(139, 92, 246, 0.28),
    0 10px 28px rgba(26, 115, 232, 0.22),
    0 4px 12px rgba(139, 92, 246, 0.18);
}

/* Dark-theme adjustment — keep sparkles bright on darker surface */
[data-theme="dark"] .ai-analyst-fab {
  background:
    radial-gradient(circle at 30% 25%, rgba(66, 133, 244, 0.18), transparent 55%),
    radial-gradient(circle at 75% 80%, rgba(168, 85, 247, 0.22), transparent 55%),
    #1b1f27;
  box-shadow:
    0 0 0 1px rgba(26, 115, 232, 0.24),
    0 10px 28px rgba(26, 115, 232, 0.28),
    0 4px 12px rgba(139, 92, 246, 0.26);
}

.ai-analyst-fab svg { display: inline-flex; }

.ai-analyst-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--color-brand, #CB222A);
  color: #ffffff;
  font-size: var(--font-xs, 11px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-base, #F4F5F7);
  line-height: 1;
}

/* ------------------------------------------------------------
   AI Analyst modal — mirrors Feedback modal structure
   ------------------------------------------------------------ */
.ai-analyst-modal { max-width: 640px; padding: 0; }

/* Header — title on the left, download + close on the right. Replaces
   the inherited feedback-modal__header so we can control spacing. */
.ai-analyst-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3, 12px);
  padding: 18px var(--space-5, 20px) 4px;
}
.ai-analyst-modal__title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  font-weight: 700;
  color: var(--text-primary, #111318);
}
.ai-analyst-modal__title-sub {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary, #5F6775);
}
.ai-analyst-modal__header-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.ai-analyst-modal__icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: transparent;
  border: 0;
  color: var(--text-secondary, #5F6775);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.ai-analyst-modal__icon-btn:hover {
  background: color-mix(in srgb, var(--color-action, #2563eb) 8%, transparent);
  color: var(--text-primary, #111318);
}

/* Tabs — sit right below the header, switch between Analyse / History */
.ai-analyst-modal__tabs {
  display: flex;
  gap: var(--space-4, 16px);
  padding: 0 var(--space-5, 20px);
  border-bottom: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.06));
  background: var(--bg-surface, #ffffff);
}
.ai-analyst-modal__tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 0;
  padding: 12px 0;
  margin: 0;
  font-size: var(--font-small, 13px);
  font-weight: 600;
  color: var(--text-tertiary, #8C95A4);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.ai-analyst-modal__tab:hover { color: var(--text-secondary, #5F6775); }
.ai-analyst-modal__tab.is-active {
  color: var(--text-primary, #111318);
  border-bottom-color: var(--color-action, #2563eb);
}
.ai-analyst-modal__tab-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--color-action, #2563eb) 12%, transparent);
  color: var(--color-action, #2563eb);
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.ai-analyst-modal__tab.is-active .ai-analyst-modal__tab-pill {
  background: color-mix(in srgb, var(--color-action, #2563eb) 18%, transparent);
}

.ai-analyst-modal__panel {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
.ai-analyst-modal__panel--history {
  padding: var(--space-3, 12px) var(--space-5, 20px) var(--space-4, 16px);
  background: var(--bg-elevated, #F8F9FB);
}

/* Meta strip — labeled stat blocks instead of middot soup */
.ai-analyst-modal__meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3, 12px);
  padding: var(--space-3, 12px) var(--space-5, 20px);
  border-bottom: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.06));
  background: linear-gradient(
    to bottom,
    color-mix(in srgb, var(--color-action, #2563eb) 3%, transparent),
    transparent
  );
}
.ai-analyst-modal__stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.ai-analyst-modal__stat-label {
  font-size: var(--font-xs, 11px);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary, #8C95A4);
}
.ai-analyst-modal__stat-value {
  font-size: var(--font-body, 14px);
  font-weight: 700;
  color: var(--text-primary, #111318);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-analyst-modal__stat-value--muted { color: var(--text-secondary, #5F6775); font-weight: 600; }
.ai-analyst-modal__stat-sub {
  font-size: var(--font-xs, 11px);
  color: var(--text-tertiary, #8C95A4);
  font-variant-numeric: tabular-nums;
}

.ai-analyst-modal__options {
  flex-direction: row !important;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3, 12px);
}
.ai-analyst-modal__lang {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2, 8px);
}
.ai-analyst-modal__radio,
.ai-analyst-modal__opus {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--font-small, 12px);
  color: var(--text-primary);
  cursor: pointer;
}
.ai-analyst-modal__radio input,
.ai-analyst-modal__opus input {
  accent-color: var(--color-action, #2563eb);
}

.feedback-field__hint.is-over {
  color: var(--color-brand, #CB222A);
  font-weight: 700;
}

/* ------------------------------------------------------------
   AI Analyst modal — Analyse panel (redesigned Sprint 1.22)
   Context band + prompt field + segmented controls + footer
   ------------------------------------------------------------ */

/* Context band — PERIOD (small, left) | COST (hero, centre) | SCOPE
   (small, muted, right). The hero cell is what the user actually needs
   before pulling the trigger: estimated cost of this run plus remaining
   quota. Period is reference, scope is reassurance. */
.ai-analyst-modal__context-band {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  align-items: center;
  gap: var(--space-4, 16px);
  margin: var(--space-3, 12px) var(--space-5, 20px) 0;
  padding: var(--space-4, 16px);
  border: 1px solid color-mix(in srgb, var(--color-action, #2563eb) 18%, transparent);
  border-radius: var(--radius-md, 10px);
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--color-action, #2563eb) 6%, transparent),
      color-mix(in srgb, var(--color-action, #2563eb) 2%, transparent));
}
.ai-analyst-modal__context-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.ai-analyst-modal__context-cell--hero {
  align-items: center;
  text-align: center;
  gap: 4px;
  padding: 0 var(--space-3, 12px);
  border-left: 1px solid color-mix(in srgb, var(--color-action, #2563eb) 15%, transparent);
  border-right: 1px solid color-mix(in srgb, var(--color-action, #2563eb) 15%, transparent);
}
.ai-analyst-modal__context-cell--side {
  gap: 2px;
}
.ai-analyst-modal__context-cell--muted .ai-analyst-modal__context-value,
.ai-analyst-modal__context-cell--muted .ai-analyst-modal__context-label {
  color: var(--text-tertiary, #8C95A4);
}
.ai-analyst-modal__context-cell--muted .ai-analyst-modal__context-value {
  font-weight: 600;
  font-size: var(--font-small, 13px);
}
.ai-analyst-modal__context-label {
  font-size: var(--font-xs, 11px);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary, #8C95A4);
}
.ai-analyst-modal__context-value {
  font-size: var(--font-body, 14px);
  font-weight: 700;
  color: var(--text-primary, #111318);
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.ai-analyst-modal__context-sub {
  font-size: var(--font-xs, 11px);
  color: var(--text-tertiary, #8C95A4);
  font-variant-numeric: tabular-nums;
}
/* Hero number — trimmed back; still the centrepiece but no longer the
   screaming 28px. Cost is a "nice to know", not a "stop the presses". */
.ai-analyst-modal__context-hero-value {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--color-action, #2563eb);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
/* VND equivalent directly under the hero USD — smaller muted sibling. */
.ai-analyst-modal__context-hero-vnd {
  font-size: var(--font-xs, 11px);
  font-weight: 500;
  color: var(--text-tertiary, #8C95A4);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

/* Body — the interactive block (prompt, meta, controls, actions). */
.ai-analyst-modal__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3, 12px);
  padding: var(--space-4, 16px) var(--space-5, 20px) 0;
}

.ai-analyst-modal__field { display: flex; flex-direction: column; gap: 6px; }
.ai-analyst-modal__field-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2, 8px);
}
.ai-analyst-modal__field-label {
  font-size: var(--font-body, 14px);
  font-weight: 700;
  color: var(--text-primary, #111318);
}
.ai-analyst-modal__field-counter {
  font-size: var(--font-xs, 11px);
  color: var(--text-tertiary, #8C95A4);
  font-variant-numeric: tabular-nums;
}
.ai-analyst-modal__field-counter.is-over {
  color: var(--color-brand, #CB222A);
  font-weight: 700;
}
.ai-analyst-modal__field textarea {
  width: 100%;
  min-height: 88px;
  padding: 10px 12px;
  font: inherit;
  font-size: var(--font-small, 13px);
  color: var(--text-primary, #111318);
  background: var(--bg-surface, #ffffff);
  border: 1px solid var(--border-default, rgba(0, 0, 0, 0.12));
  border-radius: var(--radius-md, 10px);
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.ai-analyst-modal__field textarea:focus {
  outline: none;
  border-color: var(--color-action, #2563eb);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-action, #2563eb) 18%, transparent);
}

.ai-analyst-modal__meta-line {
  font-size: var(--font-xs, 11px);
  color: var(--text-tertiary, #8C95A4);
  font-variant-numeric: tabular-nums;
  margin-top: -4px;
}

/* Controls row — MODEL and LANGUAGE as segmented pills. */
.ai-analyst-modal__controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4, 16px);
  flex-wrap: wrap;
}
.ai-analyst-modal__control-group {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2, 8px);
}
.ai-analyst-modal__control-label {
  font-size: var(--font-xs, 11px);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary, #8C95A4);
}
.ai-analyst-modal__segmented {
  display: inline-flex;
  background: color-mix(in srgb, var(--color-action, #2563eb) 6%, #F4F5F7);
  border-radius: 8px;
  padding: 3px;
}
.ai-analyst-modal__segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 6px 12px;
  font: inherit;
  font-size: var(--font-small, 13px);
  font-weight: 600;
  color: var(--text-secondary, #5F6775);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.ai-analyst-modal__segmented button.is-selected {
  background: var(--bg-surface, #ffffff);
  color: var(--color-action, #2563eb);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.ai-analyst-modal__segmented button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ai-analyst-modal__error { margin: 0; }

/* Actions — Cancel (ghost) + primary Analyse with a "+" prefix. */
.ai-analyst-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2, 8px);
  margin-top: 4px;
}
.ai-analyst-modal__btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  font: inherit;
  font-size: var(--font-small, 13px);
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.ai-analyst-modal__btn--ghost {
  background: var(--bg-surface, #ffffff);
  border-color: var(--border-default, rgba(0, 0, 0, 0.12));
  color: var(--text-primary, #111318);
}
.ai-analyst-modal__btn--ghost:hover {
  background: color-mix(in srgb, var(--color-action, #2563eb) 6%, transparent);
}
.ai-analyst-modal__btn--primary {
  background: color-mix(in srgb, var(--color-action, #2563eb) 70%, #ffffff);
  color: #ffffff;
}
.ai-analyst-modal__btn--primary:not(:disabled):hover {
  background: var(--color-action, #2563eb);
}
.ai-analyst-modal__btn--primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.ai-analyst-modal__btn-plus {
  display: inline-block;
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
  transform: translateY(-1px);
}

/* Footer disclaimer — always visible at the bottom of the panel. */
.ai-analyst-modal__footer {
  margin-top: var(--space-3, 12px);
  padding: 12px var(--space-5, 20px);
  border-top: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.06));
  font-size: var(--font-xs, 11px);
  color: var(--text-tertiary, #8C95A4);
}

/* ------------------------------------------------------------
   Analysing animations — the AI call can take 30–60s. Give the
   user a clearly-alive UI: breathing glow on the modal, shimmer
   + spinner on the primary button. Both are keyed off the
   `is-analysing` class toggled by `state.submitting`.
   ------------------------------------------------------------ */
@keyframes ai-modal-glow {
  0%, 100% {
    box-shadow:
      0 20px 50px -12px rgba(8, 10, 15, 0.35),
      0 0 0 1px color-mix(in srgb, var(--color-action, #2563eb) 28%, transparent),
      0 0 36px -6px color-mix(in srgb, var(--color-action, #2563eb) 30%, transparent);
  }
  50% {
    box-shadow:
      0 28px 70px -10px rgba(8, 10, 15, 0.40),
      0 0 0 1px color-mix(in srgb, var(--color-action, #2563eb) 55%, transparent),
      0 0 70px -2px color-mix(in srgb, var(--color-action, #2563eb) 55%, transparent);
  }
}
.ai-analyst-modal.is-analysing {
  animation: ai-modal-glow 2.4s ease-in-out infinite;
}

@keyframes ai-btn-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.ai-analyst-modal__btn--primary.is-analysing {
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--color-action, #2563eb) 70%, #ffffff) 0%,
    color-mix(in srgb, var(--color-action, #2563eb) 92%, #ffffff) 50%,
    color-mix(in srgb, var(--color-action, #2563eb) 70%, #ffffff) 100%
  );
  background-size: 200% 100%;
  animation: ai-btn-shimmer 1.8s linear infinite;
  opacity: 1; /* override :disabled dimming — we're "working", not "dead" */
  cursor: progress;
}
.ai-analyst-modal__btn--primary.is-analysing:disabled {
  opacity: 1;
}

@keyframes ai-btn-spin {
  to { transform: rotate(360deg); }
}
.ai-analyst-modal__btn-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: ai-btn-spin 0.8s linear infinite;
}

/* Honour the user's reduced-motion preference — the breathing /
   shimmer / spin are decorative, so switch to static indicators. */
@media (prefers-reduced-motion: reduce) {
  .ai-analyst-modal.is-analysing { animation: none; }
  .ai-analyst-modal__btn--primary.is-analysing {
    animation: none;
    background: var(--color-action, #2563eb);
  }
  .ai-analyst-modal__btn-spinner {
    animation: none;
    border-top-color: rgba(255, 255, 255, 0.6);
  }
}

/* ------------------------------------------------------------
   Completion dialog — full-screen blocking confirmation shown
   after submit() resolves. User must tick the acknowledgement
   AND press the button. No overlay-click dismiss, no auto-close,
   no X in the corner. This is deliberate: the insight is only
   as good as the data it was pulled from, and we want explicit
   buy-in that the reader understands that.
   ------------------------------------------------------------ */
.ai-completion-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 1400;
  background: rgba(8, 10, 15, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4, 16px);
  backdrop-filter: blur(2px);
}
.ai-completion-dialog {
  width: 100%;
  max-width: 460px;
  background: var(--bg-surface, #ffffff);
  border-radius: var(--radius-lg, 14px);
  padding: 28px 28px 22px;
  box-shadow:
    0 30px 70px -20px rgba(8, 10, 15, 0.45),
    0 8px 20px -8px rgba(16, 185, 129, 0.25);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3, 12px);
}
.ai-completion-dialog__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: color-mix(in srgb, #10B981 14%, transparent);
  color: #10B981;
  margin-bottom: 4px;
  animation: ai-completion-pop 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
/* Warning variant — used for the replay confirm dialog. */
.ai-completion-dialog__icon--warn {
  background: color-mix(in srgb, #f59e0b 14%, transparent);
  color: #d97706;
}
@keyframes ai-completion-pop {
  0%   { transform: scale(0.6); opacity: 0; }
  70%  { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}
.ai-completion-dialog__title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary, #111318);
  letter-spacing: -0.01em;
}
.ai-completion-dialog__text {
  margin: 0;
  font-size: var(--font-small, 13.5px);
  line-height: 1.5;
  color: var(--text-secondary, #5F6775);
  max-width: 380px;
}
.ai-completion-dialog__text p {
  margin: 0;
  padding: 2px 0;
}
.ai-completion-dialog__text strong {
  color: var(--text-primary, #111318);
  font-weight: 700;
}
/* Vietnamese sibling — divider above, slightly muted so the English
   block reads as primary but VI is still prominent enough to act on. */
.ai-completion-dialog__text--vi {
  padding-top: 8px;
  margin-top: 2px;
  border-top: 1px dashed color-mix(in srgb, var(--text-tertiary, #8C95A4) 35%, transparent);
  color: var(--text-secondary, #5F6775);
  font-style: normal;
}
.ai-completion-dialog__ack {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--color-action, #2563eb) 6%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-action, #2563eb) 18%, transparent);
  border-radius: var(--radius-md, 10px);
  text-align: left;
  font-size: var(--font-small, 12.5px);
  line-height: 1.45;
  color: var(--text-primary, #111318);
  cursor: pointer;
  width: 100%;
}
.ai-completion-dialog__ack input {
  flex: 0 0 auto;
  margin-top: 2px;
  accent-color: var(--color-action, #2563eb);
  cursor: pointer;
}
.ai-completion-dialog__actions {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 4px;
}
/* Two-button variant (Cancel + Confirm) used by the replay dialog. */
.ai-completion-dialog__actions--pair {
  gap: 10px;
}
.ai-completion-dialog__btn--ghost {
  background: var(--bg-surface, #ffffff);
  color: var(--text-primary, #111318);
  border: 1px solid var(--border-default, rgba(0, 0, 0, 0.12));
  box-shadow: none;
}
.ai-completion-dialog__btn--ghost:not(:disabled):hover {
  background: color-mix(in srgb, var(--color-action, #2563eb) 6%, transparent);
}
.ai-completion-dialog__btn {
  appearance: none;
  border: 0;
  padding: 10px 22px;
  font: inherit;
  font-size: var(--font-small, 13px);
  font-weight: 700;
  background: var(--color-action, #2563eb);
  color: #ffffff;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
  box-shadow: 0 8px 18px -6px color-mix(in srgb, var(--color-action, #2563eb) 45%, transparent);
}
.ai-completion-dialog__btn:not(:disabled):hover {
  background: color-mix(in srgb, var(--color-action, #2563eb) 85%, #000);
}
.ai-completion-dialog__btn:not(:disabled):active {
  transform: translateY(1px);
}
.ai-completion-dialog__btn:disabled {
  background: color-mix(in srgb, var(--color-action, #2563eb) 35%, #e2e5ec);
  cursor: not-allowed;
  box-shadow: none;
}

/* Fade + subtle scale-in */
.ai-completion-dialog-enter-from .ai-completion-dialog,
.ai-completion-dialog-leave-to .ai-completion-dialog {
  opacity: 0;
  transform: scale(0.94);
}
.ai-completion-dialog-enter-from,
.ai-completion-dialog-leave-to {
  opacity: 0;
}
.ai-completion-dialog-enter-active,
.ai-completion-dialog-leave-active {
  transition: opacity 0.2s ease;
}
.ai-completion-dialog-enter-active .ai-completion-dialog,
.ai-completion-dialog-leave-active .ai-completion-dialog {
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

@media (prefers-reduced-motion: reduce) {
  .ai-completion-dialog__icon { animation: none; }
  .ai-completion-dialog-enter-active .ai-completion-dialog,
  .ai-completion-dialog-leave-active .ai-completion-dialog {
    transition: opacity 0.2s ease;
    transform: none;
  }
}

/* History tab — compact rows stacked vertically. The scroll happens on
   .ai-analyst-modal__panel--history itself (flex-grow, overflow-y:auto),
   not here, so the first row's rounded top border isn't clipped by an
   inner scroll container's edge. */
.ai-analyst-modal__history-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2, 8px);
  padding-top: 2px;
}
.ai-analyst-modal__history-empty {
  padding: var(--space-4, 16px);
  text-align: center;
  color: var(--text-tertiary);
  font-size: var(--font-small, 12px);
  border: 1px dashed var(--border-default, rgba(0, 0, 0, 0.1));
  border-radius: var(--radius-md, 10px);
  background: var(--bg-surface, #fff);
}

/* History row — compact card with initial avatar */
.ai-history-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-surface, #ffffff);
  border: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.08));
  border-radius: var(--radius-md, 10px);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.ai-history-row:hover {
  border-color: var(--color-action, #2563eb);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.10);
  transform: translateY(-1px);
}
.ai-history-row:focus-visible {
  outline: 2px solid var(--color-action, #2563eb);
  outline-offset: 2px;
}

.ai-history-row__avatar {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  user-select: none;
}

.ai-history-row__body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ai-history-row__headline {
  font-size: var(--font-small, 13px);
  font-weight: 700;
  color: var(--text-primary, #111318);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ai-history-row__headline--empty {
  font-weight: 500;
  color: var(--text-tertiary, #8C95A4);
  font-style: italic;
}

.ai-history-row__brief {
  font-size: var(--font-small, 12px);
  color: var(--text-secondary, #5F6775);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ai-history-row__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}
.ai-history-row__chip {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-secondary, #5F6775);
  background: var(--bg-elevated, #F4F5F7);
  border: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.06));
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-history-row__meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--font-xs, 11px);
  color: var(--text-tertiary, #8C95A4);
  font-variant-numeric: tabular-nums;
}
.ai-history-row__author { color: var(--text-secondary, #5F6775); font-weight: 600; }
.ai-history-row__dot { opacity: 0.55; }
.ai-history-row__cost { color: var(--text-secondary, #5F6775); }

.ai-history-row__chevron {
  flex: 0 0 auto;
  align-self: center;
  font-size: 20px;
  line-height: 1;
  color: var(--text-tertiary, #8C95A4);
  transition: transform 0.15s ease, color 0.15s ease;
}
.ai-history-row:hover .ai-history-row__chevron {
  color: var(--color-action, #2563eb);
  transform: translateX(2px);
}

/* Dark theme tweaks */
[data-theme="dark"] .ai-history-row { background: var(--bg-surface, #1b1f27); }
[data-theme="dark"] .ai-analyst-modal__history { background: var(--bg-elevated, #151820); }

/* ------------------------------------------------------------
   Print styles — triggered when the user hits the Download
   button in the AI Analyst modal. Hides chrome (sidebar, FAB,
   modals, replay banner) so the PDF captures page + insights.
   ------------------------------------------------------------ */
@media print {
  body { background: #ffffff !important; }
  .feedback-modal-overlay,
  .ai-analyst-fab,
  .feedback-fab,
  .ai-analyst-replay-banner,
  .sidebar,
  .nav-sidebar,
  .mobile-nav,
  .nav-toggle {
    display: none !important;
  }
  .main-content,
  .app-main,
  .layout-main {
    margin-left: 0 !important;
    padding: 8mm 10mm !important;
    max-width: none !important;
  }
  .ai-overall-box,
  .ai-section-box {
    break-inside: avoid;
    box-shadow: none !important;
  }
}

/* ------------------------------------------------------------
   Insight cards — teleported into #analyst-overall-slot and
   [data-analyst-section-slot="..."] wrappers.
   ------------------------------------------------------------ */
/* Insight card — tinted gradient + glowing border matching the FAB family */
.ai-overall-box,
.ai-section-box {
  position: relative;
  padding: 18px 20px 20px;
  margin: 16px 0;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, #7c5cff 22%, transparent);
  background:
    radial-gradient(circle at 0% 0%, rgba(66, 133, 244, 0.10), transparent 55%),
    radial-gradient(circle at 100% 100%, rgba(168, 85, 247, 0.12), transparent 55%),
    var(--color-ai-accent-bg);
  box-shadow:
    0 0 0 1px color-mix(in srgb, #4285f4 10%, transparent),
    0 8px 24px rgba(66, 133, 244, 0.08),
    0 2px 8px rgba(168, 85, 247, 0.10);
  font-variant-numeric: tabular-nums;
  isolation: isolate;
}
[data-theme="dark"] .ai-overall-box,
[data-theme="dark"] .ai-section-box {
  border-color: color-mix(in srgb, #7c5cff 38%, transparent);
  box-shadow:
    0 0 0 1px color-mix(in srgb, #4285f4 18%, transparent),
    0 12px 32px rgba(66, 133, 244, 0.18),
    0 4px 12px rgba(168, 85, 247, 0.22);
}

.ai-overall-box .ai-overall-headline {
  font-size: var(--font-h3, 16px);
  font-weight: 700;
  margin: 8px 0 10px;
  color: var(--text-primary, #111318);
}

.ai-overall-bullets,
.ai-section-bullets {
  list-style: disc;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

.ai-overall-bullets li,
.ai-section-bullets li {
  font-size: var(--font-body, 14px);
  line-height: 1.55;
  color: var(--text-primary, #111318);
}

.ai-section-actions {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed color-mix(in srgb, var(--color-ai-accent) 25%, transparent);
  font-size: var(--font-small, 12px);
}

/* The "Suggested actions" label sits as a direct child of .ai-section-actions
   (see ai-analyst-insights.js). Scope to `>` so inline <strong> inside the
   action <li>s (emitted by the model per the v1.3 HTML contract) keeps
   normal inline emphasis instead of becoming an uppercase block label. */
.ai-section-actions > strong {
  display: block;
  font-size: var(--font-xs, 11px);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary, #5F6775);
  margin-bottom: 6px;
}

.ai-section-actions ul {
  list-style: disc;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ------------------------------------------------------------
   AI chip — small "AI" / "AI summary" label anchored top-right
   ------------------------------------------------------------ */
.ai-chip {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--color-ai-chip-bg);
  color: #ffffff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  line-height: 1.4;
}

/* ------------------------------------------------------------
   Per-run cost footer — teleported to #analyst-cost-footer-slot
   ------------------------------------------------------------ */
.ai-analyst-cost-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-tertiary, #8C95A4);
  font-size: var(--font-small, 12px);
  font-variant-numeric: tabular-nums;
  padding: 12px 24px;
  border-top: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.06));
  margin-top: 12px;
}

.ai-analyst-cost-footer__sep {
  opacity: 0.6;
}

/* ------------------------------------------------------------
   Replay banner — sticky strip reminding the user they are
   viewing a frozen past analysis.
   ------------------------------------------------------------ */
.ai-analyst-replay-banner {
  /* Teleported to <body> as a trailing child — sticky would anchor
     at the bottom of the document. Fixed pins it to the viewport top. */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fef3c7;
  color: #111318;
  padding: 10px 16px;
  border-bottom: 1px solid color-mix(in srgb, #b45309 25%, transparent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  z-index: 800;
  font-size: var(--font-small, 12px);
  font-variant-numeric: tabular-nums;
}

/* Push the page down while replay is active so the banner doesn't cover
   the top of the dashboard. The store toggles this class on <body>.
   The sidebar is `position: fixed; top: 0` so body padding can't move it
   — shift it explicitly. Same for the toast container. */
body.ai-replay-active {
  padding-top: 44px;
}
body.ai-replay-active .sidebar {
  top: 44px;
}
body.ai-replay-active .toast-container {
  top: calc(var(--space-4) + 44px);
}

.ai-analyst-replay-banner__icon {
  flex: 0 0 auto;
  font-size: 16px;
  line-height: 1;
  color: #b45309;
}

.ai-analyst-replay-banner__text {
  flex: 1;
  line-height: 1.4;
}

.ai-analyst-replay-banner__text strong {
  font-weight: 700;
}

.ai-analyst-replay-banner__sep {
  opacity: 0.5;
  margin: 0 4px;
}

.ai-analyst-replay-banner__close {
  background: none;
  border: 1px solid color-mix(in srgb, #b45309 35%, transparent);
  color: #111318;
  font-size: var(--font-small, 12px);
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-sm, 6px);
  cursor: pointer;
}

.ai-analyst-replay-banner__close:hover {
  background: color-mix(in srgb, #b45309 12%, transparent);
}

/* ------------------------------------------------------------
   Contextual text colors inside AI cards — model emits
   <strong>, <span class="ai-pos">, <span class="ai-neg">,
   <span class="ai-muted">. Sanitized server-side before render.
   ------------------------------------------------------------ */
.ai-overall-box strong,
.ai-section-box strong {
  font-weight: 700;
  color: var(--text-primary, #111318);
}
.ai-overall-box .ai-pos,
.ai-section-box .ai-pos {
  color: #10B981;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.ai-overall-box .ai-neg,
.ai-section-box .ai-neg {
  color: var(--color-brand, #CB222A);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.ai-overall-box .ai-muted,
.ai-section-box .ai-muted {
  color: var(--text-tertiary, #8C95A4);
  font-weight: 500;
}
[data-theme="dark"] .ai-overall-box .ai-pos,
[data-theme="dark"] .ai-section-box .ai-pos { color: #34d399; }
[data-theme="dark"] .ai-overall-box .ai-neg,
[data-theme="dark"] .ai-section-box .ai-neg { color: #f87171; }

/* "AI can make mistakes" disclaimer below the content of each card */
.ai-insight-disclaimer {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px dashed color-mix(in srgb, #7c5cff 22%, transparent);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--font-xs, 11px);
  letter-spacing: 0.02em;
  color: var(--text-tertiary, #8C95A4);
}
.ai-insight-disclaimer__dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4285f4, #a855f7);
}

/* ------------------------------------------------------------
   Mobile — tighten right offset so FAB doesn't clip bottom nav
   ------------------------------------------------------------ */
@media (max-width: 768px) {
  .ai-analyst-fab {
    bottom: 140px;   /* leaves room above feedback fab + bottom nav */
    right: 16px;
    width: 52px;
    height: 52px;
  }
}
