:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f8f8f6;
  --border: #e3e3de;
  --text: #121211;
  --text-2: #52514e;
  --muted: #7a7974;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #d6f1ec;
  --series-1: #2a78d6; /* receitas */
  --series-2: #eb6834; /* despesas */
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --good: #1a7f37;
  --warning: #9a6700;
  --serious: #c4501b;
  --critical: #cf222e;
  --wa: #25d366;
  --wa-bubble: #d9fdd3;
  --wa-bg: #efeae2;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #222220; --border: #2f2f2c;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
    --brand: #2dd4bf; --brand-ink: #062b27; --brand-soft: #123b36;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #0ca30c; --series-7: #9085e9; --series-8: #e66767;
    --good: #3fb950; --warning: #d29922; --serious: #f0883e; --critical: #f85149;
    --wa-bubble: #005c4b; --wa-bg: #0b141a;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #222220; --border: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
  --brand: #2dd4bf; --brand-ink: #062b27; --brand-soft: #123b36;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #0ca30c; --series-7: #9085e9; --series-8: #e66767;
  --good: #3fb950; --warning: #d29922; --serious: #f0883e; --critical: #f85149;
  --wa-bubble: #005c4b; --wa-bg: #0b141a;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; }
.wrap { flex-wrap: wrap; }
.gap-s { gap: 8px; } .gap { gap: 14px; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* Botões e formulários */
.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--critical); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn.wa { background: var(--wa); color: #06301a; border-color: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
.form { display: grid; gap: 12px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--text-2); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.error { color: var(--critical); margin: 0; min-height: 1em; font-size: 13px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 7px 12px; font: inherit; font-size: 13px; font-weight: 600; color: var(--text-2); cursor: pointer; }
.seg button.active { background: var(--brand-soft); color: var(--text); }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, var(--brand-soft), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 16px; }
.auth-features { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 13px; color: var(--text-2); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 10px; padding: 4px; }
.tab { border: 0; background: transparent; padding: 8px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; color: var(--text-2); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 17px; }
.brand.big { font-size: 22px; }
.logo { display: inline-block; width: 32px; height: 32px; border-radius: 9px; object-fit: cover; }

/* Layout */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 22px; padding: 20px 14px; border-right: 1px solid var(--border); background: var(--surface); }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; color: var(--text-2); text-decoration: none; font-weight: 600; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--brand-soft); color: var(--text); }
.nav .ico { width: 22px; text-align: center; }
.sidebar-foot { margin-top: auto; display: grid; gap: 10px; }
.user-chip { font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; }
.user-chip b { display: block; color: var(--text); }
.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar h1 { font-size: 20px; }
.view { padding: 22px 28px 40px; display: grid; gap: 18px; max-width: 1400px; }
.wa-pill { font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border); color: var(--text-2); }
.wa-pill .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.wa-pill.on .dot { background: var(--wa); }

/* Cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.card-head .sub { font-size: 12px; color: var(--muted); }
.grid { display: grid; gap: 18px; }
.g-kpi { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-21 { grid-template-columns: 2fr 1fr; }
.g-12 { grid-template-columns: 1fr 2fr; }
.kpi { padding: 16px; }
.kpi .label { font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; }
.kpi .value { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: clamp(18px, 1.55vw, 23px); font-weight: 750; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .delta { font-size: 12px; margin-top: 4px; color: var(--muted); }
.delta.up-good, .delta.down-good { color: var(--good); }
.delta.up-bad, .delta.down-bad { color: var(--serious); }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 300px; }
.chart-box.short { height: 200px; }

/* Score */
.score { display: grid; grid-template-columns: 140px 1fr; gap: 18px; align-items: center; }
.ring { width: 140px; height: 140px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--ring-color) calc(var(--p) * 1%), var(--surface-2) 0); }
.ring > div { width: 112px; height: 112px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; text-align: center; }
.ring b { font-size: 34px; display: block; line-height: 1; }
.ring span { font-size: 12px; color: var(--muted); }
.parts { display: grid; gap: 8px; font-size: 13px; }
.part-row { display: grid; grid-template-columns: 110px 1fr 44px; gap: 8px; align-items: center; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--brand); }

/* Listas */
.list { display: grid; }
.item { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 11px 0; border-top: 1px solid var(--border); }
.item:first-child { border-top: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { font-size: 12px; color: var(--muted); }
.item .amt { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.amt.inc { color: var(--good); }
.avatar { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); font-size: 17px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.good { color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent); }
.badge.warning { color: var(--warning); background: color-mix(in srgb, var(--warning) 14%, transparent); }
.badge.serious { color: var(--serious); background: color-mix(in srgb, var(--serious) 13%, transparent); }
.badge.critical { color: var(--critical); background: color-mix(in srgb, var(--critical) 12%, transparent); }
.badge.wa { color: #0a7a3b; background: color-mix(in srgb, var(--wa) 18%, transparent); }
.insights { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.insights li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; font-size: 14px; }
.legend { display: grid; gap: 6px; font-size: 13px; margin-top: 10px; }
.legend div { display: grid; grid-template-columns: 12px 1fr auto auto; gap: 8px; align-items: center; }
.legend i { width: 12px; height: 12px; border-radius: 3px; }
.legend .pct { color: var(--muted); width: 40px; text-align: right; }
.legend-inline { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.legend-inline span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; background: var(--c); vertical-align: -1px; }
.progress { display: grid; gap: 6px; padding: 10px 0; border-top: 1px solid var(--border); }
.progress:first-child { border-top: 0; }
.progress .bar { height: 10px; }
.progress .bar > i.warn { background: var(--warning); }
.progress .bar > i.over { background: var(--critical); }

/* Tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
td.r, th.r { text-align: right; }
tr.paid td { color: var(--muted); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; padding: 8px 10px; }

/* Notícias */
.ind-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.ind { padding: 14px; }
.ind .label { font-size: 12px; color: var(--text-2); font-weight: 600; }
.ind .value { font-size: 20px; font-weight: 750; font-variant-numeric: tabular-nums; margin-top: 4px; }
.ind .ch { font-size: 12px; }
.news-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.news { padding: 0; overflow: hidden; display: flex; flex-direction: column; text-decoration: none; color: inherit; transition: transform .15s; }
.news:hover { transform: translateY(-2px); }
.news img { width: 100%; aspect-ratio: 16/9; object-fit: cover; background: var(--surface-2); display: block; }
.news .ph { aspect-ratio: 16/9; display: grid; place-items: center; background: linear-gradient(135deg, var(--brand-soft), var(--surface-2)); font-size: 36px; }
.news .body { padding: 14px 16px 16px; display: grid; gap: 6px; }
.news h3 { font-size: 15px; line-height: 1.35; }
.news p { margin: 0; font-size: 13px; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); padding: 6px 12px; border-radius: 99px; font: inherit; font-size: 13px; font-weight: 600; color: var(--text-2); cursor: pointer; }
.chip.active { background: var(--brand-soft); color: var(--text); border-color: transparent; }

/* WhatsApp */
.phone { max-width: 420px; width: 100%; margin: 0 auto; border-radius: 22px; overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow); display: flex; flex-direction: column; height: 620px; background: var(--wa-bg); }
.phone-head { background: #075e54; color: #fff; padding: 12px 14px; display: flex; gap: 10px; align-items: center; }
.phone-head .avatar { background: #128c7e; color: #fff; }
.phone-head small { opacity: .8; display: block; font-size: 12px; }
.chat { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 85%; padding: 7px 10px 6px; border-radius: 10px; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.08); background: var(--surface); color: var(--text); }
.bubble.out { align-self: flex-end; background: var(--wa-bubble); border-top-right-radius: 2px; }
.bubble.in { align-self: flex-start; border-top-left-radius: 2px; }
.bubble time { display: block; text-align: right; font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.bubble .ch { font-size: 10px; color: var(--muted); }
.composer { display: flex; gap: 8px; padding: 10px; background: var(--surface-2); }
.composer input { border-radius: 99px; }
.composer button { border-radius: 50%; width: 44px; height: 44px; padding: 0; flex: none; }
.code { font-size: 40px; font-weight: 800; letter-spacing: .18em; font-variant-numeric: tabular-nums; text-align: center; padding: 14px; border-radius: 14px; background: var(--brand-soft); }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
kbd, code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 6px; }

/* Modal & toast */
.modal { border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--text); width: min(480px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal::backdrop { background: rgba(0,0,0,.45); }
.modal-body { padding: 22px; display: grid; gap: 14px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 10px; min-height: 120px; }
@keyframes sk { to { background-position: -200% 0; } }

/* Responsivo */
@media (max-width: 1200px) { .g-kpi { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 980px) {
  .g-2, .g-3, .g-21, .g-12 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; z-index: 20; flex-direction: row; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border); gap: 0; }
  .sidebar .brand, .sidebar-foot { display: none; }
  .nav { grid-template-columns: repeat(6, 1fr); width: 100%; }
  .nav a { flex-direction: column; gap: 2px; padding: 6px 2px; font-size: 10.5px; text-align: center; }
  .nav .ico { width: auto; font-size: 18px; }
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 18px; }
  .view { padding: 16px 16px 96px; gap: 14px; }
  .g-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi .value { font-size: 18px; }
  .wa-pill { display: none; }
  .card-head { flex-wrap: wrap; }
  .score { grid-template-columns: 1fr; justify-items: center; }
  .parts { width: 100%; }
  .form .two { grid-template-columns: 1fr; }
  .phone { height: 560px; }
  .hide-m { display: none; }
  #mobile-actions { display: flex !important; }
}
#mobile-actions { display: none; }
