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

:root {
  --primary: #2563eb;
  --success: #16a34a;
  --warning: #ea580c;
  --danger: #dc2626;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}

nav h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.nav-links {
  display: flex;
  gap: 1.5rem;
}

.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  transition: all 0.2s;
}

.nav-links a:hover {
  color: var(--primary);
  background: var(--bg);
}

.nav-links a.active {
  color: var(--primary);
  background: #eff6ff;
}

main {
  max-width: 1400px;
  margin: 2rem auto;
  padding: 0 2rem;
}

/* Pipeline View */
.pipeline-header {
  margin-bottom: 2rem;
}

.pipeline-header h2 {
  font-size: 2rem;
  margin-bottom: 1rem;
}

.stats {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.badge {
  font-size: 1rem;
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
}

.story-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: all 0.2s;
  cursor: pointer;
}

.story-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transform: translateY(-2px);
}

.story-card-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.story-card h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.story-status {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.story-status.inbox { background: #e0e7ff; color: #4338ca; }
.story-status.draft { background: #fef3c7; color: #92400e; }
.story-status.in-review { background: #dbeafe; color: #1e40af; }
.story-status.ready { background: #dcfce7; color: #166534; }
.story-status.needs-human-review { background: #fed7aa; color: #9a3412; }

.story-meta {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

.story-grade {
  font-weight: 700;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  background: #fef3c7;
  color: #92400e;
}

/* Story Detail */
.story-header {
  margin-bottom: 2rem;
}

.back-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  display: inline-block;
  margin-bottom: 1rem;
}

.back-link:hover {
  text-decoration: underline;
}

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 2rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.section h3 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.markdown-content {
  line-height: 1.8;
}

.markdown-content h1 { font-size: 2rem; margin: 1.5rem 0 1rem; }
.markdown-content h2 { font-size: 1.5rem; margin: 1.25rem 0 0.75rem; }
.markdown-content h3 { font-size: 1.25rem; margin: 1rem 0 0.5rem; }
.markdown-content p { margin-bottom: 1rem; }
.markdown-content ul, .markdown-content ol { margin-left: 1.5rem; margin-bottom: 1rem; }
.markdown-content code { background: var(--bg); padding: 0.125rem 0.25rem; border-radius: 0.25rem; }
.markdown-content pre { background: var(--bg); padding: 1rem; border-radius: 0.375rem; overflow-x: auto; }

.word-count {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.grade-badge {
  display: inline-block;
  font-size: 1.5rem;
  font-weight: 700;
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  margin-bottom: 1rem;
}

.grade-badge.a-plus, .grade-badge.a { background: #dcfce7; color: #166534; }
.grade-badge.a-minus { background: #dbeafe; color: #1e40af; }
.grade-badge.b-plus, .grade-badge.b { background: #fef3c7; color: #92400e; }
.grade-badge.b-minus, .grade-badge.c { background: #fed7aa; color: #9a3412; }

.action-buttons {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 0.375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 1rem;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: #1d4ed8; }

.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #e2e8f0; }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }

.notes-input label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.notes-input textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-family: inherit;
  font-size: 1rem;
  resize: vertical;
}

/* Bible Editor */
.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.editor-actions {
  display: flex;
  gap: 1rem;
}

.editor-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.editor-pane textarea {
  width: 100%;
  height: 70vh;
  padding: 2rem;
  border: none;
  font-family: 'Monaco', 'Menlo', monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  resize: none;
}

.preview-pane {
  padding: 2rem;
  height: 70vh;
  overflow-y: auto;
}

.save-status {
  margin-top: 1rem;
  padding: 0.75rem;
  border-radius: 0.375rem;
  font-weight: 600;
  text-align: center;
}

.save-status.success { background: #dcfce7; color: #166534; }
.save-status.error { background: #fee2e2; color: #991b1b; }

/* Ideas Browser */
.ideas-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.idea-item {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.idea-item:last-child {
  border-bottom: none;
}

/* STEM Tracker */
.stem-content {
  display: grid;
  gap: 2rem;
}

.chart-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.chart-container canvas {
  max-height: 400px;
}

.topics-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 2rem;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: var(--bg);
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.875rem;
  text-transform: uppercase;
}

/* Loading states */
.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

@media (max-width: 768px) {
  nav {
    flex-direction: column;
    gap: 1rem;
  }
  
  .story-grid {
    grid-template-columns: 1fr;
  }
  
  .action-buttons {
    flex-direction: column;
  }
  
  .btn {
    width: 100%;
  }
}

/* Story Table */
.story-table-wrapper {
  background: var(--surface);
  border-radius: 0.5rem;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.story-table {
  width: 100%;
  border-collapse: collapse;
}

.story-table thead {
  background: #f1f5f9;
  border-bottom: 2px solid var(--border);
}

.story-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.story-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.story-table tbody tr:hover {
  background: #f8fafc;
}

.story-table tbody tr:last-child {
  border-bottom: none;
}

.story-table td {
  padding: 1rem;
  vertical-align: middle;
}

.story-title .title-main {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.story-title .title-slug {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Monaco', monospace;
}

.stage-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.stage-badge.inbox {
  background: #dbeafe;
  color: #1e40af;
}

.stage-badge.draft {
  background: #fef3c7;
  color: #92400e;
}

.stage-badge.in-review {
  background: #e0e7ff;
  color: #3730a3;
}

.stage-badge.ready {
  background: #dcfce7;
  color: #166534;
}

.stage-badge.needs-human-review {
  background: #fed7aa;
  color: #9a3412;
}

.grade-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 0.25rem;
  font-weight: 700;
  font-size: 0.875rem;
  font-family: 'SF Mono', 'Monaco', monospace;
}

.grade-badge.grade-a, .grade-badge.grade-aplus, .grade-badge.grade-aminus {
  background: #dcfce7;
  color: #166534;
}

.grade-badge.grade-b, .grade-badge.grade-bplus, .grade-badge.grade-bminus {
  background: #dbeafe;
  color: #1e40af;
}

.grade-badge.grade-c, .grade-badge.grade-cplus, .grade-badge.grade-cminus {
  background: #fef3c7;
  color: #92400e;
}

.grade-badge.grade-d, .grade-badge.grade-dplus, .grade-badge.grade-dminus,
.grade-badge.grade-f {
  background: #fee2e2;
  color: #991b1b;
}

.no-grade {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.story-updated {
  font-size: 0.875rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.story-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0.375rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 0.875rem;
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-action {
  background: #8b5cf6;
  color: white;
}

.btn-action:hover {
  background: #7c3aed;
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: #15803d;
}

.empty, .error {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.error {
  color: var(--danger);
}
