:root {
  --eco-navy: #172653;
  --eco-green: #294f3e;
  --eco-ochre: #a76425;
  --eco-violet: #59427a;
  --eco-rose: #8f414b;
  --eco-teal: #28717a;
  --eco-paper: #fbfcfa;
  --eco-rule: #aab4b0;
}

.territorial-page {
  width: min(1920px, calc(100% - 24px));
  margin: 12px auto 40px;
}

.ecosystem-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 28px;
  padding: 18px 24px 16px;
  color: #1c2b25;
  background: #fff;
  border: 1px solid #d9e0dc;
  border-bottom: 4px solid var(--eco-navy);
  border-radius: 12px 12px 4px 4px;
}

.ecosystem-kicker {
  margin: 0 0 4px;
  color: #49645a;
  font-family: var(--display);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.ecosystem-intro h1 {
  max-width: 1180px;
  margin: 0;
  color: var(--eco-navy);
  font-size: clamp(2rem, 3.8vw, 4rem);
  letter-spacing: -.025em;
  line-height: .91;
  text-transform: uppercase;
}

.ecosystem-intro p:last-child {
  max-width: 1050px;
  margin: 9px 0 0;
  color: #40544b;
  font-size: clamp(.82rem, 1vw, 1rem);
  font-weight: 700;
}

.ecosystem-actions { display: flex; gap: 8px; }

.ecosystem-action {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 8px 12px;
  color: #27473a;
  background: #f1f5f2;
  border: 1px solid #bac9c0;
  border-radius: 8px;
  font: inherit;
  font-size: .72rem;
  font-weight: 850;
  cursor: pointer;
}

.ecosystem-action-primary { color: #fff; background: var(--eco-navy); border-color: var(--eco-navy); }
.ecosystem-action:hover { box-shadow: 0 5px 14px rgba(20, 47, 38, .14); }
.ecosystem-action svg { width: 16px; height: 16px; }

.ecosystem-panel {
  margin-top: 10px;
  overflow: hidden;
  background: var(--eco-paper);
  border: 1px solid #d5ddda;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(27, 53, 43, .07);
}

.ecosystem-scroll {
  max-width: 100%;
  overflow: auto;
  scrollbar-color: #6f8378 #e9eeea;
  scrollbar-width: thin;
}

.ecosystem-board {
  position: relative;
  z-index: 0;
  display: grid;
  gap: 28px;
  width: 100%;
  min-width: 1720px;
  min-height: 1050px;
  padding: 22px 20px 18px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(23, 38, 83, .025) 1px, transparent 1px) 0 0 / 80px 80px,
    #fff;
}

.ecosystem-links {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.ecosystem-link {
  fill: none;
  stroke-width: 1.55;
  stroke-dasharray: 5 5;
  opacity: .52;
  vector-effect: non-scaling-stroke;
  transition: opacity .16s ease, stroke-width .16s ease;
}

.ecosystem-link[data-type="training"] { stroke: var(--eco-navy); }
.ecosystem-link[data-type="support"] { stroke: var(--eco-green); }
.ecosystem-link[data-type="innovation"] { stroke: var(--eco-ochre); }
.ecosystem-link[data-type="strength"] { stroke: var(--eco-violet); }
.ecosystem-link[data-type="connect"] { stroke: var(--eco-teal); }
.ecosystem-link[data-type="market"] { stroke: var(--eco-rose); }
.ecosystem-link[data-type="technical"] { stroke: #6e4935; }
.ecosystem-link[data-type="projects"] { stroke: #253869; }
.ecosystem-link.is-muted { opacity: .035; }
.ecosystem-link.is-active { stroke-width: 3.6; stroke-dasharray: none; opacity: 1; }

.ecosystem-level {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
}

.ecosystem-level-label {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: var(--eco-navy);
  text-align: center;
}

.ecosystem-level-label strong {
  display: inline-flex;
  padding: 5px 9px;
  color: #fff;
  background: var(--eco-navy);
  border-radius: 6px;
  box-shadow: 0 2px 0 #0d1737;
  font-family: var(--display);
  font-size: .8rem;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.ecosystem-level-label span {
  max-width: 90px;
  margin-top: 8px;
  font-family: var(--display);
  font-size: .72rem;
  font-weight: 700;
  line-height: 1.18;
  text-transform: uppercase;
}

.ecosystem-card-grid { display: grid; gap: 8px; min-width: 0; }
.ecosystem-people-grid { grid-template-columns: repeat(var(--people-columns, 10), minmax(0, 1fr)); }
.ecosystem-needs-grid { grid-template-columns: repeat(8, minmax(0, 1fr)); }
.ecosystem-organizations-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); }

.ecosystem-card {
  position: relative;
  min-width: 0;
  color: #17251f;
  background: rgba(255,255,255,.98);
  border: 1.5px solid var(--card-color, #607d70);
  border-radius: 9px;
  box-shadow: 0 2px 5px rgba(20, 39, 31, .08);
  font: inherit;
  cursor: pointer;
  transition: opacity .16s ease, box-shadow .16s ease, transform .16s ease;
}

.ecosystem-card:hover { box-shadow: 0 7px 18px rgba(20, 39, 31, .15); transform: translateY(-2px); }
.ecosystem-card:focus-visible { outline: 4px solid #efb735; outline-offset: 2px; }
.ecosystem-card.is-muted { opacity: .18; }
.ecosystem-card.is-active { box-shadow: 0 0 0 4px color-mix(in srgb, var(--card-color, #294f3e) 24%, transparent), 0 10px 22px rgba(20, 39, 31, .16); transform: translateY(-2px); }

.ecosystem-person {
  --card-color: #657a72;
  display: grid;
  align-content: start;
  min-height: 126px;
  padding: 12px 9px 10px;
  text-align: center;
}

.ecosystem-person:nth-child(3n + 1) { --card-color: var(--eco-green); }
.ecosystem-person:nth-child(3n + 2) { --card-color: var(--eco-navy); }
.ecosystem-person:nth-child(3n + 3) { --card-color: var(--eco-ochre); }
.ecosystem-person strong { color: #283d34; font-family: var(--display); font-size: .88rem; line-height: 1.05; text-transform: uppercase; }
.ecosystem-person small { margin-top: 8px; color: #465b51; font-size: .62rem; font-weight: 750; line-height: 1.3; }
.ecosystem-person em { margin-top: 7px; overflow: hidden; color: #7a6250; font-size: .56rem; font-style: normal; text-overflow: ellipsis; white-space: nowrap; }
.ecosystem-person.is-loading span { width: 60%; height: 13px; margin: 5px auto 10px; background: #e4e9e5; border-radius: 3px; animation: eco-pulse 1s alternate infinite; }

.ecosystem-need {
  --card-color: var(--eco-green);
  display: grid;
  justify-items: center;
  align-content: start;
  min-height: 164px;
  padding: 13px 10px;
  text-align: center;
}

.ecosystem-need:nth-child(3), .ecosystem-need:nth-child(4) { --card-color: var(--eco-ochre); }
.ecosystem-need:nth-child(5) { --card-color: var(--eco-rose); }
.ecosystem-need:nth-child(6) { --card-color: var(--eco-navy); }
.ecosystem-need:nth-child(7) { --card-color: #74472c; }
.ecosystem-need:nth-child(8) { --card-color: #24386b; }
.ecosystem-need svg { width: 31px; height: 31px; margin-bottom: 9px; color: var(--card-color); stroke-width: 1.7; }
.ecosystem-need strong { color: #24352d; font-family: var(--display); font-size: .89rem; line-height: 1.05; text-transform: uppercase; }
.ecosystem-need span { margin-top: 8px; color: #34493f; font-size: .59rem; font-weight: 700; line-height: 1.3; }

.ecosystem-organization {
  --card-color: #556e61;
  display: block;
  min-height: 235px;
  padding: 13px 12px;
  text-align: left;
}

.ecosystem-organization:nth-child(1) { --card-color: var(--eco-navy); }
.ecosystem-organization:nth-child(2) { --card-color: var(--eco-green); }
.ecosystem-organization:nth-child(3) { --card-color: var(--eco-ochre); }
.ecosystem-organization:nth-child(4) { --card-color: #596177; }
.ecosystem-organization:nth-child(5) { --card-color: var(--eco-rose); }
.ecosystem-organization:nth-child(6) { --card-color: #715f47; }
.ecosystem-organization:nth-child(7) { --card-color: var(--eco-violet); }
.ecosystem-organization > strong { display: block; color: var(--card-color); font-family: var(--display); font-size: .92rem; line-height: 1.02; text-align: center; text-transform: uppercase; }
.ecosystem-organization > small { display: block; margin: 5px 0 8px; color: #34473e; font-size: .56rem; font-weight: 800; line-height: 1.25; text-align: center; }
.ecosystem-organization ul { display: grid; gap: 4px; margin: 12px 0 0; padding: 0 0 0 15px; color: #2f4038; font-size: .58rem; font-weight: 700; line-height: 1.25; }

.ecosystem-legend {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 120px repeat(8, minmax(0, 1fr));
  align-items: stretch;
  gap: 5px;
  padding: 8px;
  background: rgba(255,255,255,.98);
  border: 1px solid #cfd8d3;
  border-radius: 7px;
}

.ecosystem-legend > strong { display: grid; place-items: center; color: #33463d; font-family: var(--display); font-size: .66rem; line-height: 1.14; text-align: center; text-transform: uppercase; }
.ecosystem-legend button { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 6px; color: #33473e; background: transparent; border: 1px solid transparent; border-radius: 5px; font: inherit; font-size: .55rem; font-weight: 850; text-align: center; text-transform: uppercase; cursor: pointer; }
.ecosystem-legend button:hover, .ecosystem-legend button.is-active { background: #f1f4f2; border-color: #aebbb4; }
.ecosystem-legend button i { flex: 0 0 26px; width: 26px; height: 0; border-top: 2px dashed var(--legend-color, var(--eco-navy)); }
.ecosystem-legend button[data-relation-filter="support"] { --legend-color: var(--eco-green); }
.ecosystem-legend button[data-relation-filter="innovation"] { --legend-color: var(--eco-ochre); }
.ecosystem-legend button[data-relation-filter="strength"] { --legend-color: var(--eco-violet); }
.ecosystem-legend button[data-relation-filter="connect"] { --legend-color: var(--eco-teal); }
.ecosystem-legend button[data-relation-filter="market"] { --legend-color: var(--eco-rose); }
.ecosystem-legend button[data-relation-filter="technical"] { --legend-color: #6e4935; }
.ecosystem-legend button[data-relation-filter="projects"] { --legend-color: #253869; }

.ecosystem-outcomes {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
}

.ecosystem-outcomes header { display: grid; place-items: center; color: var(--eco-navy); font-family: var(--display); font-size: .7rem; line-height: 1.12; text-align: center; text-transform: uppercase; }
.ecosystem-outcomes ol { display: grid; grid-template-columns: 1fr 1.2fr 1.65fr 1.65fr 1.4fr 1.15fr; gap: 26px; margin: 0; padding: 0; list-style: none; counter-reset: none; }
.ecosystem-outcomes li { position: relative; display: grid; place-items: center; min-height: 66px; padding: 9px; color: #23352d; background: #f8faf8; border: 1.5px solid #879a90; border-radius: 7px; font-family: var(--display); font-size: .73rem; font-weight: 700; line-height: 1.12; text-align: center; text-transform: uppercase; }
.ecosystem-outcomes li:nth-child(3) { color: var(--eco-ochre); }.ecosystem-outcomes li:nth-child(4) { color: var(--eco-violet); }.ecosystem-outcomes li:nth-child(5) { color: var(--eco-teal); }.ecosystem-outcomes li:nth-child(6) { color: var(--eco-navy); }
.ecosystem-outcomes li:not(:last-child)::after { position: absolute; top: 50%; right: -22px; width: 17px; border-top: 3px solid var(--eco-navy); content: ''; }
.ecosystem-outcomes li:not(:last-child)::before { position: absolute; z-index: 2; top: calc(50% - 4px); right: -23px; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 7px solid var(--eco-navy); content: ''; }

.ecosystem-message {
  position: relative;
  z-index: 3;
  max-width: 1240px;
  margin: -12px auto 0;
  padding: 10px 18px;
  color: #243657;
  background: #edf1f9;
  border: 1px solid #b6c0d5;
  border-radius: 7px;
  font-size: .66rem;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
}

.ecosystem-detail {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(300px, .8fr);
  gap: 22px;
  align-items: center;
  margin-top: 10px;
  padding: 14px 18px;
  color: #30463b;
  background: #fff;
  border: 1px solid #d7e0db;
  border-left: 6px solid var(--detail-color, var(--eco-navy));
  border-radius: 8px;
}
.ecosystem-detail span { color: var(--detail-color, var(--eco-navy)); font-family: var(--display); font-size: .66rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.ecosystem-detail h2 { margin: 2px 0 4px; color: #24372e; font-size: 1.25rem; }
.ecosystem-detail p { margin: 0; color: #5a6962; font-size: .76rem; }
.ecosystem-detail ul { display: grid; gap: 4px; margin: 0; padding-left: 18px; color: #53645b; font-size: .7rem; }

.ecosystem-panel:fullscreen { width: 100vw; height: 100vh; margin: 0; overflow: hidden; background: #fff; border: 0; border-radius: 0; }
.ecosystem-panel:fullscreen .ecosystem-scroll { height: 100%; }
.ecosystem-panel:fullscreen .ecosystem-board { min-height: 100%; }

@keyframes eco-pulse { to { opacity: .35; } }

@media (max-width: 900px) {
  .territorial-page { width: calc(100% - 12px); margin-top: 6px; }
  .ecosystem-intro { grid-template-columns: 1fr; gap: 12px; padding: 15px; }
  .ecosystem-actions { justify-content: flex-start; }
  .ecosystem-detail { grid-template-columns: 1fr; gap: 10px; }
}

@media (max-width: 700px) {
  .territorial-page { width: calc(100% - 10px); margin: 5px auto 24px; }
  .ecosystem-intro { gap: 14px; padding: 16px 14px; border-bottom-width: 3px; border-radius: 12px; }
  .ecosystem-intro h1 { max-width: 14ch; font-size: clamp(1.75rem, 9vw, 2.45rem); line-height: .96; }
  .ecosystem-intro p:last-child { font-size: .82rem; line-height: 1.42; }
  .ecosystem-actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .ecosystem-action { justify-content: center; min-height: 44px; font-size: .72rem; }

  .ecosystem-panel { margin-top: 8px; overflow: visible; border-radius: 12px; }
  .ecosystem-scroll { max-width: none; overflow: visible; }
  .ecosystem-board {
    gap: 18px;
    width: 100%;
    min-width: 0;
    min-height: 0;
    padding: 12px 10px 14px;
    overflow: visible;
    background: linear-gradient(180deg, rgba(23,38,83,.025), transparent 26%), #fff;
  }
  .ecosystem-links { display: none; }
  .ecosystem-level { grid-template-columns: 1fr; gap: 9px; }
  .ecosystem-level-label { align-items: center; justify-content: flex-start; flex-direction: row; gap: 9px; text-align: left; }
  .ecosystem-level-label strong { flex: 0 0 auto; font-size: .72rem; }
  .ecosystem-level-label span { max-width: none; margin: 0; font-size: .76rem; line-height: 1.2; }

  .ecosystem-card-grid { gap: 8px; }
  .ecosystem-people-grid {
    display: grid;
    grid-auto-columns: minmax(148px, 44vw);
    grid-auto-flow: column;
    grid-template-columns: none;
    padding: 2px 2px 9px;
    overflow-x: auto;
    scroll-padding-inline: 2px;
    scroll-snap-type: x proximity;
  }
  .ecosystem-person { min-height: 122px; scroll-snap-align: start; }
  .ecosystem-person strong { font-size: .82rem; }
  .ecosystem-person small { font-size: .64rem; }
  .ecosystem-person em { font-size: .58rem; }

  .ecosystem-needs-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ecosystem-need { min-height: 150px; padding: 12px 8px; }
  .ecosystem-need svg { width: 27px; height: 27px; margin-bottom: 7px; }
  .ecosystem-need strong { font-size: .75rem; overflow-wrap: anywhere; }
  .ecosystem-need span { font-size: .59rem; }

  .ecosystem-organizations-grid { grid-template-columns: 1fr; }
  .ecosystem-organization { min-height: 0; padding: 13px 14px; }
  .ecosystem-organization > strong { font-size: .88rem; text-align: left; }
  .ecosystem-organization > small { text-align: left; }
  .ecosystem-organization ul { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px 16px; margin-top: 9px; font-size: .62rem; }

  .ecosystem-legend { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; padding: 9px; }
  .ecosystem-legend > strong { grid-column: 1 / -1; min-height: 32px; font-size: .72rem; }
  .ecosystem-legend button { justify-content: flex-start; min-height: 44px; padding: 7px; font-size: .58rem; text-align: left; }
  .ecosystem-legend button i { flex-basis: 22px; width: 22px; }

  .ecosystem-outcomes { grid-template-columns: 1fr; gap: 8px; }
  .ecosystem-outcomes header { justify-content: start; min-height: 32px; font-size: .72rem; text-align: left; }
  .ecosystem-outcomes ol { grid-template-columns: 1fr; gap: 14px; }
  .ecosystem-outcomes li { min-height: 48px; font-size: .72rem; }
  .ecosystem-outcomes li:not(:last-child)::after { top: auto; right: 50%; bottom: -11px; width: 0; height: 8px; border-top: 0; border-left: 3px solid var(--eco-navy); }
  .ecosystem-outcomes li:not(:last-child)::before { top: auto; right: calc(50% - 4px); bottom: -15px; border-top: 7px solid var(--eco-navy); border-right: 5px solid transparent; border-bottom: 0; border-left: 5px solid transparent; }
  .ecosystem-message { margin: 0; padding: 12px; font-size: .67rem; text-align: left; }
  .ecosystem-detail { margin-top: 8px; padding: 14px; border-left-width: 4px; }
  .ecosystem-detail h2 { font-size: 1.12rem; overflow-wrap: anywhere; }
  .ecosystem-detail p, .ecosystem-detail ul { font-size: .72rem; line-height: 1.45; }

  .ecosystem-panel:fullscreen { overflow: auto; }
  .ecosystem-panel:fullscreen .ecosystem-scroll { height: auto; }
  .ecosystem-panel:fullscreen .ecosystem-board { min-height: 100%; }
}

@media (max-width: 390px) {
  .ecosystem-needs-grid { grid-template-columns: 1fr; }
  .ecosystem-need { grid-template-columns: 34px minmax(0, 1fr); grid-template-rows: auto auto; justify-items: start; min-height: 0; text-align: left; }
  .ecosystem-need svg { grid-row: 1 / span 2; margin: 0 8px 0 0; }
  .ecosystem-need span { margin-top: 4px; }
  .ecosystem-organizations-grid ul { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .ecosystem-card, .ecosystem-link { transition: none; }
  .ecosystem-person.is-loading span { animation: none; }
}
