/* =========================================================
   CORDIS Spain Dashboard — base styles
   ========================================================= */

/* ---------------------------------------------------------
   [hidden] must actually hide
   ---------------------------------------------------------
   The attribute is only `display: none` in the browser's default
   stylesheet, so any author rule that sets `display` (such as
   .filter-toggle's inline-flex) beats it. `!important` makes it an
   absolute override that does not depend on stylesheet order. */
[hidden] { display: none !important; }


/* CSS custom properties (theme tokens) */
:root {
  --bg-page:        #f6f7f9;
  --bg-card:        #ffffff;
  --bg-subtle:      #eef0f4;
  --bg-header:      #ffffff;
  --bg-footer:      #1a1f2c;

  --fg-default:     #1a1f2c;        /* near-black, contrast 14:1 on bg-page */
  --fg-muted:       #5a6378;        /* contrast 4.7:1 on bg-page (AA normal) */
  --fg-strong:      #000000;
  --fg-on-dark:     #f3f4f8;
  --fg-on-accent:   #ffffff;

  --accent:         #003399;        /* EU blue */
  --accent-hover:   #002277;
  --accent-light:   #e6ecf7;

  --border:         #d8dde8;
  --border-strong:  #b6c0d0;
  --focus-ring:     #ffbf47;        /* high-contrast focus */

  /* Categorical palette: tested for ~3:1 contrast on white */
  --cat-1: #003399;
  --cat-2: #c8102e;
  --cat-3: #007a33;
  --cat-4: #d97e00;
  --cat-5: #6d4c97;
  --cat-6: #008c95;
  --cat-7: #b30000;
  --cat-8: #4a4a4a;

  /* Extra surfaces and accents. Most var() uses of these have no fallback,
     so they must stay defined here. */
  --bg-elev:        #f0f2f6;        /* elevated surface inside a card */
  --bg-hover:       #f0f0f0;
  --bg-muted:       #f5f5f5;
  --accent-dark:    #003b66;
  --accent-soft:    #eaf3ff;

  /* Semantic pillar palette, read by name in utils/pillar-labels.js. A
     pillar keeps one colour in every view: Trend plots a line per pillar
     over time, so colour by position would change from month to month. No
     red, which reads as an alert; blue/orange/green/purple/grey is
     deuteranopia-tolerant. */
  --pillar-1: #003399;              /* Pillar I   — Excellent Science (accent blue) */
  --pillar-2: #d97e00;              /* Pillar II  — Global Challenges */
  --pillar-3: #007a33;              /* Pillar III — Innovative Europe */
  --pillar-4: #6d4c97;              /* Widening & ERA */
  --pillar-5: #4a4a4a;              /* Euratom */

  /* H2020 pillar palette, separate from HORIZON's --pillar-1..5 so that a
     view showing both programmes (Conjunto) never gives two different
     pillars one colour. Same reasoning as above, no red. Seven entries:
     EU.1-5, EC, Euratom. */
  --pillar-h2020-1: #0a6e94;        /* H2020-EU.1 — Excellent Science */
  --pillar-h2020-2: #b8590a;        /* H2020-EU.2 — Industrial Leadership */
  --pillar-h2020-3: #2f7d3a;        /* H2020-EU.3 — Societal Challenges */
  --pillar-h2020-4: #7a4fa0;        /* H2020-EU.4 — Widening */
  --pillar-h2020-5: #1a8f8f;        /* H2020-EU.5 — SwafS */
  --pillar-h2020-6: #6b6b6b;        /* H2020-EC */
  --pillar-h2020-7: #52525b;        /* H2020-Euratom */

  /* Modo Conjunto: un color por programa (no por pilar), en la serie anual
     continua y en las columnas de las tablas comparativas. Azul/naranja, el
     par deuteranopia-safe del resto del dashboard (HES/PRC en Overview). HE
     reutiliza --accent en vez de duplicarlo. */
  --fp-horizon: var(--accent);      /* #003399 */
  --fp-h2020:   #d97e00;
  /* Set per .combined-kpi-card by JS (style.setProperty()). Declared here
     because the smoke test (css_tokens_defined) requires a :root
     declaration for every var() used in CSS. */
  --fp-card-color: var(--accent);

  /* Semantic policy-priority palette: five fixed, named trackers, so each
     keeps its colour (not assigned by position). */
  --prio-ai:           #6b46c1;
  --prio-biodiversity: #16a34a;
  --prio-cleanair:     #0891b2;
  --prio-climate:      #dc2626;
  --prio-digital:      #2563eb;

  /* Sequential scale for the collaborations choropleth (read by
     pages/collaborations.js): ordered, not categorical, so it reads low to
     high at a glance. */
  --seq-1: #eff3ff;
  --seq-2: #c6dbef;
  --seq-3: #9ecae1;
  --seq-4: #6baed6;
  --seq-5: #3182bd;
  --seq-6: #08519c;
  --map-nodata: #f5f5f5;            /* country present, no participation */
  --map-focus:  #d97e00;            /* Spain / selected country */
  --map-border: #666666;
  --map-focus-border: #7a4d00;   /* darker rim on the focus country */

  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  --radius: 8px;
  --space: 16px;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg-page);
  color: var(--fg-default);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
               Ubuntu, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

/* Visible focus indicator — accessibility */
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

button {
  font: inherit;
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  color: inherit;
}

/* =========================================================
   Header
   ========================================================= */
.site-header {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
}
.site-header__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1400px;
  margin: 0 auto;
}
.site-header__title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--fg-strong);
}
.site-header__subtitle {
  margin: 2px 0 0 0;
  font-size: 13px;
  color: var(--fg-muted);
}
.site-header__brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.site-header__brand-mark {
  width: 6px;
  height: 36px;
  border-radius: 3px;
  /* Bandera de España, proporción real 1:2:1 (roja-amarilla-roja). */
  background: linear-gradient(180deg,
    #AA151B 0%,  #AA151B 25%,
    #F1BF00 25%, #F1BF00 75%,
    #AA151B 75%, #AA151B 100%);
}

.lang-toggle {
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-default);
  background: var(--bg-card);
}
.lang-toggle:hover { background: var(--bg-subtle); }

/* Programme selector (HE | H2020 | Conjunto), unhidden by app.js only when
   isH2020Available(). Same pill style as .lang-toggle, as a button group
   with aria-pressed, since it is a choice among several, not a flip. */
.programme-selector {
  display: flex;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  overflow: hidden;
}
.programme-selector__btn {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-muted);        /* 4.7:1 on --bg-card — AA normal text */
  background: var(--bg-card);
  border: none;
  border-right: 1px solid var(--border-strong);
}
.programme-selector__btn:last-child { border-right: none; }
.programme-selector__btn:hover { background: var(--bg-subtle); }
.programme-selector__btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--fg-on-accent);    /* white on EU blue — well above 4.5:1 */
}
.programme-selector__btn[disabled] {
  cursor: not-allowed;
  opacity: 0.6;
}

/* =========================================================
   Navigation tabs
   ========================================================= */
.tabs {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.tabs__row {
  display: flex;
  gap: 4px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px;
  overflow-x: auto;
}
.tabs__btn {
  padding: 12px 16px;
  font-size: 14px;
  color: var(--fg-muted);
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.tabs__btn:hover { color: var(--fg-default); }
.tabs__btn[aria-current="page"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.tabs__btn[disabled] {
  color: #b6bccb;
  cursor: not-allowed;
}
.tabs__badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--fg-muted);
  background: var(--bg-subtle);
  border-radius: 4px;
  text-transform: uppercase;
}

/* =========================================================
   Main content area
   ========================================================= */
.site-main {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px;
}

/* =========================================================
   Section title
   ========================================================= */
.section-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin: 0 0 12px 0;
}
/* The missions table title ("Comparativa por misión", missions.js) sits
   right under a chart card and needs room above it. .section-title is
   shared by every other title, so it stays as is. */
.missions-table-title {
  margin-top: 20px;
}

/* =========================================================
   Headline cards
   ========================================================= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-card);
}
.kpi__label {
  display: block;
  font-size: 12px;
  color: var(--fg-muted);
  margin-bottom: 6px;
  line-height: 1.3;
}
.kpi__value {
  display: block;
  font-size: 26px;
  font-weight: 700;
  color: var(--fg-strong);
  font-variant-numeric: tabular-nums;
}
.kpi__sub {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--fg-muted);
}
.kpi__sub-note { opacity: 0.8; }
.kpi__sub-sep { margin: 0 6px; opacity: 0.5; }

/* Wider card for currency */
.kpi--wide { grid-column: span 2; }
@media (max-width: 700px) { .kpi--wide { grid-column: span 1; } }

/* =========================================================
   Chart grid + card
   ========================================================= */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 16px;
}
/* minmax(0, 1fr), not 1fr: a bare 1fr track never shrinks below a canvas's
   current pixel width, so after the window narrows (or a phone rotates) the
   charts stay at their old size and overflow — Chart.js only resizes to its
   container, which then never gets smaller. */
@media (max-width: 700px) {
  .chart-grid { grid-template-columns: minmax(0, 1fr); }
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-card);
  min-height: 320px;
}
.chart-card__title {
  margin: 0 0 2px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg-default);
}
.chart-card__desc {
  margin: 0 0 12px 0;
  font-size: 12px;
  color: var(--fg-muted);
}
.chart-card__canvas-wrap {
  position: relative;
  height: 240px;
}
/* The "by type of action" donut draws its labels outside the ring with
   leader lines (doughnutChart({externalLabels:true}) in chart-helpers.js)
   instead of a legend, so it needs more room or labels clip at the card
   edge. */
.chart-card__canvas-wrap--donut-external {
  height: 340px;
}
/* Regional analysis's "Proyectos firmados y financiación por CCAA"
   (barLineChart): 19 CCAA labels, some long, rotated 45°, plus an axis
   title on each side. The default 240px crowds them. */
.chart-card__canvas-wrap--regional-bar-line {
  height: 380px;
}

/* =========================================================
   Placeholder box ("coming soon", see showComingSoon() in ui-errors.js)
   ========================================================= */
.placeholder {
  background: var(--bg-card);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 48px 16px;
  text-align: center;
  color: var(--fg-muted);
}

/* =========================================================
   Footer
   ========================================================= */
.site-footer {
  background: var(--bg-footer);
  color: var(--fg-on-dark);
  padding: 16px 24px;
  font-size: 12px;
  margin-top: 32px;
}
.site-footer__inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
}
.site-footer a { color: #b3c4f0; }
.site-footer__meta { font-size: 11px; color: #9aa3b8; }

/* =========================================================
   Inline error and empty states
   ========================================================= */
.ui-error {
  background: #fdecec;
  color: #7a1a1a;
  border: 1px solid #f0bcbc;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14px;
  margin: 8px 0;
}
.ui-empty {
  background: var(--bg-subtle);
  color: var(--fg-muted);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  font-size: 14px;
}

/* =========================================================
   Status badge in footer for DuckDB readiness
   ========================================================= */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 11px;
}
.status-badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
}
.status-badge--loading { color: #d97e00; }
.status-badge--ready   { color: #19a558; }
.status-badge--failed  { color: #c8102e; }

/* Chart-card metric toggle (e.g., count vs EU contribution) */
.chart-toggle {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  overflow: hidden;
  font-size: 11px;
  margin-bottom: 8px;
}
.chart-toggle__btn {
  padding: 4px 10px;
  background: var(--bg-card);
  color: var(--fg-muted);
  border: none;
  font-weight: 500;
}
.chart-toggle__btn:hover { background: var(--bg-subtle); }
.chart-toggle__btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--fg-on-accent);
}

/* Skip link for keyboard users */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--fg-strong);
  color: #fff;
  padding: 8px 12px;
  z-index: 1000;
}
.skip-link:focus { left: 8px; top: 8px; }

/* =========================================================
   Filter bar (Projects page and similar)
   ========================================================= */
.filters-bar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-card);
}
.filters-bar__row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px 24px;
}
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.filter-group__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 12px;
  background: var(--bg-subtle);
  color: var(--fg-default);
  border: 1px solid var(--border);
  border-radius: 999px;
  user-select: none;
  white-space: nowrap;
}
.filter-chip:hover { background: var(--accent-light); }
.filter-chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--fg-on-accent);
  border-color: var(--accent);
}
.filter-org-search {
  font-family: inherit;
  font-size: 13px;
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-card);
  min-width: 220px;
}
/* Partner-country dropdown, a page-local filter on the Collaborations page.
   Styled like the search input so the bar reads as one set of controls. */
.filter-partner-country {
  font-family: inherit;
  font-size: 13px;
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-card);
  min-width: 180px;
  cursor: pointer;
}

/* Country ranking table on the Collaborations page, 7 columns. Under
   table-layout:fixed they would get 14% each: too wide for the ISO code and
   numbers, too narrow for the country name. */
#collab-country-table th:nth-child(1),
#collab-country-table td:nth-child(1) { width: 22%; }                /* País */
#collab-country-table th:nth-child(2),
#collab-country-table td:nth-child(2) { width: 9%;  text-align: left; } /* Código ISO */
#collab-country-table th:nth-child(3),
#collab-country-table td:nth-child(3) { width: 12%; }                /* Projects */
#collab-country-table th:nth-child(4),
#collab-country-table td:nth-child(4) { width: 14%; }                /* Participations */
#collab-country-table th:nth-child(5),
#collab-country-table td:nth-child(5) { width: 13%; }                /* Organisations */
#collab-country-table th:nth-child(6),
#collab-country-table td:nth-child(6) { width: 13%; }                /* Coordinations */
#collab-country-table th:nth-child(7),
#collab-country-table td:nth-child(7) { width: 17%; }                /* EC contribution */

/* =========================================================
   Filter-aware notice
   Shown above tables whose row metrics follow the global filters
   (Organisations, Topics, Regional, Collaborations) while any filter is
   active. Low-key on purpose: information, not an alert.
   ========================================================= */
.filter-aware-notice {
  margin: 8px 0 12px 0;
  padding: 8px 12px;
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  border-radius: 3px;
  color: var(--fg-muted);
  font-size: 13px;
  line-height: 1.4;
}
.filter-aware-notice[hidden] { display: none; }   /* also covered by the global [hidden] rule */

/* Drawer "lifetime totals" note, at the top of the org-profile drawer while
   filters are active, so the drawer does not seem to contradict the
   filtered row the user clicked. */
.drawer__lifetime-note {
  margin: 0 0 16px 0;
  padding: 8px 12px;
  background: var(--bg-subtle);
  border-left: 3px solid var(--border-strong);
  border-radius: 3px;
  color: var(--fg-muted);
  font-size: 12px;
  font-style: italic;
  line-height: 1.4;
}

/* =========================================================
   Results header (count + clear)
   ========================================================= */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--fg-muted);
}
.results-header__count strong { color: var(--fg-default); font-variant-numeric: tabular-nums; }
.btn-clear {
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--fg-default);
}
.btn-clear:hover { background: var(--bg-subtle); }
.btn-clear[disabled] { opacity: 0.5; cursor: not-allowed; }

/* =========================================================
   Data table
   ========================================================= */
.data-table-outer {
  /* Contenedor de consulta: permite que .data-table-wrap oculte la barra
     horizontal fantasma en escritorio y la reactive solo si es estrecho. */
  container-type: inline-size;
}
.data-table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  /* Con table-layout:fixed, redimensionar una columna nunca desborda (roba
     ancho a las demás), así que overflow-x:auto solo mostraría una barra
     fantasma. La @container de abajo reactiva el scroll cuando el contenedor
     es más estrecho que el min-width de la tabla. */
  overflow-x: hidden;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  /* table-layout:fixed makes per-column widths take effect and stops one long
     cell from widening the layout. */
  table-layout: fixed;
  /* min-width en la tabla, no en celdas. En un contenedor más ancho gana
     width:100%, sin barra; en uno más estrecho la tabla conserva un ancho
     legible y .data-table-wrap pone la barra horizontal. En una celda no
     sirve: con table-layout:fixed se ignora salvo en la primera fila. */
  min-width: 640px;
}

/* Solo por debajo del min-width de .data-table (640px: mantener iguales) hay
   un desbordamiento real que merece scroll. Por encima, la tabla cabe y la
   barra sería la fantasma. */
@container (max-width: 640px) {
  .data-table-wrap, .drawer__scroll-table { overflow-x: auto; }
}
.data-table thead th {
  background: var(--bg-subtle);
  color: var(--fg-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  /* sticky positions the header at scroll AND creates a containing block for the
     absolutely-positioned resize handle inside it. */
  position: sticky;
  top: 0;
}
.data-table thead th[data-sortable] { cursor: pointer; user-select: none; }
.data-table thead th[data-sortable]:hover { background: var(--accent-light); }
.data-table thead th[data-sortable]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.data-table thead th[data-sortable]::after {
  content: " ⇅";
  opacity: 0.4;
  font-size: 10px;
}
.data-table thead th[data-sort="asc"]::after  { content: " ↑"; opacity: 1; color: var(--accent); }
.data-table thead th[data-sort="desc"]::after { content: " ↓"; opacity: 1; color: var(--accent); }

/* Column resize handle — a thin invisible strip at the right edge of each <th>.
   Becomes visible on hover. Generous hit area (8px) but visually narrow (2px). */
.data-table .col-resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
  z-index: 2;
}
.data-table .col-resize-handle::after {
  content: "";
  position: absolute;
  top: 25%;
  right: 3px;
  width: 2px;
  height: 50%;
  background: var(--border);
  opacity: 0;
  transition: opacity 0.15s;
}
.data-table thead th:hover .col-resize-handle::after { opacity: 1; }
.data-table .col-resize-handle:hover::after { background: var(--accent); opacity: 1; }

.data-table tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  /* Cells truncate with an ellipsis; the multi-line title column opts out
     below. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Cells that explicitly hold multi-line content (title column) keep wrap behaviour */
.data-table tbody td.col-title {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--accent-light); }
.data-table tbody tr:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: -3px;
  background: var(--accent-light);
}

/* Totals row — sits in <thead> directly under the column labels, sticky like them */
.data-table thead tr.data-table__totals-row td {
  background: var(--bg-card);
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  font-size: 12px;
  padding: 8px 12px;
  color: var(--fg-default);
  position: sticky;
  top: 36px; /* approximate row height of the header above; keeps it pinned below labels */
  z-index: 1;
}

.data-table .col-acronym  { font-weight: 600; white-space: nowrap; }
/* Sin min-width en la columna de título: prevalecería sobre el ancho
   porcentual de table-layout:fixed y ensancharía la tabla, con barra
   horizontal. El porcentaje ya reserva sitio. */
.data-table .col-numeric  { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .col-badge {
  white-space: nowrap;
  /* Sin puntos suspensivos en la celda: el badge es un inline-block y el
     navegador pintaría los "…" a su lado, como si faltara contenido. Se
     recorta dentro del badge (regla siguiente). */
  text-overflow: clip;
}
.data-table .col-badge .badge {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

/* Title truncation with full text on hover (via title attr) */
.title-clip {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: 360px;
}

/* Status / role badges */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  letter-spacing: 0.02em;
}
.badge--signed     { background: #e3f4e8; color: #155724; }
.badge--closed     { background: var(--bg-subtle); color: var(--fg-muted); }
.badge--terminated { background: #fdecec; color: #7a1a1a; }
.badge--led        { background: #e6ecf7; color: var(--accent); border: 1px solid var(--accent); }
.badge--coord-mono { background: #fff4e0; color: #7a4d00; border: 1px solid #d97e00; }
.badge--partner    { background: var(--bg-subtle); color: var(--fg-muted); }

/* =========================================================
   Pagination
   ========================================================= */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--fg-muted);
}
.pagination__buttons { display: flex; gap: 4px; }
.pagination__btn {
  padding: 4px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--fg-default);
  font-size: 12px;
  min-width: 32px;
}
.pagination__btn:hover  { background: var(--bg-subtle); }
.pagination__btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.pagination__btn[aria-current="page"] {
  background: var(--accent);
  color: var(--fg-on-accent);
  border-color: var(--accent);
}

/* =========================================================
   Right-side drawer (project detail)
   ========================================================= */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 1100;   /* above Leaflet panes (which reach 700) */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.drawer-backdrop[data-open="true"] {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(680px, 92vw);
  background: var(--bg-card);
  box-shadow: -2px 0 12px rgba(15, 23, 42, 0.15);
  z-index: 1101;   /* above the backdrop */
  transform: translateX(100%);
  transition: transform 0.25s ease-out;
  display: flex;
  flex-direction: column;
}
.drawer[data-open="true"] { transform: translateX(0); }

.drawer__header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.drawer__title { margin: 0; font-size: 16px; font-weight: 600; }
.drawer__subtitle { font-size: 12px; color: var(--fg-muted); margin-top: 2px; }
.drawer__head-left { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.drawer__back {
  font-size: 18px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg-default);
  flex-shrink: 0;
  line-height: 1;
}
.drawer__back:hover { background: var(--bg-subtle); }
.drawer__close {
  font-size: 22px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg-default);
  flex-shrink: 0;
  line-height: 1;
}
.drawer__close:hover { background: var(--bg-subtle); }
.drawer__content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.drawer__section + .drawer__section { margin-top: 20px; }
.drawer__section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
  margin: 0 0 8px 0;
}
.drawer__field-grid {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 6px 12px;
  font-size: 13px;
}
.drawer__field-label { color: var(--fg-muted); }
.drawer__objective {
  font-size: 13px;
  line-height: 1.6;
  color: var(--fg-default);
  background: var(--bg-subtle);
  padding: 10px 12px;
  border-radius: 4px;
  white-space: pre-line;
}

/* Compact table inside the drawer (participations list). Opts out of the
   page-level table-layout:fixed and nowrap: its content (project titles
   under acronyms) must wrap, and it is too small to need resizable columns. */
.drawer .data-table { font-size: 12px; table-layout: auto; }
/* La tabla de proyectos del drawer sí usa table-layout:fixed. El opt-out de
   arriba es para las tablas pequeñas (socios); en esta anularía los anchos
   porcentuales y la tabla crecería hasta sacar barra horizontal. */
.drawer .drawer__scroll-table .data-table { table-layout: fixed; }
.drawer .data-table thead th { padding: 6px 8px; font-size: 10px; }
.drawer .data-table tbody td {
  padding: 6px 8px;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}
.drawer .data-table tbody tr { cursor: default; }
.drawer .data-table tbody tr:hover { background: var(--bg-subtle); }
.drawer .data-table--clickable-rows tbody tr { cursor: pointer; }

/* ============================================================
   Pillar breakdown with component drill-down (drawer)
   ============================================================ */
.drawer__pillar-row,
.drawer__component-row {
  display: grid;
  grid-template-columns: 14px 1fr 60px 80px 90px;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
}
.drawer__pillar-row:last-child { border-bottom: none; }

.drawer__pillar-row--expandable {
  cursor: pointer;
  user-select: none;
  border-radius: 3px;
}
.drawer__pillar-row--expandable:hover { background: var(--accent-light); }
.drawer__pillar-row--expandable:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.drawer__pillar-disc {
  color: var(--fg-muted);
  font-size: 10px;
  line-height: 1;
  text-align: center;
}
.drawer__pillar-label { font-weight: 600; }
.drawer__pillar-count {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--fg-default);
}
.drawer__pillar-ec {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--fg-muted);
  font-size: 11px;
}
.drawer__pillar-bar {
  background: var(--bg-subtle);
  border-radius: 3px;
  height: 12px;
  overflow: hidden;
}
.drawer__pillar-bar-fill {
  background: var(--accent);
  height: 100%;
  border-radius: 3px;
}
.drawer__pillar-bar--component .drawer__pillar-bar-fill {
  background: var(--accent-light);
  border: 1px solid var(--accent);
}

.drawer__component-rows {
  margin: 0 0 4px 0;
  padding: 4px 0 4px 18px;
  background: var(--bg-subtle);
  border-radius: 0 0 4px 4px;
}
.drawer__component-row {
  font-size: 11px;
  padding: 4px;
  border-bottom: 1px solid transparent;
}
.drawer__component-row:last-child { border-bottom: none; }
.drawer__component-spacer { /* keeps the grid alignment with the parent pillar row */ }
.drawer__component-label {
  color: var(--fg-default);
  font-weight: 500;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.tag {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  background: var(--bg-subtle);
  color: var(--fg-default);
  border-radius: 4px;
  border: 1px solid var(--border);
}
.tag--policy { background: var(--accent-light); color: var(--accent); border-color: var(--accent); }
.tag--es { background: #fff4e0; color: #7a4d00; border-color: #d97e00; font-weight: 600; }

/* ============================================================
   Regional Analysis page
   ============================================================ */
.regional-map-wrap {
  margin: 16px 0 8px 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-subtle);
}
#regional-map {
  height: 480px;
  width: 100%;
  background: #e6efe6;
}
.regional-footnote {
  font-size: 12px;
  color: var(--fg-muted);
  margin: 8px 12px 12px 12px;
  font-style: italic;
}
/* Muted (CSIC / Unknown) rows in the ranking table */
.data-table tbody tr.row--muted td { color: var(--fg-muted); background: var(--bg-subtle); }
.data-table tbody tr.row--muted:hover td { background: var(--bg-hover); }

/* Leaflet tooltip styling — minimal override so tooltips fit our look */
.leaflet-tooltip {
  font-family: inherit;
  font-size: 12px;
  padding: 6px 10px;
}

/* ============================================================
   Topics & Classifications page
   ============================================================ */

/* Sub-tab navigation */
.subtab-nav {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: 4px 0 16px 0;
  flex-wrap: wrap;
}
.subtab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  font: inherit;
  font-size: 14px;
  color: var(--fg-muted);
  cursor: pointer;
  margin-bottom: -1px;
  border-radius: 4px 4px 0 0;
}
.subtab-btn:hover { background: var(--bg-subtle); color: var(--fg-default); }
.subtab-btn[aria-pressed="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.subtab-content { min-height: 200px; }

/* Los controles de la lista de proyectos acompañan al scroll del drawer,
   para no perder el buscador al bajar por una lista larga. */
.drawer__content .drawer__projects-controls {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-card);
  padding-top: 4px;
}
.subtab-intro {
  color: var(--fg-muted);
  font-size: 13px;
  margin: 0 0 16px 0;
  line-height: 1.5;
}

/* Programme tree */
.tree-node {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  background: var(--bg-card);
}
.tree-node > summary {
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
  outline-offset: -2px;
}
.tree-node > summary::-webkit-details-marker { display: none; }
.tree-node > summary::before {
  content: "▶";
  display: inline-block;
  width: 14px;
  font-size: 9px;
  color: var(--fg-muted);
  transition: transform 0.15s;
  margin-right: 6px;
}
.tree-node[open] > summary::before { transform: rotate(90deg); }
.tree-node--pillar > summary { font-size: 15px; }
.tree-node--component {
  margin: 8px 12px 8px 24px;
  background: var(--bg-subtle);
}
.tree-node--component > summary { font-size: 13px; padding: 8px 12px; }
.tree-summary__line {
  display: inline-flex;
  align-items: baseline;
  justify-content: space-between;
  width: calc(100% - 24px);
  gap: 12px;
}
.tree-summary__stats {
  font-size: 12px;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.tree-children { padding-bottom: 4px; }
.tree-parts {
  list-style: none;
  padding: 0 12px 8px 28px;
  margin: 0;
}
.tree-part {
  display: grid;
  grid-template-columns: 130px 1fr auto;
  gap: 12px;
  align-items: baseline;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.tree-part:hover { background: var(--bg-subtle); }
.tree-part:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tree-part__code { font-family: monospace; font-size: 11px; color: var(--fg-muted); }
.tree-part__label { }
.tree-part__stats { color: var(--fg-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* EuroSciVoc cards */
.scivoc-list { display: flex; flex-direction: column; gap: 10px; }
.scivoc-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 18px;
  text-align: left;
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.scivoc-card:hover { border-color: var(--accent); background: var(--bg-subtle); }
.scivoc-card__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.scivoc-card__head strong { font-size: 15px; text-transform: capitalize; }
.scivoc-card__stats {
  font-size: 12px;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}
.scivoc-card__bar {
  background: var(--bg-subtle);
  border-radius: 3px;
  height: 8px;
  width: 100%;
}
.scivoc-card__bar-fill {
  background: var(--accent);
  height: 100%;
  border-radius: 3px;
  min-width: 2px;
}

/* Clickable KPI cards (Policy priorities) */
.kpi--clickable {
  cursor: pointer;
  border: 1px solid var(--border);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.kpi--clickable:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

/* ============================================================
   Collaborations page
   ============================================================ */
.collab-map-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-subtle);
  margin: 12px 0 8px 0;
}
#collab-map {
  height: 500px;
  width: 100%;
  background: #cfe6f4;
}
.collab-legend {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 11px;
  z-index: 500;     /* above tile layer (200), below Leaflet popup (700) */
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.collab-legend__title {
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 11px;
}
.collab-legend__row {
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.5;
}
.collab-legend__swatch {
  width: 14px;
  height: 12px;
  display: inline-block;
  border: 1px solid #999;
  border-radius: 2px;
  flex-shrink: 0;
}

/* =========================================================
   Monthly Trend page

   Denser than the rest of the dashboard: smaller cards, sparklines
   instead of full charts. The page is for scanning the month-over-month
   gist, not for filtering and exploring.
   ========================================================= */

.trend-intro {
  color: var(--fg-muted);
  margin: 0 0 4px 0;
}

.trend-meta {
  color: var(--fg-muted);
  font-size: 13px;
  font-style: italic;
  margin: 0 0 24px 0;
}

.trend-section {
  margin: 0 0 32px 0;
}
.trend-section .section-subtitle {
  margin: 0 0 12px 0;
  font-size: 15px;
  color: var(--fg-default);
}

/* Synthesis card — NCP note + auto-synthesis */
#trend-synthesis-section #trend-synthesis-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.trend-snapshot-notes {
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  padding: 12px 14px;
}
.trend-snapshot-notes .trend-snapshot-notes-label,
.trend-auto-synthesis .trend-auto-label {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--fg-muted);
  margin-bottom: 6px;
}
.trend-snapshot-notes p,
.trend-auto-synthesis p {
  margin: 0;
  line-height: 1.5;
}

.trend-auto-synthesis {
  background: var(--bg-subtle);
  border-left: 4px solid var(--border-strong);
  border-radius: 4px;
  padding: 12px 14px;
}

/* Smoke-test warning banner (only visible if failures) */
.trend-smoke-warning {
  margin: 0 0 20px 0;
  padding: 10px 14px;
  background: #fff4e5;
  border-left: 4px solid #d97706;
  border-radius: 4px;
  color: #7c3a00;
  font-size: 13px;
}
.trend-smoke-warning[hidden] { display: none; }

/* KPI sparklines grid */
.trend-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.trend-kpi-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.trend-kpi-label {
  font-size: 12px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.trend-kpi-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--fg-default);
}
.trend-kpi-delta {
  font-size: 12px;
  color: var(--fg-muted);
  min-height: 16px;
}
.trend-kpi-spark {
  height: 36px;
  margin-top: 4px;
}

/* Up / down semantic colours (also used in the diff tables) */
.trend-delta-up   { color: #15803d; }
.trend-delta-down { color: #b91c1c; }
.trend-delta-zero { color: var(--fg-muted); }

/* Stacked area chart container */
.trend-chart-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  min-height: 280px;
}

/* Differential tables */
.trend-table-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 0;
  overflow-x: auto;
}

.trend-diff-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.trend-diff-table th,
.trend-diff-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.trend-diff-table th {
  background: var(--bg-subtle);
  font-weight: 600;
  color: var(--fg-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.trend-diff-table tr:last-child td { border-bottom: none; }
.trend-diff-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Empty state inside trend sections */
.trend-section .empty-state {
  margin: 0;
  padding: 16px;
  color: var(--fg-muted);
  font-style: italic;
  text-align: center;
  background: var(--bg-subtle);
  border-radius: 4px;
}

/* =========================================================
   Initial loading overlay
   Shown from the first byte of HTML until the first SQL query resolves
   (see utils/app-loading.js).
   ========================================================= */
.app-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg-page, #f7f8fa);
  padding: 32px;
  text-align: center;
  /* Fade-out: keep in step with the 400 ms timeout in app-loading.js */
  opacity: 1;
  transition: opacity 0.4s ease-out;
}
.app-loading-overlay--fading {
  opacity: 0;
  pointer-events: none;
}

.app-loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border, #d0d4d9);
  border-top-color: var(--accent, #00518a);
  border-radius: 50%;
  animation: app-loading-spin 0.9s linear infinite;
}

@keyframes app-loading-spin {
  to { transform: rotate(360deg); }
}

.app-loading-message {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--fg-default);
}

.app-loading-submessage {
  margin: 0;
  font-size: 13px;
  color: var(--fg-muted, #6b7280);
  max-width: 480px;
  line-height: 1.5;
}

/* Respect reduced-motion preference: stop the spin animation entirely.
   The message itself still indicates that loading is in progress. */
@media (prefers-reduced-motion: reduce) {
  .app-loading-spinner { animation: none; }
}

/* =========================================================
   Theme tree: hierarchical pillar / component / instrument filter
   ========================================================= */
.filter-theme-tree > li {
  /* The base .filter-checkboxes li is a flex row; wrapping lets the nested
     .filter-theme-sublist drop below the pillar row instead of squeezing
     into it. */
  flex-wrap: wrap;
}

.filter-theme-caret {
  background: transparent;
  border: none;
  font-size: 13px;
  cursor: pointer;
  padding: 0 4px;
  margin-left: 2px;
  color: var(--fg-muted, #6b7280);
  border-radius: 3px;
  flex: 0 0 auto;
}
.filter-theme-caret:hover { background: var(--accent-light); }
.filter-theme-caret:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.filter-theme-sublist {
  flex-basis: 100%;                /* wrap to next line below the pillar row */
  list-style: none;
  margin: 4px 0 8px 22px;          /* indent + breathing room */
  padding: 0 0 0 10px;
  border-left: 2px solid var(--border, #d0d4d9);
}
.filter-theme-sublist > li {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88em;
  padding: 2px 0;
}
.filter-theme-sublist > li > label {
  /* Basis 0, not auto. A wrapping flex row breaks the line before it
     shrinks anything, so with basis:auto a long component name would push
     the instrument caret onto its own line. With basis 0 the label takes
     the space left over and wraps its own text. */
  flex: 1 1 0;
  min-width: 0;
  cursor: pointer;
}

/* Level 3: instruments (ERC/MSCA/EIC) nested inside a component row. The
   component <li> is a flex row too, so it needs the same wrap for its
   sublist to drop below it. */
.filter-theme-sublist > li { flex-wrap: wrap; }
.filter-theme-sublist--instruments {
  margin-left: 16px;               /* tighter than level 2 — the panel is narrow */
  font-size: 0.96em;               /* compounds with the parent's 0.88em */
  border-left-style: dotted;       /* distinguishes the third level at a glance */
}

/* =========================================================
   Org detail drawer
   ========================================================= */

/* Entity header — sits at the top of the drawer body, always visible */
.drawer__entity-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border, #d0d4d9);
}
.drawer__entity-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.drawer__entity-summary {
  margin: 0;
  font-size: 13px;
  color: var(--fg-muted, #6b7280);
  font-style: italic;
}
.drawer__entity-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}
/* En línea, un tercio cada uno. La base de 140px es el punto de ruptura:
   con menos de ~440px de panel no caben tres y flex-wrap los apila, sin
   media query. */
.drawer__entity-actions > .drawer__action-btn {
  flex: 1 1 140px;
  justify-content: center;
  text-align: center;
}
.drawer__action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 12px;
  font-family: inherit;
  background: var(--bg-elev);
  border: 1px solid var(--border, #d0d4d9);
  border-radius: 4px;
  cursor: pointer;
  color: var(--fg-default);
  text-decoration: none;
  transition: background 0.15s;
}
.drawer__action-btn:hover {
  background: var(--accent-light, #e6f0f8);
  border-color: var(--accent, #00518a);
}
.drawer__action-btn:focus-visible {
  outline: 2px solid var(--accent, #00518a);
  outline-offset: 1px;
}
.drawer__action-btn--link {
  /* External-link variant — slight visual differentiation */
  font-weight: 500;
}

/* Inline F&T Portal link (↗) next to a topic code, in table rows and in
 * the project drawer's topic lists. Its click stops propagation, so it
 * does not also open the row.
 */
.ft-inline-link {
  display: inline-block;
  padding: 0 4px;
  font-size: 12px;
  line-height: 1;
  text-decoration: none;
  color: var(--fg-muted, #6b7280);
  opacity: 0.65;
  border-radius: 3px;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
}
.ft-inline-link:hover {
  opacity: 1;
  color: var(--accent, #00518a);
  background: var(--accent-light, #e6f0f8);
}
.ft-inline-link:focus-visible {
  opacity: 1;
  outline: 2px solid var(--accent, #00518a);
  outline-offset: 1px;
  color: var(--accent, #00518a);
}

/* Sparkline canvas wrapper sized in JS to 100px height */
.drawer__sparkline-canvas {
  max-width: 100%;
}

/* Policy priorities footprint — one row per priority */
.drawer__policy-row {
  display: grid;
  grid-template-columns: 140px 1fr 140px;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  font-size: 13px;
}
.drawer__policy-label {
  font-weight: 500;
}
.drawer__policy-bar {
  height: 8px;
  background: var(--border, #d0d4d9);
  border-radius: 4px;
  overflow: hidden;
}
.drawer__policy-bar-fill {
  height: 100%;
  background: var(--accent, #00518a);
  border-radius: 4px;
  transition: width 0.3s;
}
.drawer__policy-val {
  font-size: 12px;
  color: var(--fg-muted, #6b7280);
  text-align: right;
  white-space: nowrap;
}

/* Projects-tab controls (search + status filter) */
.drawer__projects-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  align-items: center;   /* selects and the count sit on one line */
}
.drawer__projects-totals {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-default);
  padding: 4px 2px 8px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.drawer__projects-totals span { white-space: nowrap; }
.drawer__projects-search {
  flex: 1 1 200px;
  padding: 6px 10px;
  border: 1px solid var(--border, #d0d4d9);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: var(--bg-page, #fff);
  color: var(--fg-default);
}
.drawer__projects-search:focus-visible {
  outline: 2px solid var(--accent, #00518a);
  outline-offset: -1px;
  border-color: transparent;
}
.drawer__projects-status {
  padding: 6px 10px;
  border: 1px solid var(--border, #d0d4d9);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: var(--bg-page, #fff);
  color: var(--fg-default);
}

/* Collaborators table — tighter than the global data-table */
.drawer__collab-table {
  font-size: 13px;
  width: 100%;
}
.drawer__collab-table th {
  font-size: 12px;
  padding: 6px 8px;
}
.drawer__collab-table td {
  padding: 6px 8px;
}

/* Section header with right-aligned pills (track-record toggle) */
.drawer__section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.drawer__section-header .drawer__section-title { margin: 0; }

.drawer__metric-pills {
  display: inline-flex;
  background: var(--bg-elev);
  border-radius: 16px;
  padding: 2px;
  border: 1px solid var(--border, #d0d4d9);
}
.drawer__metric-pill {
  background: transparent;
  border: none;
  padding: 3px 10px;
  font-size: 11px;
  font-family: inherit;
  color: var(--fg-muted, #6b7280);
  cursor: pointer;
  border-radius: 14px;
  transition: background 0.15s, color 0.15s;
}
.drawer__metric-pill:hover { color: var(--fg-default); }
.drawer__metric-pill[aria-pressed="true"] {
  background: var(--accent, #00518a);
  color: white;
  font-weight: 600;
}
.drawer__metric-pill:focus-visible {
  outline: 2px solid var(--accent, #00518a);
  outline-offset: 1px;
}

/* "Filter dashboard by this entity" — primary action variant */
.drawer__action-btn--primary {
  background: var(--accent, #00518a);
  color: white;
  border-color: var(--accent, #00518a);
}
.drawer__action-btn--primary:hover {
  background: var(--accent-dark);
  color: white;
  border-color: var(--accent-dark);
}


/* ============ Embed button & popover ============ */
.embed-btn-bar { display: flex; justify-content: flex-end; margin: 2px 0 4px; }
.embed-btn {
  font: inherit; font-size: 12px; color: var(--fg-muted);
  background: var(--bg-subtle); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 8px; cursor: pointer;
}
.embed-btn:hover { color: var(--accent); border-color: var(--accent); }
.embed-popover {
  margin: 4px 0 8px; padding: 10px; background: var(--bg-card);
  border: 1px solid var(--border-strong); border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.embed-popover__title { font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.embed-popover__code {
  width: 100%; font-family: monospace; font-size: 11px;
  border: 1px solid var(--border); border-radius: 4px; padding: 6px;
  resize: vertical; background: var(--bg-subtle); color: var(--fg-default);
}
.embed-popover__actions { display: flex; gap: 6px; margin-top: 6px; }
.embed-popover__copy, .embed-popover__close {
  font: inherit; font-size: 12px; padding: 3px 10px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--bg-card); cursor: pointer;
}
.embed-popover__copy { background: var(--accent); color: var(--fg-on-accent); border-color: var(--accent); }


/* ============ Tendencia: selector, síntesis colapsable, filas con historial ============ */

/* Nota bajo el gráfico cuando se agrupan series en «Resto» */
.trend-chart-note { font-size: 12px; color: var(--fg-muted); margin: 4px 0 0; }

.trend-table-title { font-size: 14px; font-weight: 600; margin: 18px 0 8px; color: var(--fg-strong); }

/* --- Síntesis colapsable --- */
.trend-synth { border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-card); margin-bottom: 8px; }
.trend-synth > summary { cursor: pointer; padding: 10px 12px; display: flex;
  align-items: baseline; gap: 10px; list-style: none; }
.trend-synth > summary::-webkit-details-marker { display: none; }
.trend-synth > summary::before { content: "▸"; color: var(--fg-muted); font-size: 12px; }
.trend-synth[open] > summary::before { content: "▾"; }
.trend-synth > summary:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.trend-synth-date { font-size: 12px; color: var(--fg-muted); margin-left: auto; }
.trend-synth-body { padding: 0 12px 12px; }
.trend-synth-body p { margin: 0 0 10px; line-height: 1.5; }
.trend-synth-body p:last-child { margin-bottom: 0; }
.trend-synth--old { background: var(--bg-subtle); }
.trend-synth-history { margin-top: 14px; }
.trend-synth-history-label { font-size: 12px; font-weight: 600; color: var(--fg-muted);
  margin: 0 0 6px; text-transform: uppercase; letter-spacing: .04em; }

/* --- Acumulado en las tarjetas KPI --- */
.trend-kpi-cum { font-size: 11px; color: var(--fg-muted); margin-top: 2px; }

/* --- Tabla de variación con filas desplegables --- */
.trend-diff-row { cursor: pointer; }
.trend-diff-row:hover { background: var(--bg-hover); }
.trend-diff-row:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.trend-disc { display: inline-block; width: 12px; color: var(--fg-muted); font-size: 11px; }
.trend-diff-history > td { background: var(--bg-subtle); padding: 0 12px 10px 26px; }
.trend-history-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.trend-history-table th { text-align: left; font-weight: 600; color: var(--fg-muted);
  padding: 6px 8px; border-bottom: 1px solid var(--border); }
.trend-history-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); }
.trend-history-table tr:last-child td { border-bottom: none; }
.trend-table-hint { font-size: 12px; color: var(--fg-muted); margin: 0 0 8px; }

/* ============================================================
   Regional pivot table (components/pivot-table.js)
   ============================================================ */

.pivot-dims {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.pivot-dim-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-subtle);
  font-size: 12px;
  cursor: grab;
  user-select: none;
}
.pivot-dim-chip:active { cursor: grabbing; }

.pivot-dim-chip__num {
  font-weight: 700;
  color: var(--accent);
  min-width: 12px;
  text-align: center;
}

.pivot-dim-chip__btn {
  border: none;
  background: none;
  padding: 0 2px;
  font-size: 13px;
  line-height: 1;
  color: var(--fg-muted);
  cursor: pointer;
}
.pivot-dim-chip__btn:hover:not(:disabled) { color: var(--fg-default); }
.pivot-dim-chip__btn:disabled { opacity: 0.3; cursor: default; }
.pivot-dim-chip__btn--remove { font-size: 14px; }

.pivot-dim-chip--inactive {
  border-style: dashed;
  background: none;
  color: var(--fg-muted);
  cursor: pointer;
}
.pivot-dim-chip--inactive:hover { color: var(--fg-default); border-color: var(--accent); }

.pivot-table-wrap {
  overflow-x: auto;
}

.pivot-table {
  /* .data-table already sets width:100% + table-layout:fixed; the <colgroup>
     built in pivot-table.js pins the measure columns (592px total) so the
     label column absorbs every remaining pixel. min-width keeps the label
     column usable on narrow viewports — .pivot-table-wrap scrolls instead. */
  min-width: 760px;
}

.pivot-table thead th,
.pivot-table thead th.col-numeric {
  white-space: normal;      /* let measure headers wrap instead of clipping */
  vertical-align: bottom;
}

.pivot-table .pivot-row__label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pivot-row__toggle {
  display: inline-block;
  width: 18px;
  border: none;
  background: none;
  padding: 0;
  font-size: 11px;
  color: var(--fg-muted);
  cursor: pointer;
  text-align: center;
}
.pivot-row__toggle:hover { color: var(--accent); }
.pivot-row__toggle--spacer { cursor: default; }

.pivot-row--totals td {
  font-weight: 700;
  border-bottom: 2px solid var(--border);
}

.pivot-sort-btn {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-weight: inherit;
  color: inherit;
  cursor: pointer;
  text-align: inherit;
}
.pivot-sort-btn:hover { color: var(--accent); }
.pivot-sort-btn--active { color: var(--accent); }

.pivot-show-more {
  border: none;
  background: none;
  padding: 2px 0;
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.pivot-footnote {
  margin-top: 8px;
}

/* ============================================================
   Org drawer thematic bubble chart
   ============================================================ */

.drawer__bubble-wrap {
  position: relative;
  height: 300px;
}

.drawer__bubble-footnote {
  margin-top: 6px;
  font-size: 11px;
  color: var(--fg-muted);
  font-style: italic;
}

/* ============================================================
   Scroll lists inside the drawer (capped only in embeds.css)
   ============================================================ */

/* En el dashboard la tabla no se acota. El tope de 420px de embeds.css
   evita que un bloque insertado rompa una página ajena; en el drawer
   dejaría medio panel vacío y un segundo scroll dentro del suyo. Sin tope,
   el scroll lo lleva .drawer__content. */
.drawer__scroll-table {
  max-height: none;
  overflow-y: visible;
  /* Oculto por defecto, como .data-table-wrap: la barra horizontal es cosa
     de la @container de arriba, cuando el hueco es más estrecho que el
     min-width de la tabla. */
  overflow-x: hidden;
}

/* La cabecera se fija contra el contenedor que scrollea (.drawer__content),
   así sigue visible al recorrer la lista. */
.drawer__scroll-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-subtle);
}

/* ============================================================
   Infinite-scroll tables + inline row detail
   (used by embedded tables; the dashboard pages keep the paginator)
   ============================================================ */

.data-table-wrap--scroll {
  max-height: 460px;
  overflow-y: auto;
}
.data-table-wrap--scroll thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table__sentinel {
  padding: 10px 12px;
  text-align: center;
  font-size: 12px;
  color: var(--fg-muted);
  min-height: 8px;
}

.data-table tbody tr.row--expanded > td { background: var(--accent-light); }

.data-table__detail-row > td {
  background: var(--bg-subtle);
  padding: 12px 16px;
  white-space: normal;
}

/* ============================================================
   Chart PNG export button
   ============================================================ */

.chart-card__actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 12px;
  margin-bottom: 4px;
}

.png-btn {
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: 4px;
  padding: 2px 8px;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
  cursor: pointer;
}
.png-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.png-btn:disabled { opacity: 0.6; cursor: default; }

/* ============================================================
   Organisation typeahead (components/org-typeahead.js)
   ============================================================ */

.org-typeahead {
  position: relative;
  display: inline-block;
}

.org-typeahead__list {
  position: absolute;
  z-index: 20;
  top: 100%;
  left: 0;
  min-width: 100%;
  max-width: 460px;
  max-height: 280px;
  overflow-y: auto;
  margin: 2px 0 0;
  padding: 4px 0;
  list-style: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}

.org-typeahead__item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
}
.org-typeahead__item.is-active { background: var(--accent-light); }

.org-typeahead__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.org-typeahead__short {
  flex: 0 0 auto;
  font-weight: 600;
  color: var(--accent);
}

.org-typeahead__empty {
  padding: 6px 10px;
  font-size: 12px;
  color: var(--fg-muted);
  font-style: italic;
}

.drawer__projects-count {
  align-self: center;
  font-weight: 600;
  font-size: 12px;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ============================================================
   Widget title + accessible chart alternatives
   ============================================================ */

.cw-title {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg-default);
}

/* Visually hidden but present in the accessibility tree. NOT display:none or
   [hidden], which would remove it from the tree and defeat the purpose. */
.a11y-table {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ============================================================
   Call filter (typeahead kind in the filter panel)
   ============================================================ */

.filter-typeahead__selected {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 3px 6px;
  margin-bottom: 4px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--accent-light);
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}

.filter-typeahead__remove {
  flex: 0 0 auto;
  border: none;
  background: none;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
  color: var(--fg-muted);
  cursor: pointer;
}
.filter-typeahead__remove:hover { color: var(--accent); }

/* Hierarchical call/topic search: topics indented under their call. */
.org-typeahead__item--child { padding-left: 22px; }
.org-typeahead__item--child .org-typeahead__name { color: var(--fg-muted); }
.filter-typeahead__selected--child { margin-left: 12px; }

/* Explanatory note under a table's results count. */
.table-note {
  margin: -4px 0 8px;
  font-size: 12px;
  color: var(--fg-muted);
  line-height: 1.45;
}

/* EuroSciVoc tree navigation inside the drawer. */
.scivoc-crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--fg-muted);
}
.scivoc-crumbs__sep { opacity: 0.6; }
.scivoc-crumbs__link {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.scivoc-child-row {
  width: 100%;
  border: none;
  background: none;
  text-align: left;
  font: inherit;
  cursor: pointer;
  align-items: center;
  border-radius: 4px;
}
.scivoc-child-row:hover { background: var(--accent-light); }

/* Acción dentro del drawer (ver los proyectos de una rama SciVoc). Clase
   propia: con .drawer__action-btn, el width:100% apilaría también los tres
   botones de la cabecera de entidad. */
.drawer__branch-btn {
  margin-top: 10px;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--accent-light);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}
.drawer__branch-btn:hover:not(:disabled) { background: var(--accent); color: var(--fg-on-accent); }
.drawer__branch-btn:disabled { opacity: 0.5; cursor: default; }

/* Cabecera de cifras del árbol EuroSciVoc (compartida con el widget). */
.scivoc-tree__stats {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.scivoc-tree__leaf { font-size: 12px; color: var(--fg-muted); font-style: italic; }
/* One-line help text, widget only: added by the "scivoc-tree" mount in
   cordis-widgets.js, not by makeScivocTree(), which the dashboard also
   uses. Sits between the widget title and .scivoc-tree__stats. */
.scivoc-tree__help {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--fg-muted);
}

/* ---------- Comparative blocks ---------- */

.org-rank { display: flex; flex-direction: column; gap: 4px; }
.org-rank__row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; padding: 4px 0; font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.org-rank__row:last-child { border-bottom: none; }
.org-rank__label { color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-rank__value { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.org-rank__value--first { color: var(--accent); }

.org-rate { display: flex; flex-direction: column; gap: 6px; }
.org-rate__row {
  display: grid; grid-template-columns: minmax(0, 130px) 1fr 108px;
  gap: 8px; align-items: center; font-size: 12px;
}
.org-rate__label { color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-rate__row--self .org-rate__label { color: var(--fg-default); font-weight: 600; }
.org-rate__bar { background: var(--bg-subtle); border-radius: 3px; height: 10px; display: block; }
.org-rate__bar-fill { background: var(--border-strong); height: 100%; border-radius: 3px; display: block; min-width: 2px; }
.org-rate__row--self .org-rate__bar-fill { background: var(--accent); }
.org-rate__value { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.org-rate__row--self .org-rate__value { font-weight: 700; }

.org-country-list { display: flex; flex-direction: column; gap: 5px; }
.org-country__row {
  display: grid; grid-template-columns: minmax(0, 150px) 1fr 85px;
  gap: 8px; align-items: center; font-size: 12px;
}
.org-country__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-country__label--code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.org-country__bar { background: var(--bg-subtle); border-radius: 3px; height: 8px; display: block; }
.org-country__bar-fill { background: var(--accent); height: 100%; border-radius: 3px; display: block; }
.org-country__value { text-align: right; font-variant-numeric: tabular-nums; color: var(--fg-muted); }
.org-country__row--self { background: var(--accent-light); border-radius: 4px; padding: 2px 4px; margin: 0 -4px; }
.org-country__row--self .org-country__label { font-weight: 700; color: var(--fg-default); }
.org-country__row--self .org-country__value { font-weight: 700; color: var(--fg-default); }

/* Tabla de proyectos del drawer: debe caber sin barra horizontal en
   ~1000px. Las columnas fijas suman 892px, así que el título tiene solo un
   mínimo modesto y envuelve a dos líneas, mejor que desplazar la tabla. */
.drawer__scroll-table .data-table td,
.drawer__scroll-table .data-table th { padding-left: 8px; padding-right: 8px; }

/* 150px basta para escribir y no empuja los selectores a otra línea. */
.drawer__projects-search { flex: 0 1 150px; min-width: 110px; }

/* El título ocupa todo el ancho de su columna: con table-layout:fixed la
   columna ya tiene el suyo, y el tope de 360px de arriba recortaría antes
   de tiempo. */
.title-clip { max-width: none; }

/* Celda de una línea que se recorta con puntos y revela el texto en el
   tooltip (columna Tema). */
.cell-clip {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

/* Seis controles en una fila. El buscador se encoge hasta 110px y
   los selectores dejan de reservar ancho fijo: en un contenedor de ~900px
   caben recuento + buscador + cuatro selectores sin saltar de línea. */
.drawer__projects-controls { gap: 6px; }
.drawer__projects-search { flex: 1 1 110px; min-width: 90px; max-width: 220px; }
.drawer__projects-status { flex: 0 1 auto; min-width: 0; max-width: 150px; font-size: 12px; padding: 4px 6px; }
.drawer__projects-count { flex: 0 0 auto; }

/* Cabeceras ordenables en las tablas de socios. */
.collab-sort-btn {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-weight: inherit;
  color: inherit;
  text-align: inherit;
  cursor: pointer;
  text-transform: inherit;
  letter-spacing: inherit;
}
.collab-sort-btn:hover { color: var(--accent); }
.collab-sort-btn--active { color: var(--accent); }

/* Cinturón y tirantes contra la barra horizontal: con table-layout:fixed y
   <colgroup> la tabla se ajusta al contenedor; max-width impide que una
   regla heredada la empuje más allá. */
.data-table { max-width: 100%; }

/* Transient global notice (showNotice() in ui-errors.js), e.g. why the user
   was redirected off a page the active programme lacks. Fixed and centred,
   since a redirect can start from any tab. */
.global-notice {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--fg-strong);
  color: var(--fg-on-dark);
  padding: 10px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1000;
  max-width: 90vw;
}
.global-notice--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* =========================================================
   Modo Conjunto (pages/combined.js)
   ========================================================= */
.combined-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.combined-section > h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--fg-strong);
}

/* Per-programme KPI cards, like .kpi but with a left bar in the programme's
   colour (--fp-card-color, set inline per card). With only two cards, the
   coloured edge pairs them better than the H2020/HE label alone. */
.combined-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin: 12px 0;
}
.combined-kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--fp-card-color);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
}
.combined-kpi-card > h4 {
  margin: 0 0 8px 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--fp-card-color);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.combined-kpi-card__line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 3px 0;
  font-size: 13px;
}
.combined-kpi-card__label { color: var(--fg-muted); }
.combined-kpi-card__value {
  font-weight: 600;
  color: var(--fg-strong);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Entity trajectory search — same look as the Organisations name search. */
.combined-trajectory-search,
.combined-orgs-search {
  font-family: inherit;
  font-size: 13px;
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-card);
  min-width: 260px;
}

/* Region and entity-type filters for the yearly series (Section 1). Plain
   <select>s, not the global filter panel: combined.js's buildOnce() says
   why Conjunto has its own light filter. flex-wrap stacks the two
   label+select pairs on narrow screens instead of overflowing. */
.combined-region-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.combined-region-row__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-muted);
}
.combined-region-select,
.combined-activity-select {
  font-family: inherit;
  font-size: 13px;
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-card);
  min-width: 200px;
}
.combined-trajectory-results {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 8px;
  max-width: 480px;
}
.combined-trajectory-result {
  text-align: left;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  font-size: 13px;
}
.combined-trajectory-result:hover { background: var(--bg-subtle); }
#combined-trajectory-detail { margin-top: 16px; }
.combined-trajectory-canvas {
  width: 100%;
  max-height: 220px;
  margin-bottom: 8px;
}

/* Institutions/regions comparison tables — a soft column-group tint (not a
   border, which would fight the data-table's own row borders) marks which
   four columns belong to which programme, since each table interleaves
   H2020 and HE columns. */
.combined-col-h2020 { background: rgba(217, 126, 0, 0.08); }   /* --fp-h2020 #d97e00 @ 8% */
.combined-col-he    { background: rgba(0, 51, 153, 0.08); }    /* --fp-horizon #003399 @ 8% */

/* The by-year chart's year-basis control is a plain checkbox, not a second
   row of .chart-toggle pills: it adjusts the primary choice (projects/EC),
   and two equal pill rows would read as two equal decisions. Hidden in
   H2020, which has no call year (syncYearBasisRow in overview.js). */
.chart-subtoggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 10px;
  font-size: 11px;
  color: var(--fg-muted);
  cursor: pointer;
}
.chart-subtoggle input { margin: 0; }

/* A chart card spanning the full grid row, for the SNS tab's type-of-action
   donut, whose external labels need the width. Inside the grid it keeps
   the rhythm of the cards above. */
.chart-card--full { grid-column: 1 / -1; }
/* Room between the SNS tab's stacked blocks: table, charts, table. */
#page-sns .chart-grid { margin: 20px 0; }

/* SNS chart grid: three columns once #page-sns itself is 1300px wide
   (3×420px columns + 2×16px gaps = 1292px). A container query, because the
   viewport width does not say how wide the content area is. The 5th card
   spans columns 2-3, beside the 4th on the same row; 1 / 3 would push it
   to a row of its own. */
#page-sns {
  container-type: inline-size;
}
@container (min-width: 1300px) {
  #page-sns .chart-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)); /* see .chart-grid */
  }
  #page-sns .chart-grid > :nth-child(5) {
    grid-column: 2 / 4;
  }
}

/* SNS always has exactly six KPI cards: six columns at any width from the
   700px mobile breakpoint up, so they never wrap. The shared .kpi-grid
   stays auto-fill because other pages vary (Overview has up to 9). Below
   700px six columns would be illegible, so auto-fill applies. */
@media (min-width: 700px) {
  #page-sns .kpi-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

/* SNS by-year chart, a bar+line with a secondary % axis (barLineChart): two
   axis titles plus a legend do not fit the default 240px. Shorter than
   --regional-bar-line: it sits in a grid cell and its labels are years. */
.chart-card__canvas-wrap--sns-bar-line { height: 300px; }

/* =========================================================
   "Posición ES" page
   ========================================================= */
/* Notice explaining that the sidebar filters don't apply here (the
   aggregates have no region/entity/role dimension). Deliberately styled as
   an informational panel rather than an error: nothing is broken. */
.page-notice {
  background: var(--bg-subtle);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--fg-muted);
  border-radius: 0 var(--radius) var(--radius) 0;
}
/* Per-call-year completeness chips under the evolution chart. Three states,
   from date arithmetic alone — see position.js's completeness(). */
.completeness-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.completeness-chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  cursor: default;
}
.completeness-chip--complete   { background: var(--bg-card);   color: var(--fg-muted); }
.completeness-chip--inprogress { background: #fff4e0;          color: #8a5a00; border-color: #e8c98a; }
.completeness-chip--starting   { background: #fde8e8;          color: #a12020; border-color: #eeb4b4; }
/* Country picker for the peer comparison. */
.peer-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--fg-muted);
}
.peer-picker__item { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.peer-picker__item input { margin: 0; }
/* Taller than the default 240px: the peer and cluster charts are horizontal
   bars with up to ~20 categories. */
.chart-card__canvas-wrap--position { height: 380px; }

/* HTML tooltip (makeHtmlTooltip in chart-helpers.js): real DOM, not canvas
   pixels, so the figures can be selected and copied. That needs
   pointer-events: auto; the usual `none` makes the text unreachable. */
.chart-html-tooltip {
  position: absolute;
  z-index: 60;
  pointer-events: auto;
  opacity: 0;
  transition: opacity 0.12s;
  background: rgba(26, 31, 44, 0.97);
  color: #fff;
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  user-select: text;
}
.chart-html-tooltip__title { font-weight: 600; margin-bottom: 4px; }
.chart-html-tooltip__row { display: flex; gap: 14px; justify-content: space-between; }
.chart-html-tooltip__value { font-variant-numeric: tabular-nums; }

/* The Overview by-year chart is a bar+line with a secondary % axis: two axis
   titles plus a legend need more than the 240px default. Scoped to that
   card so the other four in the grid keep their height. */
#page-overview .chart-card:has(#chart-by-year) .chart-card__canvas-wrap { height: 300px; }

/* Programme tree levels 3 and 4 (topic-derived, see
   utils/topic-taxonomy.js). Variants are indented under their group. */
.tree-parts--variants {
  list-style: none;
  margin: 0 0 4px 22px;
  padding: 0;
  border-left: 1px solid var(--border);
}
.tree-part--variant { font-size: 12px; color: var(--fg-muted); padding-left: 10px; }
/* "Sin desglose" is a residual, not a programme part: muted, and not
   clickable (there is no code to filter by). */
.tree-part--none { color: var(--fg-muted); font-style: italic; cursor: default; }

/* Back control on the Posición ES theme chart, shown only while
   drilled into a component's destinations. Styled as a quiet text button:
   it is a way back, not an action competing with the chart. */
.position-drill-back {
  align-self: flex-start;
  margin: 0 0 8px 0;
  padding: 2px 8px;
  background: transparent;
  border: 1px solid var(--border, #d0d4d9);
  border-radius: 4px;
  font: inherit;
  font-size: 0.85em;
  color: var(--fg-muted, #6b7280);
  cursor: pointer;
}
.position-drill-back:hover { background: var(--bg-muted, #eef0f4); color: var(--fg-default); }
.position-drill-back:focus-visible { outline: 2px solid var(--accent, #1f6feb); outline-offset: 2px; }

/* -----------------------------------------------------------
 * Guided tour (components/tour.js) — dashboard only, not in embeds.css:
 * the tour never runs inside a widget.
 * --------------------------------------------------------- */
.tour-help {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  background: var(--bg-card);
  cursor: pointer;
}
.tour-help:hover { background: var(--accent-light); }
.tour-help:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

.tour { position: fixed; inset: 0; z-index: 2000; pointer-events: none; }
.tour__spot {
  position: fixed;
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(12, 18, 34, 0.58), 0 0 0 3px var(--focus-ring);
  transition: left .25s ease, top .25s ease, width .25s ease, height .25s ease;
}
.tour__spot--none { left: 50% !important; top: 50% !important; width: 0 !important; height: 0 !important; box-shadow: 0 0 0 9999px rgba(12, 18, 34, 0.58); }
.tour__card {
  position: fixed;
  width: min(380px, calc(100vw - 24px));
  padding: 18px 20px 16px;
  background: var(--bg-card);
  color: var(--fg-default);
  border-radius: 12px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
  transition: left .25s ease, top .25s ease;
}
.tour__count { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.tour__title { margin: 6px 0 8px; font-size: 18px; line-height: 1.25; color: var(--fg-strong); }
.tour__body  { margin: 0; font-size: 14px; line-height: 1.5; color: var(--fg-default); white-space: pre-line; }
.tour__actions { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.tour__spacer { flex: 1; }
.tour__btn {
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-default);
  background: var(--bg-card);
  cursor: pointer;
}
.tour__btn:hover { background: var(--bg-subtle); }
.tour__btn--primary { background: var(--accent); border-color: var(--accent); color: var(--fg-on-accent); }
.tour__btn--primary:hover { background: var(--accent-hover); }
.tour__btn--ghost { border-color: transparent; color: var(--fg-muted); padding-left: 4px; padding-right: 4px; }
.tour__btn:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .tour__spot, .tour__card { transition: none; } }
