:root {
  --ink: #172126;
  --muted: #61717a;
  --line: #dbe3e7;
  --paper: #f7f9fa;
  --panel: #ffffff;
  --green: #167a6b;
  --shadow: 0 18px 42px rgba(23, 33, 38, 0.10);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

.topbar {
  min-height: 112px;
  padding: 26px clamp(18px, 4vw, 54px);
  background: #20323a;
  color: #fff;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(28px, 4vw, 44px); letter-spacing: 0; }
h2 { font-size: 22px; letter-spacing: 0; }

.eyebrow {
  color: #7ea9a0;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  margin-bottom: 5px;
}

.source-pill {
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 999px;
  padding: 9px 12px;
  color: #dbe8e5;
  font-size: 13px;
  white-space: nowrap;
}

main {
  padding: 24px clamp(14px, 3vw, 42px) 42px;
  max-width: 1440px;
  margin: 0 auto;
}

.selector-band {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.notice {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  border-left: 5px solid var(--green);
  background: #eef7f4;
  color: #24363b;
  margin-bottom: 16px;
}

.controls-grid {
  display: grid;
  grid-template-columns: minmax(160px, .75fr) minmax(130px, .55fr) minmax(110px, .45fr) minmax(220px, 1fr) minmax(210px, .95fr) minmax(210px, .95fr);
  gap: 14px;
  align-items: end;
}

.filter-context {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #edf1f3;
  color: var(--muted);
  font-size: 13px;
}

.filter-context span {
  font-weight: 800;
  color: #31434a;
}

.filter-context strong {
  color: #31434a;
  font-weight: 750;
}

.clear-filters {
  flex: 0 0 auto;
  border: 1px solid #c8d3d8;
  background: #fff;
  color: #31434a;
  border-radius: 6px;
  padding: 8px 11px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
}

.clear-filters:hover {
  border-color: var(--green);
  color: var(--green);
}

.field { display: grid; gap: 7px; }
.field span {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

input, select {
  width: 100%;
  height: 42px;
  border: 1px solid #c8d3d8;
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.selected-ies {
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 18px 0;
}

.tab {
  border: 1px solid var(--line);
  background: #fff;
  color: #31434a;
  padding: 10px 13px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 750;
}

.tab.active {
  background: #20323a;
  border-color: #20323a;
  color: #fff;
}

.panel { display: none; }
.panel.active { display: block; }

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin: 10px 0 14px;
}

.chart-card, .kpi {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 26px rgba(23, 33, 38, .06);
}

.chart-card {
  position: relative;
  padding: 14px;
  min-height: 290px;
  margin-bottom: 16px;
  overflow: hidden;
  min-width: 0;
}

.chart-card.stacked { margin-top: 16px; }

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.comparison-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 26px rgba(23, 33, 38, .06);
  padding: 16px;
}

.comparison-card h3 {
  margin: 0 0 12px;
  min-height: 38px;
  display: flex;
  align-items: center;
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0;
}

.comparison-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(78px, auto);
  gap: 5px 12px;
  padding: 12px 0;
  border-top: 1px solid #edf1f3;
}

.comparison-row:first-of-type { border-top: 0; }
.comparison-row span {
  display: block;
  font-weight: 800;
  color: #31434a;
}
.comparison-row small,
.comparison-row em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.25;
}
.comparison-row strong {
  align-self: start;
  justify-self: end;
  font-size: 23px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.comparison-row em {
  grid-column: 2;
  justify-self: end;
  text-align: right;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-grid.expanded { grid-template-columns: repeat(4, minmax(150px, 1fr)); }
.ufpb-grid { grid-template-columns: repeat(3, minmax(180px, 1fr)); }

.kpi { padding: 15px; }
.kpi .label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.kpi .value {
  font-size: 31px;
  font-weight: 850;
  margin: 7px 0 4px;
}
.kpi .sub {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  margin-top: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  max-height: 520px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 10px 12px;
  border-bottom: 1px solid #edf1f3;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #f1f5f6;
  z-index: 1;
  color: #31434a;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

td.num, th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.program-toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.program-sample {
  margin-top: 20px;
  display: grid;
  gap: 16px;
  min-width: 0;
}

.sample-head,
.analysis-card,
.note-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 26px rgba(23, 33, 38, .06);
}

.sample-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  padding: 18px;
}

.sample-head h2 {
  margin-bottom: 7px;
}

.sample-head p {
  color: var(--muted);
  line-height: 1.45;
}

.sample-note {
  max-width: 260px;
  padding: 10px 12px;
  border-left: 4px solid var(--green);
  background: #eef7f4;
  color: #31434a;
  font-size: 13px;
  line-height: 1.35;
}

.note-timeline {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.note-card {
  padding: 15px;
  display: grid;
  gap: 7px;
  min-height: 178px;
}

.note-card span,
.note-card em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.note-card strong {
  font-size: 42px;
  line-height: 1;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}

.note-card p,
.insight-list p {
  line-height: 1.45;
}

.sample-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, .75fr);
  gap: 14px;
  align-items: start;
}

.program-chart-grid {
  display: grid;
  grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr);
  gap: 14px;
}

.program-chart {
  grid-column: 1 / -1;
  min-height: 260px;
}

.program-note-chart {
  min-height: 240px;
}

.excellence-chart {
  min-height: 0;
}

.quick-insight {
  border-left: 4px solid var(--green);
  background: #f3f8f6;
  color: #24363b;
  padding: 12px 14px;
  border-radius: 8px;
  line-height: 1.45;
  font-size: 14px;
}

.intelligence-grid {
  display: grid;
  gap: 12px;
}

.intelligence-year {
  border: 1px solid #edf1f3;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.intelligence-year header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 11px 13px;
  background: #f1f5f6;
  color: #31434a;
}

.intelligence-year header span {
  font-size: 13px;
  font-weight: 800;
}

.intelligence-year header strong {
  color: var(--green);
  font-size: 13px;
  white-space: nowrap;
}

.intelligence-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
}

.intelligence-block {
  padding: 13px;
  min-width: 0;
}

.intelligence-block + .intelligence-block {
  border-left: 1px solid #edf1f3;
}

.intelligence-block h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: #31434a;
  letter-spacing: 0;
}

.intelligence-block ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 7px;
}

.intelligence-block li,
.empty-inline {
  color: #41545c;
  font-size: 13px;
  line-height: 1.45;
}

.summary-text {
  padding: 14px;
}

.summary-text p {
  margin: 0;
  color: #33474f;
  font-size: 13px;
  line-height: 1.55;
}

.empty-inline {
  margin: 0;
  color: var(--muted);
}

.analysis-card {
  padding: 16px;
  min-width: 0;
}

.analysis-card h3 {
  margin: 0 0 12px;
  font-size: 16px;
  letter-spacing: 0;
}

.table-wrap.compact {
  margin-top: 0;
  max-height: 420px;
}

.item-detail-wrap {
  max-height: 560px;
}

.concept {
  display: inline-block;
  min-width: 92px;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.concept.muito-bom {
  background: #e7f4ef;
  color: #126555;
}

.concept.bom {
  background: #fff3d9;
  color: #8a5a07;
}

.concept.regular {
  background: #fde8df;
  color: #9b3f1c;
}

.concept.fraco {
  background: #f8dddd;
  color: #923332;
}

.concept.nao-aplicavel,
.concept.neutro {
  background: #eef2f4;
  color: #51616a;
}

.table-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.insight-list {
  display: grid;
  gap: 12px;
  color: #31434a;
}

.item-year-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.item-year {
  border: 1px solid #edf1f3;
  border-radius: 8px;
  overflow: hidden;
  min-width: 0;
}

.item-year header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  padding: 12px;
  background: #f1f5f6;
}

.item-year header span {
  color: var(--muted);
  font-size: 12px;
}

.item-list {
  display: grid;
}

.item-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  padding: 10px 12px;
  border-top: 1px solid #edf1f3;
}

.item-code {
  font-weight: 850;
  color: #31434a;
  font-variant-numeric: tabular-nums;
}

.item-group {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

canvas {
  width: 100%;
  max-width: 100%;
  display: block;
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

.chart-tooltip {
  position: fixed;
  z-index: 20;
  display: none;
  min-width: 150px;
  padding: 9px 10px;
  border-radius: 6px;
  background: #20323a;
  color: #fff;
  box-shadow: 0 12px 28px rgba(23, 33, 38, .24);
  pointer-events: none;
  font-size: 12px;
}

.chart-tooltip.visible { display: grid; gap: 3px; }
.chart-tooltip span { color: #dbe8e5; }

@media (max-width: 1180px) {
  .controls-grid { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
  .comparison-grid { grid-template-columns: 1fr; }
  .kpi-grid.expanded { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
  .sample-grid,
  .program-chart-grid,
  .item-year-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .topbar, .section-head {
    align-items: flex-start;
    flex-direction: column;
  }
  .source-pill { white-space: normal; }
  .controls-grid, .ufpb-grid { grid-template-columns: 1fr; }
  .filter-context {
    align-items: flex-start;
    flex-direction: column;
  }
  .kpi-grid { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
  .sample-head,
  .item-year header {
    flex-direction: column;
  }
  .sample-note { max-width: none; }
  .note-timeline { grid-template-columns: 1fr; }
  .intelligence-columns { grid-template-columns: 1fr; }
  .intelligence-block + .intelligence-block {
    border-left: 0;
    border-top: 1px solid #edf1f3;
  }
}

@media (max-width: 560px) {
  main { padding-left: 10px; padding-right: 10px; }
  .kpi-grid, .kpi-grid.expanded { grid-template-columns: 1fr; }
  .tab { flex: 1 1 auto; }
  .chart-card {
    min-height: 0;
    padding: 10px;
  }
  .program-chart,
  .program-note-chart {
    min-height: 0;
  }
  .comparison-card { padding: 13px; }
  .comparison-row strong { font-size: 21px; }
  .analysis-card,
  .sample-head,
  .note-card { padding: 13px; }
  .item-row {
    grid-template-columns: 38px minmax(0, 1fr);
  }
  .item-row .concept {
    grid-column: 1 / -1;
    justify-self: start;
  }
}
