:root {
  --orange:        #f66f00;
  --orange-dark:   #d45c00;
  --orange-light:  #f5a623;
  --purple:        #6f2cf2;
  --purple-dark:   #5a1fd6;
  --purple-soft:   #f0eafe;
  --dark:          #0d0d1a;
  --white:         #ffffff;
  --gray:          #f7f7f7;
  --text:          #333333;
  --muted:         #666666;
  --border:        #ebebeb;
  --green:         #1a7e46;
  --red:           #c0392b;
  --font:          'Ubuntu', system-ui, -apple-system, sans-serif;
  --font-mono:     'JetBrains Mono', monospace;
  --sidebar-w:     244px;
  --radius:        12px;
  --radius-sm:     8px;
}

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

html, body {
  font-family: var(--font);
  color: var(--text);
  background: var(--gray);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }
#app-root { display: flex; min-height: 100vh; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; border-radius: 3px; }

/* ───────── Auth (login / loading / sem acesso) ───────── */
.auth-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--gray); z-index: 100; }
.auth-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 36px 32px; width: 360px; box-shadow: 0 12px 40px rgba(0,0,0,.08); text-align: center; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 8px; }
.auth-sub { font-size: 14px; color: var(--muted); margin-bottom: 24px; line-height: 1.5; }
.auth-google { width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; border: 1px solid var(--border); background: #fff; border-radius: var(--radius-sm); padding: 11px; font-size: 14px; font-weight: 500; font-family: var(--font); color: var(--text); cursor: pointer; }
.auth-google:hover { border-color: var(--orange); }
.auth-sep { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; margin: 16px 0; }
.auth-sep::before, .auth-sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-input { width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; font-family: var(--font); font-size: 14px; margin-bottom: 10px; }
.auth-input:focus-visible { outline: 2px solid var(--orange); outline-offset: 1px; }
.auth-submit { width: 100%; padding: 11px; font-size: 14px; }
.auth-err { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 16px; }
.auth-spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--purple); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.client-square { width: 22px; height: 22px; border-radius: 6px; background: var(--brand, var(--orange)); flex: none; }
.client-wordmark { font-size: 18px; font-weight: 700; color: var(--dark); letter-spacing: -.01em; }
.signout-btn { padding: 7px 11px; font-size: 14px; line-height: 1; }
body.is-placeholder .client-chip::after { content: "placeholder"; font-size: 10px; color: var(--orange); margin-left: 6px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }

/* ───────── Sidebar ───────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 22px 22px 20px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--orange);
  position: relative; flex: none;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 7px;
  border-radius: 3px;
  background: var(--white);
  clip-path: polygon(0 100%, 50% 0, 100% 100%);
}
.brand-name { font-size: 18px; font-weight: 400; letter-spacing: -.01em; color: var(--dark); }
.brand-name strong { font-weight: 700; color: var(--purple); margin-left: 1px; }

#nav { padding: 14px 12px; overflow-y: auto; flex: 1; }
.nav-group { margin-bottom: 18px; }
.nav-group-label {
  font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); padding: 0 12px 8px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-size: 14px; font-weight: 500;
  border-left: 3px solid transparent; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--gray); }
.nav-item.active {
  background: var(--purple-soft); color: var(--purple-dark);
  border-left-color: var(--orange); font-weight: 700;
}
.nav-item .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .45; flex: none; }
.nav-item.active .dot { background: var(--orange); opacity: 1; }

.sidebar-foot { padding: 16px 22px; border-top: 1px solid var(--border); }
.client-brand { display: flex; align-items: center; }
.client-brand svg { display: block; }

/* ───────── Gestão de usuários ───────── */
.users-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.users-head .card-title { margin-bottom: 0; }
.btn-invite {
  background: var(--purple); color: #fff; border: none; border-radius: var(--radius-sm);
  padding: 9px 16px; font-size: 13px; font-weight: 700; font-family: var(--font); cursor: pointer;
}
.btn-invite:hover { background: var(--purple-dark); }
.invite-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; background: var(--gray);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 16px; }
.invite-form input, .invite-form select {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px;
  font-family: var(--font); font-size: 13px; color: var(--text); flex: 1; min-width: 140px;
}
.invite-form input:focus-visible, .invite-form select:focus-visible { outline: 2px solid var(--orange); outline-offset: 1px; }
.u-remove { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; padding: 4px 8px; border-radius: 6px; }
.u-remove:hover { background: #fbeae8; color: var(--red); }

/* ───────── Main + topbar ───────── */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
#page-title { font-size: 22px; font-weight: 700; color: var(--dark); letter-spacing: -.01em; }
.client-chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--gray); border: 1px solid var(--border);
  padding: 5px 12px; border-radius: 20px; font-size: 13px; font-weight: 500; color: var(--text);
}
.client-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand, var(--orange)); }

.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-pill {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--white);
  padding: 7px 12px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--muted); cursor: pointer;
}
.filter-pill:hover { border-color: var(--orange); color: var(--text); }
.filter-pill svg { opacity: .6; }
.filter-select {
  border: 1px solid var(--border); background: var(--white); padding: 7px 10px;
  border-radius: var(--radius-sm); font-size: 13px; font-family: var(--font); color: var(--text);
  cursor: pointer; max-width: 180px;
}
.filter-select:hover { border-color: var(--orange); }
.filter-select:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
.daterange {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border); background: var(--white);
  padding: 7px 14px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; color: var(--text);
}
.daterange-wrap { position: relative; }
.daterange { cursor: pointer; font-family: var(--font); }
.daterange svg:first-child { color: var(--purple); }
.daterange svg:last-child { opacity: .55; margin-left: 2px; }
.daterange:hover { border-color: var(--orange); }
.daterange:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }

.date-panel {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 50;
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,.12); padding: 12px; min-width: 280px;
}
.dp-presets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.dp-preset {
  border: 1px solid var(--border); background: var(--white); border-radius: var(--radius-sm);
  padding: 8px 10px; font-size: 13px; font-family: var(--font); color: var(--text);
  cursor: pointer; text-align: left;
}
.dp-preset:hover { border-color: var(--orange); background: var(--gray); }
.dp-custom { border-top: 1px solid var(--border); padding-top: 12px; }
.dp-row { display: flex; gap: 10px; margin-bottom: 10px; }
.dp-row label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); font-weight: 500; flex: 1; }
.dp-row input[type="date"] {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 8px;
  font-family: var(--font); font-size: 13px; color: var(--text); width: 100%;
}
.dp-row input:focus-visible { outline: 2px solid var(--orange); outline-offset: 1px; }
.dp-apply {
  width: 100%; background: var(--purple); color: #fff; border: none; border-radius: var(--radius-sm);
  padding: 10px; font-size: 13px; font-weight: 700; font-family: var(--font); cursor: pointer;
}
.dp-apply:hover { background: var(--purple-dark); }

#content { padding: 24px 28px 48px; }

/* ───────── Grid + cards ───────── */
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 24px; }
.card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px;
}
.card-title {
  font-size: 14px; font-weight: 700; color: var(--dark);
  margin-bottom: 16px; display: flex; align-items: center; gap: 8px;
}
.card-title::before { content: ""; width: 3px; height: 14px; background: var(--orange); border-radius: 2px; }

.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }

/* ───────── Scorecards ───────── */
.scorecards { display: grid; gap: 16px; margin-bottom: 22px; }
.scorecard {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
}
.sc-label { font-size: 12px; color: var(--muted); font-weight: 500; letter-spacing: .02em; }
.sc-value {
  font-size: 30px; font-weight: 700; color: var(--purple);
  font-variant-numeric: tabular-nums; line-height: 1.1; margin: 6px 0 4px;
  letter-spacing: -.02em;
}
.sc-delta { font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 3px; }
.sc-delta.green { color: var(--green); }
.sc-delta.red { color: var(--red); }

/* ───────── Tables ───────── */
.tbl-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th {
  text-align: right; font-weight: 500; color: var(--muted);
  padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
  font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
}
table.data th:first-child, table.data td:first-child,
table.data th.l, table.data td.l { text-align: left; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; text-align: right; }
table.data tbody tr:hover { background: var(--gray); }
table.data tr.total td { font-weight: 700; color: var(--dark); border-top: 2px solid var(--border); border-bottom: none; }
.cell-tag { font-family: var(--font-mono); font-size: 12px; color: var(--purple-dark); }
.data.wide-names td:nth-child(1), .data.wide-names th:nth-child(1) { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.data.wide-names td:nth-child(2), .data.wide-names th:nth-child(2) { max-width: 230px; overflow: hidden; text-overflow: ellipsis; }
.cell-good { color: var(--green); font-weight: 500; }
.cell-bad  { color: var(--red); font-weight: 500; }
.heat { border-radius: 4px; padding: 3px 8px; font-weight: 500; }
.badge-cell { font-size: 11px; font-weight: 700; padding: 3px 11px; border-radius: 20px; letter-spacing: .02em; display: inline-block; white-space: nowrap; }
.b-red { background: #fbeae8; color: #c0392b; }
.b-orange { background: #fdeedd; color: #a34700; }
.b-purple { background: #f0eafe; color: #5a1fd6; }
.b-green { background: #e6f4ec; color: #1f7a44; }
.b-gray { background: #f0f0f0; color: #666; }

.prose { font-size: 15px; line-height: 1.75; color: var(--text); max-width: 1000px; }
.prose b { color: var(--dark); font-weight: 700; }

/* ───────── Activity strip ───────── */
.activity-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.activity-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; background: var(--white); }
.activity-card .act-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.activity-card .act-label { font-size: 12px; color: var(--muted); margin-top: 8px; display: flex; align-items: center; gap: 7px; }
.activity-card .act-label::before { content: ""; width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--muted); }
.tone-red .act-value { color: var(--red); } .tone-red .act-label::before { background: var(--red); }
.tone-green .act-value { color: var(--green); } .tone-green .act-label::before { background: var(--green); }
.tone-purple .act-value { color: var(--purple); } .tone-purple .act-label::before { background: var(--purple); }
.tone-gray .act-value { color: var(--text); } .tone-gray .act-label::before { background: var(--muted); }

/* ───────── Clickable table rows ───────── */
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover { background: var(--purple-soft); }
table.data tr.clickable td:first-child { position: relative; }

/* ───────── Before/After highlight ───────── */
.beforeafter-card { border-color: rgba(246, 111, 0, .35); border-left: 3px solid var(--orange); }
.ba-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 16px; }
.ba-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--orange); }
.ba-caption { font-size: 13px; color: var(--muted); font-family: var(--font-mono); }
.ba-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.ba-metric { background: var(--gray); border-radius: var(--radius-sm); padding: 14px 16px; }
.ba-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.ba-vals { display: flex; align-items: baseline; gap: 8px; }
.ba-before { font-size: 13px; color: var(--muted); text-decoration: line-through; }
.ba-arrow { color: var(--muted); }
.ba-after { font-size: 20px; font-weight: 700; color: var(--green); font-variant-numeric: tabular-nums; }
.ba-footer { margin-top: 14px; font-size: 13px; color: var(--muted); }
.ba-footer b { color: var(--dark); }

/* ───────── Audit timeline ───────── */
.audit-tl { position: relative; padding-left: 6px; }
.audit-tl::before { content: ""; position: absolute; left: 11px; top: 6px; bottom: 6px; width: 1px; background: var(--border); }
.audit-date { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 14px 0 8px 28px; }
.audit-item { position: relative; display: flex; gap: 14px; padding: 8px 0 8px 28px; }
.audit-dot { position: absolute; left: 6px; top: 13px; width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--white); }
.audit-dot.tone-red { background: var(--red); } .audit-dot.tone-green { background: var(--green); }
.audit-dot.tone-purple { background: var(--purple); } .audit-dot.tone-gray { background: var(--muted); }
.audit-action { font-size: 14px; color: var(--dark); line-height: 1.45; }
.audit-time { font-size: 12px; color: var(--muted); float: right; margin-left: 12px; font-variant-numeric: tabular-nums; }
.audit-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.audit-sep { color: var(--border); }
.audit-foot { display: flex; align-items: center; gap: 7px; margin-top: 14px; margin-left: 28px; font-size: 12px; color: var(--muted); background: var(--gray); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; width: fit-content; }
.audit-live { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }

/* ───────── Finding detail (drill-down) ───────── */
.back-link { display: inline-block; font-size: 13px; color: var(--muted); text-decoration: none; margin-bottom: 18px; }
.back-link:hover { color: var(--orange); }
.fd-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.fd-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700; flex: none; }
.fd-head.is-anom .fd-icon { background: #fbeae8; color: var(--red); }
.fd-head.is-opp .fd-icon { background: #e6f4ec; color: var(--green); }
.fd-headmain { flex: 1; }
.fd-tags { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.fd-ref { font-size: 12px; color: var(--muted); font-family: var(--font-mono); }
.fd-title { font-size: 20px; font-weight: 700; color: var(--dark); }
.fd-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.fd-rc { display: flex; gap: 12px; padding: 8px 0; }
.fd-rc-n { width: 22px; height: 22px; border-radius: 50%; background: var(--purple-soft); color: var(--purple-dark); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; }
.fd-rc-t { font-size: 14px; font-weight: 500; color: var(--dark); }
.fd-rc-d { font-size: 13px; color: var(--muted); margin-top: 2px; }
.fd-action { }
.fd-act-t { font-size: 14px; font-weight: 500; color: var(--dark); }
.fd-act-d { font-size: 13px; color: var(--muted); margin: 4px 0 10px; }
.fd-impact { background: #fff7ef; border-color: rgba(246, 111, 0, .25); margin-top: 16px; }
.fd-imp-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--orange); margin-bottom: 6px; }
.fd-imp-val { font-size: 24px; font-weight: 700; color: var(--dark); font-variant-numeric: tabular-nums; }
.fd-imp-detail { font-size: 12px; color: var(--muted); margin-top: 4px; }

@media (max-width: 1100px) { .activity-strip, .ba-metrics { grid-template-columns: repeat(2, 1fr); } }

/* ───────── Chart canvas ───────── */
.chart { width: 100%; height: 300px; }
.chart.tall { height: 360px; }
.chart.short { height: 240px; }

/* ───────── Funnel (custom) ───────── */
.ofunnel { display: flex; flex-direction: column; gap: 14px; }
.ofunnel-row { display: flex; align-items: center; gap: 22px; }
.ofunnel-bar {
  color: #fff; font-weight: 700; font-size: 14px; letter-spacing: .04em;
  display: flex; align-items: center; justify-content: center;
  height: 88px; flex: none; clip-path: polygon(0 0, 100% 0, 88% 100%, 12% 100%);
}
.ofunnel-metrics { display: flex; gap: 30px; flex-wrap: wrap; }
.ofunnel-big { width: fit-content; margin: 0 auto; }
.ofunnel-big .ofunnel-barwrap { width: 270px; display: flex; justify-content: center; flex: none; }
.ofm-label { font-size: 12px; color: var(--muted); }
.ofm-value { font-size: 20px; font-weight: 700; color: var(--dark); font-variant-numeric: tabular-nums; }
.ofm-delta { font-size: 12px; font-weight: 500; }

.note { font-size: 12px; color: var(--muted); margin-top: 6px; }
.empty-hint { color: var(--muted); font-size: 14px; padding: 40px; text-align: center; }

@media (max-width: 1100px) {
  .grid > [class*="span-"] { grid-column: span 12; }
  .scorecards { grid-template-columns: repeat(2, 1fr) !important; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
