/* =========================================================================
   Critical Matters — stylesheet
   Edit values here to tweak look & feel.
   Colors are also mirrored in map.js CONFIG for the graph itself.
   ========================================================================= */

:root {
  --bg:        #FAFAF7;
  --surface:   #FFFFFF;
  --text:      #1A1A1A;
  --muted:     #6A6A6A;
  --border:    #E4E4DE;
  --accent:    #230AEA;
  --accent-fg: #FFFFFF;
  --shadow:    0 2px 12px rgba(0,0,0,0.06);
  --radius:    10px;
  --font:      'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
}

/* --------- Top bar --------- */
#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 2px solid transparent;
  border-image: linear-gradient(90deg, #230AEA 0%, #FFD0C3 100%) 1;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand h1.brand-logo {
  display: flex;
  align-items: center;
}

.brand h1.brand-logo img {
  height: 43.2px;
  width: auto;
  display: block;
}

.brand .subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.view-toggle {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.view-toggle button {
  border: 0;
  background: transparent;
  padding: 7px 16px;
  border-radius: 999px;
  font: inherit;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}

.view-toggle button.active {
  background: var(--accent);
  color: var(--accent-fg);
}

/* --------- Main layout --------- */
main {
  display: grid;
  grid-template-columns: 260px 1fr;
  overflow: hidden;
  position: relative;
}

/* --------- Filters --------- */
#filters {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
}

.filters-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
}

.filters-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

/* Toggle that collapses the filter list on mobile. On desktop the button is
   the heading itself (no chevron, no click action — full content stays open). */
.filters-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: default;
  font: inherit;
  color: inherit;
}
.filters-toggle-chevron { display: none; }

.link-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  padding: 0;
}
.link-btn:hover { text-decoration: underline; }

.filter-group {
  margin-bottom: 18px;
}

.filter-group > label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.filter-group > label.inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  margin-bottom: 6px;
}

.filter-group input[type="search"],
.filter-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font: inherit;
  color: var(--text);
}

.filter-group input[type="search"]:focus,
.filter-group select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}

/* Organization checkboxes stay fully expanded — no scroll, no collapse. */
#filter-orgtype .checkbox-list {
  max-height: none;
  overflow: visible;
}

/* Collapsible filter sections (Metal, Value-chain step). Native <details>. */
.filter-collapsible > summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  list-style: none;
  user-select: none;
}
.filter-collapsible > summary::-webkit-details-marker { display: none; }
.filter-collapsible > summary::after {
  content: '+';
  font-size: 16px;
  line-height: 1;
  color: var(--muted);
  font-weight: 400;
}
.filter-collapsible[open] > summary::after { content: '−'; }

/* Search-bar suggestion dropdown. */
#search-group { position: relative; }

#search-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  z-index: 50;
  max-height: 320px;
  overflow-y: auto;
}

#search-suggestions[hidden] { display: none; }

.suggest-section {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 8px 12px 2px;
  border-top: 1px solid var(--border);
}
.suggest-section:first-child { border-top: 0; }

.suggest-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.suggest-item:hover, .suggest-item.active {
  background: var(--bg);
}

.suggest-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 3px 0;
  cursor: pointer;
}

/* --------- Graph --------- */
#graph-wrapper {
  position: relative;
  background: var(--bg);
}

#cy {
  width: 100%;
  height: 100%;
  transition: transform 280ms cubic-bezier(0.2, 0.7, 0.2, 1);
  will-change: transform;
}

#loading {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-size: 14px;
}

#legend {
  position: absolute;
  right: 16px;
  bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  max-width: 220px;
  font-size: 12px;
  line-height: 1.6;
}

#legend h3 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-swatch {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.legend-note {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* --------- Detail panel --------- */
#detail-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 360px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 48px 24px 24px;
  overflow-y: auto;
  transition: transform 0.2s ease;
}

#detail-panel[hidden] {
  display: block !important;
  transform: translateX(100%);
  visibility: hidden;
}

#close-detail {
  position: absolute;
  top: 10px; right: 14px;
  border: 0;
  background: transparent;
  font-size: 28px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

#back-detail {
  position: absolute;
  top: 12px; left: 16px;
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

#back-detail:hover { color: var(--text); }

#back-detail[hidden] { display: none; }

#detail-body .logo {
  width: 48px; height: 48px;
  border-radius: 8px;
  object-fit: contain;
  background: var(--bg);
  padding: 6px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

#detail-body h3 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 600;
}

#detail-body .tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 14px;
}

.tag {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
}

#detail-body .field {
  margin-top: 14px;
}

#detail-body .field-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 4px;
}

#detail-body .field-value { font-size: 14px; }

#detail-body .org-link {
  color: var(--accent);
  cursor: pointer;
}
#detail-body .org-link:hover { text-decoration: underline; }

/* --------- Footer --------- */
footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

footer .eu-logo {
  height: 28px;
  width: auto;
  object-fit: contain;
  flex: 0 0 auto;
}

footer .mixi-logo {
  height: 9px;
  width: auto;
  object-fit: contain;
  vertical-align: middle;
  margin-right: 14px;
}

footer span:first-child {
  display: inline-flex;
  align-items: center;
}

footer a {
  color: #230AEA;
  margin-left: 4px;
}

/* --------- Source credit (in detail panel) --------- */
.field-source {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}
.field-source a {
  color: var(--muted);
  text-decoration: underline;
}

/* --------- Intro overlay --------- */
#intro-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#intro-overlay[hidden] {
  display: none;
}

.intro-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 440px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
}

.intro-card h2 { margin-top: 0; }
.intro-card ul { padding-left: 20px; }
.intro-card li { margin-bottom: 6px; }

.intro-card button {
  margin-top: 10px;
  background: var(--accent);
  color: var(--accent-fg);
  border: 0;
  padding: 10px 20px;
  border-radius: 6px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

/* --------- Database page (card grid) --------- */
#card-grid-wrapper {
  overflow-y: auto;
  background: var(--bg);
  padding: 20px 24px 40px;
  position: relative;
}

#db-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--muted);
}

#card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.org-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.org-card:hover, .org-card:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
  outline: none;
}

.card-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.card-head-text {
  min-width: 0;
  flex: 1 1 auto;
}

.card-favicon {
  width: 32px; height: 32px;
  border-radius: 6px;
  object-fit: contain;
  background: var(--bg);
  padding: 4px;
  border: 1px solid var(--border);
  flex: 0 0 auto;
}

.card-favicon-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--muted);
  font-size: 14px;
}

.card-name {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
  overflow-wrap: break-word;
}

.card-tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.card-tag {
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  letter-spacing: 0.02em;
}

.card-metals {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.card-metal-chip {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.card-desc {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-connected {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 2px;
}

.card-connected-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 3px;
}

.card-connected-list {
  font-size: 12px;
  color: var(--text);
  line-height: 1.4;
}

#empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px;
}

.page-nav .page-link {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  padding: 7px 15px;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  line-height: 1;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.page-nav .page-link:hover,
.page-nav .page-link:focus-visible {
  background: var(--accent);
  color: var(--accent-fg);
}

/* Feedback call-to-action — filled at rest so it always stands out. */
.page-nav .page-link-cta {
  background: var(--accent);
  color: var(--accent-fg);
}
.page-nav .page-link-cta:hover,
.page-nav .page-link-cta:focus-visible {
  filter: brightness(1.12);
}

/* --------- Mobile --------- */
@media (max-width: 768px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  #filters {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    max-height: 60vh;
    padding: 12px 20px;
    overflow-y: auto;
  }

  .filters-header {
    margin-bottom: 0;
  }

  /* On mobile, the heading becomes an actual toggle. Chevron rotates with
     aria-expanded. Filter content is hidden by default. */
  .filters-toggle {
    cursor: pointer;
    flex: 1;
    justify-content: flex-start;
  }
  .filters-toggle-chevron {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--muted);
    transition: transform 0.15s ease;
    margin-left: 4px;
  }
  .filters-toggle[aria-expanded="true"] .filters-toggle-chevron {
    transform: rotate(180deg);
  }

  .filter-content {
    display: none;
    margin-top: 12px;
  }
  #filters[data-open="true"] .filter-content {
    display: block;
  }

  #detail-panel {
    width: 100%;
  }

  #top-bar {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }

  #legend {
    display: none; /* Save screen space on mobile */
  }
}

/* =========================================================================
   News page
   ========================================================================= */

/* Header nav holds several page links on the news/database pages. */
.page-nav {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Current page — filled pill so users can see where they are at a glance. */
.page-nav .page-link.active {
  background: var(--accent);
  color: var(--accent-fg);
}

/* Footer links (About / Leave feedback). */
.footer-nav {
  display: flex;
  align-items: center;
  gap: 16px;
}
.footer-nav a {
  color: var(--accent);
  font-weight: 600;
}

/* Slightly wider cards than the org grid — news summaries need more room. */
#card-grid.news-grid {
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.news-card {
  cursor: default;
}
.news-card:hover, .news-card:focus-visible {
  /* keep the subtle lift, but news cards aren't clickable as a whole */
  transform: none;
}

.news-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.news-date {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.news-cat {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}

/* Category accent colors (indices match CATEGORY_ORDER in news.js). */
.news-cat.cat-0 { color: #1d6f42; border-color: #bfe3cd; background: #eaf6ef; } /* Funding */
.news-cat.cat-1 { color: #8a4b00; border-color: #f0d8b8; background: #fbf1e3; } /* Policy */
.news-cat.cat-2 { color: #230AEA; border-color: #cdc6fb; background: #eeebfe; } /* Research */
.news-cat.cat-3 { color: #9c2a5b; border-color: #f3c9da; background: #fcecf3; } /* Industry */

.news-desc {
  -webkit-line-clamp: 5;   /* allow more of the summary than org cards */
}

.news-related {
  font-size: 12px;
  color: var(--muted);
}

.news-foot {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 2px;
}

.news-source {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

/* =========================================================================
   About page
   ========================================================================= */
.about-page main {
  display: block;
  overflow-y: auto;
}
.about-main {
  padding: 32px 24px 64px;
}
.about-content {
  max-width: 760px;
  margin: 0 auto;
}
.about-content section {
  margin-bottom: 34px;
}
.about-content h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 10px;
}
.about-content h3 {
  font-size: 16px;
  font-weight: 700;
  margin: 22px 0 6px;
}
.about-content p {
  line-height: 1.6;
  margin: 0 0 12px;
}
.about-content ul {
  margin: 0 0 12px;
  padding-left: 20px;
}
.about-content li {
  line-height: 1.55;
  margin-bottom: 6px;
}
.about-content .placeholder {
  color: var(--muted);
}
.about-content .muted-note {
  font-size: 13px;
  color: var(--muted);
}

/* Collapsible sub-sections on the About page (keep the page short). */
.about-collapsible {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
  background: var(--surface);
}
.about-collapsible > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  user-select: none;
}
.about-collapsible > summary::-webkit-details-marker { display: none; }
.about-collapsible > summary::after {
  content: '+';
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  font-weight: 400;
}
.about-collapsible[open] > summary::after { content: '−'; }
.about-collapsible[open] > summary {
  border-bottom: 1px solid var(--border);
}
.about-collapsible-body {
  padding: 4px 16px 14px;
}
.about-collapsible-body ul { margin-top: 8px; }

/* Multi-column list for the longer raw-materials enumeration. */
.about-content ul.cols {
  columns: 2;
  column-gap: 28px;
}
.about-content ul.cols li { break-inside: avoid; }
@media (max-width: 540px) {
  .about-content ul.cols { columns: 1; }
}
