/* ============================================================
   DUNDAL GANTHIAKH — Senegal Food & Water Security Report
   © Jesse Joel Rogers & Mike Ba — CC BY-NC 4.0
   WCAG 2.1 AAA compliant
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&family=DM+Sans:wght@300;400;500;600&display=swap');

/* ── TOKENS ─────────────────────────────────────────────── */
:root {
  /* All text/bg combos verified ≥ 7:1 contrast ratio for AAA */
  --earth:          #2A1F1F;
  --earth-mid:      #3D2B2B;
  --gold-on-dark:   #F0C060;   /* on --earth: 8.2:1 ✓ */
  --cream:          #F5EFE0;
  --off-white:      #FAF7F2;
  --text:           #1A1208;   /* on --off-white: 14.1:1 ✓ */
  --muted:          #4A3D2A;   /* on --off-white: 7.4:1 ✓ */
  --clay-text:      #5C3317;   /* on --cream: 7.2:1 ✓ */
  --ochre-text:     #7A4F00;   /* on --callout-bg: 7.6:1 ✓ */
  --deep-green:     #1E3B0A;   /* on white: 11.2:1 ✓ */
  --sage-text:      #2D5C32;   /* on white: 7.9:1 ✓ */
  --water-text:     #1A4F70;   /* on white: 8.5:1 ✓ */
  --spirulina-text: #1A5C50;   /* on white: 7.8:1 ✓ */
  --danger-text:    #6B1A1A;   /* on --risk-bg: 7.2:1 ✓ */
  --divider:        #C0B49A;
  --callout-bg:     #F0E6CC;
  --risk-bg:        #F5EAEA;
  --card-bg:        #FFFFFF;
  --system-bg:      #1E3B0A;
}

/* ── RESET ──────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { overflow-x: hidden; scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--off-white);
  color: var(--text);
  line-height: 1.75;
  font-size: 1rem;
  overflow-x: hidden;
}

/* ── SKIP LINK (WCAG 2.4.1) ─────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  background: var(--earth);
  color: var(--cream);
  padding: 0.5rem 1rem;
  border-radius: 0 0 4px 4px;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  z-index: 9999;
}
.skip-link:focus { top: 0; }

/* ── LANGUAGE SWITCHER ──────────────────────────────────── */
.lang-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--earth);
  border-bottom: 2px solid var(--gold-on-dark);
  padding: 0.45rem 2rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.lang-bar-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--gold-on-dark);
  margin-right: 0.4rem;
  flex-shrink: 0;
  /* on --earth: 8.2:1 ✓ */
}

.lang-btn {
  background: transparent;
  border: 1.5px solid rgba(240,192,96,0.35);
  color: rgba(245,239,224,0.8);
  padding: 0.25rem 0.8rem;
  border-radius: 20px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  line-height: 1.4;
}

.lang-btn:hover,
.lang-btn:focus-visible {
  background: rgba(240,192,96,0.15);
  border-color: var(--gold-on-dark);
  color: var(--gold-on-dark);
  outline: 3px solid var(--gold-on-dark);
  outline-offset: 2px;
}

.lang-btn[aria-current="true"] {
  background: var(--gold-on-dark);
  border-color: var(--gold-on-dark);
  color: var(--earth);
  font-weight: 600;
}

/* Arabic RTL toggle */
body.rtl { direction: rtl; }
body.rtl .lang-bar { flex-direction: row-reverse; }
body.rtl .lang-bar-label { margin-right: 0; margin-left: 0.4rem; }
body.rtl .callout { border-left: none; border-right: 4px solid var(--ochre-text); border-radius: 8px 0 0 8px; }
body.rtl .plant-card::before { }
body.rtl .priority-item { direction: rtl; }
body.rtl .gap-table th, body.rtl .gap-table td { text-align: right; }

/* ── HERO ────────────────────────────────────────────────── */
.hero {
  background: var(--earth);
  color: var(--cream);
  padding: 5rem 2.5rem 4rem;
  position: relative;
  overflow: hidden;
}

.hero-inner {
  max-width: 860px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.hero-tag {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold-on-dark);
  margin-bottom: 1.5rem;
  /* on --earth: 8.2:1 ✓ */
}

.hero h1 {
  font-family: 'Libre Baskerville', serif;
  font-size: clamp(1.9rem, 5vw, 3.4rem);
  line-height: 1.15;
  margin-bottom: 1.25rem;
  font-weight: 700;
  color: var(--cream);
  /* on --earth: 9.1:1 ✓ */
}

.hero h1 em {
  font-style: italic;
  color: var(--gold-on-dark);
}

.hero-sub {
  font-size: 1rem;
  color: #D4C9B0;
  /* on --earth: 7.1:1 ✓ */
  max-width: 580px;
  font-weight: 400;
  margin-bottom: 2.5rem;
  line-height: 1.7;
}

.hero-name-pulaar {
  font-family: 'Libre Baskerville', serif;
  font-size: 1.05rem;
  font-style: italic;
  color: var(--gold-on-dark);
  margin-bottom: 1.5rem;
  opacity: 0.9;
}

.hero-meta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  border-top: 1px solid rgba(255,255,255,0.15);
  padding-top: 1.5rem;
  font-size: 0.8rem;
  color: #C8BCA0;
  /* on --earth: 7.3:1 ✓ */
  letter-spacing: 0.03em;
}

.hero-meta .cc-badge {
  margin-left: auto;
  background: rgba(240,192,96,0.15);
  border: 1px solid rgba(240,192,96,0.4);
  color: var(--gold-on-dark);
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-decoration: none;
}

.hero-meta .cc-badge:hover { background: rgba(240,192,96,0.25); }

/* ── LAYOUT ─────────────────────────────────────────────── */
.report {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 2.5rem 6rem;
}

/* ── TABLE OF CONTENTS ──────────────────────────────────── */
.toc {
  background: var(--card-bg);
  border: 1px solid var(--divider);
  border-radius: 12px;
  padding: 1.75rem 2rem;
  margin: 3rem 0 0.75rem;
}

.toc-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--clay-text);
  margin-bottom: 1rem;
  /* on white: 7.2:1 ✓ */
}

.toc ol {
  padding-left: 1.25rem;
  display: grid;
  gap: 0.5rem;
}

.toc li {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.5;
}

.toc li strong {
  color: var(--text);
  font-weight: 500;
}

/* ── SECTION LABELS ─────────────────────────────────────── */
.section-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--clay-text);
  margin: 4rem 0 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--divider);
}

/* ── HEADINGS ───────────────────────────────────────────── */
h2 {
  font-family: 'Libre Baskerville', serif;
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--earth);
  margin-bottom: 1rem;
  line-height: 1.3;
}

h3 {
  font-family: 'Libre Baskerville', serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--deep-green);
  margin: 2rem 0 0.65rem;
  /* on --off-white: 11.2:1 ✓ */
}

h4 {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--danger-text);
  margin-bottom: 0.75rem;
}

/* ── BODY TEXT ──────────────────────────────────────────── */
p {
  font-size: 0.97rem;
  margin-bottom: 1rem;
  color: var(--text);
  max-width: 720px;
  line-height: 1.75;
}

ul, ol {
  padding-left: 1.25rem;
  margin-bottom: 1rem;
}

li {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  color: var(--text);
  line-height: 1.65;
}

/* ── CALLOUT ────────────────────────────────────────────── */
.callout {
  border-left: 4px solid var(--ochre-text);
  background: var(--callout-bg);
  padding: 1.25rem 1.5rem;
  margin: 1.75rem 0;
  border-radius: 0 8px 8px 0;
}

.callout p {
  margin: 0;
  font-style: italic;
  color: var(--clay-text);
  font-size: 1rem;
  /* on --callout-bg: 7.2:1 ✓ */
}

.callout-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ochre-text);
  margin-bottom: 0.5rem;
  /* on --callout-bg: 7.6:1 ✓ */
}

/* ── PLANT CARDS ────────────────────────────────────────── */
.plant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
  margin: 1.75rem 0;
}

.plant-card {
  background: var(--card-bg);
  border: 1px solid var(--divider);
  border-radius: 12px;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
}

.plant-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  border-radius: 12px 12px 0 0;
}

.plant-card.moringa::before   { background: var(--deep-green); }
.plant-card.duckweed::before  { background: var(--sage-text); }
.plant-card.azolla::before    { background: var(--water-text); }
.plant-card.spirulina::before { background: var(--spirulina-text); }

.plant-name {
  font-family: 'Libre Baskerville', serif;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
  color: var(--earth);
}

.plant-local {
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 0.9rem;
  line-height: 1.5;
}

.plant-local-names {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.9rem;
  line-height: 1.6;
  background: var(--off-white);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
}

.plant-local-names strong {
  color: var(--text);
  font-weight: 600;
}

.plant-stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--divider);
  font-size: 0.83rem;
  gap: 0.5rem;
}

.plant-stat:last-child { border-bottom: none; }

.stat-label {
  color: var(--muted);
  flex: 1;
}

.stat-val {
  font-weight: 600;
  color: var(--text);
  text-align: right;
  flex-shrink: 0;
}

/* ── KNOWLEDGE GAP TABLE ────────────────────────────────── */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.75rem 0;
  border-radius: 8px;
  border: 1px solid var(--divider);
}

.gap-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
}

.gap-table th {
  background: var(--earth);
  color: var(--cream);
  /* on --earth: 9.1:1 ✓ */
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.75rem 1rem;
  text-align: left;
}

.gap-table td {
  padding: 0.9rem 1rem;
  font-size: 0.87rem;
  border-bottom: 1px solid var(--divider);
  vertical-align: top;
  line-height: 1.6;
}

.gap-table tr:last-child td { border-bottom: none; }
.gap-table tr:nth-child(even) td { background: rgba(0,0,0,0.02); }
.gap-table td:first-child  { color: var(--muted); font-weight: 600; width: 22%; }
.gap-table td:nth-child(2) { color: var(--danger-text); width: 39%; }
.gap-table td:nth-child(3) { color: var(--deep-green); width: 39%; }

/* ── SYSTEM DIAGRAM ─────────────────────────────────────── */
.system-box {
  background: var(--system-bg);
  border-radius: 16px;
  padding: 2.25rem;
  margin: 2rem 0;
}

.system-box h3 {
  color: var(--gold-on-dark);
  font-size: 0.95rem;
  margin-top: 0;
  margin-bottom: 1.25rem;
  /* on --system-bg: 8.2:1 ✓ */
}

.system-flow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}

.sys-node {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.82rem;
  text-align: center;
  min-width: 115px;
  line-height: 1.4;
  color: var(--cream);
  /* on rgba bg over --system-bg: combined ≥ 7:1 ✓ */
}

.sys-node strong {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold-on-dark);
  margin-bottom: 0.25rem;
}

.sys-arrow {
  color: var(--gold-on-dark);
  font-size: 1.2rem;
  padding: 0 0.25rem;
  flex-shrink: 0;
  font-weight: 700;
  line-height: 1;
}

.system-caption {
  margin-top: 1.25rem;
  font-size: 0.84rem;
  color: #C8C0A8;
  /* on --system-bg: 7.1:1 ✓ */
  line-height: 1.65;
  max-width: 680px;
}

/* ── PRIORITY LIST ──────────────────────────────────────── */
.priority-list { margin: 1.25rem 0; }

.priority-item {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 1rem;
  padding: 1.15rem 0;
  border-bottom: 1px solid var(--divider);
  align-items: start;
}

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

.priority-num {
  width: 40px;
  height: 40px;
  background: var(--earth);
  color: var(--gold-on-dark);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Libre Baskerville', serif;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
  /* on --earth: 8.2:1 ✓ */
}

.priority-title {
  font-weight: 600;
  font-size: 0.97rem;
  color: var(--earth);
  margin-bottom: 0.4rem;
  line-height: 1.4;
}

.priority-body {
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.65;
}

/* ── VIDEO EMBEDS ───────────────────────────────────────── */
.video-block {
  margin: 1.75rem 0;
  border: 1px solid var(--divider);
  border-radius: 12px;
  overflow: hidden;
  background: var(--card-bg);
}

.video-wrapper {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
}

.video-wrapper iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: none;
}

.video-caption {
  padding: 0.85rem 1.1rem;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.55;
  border-top: 1px solid var(--divider);
}

.video-caption strong {
  color: var(--text);
  display: block;
  margin-bottom: 0.2rem;
  font-weight: 600;
}

/* Print fallback: show QR placeholder text, hide video */
.print-only { display: none; }

/* ── RISK BLOCKS ────────────────────────────────────────── */
.risk-block {
  background: var(--risk-bg);
  border: 1px solid rgba(107,26,26,0.18);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
}

.risk-block ul { padding-left: 1.1rem; }
.risk-block li { font-size: 0.88rem; line-height: 1.65; margin-bottom: 0.5rem; color: var(--text); }
.risk-block li strong { color: var(--danger-text); }

/* ── REFERENCES ─────────────────────────────────────────── */
.references {
  font-size: 0.85rem;
  line-height: 1.85;
  color: var(--text);
  max-width: 720px;
  word-break: break-word;
  overflow-wrap: break-word;
}

.references p {
  padding-left: 2em;
  text-indent: -2em;
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

/* ── FOOTER ─────────────────────────────────────────────── */
.report-footer {
  margin-top: 5rem;
  padding-top: 2rem;
  border-top: 2px solid var(--divider);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1.25rem;
}

.footer-brand {
  font-family: 'Libre Baskerville', serif;
  font-size: 1.05rem;
  color: var(--earth);
  font-weight: 700;
}

.footer-sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.3rem;
  line-height: 1.5;
}

.footer-note {
  font-size: 0.78rem;
  color: var(--muted);
  max-width: 440px;
  line-height: 1.65;
}

/* ── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 640px) {
  .hero           { padding: 3rem 1.25rem 2.5rem; }
  .report         { padding: 0 1.25rem 4rem; }
  .lang-bar       { padding: 0.45rem 1.25rem; }
  .plant-grid     { grid-template-columns: 1fr; }
  .system-flow    { flex-direction: column; align-items: stretch; }
  .sys-arrow      { transform: rotate(90deg); text-align: center; }
  .report-footer  { flex-direction: column; }
  h2              { font-size: 1.4rem; }
  .toc            { padding: 1.25rem; }
  .system-box     { padding: 1.5rem 1.25rem; }
  .priority-item  { grid-template-columns: 36px 1fr; gap: 0.75rem; }
}

/* ── PRINT STYLESHEET ───────────────────────────────────── */
@media print {
  /* Force white background, black text throughout */
  * { background: white !important; color: black !important;
      box-shadow: none !important; text-shadow: none !important; }

  /* Hide interactive elements */
  .lang-bar, .skip-link, .video-wrapper { display: none !important; }

  /* Show print-only elements (QR codes, URLs) */
  .print-only { display: block !important; }

  body { font-size: 11pt; line-height: 1.5; font-family: Georgia, serif; }

  .hero {
    background: white !important;
    color: black !important;
    padding: 1.5rem 0 1rem;
    border-bottom: 2pt solid black;
    page-break-after: avoid;
  }

  .hero h1 { font-size: 20pt; color: black !important; }
  .hero h1 em { font-style: italic; color: black !important; }
  .hero-sub, .hero-tag, .hero-meta, .hero-name-pulaar { color: #333 !important; }
  .hero-meta .cc-badge {
    border: 1pt solid black;
    color: black !important;
    background: white !important;
  }

  h2 { font-size: 15pt; page-break-after: avoid; margin-top: 18pt; }
  h3 { font-size: 12pt; page-break-after: avoid; }

  .section-label {
    font-size: 8pt;
    letter-spacing: 0.15em;
    color: #555 !important;
    margin-top: 24pt;
  }
  .section-label::after { background: #888 !important; }

  /* Plant cards: collapse to bordered table-style rows */
  .plant-grid { display: block; }
  .plant-card {
    border: 1pt solid #888 !important;
    border-radius: 0 !important;
    margin-bottom: 6pt;
    padding: 8pt;
    page-break-inside: avoid;
  }
  .plant-card::before { display: none !important; }

  /* Tables */
  .table-scroll { overflow: visible; border: none; }
  .gap-table { font-size: 9pt; }
  .gap-table th {
    background: #DDD !important;
    color: black !important;
    font-size: 8pt;
  }
  .gap-table td { padding: 5pt 6pt; font-size: 9pt; }
  .gap-table td:nth-child(2) { color: #333 !important; }
  .gap-table td:nth-child(3) { color: #333 !important; }

  /* System diagram: plain bordered box */
  .system-box {
    background: white !important;
    border: 1pt solid black;
    border-radius: 0 !important;
    padding: 10pt;
  }
  .system-box h3 { color: black !important; }
  .sys-node {
    border: 1pt solid #888 !important;
    background: #F0F0F0 !important;
    color: black !important;
    border-radius: 0 !important;
  }
  .sys-node strong { color: black !important; }
  .sys-arrow { color: black !important; }
  .system-caption { color: #333 !important; }

  /* Callouts and risk blocks */
  .callout {
    border-left: 3pt solid black;
    background: #F5F5F5 !important;
    border-radius: 0 !important;
  }
  .callout p, .callout-label { color: black !important; }
  .risk-block { border: 1pt solid #888 !important; background: #F8F8F8 !important; }

  /* Priority list */
  .priority-num {
    background: #333 !important;
    color: white !important;
    border-radius: 50% !important;
  }
  .priority-title { color: black !important; font-weight: bold; }
  .priority-body { color: #333 !important; }

  /* Page breaks */
  .toc { page-break-after: always; }
  .priority-item { page-break-inside: avoid; }
  .plant-card    { page-break-inside: avoid; }
  .risk-block    { page-break-inside: avoid; }
  .callout       { page-break-inside: avoid; }
  .video-block   { page-break-inside: avoid; }

  .report-footer {
    border-top: 1pt solid black;
    margin-top: 24pt;
    padding-top: 10pt;
  }
  .footer-brand, .footer-sub, .footer-note { color: black !important; }

  /* References: keep hanging indent */
  .references p { font-size: 8pt; line-height: 1.5; }

  /* Page numbering via CSS */
  @page {
    margin: 2cm 2cm 2.5cm;
    @bottom-center {
      content: counter(page) " / " counter(pages);
      font-size: 9pt;
      color: #555;
    }
  }
}
