:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #6b7480;
  --line: #e4e7eb;
  --accent: #0f766e;
  --accent-soft: #ddf0f3;
  --neg: #b42318;
  --pos: #067647;
  --sel: #eef6f6;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select { font: inherit; color: inherit; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--neg); }
.pos { color: var(--pos); }
.muted { color: var(--muted); }

/* topo */
header {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
header h1 { font-size: 17px; margin: 0; font-weight: 600; }
.rodape { padding: 14px 20px 22px; text-align: center; }
.rodape .status { font-size: 12px; color: var(--muted); }
.rodape a.status { text-decoration: underline; }
header .direita { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 8px;
  padding: 7px 12px; cursor: pointer;
}
.btn:hover { border-color: #c5cbd3; }
.btn.primario { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }

/* filtros */
.filtros {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: end;
  padding: 14px 20px 6px;
}
.filtros label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.filtros input, .filtros select {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: var(--card); min-width: 130px;
}
.filtros input[type=search] { min-width: 260px; }

/* indicadores */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; padding: 8px 20px 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.kpi .rot { font-size: 12px; color: var(--muted); }
.kpi .val { font-size: 19px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* área principal */
main { display: grid; grid-template-columns: minmax(0, 1fr) 430px; gap: 14px; padding: 0 20px 20px; align-items: start; }
.cartao { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }

.tabela-wrap { max-height: calc(100vh - 260px); overflow: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
thead th {
  position: sticky; top: 0; background: #fafbfc; font-size: 12px; font-weight: 600; color: var(--muted);
  z-index: 1;
}
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f8fafb; }
tbody tr.sel { background: var(--sel); box-shadow: inset 3px 0 0 var(--accent); }
td .sub { display: block; font-size: 12px; color: var(--muted); }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: #f0f2f5; color: var(--muted); }
.tag.ok { background: #e7f6ee; color: var(--pos); }
.rodape-tab { padding: 10px; text-align: center; border-top: 1px solid var(--line); }
.vazio { padding: 40px 20px; text-align: center; color: var(--muted); }

/* painel de detalhamento */
.painel { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; }
.painel h2 { font-size: 16px; text-align: center; margin: 0; padding: 14px; border-bottom: 1px solid var(--line); }
.painel .bloco { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.painel .bloco h3 { font-size: 13px; margin: 0 0 8px; }
.par { display: flex; justify-content: space-between; gap: 16px; padding: 3px 0; }
.par .k { color: var(--muted); }
.par .v { text-align: right; }
.liq { width: 100%; }
.liq td { border: 0; padding: 6px 16px; }
.liq tr.total td, .liq tr.final td { background: var(--accent-soft); font-weight: 600; font-size: 15px; }
.liq tr.final td { font-size: 16px; }
.liq tr.sub td:first-child { padding-left: 34px; color: var(--muted); font-size: 13px; }
.liq tr.sub td:last-child { color: var(--muted); font-size: 13px; }
.liq tr.sub td:first-child::before { content: "• "; }
.liq tr.espaco td { padding: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; font-size: 12px; cursor: pointer; background: #fff; }
.chip.atual { border-color: var(--accent); color: var(--accent); }
.aviso { background: #fff7e6; border: 1px solid #fde3b0; border-radius: 8px; padding: 8px 10px; font-size: 13px; }
a { color: var(--accent); }

@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; }
  .painel { position: static; max-height: none; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; }
.login { width: 340px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 26px; }
.login h1 { font-size: 18px; margin: 0 0 4px; }
.login p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.login label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.login input { width: 100%; margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; }
.login .btn { width: 100%; padding: 10px; margin-top: 6px; }
.login .erro { color: var(--neg); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* tabela mais compacta */
.tabela-wrap table { font-size: 13px; }
.tabela-wrap th, .tabela-wrap td { padding: 7px 8px; }
.tabela-wrap td:nth-child(2) { font-size: 12px; max-width: 190px; word-break: break-all; }
.tabela-wrap td:nth-child(4) { max-width: 170px; }
main { grid-template-columns: minmax(0, 1fr) 400px; }

/* ===== Dashboard Extream ===== */
.marca { display: flex; align-items: center; gap: 10px; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff;
        display: grid; place-items: center; font-weight: 700; font-size: 13px; letter-spacing: .5px; }
.modulo { font-size: 12px; color: var(--muted); }
.periodo-txt { align-self: center; padding-bottom: 8px; font-size: 13px; }

.paineis { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 14px; padding: 0 20px 14px; }
.cartao-tit { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 12px 16px 6px; }
.cartao-tit h3 { margin: 0; font-size: 14px; }
.cartao-tit .muted { font-size: 12px; }

.barras { padding: 4px 8px 10px; max-height: 330px; overflow: auto; }
.barra { display: grid; grid-template-columns: 130px minmax(60px, 1fr) 60px 40px 110px; gap: 10px; align-items: center;
         padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.barra:hover { background: #f4f6f8; }
.barra.sel { background: var(--sel); box-shadow: inset 3px 0 0 var(--accent); }
.barra .nome { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trilho { height: 8px; background: #eef0f3; border-radius: 99px; overflow: hidden; }
.fill { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.barra.limpar { display: block; text-align: center; color: var(--accent); font-size: 12px; }

table.top { font-size: 13px; }
table.top td, table.top th { padding: 6px 12px; }
table.top thead th { position: static; background: none; }
table.top .prod { display: block; max-width: 420px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

dialog { border: 0; border-radius: 12px; padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 28, 38, .35); }
.dlg { padding: 20px 22px; width: 360px; }
.dlg.largo { width: min(820px, 92vw); padding: 6px 6px 16px; }
.dlg h3 { margin: 0 0 14px; font-size: 16px; }
.dlg label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.dlg input:not([type=checkbox]) { width: 100%; margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.dlg .acoes { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.dlg .erro, .form-usuario .erro { color: var(--neg); font-size: 13px; min-height: 18px; }
table.usuarios { margin: 6px 0 10px; }
.btn.mini { padding: 3px 9px; font-size: 12px; }
.form-usuario { padding: 0 16px; }
.form-usuario h4 { margin: 10px 0 8px; font-size: 13px; }
.form-usuario .linha { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.form-usuario .linha label { flex: 1 1 140px; margin: 0; }
.form-usuario label.check { flex: 0 0 auto; display: flex; gap: 6px; align-items: center; color: var(--text); font-size: 13px; padding-bottom: 9px; }
.form-usuario p { font-size: 12px; margin: 6px 0 0; }

@media (max-width: 1100px) { .paineis { grid-template-columns: 1fr; } }

/* ===== Resultado e custos ===== */
.kpis { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.kpi .sub { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.destaque { border-width: 2px; }
.kpi.lucro { border-color: #9fd8b8; background: #f2fbf6; }
.kpi.lucro .val { color: var(--pos); }
.kpi.prejuizo { border-color: #f3b4ae; background: #fdf4f3; }
.kpi.prejuizo .val { color: var(--neg); }
.liq.resultado tr.final.lucro td { background: #dff3e7; color: var(--pos); }
.liq.resultado tr.final.prejuizo td { background: #fbe3e1; color: var(--neg); }
.liq tr.item td { font-size: 14px; }
.abas { display: flex; gap: 4px; }
.aba { border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.aba.atual { background: var(--sel); color: var(--accent); }
.aba-corpo { padding: 0 16px; }
.ajuda { font-size: 12px; margin: 4px 0 8px; }
.form-usuario select { width: 100%; margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; }
.form-usuario .linha label.curto { flex: 0 1 110px; }
tr.inativo td { color: var(--muted); }
.linha-busca { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.linha-busca input { flex: 0 1 320px; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.tabela-prod { max-height: 52vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.tabela-prod table { margin: 0; }
.tabela-prod thead th { position: sticky; top: 0; background: #fafbfc; }
tr.sem-custo td { background: #fff8ec; }
.custo-manual { width: 100px; text-align: right; border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }
.custo-manual.salvo { border-color: var(--pos); background: #eefaf3; }
@media (max-width: 1300px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.alerta { margin: 0 20px 10px; padding: 9px 14px; border-radius: 10px; background: #fff7e6; border: 1px solid #fde3b0; font-size: 13px; }
.tag.aviso-tag { background: #fff1d6; color: #9a5b00; }
.tag.dev-tag { background: #ece9fb; color: #4b3cb0; }
#top10 tr { cursor: pointer; }
#top10 tr:hover { background: #f4f6f8; }
#top10 tr.sel { background: var(--sel); box-shadow: inset 3px 0 0 var(--accent); }
.chip-filtro { align-self: center; margin-bottom: 6px; background: var(--sel); border: 1px solid #bfe0df; color: var(--accent);
               border-radius: 99px; padding: 5px 12px; font-size: 13px; max-width: 420px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-filtro .x { cursor: pointer; margin-left: 6px; font-weight: 700; }

.liq .pct { display: inline-block; min-width: 46px; margin-right: 10px; padding: 1px 6px; border-radius: 10px;
  background: #f1f3f5; color: var(--muted); font-size: 11.5px; font-weight: 500; text-align: center; }
.liq tr.total .pct { background: #fff; }

/* ===================== celular ===================== */
.so-celular { display: none; }
.cartao, .kpi { min-width: 0; }
@media (max-width: 760px) {
  body { font-size: 14px; overflow-x: hidden; }
  .so-celular { display: inline-block; }

  /* topo: marca + botão Menu; opções abrem numa lista */
  header { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  header .marca { flex: 1 1 auto; min-width: 0; }
  header h1 { font-size: 16px; }
  #btnMenu { margin-left: auto; }
  header .direita { display: none; width: 100%; flex-direction: column; align-items: stretch; gap: 6px; margin: 0; }
  header .direita.aberto { display: flex; }
  header .direita .btn { width: 100%; text-align: left; padding: 10px 12px; }
  header .direita #usuario { order: -1; font-size: 13px; padding: 2px 2px 4px; }

  /* filtros em duas colunas */
  .filtros { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px 12px 4px; }
  .filtros label { min-width: 0; }
  .filtros input, .filtros select { min-width: 0 !important; width: 100%; padding: 9px 8px; }
  .filtros input[type=search] { min-width: 0; }
  .filtros label:has(#fBusca), .filtros label:has(#fSit), .periodo-txt, .chip-filtro { grid-column: 1 / -1; }
  .periodo-txt { padding: 0; }
  .chip-filtro { max-width: 100%; }
  .alerta { margin: 0 12px 10px; }

  /* indicadores 2 por linha */
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px; padding: 6px 12px 12px; }
  .kpi { padding: 9px 11px; }
  .kpi .val { font-size: 17px; overflow-wrap: anywhere; }
  .kpi .sub { white-space: normal; }
  .kpi.destaque { grid-column: 1 / -1; }

  /* marketplaces e top 10 */
  .paineis { grid-template-columns: 1fr; padding: 0 12px 12px; gap: 12px; }
  .cartao-tit { flex-wrap: wrap; padding: 12px 12px 6px; }
  .barras { max-height: none; padding: 4px 4px 8px; }
  .barra { grid-template-columns: minmax(0, 1fr) 42px 38px 92px; gap: 6px; padding: 8px 8px; font-size: 13px; }
  .barra .trilho { display: none; }
  table.top td, table.top th { padding: 7px 6px; }
  table.top th:nth-child(4), table.top td:nth-child(4) { display: none; }
  table.top .prod { max-width: none; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

  /* lista de pedidos vira cartões */
  main { grid-template-columns: 1fr !important; padding: 0 12px 12px; gap: 12px; }
  .tabela-wrap { max-height: none; overflow: visible; }
  .tabela-wrap table, .tabela-wrap tbody { display: block; }
  .tabela-wrap thead { display: none; }
  .tabela-wrap tbody tr { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; padding: 10px 12px;
                          border-bottom: 1px solid var(--line); }
  .tabela-wrap tbody td { border: 0; padding: 2px 0 !important; max-width: none !important; }
  .tabela-wrap td.c-ped { order: 1; }
  .tabela-wrap td.c-data { order: 2; text-align: right; }
  .tabela-wrap td.c-cli { order: 3; grid-column: 1 / -1; font-weight: 500; }
  .tabela-wrap td.c-comp { order: 4; grid-column: 1 / -1; word-break: break-all; color: var(--muted); }
  .tabela-wrap td.c-mkt { order: 5; grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
  .tabela-wrap td.num { order: 6; display: flex; justify-content: space-between; gap: 8px; text-align: right; font-size: 13px; }
  .tabela-wrap td.num::before { content: attr(data-rot); color: var(--muted); font-size: 12px; text-align: left; }
  .tabela-wrap td.c-data .sub { display: inline; margin-left: 4px; }

  /* detalhamento abaixo da lista */
  .painel { position: static; max-height: none; scroll-margin-top: 64px; }
  .voltar-lista { margin: 10px 12px 0; }
  .liq td { padding: 6px 12px; }
  .liq tr.sub td:first-child { padding-left: 24px; }
  .liq .pct { min-width: 40px; margin-right: 6px; }
  .par { gap: 10px; }
  .par .v { overflow-wrap: anywhere; }

  /* janelas (custos, usuários, senha) */
  .dlg { width: min(360px, 92vw); padding: 16px; }
  .dlg.largo { width: 96vw; }
  .tabela-prod { max-height: 60vh; }
  .linha-busca { flex-wrap: wrap; }
  .rodape { padding: 14px 12px 22px; }
}
