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

/* ---------------------------------------------------------
   [hidden] must actually hide — V1.8.7
   ---------------------------------------------------------
   The `hidden` attribute is only `display: none` in the BROWSER's default
   stylesheet, so ANY author rule that sets `display` on the same element
   beats it. `.filter-toggle { display: inline-flex }` did exactly that: the
   header's Filtros button stayed on screen on Posición ES, Tendencia and
   Conjunto — the three pages whose data ignores the filters — even though
   app.js had set `hidden = true` on it. Clicking it opened a panel whose
   settings do nothing, which is the confusion hiding it was meant to end.
   This file already carried two one-off patches for the same trap
   (.filter-aware-notice[hidden], .trend-smoke-warning[hidden]) and
   filters.css a third (.filter-chips-bar[hidden]) — the chips bar was
   covered, the button standing right next to it was not.
   One rule, declared once, so the attribute means what it says. `!important`
   is deliberate and is the standard remedy: `hidden` is meant to be an
   absolute override, and this way it does not depend on stylesheet order.
   The three older per-element rules are now redundant; left in place rather
   than removed, since they are harmless and not what this change is about. */
[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;

  /* Surfaces that existed only as inline fallbacks until V1.4.1. Three
     declarations (.trend-kpi-card, .trend-chart-wrap, .trend-table-wrap)
     used var(--bg-elev) with NO fallback and therefore applied no
     background at all; defining the token here is what the CSS always
     intended. */
  --bg-elev:        #f0f2f6;        /* elevated surface inside a card */
  --bg-hover:       #f0f0f0;
  --bg-muted:       #f5f5f5;
  --accent-dark:    #003b66;
  --accent-soft:    #eaf3ff;

  /* SEMANTIC pillar palette (V1.4.1). A pillar must keep ONE colour across
     every view: the Trend tab plots a line per pillar over time, so a
     position-based colour would make a line change colour month to month.
     Until V1.4.1 the Overview pillar chart took colours by array position
     (from a query with no ORDER BY) while Trend used its own hardcoded set,
     so Pillar I was red here and blue there. Red is deliberately absent —
     it reads as an alert. Blue/orange/green/purple/grey is a
     deuteranopia-tolerant set. */
  --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 */

  /* SEMANTIC H2020 pillar palette (V1.5.0) — kept SEPARATE from
     --pillar-1..5 (HORIZON's) rather than reused, so a future view that
     shows both universes together (Fase 5 Conjunto) never has to worry
     about two differently-meaning pillars sharing one colour. Same
     deuteranopia-tolerant reasoning as above; red avoided again. 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 */

  /* V1.5.0 Fase 5 — Modo Conjunto: un color por programa (no por pilar),
     usado en la serie anual continua y en las columnas de las tablas
     comparativas. Azul/naranja, el mismo par deuteranopia-safe que el
     resto del dashboard ya usa (HES/PRC en Overview). HE reutiliza
     --accent (marca) en vez de duplicarlo. */
  --fp-horizon: var(--accent);      /* #003399 */
  --fp-h2020:   #d97e00;
  /* Fallback for .combined-kpi-card before JS sets it per-card via
     style.setProperty() — the smoke test's css_tokens_defined check
     requires every var() used in CSS to have a :root declaration, even
     one that's always overridden inline before the card is visible. */
  --fp-card-color: var(--accent);

  /* SEMANTIC policy-priority palette (V1.4.1). Same reasoning: five fixed
     named trackers, not a sortable list. Values carried over unchanged from
     the literals previously inlined in pages/topics.js. */
  --prio-ai:           #6b46c1;
  --prio-biodiversity: #16a34a;
  --prio-cleanair:     #0891b2;
  --prio-climate:      #dc2626;
  --prio-digital:      #2563eb;

  /* SEQUENTIAL scale for the collaborations choropleth (V1.4.1) — ordered,
     NOT categorical: must read as low→high at a glance. Values carried over
     unchanged from pages/collaborations.js. */
  --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) —
     restaurado (se había perdido en algún punto anterior a este ciclo; no
     formaba parte de ningún cambio H2020). */
  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); }

/* V1.5.0 — HE | H2020 segmented control. Visible only when
   isH2020Available() unhides it (app.js). Same pill family as
   .lang-toggle, split into a button group with a pressed (aria-pressed)
   state rather than a single toggle, since it's a 2-way (soon 3-way,
   Fase 5) choice rather than a binary 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;
}
/* V1.6.1 (M's request) — this one title specifically sits flush against
   the bottom of the chart card right above it (missions.js's tblTitle,
   "Comparativa por misión") with no breathing room; .section-title itself
   stays untouched since it's shared with every other title on this page
   (and elsewhere), which M didn't ask to change. */
.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);
}

/* 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;
}
@media (max-width: 700px) {
  .chart-grid { grid-template-columns: 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;
}
/* V1.6.1 — the "by type of action" donut draws its category labels
   OUTSIDE the ring with leader lines (chart-helpers.js's
   doughnutChart({externalLabels:true})) instead of a legend — needs more
   room on every side than a normal donut+legend layout, or labels get
   clipped at the card edge. */
.chart-card__canvas-wrap--donut-external {
  height: 340px;
}
/* V1.6.1 (M's request) — Regional analysis's "Proyectos firmados y
   financiación por CCAA" (chart-helpers.js's barLineChart): 19 category
   labels (CCAA names, some long — "Comunidad Foral de Navarra") rotated
   45°, plus two axis titles (one per side) — the default 240px crowds
   both. */
.chart-card__canvas-wrap--regional-bar-line {
  height: 380px;
}

/* =========================================================
   Placeholder pages (not yet implemented)
   ========================================================= */
.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 on the Collaborations page (V1.2 Phase 5 page-local
   filter). Matches the search-input look so the controls in a single filter
   bar feel like one cohesive set. */
.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 (V1.2 Phase 5 update:
   split country into "País" full name + "Código ISO" columns, so 7 cols
   total). With table-layout:fixed, 7 cols would default to 14% each — too
   wide for the ISO/numeric cols and too narrow for the country name. The
   per-column widths below tune the visual rhythm: name gets ~22%, ISO ~9%,
   numerics share the rest. */
#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 (V1.2 r6)
   Shown above tables whose row metrics are filter-aware
   (Organisations, Topics, Regional, Collaborations) when any global filter
   is active. Hidden via the `hidden` HTML attribute otherwise. Visual is
   intentionally low-key — info, not alert — so it doesn't compete with
   the data below.
   ========================================================= */
.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; }   /* defensive — some browsers ignore the attr on flex/grid items */

/* Drawer "lifetime totals" note (V1.2 r6).
   Sits at the top of the org-profile drawer when filters are active, so
   users don't think the drawer contradicts the filter-aware row above
   they clicked through from. */
.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);
  /* V1.4.9 fix — antes: overflow-x:auto como red de seguridad. Con table-layout:fixed
     redimensionar una columna NUNCA desborda (roba ancho a las demás), así que lo
     único que activaba era la barra fantasma. Se oculta aquí; el scroll real lo
     reactiva la @container de abajo 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 manual per-column widths effective and prevents one
     long cell from blowing up the layout. Combined with overflow-x:auto on the
     wrapper, this gives predictable column behavior. */
  table-layout: fixed;
  /* V1.4.9 - min-width EN LA TABLA (no en celdas ni columnas).
     Resuelve los dos problemas con una sola regla:
       - En escritorio, si el contenedor es mas ancho que este minimo, gana
         width:100% y la tabla ocupa el contenedor sin mas - sin barra.
       - En movil, si el contenedor es mas estrecho, gana min-width: la tabla
         mantiene un ancho legible y es .data-table-wrap (overflow-x:auto)
         quien absorbe el desbordamiento con una barra horizontal, en vez de
         que las columnas se compriman hasta ser ilegibles.
     Un min-width en una CELDA es distinto y NO sirve: bajo table-layout:fixed
     el algoritmo de columnas lo ignora salvo en la primera fila. En la propia
     tabla si es fiable, porque no compite con ese algoritmo. */
  min-width: 640px;
}

/* Solo cuando el contenedor es más estrecho que el min-width de la tabla hay un
   desbordamiento REAL que merece scroll; ahí reactivamos overflow-x:auto. Por
   encima de ese umbral la tabla cabe y la barra sería solo 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;
  /* Ellipsis overflow: cells truncate cleanly within their column width.
     Multi-line cells (with `.title-clip`) opt out via their own rule 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; }
/* V1.4.9 — sin min-width en la columna de título: prevalece sobre el ancho
   porcentual de table-layout:fixed y ensanchaba la tabla por debajo, que era
   el origen real de la 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;
  /* V1.4.8 — sin puntos suspensivos DE LA CELDA. Un badge es un inline-block
     con padding y borde: cuando su caja excede el ancho de columna, el
     navegador no puede recortar dentro de él y pinta los "…" AL LADO, que se
     leen como si faltara contenido. Si algo sobra, que se recorte dentro del
     badge (regla siguiente), que sí parece intencionado. */
  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).
   Drawer tables opt out of the page-level table-layout:fixed + nowrap rules
   because their content (esp. project titles under acronyms) needs wrapping,
   and they're small enough that resizable columns aren't needed. */
.drawer .data-table { font-size: 12px; table-layout: auto; }
/* V1.4.9 — la tabla de PROYECTOS del drawer vuelve a table-layout:fixed. El
   opt-out de arriba es para las tablas pequeñas (socios), cuyo contenido
   necesita envolver; en la de proyectos anulaba los anchos porcentuales y la
   tabla se ensanchaba con el contenido 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; }

/* V1.4.9 — 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 (V1.2 Session 2)

   Visual language for this page differs slightly from the rest of the
   dashboard: smaller cards, denser layout, sparklines rather than full
   charts. The intent is "scan, don't drill" — users come here to get
   the month-over-month gist, not to filter and explore.
   ========================================================= */

.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 { /* container */
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.trend-nco-note {
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  padding: 12px 14px;
}
.trend-nco-note .trend-nco-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-nco-note 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 (V1.2)
   Shown from the very first byte of HTML, removed when first SQL
   query resolves (see utils/app-loading.js). The black-ish background
   matches the dashboard theme — it should not feel like a generic
   "page loading" spinner but rather an intentional, themed step.
   ========================================================= */
.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;
  /* Smooth fade-out — matches 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 (V1.2) — hierarchical pillar+component filter
   ========================================================= */
.filter-theme-tree > li {
  /* The base .filter-checkboxes li already sets display:flex with the
     pillar controls in a row. Adding flex-wrap lets the nested sublist
     (.filter-theme-sublist) wrap to the next line below the pillar row
     instead of squeezing into the same row. */
  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 {
  /* V1.8.4 — basis 0, not auto. In a WRAPPING flex row the browser breaks
     the line BEFORE it shrinks anything, so with basis:auto a long
     component name ("Consejo Europeo de Investigación (ERC)") claimed its
     full content width and pushed the new instrument caret onto a line of
     its own. With basis 0 the label takes only the space left over, wraps
     its own text, and the caret stays on the first line. */
  flex: 1 1 0;
  min-width: 0;
  cursor: pointer;
}

/* V1.8.4 — level 3: instruments (ERC/MSCA/EIC) nested inside a component
   row. The component <li> is display:flex, so it needs the same wrap rule
   the pillar row already has for its own 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 */
}

/* =========================================================
   V1.2.5 — Org detail drawer enhancements
   ========================================================= */

/* 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;
}
/* V1.4.8 — en línea, un tercio cada uno. La base de 140px es el punto de
   ruptura: por debajo de ~440px de panel no caben tres y flex-wrap los apila
   solo, sin necesidad de 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 icon for table rows and project drawer topic
 * lists (V1.3). Small ↗ glyph next to a topic code; muted by default,
 * accent on hover/focus. Click stops propagation so opening the
 * canonical portal page does not also trigger the row's own click.
 */
.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;   /* V1.4.7: selects and the count sit on one baseline */
}
.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;
}

/* V1.2.5+ — 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);
}


/* ============ V1.3.7 — 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); }


/* ============ V1.4.2 — 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; }

/* ============================================================
   V1.5 — 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;
}

/* ============================================================
   V1.5.2 — 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;
}

/* ============================================================
   V1.5.3 — scroll-capped lists inside the drawer / embeds
   ============================================================ */

/* V1.4.9 — EN EL DASHBOARD la tabla NO se acota.
   El tope de 420px existe para que un bloque insertado no reviente la
   maquetación de una página ajena, y sigue vigente en embeds.css. Dentro del
   drawer sobra: dejaba medio panel vacío y creaba un segundo scroll dentro
   del scroll del propio drawer, con dos barras a la vez. Sin tope, la lista
   crece y el scroll del drawer (.drawer__content) se ocupa de todo. */
.drawer__scroll-table {
  max-height: none;
  overflow-y: visible;
  /* Por defecto oculto, igual que .data-table-wrap: sin esto, cualquier
     tabla más ancha que su hueco desbordaría visualmente en vez de
     activar la barra horizontal — la @container de arriba es quien la
     reactiva de verdad 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, que ahora es
   .drawer__content: sigue visible al recorrer la lista. */
.drawer__scroll-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-subtle);
}

/* ============================================================
   V1.4.7 — 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;
}

/* ============================================================
   V1.4.7 — 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; }

/* ============================================================
   V1.4.7 — 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;
}

/* ============================================================
   V1.4.7 — 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;
}

/* ============================================================
   V1.4.7 — 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; }

/* V1.4.8 — 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;
}

/* V1.4.8 — 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); }

/* V1.4.8 — acción dentro del drawer (ver los proyectos de una rama SciVoc).
   Clase PROPIA: la primera versión reutilizó .drawer__action-btn, que ya
   existía para los tres botones de la cabecera de entidad, y su width:100%
   los convirtió en bloques apilados. */
.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; }

/* V1.4.8 — 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; }
/* V1.6.1 (M's request) — one-line help text, WIDGET-ONLY (added directly
   in cordis-widgets.js's "scivoc-tree" mount function, not in
   makeScivocTree() itself, which pages/topics.js's dashboard sub-tab also
   uses — the dashboard doesn't get this text). Sits between the widget's
   own title and .scivoc-tree__stats above. */
.scivoc-tree__help {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--fg-muted);
}

/* ---------- Comparative blocks (V1.4.8) ---------- */

.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); }

/* V1.4.9 — tabla de proyectos: caber sin barra horizontal en ~1000px.
   Las columnas fijas suman 892px, así que el título necesita un mínimo
   modesto; con los 260px anteriores el total pasaba de 1150 y aparecía el
   scroll incluso donde había sitio. El título envuelve a dos líneas, que es
   preferible a desplazar la tabla entera. */
.drawer__scroll-table .data-table td,
.drawer__scroll-table .data-table th { padding-left: 8px; padding-right: 8px; }

/* El buscador ocupaba media fila y empujaba los selectores a una segunda
   línea; 150px basta para escribir y deja los cinco controles en una. */
.drawer__projects-search { flex: 0 1 150px; min-width: 110px; }

/* V1.4.9 — el título ocupa TODO el ancho de su columna.
   Arrastraba un max-width: 360px de cuando la tabla no declaraba anchos: con
   table-layout:fixed la columna ya tiene el suyo, y ese tope dejaba hueco
   vacío a la derecha recortando 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;
}

/* V1.4.9 — 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; }

/* V1.4.9 — 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); }

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

/* V1.5.0 — transient global notice (ui-errors.js showNotice()). Currently
   used for one thing: telling the person why they were just redirected off
   a page unavailable in the active programme. Fixed + centred rather than
   anchored to any one page, since a redirect can originate 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;
}

/* =========================================================
   V1.5.0 Fase 5 — 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 — same numeric rhythm as .kpi/.kpi-grid, but a
   left accent bar (--fp-card-color, set inline per card) replaces the
   colour-per-pillar convention: here there are only ever two cards, one
   per programme, so a persistent coloured edge is a stronger visual pair
   than relying on reading order or 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;
}

/* V1.5.0 — region filter row (yearly series, Section 1). Plain <select>,
   not the global filter panel's tree — see combined.js's buildOnce() note
   on why Combined mode gets its own lightweight geography filter instead
   of reusing the 16-dimension panel.
   V1.6.1 — same row now also holds the entity-type <select> (M's request,
   combinable with region); flex-wrap added so the two label+select pairs
   stack on narrow viewports 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 per plan §Fase5.3-4. */
.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% */

/* V1.7.0 (M's request) — the by-year chart's secondary control: a plain
   checkbox rather than a second row of .chart-toggle pills, deliberately.
   The metric (projects/EC) is the primary choice; the year basis is an
   adjustment to it, and the visual hierarchy should say so — two equal
   pill rows on one card read as two equal decisions. Hidden entirely in
   H2020, where a call year isn't derivable (see overview.js's
   syncYearBasisRow). */
.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; }

/* V1.7.0 — a chart card that spans the full grid row. Used by the SNS tab's
   type-of-action donut, whose external labels need the width; inside the
   grid (rather than a separate section below it) it keeps the same vertical
   rhythm as the cards above instead of reading as a stranded block. */
.chart-card--full { grid-column: 1 / -1; }
/* Breathing room between the SNS tab's stacked blocks (table -> charts ->
   table). The chart grid sits between two tables and was butting straight
   into both. */
#page-sns .chart-grid { margin: 20px 0; }

/* V1.7.0 fix, round 2 (M's report: the first attempt didn't align at the
   top, and around 1080px viewport width three columns didn't actually
   fit). Two corrections:
   (1) `grid-column: 1/3` on the 5th card pushed it to a WHOLE NEW ROW,
       not beside the 4th — auto-placement fills column 1 of row 2 with
       the 4th card first, so a 5th card also starting at column 1 can't
       share that row and drops to row 3, leaving row 2's columns 2-3 AND
       row 3's column 3 empty. `2/4` (columns 2-3, the ones actually free
       next to the 4th card) keeps it on the SAME row — top-aligned with
       "por tipo de organización" as asked, no wasted row.
   (2) A viewport @media query doesn't know the sidebar exists, so
       "min-width: 1080px" could fire while the ACTUAL content area
       (.site-main, capped at 1400px minus its own padding and whatever
       the sidebar takes) is still too narrow for 3 real ≥420px columns —
       exactly the "no cabe" the report describes. Switched to a
       @container query, measuring #page-sns's own rendered width
       directly rather than guessing from the viewport — the same
       technique .data-table-outer already uses elsewhere in this file.
       1300px clears 3×420px columns + 2×16px gaps (1292px) with a small
       margin. */
#page-sns {
  container-type: inline-size;
}
@container (min-width: 1300px) {
  #page-sns .chart-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  #page-sns .chart-grid > :nth-child(5) {
    grid-column: 2 / 4;
  }
}

/* V1.7.0 fix, round 2 (M's report: still wrapping "at 1080" — most likely
   1080 meant screen resolution/1080p, i.e. a genuinely wide ~1920px
   window, not a literal 1080px viewport, so the original upper-bounded
   rule never applied there). The general .kpi-grid rule (auto-fill,
   minmax(200px,1fr)) is shared by every page and deliberately flexible —
   Overview alone has up to 9 KPI cards, so a fixed column count there
   would be wrong. SNS always has exactly 6, with no reason to ever let
   them wrap or hand column-count decisions to auto-fill's guessing:
   unconditional above the existing mobile breakpoint (700px, line
   ~350/360 in this file), not just in some middle band. Six `1fr` tracks
   always sum to the full container width regardless of how narrow that
   makes each one, so this can't overflow/wrap at any width ≥700px —
   removes the boundary-dependent fragility a bounded range had. Below
   700px, six columns that narrow would be illegible on an actual phone,
   so mobile keeps the general auto-fill fallback. */
@media (min-width: 700px) {
  #page-sns .kpi-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

/* V1.7.3 — SNS by-year chart became a bar+line with a secondary % axis
   (chart-helpers.js's barLineChart): two axis titles plus a legend don't
   fit the default 240px. Shorter than --regional-bar-line's 380px, since
   this one sits in a grid cell rather than spanning the full width and has
   fewer, shorter category labels (years, not CCAA names). */
.chart-card__canvas-wrap--sns-bar-line { height: 300px; }

/* =========================================================
   V1.8.0 — "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; }

/* V1.8.0 — HTML tooltip (chart-helpers.js's makeHtmlTooltip). Real DOM
   rather than canvas pixels, so the figures can be selected and copied.
   pointer-events must be auto for that to work in practice — the usual
   `none` would make the text unreachable with the mouse. */
.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; }

/* V1.8.0 — the Overview by-year chart became a bar+line with a secondary
   % axis, which needs more room than the 240px grid default (two axis
   titles plus a legend). Scoped to that one card so the other four in the
   same grid keep their height. */
#page-overview .chart-card:has(#chart-by-year) .chart-card__canvas-wrap { height: 300px; }

/* V1.8.3 — 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; }

/* V1.8.6 — 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; } }
