:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-2: #eef2f7;
    --text: #172033;
    --muted: #667085;
    --line: #d9e0ea;
    --primary: #1d4ed8;
    --primary-strong: #1e40af;
    --income: #15803d;
    --expense: #b91c1c;
    --warning: #b45309;
    --shadow: 0 18px 45px rgba(15, 23, 42, .08);
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 280px 1fr; transition: grid-template-columns .2s ease; }
body.sidebar-collapsed .shell { grid-template-columns: 82px 1fr; }

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 22px 18px;
    background: #111827;
    color: #e5e7eb;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow-x: hidden;
    transition: width .2s ease, padding .2s ease, transform .2s ease;
}

body.sidebar-collapsed .sidebar { padding: 22px 12px; }

.brand, .login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
    overflow: hidden;
    flex: 0 0 42px;
}
.brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.brand strong, .login-brand strong { display: block; font-size: 16px; }
.brand small, .login-brand small { color: #9ca3af; }
body.sidebar-collapsed .brand > span:last-child,
body.sidebar-collapsed .nav span,
body.sidebar-collapsed .logout-form span { display: none; }
body.sidebar-collapsed .brand { justify-content: center; }
body.sidebar-collapsed .nav a,
body.sidebar-collapsed .logout-form button { justify-content: center; padding: 12px 8px; }

.nav { display: grid; gap: 6px; }
.nav a, .logout-form button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 0;
    border-radius: 8px;
    padding: 12px;
    color: #cbd5e1;
    background: transparent;
}
.nav a:hover, .nav a.active, .logout-form button:hover { background: #1f2937; color: #fff; }
.nav svg, .logout-form svg, button svg, .user-chip svg { width: 18px; height: 18px; }
.logout-form { margin-top: auto; }

.content { padding: 26px; min-width: 0; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 18px;
    margin-bottom: 22px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.topbar-title { min-width: 0; margin-right: auto; }
.topbar h1 { margin: 2px 0 0; font-size: 28px; letter-spacing: 0; }
.topbar-logo {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--line);
}
.eyebrow { color: var(--muted); font-size: 13px; font-weight: 700; text-transform: uppercase; }
.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 9px 12px;
}
.menu-toggle { display: inline-flex; flex: 0 0 40px; }
.sidebar-backdrop { display: none; }

.filter-bar, .actions-row {
    display: flex;
    align-items: end;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.filter-bar {
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.filter-bar.compact { flex: 1; margin: 0; }
.actions-row { justify-content: space-between; align-items: center; }
.actions-row.right { justify-content: flex-end; }

label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 11px;
    color: var(--text);
    background: #fff;
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, .12); }

.primary-button, .secondary-button, .icon-button, .ok-button {
    border: 0;
    border-radius: 8px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 800;
}
.primary-button { background: var(--primary); color: #fff; padding: 10px 14px; }
.primary-button:hover { background: var(--primary-strong); }
.secondary-button { background: var(--surface-2); color: var(--text); padding: 10px 14px; }
.icon-button { width: 40px; background: var(--surface-2); color: var(--text); }
.ok-button { min-width: 48px; padding: 8px 12px; background: #dcfce7; color: #166534; }
.ok-button:hover { background: #bbf7d0; }
.full { width: 100%; }

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.metric-card {
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.metric-card span { color: var(--muted); font-weight: 800; font-size: 13px; }
.metric-card strong { display: block; margin: 10px 0 6px; font-size: 26px; letter-spacing: 0; }
.metric-card small { color: var(--muted); }
.metric-card.income strong { color: var(--income); }
.metric-card.expense strong { color: var(--expense); }
.metric-card.balance strong { color: var(--primary); }
.metric-card.pending strong { color: var(--warning); }
.paid-total-card { text-align: right; }
.paid-total-card strong { color: var(--income); }
.compact-metrics {
    grid-template-columns: minmax(240px, 360px);
    justify-content: end;
    margin-bottom: 18px;
}
.report-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: stretch;
    width: 100%;
}
.report-metrics .metric-card {
    min-height: 118px;
    display: grid;
    align-content: center;
}
.report-metrics .metric-card strong { font-size: 25px; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr); gap: 18px; min-width: 0; }
.dividendos-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, .85fr); gap: 18px; align-items: start; min-width: 0; }
.panel {
    max-width: 100%;
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
}
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.panel h2 { margin: 0; font-size: 18px; letter-spacing: 0; }
.muted { color: var(--muted); font-size: 13px; }

.category-list { display: grid; gap: 10px; }
.category-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}
.category-row:last-child { border-bottom: 0; }
.category-row strong { font-size: 14px; }
.category-row small { color: var(--muted); }

.table-wrap { width: 100%; max-width: 100%; min-width: 0; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 780px; }
.data-table th {
    text-align: left;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    padding: 12px;
    border-bottom: 1px solid var(--line);
}
.data-table td { padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.details-panel .table-wrap { overflow-x: visible; }
.parcelas-table {
    min-width: 0;
    table-layout: fixed;
}
.parcelas-table th,
.parcelas-table td {
    padding: 9px 6px;
    overflow-wrap: normal;
}
.parcelas-table th:nth-child(1),
.parcelas-table td:nth-child(1) {
    width: 9%;
    text-align: left;
}
.parcelas-table th:nth-child(2),
.parcelas-table td:nth-child(2) { width: 31%; }
.parcelas-table th:nth-child(3),
.parcelas-table td:nth-child(3) {
    width: 22%;
    white-space: nowrap;
}
.parcelas-table th:nth-child(4),
.parcelas-table td:nth-child(4) {
    width: 18%;
    text-align: center;
}
.parcelas-table th:nth-child(5),
.parcelas-table td:nth-child(5) {
    width: 20%;
    text-align: left;
}
.parcelas-table .row-actions {
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 4px;
}
.parcelas-table .badge {
    min-width: 64px;
    justify-content: center;
    padding: 4px 7px;
    font-size: 11px;
    white-space: nowrap;
}
.parcelas-table .ok-button {
    min-width: 42px;
    min-height: 34px;
    padding: 6px 8px;
    line-height: 1;
    white-space: nowrap;
}
.parcelas-table .icon-button {
    width: 34px;
    flex: 0 0 34px;
    min-height: 34px;
}
.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}
.badge.recebido, .badge.pago, .badge.ativa, .badge.ativo, .badge.admin { color: #166534; background: #dcfce7; }
.badge.realizado { color: #166534; background: #dcfce7; }
.badge.pendente, .badge.previsto, .badge.usuario { color: #92400e; background: #fef3c7; }
.badge.atrasado, .badge.inativa, .badge.inativo { color: #991b1b; background: #fee2e2; }
.color-dot { width: 22px; height: 22px; border-radius: 999px; display: inline-block; border: 1px solid var(--line); }

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
    gap: 14px;
    width: 100%;
    min-width: 0;
}
.dividendo-card {
    display: grid;
    gap: 14px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    cursor: pointer;
    transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.dividendo-card:hover { border-color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow); }
.dividendo-card-header, .dividendo-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.dividendo-card-header strong {
    min-width: 0;
    overflow-wrap: anywhere;
}
.dividendo-values { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.dividendo-values span {
    display: grid;
    gap: 3px;
    padding: 9px;
    border-radius: 8px;
    background: #f8fafc;
    min-width: 0;
}
.dividendo-values small, .dividendo-card-footer small { color: var(--muted); font-weight: 700; }
.dividendo-values b { font-size: 13px; overflow-wrap: anywhere; }
.dividendo-progress {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #e5e7eb;
}
.dividendo-progress span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--income);
}
.details-panel { position: sticky; top: 22px; min-width: 0; padding: 14px; }
.details-panel.inline-details-panel {
    grid-column: 1 / -1;
    position: static;
    width: 100%;
    cursor: default;
}
.small-dialog { width: min(520px, 100%); }

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: none;
    place-items: center;
    padding: 18px;
    background: rgba(15, 23, 42, .52);
}
.modal.open { display: grid; }
.modal-dialog {
    width: min(720px, 100%);
    max-width: 100%;
    max-height: 92vh;
    overflow: auto;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 24px 80px rgba(15, 23, 42, .26);
}
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; padding: 18px; }
.form-grid header, .form-grid footer { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.form-grid header { padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.form-grid footer { justify-content: flex-end; padding-top: 10px; border-top: 1px solid var(--line); }
.form-grid h2 { margin: 0; }
.span-2 { grid-column: span 2; }

.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 48%, #ecfdf5 100%);
}
.login-panel {
    width: min(420px, 100%);
    padding: 28px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.login-brand { margin-bottom: 24px; }
.form-stack { display: grid; gap: 14px; }

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 80;
    display: none;
    max-width: 420px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #111827;
    color: #fff;
    box-shadow: var(--shadow);
}
.toast.error { background: #991b1b; }
.toast.success { background: #166534; }

.app-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-top: auto;
    padding: 13px 0 0;
    border-top: 1px solid var(--line);
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}
.app-footer a,
.footer-clock { color: #a2266e; }
.app-footer a {
    font-style: italic;
    text-decoration: underline;
}
