/* ---------- Cores (claro / escuro) ---------- */
:root {
  color-scheme: light;
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f4;
  --hover: #f7f7f7;
  --border: #e6e6e6;
  --grid: #efefef;
  --text: #171717;
  --muted: #6b6b6b;
  --faint: #a3a3a3;
  --accent: #171717;
  --accent-fg: #ffffff;
  --ring: #2563eb;
  --good: #15803d;
  --bad: #c62828;
  --warn: #b45309;
  --good-soft: rgba(21, 128, 61, .08);
  --bad-soft: rgba(198, 40, 40, .07);
  --warn-soft: rgba(180, 83, 9, .08);
  --shadow: 0 8px 30px rgba(0, 0, 0, .08);
  --side: 232px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a0a0a;
    --surface: #111111;
    --surface-2: #1c1c1c;
    --hover: #161616;
    --border: #262626;
    --grid: #1f1f1f;
    --text: #ededed;
    --muted: #a1a1a1;
    --faint: #6b6b6b;
    --accent: #ededed;
    --accent-fg: #0a0a0a;
    --ring: #60a5fa;
    --good: #4ade80;
    --bad: #f87171;
    --warn: #fbbf24;
    --good-soft: rgba(74, 222, 128, .1);
    --bad-soft: rgba(248, 113, 113, .1);
    --warn-soft: rgba(251, 191, 36, .1);
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0a0a;
  --surface: #111111;
  --surface-2: #1c1c1c;
  --hover: #161616;
  --border: #262626;
  --grid: #1f1f1f;
  --text: #ededed;
  --muted: #a1a1a1;
  --faint: #6b6b6b;
  --accent: #ededed;
  --accent-fg: #0a0a0a;
  --ring: #60a5fa;
  --good: #4ade80;
  --bad: #f87171;
  --warn: #fbbf24;
  --good-soft: rgba(74, 222, 128, .1);
  --bad-soft: rgba(248, 113, 113, .1);
  --warn-soft: rgba(251, 191, 36, .1);
  --shadow: 0 8px 30px rgba(0, 0, 0, .5);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 14px/1.5 Geist, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.ic { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Menu lateral ---------- */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 30; width: var(--side);
  display: flex; flex-direction: column; gap: 2px;
  padding: 14px 12px; overflow-y: auto;
  background: var(--bg); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
.marca { width: 18px; height: 18px; border-radius: 5px; background: var(--text); flex: none; }
.sidebar .brand { padding: 4px 0 4px 8px; flex: 1; }
.side-head { display: flex; align-items: center; margin-bottom: 12px; }
.recolher {
  display: grid; place-items: center; width: 28px; height: 28px; padding: 0; flex: none;
  border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer;
}
.recolher:hover { background: var(--surface-2); color: var(--text); }
.side-nav { display: flex; flex-direction: column; gap: 1px; }
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border-radius: 6px; color: var(--muted);
  text-decoration: none; font-weight: 500;
}
.side-nav a:hover { background: var(--surface-2); color: var(--text); }
.side-nav a.active { background: var(--surface-2); color: var(--text); }
.side-nav .ini { display: none; }
.side-nav.clients a { font-weight: 400; }
.side-nav.clients a.active { font-weight: 500; }
.side-nav.clients .nome { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-nav.clients a.add { color: var(--faint); }
.side-nav.clients a.add:hover { color: var(--text); }
.side-title { margin: 20px 8px 6px; font-size: 12px; font-weight: 500; color: var(--faint); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--bad); display: inline-block; flex: none; }

.buscar {
  display: flex; align-items: center; gap: 10px; width: 100%; margin-bottom: 10px; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--faint);
  font: inherit; cursor: pointer; text-align: left;
}
.buscar:hover { color: var(--muted); border-color: var(--faint); }
.buscar .txt-menu { flex: 1; }
.buscar::after { content: "⌘K"; font-size: 11px; color: var(--faint); }

.moeda-box { margin-top: auto; padding: 16px 0 10px; }
.moeda-sel { display: flex; padding: 2px; gap: 2px; border-radius: 7px; background: var(--surface-2); }
.moeda-sel button {
  flex: 1; padding: 4px 0; border: 0; border-radius: 5px; background: none;
  color: var(--muted); font: inherit; font-weight: 500; cursor: pointer;
}
.moeda-sel button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.cotacao { margin: 8px 2px 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cotacao small { display: block; color: var(--faint); font-size: 11px; }
.side-footer { display: flex; flex-wrap: wrap; gap: 4px; padding-top: 10px; border-top: 1px solid var(--border); }
.side-footer .btn { flex: 1 1 auto; justify-content: flex-start; }
.quem { flex-basis: 100%; padding: 2px 8px 6px; font-size: 12px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.login-dica { color: var(--faint); font-size: 12px; margin-top: -4px; }
.form-linha { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.form-linha input { height: 32px; font: inherit; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.side-footer #tema { flex-basis: 100%; }

.mobilebar { display: none; }
.backdrop { display: none; }

main { padding: 28px 32px 48px; margin-left: var(--side); }

/* ---------- Botões e campos ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 0 12px; border-radius: 6px; font: inherit; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { opacity: .88; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 20px; }
.toolbar h1 { display: flex; align-items: baseline; gap: 10px; font-size: 22px; font-weight: 600; letter-spacing: -.02em; margin: 0 auto 0 0; }
.h1-sub { font-size: 14px; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.toolbar label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.toolbar input, .toolbar select {
  height: 32px; font: inherit; padding: 0 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text);
}
.toolbar.config {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; gap: 14px;
}
.toolbar.config input { width: 120px; }

.hint { color: var(--muted); margin: -8px 0 20px; }
.muted { color: var(--muted); font-weight: 400; }
.link { text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.btns { display: inline-flex; gap: 6px; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* passos da rotina de cobrança */
.steps { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: -4px 0 24px; padding: 0; list-style: none; counter-reset: passo; }
.steps li { counter-increment: passo; position: relative; padding-left: 28px; color: var(--muted); font-size: 13px; flex: 1 1 220px; max-width: 320px; }
.steps li::before {
  content: counter(passo); position: absolute; left: 0; top: 1px; width: 18px; height: 18px; border-radius: 50%;
  border: 1px solid var(--border); display: grid; place-items: center; font-size: 11px; color: var(--text);
}
.steps b { color: var(--text); font-weight: 500; }

/* ---------- Títulos de seção ---------- */
.section-title {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  margin: 32px 0 12px; font-size: 14px; font-weight: 600; letter-spacing: -.005em;
}
.section-title .muted { font-size: 13px; }
.section-title label.inline { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; font-weight: 400; color: var(--muted); cursor: pointer; }
.toolbar + .section-title { margin-top: 4px; }

/* ---------- Indicadores: painel único dividido em blocos iguais ---------- */
.kpis {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px;
  background: var(--border); border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
.kpi { background: var(--surface); padding: 16px 18px 18px; min-width: 0; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value {
  margin-top: 6px; font-size: 22px; font-weight: 500; letter-spacing: -.02em; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums;
}
.kpi .sub { margin-top: 6px; color: var(--faint); font-size: 12px; line-height: 1.4; }
.kpis.grande .kpi { padding: 20px 22px 22px; }
.kpis.grande .value { font-size: 28px; }
.kpi.pos .value { color: var(--good); }
.kpi.bad .value { color: var(--bad); }
.duas { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 24px; }
.duas .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* ---------- Tabelas ---------- */
.sheet {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  overflow: auto; max-height: calc(100vh - 120px);
}
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; }
.grid th, .grid td { border: 0; border-bottom: 1px solid var(--grid); padding: 0; height: 36px; }
.grid:not(.plain) td + td, .grid:not(.plain) th + th { border-left: 1px solid var(--grid); }
.grid th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 500;
  text-align: left; padding: 0 10px; white-space: nowrap; border-bottom-color: var(--border);
}
.grid td.calc, .grid td.txt { padding: 0 10px; white-space: nowrap; }
.grid td.num, .grid th.num { text-align: right; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid input, .grid select {
  width: 100%; height: 35px; border: 0; background: transparent; color: inherit;
  font: inherit; padding: 0 10px; outline: none; min-width: 70px;
}
.grid input::placeholder { color: var(--faint); }
.grid input[type=number] { text-align: right; }
.grid input[type=checkbox] { width: 15px; height: 15px; min-width: 0; margin: 0 auto; display: block; accent-color: var(--text); }
.grid input:disabled, .grid select:disabled { color: var(--faint); cursor: not-allowed; }
.grid input:focus, .grid select:focus { box-shadow: inset 0 0 0 1.5px var(--ring); background: var(--surface); }
.grid tbody tr:hover td { background: var(--hover); }
.grid tr.new td { background: var(--bg); }
.grid tr.new:hover td { background: var(--bg); }
.grid tfoot td {
  background: var(--surface); font-weight: 600; padding: 0 10px; position: sticky; bottom: 0;
  white-space: nowrap; border-top: 1px solid var(--border); border-bottom: 0;
}
.grid td.saved { animation: saved .9s ease; }
@keyframes saved { from { background: var(--good-soft); } }
.grid td.actions { position: sticky; right: 0; padding: 0 6px; white-space: nowrap; text-align: center; background: var(--surface); }
.grid tr.new td.actions { background: var(--bg); }
.grid tr.st-caiu td, .grid tr.st-encerrada td { color: var(--muted); }
.grid tr.st-caiu td:first-child { box-shadow: inset 2px 0 var(--bad); }
.grid tr.st-restrita td:first-child { box-shadow: inset 2px 0 var(--warn); }
.grid tr.pending td { background: var(--warn-soft); }
.grid tbody tr.destaque td { animation: destaque 3s ease; }
@keyframes destaque { 0%, 60% { background: var(--warn-soft); } }
.del { border: 0; background: none; color: var(--faint); cursor: pointer; font-size: 16px; padding: 0 4px; }
.del:hover { color: var(--bad); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* status: pontinho colorido + texto */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--faint); flex: none; }
.badge.good::before { background: var(--good); }
.badge.bad::before { background: var(--bad); }
.badge.warn::before { background: var(--warn); }
.badge.good { color: var(--good); }
.badge.bad { color: var(--bad); }
.badge.warn { color: var(--warn); }
.btn.aguardando { color: var(--warn); border-color: var(--warn-soft); background: var(--warn-soft); }

/* ---------- Login / diálogos / toast ---------- */
.overlay { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 50; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; }
.login { width: min(340px, calc(100vw - 32px)); display: grid; gap: 12px; }
.login h2 { margin: 0 0 4px; font-size: 18px; font-weight: 600; letter-spacing: -.01em; }
.err { color: var(--bad); margin: 0; min-height: 1em; font-size: 13px; }

dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 22px; width: min(420px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog h3 { margin: 0 0 14px; font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
dialog form { display: grid; gap: 12px; }
dialog label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
dialog label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
dialog fieldset { border: 1px solid var(--border); border-radius: 8px; display: grid; gap: 10px; padding: 12px; margin: 0; }
dialog small { color: var(--faint); font-size: 12px; }
.login input, dialog input[type=text], dialog input[type=date], dialog input[type=number], dialog input[type=password], dialog input:not([type]) {
  height: 36px; font: inherit; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text);
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

#busca { width: min(560px, calc(100vw - 32px)); margin-top: 12vh; padding: 8px; }
#busca-q {
  width: 100%; height: 44px; font: inherit; font-size: 15px; padding: 0 12px; margin-bottom: 4px;
  border: 0; border-bottom: 1px solid var(--border); background: none; color: var(--text); outline: none;
}
#busca-res { max-height: 50vh; overflow-y: auto; padding: 4px 0; }
#busca .hint { margin: 8px 10px; }
.achado {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; width: 100%; text-align: left;
  padding: 9px 10px; border: 0; border-radius: 6px; background: none; color: inherit; font: inherit; cursor: pointer;
}
.achado:hover, .achado:focus-visible { background: var(--surface-2); outline: none; }
.achado[disabled] { cursor: default; background: none; }
.achado-cli { font-weight: 500; }
.achado-info { grid-column: 1 / -1; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 6px);
  background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 8px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Telas menores ---------- */
@media (max-width: 1100px) {
  .kpis, .kpis.grande { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .duas { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .mobilebar {
    position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
    height: 48px; padding: 0 12px; background: var(--bg); border-bottom: 1px solid var(--border);
  }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  body.menu-aberto .sidebar { transform: none; }
  body.menu-aberto .backdrop { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, .4); }
  main { padding: 18px 14px 40px; margin-left: 0; }
  .kpi { padding: 12px 14px 14px; }
  .kpi .value, .kpis.grande .value { font-size: 19px; }
  .recolher { display: none; }
  .buscar::after { content: none; }
}

/* ---------- Menu recolhido (só no computador) ---------- */
@media (min-width: 721px) {
  .sidebar, main { transition: width .15s ease, margin-left .15s ease; }
  body.menu-recolhido { --side: 60px; }
  .menu-recolhido .sidebar { padding: 14px 8px; overflow-x: hidden; }
  .menu-recolhido .sidebar .txt-menu { display: none; }
  .menu-recolhido .side-head, .menu-recolhido .side-nav a { justify-content: center; }
  .menu-recolhido .recolher .ic { transform: rotate(180deg); }
  .menu-recolhido .side-title { border-top: 1px solid var(--border); margin: 10px 4px; }
  .menu-recolhido .side-nav a { padding: 8px 0; position: relative; }
  .menu-recolhido .side-nav .ini { display: inline; font-size: 12px; font-weight: 500; }
  .menu-recolhido .side-nav .dot { position: absolute; top: 6px; right: 5px; }
  .menu-recolhido .buscar { justify-content: center; padding: 7px 0; }
  .menu-recolhido .buscar::after { content: none; }
  .menu-recolhido .moeda-sel { flex-direction: column; }
  .menu-recolhido .side-footer { flex-direction: column; }
  .menu-recolhido .side-footer .btn { justify-content: center; padding: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, main, #toast { transition: none !important; }
  .grid td.saved, .grid tbody tr.destaque td { animation: none; }
}
