/* ===========================
   Markdown Article Overrides
   Styles for marked.js rendered content
   =========================== */

/* Loading State */
.md-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 4rem 0;
  color: var(--text-muted);
}

.md-loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ─── Tables ─── */
.table-wrapper {
  overflow-x: auto;
  margin: 2rem 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

.article-body table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  line-height: 1.6;
}

.article-body thead {
  background: linear-gradient(135deg, var(--accent-subtle), rgba(249, 115, 22, 0.04));
}

.article-body th {
  font-weight: 700;
  text-align: left;
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  border-bottom: 2px solid var(--accent);
  white-space: nowrap;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

.article-body td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.article-body tbody tr:hover {
  background: var(--accent-subtle);
}

.article-body tbody tr:last-child td {
  border-bottom: none;
}

/* Bold in tables for emphasis */
.article-body td strong,
.article-body th strong {
  color: var(--text-primary);
  font-weight: 700;
}

/* ─── H3 inside article body ─── */
.article-body h3 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 2.5rem 0 1rem;
  color: var(--text-primary);
  font-family: var(--font-serif);
}

/* ─── Horizontal rules ─── */
.article-body hr {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  margin: 3rem 0;
}

/* ─── Inline code ─── */
.article-body code {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.88em;
  padding: 0.15em 0.4em;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 4px;
  color: var(--accent);
}

[data-theme="dark"] .article-body code {
  background: rgba(255, 255, 255, 0.08);
}

/* ─── Code blocks ─── */
.article-body pre {
  background: #1a1a2e;
  color: #e0e0e0;
  padding: 1.5rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 2rem 0;
  font-size: 0.85rem;
  line-height: 1.6;
}

.article-body pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

/* ─── Lists ─── */
.article-body ul,
.article-body ol {
  margin: 1.5rem 0;
  padding-left: 1.5rem;
}

.article-body li {
  margin-bottom: 0.5rem;
  line-height: 1.8;
}

.article-body li::marker {
  color: var(--accent);
}

/* ─── Strong emphasis ─── */
.article-body strong {
  font-weight: 700;
  color: var(--text-primary);
}

/* ─── Links ─── */
.article-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color var(--transition);
}

.article-body a:hover {
  color: var(--accent-warm);
}

/* ─── Images in markdown ─── */
.article-body img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 1.5rem 0;
  display: block;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .article-body table {
    font-size: 0.78rem;
  }
  
  .article-body th,
  .article-body td {
    padding: 0.5rem 0.6rem;
  }
  
  .table-wrapper {
    margin: 1.5rem -1.5rem;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
}

/* ─── Interactive Charts ─── */
.chart-container {
  position: relative;
  width: 100%;
  height: 380px;
  margin: 2rem 0 2.5rem;
  padding: 1.25rem;
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-secondary) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
  transition: border-color var(--transition), box-shadow var(--transition);
  animation: chartFadeIn 0.6s ease-out;
}

.chart-container:hover {
  border-color: var(--border-hover);
  box-shadow: 0 4px 24px var(--accent-glow);
}

.article-chart {
  width: 100% !important;
  height: 100% !important;
}

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

@media (max-width: 768px) {
  .chart-container {
    height: 300px;
    margin: 1.5rem -1.5rem;
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding: 0.75rem;
  }
}
