:root {
    --bg: #f5f7f8;
    --panel: #ffffff;
    --text: #172126;
    --muted: #65737b;
    --line: #dce3e7;
    --primary: #167c7a;
    --primary-dark: #0e5f5d;
    --danger: #a33b3b;
    --warning: #9c6a12;
    --ok: #24734a;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}
button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    padding: 14px 22px;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
}
.topbar strong { display: block; }
.topbar span { color: var(--muted); font-size: 13px; }
.topbar nav { display: flex; gap: 8px; flex-wrap: wrap; }
.topbar nav a {
    padding: 8px 10px;
    border-radius: 6px;
    color: #304047;
}
.topbar nav a:hover { background: #edf3f3; }
.layout { max-width: 1280px; margin: 0 auto; padding: 22px; }
.toolbar, .filters {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
h1 { margin: 0; font-size: 28px; letter-spacing: 0; }
h2 { margin: 0 0 14px; font-size: 20px; letter-spacing: 0; }
h3 { margin: 0 0 8px; font-size: 17px; letter-spacing: 0; }
.btn, button {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    min-height: 38px;
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
}
.btn.primary, button.primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn.primary:hover, button.primary:hover { background: var(--primary-dark); }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 6px;
    padding: 9px 10px;
    min-height: 38px;
}
textarea { resize: vertical; }
label { display: grid; gap: 6px; color: #34444c; font-size: 13px; }
.filters {
    justify-content: flex-start;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}
.filters input, .filters select { width: auto; min-width: 140px; }
.cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.cards article, .panel, .grid-list article {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}
.cards span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.cards strong { font-size: 24px; letter-spacing: 0; }
.table-wrap {
    overflow: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}
table { width: 100%; border-collapse: collapse; min-width: 980px; }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 11px; vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); background: #f9fbfb; }
td small { display: block; color: var(--muted); margin-top: 3px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.actions form { display: inline; }
.actions button { min-height: 32px; padding: 5px 8px; font-size: 13px; }
.pill, .status {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    border: 1px solid var(--line);
}
.pill.income { color: var(--ok); background: #eaf7ef; border-color: #cce8d7; }
.pill.expense { color: var(--danger); background: #fbebeb; border-color: #efcccc; }
.status.paid { color: var(--ok); background: #eaf7ef; }
.status.pending { color: #4c5b64; background: #eef2f4; }
.status.partial { color: var(--warning); background: #fff4de; }
.status.overdue { color: var(--danger); background: #fbebeb; }
.status.cancelled { color: #606060; background: #eeeeee; }
.grid-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: 14px;
}
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 28px; }
.flash, .success, .error {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 14px;
}
.flash.success, .success { background: #eaf7ef; color: var(--ok); border: 1px solid #cce8d7; }
.flash.error, .error { background: #fbebeb; color: var(--danger); border: 1px solid #efcccc; }
dialog {
    width: min(860px, calc(100vw - 24px));
    border: 0;
    border-radius: 8px;
    padding: 0;
    box-shadow: 0 24px 80px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(17, 28, 34, .45); }
.modal-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 13px;
    padding: 20px;
}
.modal-form h2, .span2, .modal-form menu { grid-column: 1 / -1; }
.modal-form menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 8px 0 0; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
.install {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}
.auth-card {
    width: min(560px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 22px;
}
.grid-form { display: grid; gap: 12px; }
@media (max-width: 820px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    .layout { padding: 14px; }
    .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .modal-form { grid-template-columns: 1fr; }
    .filters input, .filters select, .filters .btn { width: 100%; }
}
@media (max-width: 520px) {
    .cards { grid-template-columns: 1fr; }
    h1 { font-size: 24px; }
}
