/* ==================== 5. DASHBOARD ==================== */
.dash-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.coluna-esquerda,
.coluna-direita {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
}

.bloco {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.bloco h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--txt);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.bloco h3 a {
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-body);
}

.card-patrimonio {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 200px;
  position: relative;
  overflow: hidden;
}

body.light .card-patrimonio {
  background: linear-gradient(135deg, #ffffff, #f1f5f9);
}

.card-patrimonio::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(
    circle,
    rgba(139, 92, 246, 0.1) 0%,
    transparent 60%
  );
  pointer-events: none;
}

.card-patrimonio h3 {
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  z-index: 1;
}

.card-patrimonio .valor-principal {
  font-size: 40px;
  font-weight: 800;
  font-family: var(--font-title);
  color: var(--txt);
  margin-bottom: 12px;
  z-index: 1;
}

.card-patrimonio .variacao {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  z-index: 1;
}

.card-patrimonio .variacao.positiva {
  color: var(--green);
}

.bloco-orcamento-kpi {
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.orcamento-content {
  display: flex;
  flex-direction: row;
  gap: 20px;
  align-items: center;
  width: 100%;
}

.grafico-wrapper {
  flex: 0 0 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 140px;
}

.grafico-circular {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: conic-gradient(
    var(--accent) 0% 74%,
    var(--border) 74% 100%
  );
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.grafico-circular::before {
  content: "";
  position: absolute;
  width: 90px;
  height: 90px;
  background: var(--card);
  border-radius: 50%;
}

.grafico-circular .texto-centro {
  position: relative;
  z-index: 1;
  text-align: center;
}

.grafico-circular .texto-centro .pct {
  font-size: 26px;
  font-weight: 800;
  font-family: var(--font-title);
  color: var(--txt);
}

.grafico-circular .texto-centro .lbl {
  font-size: 11px;
  color: var(--muted);
}

.kpi-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-left: 1px solid var(--border);
  padding-left: 20px;
}

.kpi-wrapper .mini-kpi {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.kpi-wrapper .mini-kpi:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.kpi-wrapper .mini-kpi .texto {
  display: flex;
  align-items: center;
  gap: 8px;
}

.kpi-wrapper .mini-kpi .texto span {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 700;
  white-space: nowrap;
}

.kpi-wrapper .mini-kpi .texto strong {
  font-size: 16px;
  color: var(--txt);
  font-family: var(--font-title);
  white-space: nowrap;
}

.bloco-cartoes {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.wallet-container {
  display: flex;
  gap: 16px;
  overflow: hidden;
  padding: 10px 0;
  align-items: center;
  width: 100%;
}

.cartao-compacto {
  flex: 1;
  min-width: 0;
  max-width: calc(50% - 8px);
  width: 100%;
  aspect-ratio: 1.58 / 1;
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: 0.3s;
}

.cartao-compacto:hover {
  transform: translateY(-5px) scale(1.02);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  z-index: 10;
}

.barra-saldo-fundo {
  height: 4px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 4px;
  margin-top: 8px;
  overflow: hidden;
}

.barra-saldo-preenchida {
  height: 100%;
  background: #fff;
  border-radius: 4px;
}

/* ==================== VISÃO GERAL PERSONALIZÁVEL (grade de 12 colunas) ==================== */
.dash-grid.dg12 {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-auto-rows: 20px;
  gap: 16px;
  align-items: stretch;
  position: relative;
}
.dash-grid.dg12 > .dw {
  min-width: 0;
  min-height: 0;
  height: 100%;
  margin: 0;
  box-sizing: border-box;
  overflow: hidden auto;
  scrollbar-width: thin;
}
.dash-grid.dg12 > .carrossel-widgets {
  height: 100% !important;
  overflow: hidden;
}
.dash-grid.dg12 > .dw[hidden] {
  display: none !important;
}
.bloco-fluxo #chart-fluxo-caixa {
  min-height: 0 !important;
  overflow: hidden;
}

/* Barra de personalização */
.dash-barra {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 14px;
}
.dash-barra .db-dica {
  margin-right: auto;
  font-size: 13px;
  color: var(--muted);
}
.dash-barra button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  width: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--txt);
  cursor: pointer;
  transition: 0.2s;
}
.dash-barra button:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.dash-barra button.primario {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.dash-barra button.primario:hover {
  filter: brightness(1.08);
  color: #fff;
}

/* Modo de edição */
.dash-grid.editando > .dw {
  outline: 2px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: -2px;
  user-select: none;
}
.dash-grid.editando > .dw.arrastando {
  z-index: 50;
  opacity: 0.92;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  outline-style: solid;
  outline-color: var(--accent);
}
.dw-ov {
  position: absolute;
  inset: 0;
  z-index: 20;
  cursor: grab;
  background: color-mix(in srgb, var(--accent) 5%, transparent);
  touch-action: none;
}
.arrastando .dw-ov {
  cursor: grabbing;
}
.dw-ov .dw-nome {
  position: absolute;
  bottom: 8px;
  left: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  pointer-events: none;
}
.dw-ov .dw-remover {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 26px;
  height: 26px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
}
.dw-ov .dw-remover:hover {
  background: var(--red);
}
.dw-ov .dw-h {
  position: absolute;
  background: transparent;
}
.dw-ov .dw-h.e {
  top: 44px;
  right: 0;
  bottom: 30px;
  width: 12px;
  cursor: ew-resize;
}
.dw-ov .dw-h.s {
  left: 30px;
  right: 30px;
  bottom: 0;
  height: 12px;
  cursor: ns-resize;
}
.dw-ov .dw-h.se {
  right: 8px;
  bottom: 8px;
  width: 24px;
  height: 24px;
  cursor: nwse-resize;
  z-index: 2;
  border-right: 4px solid var(--accent);
  border-bottom: 4px solid var(--accent);
  border-bottom-right-radius: 12px;
  box-sizing: border-box;
}
.dw-sombra {
  border-radius: 20px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 2px dashed var(--accent);
  z-index: 1;
  pointer-events: none;
}

/* Telas estreitas: uma coluna só, na ordem escolhida; sem edição */
@media (max-width: 1100px) {
  .dash-grid.dg12 {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-auto-rows: auto;
  }
  .dash-grid.dg12 > .dw {
    grid-column: 1 / -1 !important;
    grid-row: auto !important;
    height: auto;
    order: var(--o, 0);
  }
  .dash-grid.dg12 > .carrossel-widgets {
    height: 220px !important;
  }
  .dash-grid.dg12 > .bloco-fluxo {
    min-height: 300px;
  }
  .dash-barra {
    display: none;
  }
}

/* Botão "Personalizar tela" mais visível */
#btn-personalizar {
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}

/* ==================== WIDGETS EXTRAS ==================== */
.dash-grid .dw.wx {
  display: flex;
  flex-direction: column;
}
.wx .wx-corpo {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
.wx-kpi {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  container-type: inline-size;
}
.wx-kpi .wx-rot {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
}
.wx-kpi .wx-rot i {
  font-size: 18px;
}
.wx-kpi .wx-val {
  font-family: var(--font-title);
  font-weight: 800;
  color: var(--txt);
  font-size: clamp(20px, 11cqw, 40px);
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wx-kpi .wx-sub {
  font-size: 12px;
  color: var(--muted);
}
.wx-linha {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  min-height: 50px;
  box-sizing: border-box;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.wx-linha:last-child {
  border-bottom: none;
}
.wx-linha-nome {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wx-linha-sub {
  font-size: 11px;
  color: var(--muted);
}
.wx-uso {
  margin-bottom: 14px;
}
.wx-uso-topo {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
}
.wx-uso-barra {
  height: 6px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
}
.wx-uso-barra > div {
  height: 100%;
  border-radius: 4px;
}
.dw.dw-novo {
  animation: dwNovo 1.1s ease;
}
@keyframes dwNovo {
  0% {
    box-shadow: 0 0 0 0 var(--accent);
  }
  40% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 45%, transparent);
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

/* ==================== MENU LATERAL: ADICIONAR WIDGETS ==================== */
#dash-painel-widgets {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 100vw);
  z-index: 9000;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: -18px 0 40px rgba(0, 0, 0, 0.3);
  transform: translateX(105%);
  transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}
#dash-painel-widgets.aberto {
  transform: translateX(0);
}
.dpw-topo {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 22px 22px 12px;
}
.dpw-topo h3 {
  font-size: 18px;
  margin: 0 0 4px;
}
.dpw-topo p {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}
.dpw-fechar {
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--txt);
  cursor: pointer;
}
.dpw-fechar:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.dpw-busca {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 22px 8px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--muted);
}
.dpw-busca input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--txt);
  padding: 10px 0;
  font-size: 13px;
  min-width: 0;
}
.dpw-lista {
  flex: 1;
  overflow-y: auto;
  padding: 4px 22px 24px;
}
.dpw-grupo {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 16px 0 8px;
}
.dpw-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: 0.2s;
}
.dpw-item:hover {
  border-color: var(--accent);
  transform: translateX(-2px);
}
.dpw-icone {
  flex: 0 0 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.dpw-txt {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dpw-txt strong {
  font-size: 13px;
}
.dpw-txt span {
  font-size: 11px;
  color: var(--muted);
}
.dpw-acao {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
}
.dpw-item.na-tela {
  background: color-mix(in srgb, var(--green) 7%, transparent);
}
.dpw-item.na-tela .dpw-acao {
  color: var(--green);
}
.dpw-acao .t2,
.dpw-item.na-tela:hover .dpw-acao .t1 {
  display: none;
}
.dpw-item.na-tela:hover .dpw-acao .t2 {
  display: inline;
}
.dpw-item.na-tela:hover .dpw-acao {
  color: var(--red);
}
.dpw-vazio {
  padding: 24px 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}