/* Visual inspirado no Sure: cinzas neutros, cards brancos com borda suave, sidebar estreita. */
:root {
  --bg: #f7f7f7; --surface: #fff; --surface-2: #fafafa; --border: #e8e8e8; --border-strong: #d4d4d4;
  --text: #141414; --muted: #737373; --subtle: #a3a3a3;
  --primary: #141414; --on-primary: #fff;
  --green: #10a861; --green-bg: #e9f8f0; --red: #e5372b; --red-bg: #fdecea; --amber: #c27803; --amber-bg: #fef6e4;
  --blue: #2a6fdb; --blue-bg: #eaf1fd; --line: #4b5ae0;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 0 0 1px rgba(0,0,0,.03);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0b; --surface: #171717; --surface-2: #1f1f1f; --border: #262626; --border-strong: #3a3a3a;
    --text: #f5f5f5; --muted: #a3a3a3; --subtle: #737373; --primary: #f5f5f5; --on-primary: #141414;
    --green: #3ccf87; --green-bg: #0f2a1c; --red: #ff6b5e; --red-bg: #33130f; --amber: #f2b43c; --amber-bg: #2e2208;
    --blue: #7aa7f5; --blue-bg: #13213a; --line: #8b96f5; --shadow: 0 0 0 1px rgba(255,255,255,.04);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 "Geist", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
h1 { font-size: 22px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.pos { color: var(--green); } .neg { color: var(--red); }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { 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; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; padding: 4px 8px 16px; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.on { background: var(--bg); color: var(--text); box-shadow: var(--shadow); }
.nav svg, .ico { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.side .me { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; display: flex; align-items: center; gap: 8px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--blue-bg); color: var(--blue); display: grid; place-items: center; font-weight: 600; font-size: 12px; flex: none; }
main { padding: 28px 32px 64px; max-width: 1480px; width: 100%; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; align-items: start; }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0,1fr)); } .g2 { grid-template-columns: 2fr 1fr; }
.stack { display: grid; gap: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* cards */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); padding: 18px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 18px 0; }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.stat .value { font-size: 24px; font-weight: 600; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* tabelas */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
tr.month td { background: var(--bg); font-weight: 600; font-size: 12px; color: var(--muted); padding: 6px 14px; }
tr.paid td { opacity: .55; }
tr.overdue td:first-child { box-shadow: inset 3px 0 var(--red); }
.desc { width: 100%; max-width: 0; min-width: 180px; }
.desc .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 500; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.b-previsto { background: var(--amber-bg); color: var(--amber); border-color: transparent; }
.b-confirmado { background: var(--blue-bg); color: var(--blue); border-color: transparent; }
.b-pago { background: var(--green-bg); color: var(--green); border-color: transparent; }
.b-danger { background: var(--red-bg); color: var(--red); border-color: transparent; }
.b-warning { background: var(--amber-bg); color: var(--amber); border-color: transparent; }
.b-info { background: var(--blue-bg); color: var(--blue); border-color: transparent; }

/* alertas */
.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); text-decoration: none; }
.alert + .alert { margin-top: 8px; }
.alert .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; }
.alert.danger .dot { background: var(--red); } .alert.warning .dot { background: var(--amber); } .alert.info .dot { background: var(--blue); }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; background: var(--green-bg); color: var(--green); font-weight: 500; }
.flash.err { background: var(--red-bg); color: var(--red); }

/* forms */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn.primary:hover { opacity: .9; }
.btn.danger { color: var(--red); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.block { width: 100%; justify-content: center; height: 40px; }
label { display: grid; gap: 4px; font-size: 12px; font-weight: 500; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; height: 36px; padding: 0 10px; width: 100%; }
textarea { height: auto; padding: 8px 10px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--line); outline-offset: 1px; }
.form { display: grid; gap: 12px; }
.f2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.f3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input, .filters select { width: auto; min-width: 140px; height: 32px; }
.filters input[type=checkbox] { min-width: 0; height: 16px; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg a { padding: 4px 12px; border-radius: 6px; text-decoration: none; color: var(--muted); font-weight: 500; font-size: 13px; }
.seg a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog .dh { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
dialog .db { padding: 20px; }
dialog .df { display: flex; justify-content: space-between; gap: 8px; padding-top: 8px; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: min(400px, 100%); padding: 28px; }
.auth h1 { margin: 12px 0 4px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--subtle); font-size: 12px; margin: 4px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.qr { background: #fff; padding: 12px; border-radius: 12px; width: 200px; margin: 8px auto; }
.qr svg { width: 100%; height: auto; display: block; }
code, .mono { font-family: ui-monospace, "Geist Mono", Menlo, monospace; font-size: 12px; word-break: break-all; }
.secret { background: var(--surface-2); border: 1px dashed var(--border-strong); padding: 10px; border-radius: 8px; }

/* gráfico */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .zero { stroke: var(--red); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--line); stroke-width: 2; stroke-linejoin: round; }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: var(--line); stroke: var(--surface); stroke-width: 2; }
.chart .low { fill: var(--line); stroke: var(--surface); stroke-width: 2; }
.chart .low.neg { fill: var(--red); }
.bar { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--green); border-radius: 99px; }

.menu-btn { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .menu-btn { display: inline-flex; }
  main { padding: 16px 16px 48px; }
  .g4 { grid-template-columns: 1fr 1fr; } .g3, .g2, .f3 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}

/* grade editável (Planejamento) */
table.sheet td { padding: 0 4px; height: 38px; }
table.sheet td.bal, table.sheet tr.opening td, table.sheet tr.month td { padding: 0 12px; }
table.sheet tr.month td { height: 28px; }
.cell { border: 1px solid transparent; background: transparent; height: 30px; padding: 0 8px; border-radius: 6px; width: 100%; min-width: 0; text-overflow: ellipsis; }
.cell:hover { border-color: var(--border); background: var(--surface); }
.cell:focus { border-color: var(--line); background: var(--surface); outline: none; }
select.cell { appearance: none; cursor: pointer; }
input.cell.num { text-align: right; font-variant-numeric: tabular-nums; }
.cell.saved { box-shadow: 0 0 0 2px var(--green); }
.cell.error { box-shadow: 0 0 0 2px var(--red); }
.st-previsto { color: var(--amber); } .st-confirmado { color: var(--blue); } .st-pago { color: var(--green); }
tfoot .newrow td { border-top: 2px solid var(--border); background: var(--surface-2); }
table.sheet tbody td:nth-child(2) { min-width: 260px; }
table.sheet { table-layout: fixed; min-width: 1150px; }

/* tela de progresso da atualização */
.steps { list-style: none; padding: 0; margin: 4px 0; display: grid; gap: 8px; }
.steps li { display: flex; align-items: center; gap: 10px; color: var(--subtle); }
.steps li::before { content: ""; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-strong); flex: none; box-sizing: border-box; }
.steps li.done { color: var(--text); }
.steps li.done::before { background: var(--green); border-color: var(--green); }
.steps li.active { color: var(--text); font-weight: 500; }
.steps li.active::before { border-color: var(--line); border-top-color: transparent; animation: spin .8s linear infinite; }
.steps li.error { color: var(--red); font-weight: 500; }
.steps li.error::before { background: var(--red); border-color: var(--red); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .steps li.active::before { animation: none; border-top-color: var(--line); } }
