:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #dde1e6;
  --text: #1c2430;
  --muted: #667085;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 56px;
  overflow-x: auto;
}

.topbar a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
  white-space: nowrap;
}

.topbar a.brand {
  color: var(--text);
  font-weight: 700;
  font-size: 1rem;
}

.topbar a:hover { color: var(--accent); }
.topbar a.active { color: var(--accent); font-weight: 600; }

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem;
}

h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 2rem 0 0.75rem; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.flash.ok { background: #ecfdf3; color: var(--ok); border: 1px solid #b8f0cc; }
.flash.erro { background: #fef2f2; color: var(--danger); border: 1px solid #fbc9c9; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

th { color: var(--muted); font-weight: 600; }

.table-wrap { overflow-x: auto; }

label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

input, select, textarea {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  background: #fff;
  color: var(--text);
}

textarea {
  font-family: inherit;
  resize: vertical;
  max-height: 10rem;
  overflow-y: auto;
}

.campo { margin-bottom: 0.85rem; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.85rem;
}
@media (max-width: 900px) { .grid-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .grid-4 { grid-template-columns: 1fr; } }

.kpi .valor { font-size: 1.6rem; font-weight: 700; margin: 0.15rem 0; }
.kpi .valor.alerta { color: var(--danger); }
.kpi .sub { font-size: 0.78rem; color: var(--muted); }

.barras-mensal {
  display: flex;
  align-items: flex-end;
  gap: 0.9rem;
  height: 160px;
  padding-top: 1rem;
}
.barras-mensal .coluna {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
}
.barras-mensal .par { display: flex; align-items: flex-end; gap: 3px; height: 100%; width: 100%; justify-content: center; }
.barras-mensal .barra-pilha { width: 40%; min-height: 2px; display: flex; flex-direction: column; }
.barras-mensal .barra-pilha > *:first-child { border-radius: 3px 3px 0 0; }
.barras-mensal .rotulo { font-size: 0.72rem; color: var(--muted); margin-top: 0.4rem; }
.legenda-barras { display: flex; gap: 0.9rem; font-size: 0.78rem; color: var(--muted); margin-top: 0.5rem; flex-wrap: wrap; }
.legenda-barras .ponto { display: inline-block; width: 0.6rem; height: 0.6rem; border-radius: 999px; margin-right: 0.3rem; vertical-align: middle; }

.segmento.compra { background: #16a34a; }
.segmento.comodato_devolucao { background: #0d9488; }
.segmento.retorno_teste { background: #0284c7; }
.segmento.retorno_rma { background: #6366f1; }
.segmento.comodato_saida { background: #f59e0b; }
.segmento.envio_teste { background: #ea580c; }
.segmento.envio_rma { background: #dc2626; }
.segmento.descarte { background: #7f1d1d; }

[data-tooltip] { position: relative; }
[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #1c2430;
  color: #fff;
  padding: 0.3rem 0.55rem;
  border-radius: 5px;
  font-size: 0.72rem;
  white-space: nowrap;
  z-index: 20;
  margin-bottom: 5px;
  pointer-events: none;
}
[data-tooltip]:hover::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: #1c2430;
  margin-bottom: 1px;
  z-index: 20;
  pointer-events: none;
}

.classe-abc {
  display: inline-block;
  width: 1.5rem;
  height: 1.5rem;
  line-height: 1.5rem;
  text-align: center;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.8rem;
}
.classe-abc.a { background: #ecfdf3; color: var(--ok); }
.classe-abc.b { background: #fff7ed; color: #c2410c; }
.classe-abc.c { background: #f1f2f4; color: var(--muted); }

.grafico-pareto { width: 100%; height: 260px; overflow: visible; }
.grafico-pareto .barra-valor.a { fill: var(--ok); }
.grafico-pareto .barra-valor.b { fill: #f59e0b; }
.grafico-pareto .barra-valor.c { fill: #c7cbd1; }
.grafico-pareto .linha-acumulada { fill: none; stroke: var(--accent); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.grafico-pareto .ponto-acumulado { fill: var(--accent); }
.legenda-pareto { display: flex; gap: 1rem; font-size: 0.78rem; color: var(--muted); margin-top: 0.5rem; flex-wrap: wrap; }
.legenda-pareto .ponto { display: inline-block; width: 0.6rem; height: 0.6rem; border-radius: 999px; margin-right: 0.3rem; vertical-align: middle; }
.legenda-pareto .ponto.a { background: var(--ok); }
.legenda-pareto .ponto.b { background: #f59e0b; }
.legenda-pareto .ponto.c { background: #c7cbd1; }
.legenda-pareto .ponto.linha { background: var(--accent); }

.critico-item { margin-bottom: 0.85rem; }
.critico-cabecalho { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 0.3rem; }
.critico-trilha { background: #f1f2f4; border-radius: 999px; height: 0.6rem; overflow: hidden; }
.critico-preenchido { background: var(--danger); height: 100%; border-radius: 999px; }

button, .btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.88rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover, .btn:hover { background: var(--accent-hover); }
button.secundario { background: var(--muted); }
button.perigo { background: var(--danger); }

.item-linha {
  display: grid;
  grid-template-columns: 2fr 1fr 1.5fr auto;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 0.5rem;
}
@media (max-width: 640px) { .item-linha { grid-template-columns: 1fr; } }

.tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}
.tag.ativo, .tag.em_estoque, .tag.sincronizado { background: #ecfdf3; color: var(--ok); }
.tag.devolvido, .tag.inativo, .tag.descartada { background: #f1f2f4; color: var(--muted); }
.tag.em_comodato, .tag.pendente, .tag.em_teste { background: #fff7ed; color: #c2410c; }
.tag.erro, .tag.nao_integrado, .tag.em_rma { background: #fef2f2; color: var(--danger); }

.muted { color: var(--muted); font-size: 0.85rem; }
.acoes { display: flex; gap: 0.5rem; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1c1f26;
    --border: #2c313a;
    --text: #e6e8eb;
    --muted: #9aa2b1;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
  }
  input, select { background: #12141a; color: var(--text); }
  .flash.ok { background: #052e1c; }
  .flash.erro { background: #350909; }
}
