:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #14171f;
  --muted: #6a7280;
  --line: #e4e7ec;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --ok: #15803d;
  --ok-soft: #e3f6e9;
  --warn: #b45309;
  --warn-soft: #fdf0dc;
  --off: #5b6472;
  --off-soft: #eceff3;
  --err: #b42318;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #171b22;
    --text: #e8ebf0;
    --muted: #98a1b0;
    --line: #262c36;
    --accent: #6c9bff;
    --accent-soft: #1b2740;
    --ok: #5fd08a;
    --ok-soft: #16301f;
    --warn: #f0b35b;
    --warn-soft: #382a12;
    --off: #a9b1bf;
    --off-soft: #232933;
    --err: #ff8a7a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1, h2 { margin: 0; font-weight: 650; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }

/* Botões e campos */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 8px 12px; border-radius: 8px; font: inherit; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.btn.primary:disabled { opacity: .6; cursor: default; }
.btn.ghost { background: transparent; }
.btn.toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 36px;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
label input, label select { font-size: 14px; color: var(--text); font-weight: 400; }

/* Marca e topo */
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: #fff; font-size: 14px;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.user { display: flex; align-items: center; gap: 10px; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 20px 24px 48px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow);
}
.erro { color: var(--err); margin: 0; font-size: 13px; }

/* Filtros */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.filters-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.kpi .rot { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi .val { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.nota { margin: -4px 2px 0; color: var(--muted); font-size: 12px; }

/* Cartões */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head {
  display: flex; justify-content: space-between; align-items: start; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.card-tools { display: flex; gap: 8px; align-items: center; }
.chart-box { position: relative; height: 260px; padding: 12px 16px 16px; }

/* Tabela */
.table-wrap { overflow-x: auto; }
/* Modo "Organização": esconde Alcance, Cliques e CPC (colunas 4, 5 e 6) */
table.organizacao { min-width: 760px; }
table.organizacao th:nth-child(n+4):nth-child(-n+6),
table.organizacao td:nth-child(n+4):nth-child(-n+6) { display: none; }
table { width: 100%; border-collapse: collapse; min-width: 1000px; }
th, td { padding: 9px 12px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th.left, td.left { text-align: left; }
thead th {
  position: sticky; top: 0; background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 600;
  border-bottom: 1px solid var(--line); cursor: pointer; user-select: none;
}
thead th:hover { color: var(--text); }
thead th.sorted::after { content: " ▼"; font-size: 9px; }
thead th.sorted.asc::after { content: " ▲"; }
tbody tr { border-bottom: 1px solid var(--line); }
tbody tr:hover { background: var(--accent-soft); }
tbody tr.sel { background: var(--accent-soft); }
tbody tr.nivel-conta td { font-weight: 600; }
td.nome { max-width: 420px; }
.nome-wrap { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; }
.seta {
  appearance: none; border: 0; background: transparent; color: var(--muted); width: 22px; height: 22px;
  border-radius: 6px; cursor: pointer; font-size: 11px; flex: none;
}
.seta:hover { background: var(--line); color: var(--text); }
.seta.vazia { visibility: hidden; }
.nome-txt { overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
tbody tr[data-key] { cursor: pointer; }
a.nome-txt { color: inherit; text-decoration: none; }
a.nome-txt:hover { text-decoration: underline; color: var(--accent); }
.ext-ico { margin-left: 5px; font-size: 12px; color: var(--muted); }
a.nome-txt:hover .ext-ico { color: var(--accent); }
.tag {
  flex: none; font-size: 10px; text-transform: uppercase; letter-spacing: .4px; font-weight: 700;
  color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px;
}
.thumb { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; background: var(--off-soft); flex: none; }
img.thumb { cursor: zoom-in; transition: transform .12s ease, box-shadow .12s ease; }
img.thumb:hover { transform: scale(1.12); box-shadow: 0 2px 8px rgba(0, 0, 0, .3); }

/* Imagem ampliada */
.lightbox {
  position: fixed; inset: 0; z-index: 40; background: rgba(8, 10, 14, .82);
  display: grid; place-items: center; padding: 24px; cursor: zoom-out;
}
.lightbox-box {
  position: relative; display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(260px, 1fr); gap: 0;
  width: min(1000px, 100%); max-height: calc(100vh - 48px); overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; cursor: default;
}
.lightbox-img { background: #05070a; display: grid; place-items: center; min-height: 280px; }
.lightbox-img img { width: min(100%, 560px); height: auto; max-height: calc(100vh - 48px); object-fit: contain; display: block; }
.lightbox-info { padding: 22px 20px; overflow-y: auto; display: grid; gap: 10px; align-content: start; }
.lightbox-info h3 { margin: 0; font-size: 17px; line-height: 1.3; word-break: break-word; }
.lightbox-info dl { margin: 0; display: grid; gap: 12px; }
.lightbox-info dt { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; }
.lightbox-info dd { margin: 2px 0 0; white-space: pre-wrap; word-break: break-word; }
.lightbox-info a { color: var(--accent); word-break: break-all; }
.lightbox-fechar {
  position: absolute; top: 10px; right: 10px; z-index: 2; width: 34px; height: 34px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .55); color: #fff; font-size: 16px; cursor: pointer;
}
.lightbox-fechar:hover { background: rgba(0, 0, 0, .8); }
@media (max-width: 760px) {
  .lightbox-box { grid-template-columns: 1fr; overflow-y: auto; }
  .lightbox-img img { max-height: 55vh; }
}
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: var(--off-soft); color: var(--off); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.carregando td { color: var(--muted); font-style: italic; text-align: left; }
.vazio { text-align: center; color: var(--muted); padding: 28px 12px; margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #14171f; color: #fff;
  padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 50; max-width: 90vw;
}
.toast.erro { background: var(--err); }

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .topbar, .wrap { padding-left: 16px; padding-right: 16px; }
  .filters-right { margin-left: 0; width: 100%; justify-content: space-between; }
}
@media (max-width: 480px) {
  .kpi .val { font-size: 20px; }
}
