/* =====================================================================
   RESEARCH NETWORK — page-specific styles
   Preserves Version 1's .rn layout, typography, tabs, summary, map stage,
   and clean side-panel structure, while adding Version 2's search/filter/sort
   controls and researcher card layout.
   ===================================================================== */

.rn {
  --rn-rule:         color-mix(in srgb, var(--ink) 18%, transparent);
  --rn-soft:         color-mix(in srgb, var(--ink) 66%, transparent);
  --rn-land:         color-mix(in srgb, var(--ink) 9%, transparent);
  --rn-border:       color-mix(in srgb, var(--ink) 30%, transparent);
  --rn-surface:      color-mix(in srgb, var(--ink) 4%, transparent);
  --rn-surface-elev: color-mix(in srgb, var(--ink) 7%, transparent);
  --rn-hit:          color-mix(in srgb, var(--accent) 48%, transparent);
  --rn-hit-hover:    color-mix(in srgb, var(--accent-bright) 68%, transparent);
  --rn-hit-select:   color-mix(in srgb, var(--accent-bright) 88%, transparent);
  --rn-empty-select: color-mix(in srgb, var(--ink) 20%, transparent);
}

/* The hidden attribute must win over the display rules below. */
.rn [hidden] { display: none !important; }

/* ---------------------------------------------------------------------
   Intro & Status (Version 1)
   --------------------------------------------------------------------- */
.rn-intro {
  margin-bottom: 20px;
  text-align: justify;
  font-size: 0.95em;
}

.rn-status {
  margin: 0 0 20px;
  color: var(--rn-soft);
  font-style: italic;
}
.rn-status.is-error {
  font-style: normal;
  color: var(--ink);
  padding: 12px 16px;
  border: 1px solid var(--rn-border);
  border-left-width: 4px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------------
   Relationship selector tabs (Version 1)
   --------------------------------------------------------------------- */
.rn-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 0 0 22px;
}
.rn-tab {
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rn-border);
  border-radius: 6px;
  padding: 15px 20px 18px;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}
.rn-tab-title {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 500;
  font-size: 1.35rem;
  line-height: 1.2;
}
.rn-tab-desc {
  font-size: 0.9rem;
  line-height: 1.35;
  color: var(--rn-soft);
}
.rn-tab:not(:disabled):hover {
  border-color: var(--accent-bright);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.rn-tab[aria-pressed="true"] {
  border-color: var(--ink);
  background: color-mix(in srgb, var(--accent) 17%, transparent);
  box-shadow: 0 0 0 1px var(--ink), inset 0 -5px 0 var(--accent-bright);
}
.rn-tab[aria-pressed="true"] .rn-tab-title { font-weight: 600; }
.rn-tab[aria-pressed="true"] .rn-tab-title::before {
  content: '';
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  margin-right: 0.5em;
  border-radius: 50%;
  background: var(--ink);
  vertical-align: 0.08em;
}
.rn-tab[aria-pressed="true"] .rn-tab-desc { color: var(--ink); }
.rn-tab:disabled { opacity: .55; cursor: not-allowed; }

.rn-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 0 6px;
  border: 1px solid var(--rn-border);
  border-radius: 3px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  font-weight: 400;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--rn-soft);
  vertical-align: 0.1em;
}
.rn-demo {
  margin: -6px 0 18px;
  padding: 2px 0 2px 12px;
  border-left: 3px dashed var(--rn-border);
  font-size: 0.85rem;
  font-style: italic;
  color: var(--rn-soft);
}
.rn-demo .rn-tag { margin: 0 4px 0 0; font-style: normal; }

/* ---------------------------------------------------------------------
   Summary bar (Version 1)
   --------------------------------------------------------------------- */
.rn-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 34px;
  list-style: none;
  margin: 0 0 18px;
  padding: 0 0 14px;
  border-bottom: 1px solid var(--rn-rule);
}
.rn-summary li {
  margin: 0;
  padding: 0;
  font-size: 0.95em;
  color: var(--rn-soft);
}
.rn-summary strong {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 500;
  font-size: 1.55rem;
  line-height: 1;
  margin-right: 6px;
  color: var(--ink);
}

/* ---------------------------------------------------------------------
   Toolbar & Buttons (Version 1 + View Switcher)
   --------------------------------------------------------------------- */
.rn-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 10px;
  min-height: 34px;
}
.rn-bar-left, .rn-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.rn-view-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}

.rn-btn, .rn-chip {
  font: inherit;
  font-size: 0.86rem;
  line-height: 1.2;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rn-border);
  border-radius: 4px;
  padding: 6px 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: border-color .15s ease, background-color .15s ease, color .15s ease;
}
.rn-btn:hover, .rn-chip:hover {
  border-color: var(--accent-bright);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.rn-btn[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  border-color: var(--ink);
  font-weight: 600;
}

.rn-btn:focus-visible,
.rn-chip:focus-visible,
.rn-tab:focus-visible,
.rn-panel:focus-visible,
.rn-clear-btn:focus-visible,
.rn-callout-btn:focus-visible,
.rn-search-input:focus-visible,
.rn-search-clear:focus-visible,
.rn-scope-btn:focus-visible,
.rn-sort-select:focus-visible,
.rn-pub-summary:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

.rn-zoom { display: inline-flex; gap: 4px; }
.rn-zoom .rn-btn {
  width: 34px;
  padding: 6px 0;
  justify-content: center;
}

.rn-note {
  margin: 0 0 12px;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--rn-soft);
}

/* ---------------------------------------------------------------------
   Stage: Map column + Detail panel (Version 1)
   --------------------------------------------------------------------- */
.rn-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 390px);
  gap: 28px;
  align-items: start;
  margin-bottom: 30px;
}
.rn-mapcol { min-width: 0; }

.rn-frame { position: relative; }
.rn-world svg, .rn-brazil svg, .rn-usa svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: hidden;
}
.rn-brazil svg, .rn-usa svg {
  max-height: min(74vh, 680px);
  margin: 0 auto;
}

.rn-frame-msg {
  margin: 0;
  padding: 40px 16px;
  text-align: center;
  color: var(--rn-soft);
  font-style: italic;
  border: 1px dashed var(--rn-border);
  border-radius: 4px;
}

/* Map shapes (Version 1) */
.rn-land {
  fill: var(--rn-land);
  stroke: var(--rn-border);
  stroke-width: 0.7px;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.rn-land.rn-has { fill: var(--rn-hit); cursor: pointer; }
.rn-land.rn-has:hover { fill: var(--rn-hit-hover); }
.rn-land:focus { outline: none; }
.rn-land.rn-has:focus-visible {
  fill: var(--rn-hit-hover);
  stroke: var(--ink);
  stroke-width: 2.4px;
}
.rn-outline {
  fill: var(--rn-hit-select);
  stroke: var(--ink);
  stroke-width: 2.4px;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.rn-outline.is-empty {
  fill: var(--rn-empty-select);
  stroke-dasharray: 5 3;
}

/* Tooltip (Version 1) */
.rn-tip {
  position: absolute;
  z-index: 5;
  left: 0;
  top: 0;
  max-width: 250px;
  padding: 7px 11px;
  font-size: 0.88rem;
  line-height: 1.35;
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--rn-border);
  border-radius: 4px;
  box-shadow: 0 2px 10px color-mix(in srgb, var(--ink) 16%, transparent);
  pointer-events: none;
}
.rn-tip strong {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 500;
  display: block;
  font-size: 1rem;
}
.rn-tip em {
  display: block;
  color: var(--rn-soft);
  font-size: 0.82rem;
}

/* Legend (Version 1) */
.rn-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  font-size: 0.85rem;
  color: var(--rn-soft);
}
.rn-legend li {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.rn-swatch {
  width: 22px;
  height: 13px;
  border-radius: 2px;
  border: 0.7px solid var(--rn-border);
  background: var(--rn-land);
}
.rn-swatch.is-has { background: var(--rn-hit); }
.rn-swatch.is-selected { background: var(--rn-hit-select); border: 2.4px solid var(--ink); }

/* Chip list below map (Version 1) */
.rn-chips-label {
  margin: 16px 0 8px;
  font-size: 0.85rem;
  color: var(--rn-soft);
}
.rn-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.rn-chip .rn-n {
  margin-left: 2px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  color: var(--rn-soft);
}
.rn-chip[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  border: 2px solid var(--ink);
  padding: 5px 10px;
  font-weight: 600;
}
.rn-chips + .rn-note { margin-top: 14px; }

/* ---------------------------------------------------------------------
   Detail Panel Container (Version 1 layout + Version 2 controls/cards)
   --------------------------------------------------------------------- */
.rn-panel {
  border-left: 1px solid var(--rn-rule);
  padding: 2px 4px 2px 24px;
  max-height: min(82vh, 760px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.rn-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.rn-panel-eyebrow {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-bright);
  margin-bottom: 2px;
}

.rn-ptitle {
  margin: 0 0 2px;
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 500;
  font-size: 1.35rem;
  line-height: 1.25;
  color: var(--ink);
}

.rn-clear-btn {
  appearance: none;
  border: 1px solid var(--rn-border);
  background: transparent;
  color: var(--rn-soft);
  border-radius: 4px;
  padding: 3px 8px;
  font-family: inherit;
  font-size: 0.76rem;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.rn-clear-btn:hover {
  color: var(--accent-bright);
  border-color: var(--accent-bright);
}

.rn-pmeta {
  margin: 4px 0 10px;
  color: var(--rn-soft);
  font-size: 0.86rem;
  line-height: 1.4;
}

/* State Drill-Down Callout Banner in Panel (Brazil & US) */
.rn-state-callout {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  margin-bottom: 10px;
  border-radius: 5px;
  border: 1px solid color-mix(in srgb, var(--accent-bright) 42%, var(--rn-border));
  background: color-mix(in srgb, var(--accent-bright) 10%, transparent);
  font-size: 0.81rem;
}

.rn-callout-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--accent-bright);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.81rem;
  cursor: pointer;
  white-space: nowrap;
  padding: 2px 4px;
}
.rn-callout-btn:hover { text-decoration: underline; }

/* ---------------------------------------------------------------------
   Panel Search, Scope & Sort Controls (Version 2)
   --------------------------------------------------------------------- */
.rn-panel-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 11px;
  border-bottom: 1px solid var(--rn-rule);
  flex-shrink: 0;
}

.rn-search-wrap {
  position: relative;
  width: 100%;
}

.rn-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.78rem;
  color: var(--rn-soft);
  pointer-events: none;
}

.rn-search-input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 28px 6px 30px;
  border-radius: 4px;
  border: 1px solid var(--rn-border);
  background: color-mix(in srgb, var(--paper, transparent) 55%, var(--rn-surface-elev));
  color: var(--ink);
  font-family: inherit;
  font-size: 0.84rem;
  transition: border-color 0.15s ease;
}
.rn-search-input:focus { border-color: var(--accent-bright); }
.rn-search-input::placeholder { color: var(--rn-soft); opacity: 0.8; }
.rn-search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.rn-search-clear {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  appearance: none;
  border: none;
  background: transparent;
  color: var(--rn-soft);
  width: 22px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
}
.rn-search-clear:hover {
  color: var(--accent-bright);
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}

.rn-filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.rn-scope-switch {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--rn-border);
  border-radius: 4px;
  overflow: hidden;
  background: color-mix(in srgb, var(--ink) 3%, transparent);
}

.rn-scope-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--rn-soft);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  padding: 5px 9px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.rn-scope-btn + .rn-scope-btn { border-left: 1px solid var(--rn-border); }
.rn-scope-btn:hover {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent-bright) 10%, transparent);
}
.rn-scope-btn.active,
.rn-scope-btn[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent-bright) 20%, transparent);
  color: var(--accent-bright);
  font-weight: 500;
}

.rn-sort-wrap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.rn-sort-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  color: var(--rn-soft);
}
.rn-sort-select {
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--rn-border);
  background: color-mix(in srgb, var(--paper, transparent) 55%, var(--rn-surface-elev));
  color: var(--ink);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.73rem;
  cursor: pointer;
}

/* ---------------------------------------------------------------------
   Author / Researcher Card Layout (Version 2)
   --------------------------------------------------------------------- */
.researcher-list {
  list-style: none;
  padding: 0 4px 0 0;
  margin: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  flex: 1;
}

.researcher-card {
  padding: 0.85rem 0.95rem;
  border-radius: 6px;
  background: color-mix(
    in srgb,
    var(--paper, var(--rn-surface)) 40%,
    var(--paper-raised, var(--rn-surface-elev))
  );
  border: 1px solid var(--border, var(--rn-rule));
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.researcher-card:hover {
  border-color: var(--accent-bright);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent-bright) 15%, transparent);
}

.researcher-name {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.06rem;
  font-weight: 500;
  color: var(--accent-bright) !important;
  margin: 0 0 0.4rem 0;
  line-height: 1.3;
  text-shadow: 0 0 8px color-mix(in srgb, var(--accent-bright) 30%, transparent);
}

.researcher-affiliations-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.researcher-affiliation-block {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
}

.researcher-affiliation {
  font-size: 0.89rem;
  color: var(--ink);
  margin: 0;
  line-height: 1.4;
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
}
.researcher-affiliation i {
  color: var(--accent, var(--accent-bright));
  margin-top: 0.24rem;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.researcher-location {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.77rem;
  color: var(--ink-faint, var(--rn-soft));
}
.researcher-location i {
  color: var(--accent2, var(--accent-bright));
  font-size: 0.75rem;
  flex-shrink: 0;
}

/* Metrics Badge & Publication Disclosure inside Researcher Card */
.researcher-metrics-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin-top: 0.55rem;
}

.rn-cite-count-badge {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent-bright) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent-bright) 42%, var(--rn-border));
  color: var(--accent-bright);
  white-space: nowrap;
}

.rn-demo-mini-tag {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 1px 6px;
  border-radius: 3px;
  border: 1px solid var(--rn-border);
  color: var(--rn-soft);
}

.rn-pub-disclosure {
  margin-top: 0.55rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--rn-rule);
}

.rn-pub-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.73rem;
  color: var(--rn-soft);
  user-select: none;
  transition: color 0.15s ease;
}
.rn-pub-summary::-webkit-details-marker { display: none; }
.rn-pub-summary:hover { color: var(--accent-bright); }

.rn-pub-summary-chevron {
  font-size: 0.68rem;
  transition: transform 0.18s ease;
}
.rn-pub-disclosure[open] .rn-pub-summary-chevron {
  transform: rotate(180deg);
}
.rn-pub-disclosure[open] .rn-pub-summary {
  color: var(--accent-bright);
  margin-bottom: 0.55rem;
}

.rn-pub-details-body {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.rn-pub-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rn-pub-group-cited {
  padding: 6px 9px;
  border-radius: 4px;
  border-left: 2px solid var(--accent-bright);
  background: color-mix(in srgb, var(--ink) 4%, transparent);
}

.rn-pub-section-label {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--rn-soft);
}

.rn-compact-pub-list {
  margin: 0;
  padding-left: 15px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  line-height: 1.38;
  color: var(--ink);
}

.rn-compact-pub-title { font-style: italic; }

.rn-compact-pub-meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.71rem;
  color: var(--rn-soft);
}

.rn-pub-doi-link {
  color: var(--accent-bright);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.rn-empty-state {
  list-style: none;
  padding: 18px 12px;
  text-align: center;
  font-size: 0.86rem;
  color: var(--rn-soft);
  border: 1px dashed var(--rn-border);
  border-radius: 5px;
}

.rn-pextra {
  margin: 10px 0 0;
  font-size: 0.82rem;
  font-style: italic;
  color: var(--rn-soft);
  flex-shrink: 0;
}

.rn-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------------
   Responsive (Version 1 + Version 2 controls)
   --------------------------------------------------------------------- */
@media (max-width: 959px) {
  .rn-stage {
    grid-template-columns: minmax(0, 1fr);
    gap: 22px;
  }
  .rn-panel {
    border-left: 0;
    border-top: 1px solid var(--rn-rule);
    padding: 18px 0 0;
    max-height: 620px;
  }
}
@media (max-width: 520px) {
  .rn-tabs { gap: 8px; }
  .rn-tab { padding: 11px 12px 14px; }
  .rn-tab-title { font-size: 1.05rem; }
  .rn-tab-desc { font-size: 0.78rem; }
  .rn-summary { gap: 8px 22px; }
  .rn-summary strong { font-size: 1.35rem; }
  .rn-intro { text-align: left; }
  .rn-state-callout, .rn-filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .rn-scope-switch { width: 100%; }
  .rn-scope-btn { flex: 1; text-align: center; }
  .rn-sort-wrap { justify-content: space-between; }
}
@media (prefers-reduced-motion: reduce) {
  .rn * { transition: none !important; }
}