:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #65635d;
  --grid: #e1e0d9;
  --axis: #8c8b80; /* bordas de campos e botões: 3:1 sobre o fundo (WCAG 1.4.11) */
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #1d68c0; /* azul: GMV, links e ações */
  --accent-fill: #1d68c0; /* fundo de botão cheio (texto branco, 4,5:1) */
  --banner: #b84a15;
  --critical-fill: #b92b2b; /* fundo dos números de aviso */
  --on-critical: #ffffff;
  --warn-fill: #fab219;
  --on-warn: #1a1300;
  --series-2: #eb6834; /* laranja: gasto */
  --good: #006300;
  --critical: #d03b3b;
  --warn: #855500;
  --focus: #1d68c0;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --grid: #2c2c2a;
  --axis: #6f6e69;
  --muted: #898781;
  --accent-fill: #2864c2;
  --banner: #c4501f;
  --critical-fill: #ec6060;
  --on-critical: #1a0505;
  --warn-fill: #fab219;
  --on-warn: #1a1300;
  --focus: #3987e5;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --good: #0ca30c;
  --critical: #ec6060;
  --warn: #fab219;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #6f6e69;
    --muted: #898781;
    --accent-fill: #2864c2;
    --banner: #c4501f;
    --critical-fill: #ec6060;
    --on-critical: #1a0505;
    --warn-fill: #fab219;
    --on-warn: #1a1300;
    --focus: #3987e5;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --good: #0ca30c;
    --critical: #ec6060;
    --warn: #fab219;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.5 var(--font);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

h1, h2 { margin: 0; line-height: 1.25; }
h2 { font-size: 16px; font-weight: 600; }
.muted { color: var(--text-2); }
.sub { margin: 2px 0 14px; color: var(--text-2); font-size: 13px; }
.error { color: var(--critical); margin: 8px 0 0; font-size: 14px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px; display: flex; flex-direction: column; gap: 6px; }
.login-card h1 { font-size: 22px; }
.login-card label { margin-top: 10px; font-size: 13px; color: var(--text-2); }
.login-card .btn { margin-top: 16px; }

/* ---------- componentes ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}

input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--axis); border-radius: 8px; padding: 8px 10px; min-height: 38px;
}
input[type="checkbox"] { min-height: 0; accent-color: var(--series-1); }

.btn { font: inherit; border-radius: 8px; padding: 9px 16px; border: 1px solid var(--axis); background: var(--surface); color: var(--text); cursor: pointer; }
.btn.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; font-weight: 600; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.link { font: inherit; background: none; border: 0; padding: 0; color: var(--series-1); cursor: pointer; text-decoration: underline; }

/* ---------- topo ---------- */
.skip { position: absolute; left: 8px; top: -48px; z-index: 50; background: var(--accent-fill); color: #fff; padding: 10px 14px; border-radius: 8px; text-decoration: none; font-weight: 600; }
.skip:focus { top: 8px; }
.chrome { position: sticky; top: 0; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 24px; min-height: 56px; }
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; margin-right: 6px; }
.spacer { flex: 1; }
#shop-select { min-height: 40px; max-width: 220px; }
.chip {
  font: inherit; display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 12px; cursor: pointer;
  background: var(--surface); color: var(--text); border: 1px solid var(--axis); border-radius: 8px; white-space: nowrap;
}
.chip:hover { border-color: var(--series-1); }
.chip[aria-expanded="true"] { border-color: var(--series-1); }
.caret { font-size: 11px; color: var(--text-2); }
.fresh { color: var(--text-2); font-size: 13px; }
.refresh-ic { font-size: 16px; line-height: 1; }
.chip.busy .refresh-ic { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .chip.busy .refresh-ic { animation: none; } }

.pop-wrap { position: relative; }
.popover {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 40; width: 340px; max-width: calc(100vw - 24px);
  display: flex; flex-direction: column; gap: 12px; padding: 16px; background: var(--surface); color: var(--text);
  border: 1px solid var(--axis); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.popover.right { left: auto; right: 0; width: 240px; }
.pop-title { font-weight: 600; font-size: 14px; }
.pop-row { display: flex; flex-direction: column; gap: 4px; }
.pop-row label { font-size: 13px; color: var(--text-2); }
.pop-row select, .pop-row input { width: 100%; max-width: none; }
.pop-custom { display: flex; flex-direction: column; gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; }
.pop-backdrop { display: none; }

.segmented { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; border: 0; border-radius: 0; overflow: visible; }
.segmented button {
  font: inherit; font-size: 14px; padding: 9px 12px; min-height: 40px; background: var(--surface); color: var(--text);
  border: 1px solid var(--axis); border-radius: 8px; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; font-weight: 600; }

.banner { background: var(--banner); color: #fff; text-align: center; padding: 6px 12px; font-size: 13px; font-weight: 600; }

/* ---------- conteúdo ---------- */
.content { max-width: 1200px; margin: 0 auto; padding: 20px 24px 48px; display: flex; flex-direction: column; gap: 16px; }
.status { margin: 0; min-height: 1.4em; font-size: 13px; }

.group-title { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-2); margin: 4px 0 8px; }
.group-title:not(:first-child) { margin-top: 16px; }
.kpis { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.kpi .label { color: var(--text-2); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 2px; letter-spacing: -0.01em; }
.kpi .delta { font-size: 12px; color: var(--text-2); margin-top: 2px; min-height: 1.3em; }

/* Itens de grade precisam poder encolher, senão o gráfico dentro deles estoura a largura da tela. */
.grid-2 > *, .card, .chart-box { min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.chart-box { position: relative; height: 280px; }

.table-view { margin-top: 10px; font-size: 13px; }
.table-view summary { cursor: pointer; color: var(--text-2); }
.table-wrap, .table-view > div { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; white-space: normal; }
th { color: var(--text-2); font-weight: 600; font-size: 12px; }
td.num, th.num { font-variant-numeric: tabular-nums; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: 12px; }
.badge.below { color: var(--critical); }
.badge.ok { color: var(--good); }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row .bar-head { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.bar-row .bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-val { color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-track { height: 10px; margin-top: 4px; background: var(--grid); border-radius: 4px; }
.bar-fill { height: 100%; background: var(--series-1); border-radius: 4px; min-width: 2px; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 10px 0 12px; }
.filters input[type="search"] { flex: 1 1 160px; }
#ship-table th:nth-child(2), #ship-table td:nth-child(2) { text-align: left; }
#recon-wallet th:nth-child(2), #recon-wallet td:nth-child(2), #recon-wallet th:nth-child(3), #recon-wallet td:nth-child(3) { text-align: left; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; font-size: 13px; color: var(--text-2); }
.pager button:disabled { opacity: .45; cursor: default; }
#wallet-summary { margin: 0 0 6px; font-size: 13px; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--text-2); }

.empty { color: var(--text-2); font-size: 14px; padding: 12px 0; }
.notes { color: var(--muted); font-size: 12px; }
.notes p { margin: 2px 0; }

@media (max-width: 820px) {
  .grid-2 { grid-template-columns: 1fr; }
  /* Cabeçalho de uma linha (cerca de 56 px) e fixo; o seletor de período abre como folha na parte de baixo. */
  .topbar { padding: 6px 12px; gap: 8px; }
  .brand { display: none; }
  #shop-select { flex: 1 1 80px; min-width: 80px; max-width: none; min-height: 44px; }
  .topbar { gap: 6px; }
  .pop-wrap { flex: none; min-width: 0; }
  .fresh, .caret { display: none; }
  .chip { min-height: 44px; padding: 6px 8px; gap: 4px; }
  #period-label { overflow: hidden; text-overflow: ellipsis; max-width: 104px; }
  #period-trigger .caret { display: inline; }
  select, input:not([type="checkbox"]) { min-height: 44px; }
  .check, button.camp-link { min-height: 44px; display: inline-flex; align-items: center; }
  .detail-head { flex-wrap: wrap; }
  #attention-toggle { white-space: nowrap; }
  .popover {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; max-width: none; max-height: 85vh; overflow-y: auto;
    border-radius: 16px 16px 0 0; z-index: 60; padding: 18px 16px 24px;
  }
  .popover.right { left: 0; right: 0; width: auto; }
  .pop-backdrop { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, 0.5); }
  .pop-row select, .pop-row input, .btn, .segmented button { min-height: 44px; }
  .tabs { padding: 0 8px; }
  .att-row { grid-template-columns: auto minmax(0, 1fr); gap: 10px 12px; align-items: start; }
  .att-row .btn-action { grid-column: 1 / -1; width: 100%; min-height: 44px; }
  .content { padding: 16px; }
  .chart-box { height: 240px; }
  .kpi .value { font-size: 22px; }
}

@media (forced-colors: active) {
  .segmented button[aria-pressed="true"] { outline: 2px solid; }
  .bar-fill { background: CanvasText; }
}

/* ---------- alertas ---------- */
.alerts { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.alert {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: start;
  padding: 10px 12px; border: 1px solid var(--border); border-left-width: 4px; border-radius: 8px;
}
.alert.critical { border-left-color: var(--critical); }
.alert.warning { border-left-color: var(--warn); }
.alert .tag { font-size: 12px; font-weight: 700; white-space: nowrap; }
.alert.critical .tag { color: var(--critical); }
.alert.warning .tag { color: var(--text); }
.alert .title { font-weight: 600; }
.alert .detail { grid-column: 2; color: var(--text-2); font-size: 13px; }
.alert button.linklike { font: inherit; font-weight: 600; background: none; border: 0; padding: 0; color: var(--text); text-align: left; cursor: pointer; text-decoration: underline; text-decoration-color: var(--axis); }
.ok-line { color: var(--good); font-weight: 600; }

/* ---------- detalhe da campanha ---------- */
.detail-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
button.camp-link { font: inherit; background: none; border: 0; padding: 0; color: var(--series-1); cursor: pointer; text-align: left; text-decoration: underline; }
tr.selected td { background: var(--grid); }


/* ---- abas ---- */
.tabs { display: flex; gap: 4px; padding: 0 24px; border-top: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; font: inherit; background: none; border: 0; border-bottom: 3px solid transparent; padding: 11px 14px; min-height: 44px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text); font-weight: 600; border-bottom-color: var(--series-1); }
.tabs button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.panel { display: flex; flex-direction: column; gap: 16px; }
.panel[hidden] { display: none; }
.dot { display: inline-block; min-width: 20px; height: 20px; padding: 0 6px; margin-left: 6px; border-radius: 10px; font-size: 12px; font-weight: 700; line-height: 20px; text-align: center; vertical-align: middle; color: var(--on-critical); background: var(--critical-fill); }
.dot.warning { background: var(--warn-fill); color: var(--on-warn); }

/* ---- sub-abas (uma pergunta por tela) ---- */
.subtabs { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.subtabs::-webkit-scrollbar { display: none; }
.subtabs button { flex: none; font: inherit; min-height: 40px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--axis); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; }
.subtabs button[aria-selected="true"] { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; font-weight: 600; }
.subtabs .dot.warning { background: var(--warn-fill); }
.subtabs button[aria-selected="true"] .dot { outline: 2px solid #fff; }
.sub-hidden { display: none !important; }
.panel > .note-box + .subtabs { margin-top: 0; }

/* ---- atenção hoje ---- */
.attention-list { list-style: none; margin: 0; padding: 0; }
.att-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 14px 0; border-top: 1px solid var(--border); }
.att-row:first-child { border-top: 0; }
.att-ic { width: 34px; height: 34px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.att-ic.critical { background: rgba(236, 96, 96, 0.16); color: var(--critical); }
.att-ic.warning { background: rgba(250, 178, 25, 0.16); color: var(--warn); }
.att-ic.ok { background: rgba(12, 163, 12, 0.16); color: var(--good); }
.att-title { font-weight: 600; overflow-wrap: anywhere; }
.att-detail { color: var(--text-2); font-size: 13px; overflow-wrap: anywhere; }
.btn-action {
  font: inherit; min-height: 40px; padding: 8px 16px; border-radius: 8px; cursor: pointer; white-space: nowrap;
  background: transparent; color: var(--series-1); border: 1px solid var(--series-1);
}
.btn-action:hover { background: rgba(57, 135, 229, 0.14); }
.att-ok { display: flex; gap: 10px; align-items: center; color: var(--good); font-weight: 600; padding: 6px 0; }
.kpi .delta.good { color: var(--good); }
.kpi .delta.bad { color: var(--critical); }
.kpi .delta.warn { color: var(--warn); }
.value.muted { color: var(--text-2); }
.att-skeleton { height: 54px; border-radius: 8px; background: linear-gradient(90deg, var(--grid), var(--border), var(--grid)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .att-skeleton { animation: none; } }

/* ---- conciliação ---- */
.flow { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr auto 1fr auto 1fr auto 1fr; gap: 8px; align-items: stretch; }
.flow-step { background: var(--page); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.flow-step .label { color: var(--text-2); font-size: 13px; }
.flow-step .value { font-size: 26px; font-weight: 700; margin-top: 2px; }
.flow-step .delta { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.flow-arrow { align-self: center; color: var(--muted); font-size: 12px; text-align: center; white-space: nowrap; }
.badge.warn { color: var(--warn); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
td .neg { color: var(--critical); }
@media (max-width: 820px) {
  .flow { grid-template-columns: 1fr; }
  .flow-arrow { transform: rotate(90deg); }
}

/* ---- ajuda nos cards ---- */
.kpi .label { display: flex; align-items: center; gap: 6px; }
.help { position: relative; display: inline-flex; }
.help-btn { position: relative; font: inherit; font-size: 11px; font-weight: 700; line-height: 1; width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--axis); background: var(--page); color: var(--text-2); cursor: help; padding: 0; }
.help-btn:hover, .help-btn:focus-visible { border-color: var(--series-1); color: var(--series-1); }
.help .tip { display: none; position: absolute; left: 0; top: calc(100% + 6px); z-index: 20; width: 260px; max-width: 70vw; padding: 10px 12px; background: var(--surface); color: var(--text); border: 1px solid var(--axis); border-radius: 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); font-size: 12.5px; font-weight: 400; line-height: 1.4; text-align: left; white-space: normal; }
.help-btn::after { content: ""; position: absolute; inset: -13px; }
.help:hover .tip, .help:focus-within .tip, .help.open .tip { display: block; }

/* ---- alertas compactos ---- */
.alerts-summary { font-size: 13px; font-weight: 400; color: var(--text-2); }
.alert { padding: 6px 10px; gap: 2px 10px; }
.alert .detail { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.alert .title, .alert button.linklike { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.alerts { gap: 6px; }

/* ---- pedidos ---- */
.clip { display: inline-block; max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.filters select { max-width: 100%; }
@media (max-width: 820px) { .clip { max-width: 180px; } }

/* ---- destaque simples: tempo até o dinheiro ---- */
.hero-row { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.hero { background: var(--page); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; min-width: 0; }
.hero .hero-label { color: var(--text-2); font-size: 14px; }
.hero .hero-value { font-size: 40px; font-weight: 700; letter-spacing: -0.02em; margin: 4px 0; }
.hero .hero-note { color: var(--text-2); font-size: 14px; }
@media (max-width: 820px) { .hero-row { grid-template-columns: 1fr; } .hero .hero-value { font-size: 32px; } }

/* ---- lucro ---- */
.note-box { border: 1px solid var(--border); border-left: 4px solid var(--warn); border-radius: 8px; padding: 10px 14px; background: var(--surface); font-size: 14px; }
.neg { color: var(--critical); }
.hero .hero-value.neg { color: var(--critical); }
.bar-fill.neg-fill { background: var(--critical); }
.cost-input { width: 120px; text-align: right; font: inherit; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--axis); background: var(--page); color: var(--text); }
.settings-row { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin: 6px 0; }
.settings-row label { font-size: 14px; color: var(--text-2); }
.save-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 14px; }
#cost-editor > summary { cursor: pointer; font-weight: 600; font-size: 16px; }
#cost-editor[open] > summary { margin-bottom: 10px; }
.subhead { font-size: 15px; margin: 18px 0 2px; }

/* ---- editor de custos com variações ---- */
.cost-list { display: flex; flex-direction: column; }
.cost-item { border-top: 1px solid var(--border); padding: 8px 0; }
.cost-item:first-child { border-top: 0; }
.cost-head { display: grid; grid-template-columns: 1fr auto auto; gap: 14px; align-items: center; }
.cost-head .cost-name { max-width: none; min-width: 0; }
.cost-head .cost-price { color: var(--text-2); font-size: 13px; white-space: nowrap; }
.cost-input.small { width: 76px; }
.cost-variations { margin: 6px 0 4px 14px; font-size: 13px; }
.cost-variations > summary { cursor: pointer; color: var(--text-2); }
@media (max-width: 820px) { .cost-head { grid-template-columns: 1fr auto; } .cost-head .cost-price { display: none; } }
.suggest-row { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin: 4px 0 10px; font-size: 13px; }
#user-email { overflow-wrap: anywhere; }
.att-skeleton + .att-skeleton { margin-top: 8px; }

/* ---- tabelas de dados: ordenar, CSV, páginas e cartões no celular ---- */
.table-scroll { overflow-x: auto; }
.table-tools { display: flex; justify-content: space-between; align-items: center; margin: 0 0 6px; font-size: 13px; }
.btn-link { font: inherit; background: none; border: 0; color: var(--series-1); cursor: pointer; text-decoration: underline; padding: 8px 4px; min-height: 36px; }
.th-btn { font: inherit; font-size: 12px; font-weight: 600; color: var(--text-2); background: none; border: 0; padding: 4px 0; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.th-btn:hover, th[aria-sort="ascending"] .th-btn, th[aria-sort="descending"] .th-btn { color: var(--text); }
.sort-ic { font-size: 10px; opacity: 0.75; }
.sort-mobile { display: none; width: 100%; margin: 0 0 10px; }
th.num .th-btn { flex-direction: row-reverse; }
/* A tabela vira cartões quando NÃO CABE no espaço dela (e não só no celular): nunca precisa de rolagem lateral.
   Quanto mais colunas, mais cedo vira cartão (t-m até 6 colunas, t-l 7 a 8, t-xl 9 ou mais; os limites são a largura mínima em que as colunas cabem). */
.table-wrap, .table-scroll, .table-view > div { container-type: inline-size; }
td.grow { width: 99%; max-width: 0; }
td.grow .camp-link { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.grow .clip { display: block; max-width: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@container (max-width: 560px) {
  .sort-mobile.t-m { display: block; }
  table.stack.t-m thead { display: none; }
  table.stack.t-m, table.stack.t-m tbody, table.stack.t-m tr, table.stack.t-m td { display: block; width: 100%; max-width: none; }
  table.stack.t-m tbody { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
  table.stack.t-m tr { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; background: var(--page); }
  table.stack.t-m td, table.stack.t-m td:first-child { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right; white-space: normal; border-bottom: 0; padding: 5px 0; }
  table.stack.t-m td::before { content: attr(data-label); color: var(--text-2); font-size: 12px; text-align: left; flex: none; max-width: 45%; }
  table.stack.t-m td.stack-title { font-weight: 600; text-align: left; padding-bottom: 8px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
  table.stack.t-m td.stack-title::before { display: none; }
  table.stack.t-m .clip, table.stack.t-m td.grow .clip { display: inline; max-width: none; white-space: normal; overflow: visible; }
}
@container (max-width: 820px) {
  .sort-mobile.t-l { display: block; }
  table.stack.t-l thead { display: none; }
  table.stack.t-l, table.stack.t-l tbody, table.stack.t-l tr, table.stack.t-l td { display: block; width: 100%; max-width: none; }
  table.stack.t-l tbody { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
  table.stack.t-l tr { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; background: var(--page); }
  table.stack.t-l td, table.stack.t-l td:first-child { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right; white-space: normal; border-bottom: 0; padding: 5px 0; }
  table.stack.t-l td::before { content: attr(data-label); color: var(--text-2); font-size: 12px; text-align: left; flex: none; max-width: 45%; }
  table.stack.t-l td.stack-title { font-weight: 600; text-align: left; padding-bottom: 8px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
  table.stack.t-l td.stack-title::before { display: none; }
  table.stack.t-l .clip, table.stack.t-l td.grow .clip { display: inline; max-width: none; white-space: normal; overflow: visible; }
}
@container (max-width: 980px) {
  .sort-mobile.t-xl { display: block; }
  table.stack.t-xl thead { display: none; }
  table.stack.t-xl, table.stack.t-xl tbody, table.stack.t-xl tr, table.stack.t-xl td { display: block; width: 100%; max-width: none; }
  table.stack.t-xl tbody { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
  table.stack.t-xl tr { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; background: var(--page); }
  table.stack.t-xl td, table.stack.t-xl td:first-child { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right; white-space: normal; border-bottom: 0; padding: 5px 0; }
  table.stack.t-xl td::before { content: attr(data-label); color: var(--text-2); font-size: 12px; text-align: left; flex: none; max-width: 45%; }
  table.stack.t-xl td.stack-title { font-weight: 600; text-align: left; padding-bottom: 8px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
  table.stack.t-xl td.stack-title::before { display: none; }
  table.stack.t-xl .clip, table.stack.t-xl td.grow .clip { display: inline; max-width: none; white-space: normal; overflow: visible; }
}

/* ---- carregando, erro, aviso rápido e glossário ---- */
.loading-bar { height: 3px; background: var(--grid); overflow: hidden; position: relative; }
.loading-bar::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 35%; background: var(--series-1); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { left: -35%; } 100% { left: 100%; } }
@media (prefers-reduced-motion: reduce) { .loading-bar::after { animation: none; width: 100%; opacity: 0.5; } }
.fatal { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 14px; border: 1px solid var(--critical); border-radius: 8px; background: var(--surface); }
.fatal span { color: var(--critical); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80; max-width: min(92vw, 420px); padding: 12px 18px; border-radius: 10px; background: var(--text); color: var(--page); font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); }
dialog#glossary { width: min(680px, 94vw); max-height: 86vh; overflow-y: auto; padding: 20px 22px; border: 1px solid var(--axis); border-radius: 14px; background: var(--surface); color: var(--text); }
dialog#glossary::backdrop { background: rgba(0, 0, 0, 0.55); }
.glossary-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.glossary dt { font-weight: 600; margin-top: 14px; }
.glossary dd { margin: 2px 0 0; color: var(--text-2); font-size: 14px; }
@media (max-width: 820px) { .toast { bottom: 16px; } }

.stack-cards { display: flex; flex-direction: column; gap: 16px; }
.clip.wide { max-width: 520px; }
@media (max-width: 820px) { .clip.wide { max-width: none; } }

@media (max-width: 1000px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1000px) { .kpis > .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; } }
@media (max-width: 420px) { .kpi .value { font-size: 22px; } }

.inline-field { display: flex; align-items: center; gap: 8px; }
.inline-field label { font-size: 13px; color: var(--text-2); white-space: nowrap; }
@media (max-width: 820px) { .inline-field { width: 100%; } .inline-field select { flex: 1; } }

.head-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.att-more { margin: 4px 0 0; padding-top: 10px; border-top: 1px solid var(--border); color: var(--text-2); font-size: 13px; }

/* ---- conciliação: Shopee x Bling ---- */
.kpi-btn { display: block; width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.kpi-btn:hover { border-color: var(--axis); }
.kpi-btn[aria-pressed="true"] { border-color: var(--series-1); box-shadow: 0 0 0 1px var(--series-1); }
.kpi-btn .value, .kpi-btn .delta { display: block; }
.kpi .erp-label svg { flex: none; }
.kpi .erp-label.ok { color: var(--good); }
.kpi .erp-label.warn { color: var(--warn); }
.kpi .erp-label.neutral { color: var(--text-2); }
.erp-card { display: flex; flex-direction: column; }
.erp-card-sub { display: block; margin-top: 4px; font-size: 13px; color: var(--text-2); }
.erp-card.tint-ok { background: color-mix(in srgb, var(--good) 9%, var(--surface)); }
.erp-card.tint-warn { background: color-mix(in srgb, var(--warn) 9%, var(--surface)); }
.erp-card.tint-below { background: color-mix(in srgb, var(--critical) 9%, var(--surface)); }
.erp-summary { margin: 0 0 14px; }
.erp-summary:empty { display: none; }
.erp-summary-text { margin: 0; padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font-size: 16px; line-height: 1.5; }
.erp-danger { color: var(--critical); font-weight: 600; }
.erp-situation { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.erp-sub { font-size: 12px; font-weight: 400; }
.erp-legend-intro { margin: 8px 0 0; font-size: 13px; }
.kpi .erp-label.below { color: var(--critical); }
.badge.neutral { color: var(--text-2); }
.badge svg { flex: none; }
.erp-chips .btn[aria-pressed="true"] { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; font-weight: 600; }
.erp-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.erp-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 10px 0; }
.erp-empty { padding: 12px 0; max-width: 62ch; }
.erp-empty h3 { margin: 0 0 6px; font-size: 16px; }
.erp-empty .btn { margin-top: 12px; }
.erp-start { margin: 6px 0 10px; font-size: 14px; }
.erp-start:empty { display: none; }
.erp-start-line { margin: 0; display: flex; align-items: center; gap: 4px 8px; flex-wrap: wrap; }
.erp-start-line .btn { padding: 4px 12px; margin-left: 4px; }
.erp-start-form { margin-top: 8px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); max-width: 62ch; }
.erp-start-form[hidden] { display: none; }
.erp-start-field { display: flex; flex-direction: column; gap: 4px; max-width: 220px; }
.erp-start-field label { font-size: 13px; color: var(--text-2); }
.erp-start-form p { margin: 8px 0 0; font-size: 13px; }
.erp-start-error[hidden] { display: none; }
.erp-start-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.erp-sync-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; margin: 6px 0 12px; }
#erp-sync { margin: 0; font-size: 13px; }
#erp-sync:empty { display: none; }
#erp-sync-action:empty { display: none; }
.erp-sync-now { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; }
.erp-sync-now[aria-busy="true"] svg { animation: spin 0.9s linear infinite; }
@media (prefers-reduced-motion: reduce) { .erp-sync-now[aria-busy="true"] svg { animation: none; } }
#erp-legend { margin: 12px 0 4px; }
.erp-legend { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.erp-legend li { display: flex; gap: 12px; align-items: baseline; }
.erp-legend .badge { flex: none; min-width: 210px; }
#erp-table th:nth-child(n+3), #erp-table td:nth-child(n+3) { text-align: left; }
@media (max-width: 820px) {
  .erp-legend li { flex-direction: column; gap: 2px; }
  .erp-legend .badge { min-width: 0; }
  .erp-banner .btn { width: 100%; }
  .erp-start-line .btn, .erp-sync-now { min-height: 44px; }
  .erp-start-field { max-width: none; }
  .erp-start-actions .btn { flex: 1 1 100%; }
}
