/* Painel Central — app.css (CONTRATO §6, §6b, §8.4 e §9.6; design/BRIEF-VISUAL.md).
   Paleta ikarus (decisão 20): cinza-neutro escuro, verde-lima só no que é dinheiro/positivo, verde no botão
   primário, azul no foco e nos links. Inter self-hosted. Tokens num lugar só; celular primeiro; tema noturno padrão.
   Todas as classes das Fases 1 e 3 continuam válidas — só a aparência muda. */

@font-face {
  font-family: "Inter";
  src: url("fonts/InterVariable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0d0d0d;
  --bg2: #0f0f0f;
  --card: #141414;
  --card-hover: #1a1a1a;
  --row-total: #181818;
  --pill: #1d1d1d;
  --field: #0d0d0d;
  --border: #242424;
  --border-forte: #333333;
  --text: #fafafa;
  --muted: #9a9f9a;
  --lime: #99d376;
  --green: #27ae60;
  --green-hover: #2fc26c;
  --green-deep: #1e3c0f;
  --green-soft: #102008;
  --green-linha: rgba(39, 174, 96, 0.45);
  --green-text: var(--lime);         /* .verde / links de tabela: continua existindo (§6), agora vale o lima */
  --blue: #2d59f5;
  --blue-text: #7b9bff;              /* #2d59f5 fica em 3,4:1 sobre #141414; este passa de 6:1 */
  --blue-soft: rgba(45, 89, 245, 0.16);
  --red: #ff5f57;
  --red-text: #ff5f57;
  --red-soft: rgba(255, 95, 87, 0.12);
  --amber: #febc2e;
  --amber-soft: rgba(254, 188, 46, 0.12);
  --barra: var(--green);             /* preenchimento das barras (.bar > i, .bars > i); no diurno é um verde mais fundo (≥ 3:1) */
  --glow: 0 0 40px rgba(39, 174, 96, 0.2);
  --hover: rgba(255, 255, 255, 0.04);
  --topbar: rgba(13, 13, 13, 0.86);
  --radius: 16px;
  --radius-s: 10px;
  --pilula: 999px;
  /* nomes antigos (§6b) continuam resolvendo */
  --raio: var(--radius);
  --raio-s: var(--radius-s);
  --sombra: none;
  /* séries da barra segmentada (.bar-seg/.legenda): ordem fixa, paleta categórica validada pra daltonismo no fundo escuro */
  --serie-1: #3987e5;
  --serie-2: #d95926;
  --serie-3: #199e70;
  --serie-4: #c98500;
  --serie-5: #d55181;
  --serie-6: #008300;
  --serie-7: #9085e9;
  --serie-8: #e66767;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f7faf5;
  --bg2: #ffffff;
  --card: #ffffff;
  --card-hover: #f4f7f1;
  --row-total: #f1f5ee;
  --pill: #e9eee5;
  --field: #ffffff;
  --border: #e3e8df;
  --border-forte: #c9d2c3;
  --text: #0d0d0d;
  --muted: #5f6a5f;
  --lime: #2d6310;
  --green: #27ae60;
  --green-hover: #22a058;
  --green-deep: #d5f1bf;
  --green-soft: #eaf6e0;
  --green-linha: #a9d994;
  --green-text: var(--lime);
  --blue: #2d59f5;
  --blue-text: #2d59f5;
  --blue-soft: #e3e9ff;
  --red: #c62828;
  --red-text: #c62828;
  --red-soft: #fde3e1;
  --amber: #8a5a00;
  --amber-soft: #fdf1d4;
  --barra: #1f8f4e;                  /* #27ae60 dava 2,9:1 sobre branco e 2,4:1 sobre --pill; este passa de 3:1 nos dois */
  --glow: none;
  --hover: rgba(0, 0, 0, 0.035);
  --topbar: rgba(255, 255, 255, 0.88);
  --serie-1: #2a78d6;
  --serie-2: #eb6834;
  --serie-3: #1baf7a;
  --serie-4: #eda100;
  --serie-5: #e87ba4;
  --serie-6: #008300;
  --serie-7: #4a3aa7;
  --serie-8: #e34948;
  color-scheme: light;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px; line-height: 1.5; letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;   /* brief: números em tabular-nums em todo lugar (KPIs, sub-textos, selos, tabelas) */
  color: var(--text);
  background-color: var(--bg);
  /* brilho radial verde muito sutil no topo (brief); no diurno o token fica transparente */
  background-image: radial-gradient(900px 420px at 50% -120px, rgba(39, 174, 96, 0.09), transparent 70%);
  background-repeat: no-repeat;
  -webkit-font-smoothing: antialiased;
}
:root[data-theme="light"] body { background-image: none; }
a { color: var(--blue-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 10px; letter-spacing: -0.02em; font-weight: 700; }
h1.titulo { font-size: 22px; margin: 2px 0 10px; }
h2 { font-size: 17px; font-weight: 600; margin: 20px 0 10px; }
h2 .muted { font-weight: 400; font-size: 14px; letter-spacing: -0.01em; }
h3 { font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: -0.01em; margin: 0 0 10px; }
h3 .muted { font-weight: 400; }
p { margin: 0 0 10px; }
strong, b { font-weight: 600; }
.muted { color: var(--muted); }
.verde { color: var(--green-text); }
.vermelho { color: var(--red-text); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; letter-spacing: 0; }
.num { text-align: right; }
.ico { width: 20px; height: 20px; flex: none; }

/* foco visível (teclado): azul 2 px; o clique do mouse não deixa contorno */
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

/* ---------- topbar ---------- */
/* No celular o fundo é sólido: backdrop-filter num ancestral quebraria o position:fixed da .nav (que mora dentro dela) */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; letter-spacing: -0.02em; min-width: 0; }
.brand:hover { text-decoration: none; }
/* logotipo "PC": pílula verde com texto quase-preto — o único verde da moldura */
.brand-logo {
  display: inline-grid; place-items: center; height: 28px; padding: 0 11px; border-radius: var(--pilula);
  background: var(--green); color: #0d0d0d; font-size: 13px; font-weight: 800; letter-spacing: 0.04em; line-height: 1;
}
.brand-nome { display: none; white-space: nowrap; }
.topbar-acoes { margin-left: auto; display: flex; align-items: center; gap: 6px; min-width: 0; }
.form-sair, .form-atualizar { margin: 0; display: inline-flex; }
.btn.icone { padding: 0; width: 36px; height: 36px; justify-content: center; }
#tema .ico-sol { display: none; }
#tema .ico-lua { display: block; }
:root[data-theme="light"] #tema .ico-sol { display: block; }
:root[data-theme="light"] #tema .ico-lua { display: none; }
/* botão Atualizar (§9.3) e "coletor há N min" ao lado; .atrasado = passou do COLETOR_ATRASO_MIN, .rodando = em andamento */
.btn.atualizar { padding: 0 14px 0 11px; height: 36px; gap: 6px; }
.btn.atualizar .ico { width: 17px; height: 17px; }
.coletor-status { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; white-space: nowrap; }
/* no celular a palavra "coletor" não cabe: um relógio antes de "há N min" diz do que se trata; no desktop volta a palavra */
.coletor-status .ico { width: 13px; height: 13px; }
.coletor-status.atrasado { color: var(--amber); }
.coletor-status.rodando { color: var(--blue-text); }

/* nav: barra inferior no celular (6 itens: ícone + rótulo 10 px) */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around; align-items: stretch;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: var(--topbar);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
/* 6 itens têm que caber a 360 px: ~58 px por item; rótulo numa linha só (min-width: 0 + ellipsis) */
.nav a {
  flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 4px 2px; border-radius: var(--radius-s);
  color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: 0; text-decoration: none;
  transition: color 0.12s, background-color 0.12s;
}
.nav a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.2; }
.nav a .ico { width: 22px; height: 22px; padding: 3px 0; box-sizing: content-box; border-radius: var(--pilula); }
.nav a:hover { color: var(--text); text-decoration: none; }
/* item atual: ícone numa pastilha neutra (o verde fica pro dinheiro) */
.nav a.ativo { color: var(--text); }
.nav a.ativo .ico { background: var(--pill); padding: 3px 10px; }

/* ---------- conteúdo ---------- */
/* A reserva pra barra inferior fixa fica só no .rodape (ele vem depois do .app); nos dois dava ~170 px vazios */
.app {
  max-width: 1200px; margin: 0 auto;
  padding: 14px 14px 14px;
}
.pagina-cab { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.rodape {
  max-width: 1200px; margin: 0 auto; padding: 8px 14px calc(84px + env(safe-area-inset-bottom));
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  color: var(--muted); font-size: 12px;
}

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px;
}
.card > :last-child { margin-bottom: 0; }

/* Celular: .grid-2/.grid-3 em 1 coluna (CONTRATO §6); só os cards de KPI (.grid-4) ficam em 2 colunas, e
   .grid-2-sempre é pra pares curtos (país/moeda) que cabem lado a lado em qualquer largura. */
/* minmax(0, 1fr), nunca 1fr puro: 1fr = minmax(auto, 1fr), e uma tabela nowrap dentro do card faria a coluna
   crescer além da tela (o .tbl-wrap só rola quando o card tem largura fixa) */
.grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
.grid-4, .grid-2-sempre { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.kpi { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi .l { color: var(--muted); font-size: 13px; font-weight: 500; letter-spacing: -0.01em; }
/* dinheiro nunca quebra no meio dos dígitos (money() já usa NBSP): o tamanho encolhe com a tela em vez disso */
.kpi .v { font-size: clamp(18px, 5.4vw, 26px); font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; white-space: nowrap; overflow-wrap: normal; margin-top: 2px; }
.kpi .sub { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
/* KPI principal (§9.6): o único brilho da tela, valor em lima; no celular ocupa a linha inteira.
   .v.vermelho (prejuízo) continua vermelho — especificidade maior que a do lima. */
.kpi.principal { grid-column: 1 / -1; box-shadow: var(--glow); border-color: var(--green-linha); }
:root[data-theme="light"] .kpi.principal { background: var(--green-soft); }
.kpi.principal .v { color: var(--lime); font-size: clamp(30px, 9vw, 40px); }
.kpi.principal .v.vermelho { color: var(--red-text); }
.kpi.principal .l { color: var(--text); font-weight: 600; }

/* ---------- tabelas ---------- */
.tbl-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
}
.table { width: 100%; border-collapse: collapse; font-size: 14px; white-space: nowrap; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
/* (sem position: sticky; top: 0 — o .tbl-wrap só rola de lado, então o cabeçalho nunca fixava: regra sem efeito) */
.table th {
  color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: -0.01em;
  background: var(--card);
}
.table th.num, .table td.num { text-align: right; }
/* 1ª coluna fixa ao rolar a tabela de lado (nome da loja / dia / cliente não somem) */
.table thead th:first-child, .table tbody td:first-child { position: sticky; left: 0; background: var(--card); z-index: 2; }
.table thead th:first-child { z-index: 3; }
.table tbody td:first-child { box-shadow: 1px 0 0 var(--border); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--card-hover); }
/* totais em negrito: <tfoot> ou <tr class="total" data-fixo> no fim do tbody (data-fixo mantém a linha embaixo ao ordenar) */
.table tfoot td { font-weight: 700; border-top: 1px solid var(--border); background: var(--row-total); }
.table tfoot td:first-child { position: sticky; left: 0; z-index: 2; background: var(--row-total); box-shadow: 1px 0 0 var(--border); }
.table tbody tr.total td { font-weight: 700; border-top: 2px solid var(--border); background: var(--row-total); }
.table tbody tr.total td:first-child { background: var(--row-total); }
.table th[data-sort] { cursor: pointer; user-select: none; }
.table tr[data-href] { cursor: pointer; }   /* a linha inteira abre o link (app.js); Lojas, Custos e Pedidos usam */
.table th[data-sort]:hover { color: var(--text); }
.table th[data-sort].asc::after { content: " \2191"; color: var(--lime); }
.table th[data-sort].desc::after { content: " \2193"; color: var(--lime); }
.table a { color: var(--text); font-weight: 600; }
.table a:hover { color: var(--lime); }
/* variações genéricas (Fase 3): tabela densa (11 itens de custo), vigência passada, vigência atual, coluna de ações,
   formulário dentro da célula (botão "apagar") e texto secundário embaixo do valor */
.table.compacta th, .table.compacta td { padding: 6px 10px; font-size: 13px; }
.table tbody tr.passada td { color: var(--muted); }
.table tbody tr.destaque td { background: var(--green-soft); }
.table th.acoes, .table td.acoes { text-align: right; white-space: nowrap; }
/* célula que pode quebrar linha (vários selos lado a lado, ex. "Alertas" da Visão): os selos continuam inteiros */
.table td.quebra { white-space: normal; max-width: 150px; }
.table form { margin: 0; display: inline-flex; }
.table .sub { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
/* tabela "solta" (poucas colunas num card de meia largura, ex. "Lucro estimado" da Loja e "Vigente em" de Custos): os
   rótulos quebram linha e a 1ª coluna não fica fixa — com nowrap + coluna fixa, a coluna dos valores sumia da área
   visível a 1280 e a 390. Os números continuam numa linha só. */
.table.solta { white-space: normal; }
.table.solta thead th:first-child, .table.solta tbody td:first-child { position: static; box-shadow: none; }
.table.solta td.num, .table.solta th.num { white-space: nowrap; }

/* ---------- selos ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: var(--pilula); font-size: 12px; font-weight: 600; line-height: 1.5; letter-spacing: 0;
  border: 1px solid var(--border); background: var(--pill); color: var(--muted); white-space: nowrap;
}
.badge.ok, .badge.warn, .badge.bad { padding-left: 8px; border-color: transparent; }
.badge.ok::before, .badge.warn::before, .badge.bad::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge.ok { color: var(--lime); background: var(--green-deep); }
.badge.warn { color: var(--amber); background: var(--amber-soft); }
.badge.bad { color: var(--red-text); background: var(--red-soft); }
.badge.muted { color: var(--muted); }
.badge.info { color: var(--blue-text); background: var(--blue-soft); border-color: transparent; }
a.badge:hover { text-decoration: none; filter: brightness(1.12); }
/* cobertura das estimativas: selos lado a lado ("3 lojas sem custos", "2 dias sem CPA", "sem câmbio: COP") */
.cobertura { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cobertura .badge { font-size: 11.5px; }
/* marca "estimado" ao lado de um número ou título: <span class="est">estimado</span> */
.est {
  display: inline-block; vertical-align: middle; padding: 0 7px; border: 1px dashed var(--border-forte); border-radius: var(--pilula);
  color: var(--muted); font-size: 11px; font-weight: 600; line-height: 1.7; white-space: nowrap; text-transform: none; letter-spacing: 0;
}

/* ---------- botões e campos ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--pilula); border: 1px solid var(--border);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; line-height: 1.2; letter-spacing: -0.01em;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { text-decoration: none; border-color: var(--border-forte); background: var(--pill); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--green); border-color: var(--green); color: #0d0d0d; }
.btn.primary:hover { background: var(--green-hover); border-color: var(--green-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--hover); border-color: transparent; }
.btn.perigo { color: var(--red-text); }
.btn.largo { width: 100%; padding: 12px 16px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.pequeno { padding: 4px 12px; font-size: 13px; }

.input, .select {
  width: 100%; padding: 8px 12px; border-radius: var(--radius-s);
  border: 1px solid var(--border); background: var(--field); color: var(--text); font: inherit; letter-spacing: -0.01em;
  min-height: 38px;
}
.input::placeholder { color: var(--muted); }
.input:focus, .select:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
.select { appearance: auto; }
textarea.input { min-height: 80px; resize: vertical; }
.campo { margin-bottom: 12px; }
.campo label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
/* interruptor com rótulo: <label class="check"><input type="checkbox"> <span>texto, pode ter <strong>…</strong></span></label>
   O texto fica num <span> só — solto no label, cada trecho em volta de um <strong> virava um item flex próprio e a
   frase quebrava em três colunas a 390 px. */
.check { display: flex; align-items: flex-start; gap: 8px; margin: 4px 0 14px; color: var(--muted); font-size: 14px; }
.check input { width: 16px; height: 16px; flex: none; margin: 3px 0 0; accent-color: var(--green); }
.check > span { flex: 1 1 auto; min-width: 0; }
.form-login { max-width: 400px; margin: 6vh auto 0; }
/* login e setup: o único lugar centralizado (brief) — título em cima do cartão, no mesmo eixo */
.pg-login .pagina-cab, .pg-setup .pagina-cab { flex-direction: column; align-items: center; justify-content: center; margin-top: 6vh; }
.pg-login h1.titulo, .pg-setup h1.titulo { text-align: center; }
.pg-login .form-login, .pg-setup .form-login { margin-top: 0; }
.form-inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-inline .input, .form-inline .select { width: auto; }
/* um <select> com dezenas de opções longas ("SIGLA · Nome da loja") tem largura intrínseca de ~440 px e vazaria do card a 390 px */
.form-inline .select { max-width: 100%; min-width: 0; }
/* input de arquivo: a largura intrínseca do Chrome (~350 px) vazava do card a 390 px; no celular ocupa a linha inteira */
.form-inline .input[type="file"] { max-width: 100%; min-width: 0; }
@media (max-width: 719px) {
  .form-inline .input[type="file"] { width: 100%; flex: 1 1 100%; }
}
/* formulário com muitos campos curtos (nova vigência de custos): grade que se ajusta à largura; .largo ocupa a linha inteira */
.form-grid { display: grid; gap: 10px 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); align-items: end; }
.form-grid .campo { margin: 0; min-width: 0; }
.form-grid .campo.largo { grid-column: 1 / -1; }
.campo .dica { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; font-weight: 400; text-transform: none; letter-spacing: 0; }
.input.num { text-align: right; }
.input[type="file"] { padding: 6px 10px; cursor: pointer; }
.input[type="file"]::file-selector-button {
  font: inherit; font-weight: 600; margin-right: 10px; padding: 4px 12px; border-radius: var(--pilula);
  border: 1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer;
}
/* relatório em texto (importação de custos, dry-run): rola por dentro, quebra linha longa */
pre.relatorio {
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; line-height: 1.5; margin: 0 0 10px;
  padding: 10px 12px; max-height: 360px; overflow: auto;
  background: var(--field); border: 1px solid var(--border); border-radius: var(--radius-s);
}

/* chips de período (pílulas): o ativo em verde-escuro com texto lima */
.chip {
  display: inline-flex; align-items: center; padding: 6px 13px; border-radius: var(--pilula);
  border: 1px solid var(--border); background: var(--card); color: var(--muted);
  font-size: 13px; font-weight: 600; text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
.chip:hover { color: var(--text); text-decoration: none; border-color: var(--border-forte); }
.chip.ativo { background: var(--green-deep); border-color: var(--green-deep); color: var(--lime); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

.periodo-form { display: flex; flex-direction: column; gap: 8px; }
.periodo-form .datas { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.periodo-form .input { width: auto; flex: 1 1 130px; min-width: 0; }
.periodo-form .loja-sel { width: 100%; }

/* ---------- avisos ---------- */
/* linha de estado dos coletores na Visão ("Logs: há N min · Shopify: última sync há N min"), discreta, abaixo dos flashes */
.coletores-estado { font-size: 13px; margin: 0 0 12px; }
.flash {
  padding: 10px 14px; border-radius: 12px; margin-bottom: 12px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
}
.flash.ok { border-color: var(--green-linha); color: var(--lime); background: var(--green-soft); }
.flash.erro { border-color: rgba(255, 95, 87, 0.4); color: var(--red-text); background: var(--red-soft); }
.flash.aviso { border-color: rgba(254, 188, 46, 0.4); color: var(--amber); background: var(--amber-soft); }
.flash .muted { color: inherit; opacity: 0.8; }
.flash a { color: inherit; text-decoration: underline; }

/* ---------- barras (gráficos sem lib) ---------- */
.bar { position: relative; height: 8px; border-radius: var(--pilula); background: var(--pill); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; border-radius: var(--pilula); background: var(--barra); }
.bar.vermelha > i { background: var(--red); }
.bar.ambar > i { background: var(--amber); }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 90px; }
.bars > i { flex: 1 1 0; min-width: 2px; background: var(--barra); border-radius: 3px 3px 0 0; transition: background-color 0.12s; }
.bars > i:hover { background: var(--lime); }
.bar.azul > i { background: var(--blue); }
.bar.cinza > i { background: var(--muted); }

/* composição por item (custos, receita): uma linha por item = rótulo · barra · valor
   <ul class="composicao"><li><span class="rot">Produto</span><span class="bar"><i style="width:42%"></i></span><span class="val">R$ 1.234</span></li>
   … <li class="total"><span class="rot">Custos</span><span></span><span class="val">R$ 2.900</span></li></ul>
   Barra na mesma cor pra todos (é magnitude); .bar.vermelha/.ambar/.azul/.cinza quando o item tiver sentido próprio. */
.composicao { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.composicao > * { display: grid; grid-template-columns: minmax(96px, 34%) minmax(0, 1fr) auto; align-items: center; gap: 10px; min-width: 0; }
.composicao .rot { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composicao .bar { height: 10px; }
.composicao .val { font-weight: 600; white-space: nowrap; text-align: right; }
.composicao .rot .sub, .composicao .val .sub { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
/* o vigente embaixo do rótulo ("Frete € 5,90 por enviado") quebra linha em vez de ser cortado sem reticências a 390 px */
.composicao .rot .sub { white-space: normal; overflow-wrap: anywhere; }
.composicao > .total { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 2px; }
.composicao > .total .rot, .composicao > .total .val { color: var(--text); font-weight: 700; }

/* barra segmentada: UMA barra com os itens lado a lado (soma = 100 %); cores na ordem das séries (--serie-1…8) ou por
   classe s1…s8 — e a legenda com <i class="s1"></i> na mesma classe, pra cor seguir o item e não a posição
   <div class="bar-seg"><i class="s1" style="width:40%" title="Produto 40%"></i><i class="s2" style="width:25%"></i>…</div>
   <ul class="legenda"><li><i class="s1"></i>Produto · R$ 1.234</li>…</ul>  — até 8 itens; o resto vira "outros". */
.bar-seg { display: flex; height: 12px; border-radius: var(--pilula); overflow: hidden; background: var(--pill); }
.bar-seg > i { display: block; height: 100%; flex: 0 0 auto; min-width: 0; }
.bar-seg > i:not(:last-child) { border-right: 2px solid var(--card); }
.bar-seg > i:nth-child(8n+1) { background: var(--serie-1); }
.bar-seg > i:nth-child(8n+2) { background: var(--serie-2); }
.bar-seg > i:nth-child(8n+3) { background: var(--serie-3); }
.bar-seg > i:nth-child(8n+4) { background: var(--serie-4); }
.bar-seg > i:nth-child(8n+5) { background: var(--serie-5); }
.bar-seg > i:nth-child(8n+6) { background: var(--serie-6); }
.bar-seg > i:nth-child(8n+7) { background: var(--serie-7); }
.bar-seg > i:nth-child(8n+8) { background: var(--serie-8); }
.bar-seg > i.s1, .legenda i.s1 { background: var(--serie-1); }
.bar-seg > i.s2, .legenda i.s2 { background: var(--serie-2); }
.bar-seg > i.s3, .legenda i.s3 { background: var(--serie-3); }
.bar-seg > i.s4, .legenda i.s4 { background: var(--serie-4); }
.bar-seg > i.s5, .legenda i.s5 { background: var(--serie-5); }
.bar-seg > i.s6, .legenda i.s6 { background: var(--serie-6); }
.bar-seg > i.s7, .legenda i.s7 { background: var(--serie-7); }
.bar-seg > i.s8, .legenda i.s8 { background: var(--serie-8); }
.bar-seg > i.outros, .legenda i.outros { background: var(--muted); }
.legenda { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 8px 0 0; padding: 0; list-style: none; color: var(--muted); font-size: 12px; }
.legenda i { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 3px; vertical-align: -1px; background: var(--muted); }
.legenda b, .legenda strong { color: var(--text); font-weight: 600; }

/* ---------- tela Custos (pages/custos.php; antes era um <style> inline no fim do <main>) ---------- */
.cu-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.cu-chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border: 1px solid var(--border);
  border-radius: var(--pilula); background: var(--pill); font-size: 12px; white-space: nowrap;
}
.cu-chip .badge { padding: 0 7px; font-size: 11px; }
.cu-imp-linha { padding: 10px 0; border-top: 1px solid var(--border); }
/* listas do relatório de importação (ul); a tabela de custos por loja é .table.compacta.cu-tabela */
ul.cu-lista { margin: 0; padding-left: 18px; font-size: 13px; }
ul.cu-lista li { margin: 2px 0; }
.cu-form-itens .campo label { font-size: 12px; }
.cu-form-itens .campo small { display: block; font-size: 11px; margin-top: 2px; }
.cu-hist tr.cu-grupo td { border-top: 2px solid var(--border); }
.cu-vig td, .cu-hist td { vertical-align: middle; }
/* observação do custo: uma linha com reticências (o texto inteiro fica no title); a obs do CSV inicial tem ~300 caracteres */
.cu-obs { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }

/* ---------- utilidades ---------- */
.linha { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.entre { justify-content: space-between; }
.esconde-cel { display: none; }
.oculto { display: none !important; }
.sep { height: 1px; background: var(--border); margin: 12px 0; }
/* <summary> é uma ação (abre um formulário): azul como os links; o verde fica pra dinheiro (brief, princípio 1) */
details > summary { cursor: pointer; color: var(--blue-text); font-weight: 600; }
details > summary .muted { color: var(--muted); font-weight: 400; }
/* card que ocupa a linha inteira dentro de um .grid-2/.grid-3 (tabela larga, ex. rodadas do coletor na Config) */
.grid > .largo { grid-column: 1 / -1; }
/* pares rótulo/valor numa linha ("taxas usadas: conf. 93% · entrega 60%"): <ul class="kv"><li>Confirmação <b>93%</b></li>…</ul> */
.kv { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; padding: 0; list-style: none; color: var(--muted); font-size: 13px; }
.kv b, .kv strong { color: var(--text); font-weight: 600; }
/* lista de definição em duas colunas: <dl class="dl"><dt>…</dt><dd>…</dd></dl> (.ped-dl e .cfg-dl abaixo são variações) */
.dl { display: grid; grid-template-columns: minmax(100px, 160px) 1fr; gap: 6px 12px; margin: 0; }
.dl dt { color: var(--muted); font-size: 13px; font-weight: 500; padding-top: 1px; }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; letter-spacing: 0; }

/* ---------- telas Pedidos, Config e Lojas (CSS que morava em <style> dentro das páginas; §8.4: CSS é da fundação) ---------- */
/* Pedidos: detalhe (dl + lista de marcações), filtros e linhas da lista */
.ped-dl { display: grid; grid-template-columns: minmax(90px, 130px) 1fr; gap: 6px 12px; margin: 0; }
.ped-dl dt { color: var(--muted); font-size: 13px; font-weight: 500; letter-spacing: -0.01em; padding-top: 1px; }
.ped-dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.ped-marcs { list-style: none; padding: 0; margin: 0 0 14px; }
.ped-marcs li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px solid var(--border); }
.ped-marcs li:last-child { border-bottom: 0; }
.ped-marcs form { margin-left: auto; }
/* no celular o .periodo-form é coluna: flex-basis viraria ALTURA, por isso a busca é 100% de largura e só no desktop cresce */
.ped-filtros .ped-busca { flex: 0 0 auto; width: 100%; min-width: 0; }
.ped-filtros .select { width: auto; max-width: 100%; }
/* 5 chips (Hoje · Ontem · 7 dias · 30 dias · Tudo) não cabem em 328 px e a barra de rolagem é invisível: quebram linha */
.ped-filtros .chips { flex-wrap: wrap; }
.ped-linha { cursor: pointer; }
/* linha fora dos válidos (duplicado, cancelado, teste): texto em cinza, sem opacity — os selos que explicam o porquê
   (dup, cancelado Shopify, shopify) ficam inteiros e legíveis (≥ 4,5:1); a hora (link) continua em destaque */
.ped-linha.fora td { color: var(--muted); }
.ped-linha.fora td:first-child a { color: var(--text); }
/* Config: lista de dados */
.cfg-dl { display: grid; grid-template-columns: minmax(110px, 160px) 1fr; gap: 5px 12px; margin: 0; font-size: 14px; }
.cfg-dl dt { color: var(--muted); font-size: 13px; font-weight: 500; letter-spacing: -0.01em; padding-top: 1px; }
.cfg-dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
/* Lojas: implantações de uma loja e "novas implantações"; o select "Mover pra…" lista 42 lojas (sigla + nome) e sem o
   teto a largura intrínseca (~440 px) vazava do card a 390 px */
.lj-impl { padding: 10px 0; border-bottom: 1px solid var(--border); }
.lj-impl:last-child { border-bottom: 0; }
.lj-impl-meta { font-size: 13px; margin-top: 2px; }
.lj-impl .form-inline { max-width: 100%; }
.lj-impl .form-inline .select { max-width: 100%; min-width: 0; }
.lj-nova { padding: 12px 0; border-top: 1px solid var(--border); }
.lj-form-vinc .select { max-width: min(420px, 100%); min-width: 0; }

/* ---------- desktop ---------- */
@media (min-width: 720px) {
  .app { padding: 22px 24px 40px; }
  .rodape { padding: 8px 24px 24px; }
  h1.titulo { font-size: 24px; }
  .card { padding: 16px 18px; }
  .topbar {
    padding: 10px 24px; gap: 18px;
    background: var(--topbar);
    -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  }
  .brand-nome { display: inline; }
  .topbar-acoes { gap: 8px; }
  .coletor-status { font-size: 13px; margin-right: 4px; }
  .nav {
    position: static; display: flex; gap: 2px; padding: 0; background: transparent;
    border: 0; -webkit-backdrop-filter: none; backdrop-filter: none;
  }
  .nav a { flex: none; flex-direction: row; gap: 7px; padding: 7px 13px; font-size: 14px; letter-spacing: -0.01em; border-radius: var(--pilula); }
  .nav a .ico { width: 17px; height: 17px; padding: 0; border-radius: 0; }
  .nav a:hover { background: var(--hover); }
  .nav a.ativo { background: var(--pill); }
  .nav a.ativo .ico { background: transparent; padding: 0; }
  .pagina-cab { flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; }
  .periodo-form { flex-direction: row; align-items: center; flex-wrap: wrap; }
  .periodo-form .input { flex: none; width: 150px; }
  .periodo-form .loja-sel { width: auto; max-width: 260px; }
  .grid-2, .grid-2-sempre { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  /* 720–1023 (tablet): 3 colunas, não 4 — com 4, a 768 px o card tinha 135 px internos e "R$ 375.953" a 28 px estourava
     no vizinho. O KPI principal ocupa 2 das 3 colunas (8 cards = 3 linhas cheias) e a fonte acompanha a largura. */
  .grid-4 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi .v { font-size: clamp(20px, 3vw, 28px); }
  .kpi.principal { grid-column: span 2; }
  .kpi.principal .v { font-size: clamp(28px, 4.4vw, 38px); }
  .coletor-status .ico { display: none; }
  .esconde-cel { display: initial; }
  th.esconde-cel, td.esconde-cel { display: table-cell; }
  .form-login { margin-top: 10vh; }
}
@media (min-width: 1024px) {
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kpi .v { font-size: 30px; }
  .kpi.principal { grid-column: auto; }
  .kpi.principal .v { font-size: 40px; }
}
/* A topbar numa linha só (marca + 6 itens de nav + Atualizar/estado/tema/sair) precisa de ~1.090 px.
   720–899 (tablet em pé): vira duas linhas, a nav embaixo, inteira. 900–1099: uma linha sem o nome da marca
   (a pílula "PC" basta); até 979 o texto "coletor há N min" também sai (fica no title do botão). */
@media (min-width: 720px) and (max-width: 919px) {
  .topbar { flex-wrap: wrap; row-gap: 2px; padding-bottom: 6px; }
  .topbar-acoes { order: 2; }
  .nav { order: 3; flex: 1 1 100%; justify-content: flex-start; margin-left: -10px; }
}
@media (min-width: 920px) and (max-width: 1139px) {
  .brand-nome { display: none; }
  .nav a { padding: 7px 10px; }
}
@media (min-width: 920px) and (max-width: 999px) {
  .coletor-status { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media print {
  .topbar, .nav, .periodo-form, .rodape, .form-atualizar { display: none; }
  body { background: #fff; color: #000; }
}
