:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #efeeea;
  --border: #e1e0da;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7b7a74;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e8e7e2;
  --good: #0d7d2c;
  --good-bg: #e2f3e6;
  --warn: #8a5a00;
  --warn-bg: #fdf0d2;
  --bad: #b42318;
  --bad-bg: #fde4e1;
  --rep-1: #e34948; --rep-2: #eb6834; --rep-3: #eda100; --rep-4: #8cc63f; --rep-5: #0d9b3a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8d8c84;
    --accent: #3987e5; --series-1: #3987e5; --series-2: #d95926; --grid: #2a2a28;
    --good: #5fd27e; --good-bg: #16301e; --warn: #f2c14e; --warn-bg: #352a10; --bad: #ff8a80; --bad-bg: #3a1716;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8d8c84;
  --accent: #3987e5; --series-1: #3987e5; --series-2: #d95926; --grid: #2a2a28;
  --good: #5fd27e; --good-bg: #16301e; --warn: #f2c14e; --warn-bg: #352a10; --bad: #ff8a80; --bad-bg: #3a1716;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }

/* ---------- topo ---------- */
.topo {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 0;
}
.topo-linha { display: flex; align-items: center; gap: 12px; max-width: 1200px; margin: 0 auto; }
.marca { font-weight: 700; letter-spacing: -.01em; }
.marca small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.topo .espaco { flex: 1; }
.status-coleta { font-size: 12px; color: var(--muted); text-align: right; }
.abas {
  display: flex; gap: 4px; max-width: 1200px; margin: 8px auto 0; overflow-x: auto;
  scrollbar-width: none;
}
.abas::-webkit-scrollbar { display: none; }
.aba {
  border: 0; background: none; padding: 10px 12px; cursor: pointer; white-space: nowrap;
  color: var(--text-2); border-bottom: 2px solid transparent; font-weight: 500;
}
.aba[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.aba .badge { margin-left: 6px; }

main { max-width: 1200px; margin: 0 auto; padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 32px); }
.secao[hidden] { display: none; }

/* ---------- cards ---------- */
.grade { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); margin-bottom: 16px; }
.cartao {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.kpi .rotulo { font-size: 13px; color: var(--text-2); }
.kpi .valor { font-size: 28px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .detalhe { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.alerta { border-color: var(--warn); }
.kpi.alerta .valor { color: var(--warn); }

.graficos { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); margin-bottom: 16px; }
.cartao h2, .cartao h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.cartao .sub { margin: 0 0 10px; font-size: 12px; color: var(--muted); }
.grafico { position: relative; height: 240px; }
.grafico.alto { height: 320px; }

.barra-acoes { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.barra-acoes .espaco { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 6px 12px; cursor: pointer; color: var(--text-2); }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); font-weight: 600; }

.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn.primario { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primario:hover { filter: brightness(1.07); }
.btn.perigo { color: var(--bad); }
.btn.pequeno { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: progress; }

/* ---------- tabelas ---------- */
.tabela-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr.clicavel { cursor: pointer; }
tbody tr.clicavel:hover { background: var(--surface-2); }
tbody tr.sel { background: var(--surface-2); }
.titulo-item { display: flex; gap: 10px; align-items: center; min-width: 220px; }
.titulo-item img { width: 40px; height: 40px; object-fit: contain; border-radius: 6px; background: #fff; flex: none; }
.titulo-item span { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); }

.badge {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.badge.bom { background: var(--good-bg); color: var(--good); }
.badge.aviso { background: var(--warn-bg); color: var(--warn); }
.badge.ruim { background: var(--bad-bg); color: var(--bad); }
.sobe { color: var(--bad); }
.desce { color: var(--good); }

.vazio { color: var(--muted); padding: 18px 4px; text-align: center; font-size: 14px; }
.nota { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

/* ---------- pedidos ---------- */
.lista-pedidos { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.pedido .linha { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.pedido .itens { margin: 8px 0; font-size: 14px; }
.pedido .prazo { font-size: 13px; color: var(--text-2); }

/* ---------- reputação ---------- */
.termometro { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin: 12px 0 6px; }
.termometro div { height: 12px; border-radius: 4px; opacity: .22; }
.termometro div.on { opacity: 1; outline: 2px solid var(--text); outline-offset: 2px; }
.termometro .r1 { background: var(--rep-1); } .termometro .r2 { background: var(--rep-2); }
.termometro .r3 { background: var(--rep-3); } .termometro .r4 { background: var(--rep-4); }
.termometro .r5 { background: var(--rep-5); }
.termometro-rotulos { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.metricas-rep { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); margin-top: 12px; }

/* ---------- concorrentes ---------- */
.form-conc { display: grid; grid-template-columns: 2fr 1fr auto; gap: 8px; }
.form-conc input {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 9px 12px; min-width: 0;
}
.form-conc input:focus, .login input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.lista-conc { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); margin-top: 12px; }
.conc { cursor: pointer; text-align: left; width: 100%; }
.conc:hover { border-color: var(--accent); }
.conc.sel { border-color: var(--accent); outline: 1px solid var(--accent); }
.conc .topo-conc { display: flex; gap: 8px; justify-content: space-between; align-items: start; }
.conc .nome { font-weight: 600; overflow-wrap: anywhere; }
.conc .preco { font-size: 22px; font-weight: 650; margin-top: 6px; font-variant-numeric: tabular-nums; }
.conc .meta { font-size: 12px; color: var(--muted); }
.conc.pausado { opacity: .6; }
.detalhe-conc { margin-top: 16px; }
.erro-msg { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 8px 12px; font-size: 13px; margin: 8px 0; }

/* ---------- login ---------- */
.login-pagina { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login p { margin: 0 0 16px; color: var(--text-2); font-size: 14px; }
.login label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.login input {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px;
}
.login .btn { width: 100%; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 20;
}

@media (max-width: 640px) {
  .kpi .valor { font-size: 24px; }
  .form-conc { grid-template-columns: 1fr; }
  .status-coleta { display: none; }
  .grafico { height: 220px; }
  .graficos { grid-template-columns: 1fr; }
}
