:root {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --surface-3: #2c2c2a;
  --border: rgba(255, 255, 255, 0.1);
  --grid: #2c2c2a;
  --axis: #383835;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-text: #0ca30c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ef;
  --surface-3: #e9e8e3;
  --border: rgba(11, 11, 11, 0.1);
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6e6c66;
  --accent: #2a78d6;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --good-text: #006300;
  --shadow: 0 1px 2px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px 28px; }
.login-card h1 { margin: 12px 0 4px; font-size: 22px; }
.login-card p { color: var(--text-2); margin: 0 0 20px; }
.brand-mark { width: 44px; height: 44px; border-radius: 12px; background: var(--accent); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 18px; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand-mark.sm { width: 32px; height: 32px; border-radius: 9px; font-size: 14px; }
.brand b { display: block; font-size: 15px; }
.brand span { color: var(--muted); font-size: 12px; }
.nav-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; background: none; text-align: left; cursor: pointer; color: var(--text-2); }
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn.active { background: var(--surface-3); color: var(--text); font-weight: 600; }
.nav-btn svg { width: 18px; height: 18px; flex: none; }
.nav-sep { height: 1px; background: var(--border); margin: 8px 4px; }
.nav-badge { margin-left: auto; background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; font-weight: 600; }
.sidebar-foot { margin-top: auto; padding-top: 12px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.topbar h2 { margin: 0; font-size: 18px; }
.topbar .acct { color: var(--text-2); font-size: 13px; }
.topbar .spacer { flex: 1; }
.menu-toggle { display: none; }
.content { padding: 24px; max-width: 1400px; width: 100%; }

/* ---------- Controles ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface-2); padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--critical); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 16px; height: 16px; }
.select, .input, textarea.input { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; }
.select { width: auto; }
.input:focus, .select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: grid; gap: 4px; margin-bottom: 12px; }
label.field > span { font-size: 12px; color: var(--text-2); font-weight: 600; }
label.field small { color: var(--muted); font-size: 12px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 5px 10px; border-radius: 6px; cursor: pointer; color: var(--text-2); font-size: 13px; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }

/* toggle */
.switch { position: relative; width: 34px; height: 20px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--surface-3); border-radius: 999px; cursor: pointer; transition: .15s; border: 1px solid var(--border); }
.switch span::before { content: ""; position: absolute; width: 14px; height: 14px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(14px); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h3 { margin: 0; flex: 1; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); }
.grid.two { grid-template-columns: 2fr 1fr; }
.grid.half { grid-template-columns: 1fr 1fr; }
.mt { margin-top: 16px; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }

.kpi { padding: 14px 16px; }
.kpi .label { color: var(--text-2); font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.kpi .value { font-size: 24px; font-weight: 650; margin-top: 4px; letter-spacing: -0.01em; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .sub.good { color: var(--good-text); }
.kpi .sub.bad { color: var(--critical); }
.tip { cursor: help; color: var(--muted); font-size: 11px; border: 1px solid var(--border); border-radius: 50%; width: 15px; height: 15px; display: inline-grid; place-items: center; }

/* Veredito */
.verdict { display: flex; gap: 16px; align-items: flex-start; border-left: 4px solid var(--muted); }
.verdict .icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none; color: #fff; font-weight: 700; }
.verdict h3 { font-size: 17px; margin: 0 0 4px; }
.verdict p { margin: 0; color: var(--text-2); }
.verdict.aumentar { border-left-color: var(--good); } .verdict.aumentar .icon { background: var(--good); }
.verdict.manter { border-left-color: var(--warning); } .verdict.manter .icon { background: var(--warning); color: #0b0b0b; }
.verdict.reduzir { border-left-color: var(--critical); } .verdict.reduzir .icon { background: var(--critical); }
.verdict.configurar, .verdict.iniciar { border-left-color: var(--accent); } .verdict.configurar .icon, .verdict.iniciar .icon { background: var(--accent); }
.health { text-align: center; flex: none; padding-left: 16px; border-left: 1px solid var(--border); }
.health b { font-size: 28px; display: block; }
.health span { font-size: 12px; color: var(--muted); }

/* ---------- Tabela ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { font-size: 12px; color: var(--text-2); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; cursor: pointer; user-select: none; }
table.data th:first-child, table.data td:first-child, table.data td.l, table.data th.l { text-align: left; }
table.data td { font-variant-numeric: tabular-nums; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tfoot td { font-weight: 650; background: var(--surface-2); }
.name-cell { display: flex; align-items: center; gap: 10px; min-width: 260px; max-width: 420px; }
.name-cell .nm { white-space: normal; font-weight: 550; }
.name-cell .nm small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.link { color: var(--accent); cursor: pointer; background: none; border: 0; padding: 0; text-align: left; font-weight: 550; }
.link:hover { text-decoration: underline; }
.budget-edit { display: inline-flex; align-items: center; gap: 4px; }
.budget-edit input { width: 80px; text-align: right; padding: 3px 6px; }

.status { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-2); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status.ACTIVE::before { background: var(--good); }
.status.WITH_ISSUES::before, .status.DISAPPROVED::before { background: var(--critical); }
.status.IN_PROCESS::before, .status.PENDING_REVIEW::before { background: var(--warning); }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-3); color: var(--text-2); }
.pill.demo { background: var(--warning); color: #0b0b0b; }
.pill.live { background: var(--good); color: #fff; }

/* ---------- Diagnóstico ---------- */
.diag { display: flex; gap: 12px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); align-items: flex-start; }
.diag + .diag { margin-top: 10px; }
.diag .sev { flex: none; display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px; text-transform: uppercase; letter-spacing: .02em; }
.sev.critico { background: var(--critical); color: #fff; }
.sev.atencao { background: var(--warning); color: #0b0b0b; }
.sev.oportunidade { background: var(--good); color: #fff; }
.diag .body { flex: 1; min-width: 0; }
.diag .body b { display: block; margin-bottom: 2px; }
.diag .body p { margin: 0; color: var(--text-2); }
.diag .act { flex: none; }

/* ---------- Funil ---------- */
.funnel-row { display: grid; grid-template-columns: 130px 1fr 70px; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.funnel-row .bar { height: 22px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.funnel-row .bar i { display: block; height: 100%; background: var(--s1); border-radius: 0 4px 4px 0; min-width: 2px; }
.funnel-row .rate { text-align: right; color: var(--muted); font-size: 12px; }

/* ---------- Anúncios ---------- */
.ads-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.ad-card { display: flex; flex-direction: column; gap: 10px; }
.ad-top { display: flex; gap: 12px; }
.ad-top img { width: 72px; height: 72px; border-radius: 8px; object-fit: cover; background: var(--surface-2); flex: none; }
.ad-top .t { min-width: 0; }
.ad-top .t b { display: block; }
.ad-top .t small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-copy { font-size: 12px; color: var(--text-2); background: var(--surface-2); padding: 8px 10px; border-radius: 8px; }
.mini-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mini-metrics div { background: var(--surface-2); border-radius: 8px; padding: 6px 8px; }
.mini-metrics span { display: block; font-size: 11px; color: var(--muted); }
.mini-metrics b { font-variant-numeric: tabular-nums; font-size: 14px; }
.ad-foot { display: flex; align-items: center; gap: 8px; }

/* ---------- Chat ---------- */
.chat { display: grid; grid-template-columns: 1fr 320px; gap: 16px; height: calc(100vh - 120px); min-height: 500px; }
.chat-main { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-height: 0; }
.chat-log { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 860px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; padding: 10px 14px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; }
.msg.bot { align-self: flex-start; background: var(--surface-2); padding: 12px 16px; border-radius: 14px 14px 14px 4px; width: 100%; }
.msg.bot :first-child { margin-top: 0; } .msg.bot :last-child { margin-bottom: 0; }
.msg.bot h1, .msg.bot h2, .msg.bot h3 { font-size: 15px; margin: 14px 0 6px; }
.msg.bot table { border-collapse: collapse; margin: 8px 0; font-size: 13px; display: block; overflow-x: auto; }
.msg.bot th, .msg.bot td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; }
.msg.bot ul, .msg.bot ol { padding-left: 20px; }
.msg.bot code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; }
.msg .tools { font-size: 11px; color: var(--muted); margin-top: 8px; }
.msg.err { background: color-mix(in srgb, var(--critical) 18%, var(--surface)); }
.typing { color: var(--muted); font-style: italic; }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.chat-input textarea { resize: none; height: 46px; max-height: 160px; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 12px; }
.quick button { font-size: 12px; }
.chat-side { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; min-height: 0; }
.action-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--surface); }
.action-card b { display: block; margin-bottom: 4px; font-size: 13px; }
.action-card p { margin: 0 0 8px; font-size: 12px; color: var(--text-2); }
.action-card .row { display: flex; gap: 6px; }
.action-card.executada { opacity: .7; border-color: var(--good); }
.action-card.recusada { opacity: .5; }
.state { font-size: 11px; font-weight: 700; text-transform: uppercase; }
.state.executada { color: var(--good-text); } .state.recusada { color: var(--muted); }

/* ---------- Planejador ---------- */
.plan-out { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.plan-out .card b { font-size: 22px; display: block; }
.plan-out .card span { font-size: 12px; color: var(--text-2); }

/* ---------- Modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 22px; width: 100%; max-width: 460px; }
.modal h3 { margin: 0 0 14px; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--surface-3); border: 1px solid var(--border); padding: 10px 16px; border-radius: 10px; z-index: 60; box-shadow: 0 6px 24px rgba(0,0,0,.3); max-width: 380px; }
.toast.err { border-color: var(--critical); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.chart-box { position: relative; height: 280px; }
.steps { margin: 0; padding-left: 20px; color: var(--text-2); }
.steps li { margin-bottom: 6px; }
.banner { padding: 10px 14px; border-radius: 10px; background: color-mix(in srgb, var(--warning) 18%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warning) 50%, transparent); margin-bottom: 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- Responsivo ---------- */
@media (max-width: 1000px) {
  .grid.two, .grid.half { grid-template-columns: 1fr; }
  .chat { grid-template-columns: 1fr; height: auto; }
  .chat-main { height: 75vh; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; width: 250px; transform: translateX(-100%); transition: .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .menu-toggle { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .verdict { flex-wrap: wrap; }
  .health { border-left: 0; padding-left: 0; }
  .grid.kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi .value { font-size: 20px; }
}
