/* ===================================
   BPI Newsletter - Modern Redesign
   Fresh, professional, accessible
   =================================== */

:root {
  /* Dark theme - Modern indigo/teal palette */
  --bg: #0f1419;
  --bg-elevated: #1a1f2e;
  --card: #1e2533;
  --card-hover: #242b3d;
  --ink: #e8ecf4;
  --ink-muted: #9ca3af;
  --ink-dim: #6b7280;

  /* Brand colors - Vibrant but professional */
  --primary: #3b82f6;
  /* Blue */
  --primary-hover: #2563eb;
  --primary-light: #60a5fa;
  --accent: #8b5cf6;
  /* Violet */
  --accent-hover: #7c3aed;
  --accent-light: #a78bfa;

  /* Semantic colors */
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;

  /* UI elements */
  --border: #2d3748;
  --border-light: #374151;
  --input-bg: #111827;
  --editor-bg: #0d1117;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6), 0 10px 10px -5px rgba(0, 0, 0, 0.4);

  /* Border radius - Subtle, not pill-shaped */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
}

body[data-theme="light"] {
  /* Light theme - Clean and bright */
  --bg: #e4eaf7;
  --bg-elevated: #ffffff;
  --card: #ffffff;
  --card-hover: #f1f5f9;
  --ink: #0f172a;
  --ink-muted: #64748b;
  --ink-dim: #94a3b8;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #3b82f6;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-light: #8b5cf6;

  --success: #059669;
  --warning: #d97706;
  --error: #dc2626;

  --border: #e2e8f0;
  --border-light: #cbd5e1;
  --input-bg: #f8fafc;
  --editor-bg: #ffffff;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.12), 0 10px 10px -5px rgba(0, 0, 0, 0.06);
}

/* ===================================
   Base Styles
   =================================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: var(--primary-light);
}

code {
  background: var(--input-bg);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
}

/* ===================================
   Layout
   =================================== */

.wrap {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 24px 120px;   /* no top padding — hero image sits flush at top */
}

@media (max-width: 768px) {
  .wrap {
    padding: 0 16px 80px;
  }
}

/* ===================================
   Header
   =================================== */

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--ink);
}

@media (max-width: 640px) {
  h1 {
    font-size: 1.25rem;
  }
}

/* Header Actions (Auth) */
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-email {
  font-size: 0.875rem;
  color: var(--ink-muted);
  font-weight: 400;
}

.btn-logout {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-logout:hover {
  background: var(--card-hover);
  border-color: var(--border-light);
  transform: translateY(-1px);
}

.btn-logout:active {
  transform: translateY(0);
}

@media (max-width: 768px) {
  .user-email {
    display: none;
    /* Hide email on mobile */
  }
}

.hero {
  width: 100%;
  border-radius: var(--radius-xl);
  overflow: hidden;
  margin: 0 0 16px;        /* tight gap between logo and workspace title */
  line-height: 0;           /* collapse inline spacing below <img> */
}

.hero picture,
.hero img {
  display: block;
  width: 100%;
  height: auto;   /* image dictates its own height */
  object-fit: cover;
  border-radius: var(--radius-xl);
}

.hero .label {
  padding: 16px;
  text-align: center;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* ===================================
   Cards
   =================================== */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

/* ===================================
   Controls & Forms
   =================================== */

.controls {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 140px;
}

.control-group.flex-grow {
  flex: 1;
  min-width: 220px;
}

.control-group.fetch-group {
  flex: 0 0 auto;
}

label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

input,
select {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  transition: all 0.15s ease;
  font-family: inherit;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

input::placeholder {
  color: var(--ink-dim);
}

/* ===================================
   Buttons
   =================================== */

.btn {
  appearance: none;
  border-radius: var(--radius-md);
  padding: 10px 20px;
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  font-family: inherit;
  white-space: nowrap;
  position: relative;
}

/* Spinner overlay for in-flight state */
.btn--loading {
  color: transparent !important;
  pointer-events: none;
}
.btn--loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btnSpin 0.7s linear infinite;
}
@keyframes btnSpin {
  to { transform: rotate(360deg); }
}

.btn:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.btn:active {
  transform: translateY(1px);
}

/* Primary button */
.btn.primary {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: var(--shadow-md);
}

.btn.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Secondary button */
.btn.secondary {
  background: transparent;
  color: var(--primary);
  border-color: var(--border-light);
}

.btn.secondary:hover {
  background: var(--card-hover);
  border-color: var(--primary);
}

/* Accent button - "Ready to Publish" with subtle violet styling */
.btn.accent {
  background: rgba(139, 92, 246, 0.08);
  color: var(--ink);
  border: 1.5px solid var(--accent-hover);
  font-weight: 500;
  transition: all 0.2s ease;
}

.btn.accent:hover {
  background: rgba(139, 92, 246, 0.15);
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.2);
  animation: wiggle 0.3s ease-in-out;
}

.btn.accent:active {
  transform: scale(0.98);
  background: rgba(139, 92, 246, 0.2);
}

.btn.accent:disabled {
  background: rgba(139, 92, 246, 0.03);
  border-color: rgba(124, 58, 237, 0.3);
  color: rgba(0, 0, 0, 0.4);
  cursor: not-allowed;
  opacity: 0.6;
}

/* Ghost button */
.btn.ghost {
  background: transparent;
  color: var(--ink-muted);
  border-color: var(--border);
}

.btn.ghost:hover {
  background: var(--card-hover);
  color: var(--ink);
  border-color: var(--border-light);
}

/* Theme toggle */
.toggle {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: var(--radius-md);
  padding: 6px 14px;
  /* match btn-logout */
  cursor: pointer;
  font-size: 0.875rem;
  /* match btn-logout */
  transition: all 0.15s ease;
  height: auto;
  align-self: center;
}

.toggle:hover {
  background: var(--card-hover);
  border-color: var(--border-light);
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 8px;
  padding: 4px 10px;
  border-radius: var(--radius-lg);
  font-size: 0.8125rem;
  font-weight: 700;
  color: #ffffff;
  background: var(--primary);
  min-width: 24px;
}

/* ===================================
   Article Cards Grid
   =================================== */

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 20px;
}

@media (max-width: 980px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

.article-card {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.article-card:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.article-card.selected {
  border-color: var(--primary);
  background: var(--card-hover);
  box-shadow: 0 0 0 1px var(--primary);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.card-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary);
}

.card-link {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--primary);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.card-link:hover {
  background: var(--primary);
  color: #ffffff;
}

.card-meta {
  font-size: 0.8125rem;
  color: var(--ink-dim);
  margin-bottom: 8px;
}

.card-title {
  font-weight: 700;
  font-size: 0.9375rem;
  line-height: 1.4;
  margin-bottom: 8px;
  color: var(--ink);
}

.card-snippet {
  font-size: 0.875rem;
  color: var(--ink-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===================================
   Action Panel
   =================================== */

.action-panel {
  margin-top: 24px;
}

.panel-header {
  margin-bottom: 16px;
}

.writing-controls {
  margin-bottom: 16px;
}

.control-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* Action row: buttons (left) + pipeline visualization (right, always visible) */
.action-row {
  display: flex;
  align-items: flex-start;  /* top-anchor so button tops and pipeline track top are on the same line */
  gap: 20px;
  flex-wrap: wrap;
}

.action-buttons {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* ===================================
   Output Section
   =================================== */

.output-section {
  margin-top: 24px;
}

.output-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

/* Version Tabs - Professional design */
.version-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.version-tab {
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--ink-muted);
  padding: 6px 14px;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.version-tab:hover {
  background: var(--card-hover);
  border-color: var(--border-light);
  color: var(--ink);
}

.version-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

/* Toolbar - Professional edit controls */
.toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px;
  background: var(--input-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.btn-tool {
  appearance: none;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.15s ease;
  min-width: 36px;
}

.btn-tool:hover {
  background: var(--card-hover);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-tool:active {
  transform: scale(0.95);
}

.btn-clear {
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink-muted);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-left: auto;
}

.btn-clear:hover {
  background: var(--card-hover);
  color: var(--ink);
  border-color: var(--border-light);
}

/* Editor */
.editor {
  min-height: 300px;
  padding: 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--editor-bg);
  font-size: 0.9375rem;
  line-height: 1.7;
  color: var(--ink);
  overflow-y: auto;
}

.editor:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.editor:empty:before {
  content: 'Text display area';
  color: var(--ink-dim);
}

/* ===================================
   Utilities
   =================================== */

.meta {
  font-size: 0.875rem;
  color: var(--ink-muted);
}

.hidden {
  display: none !important;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.footer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.875rem;
  color: var(--ink-dim);
}

/* ===================================
   Animations
   =================================== */

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.article-card {
  animation: fadeIn 0.3s ease;
}

/* ===================================
   Responsive Adjustments
   =================================== */

@media (max-width: 768px) {
  .control-row {
    flex-direction: column;
  }

  .control-group {
    width: 100%;
  }

  .action-row {
    flex-direction: column;
    align-items: stretch;
  }

  .action-buttons {
    flex-direction: column;
    align-items: stretch;
  }

  .action-buttons .btn {
    width: 100%;
  }

  .agent-pipeline {
    min-width: 0;
    width: 100%;
  }

  .toolbar {
    justify-content: center;
  }

  .btn-clear {
    margin-left: 0;
    width: 100%;
  }
}

/* ===================================
   Print Styles
   =================================== */

@media print {

  .controls,
  .action-panel,
  .toolbar,
  .toggle,
  .footer {
    display: none !important;
  }

  .editor {
    border: none;
    min-height: auto;
  }
}

/* --- Canonical typography for injected newsletter HTML --- */
#editor {
  /* robust, cross-platform sans stack */
  --bpi-font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  font-family: var(--bpi-font-sans);
  line-height: 1.65;
  /* unitless → better inheritance */
}

/* Keep margins and rhythm consistent inside injected content */
#editor p {
  margin: 0 0 1em;
}

#editor li {
  margin: 0.25em 0;
}

#editor h1,
#editor h2,
#editor h3 {
  line-height: 1.25;
}

.app-footer {
  margin-top: 40px;
  padding: 20px 0 32px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  color: var(--muted-foreground, #667085);
  font-size: 0.95rem;
}

.app-footer .footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}

.app-footer a {
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}

.app-footer a:hover {
  border-bottom-style: solid;
}

.app-footer .footer-line {
  margin: 4px 0;
  line-height: 1.5;
}


/* ===================================
   Particle Wave Loader
   =================================== */

.loader-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  background: transparent;
  opacity: 0;
  pointer-events: none;
  /* Let clicks pass through when hidden */
  transition: opacity 0.5s ease;
  border-radius: var(--radius-md);
  /* Match editor border radius */
  min-height: 300px;
  /* Match editor min-height */
  overflow: hidden;
  /* Prevent particles from spilling outside */
}

.loader-overlay.visible {
  opacity: 1;
  pointer-events: all;
  /* Block interactions when visible */
}

/* Ensure canvas fills the container */
.loader-overlay canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100% !important;
  height: 100% !important;
  z-index: 0;
  border-radius: var(--radius-md);
}

@keyframes pulse {
  0% {
    opacity: 0.7;
    transform: scale(0.98);
  }

  50% {
    opacity: 1;
    transform: scale(1.02);
  }

  100% {
    opacity: 0.7;
    transform: scale(0.98);
  }
}

/* Animated dots for status messages */
@keyframes dotPulse {

  0%,
  20% {
    content: '';
  }

  40% {
    content: '.';
  }

  60% {
    content: '..';
  }

  80%,
  100% {
    content: '...';
  }
}

.status-dots::after {
  content: '';
  animation: dotPulse 1.5s infinite;
}

/* Status message styling */
.status-message {
  color: #8b5cf6;
  /* Violet color */
  font-weight: 500;
}

.hidden {
  display: none !important;
}

font-size: 0.85rem;
}

.app-footer .sep {
  margin: 0 8px;
  opacity: 0.65;
}

/* Light/Dark subtlety */
@media (prefers-color-scheme: dark) {
  .app-footer {
    border-top-color: rgba(255, 255, 255, 0.12);
  }
}

/* Manual Story Form Animations */
#manualFormContainer {
  animation: slideDown 0.3s ease;
  overflow: hidden;
}

@keyframes slideDown {
  from {
    max-height: 0;
    opacity: 0;
  }

  to {
    max-height: 1000px;
    opacity: 1;
  }
}

/* Manual Story Upload Badge in Cards */
.manual-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--accent);
  color: #ffffff;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
}

/* Form textarea specific styles */
#manualContent:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ===================================
   Enhanced Toolbar Styling
   =================================== */

/* Toolbar Container */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  /* Remove horizontal padding, align with grid */
  margin: 0;
  /* Remove margins that broke alignment */
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: nowrap;
  /* Force single deck */
  width: 100%;
  /* Restore full width */
  overflow-x: auto;
  /* Handle overflow gracefully */
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  /* Hide scrollbar for cleaner look */
}

/* Hide scrollbar for Chrome/Safari/Opera */
.toolbar::-webkit-scrollbar {
  display: none;
}

/* Format Dropdown */
.format-select {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
  /* Fix mangled layout on small screens */
  max-width: 130px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.format-select:hover {
  border-color: var(--primary);
  background: var(--card-hover);
}

.format-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Toolbar Divider */
.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

/* Color Picker Wrapper */
.color-picker-wrapper {
  position: relative;
  display: inline-block;
}

.hidden-color-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

/* AI Button Styling - Subtle transparent violet with wiggle */
.btn-ai {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px !important;
  background: rgba(139, 92, 246, 0.08);
  /* Light transparent violet */
  color: var(--ink) !important;
  /* Black text for legibility */
  border: 1.5px solid var(--accent-hover);
  /* Dark violet border */
  transition: all 0.2s ease;
  min-width: 100px;
  justify-content: center;
  flex-shrink: 0;
  white-space: nowrap;
  font-weight: 500;
}

/* Inactive state - when editor is empty */
.btn-ai:disabled {
  background: rgba(139, 92, 246, 0.03);
  border-color: rgba(124, 58, 237, 0.3);
  color: rgba(0, 0, 0, 0.4) !important;
  cursor: not-allowed;
  opacity: 0.6;
}

/* Active/Hover state - wiggle animation */
.btn-ai:not(:disabled):hover {
  background: rgba(139, 92, 246, 0.15);
  border-color: var(--accent);
  animation: wiggle 0.3s ease-in-out;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.2);
}

.btn-ai:not(:disabled):active {
  transform: scale(0.98);
  background: rgba(139, 92, 246, 0.2);
}

/* Loading state - keep existing behavior */
.btn-ai.btn-loading {
  background: rgba(139, 92, 246, 0.12);
  border-color: var(--accent-light);
  cursor: wait;
  opacity: 0.9;
}

/* Wiggle animation on interaction */
@keyframes wiggle {
  0%, 100% {
    transform: translateX(0) rotate(0deg);
  }
  25% {
    transform: translateX(-2px) rotate(-1deg);
  }
  75% {
    transform: translateX(2px) rotate(1deg);
  }
}

.ai-badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  background: rgba(139, 92, 246, 0.15);
  /* Subtle violet for badge */
  border-radius: var(--radius-sm);
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--accent-hover);
}

/* Spinner Animation */
@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(129, 140, 248, 0.3);
  border-radius: 50%;
  border-top-color: #818cf8;
  animation: spin 0.8s linear infinite;
  margin-right: 6px;
}

/* ===================================
   AI-Injected Content Styling
   =================================== */

/* AI Shortened Text & Fact-Check & Stylesheet (Blue Theme) */
.ai-shortened,
.ai-factcheck,
.ai-stylesheet {
  color: var(--ink);
  background: rgba(59, 130, 246, 0.05);
  /* Light Blue Background */
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-md);
  margin: 16px 0;
  font-size: 0.9375rem;
  line-height: 1.7;
  transition: all 0.2s ease;
  overflow: hidden;
}

.ai-shortened:hover,
.ai-factcheck:hover,
.ai-stylesheet:hover {
  background: rgba(59, 130, 246, 0.08);
  /* Slightly darker on hover */
  box-shadow: var(--shadow-sm);
}

.ai-box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(59, 130, 246, 0.1);
  border-bottom: 1px solid rgba(59, 130, 246, 0.1);
}

.ai-box-controls {
  display: flex;
  gap: 6px;
}

.ai-box-btn {
  background: transparent;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9rem;
  transition: all 0.15s ease;
}

.ai-box-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--primary);
}

.ai-box-content {
  padding: 12px 16px;
}

/* Fact Verdict styling override for text */
.fact-verdict-correct {
  color: var(--success);
  font-weight: 600;
}

.fact-verdict-incorrect {
  color: var(--warning);
  font-weight: 600;
}

.fact-verdict-mixed {
  color: var(--warning);
  font-weight: 600;
}

/* Links in fact-check results */
.ai-factcheck a {
  color: var(--primary);
  text-decoration: underline;
  transition: color 0.15s ease;
}

.ai-factcheck a:hover {
  color: var(--primary-light);
}

/* Status dots animation (for loading states)
   Fixed-width inline-block so the preceding text never shifts position.
   Content cycles inside a reserved 1.5ch box — layout stays locked. */
@keyframes statusDots {
  0%,  24% { content: '.'; }
  25%, 49% { content: '..'; }
  50%, 74% { content: '...'; }
  75%,100% { content: ''; }
}

.status-dots {
  display: inline-block;
  width: 1.5ch;          /* always reserves space for "..." — text never shifts */
  overflow: hidden;
  vertical-align: bottom;
  text-align: left;
}

.status-dots::after {
  content: '';
  animation: statusDots 1.2s steps(1, end) infinite;
}
/* === Injected-info highlights (Opinionated mode) ===
   Rendered by injection_detector after writer completes.
   Categories: fact_claim | opinion | persona_colour | connective
   Only fact_claim spans carry a clickable fact-check badge. */
.nl-injected {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-bottom: 1px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: 2px;
  padding: 0 1px;
}
.nl-injected[data-injected-category="persona_colour"],
.nl-injected[data-injected-category="connective"] {
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  border-bottom-color: color-mix(in srgb, var(--accent) 30%, transparent);
}
body[data-theme="light"] .nl-injected {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.nl-factcheck-badge {
  display: inline;
  margin: 0 1px;
  font-size: 0.7em;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  vertical-align: super;
  opacity: 0.75;
  transition: opacity 0.12s ease, transform 0.12s ease;
  background: none;
  border: none;
  padding: 0;
}
.nl-factcheck-badge:hover {
  opacity: 1;
  transform: scale(1.2);
}
.nl-factcheck-badge.is-checking {
  opacity: 0.8;
  cursor: progress;
  pointer-events: none;
}

/* === Agentic progress pipeline === */
.agent-pipeline {
  display: none;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  flex-shrink: 0;  /* do not stretch — pipeline stays compact */
  width: auto;
  margin: 0;
  margin-left: auto;        /* push to the far right of the action-row */
  padding-top: 7px;         /* (btn ~38px - ring 24px) / 2 — ring centres align with button centres */
}

.pipeline-track {
  display: flex;
  align-items: flex-start;  /* rings align at their tops; multi-line labels hang freely below */
  gap: 0;
  width: auto;     /* shrink-wrap to content */
}

/* Node — fixed equal width so ring centres are evenly spaced regardless of label length */
.pipeline-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  width: 72px;       /* fixed: all 4 nodes identical width */
}

.pnode-ring {
  position: relative;
  width: 24px;
  height: 24px;
}
.pnode-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; }

/* Spinner: rotating arc */
.pnode-spinner {
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.2s;
}
.pnode-spinner circle { transform-origin: center; }

/* Check ring / tick mark */
.pnode-check {
  opacity: 1;
  transition: color 0.3s, opacity 0.2s;
}

/* ── States ─────────────────────────────────────────────────── */
/* idle: soft lavender outline */
.pipeline-node[data-state="idle"] .pnode-spinner { opacity: 0; }
.pipeline-node[data-state="idle"] .pnode-check   { color: var(--accent-light); opacity: 0.45; }
.pipeline-node[data-state="idle"] .pnode-label   { color: var(--accent-light); opacity: 0.6; }

/* active: vivid accent + glow on the spinning arc */
.pipeline-node[data-state="active"] .pnode-spinner {
  opacity: 1;
  color: var(--accent);
  animation: pipelineRotate 0.9s linear infinite;
  filter: drop-shadow(0 0 3px var(--accent));
}
.pipeline-node[data-state="active"] .pnode-check { opacity: 0; }
.pipeline-node[data-state="active"] .pnode-label { color: var(--accent); opacity: 1; font-weight: 700; }

/* done: solid accent tick */
.pipeline-node[data-state="done"] .pnode-spinner { opacity: 0; }
.pipeline-node[data-state="done"] .pnode-check   { color: var(--accent); opacity: 1; }
.pipeline-node[data-state="done"] .pnode-label   { color: var(--accent); opacity: 0.8; }

@keyframes pipelineRotate {
  to { transform: rotate(360deg); }
}

/* Label — wraps to keep the node at a fixed 72 px width */
.pnode-label {
  font-size: 0.58rem;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  letter-spacing: 0.02em;
  text-align: center;
  white-space: normal;       /* allow wrap so width stays fixed */
  line-height: 1.3;
  font-weight: 400;
  transition: color 0.3s, opacity 0.3s, font-weight 0.15s;
}

/* Connecting line — fixed short dash, purple palette */
.pipeline-line {
  flex: none;
  width: 20px;
  height: 1px;
  border-top: 1.5px dotted var(--accent-light);
  opacity: 0.4;
  margin-top: 11px;   /* (ring 24px - border 1.5px) / 2 ≈ 11px — centres line with ring */
  transition: border-color 0.35s, opacity 0.35s;
}
.pipeline-line.lit {
  border-color: var(--accent);
  border-top-style: solid;
  opacity: 0.75;
}

/* Status text */
.pipeline-status {
  font-size: 0.7rem;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  letter-spacing: 0.03em;
  font-weight: 400;
  color: var(--ink-dim);
  min-height: 1em;
  width: 100%;
  text-align: center;
}
/* pipeline-status inherits the shared .status-dots rules above — no override needed */
