:root {
    --navy: #14213d;
    --navy-2: #1f3158;
    --blue: #2563eb;
    --green: #12805c;
    --green-bg: #e9f8f1;
    --red: #c2414b;
    --red-bg: #fff0f1;
    --amber: #b56808;
    --amber-bg: #fff7e6;
    --gray-50: #f7f8fa;
    --gray-100: #eef0f4;
    --gray-300: #d5dae3;
    --gray-500: #697386;
    --gray-700: #344054;
    --white: #fff;
    --shadow: 0 10px 30px rgba(20, 33, 61, .08);
    --radius: 14px;
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--navy); background: var(--gray-50); }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; }
body:not(.auth-page) { padding-left: 260px; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.topbar {
    position: fixed; inset: 0 auto 0 0; z-index: 20; width: 260px; min-height: 100vh; padding: 1.25rem 1rem;
    display: flex; flex-direction: column; align-items: stretch; gap: 1.5rem; overflow-y: auto; color: white;
    background: linear-gradient(165deg, var(--navy), var(--navy-2)); box-shadow: 4px 0 18px rgba(20,33,61,.18);
}
.brand { display: flex; align-items: center; gap: .7rem; min-width: 0; padding: .25rem .45rem; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; background: #3b82f6; font-weight: 800; letter-spacing: -.05em; }
.company-logo { overflow: hidden; background: white; }
.company-logo img { width: 100%; height: 100%; object-fit: contain; }
.logo-placeholder { color: #dbeafe; border: 1px dashed rgba(255,255,255,.55); background: rgba(255,255,255,.08); font-size: 1.35rem; font-weight: 500; }
.brand strong, .brand small { display: block; line-height: 1.05; }
.brand strong { max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand small { font-size: .72rem; color: #cbd5e1; margin-top: .2rem; }
.main-nav { display: flex; flex-direction: column; align-items: stretch; gap: .3rem; width: 100%; }
.main-nav a { width: 100%; padding: .78rem .85rem; border-radius: 9px; color: #dbe4f3; font-size: .9rem; white-space: nowrap; }
.main-nav a:hover, .main-nav a.active { background: rgba(255,255,255,.12); color: white; }
.menu-toggle { display: none; margin-left: auto; color: white; border: 0; background: transparent; cursor: pointer; }
.logout-form { width: 100%; margin-top: auto; }
.logout-form button { width: 100%; padding: .65rem .7rem; color: #dbe4f3; border: 1px solid rgba(255,255,255,.2); border-radius: 8px; background: transparent; cursor: pointer; font-size: .8rem; }
.logout-form button:hover { color: white; background: rgba(255,255,255,.12); }

.container { width: min(1180px, 92vw); margin: 2rem auto 4rem; flex: 1; }
body:not(.auth-page) .container { width: min(1180px, calc(100% - 4rem)); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.page-head h1 { margin: 0; font-size: clamp(1.55rem, 3vw, 2.15rem); letter-spacing: -.04em; }
.page-head p { margin: .4rem 0 0; color: var(--gray-500); }
.actions { display: flex; gap: .55rem; flex-wrap: wrap; align-items: center; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-height: 40px;
    border: 1px solid transparent; border-radius: 9px; padding: .55rem .9rem; cursor: pointer;
    background: var(--blue); color: white; font-weight: 650; font-size: .88rem;
}
.btn:hover { filter: brightness(.95); }
.btn-secondary { color: var(--navy); background: white; border-color: var(--gray-300); }
.btn-danger { background: var(--red); }
.btn-success { background: var(--green); }
.btn-small { min-height: 32px; padding: .35rem .58rem; font-size: .78rem; }
.link-danger { color: var(--red); }

.card { background: white; border: 1px solid #e7e9ee; border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 1.25rem; }
.card-title { margin: 0 0 1rem; font-size: 1.05rem; }
.stats-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1rem; margin-bottom: 1.25rem; }
.stat { padding: 1.15rem; overflow: hidden; position: relative; }
.stat::after { content: ""; position: absolute; width: 70px; height: 70px; right: -20px; bottom: -30px; border-radius: 50%; background: currentColor; opacity: .07; }
.stat-label { display: block; color: var(--gray-500); font-size: .82rem; }
.stat-value { display: block; margin-top: .45rem; font-size: clamp(1.15rem, 2vw, 1.55rem); font-weight: 780; letter-spacing: -.04em; }
.text-credit { color: var(--green); }
.text-debit { color: var(--red); }
.text-pending { color: var(--amber); }
.text-muted { color: var(--gray-500); }
.negative { color: var(--red) !important; }

.filters { padding: 1rem; margin-bottom: 1.25rem; }
.filter-grid { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); gap: .8rem; align-items: end; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.2rem; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: .38rem; color: var(--gray-700); font-size: .82rem; font-weight: 650; }
.field input, .field select, .field textarea {
    width: 100%; min-height: 43px; padding: .65rem .72rem; color: var(--navy); background: white;
    border: 1px solid var(--gray-300); border-radius: 9px; outline: none;
}
.field textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--red); background: var(--red-bg); }
.field.has-error input:focus, .field.has-error select:focus, .field.has-error textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(194,65,75,.12); }
.field-error { display: block; margin-top: .3rem; color: var(--red); }
.form-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: .7rem; padding-top: .5rem; }

.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; background: white; }
th, td { padding: .85rem .9rem; border-bottom: 1px solid var(--gray-100); text-align: left; font-size: .88rem; vertical-align: middle; }
th { color: var(--gray-500); background: #fafbfc; font-size: .75rem; text-transform: uppercase; letter-spacing: .045em; }
tbody tr:hover { background: #fbfcff; }
tbody tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; gap: .35rem; white-space: nowrap; }
.table-actions form { display: inline; }
.empty { padding: 3rem 1rem !important; color: var(--gray-500); text-align: center; }

.badge { display: inline-flex; padding: .28rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.badge-ativo, .badge-recebido, .badge-pago { color: var(--green); background: var(--green-bg); }
.badge-inativo, .badge-cancelado { color: var(--gray-500); background: var(--gray-100); }
.badge-pendente { color: var(--amber); background: var(--amber-bg); }
.badge-atrasado { color: var(--red); background: var(--red-bg); }
.badge-credito { color: var(--green); background: var(--green-bg); }
.badge-debito { color: var(--red); background: var(--red-bg); }

.alert { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; padding: .85rem 1rem; border-radius: 10px; }
.alert-success { color: #075b40; background: var(--green-bg); border: 1px solid #bee9d6; }
.alert-error { color: #9e2630; background: var(--red-bg); border: 1px solid #f6cbd0; }
.alert-close { color: inherit; border: 0; background: transparent; font-size: 1.2rem; cursor: pointer; }

.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
.detail-item { padding: 1rem 1.25rem; border-bottom: 1px solid var(--gray-100); }
.detail-item span { display: block; margin-bottom: .3rem; color: var(--gray-500); font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; }
.detail-item strong { font-size: .94rem; word-break: break-word; }
.detail-item.full { grid-column: 1 / -1; }
.quick-grid { display: grid; grid-template-columns: 1.1fr 1.9fr; gap: 1.25rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.2rem; border-bottom: 1px solid var(--gray-100); }
.section-head h2 { margin: 0; font-size: 1.05rem; }
.projection-chart-card { margin-bottom: 1.25rem; }
.projection-chart-card .section-head { align-items: flex-start; }
.projection-chart-card .section-head p { margin: .3rem 0 0; color: var(--gray-500); font-size: .82rem; }
.chart-legend { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; color: var(--gray-700); font-size: .78rem; }
.chart-legend-item { display: inline-flex; align-items: center; gap: .38rem; white-space: nowrap; }
.chart-legend-color { width: .75rem; height: .75rem; border-radius: 3px; }
.chart-legend-credit, .projection-bar-credit { background: var(--green); }
.chart-legend-debit, .projection-bar-debit { background: var(--red); }
.projection-chart-scroll { overflow-x: auto; padding: 1.35rem 1.2rem 1rem; }
.projection-chart {
    display: flex; align-items: flex-end; gap: .35rem; min-width: max-content; height: 290px; padding: 1rem .5rem 0;
    border-bottom: 1px solid var(--gray-300);
    background: repeating-linear-gradient(to bottom, transparent 0, transparent 54px, var(--gray-100) 55px);
}
.projection-chart-month { display: grid; grid-template-rows: 220px auto; gap: .5rem; width: 152px; height: 100%; text-align: center; }
.projection-chart-bars { display: flex; align-items: flex-end; justify-content: center; gap: .1rem; height: 220px; }
.projection-bar-item { position: relative; display: block; width: 72px; height: 190px; cursor: help; }
.projection-bar-value {
    position: absolute; right: 50%; bottom: calc(var(--bar-height) + .3rem); z-index: 1; transform: translateX(50%);
    font-size: .67rem; line-height: 1; white-space: nowrap;
}
.projection-bar { position: absolute; right: 50%; bottom: 0; display: block; width: 38px; height: var(--bar-height); transform: translateX(50%); border-radius: .4rem .4rem 0 0; transition: filter .15s ease, width .15s ease; }
.projection-bar:hover { filter: brightness(.9); transform: translateX(50%) scaleX(1.08); }
.projection-chart-month-summary { display: grid; gap: .2rem; }
.projection-chart-month-summary > strong { color: var(--gray-700); font-size: .72rem; line-height: 1.2; }
.projection-chart-month-summary > span { font-size: .66rem; font-weight: 750; white-space: nowrap; }
.type-line { display: flex; align-items: center; gap: .6rem; }
.type-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.type-dot.credito { background: var(--green); }
.type-dot.debito { background: var(--red); }
.footer { display: flex; justify-content: space-between; gap: 1rem; padding: 1.25rem 5vw; border-top: 1px solid var(--gray-100); color: var(--gray-500); font-size: .8rem; background: white; }
.field-hint { display: block; margin-top: .35rem; color: var(--gray-500); font-size: .75rem; }
.checkbox-option { display: flex; align-items: flex-start; gap: .7rem; padding: .85rem 1rem; border: 1px solid var(--gray-300); border-radius: .65rem; background: var(--gray-50); cursor: pointer; }
.checkbox-option input { width: auto; margin-top: .15rem; accent-color: var(--blue); }
.checkbox-option span { display: grid; gap: .15rem; }
.checkbox-option small { color: var(--gray-500); font-weight: 400; }
.recurrence-chip { display: inline-block; margin-top: .25rem; color: var(--blue); font-size: .72rem; font-weight: 750; }
[data-recurrence-fields][hidden] { display: none; }
.print-only { display: none; }
.logo-preview { display: flex; justify-content: center; padding: 1rem; border: 1px dashed var(--gray-300); border-radius: 12px; background: var(--gray-50); }
.logo-preview img { width: min(220px, 80%); max-height: 110px; object-fit: contain; }
.form-divider { display: flex; align-items: baseline; gap: .65rem; margin-top: .5rem; padding: 1rem 0 .25rem; border-top: 1px solid var(--gray-100); }
.form-divider span { color: var(--gray-500); font-size: .8rem; }

.auth-page { min-height: 100vh; background: radial-gradient(circle at top left, #e8f0ff, transparent 35%), linear-gradient(145deg, #f7f9fc, #edf2f9); }
.auth-shell { width: min(620px, 92vw); margin: auto; padding: 3rem 0; }
.auth-brand { display: flex; justify-content: center; align-items: center; gap: .75rem; margin-bottom: 1.5rem; }
.auth-brand strong, .auth-brand small { display: block; }
.auth-brand small { margin-top: .2rem; color: var(--gray-500); font-size: .75rem; }
.auth-card { padding: clamp(1.4rem, 4vw, 2.25rem); background: white; border: 1px solid #e1e6ee; border-radius: 20px; box-shadow: 0 20px 60px rgba(20,33,61,.12); }
.auth-card-wide { width: min(720px, 96vw); margin-left: 50%; transform: translateX(-50%); }
.auth-heading { margin-bottom: 1.4rem; text-align: center; }
.auth-heading h1 { margin: .35rem 0 .5rem; font-size: clamp(1.6rem, 4vw, 2.1rem); letter-spacing: -.04em; }
.auth-heading p { margin: 0; color: var(--gray-500); line-height: 1.5; }
.auth-kicker { color: var(--blue); font-size: .75rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.auth-form { display: grid; gap: 1rem; }
.auth-form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.auth-form-grid .full { grid-column: 1 / -1; }
.auth-submit { width: 100%; margin-top: .25rem; min-height: 48px; }
.auth-switch { display: flex; justify-content: center; gap: .4rem; flex-wrap: wrap; margin-top: 1.35rem; color: var(--gray-500); font-size: .9rem; }
.auth-switch a { color: var(--blue); font-weight: 750; }
.auth-footer { margin: 1.25rem 0 0; color: var(--gray-500); text-align: center; font-size: .78rem; }

@media (max-width: 1280px) and (min-width: 1021px) {
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
    .filter-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 1020px) {
    body:not(.auth-page) { padding-left: 0; }
    .topbar {
        position: sticky; inset: auto; width: 100%; min-height: 72px; padding: 0 3vw;
        flex-direction: row; align-items: center; gap: 1rem; overflow: visible;
        background: linear-gradient(110deg, var(--navy), var(--navy-2)); box-shadow: 0 4px 18px rgba(20,33,61,.18);
    }
    .brand { flex: 1; padding: 0; }
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
    .filter-grid { grid-template-columns: repeat(3, 1fr); }
    .quick-grid { grid-template-columns: 1fr; }
    .main-nav {
        position: fixed; inset: 72px 0 auto 0; display: none; max-height: calc(100vh - 72px);
        padding: 1rem 5vw; overflow-y: auto; background: var(--navy); box-shadow: var(--shadow);
    }
    .main-nav.is-open { display: flex; }
    .menu-toggle { display: block; }
    .logout-form { width: auto; margin: 0; }
    .logout-form button { width: auto; padding: .5rem .7rem; }
}
@media (max-width: 680px) {
    body:not(.auth-page) .container { width: min(94vw, 1180px); margin-top: 1.2rem; }
    .brand strong { max-width: 125px; }
    .page-head { align-items: flex-start; flex-direction: column; }
    .stats-grid, .filter-grid, .form-grid, .detail-grid { grid-template-columns: 1fr; }
    .form-grid .full, .detail-item.full { grid-column: 1; }
    .stats-grid { gap: .7rem; }
    .stat { display: block; }
    .stat-value { margin-top: .45rem; }
    .form-actions { justify-content: stretch; }
    .form-actions .btn { flex: 1; }
    .footer { flex-direction: column; }
    .auth-form-grid { grid-template-columns: 1fr; }
    .auth-form-grid .full { grid-column: 1; }
    .auth-shell { padding: 1.5rem 0; }
    .projection-chart-card .section-head { align-items: flex-start; flex-direction: column; }
}
@media print {
    .topbar, .footer, .no-print, .alert { display: none !important; }
    body, html { background: white; }
    body:not(.auth-page) { padding-left: 0; }
    .container { width: 100%; margin: 0; }
    .card { box-shadow: none; border: 1px solid #ddd; }
    .table-wrap { overflow: visible; }
    th, td { padding: .5rem; font-size: .75rem; }
    .print-only { display: block !important; }
    .report-print-head { margin-bottom: 1rem; border-bottom: 2px solid #14213d; }
    .report-print-head h1 { margin-bottom: .35rem; }
    .report-print-head p { margin: .2rem 0; font-size: .78rem; }
    thead { display: table-header-group; }
    tr, .stat { break-inside: avoid; page-break-inside: avoid; }
    .page-head { break-after: avoid; page-break-after: avoid; }
    .projection-chart-card { break-inside: avoid; page-break-inside: avoid; }
    .projection-chart-scroll { overflow: visible; padding: .75rem .5rem .5rem; }
    .projection-chart { width: 100%; min-width: 0; height: 210px; gap: .3rem; padding: .5rem .25rem 0; }
    .projection-chart-month { flex: 1; width: auto; min-width: 0; grid-template-rows: 160px auto; }
    .projection-chart-bars { height: 160px; gap: .2rem; }
    .projection-bar-item { width: 50%; height: 135px; }
    .projection-bar-value { font-size: .52rem; }
    .projection-bar { width: min(24px, 52%); print-color-adjust: exact; -webkit-print-color-adjust: exact; }
    .projection-chart-month-summary > strong { font-size: .6rem; }
    .projection-chart-month-summary > span { font-size: .5rem; }
    @page { size: landscape; margin: 10mm; }
}
