:root {
  color-scheme: dark;
  --bg: #090909;
  --surface: #111;
  --surface-2: #171717;
  --surface-3: #1d1d1d;
  --text: #f5f5f5;
  --muted: #8b8b8b;
  --faded: #646464;
  --border: #292929;
  --border-strong: #3a3a3a;
  --positive: #43d17b;
  --negative: #ff5d68;
  --warning: #d9ad36;
  --accent: #fff;
  --accent-text: #0a0a0a;
  --shadow: 0 18px 50px rgba(0,0,0,.32);
  --cri-money: #43d17b;
  --cri-money-muted: #86efac;
  --cri-money-hubla: #4ade80;
  --cri-rate: #93c5fd;
  --cri-count: #fcd34d;
  --cri-thead-bg: #161616;
  --cri-thead-fg: #a3a3a3;
  --cri-name: #f5f5f5;
  --cri-row-border: rgba(42, 42, 42, 0.75);
  --cri-row-hover: rgba(255, 255, 255, 0.025);
  --cri-thumb-bg: #1a1a1a;
  --cri-chip-bg: rgba(255, 255, 255, 0.05);
  --funnel-pill-bg: linear-gradient(180deg, #2a2a2a, #151515);
  --funnel-pill-border: var(--border);
  --funnel-pill-value: #f5f5f5;
  --funnel-pill-label: #a3a3a3;
  --sync-badge-bg: rgba(255, 255, 255, 0.04);
  --sync-badge-border: rgba(255, 255, 255, 0.12);
  --sync-badge-kind: #fff;
  --sync-live-bg: rgba(34, 197, 94, 0.12);
  --sync-live-border: rgba(34, 197, 94, 0.4);
  --sync-live-kind: #86efac;
  --sync-snap-bg: rgba(59, 130, 246, 0.12);
  --sync-snap-border: rgba(59, 130, 246, 0.35);
  --sync-snap-kind: #93c5fd;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f2f0;
  --surface: #fff;
  --surface-2: #f7f7f5;
  --surface-3: #ececea;
  --text: #141414;
  --muted: #666;
  --faded: #8b8b8b;
  --border: #dededb;
  --border-strong: #c9c9c5;
  --accent: #111;
  --accent-text: #fff;
  --shadow: 0 18px 50px rgba(0,0,0,.08);
  --positive: #16a34a;
  --negative: #dc2626;
  --warning: #b45309;
  --cri-money: #15803d;
  --cri-money-muted: #166534;
  --cri-money-hubla: #15803d;
  --cri-rate: #1d4ed8;
  --cri-count: #a16207;
  --cri-thead-bg: #f0efec;
  --cri-thead-fg: #6b6b66;
  --cri-name: #141414;
  --cri-row-border: #e8e8e4;
  --cri-row-hover: rgba(0, 0, 0, 0.03);
  --cri-thumb-bg: #ececea;
  --cri-chip-bg: rgba(0, 0, 0, 0.04);
  --funnel-pill-bg: linear-gradient(180deg, #f4f4f1, #eaeae6);
  --funnel-pill-border: #d4d4cf;
  --funnel-pill-value: #141414;
  --funnel-pill-label: #6b6b66;
  --sync-badge-bg: #f4f4f1;
  --sync-badge-border: #d4d4cf;
  --sync-badge-kind: #141414;
  --sync-live-bg: #ecfdf3;
  --sync-live-border: #86efac;
  --sync-live-kind: #166534;
  --sync-snap-bg: #eff6ff;
  --sync-snap-border: #93c5fd;
  --sync-snap-kind: #1e40af;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: "DM Sans", system-ui, sans-serif; }

/* Theme crossfade (View Transitions API) */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.42s;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

/* Fallback when View Transitions unavailable */
html.theme-animating,
html.theme-animating body,
html.theme-animating .sidebar,
html.theme-animating main,
html.theme-animating .app-header,
html.theme-animating .dash-block,
html.theme-animating .creatives-table thead th,
html.theme-animating .creatives-table tbody td,
html.theme-animating .nav-item,
html.theme-animating .icon-btn,
html.theme-animating .sync-badge {
  transition:
    background-color 0.38s cubic-bezier(0.22, 1, 0.36, 1),
    color 0.38s cubic-bezier(0.22, 1, 0.36, 1),
    border-color 0.38s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.38s cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none !important;
  }
  html.theme-animating,
  html.theme-animating * {
    transition: none !important;
  }
}

button, input, select { font: inherit; }
button, select { cursor: pointer; }
[hidden] { display: none !important; }

.login-view { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
.login-brand { padding: clamp(42px, 8vw, 110px); display: flex; flex-direction: column; justify-content: center; background: radial-gradient(circle at 25% 20%, #272727, #080808 58%); }
.login-brand h1 { font-size: clamp(42px, 6vw, 78px); line-height: .98; letter-spacing: -.06em; margin: 20px 0; }
.login-brand > p:last-child { max-width: 520px; font-size: 18px; color: #aaa; }
.eyebrow { letter-spacing: .18em; font-size: 12px; font-weight: 700; }
.brand-logo { display: block; width: auto; object-fit: contain; }
.brand-logo--hero { width: 118px; height: 44px; object-position: left center; }
.brand-logo--login { width: 104px; height: 38px; object-position: left center; }
.brand-logo--sidebar { width: 50px; height: 22px; object-position: left center; }
.brand-mark { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 15px; background: #fff; color: #050505; font-weight: 800; font-size: 28px; }
.brand-mark--small { width: 36px; height: 36px; border-radius: 10px; font-size: 17px; }
.login-panel { display: grid; place-items: center; padding: 32px; }
.login-card { width: min(430px, 100%); padding: 42px; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; box-shadow: var(--shadow); }
.login-card h2 { margin: 22px 0 6px; font-size: 28px; }
.login-card > p { color: var(--muted); margin: 0 0 28px; }
.login-card label, .filters label { display: flex; flex-direction: column; gap: 7px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.login-card > form > input,
.filters input,
.filters select { width: 100%; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 10px; padding: 12px 13px; outline: none; text-transform: none; letter-spacing: 0; }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 48px; }
.password-field button { position: absolute; right: 5px; top: 50%; translate: 0 -50%; width: 36px; height: 36px; display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); }
.password-field button svg { width: 17px; }
.login-card label { margin: 14px 0; }
.login-card > form > input:focus,
.filters select:focus,
.filters input:focus { border-color: var(--border-strong); box-shadow: 0 0 0 3px rgba(127,127,127,.12); }
.form-error { color: var(--negative); min-height: 20px; margin-top: 12px; font-size: 13px; }

.btn { border: 1px solid var(--border-strong); background: var(--accent); color: var(--accent-text); border-radius: 9px; padding: 9px 15px; font-weight: 700; }
.btn--primary { width: 100%; padding: 13px; margin-top: 12px; }
.btn--ghost { background: transparent; color: var(--text); }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border); color: var(--text); background: var(--surface-2); display: grid; place-items: center; }
.icon-btn svg { width: 17px; }
.icon-btn:disabled { opacity: .55; cursor: wait; }
.icon-btn.is-loading svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.app { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 220px; background: var(--bg); border-right: 1px solid var(--border); padding: 18px 12px; display: flex; flex-direction: column; z-index: 20; overflow: hidden; transition: width .2s ease, box-shadow .2s ease; }
.sidebar-brand { display: flex; align-items: center; gap: 9px; min-height: 40px; font-weight: 700; padding: 4px 3px 24px; white-space: nowrap; color: var(--text); }
.sidebar-brand > span { color: var(--text); letter-spacing: 0.02em; }

/* Logo branca → preta no light (arquivo é NYO branco) */
:root[data-theme="light"] .brand-logo--sidebar {
  filter: invert(1);
}
.sidebar-pin-btn { width: 30px; height: 30px; margin-left: auto; flex: 0 0 auto; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); background: var(--surface-2); }
.sidebar-pin-btn:hover, .sidebar-pin-btn.is-pinned { color: var(--text); border-color: var(--border-strong); background: var(--surface-3); }
.sidebar-pin-btn svg { width: 15px; height: 15px; }
.sidebar nav { display: grid; gap: 4px; }
.nav-item { border: 0; background: transparent; color: var(--muted); display: flex; align-items: center; gap: 11px; width: 100%; border-radius: 9px; padding: 11px 12px; text-align: left; }
.nav-item:hover, .nav-item.active { color: var(--text); background: var(--surface-2); }
.nav-item svg { width: 18px; }
.sidebar-foot { margin-top: auto; }
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 12px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  box-sizing: border-box;
}

:root[data-theme="light"] .sidebar-user {
  color: #525252;
}
.sidebar-user svg { width: 18px; height: 18px; flex: 0 0 auto; opacity: 0.85; }
.sidebar-user > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
main { margin-left: 220px; padding: 16px 22px 60px; min-width: 0; transition: margin-left .2s ease; }
body.sidebar-collapsed main { margin-left: 62px; }
.sidebar.collapsed { width: 62px; }
.sidebar.collapsed .sidebar-brand { justify-content: center; padding-left: 0; padding-right: 0; }
.sidebar.collapsed .brand-logo--sidebar { width: 38px; }
.sidebar.collapsed .sidebar-brand > span,
.sidebar.collapsed .nav-item > span,
.sidebar.collapsed .sidebar-user > span,
.sidebar.collapsed .sidebar-pin-btn { display: none; }
.sidebar.collapsed .nav-item,
.sidebar.collapsed .sidebar-user { justify-content: center; padding-left: 0; padding-right: 0; }

@media (min-width: 761px) {
  .sidebar.collapsed:not(.pinned):hover { width: 220px; box-shadow: 18px 0 42px rgba(0,0,0,.4); }
  .sidebar.collapsed:not(.pinned):hover .sidebar-brand { justify-content: flex-start; padding-left: 3px; padding-right: 3px; }
  .sidebar.collapsed:not(.pinned):hover .brand-logo--sidebar { width: 50px; }
  .sidebar.collapsed:not(.pinned):hover .sidebar-brand > span,
  .sidebar.collapsed:not(.pinned):hover .nav-item > span,
  .sidebar.collapsed:not(.pinned):hover .sidebar-user > span,
  .sidebar.collapsed:not(.pinned):hover .sidebar-pin-btn { display: revert; }
  .sidebar.collapsed:not(.pinned):hover .sidebar-pin-btn { display: grid; }
  .sidebar.collapsed:not(.pinned):hover .nav-item,
  .sidebar.collapsed:not(.pinned):hover .sidebar-user { justify-content: flex-start; padding-left: 12px; padding-right: 12px; }
}
.app-header { position: sticky; top: 8px; z-index: 15; height: 82px; background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--border); border-radius: 14px; padding: 15px 20px; display: flex; align-items: center; justify-content: space-between; backdrop-filter: blur(12px); box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.app-header h1 { margin: 0; font-size: 22px; letter-spacing: -.03em; }
.app-header p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.header-actions { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 11px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--surface-3); border: 1px solid var(--border); display: grid; place-items: center; color: var(--text); font-weight: 700; }

.filter-card, .block, .card { background: var(--surface); border: 1px solid var(--border); border-radius: 13px; }
.filter-card { margin-top: 12px; padding: 15px 18px; }
.filter-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 13px; }
.filter-head > div { display: flex; align-items: baseline; gap: 10px; }
.filter-head span { color: var(--muted); font-size: 11px; }
.filters { display: grid; grid-template-columns: 1.2fr 1fr repeat(3, minmax(130px,.9fr)); gap: 12px; }
.filters select:disabled { opacity: .65; cursor: not-allowed; }
.global-message { margin: 12px 0; border: 1px solid rgba(217,173,54,.35); background: rgba(217,173,54,.08); color: #e2bd54; padding: 13px 15px; border-radius: 10px; font-size: 13px; }
.view { display: none; }
.view.active { display: block; }

.block { margin-top: 14px; padding: 16px; }
.block-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.block-title { display: flex; gap: 10px; align-items: flex-start; }
.block-icon { width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 9px; display: grid; place-items: center; }
.block-icon svg { width: 16px; }
.block h2 { margin: 0; font-size: 15px; }
.block-head p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 9px; }
.kpi-grid--four { grid-template-columns: repeat(4, minmax(0,1fr)); }
.kpi-grid--six { grid-template-columns: repeat(3, minmax(0,1fr)); }
.kpi { padding: 15px; min-height: 108px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; }
.kpi-label { color: var(--muted); text-transform: uppercase; font-size: 10px; letter-spacing: .05em; display: flex; align-items: center; gap: 7px; }
.kpi-label svg { width: 15px; }
.kpi-info-btn { margin-left: auto; width: 24px; height: 24px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-3); color: var(--muted); padding: 0; }
.kpi-info-btn:hover { color: var(--text); border-color: var(--border-strong); }
.kpi-info-btn svg { width: 13px; height: 13px; }
.kpi-value { font-size: 23px; margin-top: 12px; font-weight: 700; letter-spacing: -.04em; }
.kpi-meta { color: var(--muted); font-size: 10px; margin-top: 7px; }
.pos { color: var(--positive) !important; }
.neg { color: var(--negative) !important; }
.warn { color: var(--warning) !important; }

.cols-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.cols-3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; }
.card { padding: 15px; }
.card h3 { margin: 0 0 4px; font-size: 13px; }
.card-sub { color: var(--muted); font-size: 11px; margin: 0 0 13px; }
.pnl { overflow: hidden; padding: 0; }
.pnl-head { padding: 15px; }
.pnl-row { display: flex; align-items: center; justify-content: space-between; gap: 15px; border-top: 1px solid var(--border); padding: 11px 15px; color: var(--muted); font-size: 12px; }
.pnl-row strong { color: var(--text); }
.pnl-row--total { background: rgba(67,209,123,.1); font-weight: 700; }
.pnl-row--total strong { font-size: 18px; }
.cost-tag { display: inline-flex; padding: 3px 7px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); font-size: 9px; margin-left: 5px; }

.chart-card { min-height: 320px; }
.chart-wrap { height: 245px; position: relative; }
.chart-wrap--short { height: 200px; }
/* Funil macro horizontal (Sankey / escala log) */
.funnel-main { width: 100%; }
.funnel-main-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2, #141414);
  padding: 8px 6px 4px;
  overflow: hidden;
}
.funnel-main-svg {
  display: block;
  width: 100%;
  height: auto;
}
.funnel-main-foot {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--muted);
  text-align: right;
}
.product-list--funnel .product-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(80px, 1fr) auto;
  gap: 10px;
  align-items: center;
}
.product-funnel-block { margin-bottom: 14px; }
.product-funnel-head {
  margin-bottom: 8px;
}
.product-funnel-head strong {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.product-row-metrics {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  font-variant-numeric: tabular-nums;
}
.product-row-metrics em {
  font-style: normal;
  font-size: 10px;
  color: var(--positive, #43d17b);
}
.product-funnel-note {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--muted);
}
.product-row-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.product-row-name {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.product-row-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.product-row-tags em {
  font-style: normal;
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--border, #2a2a2a);
  border-radius: 999px;
  padding: 1px 7px;
}
.product-row-role {
  color: var(--text, #ddd) !important;
}
@media (max-width: 720px) {
  .product-list--funnel .product-row { grid-template-columns: 1fr; }
  .product-row-metrics { align-items: flex-start; }
}

.attr-track { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; margin: 14px 0; }
.attr-fill { height: 100%; background: var(--positive); }
.product-list { display: grid; gap: 8px; }
.product-row { display: grid; grid-template-columns: minmax(120px,1.3fr) 2fr auto; align-items: center; gap: 10px; font-size: 11px; }
.mini-track { height: 7px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.mini-track > span { display: block; height: 100%; background: #c7c7c7; border-radius: inherit; }

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 11px; }
table { width: 100%; border-collapse: collapse; font-size: 11px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th { color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
th:first-child, td:first-child { text-align: left; }
.source-card { position: relative; overflow: hidden; }
.source-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--text); opacity: .7; }
.source-card .source-name { font-size: 18px; }
.source-actions { display: flex; gap: 8px; margin-top: 15px; flex-wrap: wrap; }
.empty-state .source-actions { justify-content: center; }
.source-actions a { color: var(--text); text-decoration: none; }
.status-pill { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); font-size: 10px; }
.empty-state { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty-state svg { width: 30px; margin-bottom: 10px; }
.transaction-kpis { margin-bottom: 10px; }

.metric-modal-overlay { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 24px; background: rgba(0,0,0,.72); backdrop-filter: blur(8px); }
.metric-modal { width: min(700px, 100%); max-height: min(780px, 90vh); overflow: auto; padding: 20px; border: 1px solid var(--border-strong); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.metric-modal > header { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.metric-modal > header > div { display: flex; align-items: center; gap: 10px; }
.metric-modal h2 { margin: 0; font-size: 20px; }
.metric-modal > header button { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); color: var(--muted); }
.metric-modal > header button svg, .metric-modal-icon svg { width: 16px; }
.metric-modal-icon { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 9px; }
.metric-formula { margin: 15px 0; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); color: var(--muted); font-size: 12px; }
.metric-total { padding: 16px; border: 1px solid var(--border); border-radius: 11px; display: grid; gap: 5px; }
.metric-total > span, .metric-breakdown article > span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.metric-total > strong { font-size: 28px; }
.metric-total small, .metric-breakdown small { color: var(--muted); }
.metric-breakdown { display: grid; grid-template-columns: repeat(2,1fr); gap: 9px; margin-top: 9px; }
.metric-breakdown article { padding: 14px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2); display: grid; gap: 6px; }
.metric-breakdown article strong { font-size: 20px; }
.info-callout { margin-top: 10px; padding: 13px 14px; border: 1px solid rgba(67,209,123,.3); border-radius: 10px; background: rgba(67,209,123,.08); display: grid; gap: 4px; }
.info-callout span { color: var(--muted); font-size: 11px; }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(3,1fr); }
  .kpi-grid--six { grid-template-columns: repeat(2,1fr); }
  .filters { grid-template-columns: repeat(3,1fr); }
}
@media (max-width: 760px) {
  .login-view { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .sidebar { width: 62px; }
  .sidebar-brand span, .sidebar-pin-btn, .nav-item span, .sidebar-user > span { display: none; }
  .sidebar-user { justify-content: center; padding-left: 0; padding-right: 0; }
  main { margin-left: 62px; padding: 8px; }
  body.sidebar-collapsed main { margin-left: 62px; }
  .app-header { padding: 12px; }
  .header-actions > span { display: none; }
  .filters, .kpi-grid, .kpi-grid--four, .kpi-grid--six, .cols-2, .cols-3 { grid-template-columns: 1fr; }
  .metric-breakdown { grid-template-columns: 1fr; }
}
