/* === StoryHarness V2.0 - Pipeline Card UI Theme === */

:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #0d1321;
  --bg-card: rgba(15, 23, 42, 0.8);
  --bg-input: rgba(30, 41, 59, 0.6);
  --accent: #00d4ff;
  --accent-hover: #00e7ff;
  --accent-gradient: linear-gradient(135deg, #00d4ff 0%, #a855f7 50%, #ec4899 100%);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: rgba(148, 163, 184, 0.15);
  --border-glow: rgba(0, 212, 255, 0.3);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 12px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px rgba(0, 212, 255, 0.2);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --pipeline-gap: 20px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* === Animated Background === */
.bg-grid {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: 
    linear-gradient(rgba(0, 212, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 212, 255, 0.03) 1px, transparent 1px);
  background-size: 60px 60px;
  pointer-events: none;
  z-index: 0;
}

.bg-gradient {
  position: fixed;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background: radial-gradient(circle at 30% 20%, rgba(168, 85, 247, 0.15) 0%, transparent 50%),
              radial-gradient(circle at 70% 80%, rgba(0, 212, 255, 0.1) 0%, transparent 50%),
              radial-gradient(circle at 50% 50%, rgba(236, 72, 153, 0.05) 0%, transparent 70%);
  animation: gradientShift 20s ease infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes gradientShift {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  33% { transform: translate(5%, -5%) rotate(1deg); }
  66% { transform: translate(-5%, 5%) rotate(-1deg); }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { 
  background: linear-gradient(180deg, rgba(0, 212, 255, 0.3) 0%, rgba(168, 85, 247, 0.3) 100%);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: linear-gradient(180deg, rgba(0, 212, 255, 0.5) 0%, rgba(168, 85, 247, 0.5) 100%); }

/* ============================================================
   APP CONTAINER & TOPBAR
   ============================================================ */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: rgba(13, 19, 33, 0.9);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.topbar .logo {
  font-size: 20px;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 1.5px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar .logo-img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.4);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 20px rgba(0, 212, 255, 0.4); }
  50% { box-shadow: 0 0 40px rgba(0, 212, 255, 0.6), 0 0 60px rgba(168, 85, 247, 0.3); }
}

.topbar .logo span {
  color: var(--text-secondary);
  font-weight: 400;
  font-size: 13px;
  margin-left: 4px;
  background: none;
  -webkit-background-clip: text;
  -webkit-text-fill-color: var(--text-secondary);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.project-indicator {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 6px 14px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border);
  border-radius: 20px;
  backdrop-filter: blur(10px);
  transition: var(--transition);
}

.project-indicator.active {
  color: var(--accent);
  border-color: var(--border-glow);
  box-shadow: 0 0 15px rgba(0, 212, 255, 0.2);
}

/* ============================================================
   PIPELINE CONTAINER
   ============================================================ */
.pipeline-container {
  flex: 1;
  position: relative;
  display: flex;
  align-items: stretch;
  padding: 24px;
  min-height: calc(100vh - 120px);
  gap: 0;
}

.pipeline-card {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.pipeline-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent-gradient);
  opacity: 0;
  transition: var(--transition);
}

/* --- Main Card (Center, Prominent, Fluid Width) --- */
.pipeline-main-card {
  flex: 1;
  z-index: 10;
  border-color: var(--border-glow);
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.5), 0 0 40px rgba(0, 212, 255, 0.08);
  display: flex;
  flex-direction: column;
  margin: 0 8px;
}

.pipeline-main-card::before { opacity: 1; }

/* --- Main Card Title --- */
.pipeline-main-title {
  padding: 14px 28px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(15, 23, 42, 0.4);
}

.pipeline-main-title::before {
  content: '';
  width: 4px;
  height: 18px;
  background: var(--accent-gradient);
  border-radius: 2px;
}

/* --- Left Stacked Card (narrow, just wider than tag) --- */
.pipeline-left-stack {
  width: 100px;
  flex-shrink: 0;
  z-index: 5;
  opacity: 0.55;
  filter: blur(1.5px);
  transform: perspective(600px) rotateY(6deg);
  transform-origin: right center;
}

.pipeline-left-stack:hover {
  opacity: 0.85;
  filter: blur(0px);
  z-index: 8;
}

/* --- Right Stacked Card (narrow, just wider than tag) --- */
.pipeline-right-stack {
  width: 100px;
  flex-shrink: 0;
  z-index: 5;
  opacity: 0.55;
  filter: blur(1.5px);
  transform: perspective(600px) rotateY(-6deg);
  transform-origin: left center;
}

.pipeline-right-stack:hover {
  opacity: 0.85;
  filter: blur(0px);
  z-index: 8;
}

/* --- Card Tags (on stacked cards, facing center) --- */
.pipeline-card-tag {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  padding: 8px 8px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-gradient);
  color: #fff;
  border-radius: 4px;
  z-index: 15;
  letter-spacing: 0.5px;
  pointer-events: auto;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  writing-mode: vertical-lr;
  text-orientation: upright;
  white-space: nowrap;
}

.pipeline-card-tag:hover {
  transform: translateY(-50%) scale(1.08);
  box-shadow: 0 4px 16px rgba(0, 212, 255, 0.4);
}

.pipeline-tag-left {
  right: 4px;
}

.pipeline-tag-right {
  left: 4px;
}

/* --- Card Body --- */
.pipeline-card-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 28px 16px 28px;
}

.pipeline-card-inner {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 12px 8px;
  pointer-events: none;
}

/* --- Card Footer --- */
.pipeline-card-footer {
  padding: 16px 28px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-shrink: 0;
}

/* ============================================================
   CARD CONTENT SECTIONS
   ============================================================ */

/* Plot Creativity in pipeline */
.plot-creativity-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.plot-creativity-content .form-group { max-width: 320px; }

.plot-creativity-content textarea {
  min-height: 300px;
  font-size: 14px;
}

/* Materials in pipeline - two column */
.materials-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.materials-col-left,
.materials-col-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.materials-content .material-list-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.materials-content .guide-list-scroll {
  flex: 1;
  overflow-y: auto;
  margin-top: 8px;
  min-height: 0;
}

/* Writing content in pipeline */
.writing-auto-collapsed {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 12px;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.writing-auto-collapsed:hover {
  border-color: var(--border-glow);
  color: var(--text-primary);
}

.writing-manual-expanded {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ============================================================
   WRITING PAGE LAYOUTS (loaded inside pipeline-card-body)
   ============================================================ */

/* Manual writing: 2 columns (sidebar + main) */
.writing-layout-manual {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
  min-height: 0;
  flex: 1;
}

/* Outline edit page: single column */
.writing-layout-outline {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.writing-sidebar-left {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  overflow-y: auto;
  backdrop-filter: blur(10px);
}

.writing-sidebar-left h4 {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  padding: 0;
  margin: 0;
}

.writing-main {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
}

.inspiration-panel {
  background: rgba(15, 23, 42, 0.35);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 12px;
  backdrop-filter: blur(8px);
}

.inspiration-panel h4 {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.inspiration-panel textarea { min-height: 56px !important; font-size: 13px; }

.editor-toolbar {
  display: flex;
  gap: 4px;
  padding: 8px 0;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.editor-textarea {
  flex: 1;
  min-height: 200px;
  font-size: 14px;
  font-family: 'Courier New', monospace;
  line-height: 1.8;
}

.writing-word-stats {
  display: flex;
  justify-content: space-between;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.3);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

/* --- Chapter list sidebar --- */
.chapter-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  cursor: pointer;
  transition: var(--transition);
  background: rgba(15, 23, 42, 0.4);
}

.chapter-card:hover { border-color: var(--border-glow); }
.chapter-card.active { border-color: var(--accent); background: rgba(0, 212, 255, 0.08); }

.chapter-card .ch-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  min-width: 32px;
}

.chapter-card .ch-info { flex: 1; min-width: 0; }
.chapter-card .ch-title {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-card .ch-meta { font-size: 11px; color: var(--text-muted); }
.chapter-card .ch-status { font-size: 14px; }

/* --- Auto pipeline layout inside pipeline card --- */
.auto-layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 16px;
  min-height: 0;
  flex: 1;
}

.auto-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.auto-sidebar {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  overflow-y: auto;
  backdrop-filter: blur(10px);
}

.auto-sidebar h4 {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.auto-ws-log {
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 11px;
  line-height: 1.5;
  color: #8899b4;
  white-space: pre-wrap;
  word-break: break-all;
  min-height: 80px;
}

.auto-info { margin-bottom: 10px; }

.auto-live-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.auto-stage-indicator {
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
  font-size: 12px;
}

.auto-preview-content {
  flex: 1;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  overflow-y: auto;
  max-height: 220px;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--text-secondary);
}

.version-snapshot-list { display: flex; flex-direction: column; gap: 4px; }

.snapshot-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  transition: var(--transition);
}

.snapshot-card:hover { border-color: var(--accent); background: rgba(0, 212, 255, 0.06); }

.snapshot-label { font-size: 11px; font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.snapshot-meta { font-size: 10px; color: var(--text-muted); display: flex; justify-content: space-between; }

.snapshot-badge {
  display: inline-block;
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 10px;
  font-weight: 600;
  margin-right: 4px;
}

.snapshot-badge.draft  { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }
.snapshot-badge.revised { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.snapshot-badge.final   { background: rgba(16, 185, 129, 0.2); color: #34d399; }

/* --- Merge in pipeline --- */
.merge-status-bar {
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: 8px;
  padding: 10px 16px;
  margin-top: 12px;
  font-size: 13px;
  color: #155724;
}

.merge-snapshot { margin-bottom: 6px; }
.merge-snapshot:hover { border-color: var(--accent) !important; }

/* --- Eval in pipeline --- */
.eval-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.eval-card {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  backdrop-filter: blur(10px);
  transition: var(--transition);
}

.eval-card:hover { border-color: var(--border-glow); }

.eval-card h4 {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

/* Score Bars */
.score-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.score-bar .label {
  width: 70px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: right;
}

.score-bar .bar {
  flex: 1;
  height: 14px;
  background: var(--bg-input);
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.score-bar .bar-inner {
  height: 100%;
  border-radius: 6px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.score-bar .value {
  width: 36px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

/* Certificate in pipeline */
.certificate {
  background: linear-gradient(135deg, #fffef5 0%, #fef9c3 100%);
  color: #2d3748;
  padding: 30px;
  border-radius: var(--radius);
  font-family: 'Georgia', 'STSong', 'SimSun', serif;
  border: 2px solid #c9a96e;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  position: relative;
  overflow: hidden;
}

.certificate::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, #8b6914 0%, #c9a96e 50%, #8b6914 100%);
}

.certificate h2 {
  text-align: center;
  color: #8b6914;
  font-size: 22px;
  margin-bottom: 20px;
  letter-spacing: 4px;
  font-weight: 700;
}

.certificate .cert-field {
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.6;
}

.certificate .cert-label {
  color: #666;
  display: inline-block;
  width: 90px;
  font-weight: 600;
}

.certificate .cert-hash {
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 11px;
  word-break: break-all;
  color: #555;
  background: rgba(0, 0, 0, 0.05);
  padding: 10px;
  border-radius: 8px;
  margin-top: 6px;
}

.certificate .cert-footer {
  text-align: center;
  margin-top: 24px;
  font-style: italic;
  color: #888;
  font-size: 13px;
}

/* --- Guide entries --- */
.guide-entry {
  padding: 6px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 4px;
  border-left: 3px solid var(--accent);
}

/* Outline editor nodes */
.outline-node {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  cursor: grab;
  transition: var(--transition);
  backdrop-filter: blur(10px);
}

.outline-node:hover { border-color: var(--border-glow); }

.outline-node .node-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.outline-node .node-number {
  background: var(--accent-gradient);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 0 15px rgba(0, 212, 255, 0.4);
}

.outline-node .node-title-input {
  flex: 1;
}

.outline-node .node-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

/* ============================================================
   MATERIAL CARD (CONSISTENT STYLE)
   ============================================================ */
.material-card {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  transition: var(--transition);
  backdrop-filter: blur(10px);
}

.material-card:hover { border-color: var(--border-glow); }

.material-card .mat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.material-card .mat-name {
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.material-card .mat-preview {
  font-size: 12px;
  color: var(--text-muted);
  max-height: 60px;
  overflow: hidden;
  line-height: 1.5;
}

/* ============================================================
   WRITING TAB SWITCH (AUTO / MANUAL)
   ============================================================ */
.writing-mode-area {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.writing-tab-header {
  display: flex;
  gap: 0;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.6);
}

.writing-tab-btn {
  padding: 10px 24px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: var(--transition);
  user-select: none;
}

.writing-tab-btn:hover { color: var(--text-primary); }
.writing-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.writing-tab-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  transition: 0.5s;
}

.btn:hover::before { left: 100%; }

.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 15px rgba(0, 212, 255, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(0, 212, 255, 0.4);
}

.btn-secondary {
  background: rgba(30, 41, 59, 0.6);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: rgba(30, 41, 59, 0.8);
  border-color: var(--border-glow);
  color: var(--text-primary);
}

.btn-success {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #fff;
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(16, 185, 129, 0.4);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: #fff;
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(239, 68, 68, 0.4);
}

.btn-warning {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #fff;
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.btn-warning:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(245, 158, 11, 0.4);
}

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 14px 28px; font-size: 15px; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover {
  background: rgba(30, 41, 59, 0.6);
  border-color: var(--border-glow);
  color: var(--text-primary);
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

.btn-group { display: flex; gap: 10px; flex-wrap: wrap; }

/* ============================================================
   INPUTS
   ============================================================ */
input[type="text"],
input[type="number"],
input[type="password"],
textarea,
select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  width: 100%;
  transition: var(--transition);
  backdrop-filter: blur(10px);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.2), inset 0 0 20px rgba(0, 212, 255, 0.05);
}

textarea { resize: vertical; min-height: 100px; }

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-row { display: flex; gap: 16px; }
.form-row > * { flex: 1; }

/* ============================================================
   TABLES
   ============================================================ */
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
tr:hover { background: rgba(0, 212, 255, 0.05); }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  backdrop-filter: blur(10px);
}

.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}
.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}
.badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.badge-lang {
  background: rgba(59, 130, 246, 0.12);
  color: var(--info);
  border: 1px solid rgba(59, 130, 246, 0.25);
  font-size: 11px;
}
.badge-info {
  background: rgba(59, 130, 246, 0.15);
  color: var(--info);
  border: 1px solid rgba(59, 130, 246, 0.3);
}
.badge-accent {
  background: rgba(0, 212, 255, 0.15);
  color: var(--accent);
  border: 1px solid rgba(0, 212, 255, 0.3);
}

/* Topbar tier badge */
.topbar-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  cursor: default;
  white-space: nowrap;
  margin-left: 2px;
}
.topbar-badge.free-upgrade {
  background: rgba(245, 158, 11, 0.2);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.4);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 11px;
}
.topbar-badge.free-upgrade:hover {
  background: rgba(245, 158, 11, 0.35);
  transform: translateY(-1px);
}
.topbar-badge.svip {
  background: rgba(251, 191, 36, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.4);
}
.topbar-badge.monthly {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}
.topbar-badge.annual {
  background: rgba(59, 130, 246, 0.15);
  color: var(--info);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

/* Rename inline */
.rename-input {
  padding: 3px 8px;
  border: 1px solid var(--border-glow);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  vertical-align: middle;
}
.btn-rename-confirm, .btn-rename-cancel { padding: 3px 8px; margin-left: 4px; cursor: pointer; }
.btn-rename-trigger { padding: 3px 7px; cursor: pointer; }
.project-name-display strong { margin-right: 4px; }

/* ============================================================
   INFO ROW / ALERTS
   ============================================================ */
.info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.info-row:last-child { border-bottom: none; }
.info-label { color: var(--text-muted); font-size: 13px; }

.alert {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
  border: 1px solid transparent;
  backdrop-filter: blur(10px);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.alert-info  { background: rgba(59, 130, 246, 0.1); border-color: rgba(59, 130, 246, 0.2); color: var(--info); }
.alert-success { background: rgba(16, 185, 129, 0.1); border-color: rgba(16, 185, 129, 0.2); color: var(--success); }
.alert-warning { background: rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.2); color: var(--warning); }
.alert-danger  { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.2); color: var(--danger); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: rgba(13, 19, 33, 0.95);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  min-width: 420px;
  max-width: 650px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 40px rgba(0, 212, 255, 0.1);
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-title::before {
  content: '';
  width: 4px;
  height: 20px;
  background: var(--accent-gradient);
  border-radius: 2px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   LOADING & PROGRESS
   ============================================================ */
.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  position: relative;
}

.spinner::before {
  content: '';
  position: absolute;
  top: 2px; left: 2px; right: 2px; bottom: 2px;
  border: 2px solid transparent;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite reverse;
}

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

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 48px;
  color: var(--text-secondary);
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(10, 14, 26, 0.7);
  backdrop-filter: blur(8px);
  z-index: 200;
}

.loading-text { font-size: 14px; color: var(--text-secondary); }

.log-console {
  max-width: 600px;
  max-height: 200px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: 'Cascadia Code', monospace;
  font-size: 12px;
  line-height: 1.6;
  width: 100%;
}

.log-line { margin-bottom: 2px; }
.log-line.stage { color: var(--accent); font-weight: 600; }
.log-line.success { color: var(--success); }
.log-line.warning { color: var(--warning); }
.log-line.error { color: var(--danger); }
.log-line.info { color: var(--text-secondary); }

.progress-bar-container { width: 100%; max-width: 500px; }

.progress-bar {
  height: 10px;
  background: var(--bg-input);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}

.progress-bar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.progress-bar .fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.progress-bar .fill::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.1), transparent, rgba(255, 255, 255, 0.1));
  animation: shimmer 2s infinite;
}

.fill-success { background: linear-gradient(90deg, #10b981 0%, #059669 100%); box-shadow: 0 0 10px rgba(16, 185, 129, 0.5); }
.fill-warning { background: linear-gradient(90deg, #f59e0b 0%, #d97706 100%); box-shadow: 0 0 10px rgba(245, 158, 11, 0.5); }
.fill-danger  { background: linear-gradient(90deg, #ef4444 0%, #dc2626 100%); box-shadow: 0 0 10px rgba(239, 68, 68, 0.5); }
.fill-accent  { background: var(--accent-gradient); box-shadow: 0 0 15px rgba(0, 212, 255, 0.5); }

/* ============================================================
   TOAST
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  z-index: 300;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  backdrop-filter: blur(20px);
  animation: slideInRight 0.3s ease;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.toast-info    { background: rgba(59, 130, 246, 0.2); border: 1px solid rgba(59, 130, 246, 0.5); color: #93c5fd; }
.toast-success { background: rgba(16, 185, 129, 0.2); border: 1px solid rgba(16, 185, 129, 0.5); color: #6ee7b7; }
.toast-error   { background: rgba(239, 68, 68, 0.2); border: 1px solid rgba(239, 68, 68, 0.5); color: #fca5a5; }
.toast-warning { background: rgba(245, 158, 11, 0.2); border: 1px solid rgba(245, 158, 11, 0.5); color: #fcd34d; }

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============================================================
   UTILITY
   ============================================================ */
.hidden { display: none !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.text-sm { font-size: 13px; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ============================================================
   PLOT SAVED STATE (blurred, static drawing overlay)
   ============================================================ */
.pipeline-left-stack.plot-saved .pipeline-card-inner {
  pointer-events: none;
}

.pipeline-left-stack.plot-saved .pipeline-card-inner > * {
  filter: blur(3px);
  opacity: 0.6;
}

/* ============================================================
   MATERIALS ANALYSIS DISPLAY
   ============================================================ */
.analysis-panel {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-top: 12px;
  max-height: 160px;
  overflow-y: auto;
}

.analysis-panel .analysis-line {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

/* ============================================================
   MOBILE RESPONSIVE
   ============================================================ */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(13, 19, 33, 0.95);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  z-index: 100;
  justify-content: space-between;
  align-items: center;
}

.mobile-nav-btn {
  padding: 8px 16px;
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  transition: var(--transition);
}

.mobile-nav-btn:hover {
  border-color: var(--accent);
  background: rgba(0, 212, 255, 0.1);
}

.mobile-nav-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

/* --- Tablet / Small Desktop --- */
@media (max-width: 1200px) {
  .pipeline-left-stack,
  .pipeline-right-stack {
    width: 70px;
  }
  .pipeline-card-tag {
    font-size: 10px;
    padding: 6px 6px;
  }
}

/* --- Mobile --- */
@media (max-width: 768px) {
  .topbar {
    padding: 6px 10px;
    flex-wrap: wrap;
    gap: 4px;
  }

  .topbar-left {
    flex: 1 1 100%;
    gap: 8px;
    justify-content: space-between;
  }

  .topbar .logo {
    font-size: 15px;
  }

  .topbar .logo span {
    display: none;
  }

  .project-indicator {
    font-size: 11px;
    padding: 4px 10px;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-right {
    flex: 1 1 100%;
    gap: 4px;
    justify-content: flex-end;
    padding-top: 2px;
  }

  .topbar-right .btn-sm {
    padding: 5px 8px;
    font-size: 11px;
  }

  /* Project popup table simplified: name + action only */
  .modal table th:nth-child(2),
  .modal table td:nth-child(2),
  .modal table th:nth-child(3),
  .modal table td:nth-child(3) {
    display: none;
  }

  .modal table td:last-child .btn-group {
    flex-direction: column;
    gap: 4px;
  }

  .modal table td:last-child .btn-group .btn {
    width: 100%;
    text-align: center;
    border-radius: 20px;
    padding: 6px 10px;
    font-size: 12px;
  }

  .modal table th,
  .modal table td {
    padding: 8px 10px;
    font-size: 13px;
  }

  /* Pipeline becomes full-screen card with mobile nav */
  .pipeline-container {
    padding: 12px;
    min-height: calc(100vh - 160px);
    align-items: flex-start;
  }

  .pipeline-left-stack,
  .pipeline-right-stack {
    display: none !important;
  }

  .pipeline-main-card {
    margin: 0;
    min-height: auto;
    flex: 1 1 auto;
    overflow: visible;
  }

  .pipeline-main-title {
    padding: 12px 16px;
    font-size: 16px;
  }

  .pipeline-card-body {
    padding: 16px 16px 60px 16px;
    flex: 0 0 auto;
  }

  .pipeline-card-footer {
    padding: 12px 16px;
    flex-wrap: wrap;
  }

  .pipeline-main-card .pipeline-tag-left,
  .pipeline-main-card .pipeline-tag-right {
    display: none;
  }

  .mobile-nav {
    display: flex;
  }

  /* Writing layout becomes stacked */
  .writing-layout-manual {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .writing-sidebar-left {
    max-height: 200px;
  }

  .auto-layout {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .auto-sidebar {
    max-height: 200px;
  }

  .eval-grid {
    grid-template-columns: 1fr;
  }

  .materials-content {
    grid-template-columns: 1fr;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .form-row {
    flex-direction: column;
    gap: 10px;
  }

  .modal {
    min-width: auto;
    width: 90vw;
    max-width: 90vw;
    max-height: 80vh;
  }

  .btn-group {
    flex-wrap: wrap;
  }
}

/* Small mobile */
@media (max-width: 480px) {
  .topbar {
    padding: 6px 8px;
  }

  .pipeline-container {
    padding: 8px;
  }

  .pipeline-card-body {
    padding: 16px 12px 70px 12px;
  }
}
