/* Mycélium — Design system */
:root {
  /* Clear, warm background */
  --bg-base: #f8f6f1;
  --bg-card: #ffffff;
  --bg-card-hover: #fdfcfa;

  /* Forest & mycelium palette */
  --forest-900: #1a2f1e;
  --forest-700: #2d4a32;
  --forest-600: #355d3d;
  --forest-500: #3d6b47;
  --forest-300: #6b9b6e;
  --forest-100: #c5ddc4;

  /* Amber & terracotta accents */
  --amber-600: #c17f3a;
  --amber-500: #d4a054;
  --amber-200: #f0d9b8;
  --terracotta: #b85c38;
  --burgundy: #722f37;

  /* Neutrals */
  --text-primary: #1a2f1e;
  --text-secondary: #4a5d4e;
  --text-muted: #7a8b7c;
  --border: #e2e6de;
  --shadow: rgba(26, 47, 30, 0.08);
  --shadow-hover: rgba(26, 47, 30, 0.12);

  --radius: 12px;
  --radius-lg: 16px;
  --font-sans: 'Outfit', system-ui, sans-serif;
  --font-display: 'Playfair Display', serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--forest-900) 0%, var(--forest-700) 100%);
  color: #fff;
  padding: 1.5rem 2rem;
  box-shadow: 0 4px 20px var(--shadow);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
}

.logo {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 600;
  margin: 0 0 0.25rem 0;
  letter-spacing: 0.02em;
}

.logo-link {
  color: inherit;
  text-decoration: none;
}

.logo-link:hover {
  opacity: 0.9;
}

.tagline {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 400;
  opacity: 0.9;
}

/* Main */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.dashboard {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

/* Subject section */
.subject-section {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 16px var(--shadow);
  overflow: hidden;
  border: 1px solid var(--border);
}

.subject-header {
  background: linear-gradient(90deg, var(--forest-500) 0%, var(--forest-300) 100%);
  color: #fff;
  padding: 1rem 1.5rem;
  font-weight: 600;
  font-size: 1.1rem;
}

.subject-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* KPIs grid */
.kpis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.kpi-card {
  background: var(--bg-card-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  text-decoration: none;
  color: inherit;
  display: block;
  text-align: left;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--shadow-hover);
  border-color: var(--forest-300);
}

.kpi-card .kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--forest-700);
  margin-bottom: 0.25rem;
}

.kpi-card .kpi-unit {
  font-size: 0.9rem;
  color: var(--amber-600);
  font-weight: 500;
}

.kpi-card .kpi-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  line-height: 1.35;
}

.kpi-card .kpi-context {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  line-height: 1.35;
}

/* Charts & graphs container */
.viz-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
}

.viz-card {
  background: var(--bg-card-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  text-decoration: none;
  color: inherit;
  display: block;
}

.viz-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--shadow-hover);
  border-color: var(--forest-300);
}

.viz-card h3 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--forest-700);
}

.chart-value-label {
  margin: 0 0 0.5rem 0;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.line-graph-wrap {
  position: relative;
}

/* Chart SVG axes */
.chart-svg {
  width: 100%;
  max-height: 280px;
  overflow: visible;
}

.chart-svg .axis-line {
  stroke: var(--forest-700);
  stroke-width: 1.5;
  stroke-linecap: round;
}

.chart-svg .axis-tick {
  stroke: var(--forest-500);
  stroke-width: 1;
}

.chart-svg .axis-tick-label {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  fill: var(--text-secondary);
}

.chart-svg .axis-tick-label-x {
  font-size: 10px;
}

.chart-svg .axis-title {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  fill: var(--forest-700);
}

.chart-svg .axis-title-x {
  font-size: 10px;
  fill: var(--text-secondary);
}

.chart-svg .bar-fill-svg {
  transition: opacity 0.2s ease;
}

.chart-svg .bar-fill-svg.amber { fill: var(--amber-500); }
.chart-svg .bar-fill-svg.forest { fill: var(--forest-500); }
.chart-svg .bar-fill-svg.terracotta { fill: var(--terracotta); }

.viz-card:hover .chart-svg .bar-fill-svg {
  opacity: 0.9;
}

.axis-caption {
  margin: 0.35rem 0 0 0;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.viz-placeholder {
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Bar chart */
.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.bar-label {
  flex: 0 0 140px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  flex: 1;
  height: 24px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 6px;
  min-width: 4px;
  transition: width 0.5s ease;
}

.bar-fill.amber { background: linear-gradient(90deg, var(--amber-500), var(--amber-600)); }
.bar-fill.forest { background: linear-gradient(90deg, var(--forest-300), var(--forest-500)); }
.bar-fill.terracotta { background: linear-gradient(90deg, var(--terracotta), var(--burgundy)); }

.bar-value {
  flex: 0 0 36px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--forest-700);
  text-align: right;
}

/* Line graph */
.line-graph {
  min-height: 240px;
  position: relative;
}

.line-graph .line {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 0.2s ease;
}

.line-graph .line.amber { stroke: var(--amber-600); }
.line-graph .line.forest { stroke: var(--forest-500); }
.line-graph .line.terracotta { stroke: var(--terracotta); }

.line-graph .dot {
  transition: r 0.2s ease;
}

.viz-card:hover .line-graph .dot {
  r: 6;
}

.legend-box {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.legend-title {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.legend-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.legend-dot {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  margin-top: 0.35rem;
  border-radius: 50%;
}

.legend-dot.amber { background: var(--amber-600); }
.legend-dot.forest { background: var(--forest-500); }
.legend-dot.terracotta { background: var(--terracotta); }

.legend-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.legend-name {
  font-weight: 600;
  color: var(--text-primary);
}

.legend-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* Source page */
.main-source {
  padding-top: 1rem;
}

.back-link {
  display: inline-block;
  margin-bottom: 1.5rem;
  color: var(--forest-600);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.back-link:hover {
  color: var(--forest-700);
}

.source-content {
  max-width: 560px;
}

.source-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 16px var(--shadow);
  border: 1px solid var(--border);
  padding: 2rem;
}

.source-title {
  margin: 0 0 0.75rem 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--forest-700);
  word-break: break-all;
}

.source-description {
  margin: 0 0 1.5rem 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.source-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--shadow-hover);
}

.btn-primary {
  background: linear-gradient(135deg, var(--forest-500), var(--forest-600));
  color: #fff;
  border: none;
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--forest-600), var(--forest-700));
}

.btn-secondary {
  background: var(--bg-base);
  color: var(--forest-700);
  border: 2px solid var(--forest-300);
}

.btn-secondary:hover {
  border-color: var(--forest-500);
  color: var(--forest-900);
}

/* Footer */
.footer {
  margin-top: 3rem;
  padding: 1.5rem 2rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

/* Article app (liste + lecture) */
.main-article {
  max-width: 720px;
}

.article-app {
  min-height: 40vh;
}

.article-list-intro {
  color: var(--text-secondary);
  margin: 0 0 1.25rem 0;
}

.article-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.article-card {
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  text-decoration: none;
  color: inherit;
  box-shadow: 0 2px 12px var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.article-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--shadow-hover);
  border-color: var(--forest-300);
}

.article-card-title {
  margin: 0 0 0.35rem 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--forest-700);
}

.article-card-meta {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.article-body {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: 0 2px 16px var(--shadow);
  padding: 2rem 2.25rem;
}

.article-header .back-link {
  margin-bottom: 1rem;
}

.article-title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 600;
  color: var(--forest-900);
  margin: 0 0 0.5rem 0;
  line-height: 1.2;
}

.article-subtitle {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--forest-600);
  margin: 0 0 1rem 0;
}

.article-deck {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin: 0 0 0.75rem 0;
  line-height: 1.55;
}

.article-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
}

.takeaways {
  margin: 1.75rem 0;
  padding: 1.25rem 1.5rem;
  background: var(--bg-base);
  border-radius: var(--radius);
  border-left: 4px solid var(--amber-500);
}

.takeaways-title {
  margin: 0 0 0.75rem 0;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--amber-600);
}

.takeaways-list {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--text-primary);
  line-height: 1.55;
}

.takeaways-list li {
  margin-bottom: 0.5rem;
}

.article-section {
  margin-top: 2rem;
}

.article-section-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--forest-700);
  margin: 0 0 1rem 0;
}

.article-p {
  margin: 0 0 1rem 0;
  color: var(--text-primary);
  line-height: 1.65;
}

.metaphor-box {
  margin: 1.25rem 0;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, var(--forest-100) 0%, #e8f0e8 100%);
  border-radius: var(--radius);
  border: 1px solid var(--forest-300);
}

.metaphor-box .metaphor-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--forest-600);
  margin-bottom: 0.5rem;
}

.metaphor-box p {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-primary);
  line-height: 1.55;
}

.article-figures {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.article-figure {
  margin: 0;
}

.article-figure img {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.article-figure figcaption {
  margin-top: 0.65rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.article-figure-heading {
  margin: 0 0 0.75rem 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--forest-700);
}

.article-figure-svg {
  background: var(--bg-card-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.article-viz-inner .article-viz-title {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--forest-700);
}

.viz-source-link {
  display: inline-block;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--forest-600);
  text-decoration: none;
}

.viz-source-link:hover {
  color: var(--forest-700);
  text-decoration: underline;
}

.viz-fallback {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0;
}

.article-limitations {
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border);
}

/* Conseils pratiques (fin d'article) */
.article-practical {
  margin-top: 2rem;
  padding: 1.35rem 1.5rem;
  background: linear-gradient(135deg, #e8f2ea 0%, var(--bg-base) 100%);
  border-radius: var(--radius-lg);
  border: 1px solid var(--forest-300);
  box-shadow: 0 2px 12px var(--shadow);
}

.article-practical .article-section-title {
  margin-top: 0;
  color: var(--forest-700);
}

.article-practical-lead {
  margin: 0 0 1rem 0;
  font-size: 0.98rem;
  color: var(--text-secondary);
  line-height: 1.55;
}

.practical-list {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--text-primary);
  line-height: 1.6;
}

.practical-list li {
  margin-bottom: 0.55rem;
}

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

.error {
  background: #fef2f2;
  color: #991b1b;
  padding: 1rem 1.5rem;
  border-radius: var(--radius);
  margin: 1rem 0;
}

@media (max-width: 640px) {
  .header, .main {
    padding-left: 1rem;
    padding-right: 1rem;
  }

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

  .viz-row {
    grid-template-columns: 1fr;
  }

  .bar-label {
    flex: 0 0 100px;
  }
}
