:root {
  --bg: #0e1018;
  --panel: #161a26;
  --panel-2: #1b2030;
  --sidebar: #12151f;
  --border: #242a3a;
  --text: #eef1f6;
  --muted: #8a93a6;
  --pink: #01A24A;
  --purple: #01A24A;
  --cyan: #2dd4d4;
  --blue: #3b82f6;
  --teal: #2bd4a8;
  --grad-pink: linear-gradient(135deg, #01A24A 0%, #015627 100%);
  --grad-teal: linear-gradient(135deg, #29c7c7 0%, #4f86f0 100%);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #2a2440 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  transition: background .2s, color .2s;
}

/* ---------- TEMA CLARO ---------- */
body.light {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #f5f6f9;
  --sidebar: #ffffff;
  --border: #e6e8ee;
  --text: #1a1d29;
  --muted: #6b7280;
  background: radial-gradient(1200px 600px at 80% -10%, #ece9f9 0%, #f4f5f8 55%);
}
body.light .sidebar,
body.light .card,
body.light .mini-card,
body.light .chart-card { box-shadow: 0 1px 3px rgba(16,24,40,.04); }

.app { display: flex; min-height: 100vh; }

/* ---------- SIDEBAR ---------- */
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 26px 20px;
  display: flex;
  flex-direction: column;
}
.logo { display: flex; align-items: center; gap: 12px; margin-bottom: 34px; }
.logo-mark {
  width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center; color: #fff;
  background: var(--grad-pink);
}
.logo-mark svg { width: 22px; height: 22px; }

/* Ícones Lucide */
svg.lucide { width: 20px; height: 20px; stroke-width: 2; }
.logo h1 { font-size: 17px; font-weight: 600; }
.logo p { font-size: 11px; color: var(--muted); margin-top: 2px; }

.nav-head {
  font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
  color: var(--pink); margin: 22px 0 10px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: 10px; font-size: 14px;
  color: var(--text); cursor: pointer; transition: .15s;
}
.nav-item svg { width: 17px; height: 17px; }
.nav-item.active { background: linear-gradient(90deg, rgba(1,162,74,.35), rgba(1,162,74,.05)); }
.nav-item:hover { background: rgba(255,255,255,.04); }

.period-select {
  width: 100%; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; font-size: 14px;
  font-family: inherit; cursor: pointer;
}

.brand-nav { display: flex; flex-direction: column; gap: 4px; }
.brand-nav .bn {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 9px;
  font-size: 13px; color: var(--text); cursor: pointer; transition: .15s;
}
.brand-nav .bn:hover { background: rgba(255,255,255,.04); }
.brand-nav .bn.active { background: linear-gradient(90deg, rgba(1,162,74,.35), rgba(1,162,74,.05)); }
.brand-nav .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.brand-nav .bn small { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 24px; }
.btn-refresh, .btn-download {
  border: none; border-radius: 11px; padding: 12px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit; color: #fff;
}
.btn-theme {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 11px; padding: 11px; font-size: 14px; font-weight: 500; cursor: pointer; font-family: inherit;
}
.btn-theme svg { width: 16px; height: 16px; }
.btn-theme:hover { border-color: var(--purple); }
.btn-refresh, .btn-download {
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-refresh svg, .btn-download svg { width: 17px; height: 17px; }
.btn-refresh { background: var(--grad-teal); }
.btn-download { background: var(--grad-pink); }
.btn-refresh:hover, .btn-download:hover { filter: brightness(1.08); }

/* ---------- MAIN ---------- */
.main { flex: 1; padding: 28px 32px 40px; overflow-x: hidden; max-width: 1500px; }

.banner { padding: 14px 18px; border-radius: 12px; margin-bottom: 20px; background: #2a1717; border: 1px solid #5a2020; color: #f59a9a; }
.hidden { display: none; }

.view-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.view-head .btn-copy { margin-left: auto; }
.btn-copy {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--grad-teal); color: #05231a; border: none;
  border-radius: 11px; padding: 9px 15px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-copy svg { width: 16px; height: 16px; }
.btn-copy:hover { filter: brightness(1.08); }
.btn-copy.hidden { display: none; }
.view-head .btn-theme { padding: 9px 15px; }
.view-title { font-size: 22px; font-weight: 700; }
.view-tag {
  font-size: 12px; color: var(--muted); padding: 4px 12px; border-radius: 20px;
  background: var(--panel); border: 1px solid var(--border);
}

/* HERO ROW */
.hero-row {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr;
  gap: 18px;
  margin-bottom: 22px;
}
.hero-card {
  background: var(--grad-pink);
  border-radius: 20px;
  padding: 26px 28px;
  box-shadow: 0 12px 30px rgba(1,162,74,.25);
  display: flex; flex-direction: column; justify-content: center;
  color: #fff; /* texto sempre branco sobre o gradiente verde (vale nos 2 temas) */
}
.hero-label { font-size: 14px; opacity: .9; }
.hero-value { font-size: 52px; font-weight: 700; line-height: 1.05; margin: 6px 0; }
.hero-sub { font-size: 12px; opacity: .85; }

.mini-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  display: flex; align-items: center; gap: 14px;
}
.mini-icon {
  width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; flex-shrink: 0;
}
.mini-icon svg { width: 22px; height: 22px; }
.i-blue { background: rgba(59,130,246,.18); color: #60a5fa; }
.i-purple { background: rgba(1,162,74,.18); color: #a78bfa; }
.i-teal { background: rgba(43,212,168,.18); color: #2bd4a8; }
.mini-label { font-size: 12px; color: var(--muted); }
.mini-value { font-size: 24px; font-weight: 700; margin-top: 4px; }

/* CARDS */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 22px 24px;
  margin-bottom: 22px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-head h2 { font-size: 15px; font-weight: 600; }

.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.lg { position: relative; padding-left: 20px; }
.lg::before { content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 14px; height: 3px; border-radius: 2px; }
.lg-cyan::before { background: var(--cyan); }
.lg-purple::before { background: var(--purple); }

.chart-line canvas { max-height: 300px; }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; align-items: stretch; margin-bottom: 22px; }
.grid-3 .card { margin-bottom: 0; display: flex; flex-direction: column; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; margin-bottom: 22px; }
.grid-2 .card { margin-bottom: 0; }
.chart-fill { position: relative; flex: 1; min-height: 220px; }
.chart-fill canvas { position: absolute; inset: 0; }
#weekdayChartBrand { max-height: 260px; }

/* Tabela de campanhas */
.muted-count { color: var(--muted); font-weight: 500; font-size: 13px; }
.table-wrap { overflow-x: auto; }
.camp-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.camp-table th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
  padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.camp-table th.num, .camp-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.camp-table td { padding: 12px; border-bottom: 1px solid var(--border); }
.camp-table tbody tr:last-child td { border-bottom: none; }
.camp-table tbody tr:hover td { background: rgba(255,255,255,.025); }
.camp-table .cname { font-weight: 500; max-width: 340px; }
.camp-empty { padding: 24px 12px; color: var(--muted); text-align: center; }
.type-pill {
  display: inline-block; font-size: 11px; padding: 3px 10px; border-radius: 20px;
  background: rgba(1,162,74,.15); color: #86e0ab; border: 1px solid rgba(1,162,74,.3);
  white-space: nowrap;
}

/* Abas (Resumo / Anúncios) */
.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab {
  background: var(--panel); color: var(--muted); border: 1px solid var(--border);
  border-radius: 11px; padding: 10px 18px; font-size: 14px; font-weight: 500;
  font-family: inherit; cursor: pointer; transition: .15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--grad-pink); color: #fff; border-color: transparent; }

/* Tabela de anúncios */
.ads-table th, .ads-table td { padding: 12px 10px; }
.ad-cell { display: flex; align-items: center; gap: 12px; min-width: 230px; }
.ad-thumb {
  width: 44px; height: 44px; border-radius: 9px; object-fit: cover; flex-shrink: 0;
  background: var(--panel-2); border: 1px solid var(--border);
}
.ad-thumb.ph { display: grid; place-items: center; color: var(--muted); font-size: 16px; }
.ad-name { font-weight: 500; line-height: 1.25; }
.ad-camp { font-size: 11px; color: var(--muted); margin-top: 2px; }
.sub-label { display: block; font-size: 10.5px; color: var(--muted); margin-top: 2px; font-weight: 400; }

/* Galeria de criativos */
.creatives-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px;
}
.creative-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 16px; overflow: hidden;
  display: flex; flex-direction: column; transition: .15s; cursor: pointer;
}
.creative-card:hover { transform: translateY(-3px); border-color: var(--purple); }
.ad-cell[data-id] { cursor: pointer; }
.cr-rank {
  position: absolute; top: 10px; left: 10px; z-index: 2;
  background: rgba(0,0,0,.6); color: #fff; font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 20px; backdrop-filter: blur(4px);
}
.cr-imgwrap { position: relative; aspect-ratio: 1 / 1; background: #0c0e14; }
.cr-imgwrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cr-imgwrap .ph { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 28px; }
.cr-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.cr-name { font-size: 12.5px; font-weight: 500; line-height: 1.3; min-height: 32px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cr-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 8px; }
.cr-metric { display: flex; flex-direction: column; }
.cr-metric span { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.cr-metric b { font-size: 16px; font-weight: 700; }
.cr-metric.full { grid-column: 1 / -1; }

/* Chip de marca (Visão Geral) */
.brand-chip { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; white-space: nowrap; }
.brand-chip .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.cr-brand {
  position: absolute; top: 10px; left: 10px; z-index: 2; display: inline-flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,.6); color: #fff; font-size: 11px; font-weight: 600;
  padding: 4px 10px; border-radius: 20px; backdrop-filter: blur(4px);
}
.cr-brand .dot { width: 8px; height: 8px; border-radius: 50%; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 30px; }
.lightbox.hidden { display: none; }
.lb-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.82); backdrop-filter: blur(5px); }
.lb-content {
  position: relative; z-index: 1; display: flex; gap: 24px; max-width: 1020px; max-height: 88vh;
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 22px; overflow: auto;
}
.lb-imgwrap { flex-shrink: 0; display: grid; place-items: center; }
.lb-content img { max-width: 560px; max-height: 78vh; border-radius: 12px; object-fit: contain; background: #0c0e14; }
.lb-info { min-width: 230px; }
.lb-info h3 { font-size: 16px; margin-bottom: 4px; line-height: 1.3; }
.lb-camp { font-size: 12px; color: var(--muted); margin-bottom: 18px; }
.lb-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.lb-metrics span { display: block; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.lb-metrics b { font-size: 18px; font-weight: 700; }
.lb-close {
  position: absolute; top: 12px; right: 14px; background: none; border: none; color: var(--muted);
  cursor: pointer; display: grid; place-items: center; padding: 6px; border-radius: 8px;
}
.lb-close svg { width: 20px; height: 20px; }
.lb-close:hover { color: var(--text); background: rgba(255,255,255,.06); }
@media (max-width: 760px) { .lb-content { flex-direction: column; } .lb-content img { max-width: 100%; } }

.donut-wrap { position: relative; height: 210px; display: grid; place-items: center; }
.donut-wrap canvas { max-height: 210px; }

/* Donut com legenda em lista ao lado (Resultados por campanha) */
.donut-row { display: flex; align-items: center; gap: 32px; flex-wrap: wrap; }
.donut-row .donut-wrap { width: 220px; flex-shrink: 0; }
.legend-list { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 11px; }
.legend-list .row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.legend-list .dot { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; }
.legend-list .nm { flex: 1; line-height: 1.3; }
.legend-list .val { font-weight: 600; white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.donut-center { position: absolute; text-align: center; pointer-events: none; }
.donut-center span { display: block; font-size: 24px; font-weight: 700; }
.donut-center small { font-size: 11px; color: var(--muted); }

.brand-legend { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.brand-legend .row { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.brand-legend .dot { width: 10px; height: 10px; border-radius: 50%; }
.brand-legend .val { margin-left: auto; font-weight: 600; }

.foot { margin-top: 26px; color: var(--muted); font-size: 12px; text-align: right; }

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