/* ============================================================
   ScholarFlow AI — Professional Dual-Theme CSS
   Based on Stitch design: clean, minimal, academic
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=Lora:ital,wght@0,400;0,500;1,400&display=swap&display=swap');

/* ── Design Tokens (Stitch Premium UI) ── */
:root {
  /* Dark theme (default) */
  --primary: #200df2;
  --accent-purple: #8b5cf6;
  --accent-cyan: #06b6d4;
  --bg-body: #0a0a16;
  --bg-card: rgba(20, 20, 35, 0.6);
  --bg-card-hover: rgba(30, 30, 50, 0.6);
  --bg-input: rgba(255, 255, 255, 0.05);
  --bg-input-focus: rgba(32, 13, 242, 0.1);
  --border: rgba(255, 255, 255, 0.1);
  --border-focus: var(--primary);

  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.3);
  --shadow-neon-primary: 0 0 20px rgba(32, 13, 242, 0.4);
  --shadow-neon-cyan: 0 0 15px rgba(6, 182, 212, 0.4);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-label: #cbd5e1;

  --accent: var(--primary);
  --accent-hover: #3b28ff;
  --accent-muted: rgba(32, 13, 242, 0.15);

  --green: #16a34a;
  --green-bg: rgba(22, 163, 74, 0.1);
  --green-border: rgba(22, 163, 74, 0.25);

  --amber: #d97706;
  --amber-bg: rgba(217, 119, 6, 0.1);
  --amber-border: rgba(217, 119, 6, 0.25);

  --step-idle: rgba(255, 255, 255, 0.03);
  --step-active: rgba(32, 13, 242, 0.15);
  --step-done: rgba(6, 182, 212, 0.08);
  /* Cyan for done */
  --step-rejected: rgba(239, 68, 68, 0.08);

  --dot-idle: #334155;
  --dot-active: var(--primary);
  --dot-done: var(--accent-cyan);
  --dot-rejected: #ef4444;

  --num-bg: rgba(255, 255, 255, 0.05);
  --num-active-bg: var(--primary);
  --num-active-col: #ffffff;
  --num-done-bg: var(--accent-cyan);
  --num-done-col: #ffffff;

  --toggle-bg: #1e293b;
  --toggle-thumb: #f1f5f9;

  --font-sans: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-serif: 'Lora', Georgia, serif;

  --radius-card: 16px;
  /* ROUND_TWELVE roughly */
  --radius-input: 12px;
  --radius-btn: 12px;
}

/* ── Light theme ── */
[data-theme="light"] {
  --bg-body: #f5f6fa;
  --bg-card: #ffffff;
  --bg-card-hover: #fafbff;
  --bg-input: #f8f9fc;
  --bg-input-focus: #f0f3ff;
  --border: rgba(0, 0, 0, 0.07);
  --border-focus: rgba(59, 111, 240, 0.45);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-card: 0 0 0 1px rgba(0, 0, 0, 0.06), 0 4px 20px rgba(0, 0, 0, 0.07);

  --text-primary: #1a1d27;
  --text-secondary: #4a5568;
  --text-muted: #9aa3b5;
  --text-label: #64748b;

  --accent: #3b6ff0;
  --accent-hover: #2f5fe0;
  --accent-muted: rgba(59, 111, 240, 0.08);

  --green: #059669;
  --green-bg: rgba(5, 150, 105, 0.07);
  --green-border: rgba(5, 150, 105, 0.2);

  --amber: #d97706;
  --amber-bg: rgba(217, 119, 6, 0.08);
  --amber-border: rgba(217, 119, 6, 0.2);

  --step-idle: rgba(0, 0, 0, 0.03);
  --step-active: rgba(59, 111, 240, 0.06);
  --step-done: rgba(5, 150, 105, 0.06);
  --step-rejected: rgba(220, 38, 38, 0.06);

  --dot-idle: #cbd5e0;
  --dot-active: #3b6ff0;
  --dot-done: #059669;
  --dot-rejected: #dc2626;

  --num-bg: rgba(0, 0, 0, 0.05);
  --num-active-bg: rgba(59, 111, 240, 0.12);
  --num-active-col: #3b6ff0;
  --num-done-bg: rgba(5, 150, 105, 0.1);
  --num-done-col: #059669;

  --toggle-bg: #e2e8f0;
  --toggle-thumb: #3b6ff0;
}

/* ── Reset ── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  /* Aurora Deep Background Effect */
  background: radial-gradient(circle at 0% 0%, #111022 0%, #0a0a16 100%),
    radial-gradient(circle at 80% 20%, rgba(32, 13, 242, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 20% 80%, rgba(139, 92, 246, 0.1) 0%, transparent 40%);
  background-attachment: fixed;
  transition: background 0.3s ease, color 0.3s ease;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background 0.3s, border-color 0.3s;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.brand-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  line-height: 1.2;
}

.brand-sub {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
  letter-spacing: 0;
}

/* ── Theme Toggle ── */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.toggle-track {
  display: flex;
  align-items: center;
  width: 56px;
  height: 28px;
  background: var(--toggle-bg);
  border-radius: 14px;
  padding: 3px;
  position: relative;
  transition: background 0.3s;
}

.toggle-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  z-index: 1;
  color: var(--text-secondary);
  transition: opacity 0.2s;
}

.toggle-thumb {
  position: absolute;
  width: 22px;
  height: 22px;
  background: var(--toggle-thumb);
  border-radius: 50%;
  left: 3px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

[data-theme="light"] .toggle-thumb {
  transform: translateX(28px);
}

.sun {
  opacity: 1;
}

.moon {
  opacity: 0.45;
  margin-left: auto;
}

[data-theme="light"] .sun {
  opacity: 0.45;
}

[data-theme="light"] .moon {
  opacity: 1;
}

/* ── Main Grid ── */
.main-grid {
  display: grid;
  grid-template-columns: 340px 1fr 450px;
  gap: 24px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
  align-items: start;
}

/* ── Card (Glassmorphism applied here) ── */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 32px 24px;
  box-shadow: var(--shadow-card);
  transition: background 0.3s, border-color 0.3s;
}

.card-heading {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-label);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 20px;
}

/* ── Form Fields ── */
.field-group {
  margin-bottom: 18px;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-label);
  margin-bottom: 7px;
  letter-spacing: 0.1px;
}

.field-textarea,
.field-select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 400;
  padding: 11px 14px;
  outline: none;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  line-height: 1.6;
}

.field-textarea {
  resize: vertical;
  min-height: 130px;
}

.field-textarea::placeholder {
  color: var(--text-muted);
}

.field-textarea:focus,
.field-select:focus {
  border-color: var(--border-focus);
  background: var(--bg-input-focus);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.select-wrap {
  position: relative;
}

.field-select {
  appearance: none;
  cursor: pointer;
  padding-right: 36px;
}

.select-chevron {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* ── Generate Button ── */
.btn-generate {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 20px;
  border-radius: var(--radius-btn);
  border: none;
  background: linear-gradient(to right, var(--primary), var(--accent-purple));
  color: #fff;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  box-shadow: var(--shadow-neon-primary);
  transition: opacity 0.2s, transform 0.15s, box-shadow 0.2s;
  margin-top: 16px;
}

.btn-generate:hover:not(:disabled) {
  opacity: 0.95;
  transform: scale(1.02);
  box-shadow: 0 0 25px rgba(32, 13, 242, 0.6);
}

.btn-generate:active:not(:disabled) {
  transform: translateY(0);
}

.btn-generate:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-icon {
  transition: opacity 0.2s;
}

.btn-icon.hidden {
  display: none;
}

/* Spinner */
.btn-spinner {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  display: none;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

.btn-spinner.active {
  display: block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Pipeline Steps ── */
.pipeline-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.step-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--step-idle);
  border: 1px solid transparent;
  transition: all 0.35s ease;
}

.step-row.active {
  background: transparent;
  border-color: rgba(91, 141, 238, 0.0);
}

.step-row.done {
  background: transparent;
  border-color: rgba(52, 211, 153, 0.0);
}

.step-row.rejected {
  background: var(--step-rejected);
  border-color: rgba(239, 68, 68, 0.15);
}

/* Step number circle */
.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--num-bg);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.35s;
}

.step-row.active .step-num {
  background: var(--num-active-bg);
  color: var(--num-active-col);
  box-shadow: var(--shadow-neon-primary);
}

.step-row.done .step-num {
  background: var(--num-done-bg);
  color: var(--num-done-col);
}

.step-row.done .step-num::before {
  content: "✓";
}

.step-row.done .step-num>.num-text {
  display: none;
}

.step-body {
  flex: 1;
  min-width: 0;
}

.step-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.step-label {
  font-size: 10.5px;
  font-weight: 400;
  color: var(--text-muted);
  font-style: italic;
}

.step-msg {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

/* Pulse dot */
.step-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dot-idle);
  flex-shrink: 0;
  transition: background 0.3s;
}

.step-row.active .step-dot {
  background: var(--dot-active);
  animation: dotPulse 1.2s ease-in-out infinite;
}

.step-row.done .step-dot {
  background: var(--dot-done);
  animation: none;
}

.step-row.rejected .step-dot {
  background: var(--dot-rejected);
  animation: none;
}

@keyframes dotPulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
    box-shadow: 0 0 0 0 var(--primary);
  }
  50% {
    transform: scale(1.6);
    opacity: 0.5;
    box-shadow: 0 0 10px 4px var(--primary);
  }
}

@keyframes agentPulse {
  0% { box-shadow: 0 0 0 0 rgba(32, 13, 242, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(32, 13, 242, 0); }
  100% { box-shadow: 0 0 0 0 rgba(32, 13, 242, 0); }
}

@keyframes textGlow {
  0%, 100% { text-shadow: 0 0 5px rgba(255,255,255,0.2); }
  50% { text-shadow: 0 0 15px rgba(255,255,255,0.6); }
}

/* ── Pipeline Steps ── */
.pipeline-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.step-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--step-idle);
  border: 1px solid transparent;
  transition: all 0.35s ease;
  position: relative;
  overflow: hidden;
}

.step-row::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
  transition: none;
}

.step-row.active {
  background: var(--step-active);
  border-color: var(--border-focus);
}

.step-row.active::after {
  animation: shine 2s infinite;
}

@keyframes shine {
  to { left: 100%; }
}

.step-row.active .step-num {
  background: var(--num-active-bg);
  color: var(--num-active-col);
  animation: agentPulse 2s infinite;
}

.step-row.active .num-text {
  animation: textGlow 1.5s infinite;
}

.step-row.active .step-title {
  color: #fff;
}

/* ── Revision Notice ── */
.revision-notice {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--amber-bg);
  border: 1px solid var(--amber-border);
  color: var(--amber);
  font-size: 12px;
  margin-bottom: 14px;
}

.revision-notice.visible {
  display: flex;
}

/* ── Stats Row ── */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.stat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 8px;
  border-radius: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.stat-val {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
}

.stat-key {
  font-size: 9.5px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* ── Sources Log ── */
.sources-log {
  font-size: 10.5px;
  color: var(--text-secondary);
  max-height: 64px;
  overflow-y: auto;
}

.source-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 0;
  border-bottom: 1px solid var(--border);
}

.source-item a {
  color: var(--accent);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-item a:hover {
  text-decoration: underline;
}

/* ── Preview Panel ── */
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.btn-download-row {
  display: flex;
  gap: 10px;
}

.btn-download {
  display: flex;
  opacity: 0.45;
  filter: grayscale(40%);
  pointer-events: none;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-download.visible {
  opacity: 1;
  filter: grayscale(0%);
  pointer-events: auto;
  box-shadow: 0 0 15px rgba(32, 13, 242, 0.3);
}

.btn-download.pdf {
  border-color: var(--green-border);
  background: var(--green-bg);
  color: var(--green);
}

.btn-download.word {
  border-color: rgba(139, 92, 246, 0.3);
  background: rgba(139, 92, 246, 0.1);
  color: var(--accent-purple);
}

.btn-download:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.preview-scroll {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  min-height: 440px;
  max-height: 580px;
  overflow-y: auto;
  transition: background 0.3s;
}

.preview-scroll::-webkit-scrollbar {
  width: 5px;
}

.preview-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.preview-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.preview-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 380px;
  gap: 14px;
  color: var(--text-muted);
  text-align: center;
}

.preview-placeholder svg {
  color: var(--text-muted);
}

.preview-placeholder p {
  font-size: 12.5px;
  color: var(--text-secondary);
  max-width: 220px;
  line-height: 1.7;
}

/* Paper content typography */
.paper-content {
  font-family: var(--font-serif);
  color: var(--text-primary);
  line-height: 1.85;
}

.paper-content h1 {
  font-size: 17px;
  font-weight: 500;
  margin-bottom: 14px;
  font-family: var(--font-serif);
}

.paper-content h2 {
  font-size: 13.5px;
  font-weight: 600;
  font-family: var(--font-sans);
  margin: 18px 0 7px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  padding-bottom: 5px;
}

.paper-content h3 {
  font-size: 12.5px;
  font-style: italic;
  margin: 12px 0 5px;
  color: var(--text-secondary);
  font-family: var(--font-serif);
}

.paper-content p {
  font-size: 12.5px;
  margin-bottom: 9px;
  text-align: justify;
}

.paper-content a {
  color: var(--accent);
}

.paper-content strong {
  font-weight: 600;
}

.paper-content em {
  font-style: italic;
}

/* ── Responsive ── */
@media (max-width: 1200px) {
  .main-grid {
    grid-template-columns: 320px 1fr;
  }

  .main-grid .card:last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 768px) {
  .main-grid {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .header {
    padding: 0 16px;
  }

  .brand-sub {
    display: none;
  }
}