:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --border: #dde2e8;
  --accent: #1b57c3;
  --action-bg: #1f6feb;
  --accent-soft: #e6efff;
  --good: #16682c;
  --good-soft: #e3f5e8;
  --warn: #855900;
  --warn-soft: #fff4d6;
  --bad: #c2261c;
  --bad-soft: #fde8e6;
  --info: #6639ba;
  --info-soft: #f0e9ff;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
/* Tema: claro por padrão; a paleta escura vale quando o esquema efetivo (data-scheme,
   resolvido no base.html) é "dark" — por escolha do usuário ou, no modo automático, pelo sistema */
:root[data-scheme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1f242c;
  --text: #e6e9ee;
  --muted: #9aa5b4;
  --border: #2c333d;
  --accent: #5b9dff;
  --accent-soft: #1b2a44;
  --good: #4cc26b;
  --good-soft: #15301e;
  --warn: #e0b341;
  --warn-soft: #362b0f;
  --bad: #ff6b61;
  --bad-soft: #3a1714;
  --info: #b392ff;
  --info-soft: #2a1f44;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:is(a, button, summary, input, select, textarea):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 3px;
}
.skip-link { position: fixed; left: 12px; top: -100px; z-index: 20; padding: 12px 16px;
  background: var(--surface); color: var(--accent); border: 2px solid var(--accent); }
.skip-link:focus { top: 12px; }
header.top {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
header.top .brand { font-weight: 700; color: var(--text); }
header.top .brand small { color: var(--muted); font-weight: 400; margin-left: 6px; }
nav.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
nav.tabs a {
  padding: 6px 12px; border-radius: var(--radius); color: var(--muted); font-weight: 500;
}
nav.tabs a.active, nav.tabs a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
main { padding: 16px 20px 48px; max-width: 1600px; margin: 0 auto; }
h1 { font-size: 20px; margin: 4px 0 12px; }
h2 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px;
}
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.pills { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.pills a {
  padding: 5px 12px; border: 1px solid var(--border); border-radius: 999px;
  color: var(--text); background: var(--surface);
}
.pills a.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.pills a .n { color: var(--muted); margin-left: 4px; }
.tabs-caption { color: var(--muted); font-size: 11px; margin: 0 0 4px; }
.subtabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.subtabs a { display: inline-flex; align-items: center; gap: 8px; min-height: 40px;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.subtabs a.active { background: var(--accent-soft); border-color: var(--accent); }
.subtabs .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.batch-reason { width: min(100%, 360px); }
form.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
form.filters label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
input, select, textarea, button {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px;
}
textarea { width: 100%; min-height: 70px; }
button, .button {
  background: var(--action-bg); color: #fff; border-color: var(--action-bg); cursor: pointer;
  padding: 6px 14px; border-radius: 6px; display: inline-block;
}
.button.secondary, button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.title { max-width: 420px; }
td.nowrap { white-space: nowrap; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.b-good { background: var(--good-soft); color: var(--good); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-info { background: var(--info-soft); color: var(--info); }
.b-accent { background: var(--accent-soft); color: var(--accent); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.navbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.flash { padding: 8px 12px; border-radius: var(--radius); margin-bottom: 12px; }
.flash.ok { background: var(--good-soft); color: var(--good); }
.flash.err { background: var(--bad-soft); color: var(--bad); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.desc { white-space: pre-wrap; max-height: 320px; overflow: auto; background: var(--surface-2); padding: 10px; border-radius: 6px; }
ul.compact { margin: 0; padding-left: 18px; }
.form-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.form-grid label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.form-grid .wide { grid-column: 1 / -1; }
details summary { cursor: pointer; color: var(--muted); }
@media (max-width: 720px) {
  main { padding: 12px 12px 40px; }
  header.top { padding: 8px 12px; gap: 10px; }
  /* celular: nome e tema na primeira linha, abas embaixo */
  header.top .theme-toggle { order: 2; }
  nav.tabs { order: 3; width: 100%; }
  .subtabs a, form.filters :is(button, .button) { min-height: 44px; }
}
.theme-toggle {
  margin-left: 0; background: transparent; color: var(--muted); border: 1px solid var(--border);
  border-radius: 999px; width: 32px; height: 32px; font-size: 16px; line-height: 1; padding: 0;
}
/* busca global no cabeçalho */
.global-search { margin-left: auto; display: flex; }
.global-search input { width: 150px; padding: 4px 8px; }
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
/* menu "Mais" do cabeçalho */
nav.tabs details.more { position: relative; }
nav.tabs details.more summary {
  list-style: none; padding: 6px 12px; border-radius: var(--radius); color: var(--muted); font-weight: 500;
}
nav.tabs details.more summary::-webkit-details-marker { display: none; }
nav.tabs details.more summary.active, nav.tabs details.more summary:hover { background: var(--accent-soft); color: var(--accent); }
nav.tabs details.more .menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 10; min-width: 190px; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}
nav.tabs details.more .menu a { padding: 7px 10px; }
.good-text { color: var(--good); font-size: 12px; }
.bad-text { color: var(--bad); font-size: 12px; }

/* ordenação pelas colunas e ajuda das métricas */
th a.sort { color: inherit; text-decoration: none; }
th a.sort:hover, th a.sort.active { color: var(--text); text-decoration: underline; }
th a.sort .arrow { margin-left: 3px; font-size: 10px; }
th div a.sort { font-weight: 400; }
a.help, .help-inline {
  display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px;
  border-radius: 50%; border: 1px solid var(--border); font-size: 10px; font-weight: 700;
  color: var(--muted); text-decoration: none; vertical-align: 1px;
}
a.help:hover { color: var(--text); border-color: var(--muted); }
.formula { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; overflow-x: auto; white-space: pre; }
.help-page section { scroll-margin-top: 16px; }
.help-page section:target { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 8px; }

form.quick { margin-top: .4rem; }

/* gráfico de tendência de preço no detalhe do produto */
.price-chart { position: relative; max-width: 640px; margin-bottom: 8px; }
.price-chart svg { width: 100%; height: 200px; background: var(--surface-2); border-radius: 6px; }
.price-chart .axis { fill: var(--muted); font-size: 11px; }
.chart-legend { margin: 4px 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.chart-tip {
  position: absolute; z-index: 6; pointer-events: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px; font-size: 12px; color: var(--text);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .18); white-space: nowrap;
}
.chart-key { display: inline-flex; align-items: center; gap: 5px; }
.chart-key::before { content: ""; width: 14px; height: 3px; background: var(--c); display: inline-block; }

/* filtros recolhíveis e colunas opcionais nas abas de anúncios */
form.filters details.filters-more summary {
  cursor: pointer; color: var(--muted); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 12px; user-select: none; list-style: none;
}
form.filters details.filters-more summary::-webkit-details-marker { display: none; }
form.filters details.filters-more[open] summary { color: var(--accent); border-color: var(--accent); }
.filters-extra {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: end;
  margin-top: 8px; padding: 10px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface-2);
}
form.filters label.chk { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; }
/* sair, no fim do cabeçalho */
header.top form.logout { margin: 0; }
header.top form.logout button { padding: 4px 12px; }
@media (max-width: 720px) { header.top form.logout { order: 2; } }
/* tela de login: um cartão centrado, sem o cabeçalho das abas */
body.login-page main {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 28px 24px 20px; box-shadow: 0 8px 28px rgb(0 0 0 / 8%);
}
.login-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.login-brand { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.login-lead { margin: 6px 0 20px; color: var(--muted); }
.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form label { font-weight: 600; }
.login-form input[type="password"] { padding: 9px 10px; font-size: 16px; }
.login-form button { margin-top: 8px; padding: 10px 14px; font-weight: 600; min-height: 44px; }
.login-foot { margin: 18px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
