/* Identidade AVAL — terminal de dados: dark padrão, dourado como acento. */
:root {
  --gold: #C9A24A;
  --gold-hover: #E2BE63;
  --up: #3FB950;
  --down: #F85149;
  --neutral: #8B949E;

  --bg: #0E1117;
  --panel: #161B22;
  --panel2: #1B2230;
  --border: #30363D;
  --text: #E6EDF3;
  --label: #8B949E;
}
body.light {
  --bg: #F5F7FA;
  --panel: #FFFFFF;
  --panel2: #EEF1F5;
  --border: #DDE3EA;
  --text: #0E1117;
  --label: #51607A;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}
h1, h2, h3, .brand-title { font-family: 'Space Grotesk', sans-serif; letter-spacing: -0.02em; }
a { color: var(--gold); }

/* ---------- sidebar ---------- */
#sidebar {
  width: 290px;
  min-width: 290px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1.1rem 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: 100vh;
  overflow-y: auto;
  position: sticky;
  top: 0;
}
.brand-title { font-size: 1.05rem; font-weight: 700; }
.brand-sub { color: var(--label); font-size: 0.78rem; margin-top: 0.25rem; line-height: 1.35; }

#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a {
  color: var(--text);
  text-decoration: none;
  font-size: 0.88rem;
  padding: 0.42rem 0.6rem;
  border-radius: 8px;
}
#nav a:hover { background: var(--panel2); }
#nav a.active { background: var(--panel2); color: var(--gold); font-weight: 600; }

.filters { border-top: 1px solid var(--border); padding-top: 0.9rem; display: flex; flex-direction: column; gap: 0.45rem; }
.filters-title { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--label); font-weight: 600; }
.f-label { font-size: 0.75rem; color: var(--label); margin-top: 0.35rem; }
.filters input[type="search"], .filters input[type="number"], .filters select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.42rem 0.55rem;
  font-family: 'Inter', sans-serif;
  font-size: 0.84rem;
}
.filters input:focus, .filters select:focus { outline: 1px solid var(--gold); }
.f-check { display: flex; gap: 0.45rem; align-items: center; font-size: 0.84rem; margin-top: 0.3rem; cursor: pointer; }
.range-pair { display: flex; gap: 0.4rem; }

.chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.18rem 0.6rem;
  font-size: 0.74rem;
  cursor: pointer;
  color: var(--label);
  user-select: none;
}
.chip.on { border-color: var(--gold); color: var(--gold); background: color-mix(in srgb, var(--gold) 12%, transparent); }

.btn-ghost {
  margin-top: 0.6rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--label);
  border-radius: 8px;
  padding: 0.4rem;
  cursor: pointer;
  font-size: 0.8rem;
}
.btn-ghost:hover { border-color: var(--gold); color: var(--gold); }

.active-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.5rem; }
.active-chips .chip { border-color: var(--gold); color: var(--gold); }
.active-chips .chip::after { content: " ✕"; }

.side-footer { margin-top: auto; border-top: 1px solid var(--border); padding-top: 0.8rem; }
.meta-info { color: var(--label); font-size: 0.72rem; margin-top: 0.5rem; line-height: 1.4; }

/* ---------- main ---------- */
#main { flex: 1; padding: 1.4rem 1.8rem 3rem; min-width: 0; }
.hero {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.2rem 1.5rem;
  background: linear-gradient(135deg, var(--panel), var(--panel2));
  margin-bottom: 1.1rem;
}
.hero h1 { margin: 0; font-size: 1.45rem; }
.hero p { margin: 0.35rem 0 0; color: var(--label); font-size: 0.9rem; max-width: 70rem; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.7rem; margin-bottom: 1.1rem; }
.kpi {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  padding: 0.75rem 0.95rem;
}
.kpi .k-label { color: var(--label); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi .k-value { font-family: 'IBM Plex Mono', monospace; font-size: 1.35rem; font-weight: 600; margin-top: 0.15rem; }
.kpi .k-sub { font-size: 0.76rem; color: var(--neutral); margin-top: 0.15rem; }
.kpi .k-sub.up { color: var(--up); }
.kpi .k-sub.down { color: var(--down); }

.grid2 { display: grid; grid-template-columns: 3fr 2fr; gap: 1rem; margin-bottom: 1rem; }
.grid2-eq { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
@media (max-width: 1100px) { .grid2, .grid2-eq { grid-template-columns: 1fr; } }

.card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  padding: 0.9rem 1rem;
  min-width: 0;
}
.card h3 { margin: 0 0 0.6rem; font-size: 0.98rem; }
.card .hint { color: var(--label); font-size: 0.76rem; margin: -0.35rem 0 0.6rem; }

.chart { width: 100%; height: 380px; }
.chart.tall { height: 560px; }
.chart.short { height: 300px; }

.note {
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: 10px;
  background: var(--panel);
  padding: 0.8rem 1rem;
  font-size: 0.85rem;
  color: var(--text);
  margin: 1rem 0;
  line-height: 1.5;
}
.note.alert { border-left-color: var(--down); }

.fonte { color: var(--label); font-size: 0.75rem; border-top: 1px solid var(--border); padding-top: 0.5rem; margin-top: 0.8rem; }

.toolbar { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.7rem; }
.toolbar select, .toolbar input {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 0.35rem 0.55rem; font-size: 0.82rem; font-family: 'Inter', sans-serif;
}
.btn {
  background: transparent; border: 1px solid var(--gold); color: var(--gold);
  border-radius: 8px; padding: 0.35rem 0.8rem; font-size: 0.8rem; cursor: pointer;
}
.btn:hover { background: color-mix(in srgb, var(--gold) 14%, transparent); }

/* Tabulator adjustments (tema base midnight, ajustado às cores AVAL) */
.tabulator { background: var(--panel) !important; border: 1px solid var(--border) !important; border-radius: 10px; font-size: 0.82rem; }
.tabulator .tabulator-header { background: var(--panel2) !important; border-bottom: 1px solid var(--border) !important; }
.tabulator .tabulator-header .tabulator-col { background: var(--panel2) !important; color: var(--label) !important; }
.tabulator .tabulator-row { background: var(--panel) !important; color: var(--text) !important; border-bottom: 1px solid var(--border) !important; }
.tabulator .tabulator-row:hover { background: var(--panel2) !important; }
.tabulator .tabulator-footer { background: var(--panel2) !important; border-top: 1px solid var(--border) !important; color: var(--label) !important; }
.tabulator .tabulator-cell { border-right: none !important; }
body.light .tabulator .tabulator-row { color: #0E1117 !important; }

.mono { font-family: 'IBM Plex Mono', monospace; }
.tag { display: inline-block; padding: 0.05rem 0.5rem; border-radius: 999px; font-size: 0.72rem; border: 1px solid var(--border); color: var(--label); }
.tag.gold { border-color: var(--gold); color: var(--gold); }

.metodologia h2 { font-size: 1.15rem; margin-top: 1.6rem; }
.metodologia p, .metodologia li { font-size: 0.9rem; line-height: 1.6; }
.metodologia code { background: var(--panel2); border-radius: 5px; padding: 0.05rem 0.35rem; font-size: 0.82rem; }

/* ---------- autocomplete (lista com busca) ---------- */
.ac-box {
  display: none; position: absolute; z-index: 40; top: calc(100% + 4px); left: 0;
  min-width: 100%; width: max-content; max-width: 420px; max-height: 340px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0,0,0,.35);
}
.ac-item { padding: .48rem .7rem; cursor: pointer; font-size: .84rem; display: flex; flex-direction: column; gap: 1px; }
.ac-item:hover { background: var(--panel2); }
.ac-item b { font-weight: 600; }
.ac-item span { color: var(--label); font-size: .74rem; font-family: 'IBM Plex Mono', monospace; }
.toolbar input[type="search"] {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: .38rem .6rem; font-size: .84rem; font-family: 'Inter', sans-serif;
}
.toolbar input[type="search"]:focus { outline: 1px solid var(--gold); }
.f-hint { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--label); }

/* ---------- refinamentos do tema claro ---------- */
body.light .tabulator .tabulator-header .tabulator-col { color: #51607A !important; }
body.light .tabulator .tabulator-footer { color: #51607A !important; }
body.light .hero { background: linear-gradient(135deg, var(--panel), var(--panel2)); }
body.light .ac-box { box-shadow: 0 10px 28px rgba(15,23,42,.16); }
body.light .kpi .k-sub { color: #64748B; }
body.light #nav a.active { color: #8a6d24; }
body.light a { color: #8a6d24; }
body.light .btn, body.light .lock { color: #8a6d24; border-color: #C9A24A; }
body.light .tag.gold { color: #8a6d24; }

/* ---------- interatividade tabela→gráfico ---------- */
.tabulator .tabulator-row { cursor: pointer; transition: background .12s ease; }
.tabulator .tabulator-row.sel {
  background: color-mix(in srgb, var(--gold) 16%, var(--panel)) !important;
  box-shadow: inset 3px 0 0 var(--gold);
}
.chip-voltar {
  background: transparent; border: 1px solid var(--gold); color: var(--gold);
  border-radius: 999px; padding: .12rem .7rem; font-size: .74rem; cursor: pointer;
  font-family: 'Inter', sans-serif;
}
.chip-voltar:hover { background: color-mix(in srgb, var(--gold) 14%, transparent); }
.card { transition: border-color .15s ease; }
.card:hover { border-color: color-mix(in srgb, var(--gold) 35%, var(--border)); }
.kpi { transition: transform .12s ease, border-color .15s ease; }
.kpi:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--gold) 30%, var(--border)); }

/* ---------- responsivo ---------- */
@media (max-width: 900px) {
  body { flex-direction: column; }
  #sidebar { width: 100%; min-width: 0; height: auto; position: static; border-right: 0;
             border-bottom: 1px solid var(--border); padding: .7rem 1rem .5rem; }
  /* compacto: nav em linha rolável, sem sub-título/rodapé — o conteúdo sobe */
  .brand-sub, .side-footer { display: none; }
  #nav { flex-direction: row; flex-wrap: nowrap; overflow-x: auto;
         -webkit-overflow-scrolling: touch; gap: .15rem; padding-bottom: .3rem;
         scrollbar-width: none; }
  #nav::-webkit-scrollbar { display: none; }
  #nav a { white-space: nowrap; flex: 0 0 auto; }
  .filters { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem .6rem;
             align-items: end; margin-top: .4rem; }
  .filters-title, .f-hint { display: none; }
  .filters label[for="f-busca"], #f-busca { grid-column: 1 / -1; }
  #main { padding: 1rem; }
  .grid2, .grid2-eq { grid-template-columns: 1fr; }
  .chart { height: 300px; }
}
@media (max-width: 560px) {
  .hero { padding: .9rem 1rem; }
  .hero h1 { font-size: 1.15rem; }
  .hero p { font-size: .82rem; }
  .kpis { grid-template-columns: 1fr 1fr; gap: .5rem; }
  .kpi .k-value { font-size: 1.05rem; }
  .chart { height: 260px; }
  .chart.tall { height: 380px; }
  .tb-chip { max-width: 130px; }
  .tb-brand .logo-word, .tb-brand span { display: none; }  /* só o ícone Λ + "Institucional" */
  .auth-wrap { padding: 1.5rem .6rem; }
  .toolbar input, .toolbar select { min-width: 0 !important; width: 100%; }
  .toolbar { display: flex; flex-direction: column; align-items: stretch; }
}
@media (prefers-reduced-motion: reduce) {
  .kpi, .card, .tabulator .tabulator-row { transition: none; }
}

/* ---------- filtros nos cabeçalhos (Tabulator headerFilter) ---------- */
.tabulator .tabulator-header-filter input {
  background: var(--bg) !important; border: 1px solid var(--border) !important;
  color: var(--text) !important; border-radius: 6px !important;
  padding: 2px 6px !important; font-size: .76rem !important; font-family: 'Inter', sans-serif;
}
.tabulator .tabulator-header-filter input:focus { outline: 1px solid var(--gold) !important; }
.tabulator .tabulator-header .tabulator-col { vertical-align: bottom; }

.cel-pct { color: var(--label); font-size: .72rem; }

.star { cursor: pointer; font-size: 1rem; color: var(--label); transition: transform .1s; }
.star:hover { transform: scale(1.3); color: var(--gold); }
.star.on { color: var(--gold); }

/* ---------- autenticação ---------- */
.auth-wrap { display: flex; justify-content: center; padding: 3rem 1rem; }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 1.6rem 1.7rem; display: flex; flex-direction: column; gap: .55rem; }
.auth-logo { font-family: 'Space Grotesk', sans-serif; font-weight: 700; color: var(--gold); }
.auth-logo span { color: var(--label); margin: 0 .3rem; }
.auth-card h2 { margin: .2rem 0 .4rem; font-size: 1.25rem; }
.auth-card input { background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: .55rem .7rem; font-size: .9rem; font-family: 'Inter', sans-serif; }
.auth-card input:focus { outline: 1px solid var(--gold); }
.auth-card input.invalido { border-color: var(--down); }
.auth-hint { font-size: .72rem; color: var(--label); min-height: .9rem; }
.forca { height: 4px; background: var(--panel2); border-radius: 2px; margin-top: 3px; }
.forca i { display: block; height: 100%; border-radius: 2px; transition: width .2s; }
.auth-btn { margin-top: .3rem; background: var(--gold); color: #0E1117; border: 0; border-radius: 8px;
  padding: .6rem; font-weight: 600; font-size: .9rem; cursor: pointer; font-family: 'Inter', sans-serif; }
.auth-btn:disabled { opacity: .6; cursor: wait; }
.auth-btn.social { background: transparent; color: var(--text); border: 1px solid var(--border); font-weight: 500; }
.auth-btn.social:hover { border-color: var(--gold); }
.aval-spin { display: inline-block; color: #0E1117; animation: avalgira 1s linear infinite; }
@keyframes avalgira { from { transform: rotate(0) } to { transform: rotate(360deg) } }
.auth-sep { display: flex; align-items: center; gap: .6rem; color: var(--label); font-size: .72rem; }
.auth-sep::before, .auth-sep::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.auth-erro { color: var(--down); font-size: .8rem; min-height: 1rem; }
.auth-ok { color: var(--up); font-size: .8rem; }
.auth-troca { font-size: .8rem; color: var(--label); text-align: center; margin-top: .3rem; }

#nav a.trancado { opacity: .75; }
.cadeado { font-size: .7rem; }

/* ---------- cabeçalho ---------- */
#conteudo { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center;
  justify-content: space-between; gap: 1rem; padding: .55rem 1.8rem;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border-bottom: 1px solid var(--border); backdrop-filter: blur(6px); }
.tb-brand { font-family: 'Space Grotesk', sans-serif; font-size: .95rem; color: var(--text);
  text-decoration: none; letter-spacing: .02em; }
.tb-brand b { color: var(--gold); } .tb-brand span { color: var(--label); margin: 0 .3rem; }
.tb-right { display: flex; align-items: center; gap: .5rem; }
.tb-icone { background: transparent; border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: .3rem .55rem; cursor: pointer; font-size: .85rem; }
.tb-icone:hover { border-color: var(--gold); }
.tb-user { position: relative; }
.tb-chip { background: transparent; border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: .32rem .8rem; cursor: pointer; font-size: .8rem;
  font-family: 'Inter', sans-serif; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-chip:hover { border-color: var(--gold); color: var(--gold); }
.tb-menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; z-index: 40;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0,0,0,.35); padding: .4rem; display: flex; flex-direction: column; gap: .2rem; }
.tb-menu-email { font-size: .75rem; color: var(--label); padding: .35rem .6rem;
  border-bottom: 1px solid var(--border); font-family: 'IBM Plex Mono', monospace;
  overflow: hidden; text-overflow: ellipsis; }
.tb-menu button { background: transparent; border: 0; color: var(--text); text-align: left;
  padding: .45rem .6rem; border-radius: 6px; cursor: pointer; font-size: .84rem; font-family: 'Inter', sans-serif; }
.tb-menu button:hover { background: var(--panel2); }
#main { padding-top: 1.1rem; }
@media (max-width: 900px) { #topbar { padding: .5rem 1rem; } }

/* ---------- logo oficial ---------- */
.tb-brand { display: flex; align-items: center; gap: .1rem; }
.tb-brand img { height: 26px; display: block; }
.brand-icone { height: 20px; vertical-align: -4px; margin-right: .25rem; }
.auth-logo { display: flex; align-items: center; gap: .1rem; color: var(--label); font-weight: 500; }
.auth-logo img { height: 30px; }
.logo-light { display: none; }
body.light .logo-light { display: inline-block; }
body.light .logo-dark { display: none; }

.logo-ico { height: 22px; width: 22px; margin-right: .35rem; }
.logo-word { font-family: 'Space Grotesk', sans-serif; font-weight: 600; color: var(--text);
  font-size: 1.05rem; letter-spacing: .01em; }
.tb-brand span, .auth-logo span { color: var(--gold); margin: 0 .35rem; font-weight: 700; }
.auth-logo { font-family: 'Space Grotesk', sans-serif; }
.logo-light { display: none !important; }
.logo-dark { display: inline-block !important; }
body.light .logo-light { display: inline-block !important; }
body.light .logo-dark { display: none !important; }
