:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --ink: #183246;
  --muted: #617383;
  --line: #d7e0e6;
  --panel: #ffffff;
  --blue: #0076a8;
  --blue-dark: #003f62;
  --blue-deep: #002f4b;
  --cyan: #00a7c7;
  --soft-blue: #eaf3f7;
  --shadow: 0 8px 24px rgba(18, 52, 73, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

.app-shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 44px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  padding: 26px 30px;
  border-top: 5px solid var(--cyan);
  background: var(--blue-deep);
  color: #fff;
}

.title-block {
  max-width: 980px;
}

.eyebrow {
  margin: 0 0 7px;
  color: #8fd9e7;
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 3.8vw, 4rem);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  font-size: 1.05rem;
}

.brand-subtitle {
  max-width: 740px;
  margin-top: 10px;
  color: #d9e7ee;
  font-size: 1.03rem;
}

.partner-lockup {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-width: 184px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: #fff;
}

.partner-lockup strong {
  color: var(--blue);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.28rem;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

.appearance-toolbar {
  position: relative;
  display: flex;
  justify-content: flex-end;
  padding: 10px 0 0;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--blue-dark);
  padding: 0 12px;
  font-weight: 850;
  cursor: pointer;
}

.palette-icon {
  width: 16px;
  height: 16px;
  border: 3px solid var(--blue);
  border-radius: 50%;
  box-shadow: 6px 0 0 -3px var(--cyan), 0 6px 0 -3px var(--blue-dark);
}

.theme-editor {
  position: absolute;
  z-index: 20;
  top: 54px;
  right: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  min-width: min(680px, calc(100vw - 32px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 16px 38px rgba(15, 49, 70, 0.16);
}

.theme-editor[hidden] {
  display: none;
}

.theme-editor input[type="color"] {
  height: 40px;
  padding: 3px;
  cursor: pointer;
}

.network-strip {
  display: grid;
  grid-template-columns: minmax(170px, 220px) 1fr;
  gap: 20px;
  align-items: center;
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-top: 0;
  background: #fff;
}

.network-heading {
  display: grid;
  gap: 4px;
  padding-right: 20px;
  border-right: 1px solid var(--line);
}

.network-heading span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  text-transform: uppercase;
}

.network-heading strong {
  color: var(--blue-dark);
  font-size: 1rem;
}

.university-logos {
  display: grid;
  grid-template-columns: repeat(6, minmax(100px, 1fr));
  gap: 10px;
}

.university-logo {
  display: grid;
  grid-template-rows: 54px auto;
  align-items: center;
  justify-items: center;
  min-width: 0;
  padding: 8px 10px 7px;
  border-left: 2px solid #eef2f4;
  background: #fff;
}

.university-logo:first-child {
  border-left: 0;
}

.university-logo img {
  width: 100%;
  height: 48px;
  object-fit: contain;
}

.university-logo span {
  color: var(--blue-dark);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.capes-mark {
  position: relative;
  width: 90px;
  height: 74px;
}

.petal {
  position: absolute;
  display: block;
  border-radius: 78% 22% 73% 27% / 68% 27% 73% 32%;
  background: var(--blue);
}

.p1 {
  width: 24px;
  height: 46px;
  left: 34px;
  top: 0;
  transform: rotate(2deg);
  background: var(--blue-dark);
}

.p2 {
  width: 30px;
  height: 58px;
  left: 48px;
  top: 3px;
  transform: rotate(28deg);
}

.p3 {
  width: 26px;
  height: 58px;
  left: 24px;
  top: 20px;
  transform: rotate(-42deg);
}

.p4 {
  width: 26px;
  height: 53px;
  left: 56px;
  top: 36px;
  transform: rotate(65deg);
}

.p5 {
  width: 25px;
  height: 42px;
  left: 35px;
  top: 45px;
  transform: rotate(82deg);
}

.p6 {
  width: 16px;
  height: 32px;
  left: 8px;
  top: 39px;
  transform: rotate(-58deg);
  background: var(--blue-dark);
}

.p7 {
  width: 18px;
  height: 36px;
  right: 2px;
  top: 26px;
  transform: rotate(52deg);
  background: var(--blue-dark);
}

.filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr)) minmax(200px, 1.35fr) auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

label,
.compact-control {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
  text-transform: uppercase;
}

select,
input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfe;
  color: var(--ink);
  padding: 0 10px;
  font: inherit;
  text-transform: none;
}

.ghost-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 16px 0 12px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  padding: 0 16px;
  font-weight: 850;
  white-space: nowrap;
  cursor: pointer;
}

.tab-button.active {
  border-color: var(--blue-dark);
  background: var(--blue-dark);
  color: #fff;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
  gap: 12px;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.compact-kpis {
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 14px;
}

.kpis article {
  min-height: 104px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.kpis span {
  color: var(--muted);
  font-size: 0.84rem;
}

.kpis strong {
  display: block;
  margin-top: 12px;
  color: var(--blue-dark);
  font-size: clamp(1.6rem, 2.6vw, 2.5rem);
  line-height: 1;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 12px;
}

.span-6 {
  grid-column: span 6;
}

.span-12 {
  grid-column: span 12;
}

.panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel p {
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 4px;
}

.bar-chart {
  display: grid;
  gap: 10px;
}

.bar-chart.large {
  gap: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 240px) 1fr minmax(56px, auto);
  align-items: center;
  gap: 12px;
}

.bar-label {
  overflow: hidden;
  color: #223240;
  font-size: 0.9rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 22px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--soft-blue);
}

.bar-fill {
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--blue));
}

.bar-value {
  color: var(--blue-dark);
  font-weight: 900;
  text-align: right;
  white-space: nowrap;
}

.year-grouped-bars {
  display: grid;
  gap: 18px;
}

.stack-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-bottom: 4px;
}

.stack-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 760;
}

.stack-swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
}

.year-stack-group {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfe;
}

.year-stack-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 2px;
}

.year-stack-heading h3 {
  margin: 0;
  color: var(--blue-dark);
  font-size: 1.22rem;
}

.year-stack-heading span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 850;
}

.year-stack-bars {
  display: grid;
  gap: 8px;
}

.institution-stack-row {
  display: grid;
  grid-template-columns: minmax(92px, 140px) 1fr minmax(44px, auto);
  align-items: center;
  gap: 10px;
}

.institution-stack-label {
  overflow: hidden;
  color: #243443;
  font-size: 0.86rem;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.institution-stack-track {
  height: 26px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--soft-blue);
}

.institution-stack-fill {
  display: flex;
  height: 100%;
  min-width: 3px;
  overflow: hidden;
  border-radius: inherit;
}

.stack-segment {
  display: grid;
  min-width: 2px;
  place-items: center;
  color: #fff;
  font-size: 0.74rem;
  font-weight: 900;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.24);
}

.institution-stack-total {
  color: var(--blue-dark);
  font-weight: 950;
  text-align: right;
}

.table-wrap {
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-wrap.spaced {
  margin-top: 4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 0.88rem;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid #edf3f6;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fbfd;
  color: #5d7180;
  font-size: 0.73rem;
  text-transform: uppercase;
}

.num {
  text-align: right;
  white-space: nowrap;
}

.matrix-table th:first-child,
.matrix-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
}

.matrix-table th:first-child {
  z-index: 3;
  background: #f8fbfd;
}

.matrix-cell {
  min-width: 100px;
  font-weight: 850;
}

.matrix-total {
  background: #f3f8fb;
  color: var(--blue-dark);
  font-weight: 950;
}

@media (max-width: 1120px) {
  .network-strip {
    grid-template-columns: 1fr;
  }

  .network-heading {
    padding-right: 0;
    padding-bottom: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .university-logos {
    grid-template-columns: repeat(3, 1fr);
  }

  .filters {
    grid-template-columns: repeat(2, 1fr);
  }

  .ghost-button {
    width: fit-content;
  }

  .kpis {
    grid-template-columns: repeat(2, 1fr);
  }

  .compact-kpis {
    grid-template-columns: repeat(2, 1fr);
  }

  .span-6,
  .span-12 {
    grid-column: 1 / -1;
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100vw - 18px, 1440px);
    padding-top: 16px;
  }

  .topbar,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    padding: 22px 18px;
  }

  .university-logos {
    grid-template-columns: repeat(2, 1fr);
  }

  .partner-lockup {
    justify-items: start;
    padding-left: 0;
  }

  .theme-editor {
    grid-template-columns: repeat(2, 1fr);
    min-width: calc(100vw - 18px);
  }

  .filters,
  .kpis,
  .compact-kpis {
    grid-template-columns: 1fr;
  }

  .bar-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .bar-value {
    text-align: left;
  }

  .institution-stack-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .institution-stack-total {
    text-align: left;
  }
}
