:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --borda: #e2e1dc;
  --texto: #0b0b0b;
  --texto-2: #52514e;
  --texto-3: #7a7974;
  --pri: #2a78d6;
  --pri-texto: #ffffff;
  --pos: #0f7a3d;
  --neg: #c23b3a;
  --barra-total: #52514e;
  --barra-neg: #e34948;
  --barra-pos: #2a78d6;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --raio: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --borda: #34342f;
    --texto: #ffffff;
    --texto-2: #c3c2b7;
    --texto-3: #8f8e86;
    --pri: #3987e5;
    --pos: #3ccf7a;
    --neg: #ff7b7a;
    --barra-total: #8f8e86;
    --barra-neg: #e66767;
    --barra-pos: #3987e5;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --borda: #34342f;
  --texto: #ffffff; --texto-2: #c3c2b7; --texto-3: #8f8e86; --pri: #3987e5;
  --pos: #3ccf7a; --neg: #ff7b7a; --barra-total: #8f8e86; --barra-neg: #e66767; --barra-pos: #3987e5;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--texto);
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-feature-settings: "tnum" 1;
}
h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 2px; font-weight: 600; }
.muted { color: var(--texto-2); }
.pequeno { font-size: 12px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* topo */
.topo {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 16px 24px; background: var(--surface); border-bottom: 1px solid var(--borda);
  position: sticky; top: 0; z-index: 5;
}
.topo-esq { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.topo-dir { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sel-mes { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--texto-2); }

select, input[type=text], input[type=number], input[type=password], input[type=month] {
  font: inherit; color: var(--texto); background: var(--surface);
  border: 1px solid var(--borda); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
select:focus, input:focus { outline: 2px solid var(--pri); outline-offset: -1px; }

.btn {
  font: inherit; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--borda);
  background: var(--surface); color: var(--texto); text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-pri { background: var(--pri); border-color: var(--pri); color: var(--pri-texto); }
.btn-pri:hover { background: var(--pri); filter: brightness(1.08); }
.btn-fantasma { border-color: transparent; color: var(--texto-2); }
.btn-perigo { color: var(--neg); }
.btn-x { border: 0; background: none; color: var(--texto-3); cursor: pointer; font-size: 16px; padding: 4px 8px; border-radius: 6px; }
.btn-x:hover { color: var(--neg); background: var(--surface-2); }

/* abas */
.abas { display: flex; gap: 4px; padding: 12px 24px 0; overflow-x: auto; }
.aba {
  font: inherit; font-weight: 500; cursor: pointer; padding: 8px 14px; border: 0; border-radius: 8px 8px 0 0;
  background: transparent; color: var(--texto-2); border-bottom: 2px solid transparent; white-space: nowrap;
}
.aba.ativa { color: var(--texto); border-bottom-color: var(--pri); }

main#app { padding: 16px 24px 48px; max-width: 1400px; margin: 0 auto; display: grid; gap: 16px; }
.aba-conteudo { display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--borda); border-radius: var(--raio); padding: 16px 18px; min-width: 0; }
.card-topo { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.grade-2 { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; }
.grafico { position: relative; height: 260px; margin-top: 12px; }
.grafico.alto { height: 340px; }
.vazio { text-align: center; padding: 48px 16px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--borda); border-radius: var(--raio); padding: 14px 16px; min-width: 0; }
.kpi .rot { font-size: 12px; color: var(--texto-2); }
.kpi .val { font-size: 21px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .sub { font-size: 12px; color: var(--texto-2); margin-top: 2px; }
.kpi.destaque { border-color: var(--pri); }

/* tabelas */
.tabela-wrap { overflow-x: auto; margin-top: 10px; }
.tabela { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabela th { text-align: left; font-weight: 500; color: var(--texto-2); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--borda); white-space: nowrap; }
.tabela td { padding: 7px 10px; border-bottom: 1px solid var(--borda); white-space: nowrap; }
.tabela .num { text-align: right; }
.tabela tfoot td { font-weight: 600; border-bottom: 0; border-top: 2px solid var(--borda); }
.tabela tr:hover td { background: var(--surface-2); }
.tabela.editavel input[type=text] { width: 100%; min-width: 160px; }
.tabela.editavel input.valor { width: 130px; text-align: right; }
.tabela.editavel select { min-width: 170px; }
.ponto { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; vertical-align: -1px; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--surface-2); color: var(--texto-2); }
.tag.manual { color: var(--pri); }
.nome-centro { cursor: text; border-bottom: 1px dashed transparent; }
.nome-centro:hover { border-bottom-color: var(--texto-3); }

details.det { margin-top: 12px; border-top: 1px solid var(--borda); padding-top: 10px; }
details.det summary { cursor: pointer; color: var(--texto-2); font-size: 13px; }
.det-grade { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 10px; }
.det-grade h3 { font-size: 13px; margin: 0 0 4px; }
.det-grade table td { padding: 3px 6px; font-size: 12px; }

.acoes-perigo { display: flex; justify-content: flex-end; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 12px; }
.erro { color: var(--neg); margin: 0; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--texto); color: var(--surface); padding: 10px 16px; border-radius: 8px;
  font-size: 13px; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.2);
}

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grade-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topo, .abas, main#app { padding-left: 16px; padding-right: 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .val { font-size: 18px; }
}
[hidden] { display: none !important; }

/* ponto de equilíbrio */
.grade-igual { grid-template-columns: 1fr 1fr; }
.pe-num { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 14px; }
.pe-linhas { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.pe-linhas .rot { font-size: 12px; color: var(--texto-2); }
.pe-linhas .val { font-size: 15px; font-weight: 600; margin-top: 2px; }
.pe-barra { position: relative; height: 14px; border-radius: 99px; background: var(--surface-2); margin: 34px 0 30px; }
.pe-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; background: var(--barra-pos); }
.pe-fill.abaixo { background: var(--barra-neg); }
.pe-marca { position: absolute; top: -8px; bottom: -8px; width: 2px; background: var(--texto); }
.pe-marca span, .pe-fat span { position: absolute; font-size: 11px; white-space: nowrap; color: var(--texto-2); transform: translateX(-50%); }
.pe-marca span { top: -18px; left: 1px; }
.pe-fat { position: absolute; top: 22px; }
.pe-fat span { top: 0; }
.pe-msg { font-size: 13px; margin: 0; }
@media (max-width: 1100px) { .grade-igual { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .pe-linhas { grid-template-columns: 1fr 1fr; } }
