:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #172033;
    --muted: #667085;
    --line: #e4e7ec;
    --primary: #2457d6;
    --primary-dark: #1d46ad;
    --success: #18794e;
    --success-bg: #ecfdf3;
    --warning: #9a6700;
    --warning-bg: #fff7d6;
    --danger: #b42318;
    --danger-bg: #fef3f2;
    --sidebar: #101828;
    --sidebar-muted: #98a2b3;
    --radius: 14px;
    --shadow: 0 8px 28px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { margin: 0; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }

.app-body { min-height: 100vh; }
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: 260px; padding: 22px 18px;
    background: var(--sidebar); color: white; display: flex; flex-direction: column;
    z-index: 30; overflow-y: auto;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 6px 22px; }
.brand > div { min-width: 0; }
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--sidebar-muted); display: block; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: #ffffff; color: var(--sidebar); font-weight: 800; flex: 0 0 auto; }
.nav-list { display: grid; gap: 5px; }
.nav-link { color: #d0d5dd; padding: 10px 12px; border-radius: 9px; font-weight: 600; font-size: 14px; }
.nav-link:hover { background: rgba(255,255,255,.08); color: white; text-decoration: none; }
.nav-link.active { background: rgba(255,255,255,.12); color: white; }
.sidebar-spacer { flex: 1; min-height: 22px; }
.subscription-card { border: 1px solid rgba(255,255,255,.12); border-radius: 12px; padding: 14px; display: grid; gap: 5px; background: rgba(255,255,255,.04); }
.subscription-card .eyebrow { color: var(--sidebar-muted); text-transform: uppercase; letter-spacing: .08em; font-size: 10px; font-weight: 700; }
.subscription-card strong { font-size: 14px; }
.subscription-card span:not(.eyebrow) { color: #d0d5dd; font-size: 12px; }
.subscription-card a { color: white; font-size: 12px; margin-top: 5px; }
.logout-form { margin-top: 10px; }

.main-content { margin-left: 260px; padding: 34px; min-height: 100vh; }
.mobile-topbar { display: none; }
.sidebar-overlay { display: none; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-header h1 { margin: 0 0 6px; font-size: clamp(26px, 3vw, 34px); line-height: 1.15; }
.page-header p { margin: 0; color: var(--muted); }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.metric-card, .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(16,24,40,.03); }
.metric-card { padding: 18px; }
.metric-label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 9px; }
.metric-value { display: block; font-size: clamp(22px, 2.4vw, 30px); font-weight: 750; letter-spacing: -.03em; }
.metric-note { display: block; color: var(--muted); font-size: 12px; margin-top: 7px; }
.card { padding: 20px; }
.card h2, .card h3 { margin-top: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.card-header h2 { margin: 0; font-size: 18px; }
.card-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 9px 14px; border-radius: 9px; border: 1px solid transparent; cursor: pointer; font-weight: 650; font-size: 14px; text-decoration: none; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: white; color: var(--text); border-color: var(--line); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: #fecdca; }

.btn-warning { background: var(--warning-bg); color: var(--warning); border-color: #fedf89; }
.btn-warning:hover { background: #ffefb0; }
.btn-success { background: var(--success-bg); color: var(--success); border-color: #abefc6; }
.btn-success:hover { background: #dcfae6; }

.table-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.table-actions .inline-form { margin: 0; }
.table-actions .btn, .table-actions a { white-space: nowrap; }
.btn-ghost { background: transparent; color: #d0d5dd; border-color: rgba(255,255,255,.15); }
.btn-full { width: 100%; }
.btn-sm { min-height: 34px; padding: 6px 10px; font-size: 12px; }

.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
.summary-list { display: grid; gap: 0; }
.summary-row { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.summary-row:last-child { border-bottom: 0; }
.summary-row span:first-child { color: var(--muted); }
.summary-row strong { text-align: right; }

.status { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 8px; font-size: 12px; font-weight: 700; }
.status-success { color: var(--success); background: var(--success-bg); }
.status-warning { color: var(--warning); background: var(--warning-bg); }
.status-danger { color: var(--danger); background: var(--danger-bg); }
.status-neutral { color: #344054; background: #f2f4f7; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 650px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
td { font-size: 14px; }
.empty-state { color: var(--muted); text-align: center; padding: 28px 12px; }

.form-card { max-width: 760px; }
form p { margin: 0 0 16px; }
label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 650; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="month"], input[type="search"], select, textarea {
    width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #d0d5dd; border-radius: 9px; background: white; color: var(--text); outline: none;
}
textarea { min-height: 100px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #84a9ff; box-shadow: 0 0 0 3px rgba(36,87,214,.12); }
.helptext { display: block; color: var(--muted); font-size: 12px; margin-top: 5px; }
ul.errorlist { color: var(--danger); background: var(--danger-bg); border-radius: 8px; padding: 9px 12px 9px 28px; font-size: 13px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }

.filter-bar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 18px; }
.filter-bar label { margin: 0; }
.filter-bar input { min-width: 200px; }
.filter-tabs { display: flex; gap: 7px; flex-wrap: wrap; margin: 12px 0 18px; }
.filter-tab { padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; background: white; color: var(--text); font-size: 13px; }
.filter-tab.active { background: var(--primary); color: white; border-color: var(--primary); }

.messages { display: grid; gap: 8px; margin-bottom: 18px; }
.message { border: 1px solid var(--line); background: white; border-radius: 10px; padding: 11px 13px; }
.message.success { background: var(--success-bg); color: var(--success); border-color: #abefc6; }
.message.error { background: var(--danger-bg); color: var(--danger); border-color: #fecdca; }
.message.warning { background: var(--warning-bg); color: var(--warning); border-color: #fedf89; }

.section-title { margin: 26px 0 14px; font-size: 19px; }
.muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-right { text-align: right; }
.inline-form { display: inline; }

.public-body { min-height: 100vh; background: radial-gradient(circle at top left, #eef4ff, #f8fafc 45%, #ffffff); display: grid; place-items: center; padding: 24px; }
.public-shell { width: min(100%, 470px); }
.public-brand { display: flex; justify-content: center; align-items: center; gap: 10px; margin-bottom: 18px; }
.public-brand .brand-mark { background: var(--sidebar); color: white; }
.auth-card { background: white; border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { margin-top: 0; }
.auth-card .btn, .auth-card button[type="submit"] { width: 100%; }
.auth-card button[type="submit"] { min-height: 42px; border: 0; border-radius: 9px; background: var(--primary); color: white; font-weight: 700; cursor: pointer; padding: 9px 14px; }

@media (max-width: 1100px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 850px) {
    .mobile-topbar { position: sticky; top: 0; z-index: 20; height: 58px; padding: 0 16px; background: white; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; text-align: center; }
    .menu-toggle { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 9px; background: white; cursor: pointer; }
    .sidebar { transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow); }
    .sidebar.is-open { transform: translateX(0); }
    .sidebar-overlay { display: block; position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 25; opacity: 0; pointer-events: none; transition: opacity .2s ease; }
    .sidebar-overlay.is-open { opacity: 1; pointer-events: auto; }
    .main-content { margin-left: 0; padding: 22px 16px 40px; }
    .page-header { flex-direction: column; }
    .page-actions { width: 100%; }
}

@media (max-width: 620px) {
    .metric-grid, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .metric-card, .card { border-radius: 12px; }
    .quick-actions .btn { flex: 1 1 100%; }
    .page-actions .btn { flex: 1 1 auto; }
    .table-actions { flex-direction: column; align-items: stretch; }
    .table-actions .btn, .table-actions a { width: 100%; }
    .auth-card { padding: 22px 18px; }
}

/* Etapa 7 — Relatórios */
.report-filter-card { margin-bottom: 16px; padding-bottom: 14px; }
.report-filter { margin-bottom: 6px; }
.report-period { margin: 0; font-size: 13px; }
.summary-total { margin-top: 2px; padding-top: 14px; font-size: 15px; }
.summary-total span, .summary-total strong { color: var(--text) !important; }
.report-secondary-metrics { margin: 16px 0; }
.report-result { display: block; font-size: 18px; margin: 8px 0 2px; }
.report-result-card { display: flex; flex-direction: column; justify-content: center; }
@media (max-width: 620px) {
    .report-filter { align-items: stretch; }
    .report-filter > div, .report-filter .btn { width: 100%; }
    .report-filter input { min-width: 0; }
}

/* Etapa 8 — A receber + cobrança */
.receive-search-card { margin-bottom: 14px; }
.receive-search { display:flex; gap:10px; align-items:end; }
.receive-search > div { flex:1; }
.receive-search label { margin-bottom:6px; }
.billing-actions { display:flex; gap:10px; flex-wrap:wrap; margin:18px 0 12px; }
.billing-actions form { margin:0; }
.billing-note { margin-top:14px; line-height:1.55; }
.billing-history { margin-top:16px; }
button:disabled { opacity:.55; cursor:not-allowed; }
@media (max-width:620px) { .receive-search { flex-direction:column; align-items:stretch; } .receive-search .btn { width:100%; } .billing-actions, .billing-actions form, .billing-actions .btn { width:100%; } }
