/* =====================================================================
   Componentes: botões, formulários, KPIs, tabela, modal, avisos, etc.
   ===================================================================== */

/* ------------------------------------------------ botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: var(--r-s);
  background: var(--surface); color: var(--ink);
  font-weight: 500; font-size: 13.5px; white-space: nowrap;
  cursor: pointer; text-decoration: none !important;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.primario { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primario:hover { background: var(--teal-600); border-color: var(--teal-600); }
:root[data-theme="escuro"] .btn.primario { color: #062326; }
.btn.azul { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.azul:hover { background: var(--blue-600); }
.btn.perigo { background: var(--err); border-color: var(--err); color: #fff; }
.btn.perigo-sutil { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--line)); }
.btn.perigo-sutil:hover { background: var(--err-50); }
.btn.fantasma { border-color: transparent; background: none; color: var(--ink-2); }
.btn.fantasma:hover { background: var(--surface-3); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn .spin { display: none; }
.btn.carregando .spin { display: inline-block; }
.btn.carregando svg.i:not(.spin) { display: none; }

.spin { width: 15px; height: 15px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: girar .7s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }

/* ------------------------------------------------ formulários */
.campo { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.campo > label { font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.campo > label .obr { color: var(--err); }
.campo .ajuda { font-size: 12px; color: var(--muted); }
.entrada, .campo input[type="text"], .campo input[type="password"], .campo input[type="number"], .campo input[type="search"],
.campo input[type="date"], .campo input[type="time"], .campo input[type="email"], .campo select, .campo textarea {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-s);
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
}
.campo textarea { height: auto; min-height: 80px; padding: 8px 10px; resize: vertical; }
.campo input:focus, .campo select:focus, .campo textarea:focus, .entrada:focus {
  outline: none; border-color: var(--teal); box-shadow: var(--focus);
}
.campo.erro input, .campo.erro select { border-color: var(--err); }

.grade-campos { display: grid; gap: 12px 14px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.grade-campos .largo { grid-column: span 2; }
.grade-campos .inteiro { grid-column: 1 / -1; }
@media (max-width: 560px) { .grade-campos .largo { grid-column: 1 / -1; } }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.check input { width: 16px; height: 16px; accent-color: var(--teal); }

/* seleção múltipla com busca */
.multi { position: relative; }
.multi-botao {
  width: 100%; height: 36px; padding: 0 30px 0 10px;
  display: flex; align-items: center;
  border: 1px solid var(--line-strong); border-radius: var(--r-s);
  background: var(--surface); text-align: left; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 13.5px;
}
.multi-botao::after { content: ""; position: absolute; right: 12px; top: 15px; border: 5px solid transparent; border-top-color: var(--muted); }
.multi-botao .vazio { color: var(--faint); }
.multi-painel {
  position: absolute; z-index: 50; left: 0; right: 0; top: calc(100% + 4px);
  min-width: 260px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m);
  box-shadow: var(--shadow-2);
  display: none;
}
.multi.aberto .multi-painel { display: block; }
.multi-painel input { width: calc(100% - 16px); margin: 8px; height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: var(--r-s); background: var(--surface-2); }
.multi-lista { max-height: 260px; overflow: auto; padding: 0 4px 6px; }
.multi-lista label { display: flex; gap: 8px; align-items: flex-start; padding: 6px 8px; border-radius: var(--r-s); cursor: pointer; font-size: 13px; }
.multi-lista label:hover { background: var(--surface-3); }
.multi-lista input { margin-top: 2px; accent-color: var(--teal); }
.multi-rodape { display: flex; justify-content: space-between; padding: 6px 8px; border-top: 1px solid var(--line); }

/* ------------------------------------------------ painéis */
.painel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  box-shadow: var(--shadow-1);
}
.painel + .painel { margin-top: 16px; }
.painel-cab {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.painel-cab h2 { font-size: 15px; }
.painel-cab .acoes { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.painel-corpo { padding: 16px; }

.filtros { padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); border-radius: var(--r-m) var(--r-m) 0 0; }
.filtros .barra-acoes { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-top: 12px; }
.filtros .barra-acoes .espaco { flex: 1; }

/* ------------------------------------------------ indicadores (faixa única dividida) */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  border-bottom: 1px solid var(--line);
}
.kpi { padding: 14px 16px; border-right: 1px solid var(--line); min-width: 0; }
.kpi:last-child { border-right: 0; }
.kpi .rot { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .rot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--kpi-cor, var(--teal)); }
.kpi .val { font-size: 22px; font-weight: 600; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.clicavel { cursor: pointer; }
.kpi.clicavel:hover { background: var(--surface-2); }
.kpi.sel { background: var(--teal-50); }

/* ------------------------------------------------ tabela */
.tabela-barra {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.tabela-barra .busca { position: relative; flex: 1 1 220px; max-width: 360px; }
.tabela-barra .busca input { width: 100%; height: 34px; padding: 0 10px 0 32px; border: 1px solid var(--line-strong); border-radius: var(--r-s); background: var(--surface); }
.tabela-barra .busca svg { position: absolute; left: 9px; top: 8px; color: var(--faint); }
.tabela-barra .info { color: var(--muted); font-size: 12.5px; }
.tabela-barra .acoes { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.tabela-wrap { overflow: auto; max-height: calc(100vh - 260px); min-height: 160px; }
.tabela-wrap.livre { max-height: none; }
table.grade { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.grade th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2);
  color: var(--ink-2);
  font-family: var(--font-cond);
  font-weight: 600; font-size: 12.5px; text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap; user-select: none;
}
.grade th.ord { cursor: pointer; }
.grade th.ord:hover { color: var(--ink); }
.grade th .seta-ord { opacity: .35; margin-left: 4px; font-size: 10px; }
.grade th[aria-sort] .seta-ord { opacity: 1; color: var(--teal); }
.grade th.num, .grade td.num { text-align: right; }
.grade td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  max-width: 420px;
}
.grade td.trunc { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 320px; }
.grade tbody tr:hover td { background: var(--surface-2); }
.grade tbody tr.sel td { background: var(--teal-50); }
.grade tfoot td { position: sticky; bottom: 0; background: var(--surface-2); font-weight: 600; border-top: 1px solid var(--line-strong); border-bottom: 0; }
.grade td.chk, .grade th.chk { width: 36px; text-align: center; }
.grade input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--teal); }
.grade .cel-input { width: 100%; min-width: 110px; height: 30px; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: var(--r-s); background: var(--surface); }
.grade .filtro-col th { top: 37px; padding: 4px 6px; background: var(--surface); }
.grade .filtro-col input { width: 100%; min-width: 60px; height: 26px; padding: 0 6px; border: 1px solid var(--line); border-radius: 4px; font: 12px var(--font); background: var(--surface-2); }
.link-cel { color: var(--blue); cursor: pointer; background: none; border: 0; padding: 0; font: inherit; text-align: left; }
.link-cel:hover { text-decoration: underline; }

.paginacao { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.paginacao .espaco { flex: 1; }
.paginacao select { height: 30px; border: 1px solid var(--line-strong); border-radius: var(--r-s); background: var(--surface); padding: 0 6px; }

/* cartões no celular: cada linha vira um bloco */
@media (max-width: 720px) {
  .grade.responsiva thead { display: none; }
  .grade.responsiva tbody tr { display: block; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .grade.responsiva tbody td { display: flex; gap: 10px; justify-content: space-between; border: 0; padding: 3px 0; max-width: none; text-align: right; white-space: normal; }
  .grade.responsiva tbody td::before { content: attr(data-rot); color: var(--muted); font-size: 12px; text-align: left; flex: 0 0 42%; }
  .grade.responsiva tbody td.chk { justify-content: flex-start; }
  .grade.responsiva tbody td.chk::before { content: none; }
  .grade.responsiva tbody tr:hover td { background: none; }
  .grade.responsiva tfoot { display: none; }
  .tabela-wrap { max-height: none; }
}

/* ------------------------------------------------ selos */
.selo {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--surface-3); color: var(--ink-2);
}
.selo.ok { background: var(--ok-50); color: var(--ok); }
.selo.aviso { background: var(--warn-50); color: var(--warn); }
.selo.erro { background: var(--err-50); color: var(--err); }
.selo.info { background: var(--blue-50); color: var(--blue); }
.selo.teal { background: var(--teal-50); color: var(--teal-600); }
.selo.ponto::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* antes -> depois */
.diff { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.diff .antes { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--err) 60%, transparent); }
.diff .depois { color: var(--ink); font-weight: 600; }
.diff .seta { color: var(--faint); }
.diff .var { font-size: 12px; padding: 1px 6px; border-radius: 999px; }
.diff .var.sobe { color: var(--err); background: var(--err-50); }
.diff .var.desce { color: var(--ok); background: var(--ok-50); }

/* ------------------------------------------------ avisos */
.alerta { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--r-m); border: 1px solid; font-size: 13.5px; }
.alerta svg { margin-top: 1px; }
.alerta.info { background: var(--blue-50); border-color: color-mix(in srgb, var(--blue) 30%, transparent); color: var(--ink); }
.alerta.aviso { background: var(--warn-50); border-color: color-mix(in srgb, var(--warn) 35%, transparent); color: var(--ink); }
.alerta.erro { background: var(--err-50); border-color: color-mix(in srgb, var(--err) 35%, transparent); color: var(--ink); }
.alerta.ok { background: var(--ok-50); border-color: color-mix(in srgb, var(--ok) 35%, transparent); color: var(--ink); }
.alerta p:last-child { margin: 0; }

.vazio {
  padding: 48px 20px; text-align: center; color: var(--muted);
}
.vazio .ilustra { width: 54px; height: 54px; margin: 0 auto 12px; color: var(--line-strong); }
.vazio h3 { color: var(--ink-2); margin-bottom: 6px; }

.esqueleto { height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: brilho 1.2s infinite; }
@keyframes brilho { to { background-position: -200% 0; } }

/* ------------------------------------------------ toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--teal);
  border-radius: var(--r-m); box-shadow: var(--shadow-2);
  font-size: 13.5px;
  animation: entrar .2s ease-out;
}
.toast.erro { border-left-color: var(--err); }
.toast.aviso { border-left-color: var(--warn); }
.toast.ok { border-left-color: var(--ok); }
.toast button { margin-left: auto; border: 0; background: none; color: var(--muted); cursor: pointer; }
@keyframes entrar { from { transform: translateY(8px); opacity: 0; } }

/* ------------------------------------------------ modal */
.modal-fundo {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(8, 18, 28, .5);
  animation: aparecer .15s ease-out;
}
@keyframes aparecer { from { opacity: 0; } }
.modal {
  width: min(560px, 100%);
  max-height: calc(100vh - 32px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-3);
  border: 1px solid var(--line);
}
.modal.grande { width: min(1100px, 100%); }
.modal.medio { width: min(780px, 100%); }
.modal-cab { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-cab h2 { font-size: 16px; }
.modal-cab .btn-icone { margin-left: auto; }
.modal-corpo { padding: 18px 20px; overflow: auto; }
.modal-corpo.sem-pad { padding: 0; }
.modal-rodape { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-l) var(--r-l); }
@media (max-width: 640px) {
  .modal-fundo { padding: 0; place-items: end stretch; }
  .modal, .modal.grande, .modal.medio { width: 100%; max-height: 92vh; border-radius: var(--r-l) var(--r-l) 0 0; }
}

/* ------------------------------------------------ abas */
.abas { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 12px; overflow-x: auto; }
.abas button {
  padding: 10px 14px; border: 0; background: none; cursor: pointer;
  color: var(--muted); font-weight: 500; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.abas button:hover { color: var(--ink); }
.abas button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--teal); }
.abas .cont { margin-left: 6px; font-size: 11.5px; padding: 1px 6px; border-radius: 999px; background: var(--surface-3); color: var(--ink-2); }

/* ------------------------------------------------ área de envio de arquivo */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 28px 16px;
  border: 1.5px dashed var(--line-strong); border-radius: var(--r-m);
  background: var(--surface-2);
  text-align: center; color: var(--muted); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.sobre { border-color: var(--teal); background: var(--teal-50); color: var(--ink-2); }
.dropzone b { color: var(--ink); }
.dropzone .arquivo { font-weight: 600; color: var(--teal-600); }

.progresso { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progresso > div { height: 100%; background: linear-gradient(90deg, var(--teal), var(--blue)); width: 0; transition: width .3s; }
.progresso.indeterminado > div { width: 35%; animation: andar 1.1s ease-in-out infinite; }
@keyframes andar { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

/* interruptor */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { appearance: none; width: 34px; height: 20px; border-radius: 99px; background: var(--line-strong); position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked { background: var(--teal); }
.switch input:checked::after { transform: translateX(14px); }

/* lista de definições */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13.5px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }

/* gráfico */
.grafico-box { padding: 12px 16px 16px; border-bottom: 1px solid var(--line); }
.grafico-box canvas { width: 100% !important; max-height: 260px; }

/* paleta de comandos (Ctrl+K) */
.paleta { width: min(640px, 100%); }
.paleta input { width: 100%; height: 52px; border: 0; border-bottom: 1px solid var(--line); padding: 0 20px; font-size: 16px; background: transparent; outline: none; }
.paleta ul { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow: auto; }
.paleta li a { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: var(--r-s); color: var(--ink); text-decoration: none !important; }
.paleta li a small { color: var(--muted); margin-left: auto; font-size: 12px; }
.paleta li a.sel, .paleta li a:hover { background: var(--teal-50); }

/* grade de cartões genérica */
.colunas-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.colunas-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1100px) { .colunas-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .colunas-2, .colunas-3 { grid-template-columns: minmax(0, 1fr); } }
.colunas-2 > .painel + .painel, .colunas-3 > .painel + .painel { margin-top: 0; }

/* projeção de receita (era X, ficou Y) */
.proj-cab { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.proj-cab h3 { display: flex; align-items: center; gap: 6px; margin: 0 0 4px; font-size: 15px; }
.proj-cab p { margin: 0; font-size: 12.5px; max-width: 900px; }
