:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f0f3f2;
  --line: #e2e8e5;
  --text: #17211d;
  --text-2: #5d6b65;
  --text-3: #8a9690;
  --primary: #0b7a5c;
  --primary-2: #0e9470;
  --primary-soft: #e3f4ee;
  --on-primary: #ffffff;
  --good: #0a8a3e; --good-soft: #e5f5ea;
  --warn: #b26b00; --warn-soft: #fdf2dc;
  --bad: #c9302c; --bad-soft: #fbe7e6;
  --info: #1f6fd1; --info-soft: #e5effb;
  --series-1: #257de0; --series-2: #f47230; --series-3: #00b894; --grid: #e6ebe9;
  --shadow: 0 1px 2px rgba(16, 40, 30, .06), 0 4px 16px rgba(16, 40, 30, .05);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1412;
  --surface: #171e1b;
  --surface-2: #1f2824;
  --line: #2a3530;
  --text: #e8efec;
  --text-2: #a3b1ab;
  --text-3: #75827c;
  --primary: #2fbf8f;
  --primary-2: #4fd3a5;
  --primary-soft: #16362b;
  --on-primary: #06231a;
  --good: #3fcf78; --good-soft: #143222;
  --warn: #f0b545; --warn-soft: #362a12;
  --bad: #f07470; --bad-soft: #3a1b1a;
  --info: #6aa8f5; --info-soft: #162a44;
  --series-1: #338ced; --series-2: #e76624; --series-3: #00a888; --grid: #26302c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 18px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); 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(--primary); }
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 17px; }
.brand-logo { width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-size: 18px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px; color: var(--text-2); text-decoration: none; font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav .ico { width: 22px; text-align: center; font-size: 17px; }
.sidebar .user-box { margin-top: auto; padding: 12px; border-top: 1px solid var(--line); font-size: 13px; }
.main { min-width: 0; padding: 22px 28px 40px; max-width: 1240px; width: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.month-picker { display: inline-flex; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; box-shadow: var(--shadow); }
.month-picker button { border: 0; background: transparent; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 18px; color: var(--text-2); }
.month-picker button:hover { background: var(--surface-2); color: var(--text); }
.month-picker .label { min-width: 150px; text-align: center; font-weight: 600; cursor: pointer; padding: 0 6px; }

.bottom-nav { display: none; }
.fab { display: none; }

/* ---------- componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card h2, .card h3 { margin: 0 0 12px; font-size: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpis.k6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12.5px; color: var(--text-2); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.kpi.hl { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.kpi.hl .label, .kpi.hl .sub { color: inherit; opacity: .85; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; color: var(--text-2); font-size: 16px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; outline: none; min-height: 42px; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input.money { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.input.inline { min-height: 34px; padding: 6px 10px; }
.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; margin-bottom: 10px; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.hint { font-size: 12.5px; color: var(--text-2); margin-top: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 7px 12px; border-radius: 999px; cursor: pointer; font-size: 13.5px; font-weight: 500; }
.chip.on { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }

.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--good); transition: width .3s; }
.bar.warn > i { background: var(--warn); }
.bar.bad > i { background: var(--bad); }
.bar.primary > i { background: var(--primary); }

.cat-ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 18px; flex-shrink: 0; }

.list { margin: 0; padding: 0; list-style: none; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item.click { cursor: pointer; border-radius: 10px; padding: 10px 8px; }
.list-item.click:hover { background: var(--surface-2); }
.list-item .title { font-weight: 600; font-size: 14.5px; }
.list-item .meta { font-size: 12.5px; color: var(--text-2); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.date-head { font-size: 12.5px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; padding: 14px 4px 4px; }

.budget-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.budget-row:last-child { border-bottom: 0; }
.budget-row .top { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; }

.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 700; padding: 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.tbl tr.off td { opacity: .45; }

.alert { display: block; padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 8px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert.good { background: var(--good-soft); color: var(--good); }
.alert b { color: inherit; }

.empty { text-align: center; padding: 28px 12px; color: var(--text-2); }
.empty .big { font-size: 38px; margin-bottom: 6px; }

.credit-card { border-radius: 16px; padding: 16px 18px; color: #fff; min-height: 120px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.credit-card::after { content: ""; position: absolute; right: -40px; top: -40px; width: 150px; height: 150px; border-radius: 50%; background: rgba(255, 255, 255, .12); }
.credit-card .cc-name { font-weight: 700; font-size: 16px; }
.credit-card .cc-val { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.credit-card .cc-sub { font-size: 12.5px; opacity: .9; }

.mini-bars { display: flex; align-items: flex-end; gap: 6px; height: 70px; }
.mini-bars .mb { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.mini-bars .mb i { width: 100%; max-width: 28px; background: var(--series-1); border-radius: 4px 4px 0 0; min-height: 2px; }
.mini-bars .mb span { font-size: 10.5px; color: var(--text-3); }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.chart-box { position: relative; height: 280px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 30px 16px; text-align: center; cursor: pointer; background: var(--surface); transition: .2s; }
.dropzone:hover, .dropzone.over { border-color: var(--primary); background: var(--primary-soft); }
.dropzone .big { font-size: 40px; }
.steps { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.steps .st { flex: 1; min-width: 120px; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); color: var(--text-3); font-size: 13px; font-weight: 600; }
.steps .st.on { background: var(--primary-soft); color: var(--primary); }
.steps .st.done { color: var(--good); }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(8, 15, 12, .5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 520px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); animation: pop .18s; }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 8px; }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-body { padding: 8px 18px 16px; overflow-y: auto; }
.modal-foot { padding: 12px 18px 16px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }

.toast-wrap { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 500; box-shadow: var(--shadow); animation: pop .2s; max-width: 90vw; }
.toast.bad { background: var(--bad); color: #fff; }

/* ---------- login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1000px 500px at 10% -10%, var(--primary-soft), transparent), var(--bg); }
.auth-box { width: 100%; max-width: 400px; }
.auth-box .card { padding: 26px; }
.auth h1 { font-size: 24px; margin: 0 0 4px; }
.code-box { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 24px; font-weight: 800; letter-spacing: .08em; text-align: center; padding: 16px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); margin: 12px 0; user-select: all; }

.emoji-pick { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.emoji-pick button { border: 1px solid var(--line); background: var(--surface); width: 36px; height: 36px; border-radius: 8px; cursor: pointer; font-size: 18px; }
.emoji-pick button.on { border-color: var(--primary); background: var(--primary-soft); }
.color-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.color-pick button { width: 28px; height: 28px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.color-pick button.on { border-color: var(--text); }

.bulk-bar { position: sticky; top: 0; z-index: 5; background: var(--primary); color: var(--on-primary); border-radius: 12px; padding: 8px 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.bulk-bar .btn { background: rgba(255, 255, 255, .15); color: inherit; border-color: transparent; }
.sel-box { width: 18px; height: 18px; accent-color: var(--primary); flex-shrink: 0; }

.loader { min-height: 100vh; display: grid; place-items: center; color: var(--text-2); }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- celular ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 14px 14px 96px; }
  .topbar h1 { font-size: 20px; }
  .month-picker { width: 100%; justify-content: space-between; }
  .month-picker .label { min-width: 0; flex: 1; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .kpis, .kpis.k6 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px; }
  .kpi .value { font-size: 18px; }
  .card { padding: 14px; }
  .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--line); z-index: 50; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
  .bottom-nav a, .bottom-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--text-2); text-decoration: none; padding: 4px 0; border: 0; background: transparent; cursor: pointer; font-weight: 500; }
  .bottom-nav .ico { font-size: 20px; }
  .bottom-nav a.active { color: var(--primary); }
  .bottom-nav .plus .ico { width: 46px; height: 46px; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-size: 26px; margin-top: -20px; box-shadow: 0 6px 16px rgba(11, 122, 92, .4); }
  .modal-bg { align-items: flex-end; padding: 0; }
  .modal { border-radius: 18px 18px 0 0; max-height: 92vh; }
  .fields-2 { grid-template-columns: 1fr 1fr; }
  .hide-m { display: none !important; }
  .tbl { font-size: 13px; }
}
@media (min-width: 861px) { .show-m { display: none !important; } }

.drawer-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 90; }
.drawer { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-radius: 18px 18px 0 0; padding: 14px 12px calc(14px + env(safe-area-inset-bottom)); z-index: 91; animation: pop .18s; }
.drawer .nav { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.drawer .nav a { flex-direction: column; text-align: center; gap: 4px; font-size: 13px; padding: 12px 4px; background: var(--surface-2); }
.drawer .nav .ico { font-size: 22px; width: auto; }

@media print {
  .sidebar, .bottom-nav, .topbar .btn, .month-picker button { display: none !important; }
  .app { display: block; }
}
