/* ==========================================================================
   FinanCerto — tema
   ========================================================================== */
:root {
  --brand: #4361ee;
  --brand-600: #3651d4;
  --brand-50: #eef1fe;
  --nav-bg: #0f172a;
  --nav-text: #94a3b8;
  --nav-hover: #1e293b;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #e5e9f0;
  --text: #0f172a;
  --muted: #64748b;
  --success: #0f9d6b;
  --success-50: #e3f7ef;
  --danger: #dc3545;
  --danger-50: #fdecee;
  --warning: #b7791f;
  --warning-50: #fff4dc;
  --info-50: #e8f0ff;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .04);
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --gap: clamp(16px, 2vw, 32px);

  --bs-primary: var(--brand);
  --bs-primary-rgb: 67, 97, 238;
  --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --bs-body-color: var(--text);
  --bs-border-color: var(--border);
  --bs-link-color: var(--brand);
  --bs-link-hover-color: var(--brand-600);
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-padding-top: calc(var(--topbar-height) + 16px); }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--bs-body-font-family); font-size: .935rem; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { text-decoration: none; }
h1 { font-size: clamp(1.35rem, 1.1rem + .6vw, 1.7rem); font-weight: 700; letter-spacing: -.02em; margin: 0; }
h5 { font-weight: 650; font-size: 1rem; }
.tabular, .money-cell { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-width); z-index: 40;
  display: flex; flex-direction: column; padding: 18px 14px; overflow-y: auto;
  background: var(--nav-bg); scrollbar-width: thin; scrollbar-color: #334155 transparent;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; color: #fff; font-size: 1.15rem; font-weight: 800; letter-spacing: -.02em; }
.brand:hover { color: #fff; }
.brand-logo { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: linear-gradient(135deg, var(--brand), #7b5cff); font-size: 1rem; }
.nav-section { margin: 18px 12px 6px; color: #64748b; font-size: .68rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.nav-link-item { display: flex; align-items: center; gap: 11px; margin: 2px 0; padding: 9px 12px; border-radius: 9px; color: var(--nav-text); font-size: .9rem; font-weight: 500; transition: background-color .15s, color .15s; }
.nav-link-item i { font-size: 1.05rem; width: 18px; text-align: center; opacity: .9; }
.nav-link-item:hover { background: var(--nav-hover); color: #fff; }
.nav-link-item.active { background: rgba(67, 97, 238, .18); color: #fff; box-shadow: inset 3px 0 0 var(--brand); }
.nav-link-item.active i { color: #8ea2ff; }
.sidebar-backdrop { display: none; }

/* ---------- Topbar ---------- */
.topbar {
  position: fixed; top: 0; right: 0; left: var(--sidebar-width); height: var(--topbar-height); z-index: 30;
  display: flex; align-items: center; gap: 12px; padding: 0 var(--gap);
  background: rgba(255, 255, 255, .9); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.company-chip { display: inline-flex; align-items: center; gap: 8px; max-width: 340px; padding: 7px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); font-size: .87rem; font-weight: 600; }
.company-chip:hover { border-color: var(--brand); color: var(--brand); }
.company-chip .bi-building { color: var(--brand); }
.user-menu { display: inline-flex; align-items: center; gap: 9px; padding: 4px 8px 4px 4px; border: 0; border-radius: 999px; background: transparent; color: var(--text); font-weight: 500; }
.user-menu:hover { background: #f1f4f9; }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: var(--brand-50); color: var(--brand); font-weight: 700; }
.dropdown-menu { border-color: var(--border); border-radius: 12px; padding: 6px; font-size: .9rem; }
.dropdown-item { display: flex; align-items: center; gap: 9px; border-radius: 8px; padding: 8px 10px; }
.dropdown-header { font-size: .78rem; }

/* ---------- Layout ---------- */
.content { min-height: 100vh; margin-left: var(--sidebar-width); padding: calc(var(--topbar-height) + var(--gap)) var(--gap) var(--gap); }
.auth-content { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 15% 15%, #dfe6ff, transparent 40%), radial-gradient(circle at 85% 90%, #e8dcff, transparent 35%), var(--bg); }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.back-link { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 6px; color: var(--muted); font-size: .85rem; font-weight: 500; }
.back-link:hover { color: var(--brand); }

/* ---------- Cards ---------- */
.card, .panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.panel { padding: clamp(16px, 1.6vw, 24px); }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.panel-title h5 { margin: 0; }

/* ---------- Métricas ---------- */
.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 1199.98px) { .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .metrics-grid { grid-template-columns: 1fr; } }
.metric { position: relative; min-width: 0; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.metric .metric-icon { position: absolute; top: 16px; right: 16px; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; background: var(--brand-50); color: var(--brand); font-size: 1.1rem; }
.metric span.label { display: block; padding-right: 44px; color: var(--muted); font-size: .82rem; font-weight: 500; }
.metric strong { display: block; margin-top: 8px; font-size: clamp(1.15rem, 1rem + .4vw, 1.45rem); font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric small { display: block; margin-top: 4px; color: var(--muted); font-size: .8rem; }
.metric.tone-success .metric-icon { background: var(--success-50); color: var(--success); }
.metric.tone-danger .metric-icon { background: var(--danger-50); color: var(--danger); }
.metric.tone-warning .metric-icon { background: var(--warning-50); color: var(--warning); }
.metric.tone-danger strong.has-value { color: var(--danger); }
a.metric { color: inherit; transition: border-color .15s, transform .15s; }
a.metric:hover { border-color: #c7d0ff; transform: translateY(-1px); }
.metric.inactive { opacity: .6; }

/* ---------- Filtros ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.filters .filter-item { display: flex; flex-direction: column; gap: 4px; flex: 1 1 170px; min-width: 0; }
.filters .filter-item.grow { flex: 3 1 260px; }
.filters label { color: var(--muted); font-size: .75rem; font-weight: 600; }
.filters .filter-actions { display: flex; gap: 8px; }

/* ---------- Tabelas ---------- */
.table-card { overflow: hidden; }
.table-card .table-responsive { max-height: calc(100vh - 260px); }
.table { margin: 0; font-size: .89rem; --bs-table-hover-bg: #f8faff; }
.table thead th { position: sticky; top: 0; z-index: 2; padding: 12px 16px; background: #f8fafc; border-bottom: 1px solid var(--border); color: var(--muted); font-size: .72rem; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
.table td { padding: 12px 16px; vertical-align: middle; border-color: #eef1f6; }
.table tbody tr:last-child td { border-bottom: 0; }
.table td small { display: block; color: var(--muted); font-size: .8rem; }
.table tfoot td { padding: 12px 16px; background: #f8fafc; font-weight: 650; border-top: 1px solid var(--border); border-bottom: 0; }
.table .row-muted td { opacity: .55; }
.table .row-muted td.actions { opacity: 1; }
td.actions, th.actions { width: 1%; white-space: nowrap; text-align: right; }
td.actions .btn + .btn, td.actions form + .btn, td.actions .btn + form, td.actions form + form { margin-left: 4px; }
.text-end { text-align: right; }
.empty { padding: 48px 16px !important; color: var(--muted); text-align: center !important; }
.empty > i { display: block; margin-bottom: 8px; font-size: 2rem; color: #c3cbd8; }
.cell-link { color: var(--text); font-weight: 600; }
.cell-link:hover { color: var(--brand); }
.amount-in { color: var(--success); font-weight: 600; }
.amount-out { color: var(--danger); font-weight: 600; }

/* ---------- Status ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .76rem; font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-aberto { background: var(--info-50); color: #2f55d4; }
.status-parcial { background: var(--warning-50); color: var(--warning); }
.status-vencido { background: var(--danger-50); color: #c42b3a; }
.status-recebido, .status-pago { background: var(--success-50); color: var(--success); }
.status-cancelado { background: #eef0f3; color: #64748b; }
.status.lg { padding: 6px 14px; font-size: .85rem; }

/* ---------- Botões ---------- */
.btn { --bs-btn-font-weight: 600; --bs-btn-border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; font-size: .88rem; padding: .5rem .95rem; }
.btn-sm { --bs-btn-border-radius: 8px; padding: .3rem .6rem; font-size: .8rem; gap: 5px; }
.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-600); --bs-btn-hover-border-color: var(--brand-600); --bs-btn-active-bg: var(--brand-600); --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand); box-shadow: 0 1px 2px rgba(67, 97, 238, .25); }
.btn-success { --bs-btn-bg: var(--success); --bs-btn-border-color: var(--success); --bs-btn-hover-bg: #0b8159; --bs-btn-hover-border-color: #0b8159; }
.btn-light { --bs-btn-bg: #fff; --bs-btn-border-color: var(--border); --bs-btn-hover-bg: #f1f4f9; --bs-btn-hover-border-color: #d7dde7; --bs-btn-color: var(--text); }
.btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: #c7d0ff; --bs-btn-hover-bg: var(--brand-50); --bs-btn-hover-color: var(--brand); --bs-btn-hover-border-color: var(--brand); }
.btn-soft-primary { --bs-btn-bg: var(--brand-50); --bs-btn-color: var(--brand); --bs-btn-border-color: transparent; --bs-btn-hover-bg: #dfe5fd; --bs-btn-hover-color: var(--brand-600); --bs-btn-hover-border-color: transparent; }
.btn-soft-success { --bs-btn-bg: var(--success-50); --bs-btn-color: var(--success); --bs-btn-border-color: transparent; --bs-btn-hover-bg: #cdf0e1; --bs-btn-hover-color: #0b8159; --bs-btn-hover-border-color: transparent; }
.btn-soft-danger { --bs-btn-bg: var(--danger-50); --bs-btn-color: var(--danger); --bs-btn-border-color: transparent; --bs-btn-hover-bg: #f9d7db; --bs-btn-hover-color: #b02a37; --bs-btn-hover-border-color: transparent; }
.btn-soft-secondary { --bs-btn-bg: #f1f4f9; --bs-btn-color: #475569; --bs-btn-border-color: transparent; --bs-btn-hover-bg: #e5e9f0; --bs-btn-hover-color: var(--text); --bs-btn-hover-border-color: transparent; }
.btn-icon { width: 38px; height: 38px; padding: 0; border-radius: 10px; font-size: 1.25rem; }
.btn:focus-visible, .form-control:focus, .form-select:focus { box-shadow: 0 0 0 .2rem rgba(67, 97, 238, .2); border-color: var(--brand); }

/* ---------- Formulários ---------- */
.form-control, .form-select { min-height: 40px; border-color: #d9dfe8; border-radius: 10px; font-size: .9rem; }
.form-control::placeholder { color: #a0aabb; }
.form-label { margin-bottom: 5px; color: #334155; font-size: .84rem; font-weight: 600; }
.form-label .req { color: var(--danger); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-page { width: min(1100px, 100%); margin-left: 0 !important; overflow: hidden; }
.form-page-narrow { width: min(720px, 100%); }
.form-section { padding: clamp(18px, 2vw, 28px); border-bottom: 1px solid #eef1f6; }
.form-section-head { margin-bottom: 18px; }
.form-section-head h5 { margin: 0; }
.form-section-head p { margin: 3px 0 0; color: var(--muted); font-size: .85rem; }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 16px clamp(18px, 2vw, 28px); background: #fafbfd; }
.permission-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: #fafbfd; }
.switch-card { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: #fafbfd; }
.switch-card .form-check-input { margin-top: 3px; }
.switch-card small { display: block; color: var(--muted); }
.input-group-text { border-color: #d9dfe8; background: #f8fafc; color: var(--muted); font-size: .85rem; border-radius: 10px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px; border: 1px solid #d9dfe8; border-radius: 10px; background: #fff; cursor: pointer; font-weight: 600; color: var(--muted); }
.segmented input:checked + label.in { border-color: var(--success); background: var(--success-50); color: var(--success); }
.segmented input:checked + label.out { border-color: var(--danger); background: var(--danger-50); color: var(--danger); }
.segmented input:focus-visible + label { box-shadow: 0 0 0 .2rem rgba(67, 97, 238, .2); }

/* ---------- Dashboard ---------- */
.chart-wrap { position: relative; height: clamp(260px, 28vw, 380px); }
.forecast { display: flex; flex-direction: column; gap: 10px; }
.forecast-row { padding: 12px 14px; border: 1px solid #eef1f6; border-radius: 12px; }
.forecast-row .days { font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.forecast-row .vals { display: flex; justify-content: space-between; gap: 10px; margin-top: 4px; font-variant-numeric: tabular-nums; font-size: .9rem; }
.period-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.period-form .form-control { width: auto; }

/* ---------- Título ---------- */
.info-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px 24px; margin: 0; }
.info-list dt { color: var(--muted); font-size: .76rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.info-list dd { margin: 2px 0 0; font-weight: 500; }
.progress-thin { height: 8px; border-radius: 99px; background: #edf0f5; }
.progress-thin .progress-bar { background: var(--success); border-radius: 99px; }

/* ---------- Contas ---------- */
.account-card { display: flex; flex-direction: column; gap: 6px; height: 100%; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.account-card .head { display: flex; align-items: center; gap: 12px; }
.account-card .icon { width: 42px; height: 42px; flex: none; display: grid; place-items: center; border-radius: 12px; background: var(--brand-50); color: var(--brand); font-size: 1.2rem; }
.account-card h5 { margin: 0; font-size: .98rem; }
.account-card .type { color: var(--muted); font-size: .8rem; }
.account-card .balance { margin-top: 8px; font-size: 1.45rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.account-card .balance.neg { color: var(--danger); }
.account-card .meta { color: var(--muted); font-size: .8rem; min-height: 1.2em; }
.account-card .foot { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 12px; border-top: 1px solid #eef1f6; }
.account-card.inactive { opacity: .6; }

/* ---------- Login ---------- */
.login-card { width: min(420px, 92vw); padding: clamp(28px, 3vw, 40px); border: 1px solid var(--border); border-radius: 20px; background: #fff; box-shadow: 0 24px 60px rgba(15, 23, 42, .12); }
.login-card .brand-logo { width: 48px; height: 48px; border-radius: 14px; color: #fff; font-size: 1.4rem; }
.login-card h1 { margin: 18px 0 4px; }
.auth-card { width: min(480px, 92vw); }

/* ---------- Mensagens ---------- */
.toast-stack { position: fixed; top: calc(var(--topbar-height) + 12px); right: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; width: min(400px, calc(100vw - 32px)); max-width: none !important; }
.auth .toast-stack { top: 16px; }
.flash { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border: 1px solid var(--border); border-left-width: 4px; border-radius: 12px; background: #fff; box-shadow: 0 10px 30px rgba(15, 23, 42, .12); font-size: .88rem; animation: flash-in .2s ease-out; }
.flash > i { margin-top: 1px; font-size: 1.05rem; }
.flash > span { flex: 1; }
.flash .btn-close { font-size: .7rem; margin-top: 3px; }
.flash-success { border-left-color: var(--success); } .flash-success > i { color: var(--success); }
.flash-danger { border-left-color: var(--danger); } .flash-danger > i { color: var(--danger); }
.flash-warning { border-left-color: #e0a100; } .flash-warning > i { color: #e0a100; }
.flash-info { border-left-color: var(--brand); } .flash-info > i { color: var(--brand); }
.flash.hide { opacity: 0; transform: translateX(16px); transition: opacity .25s, transform .25s; }
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } }

.notice { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 12px; background: var(--info-50); color: #2a3f8f; font-size: .88rem; }
.notice.warning { background: var(--warning-50); color: #7a5410; }
.notice > i { font-size: 1.1rem; }

/* ---------- Diálogo de confirmação ---------- */
.confirm-dialog { width: min(420px, calc(100vw - 32px)); padding: 24px; border: 0; border-radius: 18px; box-shadow: 0 30px 80px rgba(15, 23, 42, .3); }
.confirm-dialog::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); }
.confirm-dialog h5 { margin: 12px 0 6px; }
.confirm-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; background: var(--danger-50); color: var(--danger); font-size: 1.25rem; }
.confirm-dialog.primary .confirm-icon { background: var(--brand-50); color: var(--brand); }

/* ---------- Responsivo ---------- */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: 10px 0 30px rgba(0, 0, 0, .2); }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(15, 23, 42, .4); }
  .topbar { left: 0; padding: 0 12px; }
  .content { margin-left: 0; padding: calc(var(--topbar-height) + 18px) 14px 28px; }
  .table-card .table-responsive { max-height: none; }
  .company-chip { max-width: 200px; }
}
@media (max-width: 600px) {
  .page-head { align-items: stretch; }
  .page-actions { width: 100%; }
  .page-actions > .btn, .page-actions > form { flex: 1; }
  .page-actions > form .btn { width: 100%; }
  .filters .filter-actions { width: 100%; }
  .filters .filter-actions .btn { flex: 1; }
  .form-actions { flex-direction: column-reverse; align-items: stretch; }
  .period-form { width: 100%; }
  .period-form .form-control { flex: 1; }
  td.actions .btn-icon-text span { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
