/* ==========================================================================
   Dashboard de vendas — grids de KPIs, período, tipo e gráficos.
   Migrado do styles.css original; mantém os fixes de responsividade (min-width:0,
   spark-wrap, canvas.bar) documentados no README.
   ========================================================================== */
.dashboard { display: flex; flex-direction: column; gap: 18px; }
/* Telas com toolbar + cards + tabela: espaçamento consistente entre os blocos. */
.estoque, .relatorio, .produtos { display: flex; flex-direction: column; gap: 18px; }

/* Toolbar do dashboard (date picker + filtro de tipo + ações). */
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 22px; padding: 16px 22px; }
.tb-group { display: flex; flex-direction: column; gap: 6px; }
.tb-group > label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; font-weight: 700; color: var(--text-muted); }
.tb-right { margin-left: auto; flex-direction: row; align-items: center; gap: 14px; }
#datePicker {
  font-family: inherit; font-size: 16px; font-weight: 700; color: var(--teal-d);
  padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--card-bg-2);
}
[data-theme="dark"] #datePicker { color-scheme: dark; }
.updated { font-size: 11px; color: var(--text-muted); font-weight: 600; }
/* "Última atualização" como rodapé do card de filtros (linha própria, com separador). */
.toolbar .est-atualizacao {
  flex-basis: 100%; width: 100%; margin: 0; padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted); font-weight: 600;
}
.histMensal-hint { font-size: 11px; font-weight: 600; color: var(--text-muted); }

/* Aviso discreto de "dia sem vendas". */
.aviso-sem-vendas {
  display: flex; align-items: center; gap: 9px;
  background: var(--card-bg-2); border: 1px solid var(--border); border-left: 3px solid var(--orange);
  color: var(--text-muted); padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
}
.aviso-sem-vendas .ico {
  flex: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--orange); color: #fff; font-size: 12px; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center;
}
.aviso-sem-vendas b { color: var(--text-main); font-weight: 700; }

/* CRÍTICO: filhos de grid têm min-width:auto e não encolhem abaixo do conteúdo
   (canvas do Chart.js). min-width:0 libera o encolhimento em telas estreitas. */
.stats-grid > *, .mid-grid > *, .bottom-grid > * { min-width: 0; }

/* ---------- Stats topo ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.stats-grid-4 { grid-template-columns: repeat(4, 1fr); }
.stats-grid-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 1000px) { .stats-grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 1200px) { .stats-grid-5 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 760px) { .stats-grid-5 { grid-template-columns: repeat(2, 1fr); } }
.stat-card { padding: 20px 24px; display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 12px; text-transform: uppercase; color: var(--text-muted); font-weight: 700; letter-spacing: .5px; }
.stat-value { font-size: 32px; font-weight: 800; color: var(--teal-d); }
.stat-card.accent .stat-value { color: var(--orange); }
.stat-sub { font-size: 12px; color: var(--text-muted); }
.stat-split {
  display: flex; gap: 16px; margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed var(--border); font-size: 12px; color: var(--text-muted); font-weight: 600;
}
.stat-split span { display: flex; align-items: center; }
.dot-sm { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }

/* ---------- Grid central ---------- */
.mid-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel { padding: 22px 24px; }
.panel-title {
  font-size: 14px; font-weight: 800; color: var(--teal-d); text-transform: uppercase;
  letter-spacing: .5px; margin-bottom: 16px;
}
.periodo-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.periodo-row:last-child { border-bottom: none; }
.periodo-info { min-width: 0; flex: 0 1 auto; }
.periodo-info .lbl { font-size: 12px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; }
.periodo-info .val { font-size: 24px; font-weight: 800; color: var(--teal-d); }
.periodo-meta { display: flex; align-items: baseline; gap: 6px; margin-top: 2px; }
.periodo-kg { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.periodo-margem { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-top: 3px; }
.periodo-margem b { color: var(--pos); font-weight: 800; }
.periodo-margem b.neg { color: var(--neg); }
.periodo-margem .mrg-sep { font-weight: 600; color: var(--text-muted); }
.spark-wrap { flex: 1 1 0; min-width: 0; height: 48px; position: relative; overflow: hidden; }
.spark-wrap canvas { display: block; position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
@media (min-width: 861px) {
  .panel-periodo { display: flex; flex-direction: column; }
  .panel-periodo .periodo-list { flex: 1 1 auto; display: flex; flex-direction: column; }
  .panel-periodo .periodo-row { flex: 1 1 0; }
  .panel-periodo .spark-wrap { height: auto; align-self: stretch; margin: 12px 0; }
}

/* tipo de produto */
.donut-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.donut-box { flex: 0 0 auto; width: 160px; height: 160px; position: relative; }
.donut-box canvas { display: block; position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.donut-legend { flex: 1 1 auto; min-width: 0; font-size: 13px; color: var(--text-main); }
.donut-legend div { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-weight: 600; }
.dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.tipo-cards { display: grid; grid-template-columns: 1fr; gap: 16px; margin-top: 16px; }
.tipo-card { border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; background: var(--card-bg-2); transition: opacity .15s, box-shadow .15s; }
.tipo-card.dim { opacity: .38; }
.tipo-card.focus { box-shadow: 0 0 0 2px var(--teal-l); }
.tipo-card .tc-head { display: flex; flex-direction: column; gap: 2px; padding-bottom: 10px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.tipo-card .tc-title { font-size: 14px; font-weight: 800; text-transform: uppercase; letter-spacing: .4px; }
.tipo-card.cong .tc-title { color: var(--cong); }
.tipo-card.fres .tc-title { color: var(--fres); }
.tp-rows { display: flex; flex-direction: column; }
.tp-row { display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.tp-row:last-child { border-bottom: none; }
.tp-lbl { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; }
.tp-mid { display: flex; align-items: baseline; gap: 8px; line-height: 1.2; min-width: 0; }
.tp-val { font-size: 18px; font-weight: 800; color: var(--text-main); white-space: nowrap; }
.tp-kg { font-size: 12px; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.tp-row .var { font-size: 12px; white-space: nowrap; justify-self: end; }

/* ---------- Charts inferiores ---------- */
.bottom-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel-chart { padding: 16px 22px; }
.panel-chart .panel-title { margin-bottom: 8px; }
canvas.bar { display: block; width: 100% !important; max-width: 100%; height: 230px !important; }

/* ---------- Responsivo ---------- */
@media (max-width: 860px) {
  .toolbar { gap: 14px; }
  .tb-right { margin-left: 0; width: 100%; flex-wrap: wrap; }
  /* No mobile a toolbar fica à esquerda; ancora o menu à esquerda do botão para
     não sair da tela pela lateral (bug do dropdown de opções). */
  .toolbar .menu { right: auto; left: 0; }
  .stats-grid { grid-template-columns: 1fr; }
  .mid-grid { grid-template-columns: 1fr; }
  .bottom-grid { grid-template-columns: 1fr; }
  .panel-periodo .periodo-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
  .periodo-row:nth-last-child(-n+2) { border-bottom: none; }
  .spark-wrap { height: 42px; }
  .stat-value { font-size: 28px; }
}
@media (max-width: 520px) {
  .panel-periodo .periodo-list { grid-template-columns: 1fr; }
  .tipo-cards { grid-template-columns: 1fr; }
  .tp-row { grid-template-columns: minmax(48px, auto) minmax(0, 1fr) auto; column-gap: 10px; }
  .tp-mid { flex-direction: column; align-items: flex-start; gap: 1px; }
  .tp-val { font-size: 16px; }
}
