:root {
  --bg: #f6f7f9; --surface: #fff; --text: #1d2330; --muted: #667085; --border: #e3e6eb;
  --primary: #2f6f5e; --primary-ink: #fff; --income: #1f7a4d; --expense: #b42318; --transfer: #475467;
  --warn: #b54708; --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.topbar { background: var(--text); color: #fff; }
.topbar .inner { max-width: 1180px; margin: 0 auto; padding: .6rem 1rem; display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 700; color: #fff; font-size: 1.1rem; letter-spacing: .02em; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a { color: #d0d5dd; padding: .3rem .6rem; border-radius: 6px; }
.nav a:hover, .nav a.active { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.userbox { display: flex; gap: .5rem; align-items: center; color: #d0d5dd; }
.userbox button { background: none; border: 1px solid #667085; color: #fff; padding: .2rem .6rem; }

main { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.grid { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1.1rem; }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.4rem; font-weight: 650; font-variant-numeric: tabular-nums; }

.btn, button { display: inline-block; background: var(--primary); color: var(--primary-ink); border: 1px solid var(--primary); border-radius: 7px; padding: .45rem .9rem; font: inherit; cursor: pointer; }
.btn:hover, button:hover { filter: brightness(1.08); text-decoration: none; }
.btn.secondary, button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.danger, button.danger { background: var(--expense); border-color: var(--expense); }
.btn.small, button.small { padding: .2rem .55rem; font-size: .85rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tfoot td { font-weight: 650; border-top: 2px solid var(--border); }

.income { color: var(--income); }
.expense { color: var(--expense); }
.transfer { color: var(--transfer); }
.neg { color: var(--expense); }
.badge { display: inline-block; font-size: .75rem; padding: .05rem .5rem; border-radius: 999px; background: #eef1f4; color: var(--muted); }
.badge.income { background: #e7f5ee; }
.badge.expense { background: #fdecea; }
.badge.warn { background: #fef0c7; color: var(--warn); }
.badge.dup { background: #fef0c7; color: var(--warn); }

.progress { height: 10px; background: #eef1f4; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--income); }
.progress.warn > span { background: #f79009; }
.progress.over > span { background: var(--expense); }

form p, .field { margin: 0 0 .9rem; }
label { display: block; font-weight: 550; margin-bottom: .25rem; }
input[type=text], input[type=number], input[type=date], input[type=month], input[type=password], input[type=file], select, textarea {
  width: 100%; max-width: 100%; padding: .45rem .6rem; border: 1px solid #cfd4dc; border-radius: 7px; font: inherit; background: #fff;
}
input[type=checkbox], input[type=radio] { margin-right: .35rem; }
.helptext { display: block; color: var(--muted); font-size: .82rem; margin-top: .2rem; }
.errorlist { color: var(--expense); list-style: none; padding: 0; margin: .2rem 0; font-size: .88rem; }
.form-card { max-width: 560px; }
form ul:not(.errorlist) { list-style: none; padding: 0; margin: 0; }
form ul:not(.errorlist) label { font-weight: 400; display: flex; align-items: center; }

.filters { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
.filters p { margin: 0; }
.filters label { font-size: .82rem; }

.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li { padding: .6rem .9rem; border-radius: 8px; margin-bottom: .5rem; background: #e7f5ee; border: 1px solid #b7e1c9; }
.messages li.error { background: #fdecea; border-color: #f5c2bd; }
.messages li.info { background: #eaf2fd; border-color: #c3d8f6; }

.pagination { display: flex; gap: .75rem; align-items: center; margin-top: 1rem; }
.empty { padding: 1.5rem; text-align: center; color: var(--muted); }
.chart-box { position: relative; height: 300px; }
.auth-card { max-width: 400px; margin: 3rem auto; }
.inline-form { display: inline; }

@media (max-width: 640px) {
  .nav { order: 3; flex-basis: 100%; }
  h1 { font-size: 1.35rem; }
  .hide-sm { display: none; }
}
