:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --axis: #c3c2b7;
  --series: #2a78d6;
  --series-soft: #cde2fb;
  --accent: #256abf;
  --good: #006300;
  --bad: #b32d2d;
  --warn-bg: #fdf1d3;
  --warn-ink: #6b4a00;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #2c2c2a;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --line: #2c2c2a;
    --axis: #383835;
    --series: #3987e5;
    --series-soft: #104281;
    --accent: #6da7ec;
    --good: #0ca30c;
    --bad: #e66767;
    --warn-bg: #3a2f10;
    --warn-ink: #fab219;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- estrutura ---------- */
.shell { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.side {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 16px; }
.brand span { color: var(--series); }
.side a.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 500;
}
.side a.nav:hover { background: var(--surface-2); }
.side a.nav.active { background: var(--surface-2); color: var(--ink); }
.badge {
  background: var(--series);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  padding: 1px 7px;
}
.side .foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); }
main { padding: 22px 26px 60px; min-width: 0; }
.head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .brand { padding: 4px 10px; }
  .side .foot { margin: 0 0 0 auto; }
  main { padding: 16px; }
}

/* ---------- componentes ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.grid { display: grid; gap: 14px; }
.tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 14px; }
.cols { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
@media (max-width: 1100px) { .cols { grid-template-columns: 1fr; } }

/* Cabeçalho fixo: a tabela rola dentro da própria área e os nomes das colunas ficam sempre à vista */
.table-wrap.sticky-head { max-height: calc(100vh - 150px); min-height: 260px; overflow: auto; }
.table-wrap.sticky-head thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  border-bottom: 0;
  box-shadow: inset 0 -1px 0 var(--axis), 0 2px 4px rgba(0, 0, 0, 0.06);
}
.table-wrap.sticky-head thead th.taxcol { background: color-mix(in srgb, var(--series-soft) 22%, var(--surface)); }
.table-wrap.sticky-head thead th.pin { z-index: 3; }
.table-wrap.sticky-head td.pin { z-index: 1; }
table.dre td { padding: 8px 10px; }
table.dre tr.sum td { border-top: 1px solid var(--axis); border-bottom: 1px solid var(--axis); background: var(--surface-2); }
tr.selected td { background: color-mix(in srgb, var(--series-soft) 40%, var(--surface)); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.clickable:hover td.taxcol { background: color-mix(in srgb, var(--series-soft) 45%, var(--surface-2)); }
.prod + .prod { margin-top: 6px; }
.prod.cancelled { opacity: 0.55; }
.prod.cancelled .t a, .prod.cancelled .t { text-decoration: line-through; }
td.pin, th.pin { position: sticky; right: 0; background: var(--surface); box-shadow: -1px 0 0 var(--line); }
td.taxcol, th.taxcol { background: color-mix(in srgb, var(--series-soft) 22%, transparent); }
.abc {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 12px;
  border: 1px solid var(--axis);
  color: var(--ink-2);
}
.abc-A { background: var(--series); border-color: var(--series); color: #fff; }
.abc-B { background: var(--series-soft); border-color: var(--series-soft); color: var(--ink); }
.best { border-left: 3px solid var(--good); background: var(--surface-2); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; }
.best .label { font-size: 12px; color: var(--ink-2); }
.best .value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.forecast { margin-bottom: 14px; border-top: 3px solid var(--series); }
.forecast-nums { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin: 14px 0; }
.forecast .label { color: var(--ink-2); font-size: 12px; }
.forecast .hero { font-size: 32px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.forecast .delta { font-size: 12px; color: var(--muted); }
.forecast .delta.up { color: var(--good); }
.forecast .delta.down { color: var(--bad); }
.meter { position: relative; height: 10px; background: var(--surface-2); border-radius: 5px; margin: 4px 0 8px; }
.meter-fill { height: 100%; background: var(--series); border-radius: 5px; min-width: 2px; }
.meter-mark { position: absolute; top: -4px; width: 2px; height: 18px; background: var(--ink); transform: translateX(-1px); }
.live { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-bottom: 18px; }
.live .card { border-left: 3px solid var(--series); }
h2.section { margin: 0 0 10px; color: var(--ink-2); }
.pill.tag::before { content: none; }
.tile .delta b { color: var(--ink); font-weight: 600; }
.tile .label { color: var(--ink-2); font-size: 12px; }
.tile .value { font-size: 24px; font-weight: 650; margin: 2px 0; font-variant-numeric: tabular-nums; }
.tile .delta { font-size: 12px; color: var(--muted); }
.tile .delta.up { color: var(--good); }
.tile .delta.down { color: var(--bad); }

button, .btn, input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--axis);
  border-radius: 8px;
  padding: 7px 10px;
}
button, .btn { cursor: pointer; font-weight: 500; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { background: var(--surface-2); }
button.primary, .btn.primary { background: var(--series); border-color: var(--series); color: #fff; }
button.primary:hover, .btn.primary:hover { filter: brightness(1.08); background: var(--series); }
button.danger { color: var(--bad); }
button:disabled { opacity: 0.55; cursor: default; }
button.seg { border-radius: 0; margin-left: -1px; }
button.seg:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
button.seg:last-child { border-radius: 0 8px 8px 0; }
button.seg.on { background: var(--surface-2); font-weight: 650; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--series); outline-offset: 1px; }
input.mini { width: 92px; padding: 5px 8px; text-align: right; }
textarea { width: 100%; min-height: 70px; resize: vertical; }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  padding: 8px 10px;
  border-bottom: 1px solid var(--axis);
  white-space: nowrap;
}
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th.right, td.right { text-align: right; }
.table-wrap { overflow-x: auto; }
.thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--surface-2); flex: none; }
.prod { display: flex; gap: 10px; align-items: center; min-width: 170px; }
td, th { padding-left: 8px; padding-right: 8px; }
.prod .t { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--surface-2);
  color: var(--ink-2);
  white-space: nowrap;
}
.pill::before { content: "● "; font-size: 9px; vertical-align: 1px; }
.pill.ok::before { color: var(--good); }
.pill.bad::before { color: var(--bad); }
.pill.wait::before { color: #eda100; }

.notice { background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; }
.error { color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 36px 10px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 5px; word-break: break-all; }
ol.steps { padding-left: 20px; line-height: 1.8; }

#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--page);
  padding: 10px 16px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  max-width: 90vw;
  z-index: 10;
}
#toast.show { opacity: 1; }

/* ---------- gráficos ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .base-line { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: var(--series); }
.chart .hit { fill: transparent; }
.chart .hit:hover + .bar, .chart .bar.on { filter: brightness(1.2); }
.tip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--axis);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  white-space: nowrap;
  display: none;
  z-index: 5;
}
.tip b { display: block; font-size: 13px; color: var(--ink); }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 7px 0; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { grid-column: 1 / -1; height: 8px; }
.hbar .fill { height: 100%; background: var(--series); border-radius: 0 4px 4px 0; min-width: 2px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 340px; display: grid; gap: 12px; }
.login input { padding: 10px 12px; }
.login button { padding: 10px; }

/* ---------- Devoluções e reclamações ---------- */
.pv-linha { cursor: pointer; }
.pv-linha.aberta > td { background: var(--warn-bg); }
.pv-expandida > td { background: rgba(127, 127, 127, 0.06); padding: 16px; }
.pv-detalhe h3 { margin: 14px 0 8px; font-size: 14px; }
.pv-detalhe h3:first-child { margin-top: 0; }
.pv-colunas { display: grid; gap: 24px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.pv-resumo td { padding: 4px 10px 4px 0; vertical-align: top; border: 0; }
.etapas { list-style: none; margin: 0; padding: 0; }
.etapas li { position: relative; padding: 0 0 14px 26px; border-left: 2px solid rgba(127, 127, 127, 0.3); margin-left: 8px; color: var(--muted); }
.etapas li:last-child { border-left-color: transparent; padding-bottom: 0; }
.etapas li::before { content: ""; position: absolute; left: -8px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 2px solid rgba(127, 127, 127, 0.5); box-sizing: border-box; }
.etapas li.feito { color: inherit; border-left-color: var(--good); }
.etapas li.feito::before { background: var(--good); border-color: var(--good); }
.etapas li.atual { color: inherit; }
.etapas li.atual::before { border-color: #eda100; background: #eda100; box-shadow: 0 0 0 4px rgba(237, 161, 0, 0.25); }
.pv-mensagens { display: grid; gap: 8px; max-height: 360px; overflow: auto; }
.pv-msg { background: var(--surface); border: 1px solid rgba(127, 127, 127, 0.25); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; max-width: 760px; }
.pv-msg.minha { margin-left: auto; background: var(--warn-bg); }.manual { margin-bottom: 16px; line-height: 1.55; max-width: 980px; }
.manual h3 { margin: 20px 0 6px; font-size: 15px; }
.manual ol, .manual ul { margin: 6px 0; padding-left: 22px; }
.manual li { margin-bottom: 6px; }
.manual table td { vertical-align: top; padding: 6px 12px 6px 0; }
.manual table td:first-child { white-space: nowrap; }