:root {
  --ink: #061A33;
  --ink-2: #0D2A53;
  --muted: #6E84A3;
  --line: #D5E2F2;
  --bg: #F3F7FD;
  --card: #FFFFFF;
  --blue: #004AAD;
  --blue-2: #3980D6;
  --violet: #6711A4;
  --accent: #A66AD0;
  --green: #0E8A4F;
  --green-bg: #E5F6EE;
  --red: #C62D3A;
  --red-bg: #FDECEE;
  --amber: #B26A00;
  --amber-bg: #FFF4E0;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(6, 26, 51, .08);
  --sans: "Manrope", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --mono: "DM Mono", ui-monospace, monospace;
  --side: 248px;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.boot { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--muted); }

/* ---------- login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(900px 500px at 85% -10%, rgba(103,17,164,.45), transparent 60%), radial-gradient(800px 500px at -10% 110%, rgba(0,74,173,.45), transparent 60%), var(--ink); }
.auth-card { width: min(420px, 100%); padding: 34px 30px; border-radius: 24px; background: var(--card); box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.auth-logo { display: flex; justify-content: center; margin: -6px 0 18px; padding: 14px; border-radius: 16px; background: var(--ink); }
.auth-logo img { height: 46px; }
.auth-card h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: -.03em; }
.auth-card p.sub { margin: 0 0 22px; color: var(--muted); }
.auth-card .btn { width: 100%; margin-top: 8px; }
.auth-back { display: block; margin-top: 18px; text-align: center; color: var(--muted); font-size: 13px; text-decoration: none; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 22px 16px; color: #fff; background: var(--ink); }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; border-bottom: 1px solid rgba(255,255,255,.09); }
.side-brand img { height: 36px; }
.side-brand span { font: 500 10px var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.nav { display: grid; gap: 4px; margin-top: 18px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px; color: rgba(255,255,255,.72); font-weight: 700; text-decoration: none; }
.nav a:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav a.active { color: #fff; background: linear-gradient(90deg, rgba(0,74,173,.85), rgba(103,17,164,.6)); }
.nav .ico { width: 20px; text-align: center; font-size: 16px; }
.nav .badge { margin-left: auto; min-width: 22px; padding: 1px 7px; border-radius: 99px; background: var(--accent); color: var(--ink); font-size: 11px; font-weight: 800; text-align: center; }
.side-foot { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid rgba(255,255,255,.09); }
.side-user { font-weight: 700; }
.side-user small { display: block; color: rgba(255,255,255,.5); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.side-links { display: flex; gap: 14px; margin-top: 10px; font-size: 12px; }
.side-links a, .side-links button { padding: 0; border: 0; background: none; color: rgba(255,255,255,.6); text-decoration: none; }
.side-links a:hover, .side-links button:hover { color: var(--accent); }
.topbar { display: none; }
.main { min-width: 0; padding: 28px clamp(16px, 3vw, 36px) 60px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: -.04em; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* ---------- componentes ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px; border: 1px solid transparent; border-radius: 12px; font-weight: 800; font-size: 13px; text-decoration: none; white-space: nowrap; transition: background .15s, box-shadow .15s, transform .15s; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { color: #fff; background: var(--blue); box-shadow: 0 8px 20px rgba(0,74,173,.22); }
.btn-primary:hover { background: var(--blue-2); }
.btn-ghost { color: var(--ink); background: var(--card); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--blue-2); }
.btn-danger { color: #fff; background: var(--red); }
.btn-sm { min-height: 32px; padding: 0 10px; border-radius: 9px; font-size: 12px; }
.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font-size: 15px; }
.icon-btn:hover { border-color: var(--blue-2); color: var(--blue); }
.icon-btn.danger:hover { border-color: var(--red); color: var(--red); }

.card { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.card h2 { margin: 0 0 14px; font-size: 15px; letter-spacing: -.01em; }
.card h2 small { color: var(--muted); font-weight: 600; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.kpi { position: relative; overflow: hidden; }
.kpi .label { color: var(--muted); font: 500 10px var(--mono); letter-spacing: .12em; text-transform: uppercase; }
.kpi .value { margin-top: 6px; font-size: 24px; font-weight: 800; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.kpi .hint { margin-top: 2px; color: var(--muted); font-size: 12px; }
.kpi.pos .value { color: var(--green); }
.kpi.neg .value { color: var(--red); }
.kpi.warn { border-color: #F3C98B; background: var(--amber-bg); }
.kpi.warn .value { color: var(--amber); }
.kpi::after { content: ""; position: absolute; right: -24px; top: -24px; width: 80px; height: 80px; border-radius: 50%; background: rgba(0,74,173,.06); }
.kpis.flat { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpis.flat .kpi::after { display: none; }
.two { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }

.month { display: inline-flex; align-items: center; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.month button { width: 34px; height: 34px; border: 0; border-radius: 9px; background: transparent; font-size: 16px; }
.month button:hover { background: var(--bg); }
.month strong { min-width: 138px; text-align: center; }

.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 38%) 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; border-radius: 99px; background: var(--bg); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; }
.bar-row .amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.chart { display: grid; grid-template-columns: repeat(6, 1fr); align-items: end; gap: 10px; height: 190px; padding-top: 10px; }
.chart-col { display: grid; grid-template-rows: 1fr auto; height: 100%; gap: 6px; }
.chart-bars { display: flex; align-items: flex-end; justify-content: center; gap: 4px; }
.chart-bars i { width: 42%; max-width: 22px; min-height: 2px; border-radius: 6px 6px 2px 2px; }
.chart-bars .r { background: var(--blue); }
.chart-bars .d { background: var(--accent); }
.chart-col span { color: var(--muted); font-size: 11px; text-align: center; text-transform: capitalize; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 5px; border-radius: 3px; vertical-align: -1px; }
.empty { padding: 26px 10px; color: var(--muted); text-align: center; }

.list { display: grid; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .meta { color: var(--muted); font-size: 12px; }

.tag { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.tag-pago { color: var(--green); background: var(--green-bg); }
.tag-pendente { color: var(--blue); background: #E7F0FC; }
.tag-vencido { color: var(--red); background: var(--red-bg); }
.tag-neutral { color: var(--muted); background: var(--bg); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.money { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.money.receita { color: var(--green); }
.money.despesa { color: var(--red); }

/* ---------- filtros e tabela ---------- */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.totals { display: flex; flex-wrap: wrap; gap: 10px 26px; margin-bottom: 14px; padding: 14px 18px; border-radius: 14px; background: var(--ink); color: #fff; }
.totals div { display: grid; }
.totals small { color: rgba(255,255,255,.55); font: 500 10px var(--mono); letter-spacing: .1em; text-transform: uppercase; }
.totals strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font: 500 10px var(--mono); letter-spacing: .1em; text-transform: uppercase; background: #FAFCFF; white-space: nowrap; }
tbody tr:hover { background: #FAFCFF; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
td .desc { font-weight: 700; }
td .sub { color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- formulários ---------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label, .lbl { color: var(--muted); font: 500 10px var(--mono); letter-spacing: .1em; text-transform: uppercase; }
.input, .field input, .field select, .field textarea, .filters input, .filters select {
  width: 100%; min-height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 11px; background: #fff; outline: none;
}
.field textarea { min-height: 80px; padding: 10px 12px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .filters input:focus, .filters select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,74,173,.12); }
.field .help { color: var(--muted); font-size: 12px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.check { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; font-weight: 700; }
.check input { width: 18px; height: 18px; accent-color: var(--blue); }
.field input[type=checkbox] { width: 18px; height: 18px; min-height: 0; padding: 0; border: 0; box-shadow: none; }
.field label.check { color: var(--ink); font: 700 14px var(--sans); letter-spacing: 0; text-transform: none; cursor: pointer; }
.seg { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; margin-bottom: 16px; border-radius: 13px; background: var(--bg); }
.seg button { min-height: 40px; border: 0; border-radius: 10px; background: transparent; font-weight: 800; color: var(--muted); }
.seg button.on-despesa { color: #fff; background: var(--red); }
.seg button.on-receita { color: #fff; background: var(--green); }
.money-input { font-size: 20px !important; font-weight: 800; font-variant-numeric: tabular-nums; }
.inline { display: flex; gap: 8px; }
.inline select { flex: 1; min-width: 0; }
.error-msg { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; color: var(--red); background: var(--red-bg); font-weight: 700; }
.box { padding: 14px; margin-bottom: 14px; border: 1px dashed var(--line); border-radius: 12px; background: #FAFCFF; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 18px; background: rgba(6,26,51,.55); backdrop-filter: blur(3px); animation: fade .15s ease; }
.modal { width: min(640px, 100%); max-height: calc(100vh - 36px); overflow: auto; border-radius: 20px; background: var(--card); box-shadow: 0 30px 80px rgba(0,0,0,.3); }
.modal-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); background: var(--card); }
.modal-head h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.modal-body { padding: 20px 22px 6px; }
.modal-foot { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); background: var(--card); }
@keyframes fade { from { opacity: 0; } }

/* ---------- contatos ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.tabs button { padding: 8px 14px; border: 1px solid var(--line); border-radius: 99px; background: var(--card); font-weight: 700; color: var(--muted); }
.tabs button.on { color: #fff; border-color: var(--ink); background: var(--ink); }
.contact { display: grid; gap: 10px; }
.contact-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.contact-head strong { font-size: 15px; }
.contact-msg { margin: 0; padding: 12px 14px; border-radius: 12px; background: var(--bg); white-space: pre-wrap; word-break: break-word; }
.contact-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.contact-actions select { min-height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }

/* ---------- toasts ---------- */
.toast-area { position: fixed; z-index: 80; right: 18px; bottom: 18px; display: grid; gap: 8px; max-width: min(380px, calc(100vw - 36px)); }
.toast { padding: 12px 16px; border-radius: 12px; color: #fff; background: var(--ink); box-shadow: 0 14px 36px rgba(0,0,0,.25); font-weight: 700; animation: fade .2s ease; }
.toast.error { background: var(--red); }
.toast.ok { background: var(--green); }

/* ---------- responsivo ---------- */
@media (max-width: 1100px) { .two { grid-template-columns: 1fr; } }
/* ---------- enquadramento no PC: conteúdo centralizado em telas largas ---------- */
.main > * { max-width: 1440px; margin-left: auto; margin-right: auto; }
.bottom-nav { display: none; }
.so-celular, .so-celular-flex { display: none !important; }
.filtros-rodape { display: flex; justify-content: flex-end; margin-top: 10px; }

/* ---------- celular e tablet ---------- */
@media (max-width: 860px) {
  html { -webkit-text-size-adjust: 100%; }
  body { overscroll-behavior-y: none; }
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 70; inset: 0 auto 0 0; width: min(290px, 84vw); padding-top: calc(22px + env(safe-area-inset-top)); padding-bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-102%); transition: transform .2s ease; overflow-y: auto; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(6,26,51,.5); }
  .topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 8px calc(12px + env(safe-area-inset-left)); color: #fff; background: var(--ink); }
  .topbar img { height: 28px; }
  .topbar button { width: 42px; height: 42px; border: 1px solid rgba(255,255,255,.2); border-radius: 12px; background: transparent; color: #fff; font-size: 18px; }
  .main { padding: 16px calc(12px + env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left)); }
  .so-celular { display: inline-flex !important; }
  .so-celular-flex { display: flex !important; }
  .so-pc { display: none !important; }
  .page-head { gap: 10px; margin-bottom: 14px; }
  .page-head h1 { font-size: 22px; }
  .page-head p { font-size: 13px; }
  .head-actions { width: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
  .head-actions > .month { grid-column: 1 / -1; width: 100%; justify-content: space-between; }
  .head-actions > .month strong { flex: 1; min-width: 0; }
  .head-actions .btn { width: 100%; padding: 0 10px; }
  .head-actions > .btn:nth-child(4):last-child { grid-column: 1 / -1; }
  .filtros-empilhar { grid-template-columns: 1fr !important; }
  .card { padding: 16px; border-radius: 14px; }
  .hide-sm { display: none; }

  /* campos com 16px: o iPhone não dá zoom sozinho ao tocar */
  .input, .field input, .field select, .field textarea, .filters input, .filters select, .contact-actions select { font-size: 16px; min-height: 46px; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }
  .icon-btn { width: 40px; height: 40px; }

  /* filtros recolhidos no celular */
  .filtros-card .filtros-topo { display: flex; gap: 8px; }
  .filtros-card .filtros-topo > input { flex: 1; min-width: 0; }
  .filtros-card:not(.aberto) .filters > :not(.sempre), .filtros-card:not(.aberto) .filtros-rodape { display: none; }
  .filtros-card .filters { grid-template-columns: 1fr 1fr; }
  .filtros-card .filters > .sempre { grid-column: 1 / -1; }

  /* tabelas viram cartões em 2 colunas */
  .table-wrap { border-radius: 14px; }
  .table-wrap table, .table-wrap thead, .table-wrap tbody, .table-wrap td { display: block; }
  .table-wrap thead { display: none; }
  .table-wrap tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; padding: 14px; border-bottom: 1px solid var(--line); }
  .table-wrap td { padding: 0; border: 0; min-width: 0; overflow-wrap: anywhere; }
  .table-wrap td.num { text-align: left; }
  .table-wrap td:not([data-label]) { grid-column: 1 / -1; }
  .table-wrap td.titulo { order: -1; font-size: 15px; }
  .table-wrap td[data-label]::before { content: attr(data-label); display: block; color: var(--muted); font: 500 10px var(--mono); letter-spacing: .08em; text-transform: uppercase; }
  .table-wrap td.vazio-sm { display: none; }
  .row-actions { justify-content: flex-start; flex-wrap: wrap; margin-top: 4px; }

  .totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; padding: 14px; }
  .totals strong { font-size: 16px; }

  /* barra de navegação de aplicativo */
  .bottom-nav { position: fixed; z-index: 60; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); padding: 6px calc(6px + env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) calc(6px + env(safe-area-inset-left)); background: rgba(6,26,51,.97); backdrop-filter: blur(8px); border-top: 1px solid rgba(255,255,255,.08); }
  .bottom-nav a, .bottom-nav button { position: relative; display: grid; justify-items: center; gap: 2px; padding: 6px 2px; border: 0; border-radius: 12px; background: none; color: rgba(255,255,255,.62); font: 700 10.5px var(--sans); text-decoration: none; -webkit-tap-highlight-color: transparent; }
  .bottom-nav .ico { font-size: 19px; line-height: 1.1; }
  .bottom-nav .on { color: #fff; background: rgba(255,255,255,.08); }
  .bottom-nav .on .ico { color: var(--accent); }
  .bottom-nav .badge { position: absolute; top: 2px; right: 18%; min-width: 16px; padding: 0 4px; border-radius: 99px; background: var(--accent); color: var(--ink); font-size: 10px; line-height: 16px; }

  .toast-area { left: 12px; right: 12px; bottom: calc(82px + env(safe-area-inset-bottom)); max-width: none; }
}
@media (max-width: 560px) {
  .row, .row3 { grid-template-columns: 1fr; }
  .row3.manter { grid-template-columns: 1fr 1fr; }
  .row3.manter > :first-child { grid-column: 1 / -1; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi .value { font-size: 18px; }
  .kpi .hint { font-size: 11px; }
  .modal-bg { padding: 0; place-items: end stretch; z-index: 75; }
  .modal { width: 100%; max-height: 92vh; max-height: 92dvh; border-radius: 20px 20px 0 0; }
  .modal-head { padding: 16px 18px; }
  .modal-body { padding: 16px 18px 4px; }
  .modal-foot { padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); flex-wrap: wrap; }
  .modal-foot .btn { flex: 1; }
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-row .bar-track { grid-column: 1 / -1; grid-row: 2; }
  .chart { gap: 6px; height: 160px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .tabs button { white-space: nowrap; }
  .auth { padding: 16px; }
  .auth-card { padding: 26px 20px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
