:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e8ef;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #059669;
  --accent-soft: #d1fae5;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --income: #059669;
  --expense: #0f172a;
  --company: #7c3aed;
  --company-soft: #ede9fe;
  --nav: #0b1220;
  --nav-text: #cbd5e1;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #111a2c;
    --surface-2: #0f1727;
    --border: #1f2a40;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #34d399;
    --accent-soft: #064e3b;
    --danger: #f87171;
    --danger-soft: #450a0a;
    --income: #34d399;
    --expense: #e2e8f0;
    --company: #a78bfa;
    --company-soft: #2e1065;
    --nav: #070c17;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: Inter, system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }

/* layout */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--nav); color: var(--nav-text); padding: 22px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; padding: 0 10px 18px; }
.brand img { width: 30px; height: 30px; }
.brand small { display: block; font-weight: 500; color: var(--nav-text); font-size: 12px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--nav-text); text-decoration: none; font-weight: 500; }
.nav-item:hover { background: rgba(255,255,255,.06); }
.nav-item.active { background: rgba(52, 211, 153, .14); color: #fff; }
.nav-item svg { width: 19px; height: 19px; flex: none; }
.side .spacer { flex: 1; }
.side .who { font-size: 13px; padding: 10px 12px; color: var(--nav-text); }
.main { padding: 26px 32px 120px; max-width: 1180px; width: 100%; }

.topbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.topbar h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; flex: 1; min-width: 160px; }
.cycle-nav { display: flex; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.cycle-nav button { border: 0; background: none; width: 38px; height: 44px; cursor: pointer; color: var(--muted); font-size: 18px; }
.cycle-nav button:hover { color: var(--text); }
.cycle-nav .label { text-align: center; padding: 0 6px; min-width: 170px; cursor: pointer; }
.cycle-nav .label b { display: block; font-size: 14px; }
.cycle-nav .label span { font-size: 12px; color: var(--muted); }

/* botões */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border); background: var(--surface); padding: 10px 16px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #052e1f; } }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: none; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.fab { position: fixed; right: 24px; bottom: 24px; width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 30px; box-shadow: 0 8px 24px rgba(5, 150, 105, .35); cursor: pointer; z-index: 20; display: grid; place-items: center; }
@media (prefers-color-scheme: dark) { .fab { color: #052e1f; } }

/* cards */
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.two { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 15px; margin: 0 0 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h2 small { font-weight: 500; color: var(--muted); font-size: 13px; }
.kpi .label { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: clamp(19px, 2.1vw, 26px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 2px; }
.kpi .hint { font-size: 12.5px; color: var(--muted); }
.kpi.company { background: var(--company-soft); border-color: transparent; }
.kpi.company .value { color: var(--company); }
.up { color: var(--danger); } .down { color: var(--income); }
.section { margin-top: 16px; }

.progress { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.cycle-strip { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.cycle-strip .progress { flex: 1; min-width: 180px; }
.cycle-strip .stat { font-size: 13px; color: var(--muted); }
.cycle-strip .stat b { color: var(--text); display: block; font-size: 15px; }

.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin-bottom: 12px; font-size: 14px; }
.bar-row .bar { grid-column: 1 / -1; height: 7px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar-row .bar i { display: block; height: 100%; border-radius: 99px; }
.bar-row .name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar-row .name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .val { font-weight: 600; }
.bar-row .val small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.over { color: var(--danger); font-size: 12px; font-weight: 600; }

.invoice { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-top: 1px solid var(--border); }
.invoice:first-of-type { border-top: 0; padding-top: 0; }
.chip-card { width: 38px; height: 26px; border-radius: 6px; flex: none; }
.invoice .info { flex: 1; min-width: 0; }
.invoice .info b { display: block; }
.invoice .info span { font-size: 12.5px; color: var(--muted); }
.invoice .amt { text-align: right; font-weight: 700; }
.invoice .amt small { display: block; font-weight: 500; font-size: 12px; color: var(--company); }

/* lista de lançamentos */
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters input, .filters select { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; min-width: 0; }
.filters input { flex: 1 1 200px; }
.totals-bar { display: flex; gap: 22px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.totals-bar b { color: var(--text); font-size: 15px; }
.day-head { font-size: 12.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 4px 6px; display: flex; justify-content: space-between; }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); cursor: pointer; }
.row:first-child { border-top: 0; }
.row:hover { background: var(--surface-2); }
.row .ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; font-weight: 700; font-size: 13px; color: #fff; }
.row .desc { flex: 1; min-width: 0; }
.row .desc b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .desc span { font-size: 12.5px; color: var(--muted); }
.row .amount { font-weight: 700; text-align: right; white-space: nowrap; }
.row .amount.receita { color: var(--income); }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.badge.company { background: var(--company-soft); color: var(--company); border-color: transparent; }
.badge.ok { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

.tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; margin-bottom: 16px; }
.tabs button { border: 0; background: none; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--muted); }
.tabs button.on { background: var(--accent-soft); color: var(--accent); }

/* modal e formulários */
.overlay { position: fixed; inset: 0; background: rgba(2, 6, 23, .55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; padding: 22px; border: 1px solid var(--border); }
.modal h3 { margin: 0 0 16px; font-size: 18px; display: flex; justify-content: space-between; align-items: center; }
.modal h3 button { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input, .field select, .field textarea { width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; outline: none; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field .help { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.field.money input { font-size: 24px; font-weight: 700; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 1px solid var(--border); background: var(--surface-2); border-radius: 99px; padding: 7px 13px; cursor: pointer; font-size: 13.5px; font-weight: 500; }
.seg button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg.kind button { flex: 1; border-radius: 10px; padding: 10px; }
.seg.scope button.on[data-v=empresa] { border-color: var(--company); background: var(--company-soft); color: var(--company); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.modal-actions .left { margin-right: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.note { background: var(--surface-2); border: 1px dashed var(--border); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.colors button { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.colors button.on { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--surface); }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 20% 10%, rgba(52,211,153,.18), transparent 40%), var(--nav); }
.auth .box { background: var(--surface); border-radius: 20px; padding: 30px; width: 100%; max-width: 420px; }
.auth h1 { margin: 10px 0 4px; font-size: 22px; }
.auth p { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.auth .btn { width: 100%; padding: 13px; }
.error { color: var(--danger); font-size: 13.5px; margin: 8px 0; min-height: 1em; }

.settings-list > div { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.settings-list > div:first-child { border-top: 0; padding-top: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; flex: none; }
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cat-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.cat-item:first-of-type { border-top: 0; }
.cat-item .grow { flex: 1; min-width: 0; }
.cat-item .grow span { display: block; font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px); background: var(--nav); color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }

/* mobile */
.bottom-nav { display: none; }
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  .two { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .main { padding: 16px 16px 120px; min-width: 0; }
  .kpi .value { font-size: 18px; white-space: normal; overflow: visible; letter-spacing: -.03em; }
  .kpi .label, .kpi .hint { font-size: 12px; }
  .topbar h1 { font-size: 20px; }
  .cycle-nav { width: 100%; justify-content: space-between; }
  .kpi .value { font-size: 21px; }
  .card { padding: 16px; }
  .cat-grid, .cols { grid-template-columns: 1fr; }
  .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--nav); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 30; justify-content: space-around; }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; color: var(--nav-text); text-decoration: none; padding: 6px 4px; border-radius: 8px; flex: 1; }
  .bottom-nav a.active { color: #34d399; }
  .bottom-nav svg { width: 21px; height: 21px; }
  .fab { bottom: calc(76px + env(safe-area-inset-bottom)); right: 16px; }
  #toast { bottom: 150px; }
  .overlay { align-items: flex-end; padding: 0; }
  .modal { border-radius: 18px 18px 0 0; max-height: 92vh; }
}
