:root {
  color-scheme: light;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --ink-2: #475569;
  --muted: #64748b;
  --line: #e2e8f0;
  --grid: #e9edf2;
  --primary: #2563eb;
  --in: #2a78d6;          /* série 1: entradas */
  --out: #eb6834;         /* série 2: saídas */
  --good: #0ca30c;
  --good-text: #067a06;
  --critical: #d03b3b;
  --warning-bg: #fef3c7;
  --warning-ink: #92400e;
  --sidebar: #ffffff;
  --side-ink: #334155;
  --side-muted: #64748b;
  --side-hover: #f1f5f9;
  --side-line: #e2e8f0;
  --auth-bg:
    radial-gradient(700px 480px at 85% 10%, rgba(14, 165, 233, .18), transparent 60%),
    radial-gradient(600px 420px at 5% 95%, rgba(37, 99, 235, .14), transparent 60%),
    linear-gradient(180deg, #f8fbff, #e8f0fe);
  --radius: 14px;
  --shadow: 0 4px 18px rgba(15, 23, 42, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b1120; --surface: #151d2e; --surface-2: #1b2438; --ink: #f1f5f9; --ink-2: #cbd5e1; --muted: #94a3b8;
    --line: #26314a; --grid: #222c42; --in: #3987e5; --out: #d95926; --good-text: #3ccf3c; --critical: #e66767;
    --warning-bg: #3b2a06; --warning-ink: #fcd34d; --sidebar: #070b16; --shadow: none;
    --side-ink: #cbd5e1; --side-muted: #94a3b8; --side-hover: rgba(255, 255, 255, .06); --side-line: rgba(255, 255, 255, .06);
    --auth-bg: radial-gradient(700px 480px at 85% 10%, rgba(56, 189, 248, .25), transparent 60%), radial-gradient(600px 420px at 5% 95%, rgba(37, 99, 235, .3), transparent 60%), linear-gradient(180deg, #081128, #0b1a3d);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120; --surface: #151d2e; --surface-2: #1b2438; --ink: #f1f5f9; --ink-2: #cbd5e1; --muted: #94a3b8;
  --line: #26314a; --grid: #222c42; --in: #3987e5; --out: #d95926; --good-text: #3ccf3c; --critical: #e66767;
  --warning-bg: #3b2a06; --warning-ink: #fcd34d; --sidebar: #070b16; --shadow: none;
  --side-ink: #cbd5e1; --side-muted: #94a3b8; --side-hover: rgba(255, 255, 255, .06); --side-line: rgba(255, 255, 255, .06);
  --auth-bg: radial-gradient(700px 480px at 85% 10%, rgba(56, 189, 248, .25), transparent 60%), radial-gradient(600px 420px at 5% 95%, rgba(37, 99, 235, .3), transparent 60%), linear-gradient(180deg, #081128, #0b1a3d);
}

/* Logo certa para cada tema */
.logo-dark { display: none !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-light { display: none !important; }
  :root:not([data-theme="light"]) .logo-dark { display: block !important; }
}
:root[data-theme="dark"] .logo-light { display: none !important; }
:root[data-theme="dark"] .logo-dark { display: block !important; }

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: Inter, system-ui, sans-serif; background: var(--bg); color: var(--ink); line-height: 1.5; }
h1, h2 { font-family: Poppins, sans-serif; margin: 0; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.05rem; }
a { color: var(--primary); text-decoration: none; }
.muted { color: var(--muted); }
p { margin: 4px 0 0; }

/* Layout */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--side-ink); padding: 22px 16px; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--side-line); transition: background-color .3s;
}
.sidebar__brand { display: block; text-align: center; }
.sidebar__brand img { height: 84px; width: auto; margin: 0 auto; }
.sidebar__label { text-transform: uppercase; font-size: .72rem; letter-spacing: .1em; color: var(--side-muted); margin: 26px 10px 8px; }
.sidebar__nav { display: grid; gap: 4px; }
.sidebar__nav a { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; color: var(--side-ink); font-weight: 500; }
.sidebar__nav a:hover { background: var(--side-hover); }
.sidebar__nav a.active { background: var(--primary); color: #fff; }
.sidebar__foot { margin-top: auto; display: grid; gap: 10px; font-size: .9rem; }
.sidebar__foot a { color: var(--side-muted); padding: 0 12px; }
.theme-btn { background: var(--side-hover); color: var(--side-ink); border: 0; padding: 10px 12px; border-radius: 10px; cursor: pointer; font: inherit; text-align: left; }
.theme-btn:hover { filter: brightness(.97); }

.main { min-width: 0; padding: 0 28px 40px; }
.topbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 20px 0; position: sticky; top: 0; z-index: 5; background: var(--bg); }
.topbar__actions { margin-left: auto; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.theme-top { width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 1.1rem; }
.icon-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-dark { display: inline; }
  :root:not([data-theme="light"]) .icon-light { display: none; }
}
:root[data-theme="dark"] .icon-dark { display: inline; }
:root[data-theme="dark"] .icon-light { display: none; }
.menu-btn { display: none; background: var(--surface); border: 1px solid var(--line); color: var(--ink); border-radius: 10px; width: 42px; height: 42px; font-size: 1.2rem; cursor: pointer; }
.period { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); }

/* Controls */
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; cursor: pointer;
  background: var(--primary); color: #fff; padding: 10px 16px; border-radius: 10px; font: 600 .92rem Inter, sans-serif; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn--in { background: var(--in); }
.btn--out { background: var(--out); }
.btn--ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn--danger { background: var(--critical); }
.btn--sm { padding: 8px 12px; font-size: .85rem; }
.link-btn { background: none; border: 0; color: var(--primary); font: 600 .88rem Inter, sans-serif; cursor: pointer; padding: 0; }
.icon-btn { background: none; border: 0; font-size: 1.6rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* Panels */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.panel__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.panel--wide { grid-column: 1 / -1; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.kpis--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; display: grid; gap: 4px; box-shadow: var(--shadow); }
.kpi small { color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi strong { font-family: Poppins, sans-serif; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.kpi span { font-size: .85rem; }
.pos { color: var(--good-text); }
.neg { color: var(--critical); }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.dot--in { background: var(--in); }
.dot--out { background: var(--out); }
.legend { display: flex; gap: 16px; align-items: center; font-size: .88rem; color: var(--ink-2); flex-wrap: wrap; }
.legend span { display: flex; align-items: center; gap: 6px; }

/* Chart */
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-family: Inter, sans-serif; }
.chart .bar-in { fill: var(--in); }
.chart .bar-out { fill: var(--out); }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hit:hover, .chart .hit.on { fill: var(--ink); fill-opacity: .05; }
.chart .zero { stroke: var(--muted); stroke-width: 1; }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font-size: .85rem; box-shadow: 0 8px 24px rgba(0, 0, 0, .15); min-width: 170px;
}
.tooltip b { display: block; margin-bottom: 4px; }
.tooltip div { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.tooltip div span { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tooltip .num { font-variant-numeric: tabular-nums; font-weight: 600; }

.hbars { display: grid; gap: 12px; }
.hbar { display: grid; gap: 4px; }
.hbar__top { display: flex; justify-content: space-between; font-size: .88rem; gap: 10px; }
.hbar__top b { font-variant-numeric: tabular-nums; font-weight: 600; }
.hbar__track { height: 10px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar__fill { height: 100%; background: var(--out); border-radius: 0 4px 4px 0; }

.acc-list, .mini-list { display: grid; gap: 2px; }
.mini-item, .acc-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 6px; border-bottom: 1px solid var(--line); }
.mini-item:last-child, .acc-item:last-child { border-bottom: 0; }
.mini-item__main { min-width: 0; }
.mini-item__main b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-item__main small { color: var(--muted); }
.mini-item__val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; display: grid; justify-items: end; gap: 4px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; margin: 0; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge--pago { background: rgba(12, 163, 12, .12); color: var(--good-text); }
.badge--pendente { background: var(--warning-bg); color: var(--warning-ink); }
.badge--vencido { background: rgba(208, 59, 59, .14); color: var(--critical); }

/* Filters + table */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 14px; }
.filters label { display: grid; gap: 4px; font-size: .82rem; color: var(--muted); font-weight: 500; }
.filters .grow { flex: 1 1 200px; }
.sumbar { display: flex; flex-wrap: wrap; gap: 10px 24px; margin: 0 4px 12px; font-size: .92rem; color: var(--ink-2); }
.sumbar b { font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; padding: 0; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
.table th[data-sort] { cursor: pointer; user-select: none; }
.table td.desc { white-space: normal; min-width: 200px; }
.table td.desc small { display: block; color: var(--muted); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:hover { background: var(--surface-2); }
.table .acts { text-align: right; }
.table .acts button { background: none; border: 0; cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 1rem; }
.table .acts button:hover { background: var(--line); }
.status-toggle { border: 0; cursor: pointer; font: inherit; }
.row-actions { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; }
.val-in { color: var(--good-text); }
.val-out { color: var(--critical); }

.table--dre th:first-child, .table--dre td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.table--dre thead th:first-child { background: var(--surface-2); }
.table--dre tr.group td { font-weight: 700; background: var(--surface-2); }
.table--dre tr.total td { font-weight: 700; border-top: 2px solid var(--ink-2); }
.table--dre td.sub { padding-left: 28px; color: var(--ink-2); }
.print-title { display: none; padding: 16px; }

/* Cadastros */
.tags { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.tags li { display: flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 12px; font-size: .88rem; }
.tags button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 2px 6px; border-radius: 50%; }
.tags button:hover { background: var(--line); color: var(--critical); }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
.acc-edit { display: grid; gap: 10px; margin-bottom: 14px; }
.acc-edit__row { display: grid; grid-template-columns: 1fr 130px auto; gap: 8px; align-items: center; }
.acc-edit__row input { padding: 7px 10px; }
.acc-edit__row button { background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 1.1rem; }

.btn-col { display: grid; gap: 10px; margin-top: 16px; max-width: 380px; }
.file-btn { cursor: pointer; }
.storage-warn { background: var(--warning-bg); color: var(--warning-ink); padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; }

/* Modal */
.modal { border: 0; border-radius: 18px; padding: 0; width: min(620px, 100% - 24px); background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px rgba(0, 0, 0, .35); }
.modal::backdrop { background: rgba(2, 6, 23, .55); }
.modal form { padding: 22px; }
.modal__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal__foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; text-align: center; padding: 10px; border-radius: 10px; border: 2px solid var(--line); font-weight: 600; cursor: pointer; }
.seg label:first-child input:checked + span { border-color: var(--in); background: color-mix(in srgb, var(--in) 12%, transparent); color: var(--in); }
.seg label:last-child input:checked + span { border-color: var(--out); background: color-mix(in srgb, var(--out) 12%, transparent); color: var(--out); }
.seg input:focus-visible + span { outline: 2px solid var(--primary); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { display: grid; gap: 4px; font-size: .85rem; font-weight: 500; color: var(--ink-2); }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .invalid { border-color: var(--critical); }
.form-err { color: var(--critical); min-height: 1.2em; font-size: .88rem; margin: 10px 0 0; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 120px); background: var(--ink); color: var(--bg);
  padding: 12px 20px; border-radius: 12px; font-weight: 500; transition: transform .3s; z-index: 60; display: flex; gap: 14px; align-items: center;
}
.toast.show { transform: translate(-50%, 0); }
.toast button { background: none; border: 0; color: var(--in); font: 700 .9rem Inter, sans-serif; cursor: pointer; }

/* Responsive */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(2, 6, 23, .5); }
  .menu-btn { display: block; }
  .main { padding: 0 16px 32px; }
  .grid-2, .kpis--3 { grid-template-columns: 1fr; }
  .topbar__actions { margin-left: 0; width: 100%; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .acc-edit__row { grid-template-columns: 1fr 100px auto; }
  .topbar__actions .btn { flex: 1; }
}

/* Impressão */
@media print {
  .sidebar, .topbar, .filters, .row-actions, .toast, .storage-warn { display: none !important; }
  .app { display: block; }
  .main { padding: 0; }
  .panel { box-shadow: none; border: 0; }
  .print-title { display: block; }
  body { background: #fff; color: #000; }
  .table { font-size: 9pt; }
  .table th, .table td { padding: 4px 6px; }
}

/* Login / cadastro */
.app[hidden], .auth[hidden] { display: none !important; }
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--auth-bg);
}
.auth__card {
  width: min(420px, 100%); background: var(--surface); color: var(--ink); border-radius: 20px; border: 1px solid var(--line);
  padding: 32px 28px; box-shadow: 0 30px 80px rgba(15, 23, 42, .18); text-align: center;
}
.auth__logo { height: 88px; width: auto; margin: -8px auto 8px; }
.auth__card h1 { font-size: 1.35rem; }
.auth__tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--surface-2); border: 1px solid var(--line); padding: 4px; border-radius: 12px; margin: 22px 0 18px; }
.auth__tabs button { border: 0; background: none; color: var(--muted); font: 600 .92rem Inter, sans-serif; padding: 9px; border-radius: 9px; cursor: pointer; }
.auth__tabs button.active { background: var(--primary); color: #fff; }
.auth__form { display: grid; gap: 12px; text-align: left; }
.auth__form label { display: grid; gap: 4px; font-size: .86rem; font-weight: 500; color: var(--ink-2); }
.auth__form .btn { margin-top: 6px; padding: 12px; }
.auth__form .btn:disabled { opacity: .6; cursor: wait; }
.auth__check { grid-template-columns: auto 1fr !important; align-items: start; gap: 8px !important; font-size: .8rem !important; color: var(--muted) !important; }
.auth__check input { margin-top: 3px; }
.auth__hint { font-size: .8rem; margin: 2px 0 0; }
.auth__msg { color: var(--critical); min-height: 1.2em; font-size: .88rem; margin: 12px 0 4px; }
.auth__back { font-size: .88rem; }
.user-chip { display: grid; padding: 10px 12px; border-radius: 10px; background: var(--side-hover); }
.user-chip b { color: var(--ink); font-weight: 600; font-size: .9rem; }
.user-chip small { color: var(--side-muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; }
.auth__form[hidden] { display: none; }
.auth__form--single { margin-top: 22px; }
.pass-field { position: relative; display: block; }
.pass-field input { width: 100%; padding-right: 44px; }
.pass-toggle { position: absolute; top: 50%; right: 4px; transform: translateY(-50%); width: 36px; height: 36px; display: grid; place-items: center; background: none; border: 0; border-radius: 8px; color: var(--ink-2); cursor: pointer; }
.pass-toggle:hover { color: var(--ink); background: var(--line); }
.pass-toggle[aria-pressed="false"] .pass-toggle__slash { display: none; }

/* Editor do site (CMS) */
.ed-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; position: sticky; top: 82px; z-index: 4; }
.ed-bar input[type=search] { flex: 1 1 260px; }
.ed-bar__acts { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.ed-status { font-size: .85rem; color: var(--muted); }
.ed-status--dirty { color: var(--warning-ink); background: var(--warning-bg); padding: 4px 10px; border-radius: 999px; font-weight: 600; }
.ed-help { margin: 12px 4px 14px; font-size: .9rem; }
.ed-sec { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; box-shadow: var(--shadow); }
.ed-sec > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 16px 20px; }
.ed-sec > summary::-webkit-details-marker { display: none; }
.ed-sec > summary::before { content: "▸"; color: var(--muted); transition: transform .2s; }
.ed-sec[open] > summary::before { transform: rotate(90deg); }
.ed-sec > summary .muted { font-size: .85rem; }
.ed-vis { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--ink-2); cursor: pointer; }
.ed-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; padding: 4px 20px 20px; }
.ed-field { display: grid; gap: 6px; align-content: start; position: relative; }
.ed-field[hidden] { display: none; }
.ed-field label { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.ed-field textarea { resize: vertical; font: inherit; line-height: 1.45; }
.ed-reset { justify-self: start; background: none; border: 0; color: var(--primary); font: 600 .8rem Inter, sans-serif; cursor: pointer; padding: 0; }
.ed-field--img { grid-template-columns: 120px 1fr; gap: 12px; align-items: start; padding: 10px; border: 1px dashed var(--line); border-radius: 12px; }
.ed-field--img img { width: 120px; height: 90px; object-fit: contain; border-radius: 8px; background: repeating-conic-gradient(var(--surface-2) 0% 25%, var(--line) 0% 50%) 50% / 16px 16px; }
.ed-img__side { display: grid; gap: 8px; }
.ed-img__acts { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.ed-busy { opacity: .5; pointer-events: none; }
.ed-busy::after { content: "Enviando…"; position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; color: var(--ink); }
@media (max-width: 860px) { .ed-bar { top: 0; position: static; } .ed-grid { grid-template-columns: 1fr; } }
