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

/* 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;

  --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;
  background: linear-gradient(180deg, #c8102e 0%, #c8102e 50%, var(--accent) 50%, var(--accent) 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); }

/* =========================================================
   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;
}

/* =========================================================
   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;
}

/* =========================================================
   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-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  /* Safety net: if user resizes columns wider than the wrapper, allow horizontal scroll
     instead of clipping or breaking the layout. */
  overflow-x: auto;
}
.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;
}
.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; }
.data-table .col-title    { min-width: 260px; }
.data-table .col-numeric  { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .col-badge    { white-space: nowrap; }

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

/* ============================================================
   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, #f0f0f0); }

/* 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); }
.subtab-btn[aria-pressed="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.subtab-content { min-height: 200px; }
.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;
}

/* 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);
}

/* 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);
}
.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, #1a1f2c);
}

.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 {
  flex: 1 1 auto;
  cursor: pointer;
}

/* =========================================================
   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;
}
.drawer__action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 12px;
  font-family: inherit;
  background: var(--bg-elev, #f0f2f6);
  border: 1px solid var(--border, #d0d4d9);
  border-radius: 4px;
  cursor: pointer;
  color: var(--fg, #1a1f2c);
  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;
}
.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, #1a1f2c);
}
.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, #1a1f2c);
}

/* 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, #f0f2f6);
  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, #1a1f2c); }
.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, #003b66);
  color: white;
  border-color: var(--accent-dark, #003b66);
}
