:root {
  --bg: #f7f7f4;
  --surface: #ffffff;
  --ink: #1f2421;
  --muted: #6b7280;
  --line: #e3e3dc;
  --accent: #2e6b4f;        /* verde anfíbio */
  --accent-dark: #1f4a36;
  --accent-soft: #e8f1ec;
  --ok: #4caf50;
  --ok-bg: #e6f4ea;
  --warn: #c9881e;
  --warn-bg: #fbf0d8;
  --err: #c0392b;
  --err-bg: #fbe6e3;
  --neutral: #8a8f98;
  --neutral-bg: #eceef0;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

/* Header */
.site-header {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  box-shadow: var(--shadow);
}
.site-header .wrap { padding-top: 22px; padding-bottom: 0; }
.brand h1 { margin: 0; font-size: 1.8rem; font-weight: 700; letter-spacing: -.01em; }
.brand h1 .v { font-weight: 400; opacity: .8; }
.tagline { margin: 4px 0 16px; opacity: .9; font-size: .95rem; }

.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent; border: none; color: #fff;
  padding: 12px 18px; font-size: .95rem; cursor: pointer;
  border-bottom: 3px solid transparent; opacity: .8;
  font-family: inherit;
}
.tab:hover { opacity: 1; }
.tab.is-active { opacity: 1; border-bottom-color: #fff; font-weight: 600; }

/* Views */
.view { display: none; padding: 28px 0 60px; }
.view.is-active { display: block; }

/* --- Hero (visual clean) --- */
.hero { padding: 24px 0 8px; }
.search-hero { max-width: 640px; margin: 0 auto 28px; text-align: center; }
.search-hero input {
  width: 100%; padding: 16px 20px; font-size: 1.1rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); box-shadow: var(--shadow);
  transition: box-shadow .15s, border-color .15s;
}
.search-hero input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.hero-hint { color: var(--muted); font-size: .9rem; margin: 10px 0 0; }
.link {
  background: none; border: none; padding: 0; color: var(--accent);
  font: inherit; cursor: pointer; text-decoration: underline;
}
.link:hover { color: var(--accent-dark); }

/* Cards-resumo */
.cards { display: flex; flex-wrap: wrap; gap: 16px; margin: 20px 0 28px; }
.cards.summary { justify-content: center; }
.cards .card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; flex: 1 1 160px; min-width: 140px;
  text-align: left;
}
.card .num { font-size: 2rem; font-weight: 700; color: var(--accent); line-height: 1.1; }
.card .lbl { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.card .sub { color: var(--ink); font-size: .82rem; margin-top: 6px; }

/* --- Table block --- */
.table-block { margin-top: 8px; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end;
  margin-bottom: 16px;
}
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters label {
  font-size: .8rem; color: var(--muted); display: flex; flex-direction: column; gap: 4px;
}
.filters select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); font-size: .9rem; color: var(--ink);
}
.btn-link {
  background: none; border: none; padding: 6px 0;
  color: var(--accent); cursor: pointer; font: inherit;
  text-decoration: underline; align-self: flex-end;
}
.btn-link:hover { color: var(--accent-dark); }
.btn-phylo-jump {
  background: var(--accent-soft);
  padding: 6px 12px; border-radius: 6px;
  text-decoration: none; font-weight: 600;
}
.btn-phylo-jump:hover { background: #d3e5d9; }

.btn-bibtex {
  background: var(--accent-soft);
  padding: 6px 12px; border-radius: 6px;
  text-decoration: none; font-weight: 600;
}
.btn-bibtex:hover:not(:disabled) { background: #d3e5d9; }
.btn-bibtex:disabled {
  opacity: .5; cursor: not-allowed;
  background: var(--neutral-bg); color: var(--muted);
}

/* Filtro de range de anos */
.filter-year .year-range {
  display: inline-flex; align-items: center; gap: 4px;
}
.filter-year input[type="number"] {
  width: 70px;
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: .9rem;
  color: var(--ink);
  font-family: var(--mono);
  -moz-appearance: textfield;
}
.filter-year input[type="number"]::-webkit-outer-spin-button,
.filter-year input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}
.filter-year .dash { color: var(--muted); font-size: .9rem; }

.result-count { color: var(--muted); font-size: .85rem; margin: 0; }

/* Table */
.table-wrap {
  overflow-x: auto; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
thead th {
  text-align: left; padding: 12px 14px; background: #f0f1ec;
  border-bottom: 2px solid var(--line); font-weight: 600; white-space: nowrap;
  cursor: pointer; user-select: none; position: sticky; top: 0; z-index: 1;
}
thead th:hover { color: var(--accent); }
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: #fafaf7; }
.sp-name { font-style: italic; font-weight: 600; position: relative; }
.sp-family { color: var(--muted); font-size: .85rem; }

/* Pequeno botão "+" ao lado do nome da spp pra abrir issue pré-preenchida */
.row-suggest {
  display: inline-block; margin-left: 8px;
  color: var(--accent); text-decoration: none;
  font-style: normal; font-weight: 700; font-size: .95em;
  line-height: 1;
  opacity: 0.45; transition: opacity .15s, color .15s, background .15s;
  padding: 1px 6px; border-radius: 4px;
  border: 1px dashed var(--accent-soft);
}
tr:hover .row-suggest { opacity: 0.9; border-color: var(--accent); }
.row-suggest:hover {
  opacity: 1 !important;
  color: #fff; background: var(--accent);
  border-color: var(--accent);
}

.contrib-link {
  display: inline-block; padding: 4px 8px;
  background: var(--accent-soft); color: var(--accent-dark);
  text-decoration: none; font-weight: 600;
  border-radius: 6px; margin: 2px 0;
}
.contrib-link:hover { background: #d3e5d9; color: var(--accent-dark); }

/* Badges */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: .74rem; font-weight: 600; white-space: nowrap;
}
.badge.described { background: var(--ok-bg); color: #256b2c; }
.badge.not_described { background: var(--neutral-bg); color: #5b6068; }

/* Refs cell — clicável pra expandir */
.refs-cell { display: flex; flex-direction: column; gap: 4px; }
.refs-details {
  background: var(--accent-soft); border-radius: 6px;
  padding: 8px 10px; margin-top: 6px; font-size: .8rem;
  color: var(--ink); line-height: 1.45;
  max-width: 460px;
}
.refs-details ol { margin: 0; padding-left: 20px; }
.refs-details li { margin-bottom: 4px; }
.refs-toggle {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--accent); font: inherit; text-decoration: underline;
  font-size: .78rem; text-align: left; align-self: flex-start;
}
.refs-toggle:hover { color: var(--accent-dark); }

/* Dashboard */
.charts {
  display: grid; grid-template-columns: 1fr; gap: 24px;
}
@media (min-width: 820px) {
  .charts { grid-template-columns: 1fr 1fr; }
  .chart-card--wide { grid-column: 1 / -1; }
}
.chart-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px;
}
.chart-card h3 { margin: 0 0 12px; font-size: 1rem; }

/* --- Tendências --- */
.trend-header { margin-bottom: 12px; }
.trend-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.trend-group {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px 12px;
  margin: 0;
}
.trend-group legend {
  font-size: .78rem; color: var(--muted);
  font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  padding: 0 6px;
}
.trend-group label {
  display: block;
  font-size: .9rem;
  padding: 3px 0;
  cursor: pointer;
}
.trend-group input { margin-right: 6px; vertical-align: -2px; }
.trend-families { grid-column: span 2; }
@media (max-width: 600px) {
  .trend-families { grid-column: auto; }
}
.trend-fam-actions {
  display: flex; gap: 12px; margin: 4px 0 8px;
  border-bottom: 1px solid var(--line); padding-bottom: 8px;
}
.trend-fam-actions .btn-link { padding: 2px 0; font-size: .82rem; }
.trend-fam-list {
  max-height: 180px;
  overflow-y: auto;
  columns: 2;
  column-gap: 14px;
  font-size: .85rem;
}
.trend-fam-list label {
  break-inside: avoid;
  padding: 2px 0;
  font-size: .85rem;
}

/* Chart-card que envolve o gráfico de tendências: position:relative +
   overflow:hidden contêm o SVG absoluto do Plotly caso ele escape do
   container (acontecia quando trocávamos nº de traces e o autosize/
   responsive do Plotly entrava em conflito com o min-height do div). */
.chart-card:has(#chart-trend) {
  position: relative;
  overflow: hidden;
}
#chart-trend {
  height: 480px;
  width: 100%;
  display: block;
}

/* --- Colaborações (rede de coautoria) --- */
.coa-header { margin-bottom: 12px; }

.coa-controls {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px;
}
.coa-controls label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: .78rem; color: var(--muted);
}
.coa-controls input[type="search"],
.coa-controls input[type="number"],
.coa-controls select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); font-size: .9rem; color: var(--ink);
}
.coa-controls input[type="search"] { min-width: 220px; }
.coa-controls input[type="number"] { width: 70px; }
.coa-stats { margin-left: auto; }

.coa-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
  align-items: stretch;
}
@media (max-width: 880px) {
  .coa-layout { grid-template-columns: 1fr; }
}

.coa-graph {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow);
  height: 640px;
  position: relative;
}

.coa-side {
  display: flex; flex-direction: column; gap: 12px;
  min-height: 640px;
}
.coa-side-block {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 14px;
}
.coa-side-block h3 {
  margin: 0 0 8px; font-size: .9rem;
  color: var(--accent-dark);
  text-transform: uppercase; letter-spacing: .04em;
}
.coa-top-select {
  width: 100%; padding: 6px 8px; font-size: .82rem;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); margin-bottom: 8px;
}
.coa-top-list {
  margin: 0; padding-left: 22px; font-size: .85rem;
  line-height: 1.5;
}
.coa-top-list li { margin-bottom: 2px; cursor: pointer; }
.coa-top-list li:hover { color: var(--accent); }
.coa-top-list .val {
  color: var(--muted); font-family: var(--mono);
  font-size: .78rem; margin-left: 4px;
}

#coa-detail-body { font-size: .85rem; line-height: 1.5; }
#coa-detail-body .da-name {
  font-weight: 600; color: var(--accent-dark); font-size: .95rem;
}
#coa-detail-body .da-metric {
  display: flex; justify-content: space-between;
  padding: 2px 0; border-bottom: 1px dotted var(--line);
  font-size: .82rem;
}
#coa-detail-body .da-metric span:last-child {
  font-family: var(--mono); color: var(--ink);
}

.coa-foot { margin-top: 10px; }

/* --- Filogenia --- */
.phylo-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 16px; flex-wrap: wrap; margin-bottom: 12px;
}
.phylo-controls { display: flex; gap: 12px; }

.phylo-legend {
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 14px; margin-bottom: 14px; font-size: .82rem;
}
.lg-title { color: var(--muted); font-weight: 600; }
.lg-item { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); }
.lg-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.lg-sep { color: var(--line); margin: 0 4px; }

.phylo-container {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; overflow: auto;
  /* sem min-height: container acompanha a altura do SVG. */
  max-height: 80vh;
}
.phylo-foot { margin-top: 12px; }
.small { font-size: .82rem; }

/* SVG da filogenia */
.phylo-container svg { display: block; }
.phylo-link { fill: none; stroke: #b9c1bf; stroke-width: 1.2px; }

.phylo-internal-circle {
  fill: #fff; stroke: #6b7280; stroke-width: 1.5px;
  cursor: pointer; transition: fill .12s;
}
.phylo-internal-circle:hover { fill: var(--accent-soft); }
.phylo-internal-circle.collapsed { fill: var(--accent); stroke: var(--accent-dark); }

.phylo-mrca-label {
  font-size: 10.5px; font-family: var(--sans);
  fill: var(--ink); font-weight: 600;
  dominant-baseline: middle; pointer-events: none; user-select: none;
}
.phylo-mrca-label.clickable {
  pointer-events: auto; cursor: pointer;
}
.phylo-mrca-label.clickable:hover { fill: var(--accent); text-decoration: underline; }
.phylo-tip-circle { stroke: #fff; stroke-width: 1px; }
.phylo-tip-text {
  font-size: 11px; font-family: var(--sans); fill: var(--ink);
  font-style: italic; dominant-baseline: middle; pointer-events: none;
}
.phylo-tip-text.clickable {
  pointer-events: auto; cursor: pointer;
}
.phylo-tip-text.clickable:hover { fill: var(--accent); text-decoration: underline; }

/* Pulso amarelo no clado/ponta alvo do "Ver na filogenia" */
@keyframes phylo-flash {
  0%   { filter: drop-shadow(0 0 0 transparent); }
  30%  { filter: drop-shadow(0 0 6px var(--warn)); }
  60%  { filter: drop-shadow(0 0 10px var(--warn)); }
  100% { filter: drop-shadow(0 0 0 transparent); }
}
.phylo-highlight { animation: phylo-flash 1.2s ease-in-out 2; }
.phylo-highlight .phylo-mrca-label,
.phylo-highlight .phylo-tip-text { fill: var(--accent-dark); font-weight: 700; }

.phylo-focus-msg {
  margin-top: 8px;
  padding: 8px 12px; border-radius: 6px;
  background: var(--warn-bg); color: var(--ink);
  border-left: 3px solid var(--warn);
  font-size: .85rem;
}
.phylo-bars { pointer-events: none; }
.bar-bg, .bar-fg { stroke: none; }
.phylo-bar-n {
  font-size: 9.5px; fill: var(--muted); dominant-baseline: middle;
  font-family: var(--mono);
}

.phylo-tooltip {
  position: fixed; pointer-events: none; z-index: 10;
  background: var(--ink); color: #fff;
  padding: 8px 10px; border-radius: 6px;
  font-size: .82rem; line-height: 1.4; max-width: 280px;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
  opacity: 0; transition: opacity .15s;
}
.phylo-tooltip.visible { opacity: 1; }
.phylo-tooltip strong { color: #fff; }
.phylo-tooltip .tt-sub { color: #c7cdd2; font-size: .76rem; margin-top: 4px; }
.phylo-tooltip .tt-bars { margin-top: 8px; padding-top: 8px; border-top: 1px solid #3a4148; }
.phylo-tooltip .tt-bar-row {
  display: flex; align-items: center; gap: 6px;
  font-size: .76rem; line-height: 1.6;
}
.phylo-tooltip .tt-swatch {
  display: inline-block; width: 10px; height: 10px; border-radius: 2px;
}

/* Misc */
h2 { font-size: 1.4rem; margin-top: 0; }
.muted { color: var(--muted); }
code { font-family: var(--mono); background: #eceee9; padding: 1px 5px; border-radius: 4px; font-size: .85em; }
.site-footer { border-top: 1px solid var(--line); margin-top: 20px; }
.site-footer p { color: var(--muted); font-size: .82rem; padding: 18px 0; margin: 0; }
#view-sobre p { max-width: 70ch; }

/* Citação na aba Sobre */
.citation-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin: 24px 0;
  max-width: 76ch;
}
.citation-block h3 {
  margin: 0 0 10px;
  font-size: 1.05rem;
  color: var(--accent-dark);
}
.citation-block p { margin: 8px 0; max-width: none; }
.citation-block .cite {
  border-left: 3px solid var(--accent-soft);
  background: var(--accent-soft);
  margin: 12px 0;
  padding: 12px 16px;
  border-radius: 6px;
  font-size: .95rem;
  line-height: 1.55;
}
.citation-block a { color: var(--accent); }
.citation-block a:hover { color: var(--accent-dark); }

.bibtex {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 12px;
  background: #fafaf7;
}
.bibtex summary {
  cursor: pointer;
  font-weight: 600;
  font-size: .9rem;
  padding: 6px 0;
  color: var(--accent-dark);
}
.bibtex summary:hover { color: var(--accent); }
.bibtex pre {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: .82rem;
  line-height: 1.5;
  margin: 8px 0;
}
.bibtex code { background: none; padding: 0; font-size: inherit; }

/* Bloco mantenedor / contribuições / código-fonte */
.about-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin: 24px 0 18px;
  max-width: 76ch;
}
.about-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.about-card h3 {
  margin: 0 0 8px;
  font-size: .95rem;
  color: var(--accent-dark);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.about-card p { margin: 6px 0; font-size: .92rem; max-width: none; }
.about-card a { color: var(--accent); word-break: break-word; }
.about-card a:hover { color: var(--accent-dark); }
.about-card code { font-size: .82rem; background: var(--accent-soft); padding: 1px 5px; border-radius: 3px; }
