:root {
  --bg: #FAFAF7;
  --surface: #FFFFFF;
  --border: rgba(0,0,0,0.08);
  --border-strong: rgba(0,0,0,0.16);
  --text: #1A1A1A;
  --text-muted: #5F5E5A;
  --text-faint: #888780;

  /* Semester palette — sequential temporal */
  --c-past:    #B4B2A9;
  --c-cur:     #185FA5;
  --c-nxt:     #BA7517;
  --c-fut:     #1D9E75;
  --c-imed:    #D3D1C7;

  /* Comparison lines — high contrast */
  --line-now:  #1A1A1A;
  --line-old:  #888780;

  --success: #3B6D11;
  --danger: #A32D2D;
  --radius: 8px;
  --radius-lg: 12px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  padding: 24px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
.container { max-width: 1280px; margin: 0 auto; }
h1 { font-size: 22px; font-weight: 500; margin: 0 0 4px; }
.subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 20px; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 0.5px solid var(--border); }
.tab {
  padding: 10px 16px; cursor: pointer; font-size: 13px; font-weight: 500;
  color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -0.5px;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--text); }

/* Filter bar */
.filters {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); font-weight: 500;
}
select, input[type="date"], input[type="text"] {
  width: 100%; padding: 7px 10px;
  background: var(--bg);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
}
select:hover, input[type="date"]:hover, input[type="text"]:hover { border-color: rgba(0,0,0,0.3); }
select:focus, input[type="date"]:focus, input[type="text"]:focus { outline: none; border-color: var(--c-cur); box-shadow: 0 0 0 2px rgba(24,95,165,0.15); }
.reset-btn {
  background: transparent;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  height: 33px;
}
.reset-btn:hover { background: var(--bg); border-color: rgba(0,0,0,0.3); }

/* KPI cards */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.kpi-label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.kpi-value { font-size: 24px; font-weight: 500; line-height: 1.1; }
.kpi-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.kpi-sub.up { color: var(--success); font-weight: 500; }
.kpi-sub.down { color: var(--danger); font-weight: 500; }

/* Charts */
.legend {
  display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 12px;
  font-size: 12px; color: var(--text-muted);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.swatch { width: 11px; height: 11px; border-radius: 2px; }
.line-sample { width: 22px; height: 0; border-top-width: 2.5px; border-top-style: solid; }

.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  margin-bottom: 14px;
}
.card h2 { font-size: 14px; font-weight: 500; margin: 0 0 4px; }
.card .hint { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }
.chart-wrap { position: relative; height: 320px; }
.chart-wrap-tall { position: relative; height: 380px; }

/* Two-col layout */
.two-col {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px;
}
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* Small multiples grid */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
@media (min-width: 1000px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.mini {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.mini-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.mini-title { font-size: 13px; font-weight: 500; }
.mini-vol { font-size: 10px; color: var(--text-faint); }
.mini-stats { display: flex; gap: 12px; font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.mini-stats .now { color: var(--text); font-weight: 500; }
.mini-stats .delta-up { color: var(--success); font-weight: 500; }
.mini-stats .delta-down { color: var(--danger); font-weight: 500; }
.mini-chart { position: relative; height: 140px; }

/* Composition table */
.comp-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.comp-table th, .comp-table td {
  padding: 8px 10px; text-align: right; border-bottom: 0.5px solid var(--border);
}
.comp-table th:first-child, .comp-table td:first-child { text-align: left; }
.comp-table th { font-weight: 500; color: var(--text-muted); text-transform: uppercase; font-size: 10px; letter-spacing: 0.04em; }
.comp-table tr.total { font-weight: 500; background: var(--bg); }
.comp-table tr.total td { border-bottom: none; }
.comp-table .swatch-cell { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }

/* Carteira table with inline bars */
.cart-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.cart-table th, .cart-table td {
  padding: 10px 12px; text-align: right; border-bottom: 0.5px solid var(--border); vertical-align: middle;
}
.cart-table th:first-child, .cart-table td:first-child { text-align: left; }
.cart-table th:nth-child(2), .cart-table td:nth-child(2) { text-align: left; }
.cart-table th { font-weight: 500; color: var(--text-muted); text-transform: uppercase; font-size: 10px; letter-spacing: 0.04em; }
.cart-table tbody tr { cursor: pointer; transition: background 0.1s; }
.cart-table tbody tr:hover { background: var(--bg); }
.cart-table tbody tr.active { background: rgba(24,95,165,0.08); }
.cart-table .name { font-weight: 500; color: var(--text); }
.bar-cell { width: 180px; }
.bar-track { position: relative; height: 16px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.bar-fill { position: absolute; top: 0; left: 0; height: 100%; }
.bar-fill.cur { background: #185FA5; }
.bar-fill.nxt { background: #BA7517; }
.bar-fill.imed { background: #D3D1C7; }
.bar-fill.bad { background: #888780; }
.delta-pos { color: var(--success); font-weight: 500; }
.delta-neg { color: var(--danger); font-weight: 500; }
.delta-zero { color: var(--text-faint); }
.pct-bar-track { position: relative; height: 6px; background: var(--bg); border-radius: 2px; overflow: hidden; margin-top: 4px; width: 100%; }
.pct-bar-fill { position: absolute; top: 0; left: 0; height: 100%; background: #1A1A1A; }
.pct-bar-fill-old { position: absolute; top: 0; height: 100%; width: 1.5px; background: #888780; }

.empty {
  text-align: center; padding: 40px 20px; color: var(--text-faint);
  background: var(--surface); border: 0.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  margin-bottom: 14px;
}
.error {
  border-color: rgba(163,45,45,0.4);
  color: var(--danger);
}
.footer-note {
  margin-top: 16px; padding: 10px 14px;
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: var(--radius); font-size: 12px; color: var(--text-muted);
}
.footer-note code { background: var(--bg); padding: 1px 5px; border-radius: 3px; font-size: 11px; }

/* Drilldown modal */
.drilldown-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px;
  overflow-y: auto;
}
.drilldown-content {
  background: var(--bg);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 1280px;
  padding: 20px 24px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.drilldown-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; margin-bottom: 16px; padding-bottom: 12px;
  border-bottom: 0.5px solid var(--border);
}
.drilldown-header h2 { font-size: 18px; font-weight: 500; margin: 0; }
.drilldown-header .dim-tag {
  display: inline-block; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-faint);
  background: var(--surface); padding: 2px 8px; border-radius: 3px;
  margin-right: 8px; vertical-align: middle;
}
.drilldown-actions { display: flex; gap: 8px; }
.btn-primary {
  background: var(--text); color: var(--surface);
  border: 0.5px solid var(--text);
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: 12px;
  cursor: pointer;
  font-weight: 500;
}
.btn-primary:hover { opacity: 0.85; }

/* Estratégica — listas ranqueadas, tabelas comparativas */
.rank-list { display: flex; flex-direction: column; gap: 6px; }
.rank-item {
  display: grid; grid-template-columns: 24px 1fr auto auto; gap: 10px;
  align-items: center; font-size: 13px;
  padding: 6px 4px; border-bottom: 0.5px solid var(--border);
}
.rank-item:last-child { border-bottom: none; }
.rank-pos { color: var(--text-faint); font-size: 11px; font-weight: 500; }
.rank-name { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-bar-wrap { position: relative; height: 14px; background: var(--bg); border-radius: 3px; overflow: hidden; min-width: 80px; }
.rank-bar-fill { position: absolute; top: 0; left: 0; height: 100%; background: var(--c-cur); }
.rank-volume { font-variant-numeric: tabular-nums; color: var(--text); font-size: 12px; }
.rank-delta { font-size: 11px; font-variant-numeric: tabular-nums; min-width: 60px; text-align: right; }
.rank-delta.up { color: var(--success); font-weight: 500; }
.rank-delta.down { color: var(--danger); font-weight: 500; }
.rank-delta.neutral { color: var(--text-faint); }

.list-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
@media (max-width: 900px) { .list-pair { grid-template-columns: 1fr; } }

.concentration-cards {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px;
}
@media (max-width: 700px) { .concentration-cards { grid-template-columns: repeat(2, 1fr); } }
.conc-card {
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.conc-label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.conc-value { font-size: 22px; font-weight: 500; line-height: 1.1; margin-top: 4px; }
.conc-sub { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

/* Waterfall details — top IES por categoria abaixo do chart */
.waterfall-details { margin-top: 16px; padding-top: 14px; border-top: 0.5px dashed var(--border); }
.waterfall-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
}
@media (max-width: 900px) { .waterfall-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .waterfall-grid { grid-template-columns: 1fr; } }
.waterfall-section h4 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); margin: 0 0 8px; font-weight: 500;
}
.waterfall-list { list-style: none; padding: 0; margin: 0; font-size: 12px; }
.waterfall-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 0; border-bottom: 0.5px solid var(--border);
}
.waterfall-list li:last-child { border-bottom: none; }
.waterfall-name {
  color: var(--text); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-right: 8px;
}
.waterfall-value {
  font-variant-numeric: tabular-nums; color: var(--text-muted);
  font-size: 11px; white-space: nowrap;
}

/* Movers & Anomalies — tabela compacta */
.movers-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.movers-table th, .movers-table td {
  padding: 8px 10px; text-align: right; border-bottom: 0.5px solid var(--border);
  vertical-align: middle;
}
.movers-table th:first-child, .movers-table td:first-child,
.movers-table th:nth-child(2), .movers-table td:nth-child(2) { text-align: left; }
.movers-table th {
  font-weight: 500; color: var(--text-muted);
  text-transform: uppercase; font-size: 10px; letter-spacing: 0.04em;
}
.movers-name { font-weight: 500; color: var(--text); margin-bottom: 3px; }
.movers-bar { width: 100%; height: 4px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.movers-bar-fill { height: 100%; }

.anomaly-severe td { background: rgba(163, 45, 45, 0.05); }
.anomaly-moderate td { background: rgba(186, 117, 23, 0.04); }
