/* ===========================
   RokoAI — research pages: articles, charts and the data explorer.
   Loaded after style.css, whose colour and spacing tokens it uses.
   =========================== */

/* ===== RESEARCH: index ===== */
.section-research { padding: 88px 0 104px; background: var(--surface); }
.research-list { list-style: none; display: grid; gap: 20px; max-width: 900px; }
.research-card {
  position: relative;
  padding: 32px 36px 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition), border-color var(--transition);
}
.research-card:hover { box-shadow: var(--shadow-lg); border-color: #d5d9e0; }
.research-card::before {
  content: "";
  position: absolute;
  top: -1px; left: 36px;
  width: 48px; height: 3px;
  background: var(--red);
  border-radius: 0 0 3px 3px;
}
.research-card h2 { font-size: clamp(21px, 2.2vw, 26px); font-weight: 700; letter-spacing: -0.02em; margin-bottom: 12px; }
.research-card h2 a { color: var(--ink); }
.research-card h2 a::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius-lg); }
.research-card h2 a:hover { color: var(--red-dark); }
.research-card p { color: var(--muted); font-size: 16px; line-height: 1.7; }
.research-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; list-style: none; }
.research-tags li {
  font-size: 12px;
  font-weight: 600;
  color: var(--red-dark);
  background: var(--red-tint);
  padding: 4px 10px;
  border-radius: 100px;
}

/* ===== RESEARCH: article ===== */
.article-hero h1 { max-width: 900px; }
.article-crumb {
  display: flex;
  width: fit-content;
  align-items: center;
  gap: 8px;
  color: var(--on-dark-muted);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 28px;
}
.article-crumb::before { content: "←"; }
.article-crumb:hover { color: var(--on-dark); }

.article { padding: 72px 0 104px; background: var(--surface); }
.article-grid {
  display: grid;
  grid-template-columns:
    [full-start] minmax(24px, 1fr)
    [wide-start] minmax(0, 150px)
    [content-start] minmax(0, 760px)
    [content-end] minmax(0, 150px)
    [wide-end] minmax(24px, 1fr)
    [full-end];
}
.article-grid > * { grid-column: content; }
.article-grid > .wide { grid-column: wide; }
.article-grid h2 {
  font-size: clamp(25px, 2.6vw, 32px);
  font-weight: 700;
  letter-spacing: -0.022em;
  margin: 72px 0 18px;
  scroll-margin-top: 92px;
}
.article-grid h3 { font-size: 19px; font-weight: 600; margin: 36px 0 10px; }
.article-grid p, .article-grid li { font-size: 17px; line-height: 1.75; color: var(--text); }
.article-grid p + p { margin-top: 18px; }
.article-grid ul, .article-grid ol { margin: 18px 0; padding-left: 24px; }
.article-grid li + li { margin-top: 10px; }
.article-grid li::marker { color: var(--red); font-weight: 600; }
.article-grid p a, .article-grid li a { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(215,31,43,0.35); }
.article-grid p a:hover, .article-grid li a:hover { text-decoration-color: currentColor; }
.article-grid strong { color: var(--ink); font-weight: 600; }
.article-lead { font-size: 20px !important; line-height: 1.65 !important; color: var(--ink) !important; }

.key-findings {
  margin: 40px 0 8px;
  padding: 28px 32px 30px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.key-findings h2 { font-size: 13px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--red); margin: 0 0 14px; }
.key-findings ol { margin: 0; padding-left: 22px; }
.key-findings li { font-size: 16px; line-height: 1.65; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin: 40px 0 8px;
}
.stat-tile {
  padding: 22px 22px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.stat-value { display: block; font-size: clamp(30px, 3.2vw, 40px); font-weight: 700; line-height: 1.1; letter-spacing: -0.025em; color: var(--ink); }
.stat-value.is-red { color: var(--red); }
.stat-label { display: block; margin-top: 8px; font-size: 14px; line-height: 1.45; color: var(--muted); }

.callout {
  margin: 28px 0;
  padding: 20px 24px;
  border-left: 3px solid var(--red);
  background: var(--red-tint);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.callout p { font-size: 16px; line-height: 1.7; }

.recommendations { list-style: none; padding: 0 !important; counter-reset: rec; display: grid; gap: 14px; margin: 24px 0 !important; }
.recommendations li {
  position: relative;
  counter-increment: rec;
  margin: 0 !important;
  padding: 20px 24px 20px 64px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 16px !important;
}
.recommendations li::before {
  content: counter(rec, decimal-leading-zero);
  position: absolute;
  left: 22px; top: 20px;
  font-size: 13px;
  font-weight: 700;
  color: var(--red);
  font-variant-numeric: tabular-nums;
  line-height: 1.75;
}
.recommendations strong { display: block; margin-bottom: 2px; }

.method-list { display: grid; grid-template-columns: max-content 1fr; gap: 10px 24px; margin: 22px 0; font-size: 15px; line-height: 1.6; }
.method-list dt { font-weight: 600; color: var(--ink); }
.method-list dd { color: var(--muted); }

/* ===== RESEARCH: charts ===== */
.chart-figure { margin: 40px 0 44px; }
.chart-figure figcaption { margin-bottom: 4px; }
.fig-title { display: block; font-size: 17px; font-weight: 600; color: var(--ink); line-height: 1.4; }
.fig-sub { display: block; margin-top: 4px; font-size: 14px; line-height: 1.55; color: var(--muted); }
ul.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 14px 0 4px; padding: 0; font-size: 13px; color: var(--muted); list-style: none; }
ul.chart-legend li, ul.chart-legend li + li { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; line-height: 1.4; color: var(--muted); }
.chart-legend li::marker { content: none; }
.key-swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.key-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.key-ring { width: 10px; height: 10px; border-radius: 50%; border: 2px solid; flex-shrink: 0; }
.key-diamond { width: 8px; height: 8px; transform: rotate(45deg); flex-shrink: 0; margin: 0 1px; }
.key-line { width: 14px; height: 0; border-top: 2px solid; flex-shrink: 0; }
.chart { position: relative; width: 100%; min-height: 40px; margin-top: 6px; }
.chart:focus-visible { outline: 2px solid var(--red); outline-offset: 4px; border-radius: 6px; }
.chart svg { display: block; overflow: visible; font-family: var(--font); }
.chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chart-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px 20px;
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
}
.chart-foot p { font-size: 13px !important; line-height: 1.55 !important; color: var(--muted) !important; margin: 0 !important; flex: 1 1 320px; }
.chart-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-text {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.btn-text:hover { border-color: var(--ink); }
.btn-text:focus-visible, .ex-tab:focus-visible, .ex-select:focus-visible, .ex-pop input:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}
.chart-table-wrap { margin-top: 14px; overflow-x: auto; }
.chart-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.chart-table caption { text-align: left; font-size: 13px; color: var(--muted); padding-bottom: 8px; }
.chart-table th, .chart-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.chart-table th:first-child, .chart-table td:first-child { text-align: left; white-space: normal; }
.chart-table thead th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; border-bottom-color: #cfd4dc; }
.chart-table tbody tr:hover { background: var(--surface-2); }

.chart-tooltip {
  position: fixed;
  z-index: 300;
  top: 0; left: 0;
  min-width: 170px;
  max-width: 300px;
  padding: 10px 12px 9px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  pointer-events: none;
  opacity: 0;
  transition: opacity 90ms ease;
}
.chart-tooltip.is-visible { opacity: 1; }
.tt-title { font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.tt-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.tt-key { width: 12px; height: 0; border-top: 2px solid; flex-shrink: 0; }
.tt-label { color: var(--muted); }
.tt-value { margin-left: auto; padding-left: 12px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.tt-note { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ===== RESEARCH: data explorer ===== */
.section-explorer {
  padding: 96px 0 104px;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 68px;
}
.section-explorer .section-header { margin-bottom: 32px; }
.section-explorer .section-header p { margin-top: 14px; color: var(--muted); font-size: 17px; line-height: 1.7; }
.explorer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 24px 28px 26px;
}
.ex-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ex-filter { position: relative; }
.ex-filter > summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  transition: border-color var(--transition);
}
.ex-filter > summary::-webkit-details-marker { display: none; }
.ex-filter > summary::after {
  content: "";
  width: 6px; height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  margin-left: 2px;
}
.ex-filter > summary strong { color: var(--ink); font-weight: 600; }
.ex-filter > summary:hover, .ex-filter[open] > summary { border-color: var(--ink); }
.ex-pop {
  position: absolute;
  z-index: 60;
  top: calc(100% + 8px);
  left: 0;
  width: min(380px, calc(100vw - 40px));
  max-height: min(460px, 70vh);
  overflow-y: auto;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.ex-pop-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 4px 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.ex-pop-actions button {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 9px;
  cursor: pointer;
}
.ex-pop-actions button:hover { border-color: var(--ink); }
.ex-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 2px;
  padding: 6px 6px 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}
.ex-pop label.ex-opt {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 6px 5px 26px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.35;
  color: var(--text);
  cursor: pointer;
}
.ex-pop label.ex-opt:hover, .ex-group-head:hover { background: var(--surface-2); }
.ex-opt small { margin-left: auto; padding-left: 8px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.ex-type-row { display: flex; align-items: center; }
.ex-pop .ex-type-row label.ex-opt { flex: 1; padding-left: 6px; }
.ex-pop input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--red); flex-shrink: 0; margin: 0; }
.ex-subopts { padding-left: 22px; }
.ex-subopts label.ex-opt { font-size: 13px; color: var(--muted); }
.ex-type-toggle {
  margin-left: auto;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  background: none;
  border: none;
  padding: 2px 4px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ex-reset { margin-left: auto; }
.ex-tabs { display: flex; gap: 2px; margin-top: 20px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.ex-tab {
  flex-shrink: 0;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 10px 14px 11px;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.ex-tab:hover { color: var(--ink); }
.ex-tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--red); }
.ex-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px 16px;
  margin: 18px 0 6px;
}
.ex-summary { font-size: 13px; color: var(--muted); }
.ex-summary strong { color: var(--ink); font-weight: 600; }
.ex-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); }
.ex-select {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.ex-warning {
  margin: 10px 0 4px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  background: #fff7e6;
  border: 1px solid #f3dfb2;
  border-radius: 8px;
}
.ex-empty { padding: 48px 0; text-align: center; color: var(--muted); font-size: 15px; }
.chart.is-dim { opacity: 0.5; transition: opacity 120ms ease; }

@media (max-width: 1024px) {
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
  .section-research { padding: 64px 0 72px; }
  .research-card { padding: 26px 22px 28px; }
  .research-card::before { left: 22px; }
  .article { padding: 48px 0 72px; }
  .article-grid { grid-template-columns: [full-start] 16px [wide-start] 0 [content-start] minmax(0, 1fr) [content-end] 0 [wide-end] 16px [full-end]; }
  .article-grid h2 { margin-top: 56px; }
  .article-grid p, .article-grid li { font-size: 16px; }
  .article-lead { font-size: 18px !important; }
  .key-findings { padding: 22px 20px 24px; }
  .stat-row { gap: 10px; }
  .stat-tile { padding: 16px 16px 14px; }
  .recommendations li { padding: 18px 18px 18px 54px; }
  .recommendations li::before { left: 18px; top: 18px; }
  .method-list { grid-template-columns: 1fr; gap: 2px; }
  .method-list dd { margin-bottom: 12px; }
  .section-explorer { padding: 64px 0 72px; }
  .section-explorer .container { padding: 0 16px; }
  .explorer { padding: 18px 16px 20px; }
  .ex-reset { margin-left: 0; }
  .ex-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ex-filter > summary { display: flex; width: 100%; padding: 8px 10px; font-size: 13px; }
  .ex-filter > summary::after { margin-left: auto; }
  .ex-filter:nth-child(even) .ex-pop { left: auto; right: 0; }
  .ex-filters .btn-text { padding: 8px 10px; }
}
@media (max-width: 480px) {
  .ex-filter { grid-column: 1 / -1; }
  .ex-filter:nth-child(even) .ex-pop { left: 0; right: auto; }
  .ex-filter > summary { white-space: nowrap; }
  .ex-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; border-bottom: none; }
  .ex-tab { margin: 0; padding: 9px 8px; border: 1px solid var(--line); border-radius: 8px; text-align: center; }
  .ex-tab[aria-selected="true"] { border-color: var(--ink); box-shadow: inset 0 -2px 0 var(--red); }
}
