:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --text: #17181c;
  --muted: #6b6e76;
  --line: #e4e1da;
  --accent: #b8860b;      /* dourado da marca */
  --spend: #3d6fb6;
  --conv: #2f8f5b;
  --good: #2f8f5b;
  --warn: #b7791f;
  --bad: #c0392b;
  --proj: #d9cfae;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --card: #181b21; --text: #eceef2; --muted: #9aa0ab; --line: #2a2e36;
    --accent: #d4a62a; --spend: #5a86cc; --conv: #3aa872; --good: #4cc485; --warn: #e0a440;
    --bad: #ef6b5b; --proj: #4a4430; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --card: #181b21; --text: #eceef2; --muted: #9aa0ab; --line: #2a2e36;
  --accent: #d4a62a; --spend: #5a86cc; --conv: #3aa872; --good: #4cc485; --warn: #e0a440;
  --bad: #ef6b5b; --proj: #4a4430; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  padding: max(16px, env(safe-area-inset-top)) 16px 32px;
  max-width: 720px; margin: 0 auto;
}
h1 { font-size: 1.4rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 0.82rem; margin: 0 0 8px; color: var(--muted); font-weight: 600;
     text-transform: uppercase; letter-spacing: 0.04em; }
.eyebrow { margin: 0 0 2px; color: var(--accent); font-weight: 700; font-size: 0.8rem;
           text-transform: uppercase; letter-spacing: 0.06em; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; }

.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
#sync { margin: 4px 0 16px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px;
        padding: 16px; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-2 .card { margin-bottom: 12px; }
.big { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.big .muted { font-size: 1rem; font-weight: 500; }

.bar { position: relative; height: 12px; border-radius: 6px; background: var(--line);
       overflow: hidden; margin: 10px 0 8px; }
.bar span { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 6px; }
#bar-proj { background: var(--proj); }
#bar-spent { background: var(--accent); z-index: 1; }

.alerts:empty { display: none; }
.alert { border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; font-size: 0.92rem;
         border: 1px solid var(--line); background: var(--card); border-left: 4px solid var(--warn); }
.alert.bad { border-left-color: var(--bad); }
.alert.ok { border-left-color: var(--good); }
.alert strong { display: block; margin-bottom: 2px; }

.legend { display: flex; gap: 14px; align-items: center; margin: 0 0 8px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.dot-spend { background: var(--spend); }
.dot-conv { background: var(--conv); }
.dot-accent { background: var(--accent); }
.dot-proj { background: var(--proj); }

.chart { position: relative; margin-top: 4px; touch-action: pan-y; }
.chart svg { display: block; height: auto; max-width: 100%; }
.c-title { font-size: 11px; fill: var(--muted); font-weight: 600; }
.c-val { font-size: 10px; fill: var(--text); font-variant-numeric: tabular-nums; }
.c-x { font-size: 10px; fill: var(--muted); }
.c-axis { stroke: var(--line); stroke-width: 1; }
.c-spend { fill: var(--spend); }
.c-conv { fill: var(--conv); }
.c-hit { fill: transparent; cursor: pointer; }
.c-hit.on { fill: var(--text); fill-opacity: 0.06; }
.tip { position: absolute; top: 0; width: 130px; background: var(--card); border: 1px solid var(--line);
       border-radius: 10px; padding: 8px 10px; font-size: 0.8rem; box-shadow: 0 4px 14px rgba(0,0,0,.12);
       pointer-events: none; display: grid; gap: 1px; font-variant-numeric: tabular-nums; }
.tip[hidden] { display: none; }
details { margin-top: 10px; color: var(--muted); }
details summary { cursor: pointer; }
details table { margin-top: 8px; color: var(--text); }
.camp-meta { margin: 2px 0 0; }
.facts { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 3px; }
.cps { margin: 10px 0 0; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.cps + p { margin-top: 2px; }
.table-wrap { overflow-x: auto; }
td.note { color: var(--muted); font-size: 0.8rem; }
.hint { display: block; font-size: 0.78rem; margin-top: 4px; }
button:disabled { opacity: .6; cursor: progress; }
input:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.campaigns .camp { border-top: 1px solid var(--line); padding: 12px 0; }
.campaigns .camp:first-child { border-top: 0; padding-top: 0; }
.camp-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.camp-name { font-weight: 600; word-break: break-word; }
.badge { font-size: 0.74rem; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
         border: 1px solid var(--line); color: var(--muted); }
.badge.on { color: var(--good); border-color: currentColor; }
.badge.off { color: var(--warn); border-color: currentColor; }
.camp-metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
@media (max-width: 480px) { .camp-metrics { grid-template-columns: repeat(2, 1fr); row-gap: 10px; } }
.camp-metrics div { font-size: 0.8rem; color: var(--muted); }
.camp-metrics b { display: block; font-size: 1rem; color: var(--text); font-variant-numeric: tabular-nums; }
.good { color: var(--good) !important; }
.warn { color: var(--warn) !important; }
.bad { color: var(--bad) !important; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; }
td.num, th.num { text-align: right; }

input, button { font: inherit; }
input { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
        background: var(--bg); color: var(--text); margin-top: 4px; }
label { display: block; font-size: 0.86rem; color: var(--muted); margin-bottom: 10px; }
button { background: var(--accent); color: #111; border: 0; border-radius: 10px; padding: 11px 16px;
         font-weight: 700; cursor: pointer; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); padding: 7px 12px; font-weight: 600; }
.sales-form { margin-top: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.sales-form .full { grid-column: 1 / -1; }
.sales-form button, .sales-form p { grid-column: 1 / -1; }

.login { min-height: 80vh; display: grid; place-items: center; }
.login-card { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line);
              border-radius: 16px; padding: 22px; }
.login-card h1 { margin-bottom: 16px; }
.login-card button { width: 100%; margin-top: 4px; }

footer { margin-top: 20px; text-align: center; }

@media (max-width: 380px) {
  .grid-2 { grid-template-columns: 1fr; gap: 0; }
  .big { font-size: 1.5rem; }
}

/* ---------------------------------------------------------------- abas e visão Agência */
.tabs { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
        gap: 4px; padding: 6px 0 8px; margin: 0 0 8px; background: var(--bg); }
.tabs button { background: var(--card); color: var(--muted); border: 1px solid var(--line);
               padding: 9px 4px; font-size: 0.86rem; font-weight: 600; border-radius: 10px; }
.tabs button[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.filters { margin-bottom: 12px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 999px;
        padding: 7px 12px; font-size: 0.84rem; font-weight: 600; white-space: nowrap; flex: none; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #111; }
.custom-range { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; margin-top: 8px; }
.filter-row { display: flex; gap: 10px; margin-top: 8px; }
.filter-row label:not([hidden]) { flex: 1; min-width: 0; }
.filter-row label, .custom-range label { margin-bottom: 0; }
select { width: 100%; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line);
         background: var(--card); color: var(--text); font: inherit; margin-top: 4px; }
.period-note { margin: 6px 0 0; }
details.node > summary { list-style: none; cursor: pointer; }
details.node > summary::-webkit-details-marker { display: none; }
details.node > summary .camp-name::before { content: "▸ "; color: var(--muted); }
details.node[open] > summary .camp-name::before { content: "▾ "; }
details.adset { border-top: 1px solid var(--line); margin-top: 12px; padding: 12px 0 0 10px;
                border-left: 3px solid var(--line); }
.camp-metrics.six, .node .camp-metrics, .ad .camp-metrics { grid-template-columns: repeat(3, 1fr); }
.ad { display: grid; grid-template-columns: 56px 1fr; gap: 10px; padding: 12px 0 0; margin-top: 12px;
      border-top: 1px dashed var(--line); }
.ads-list .ad:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--line); display: block; }
.ad-body { min-width: 0; }
.delta { font-size: 0.72rem; font-weight: 700; white-space: nowrap; }
.ranks { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.rank { font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.rank.bad { color: var(--bad); border-color: currentColor; }
.rank.good { color: var(--good); border-color: currentColor; }
.alert.good { border-left-color: var(--good); }
.alert.info { border-left-color: var(--spend); }

/* Nos avisos, a cor fica na borda e no título; o texto continua legível. */
.alert.bad, .alert.warn, .alert.good, .alert.info { color: var(--text) !important; }
.alert.bad strong { color: var(--bad); }
.alert.warn strong { color: var(--warn); }
.alert.good strong { color: var(--good); }
.tag { font-size: 0.68rem; font-weight: 600; text-transform: none; letter-spacing: 0; padding: 1px 7px;
       border: 1px solid var(--line); border-radius: 999px; margin-left: 6px; vertical-align: 1px; }

/* ---------------------------------------------------------------- ajuda: termos, glossário e tour */
.top-actions { display: flex; gap: 8px; align-items: flex-start; }
button.round { width: 38px; height: 38px; padding: 0; border-radius: 50%; font-size: 1rem; }
.term { background: none; border: 0; padding: 0; margin: 0; font: inherit; color: inherit; cursor: help;
        font-weight: inherit; text-align: left; text-transform: inherit; letter-spacing: inherit;
        text-decoration: underline dotted; text-underline-offset: 3px; text-decoration-color: var(--muted); }
.term:hover { color: var(--text); }
h2 .term { color: var(--muted); font-weight: 600; }
.filter-help { margin: 2px 0 0; }
.help-dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--text);
               padding: 20px; max-width: min(440px, calc(100vw - 32px)); width: 100%; }
.help-dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.help-dialog h2 { font-size: 1.05rem; color: var(--text); text-transform: none; letter-spacing: 0; margin-bottom: 8px; }
.help-dialog p { margin: 0 0 16px; line-height: 1.5; }
.help-dialog button { width: 100%; }
.tour { position: fixed; inset: 0; z-index: 50; }
.tour-hole { position: fixed; border-radius: 14px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.62);
             outline: 2px solid var(--accent); pointer-events: none; transition: all .2s ease; }
.tour.dim { background: rgba(0, 0, 0, 0.62); }
.tour-card { position: fixed; left: 12px; right: 12px; margin: 0 auto; max-width: 460px; z-index: 51;
             background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 16px;
             padding: 16px 16px 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); }
.tour-card.pos-bottom { bottom: max(12px, env(safe-area-inset-bottom)); }
.tour-card.pos-top { top: max(12px, env(safe-area-inset-top)); }
.tour-card.pos-center { top: 50%; transform: translateY(-50%); }
.tour-card h2 { font-size: 1.05rem; color: var(--text); text-transform: none; letter-spacing: 0; margin: 2px 0 6px; }
.tour-card p { margin: 0 0 12px; line-height: 1.5; }
.tour-card #tour-step { margin: 0; }
.tour-actions { display: flex; gap: 8px; align-items: center; }
.tour-actions .spacer { flex: 1; }
/* Durante o tour, espaço extra no fim para o último destaque subir e o cartão caber embaixo. */
body.touring { padding-bottom: 70vh; }
