:root {
  color-scheme: light dark;
  --bg: #f4f2ec;
  --panel: #fffdf8;
  --ink: #1e201d;
  --muted: #676960;
  --line: #dedbd1;
  --accent: #2f5d4b;
  --accent-ink: #ffffff;
  --danger: #9d3d32;
  --shadow: 0 10px 30px rgba(30, 32, 29, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141613;
    --panel: #1d201b;
    --ink: #eceee6;
    --muted: #a7aa9f;
    --line: #33372f;
    --accent: #9ad5bb;
    --accent-ink: #142019;
    --danger: #e08f83;
    --shadow: 0 12px 34px rgba(0, 0, 0, .28);
  }
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 800; letter-spacing: .04em; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 30px 28px 64px; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 18px; flex-wrap: wrap; margin-bottom: 20px; }
.eyebrow { margin: 0 0 4px; font-size: .72rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
h1 { margin: 0; font-size: clamp(1.9rem, 4vw, 2.8rem); letter-spacing: -.035em; line-height: 1.05; }
h2 { margin: 0; font-size: 1.05rem; }
.small, .muted { color: var(--muted); font-size: .82rem; }
.month-tools { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.month-picker { display: flex; gap: 7px; align-items: center; }
.month-field { position: relative; display: flex; align-items: center; }
.month-field > .icon { position: absolute; left: 10px; z-index: 1; pointer-events: none; color: var(--muted); }
.month-field input[type="month"] { padding-left: 34px; }
input, select, button { font: inherit; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--ink); padding: 9px 11px; }
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
button { cursor: pointer; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
button:hover { filter: brightness(1.06); }
.button { display: inline-flex; align-items: center; gap: 7px; padding: 9px 11px; border: 1px solid var(--accent); border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-weight: 650; white-space: nowrap; }
.button:hover { text-decoration: none; filter: brightness(1.06); }
.export-button .icon { width: 15px; height: 15px; }
.form-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 22px; }
.form-card.form-panel { max-height: 0; padding: 0; border: 0; background: transparent; box-shadow: none; margin-bottom: 0; opacity: 0; overflow: hidden; transition: max-height .28s ease, opacity .2s ease, padding .28s ease, margin .28s ease; }
.form-card.form-panel.is-open { max-height: 2000px; padding: 18px; border: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow); margin-bottom: 22px; opacity: 1; }
.add-toggle { display: inline-flex; align-items: center; gap: 7px; padding: 8px 12px; white-space: nowrap; }
.form-panel { max-height: 0; opacity: 0; overflow: hidden; transition: max-height .28s ease, opacity .2s ease, margin-top .28s ease; }
.form-panel.is-open { max-height: 620px; opacity: 1; margin-top: 14px; }
.form-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.expense-form { display: grid; gap: 10px; }
.expense-row { display: grid; grid-template-columns: .9fr 1.25fr .8fr 1.4fr auto; gap: 9px; align-items: end; }
.expense-row label { display: grid; gap: 4px; font-size: .76rem; color: var(--muted); }
.expense-row input, .expense-row select { width: 100%; }
.expense-form button { white-space: nowrap; }
.add-row { justify-self: start; display: inline-flex; align-items: center; gap: 6px; background: transparent; color: var(--accent); border-color: var(--line); }
.remove-row { width: 34px; height: 34px; padding: 0; justify-self: end; background: transparent; color: var(--danger); border-color: var(--line); border-radius: 50%; }
.form-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
.add-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.error { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--panel)); border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line)); padding: 9px 11px; border-radius: 9px; }
.section { margin-top: 24px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 9px; }
.section-head p { margin: 3px 0 0; }
.search-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.table-wrap { overflow: hidden; background: transparent; border: 0; border-radius: 0; box-shadow: none; }
.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.data-table th { text-align: left; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 11px 9px; border-bottom: 1px solid var(--line); white-space: normal; }
.data-table tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.data-table th a { color: var(--muted); }
.data-table th a:hover { color: var(--accent); text-decoration: none; }
.data-table td { padding: 10px 9px; border-bottom: 0; vertical-align: middle; word-break: break-word; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table .amount { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .positive { color: var(--danger); }
.data-table .negative { color: var(--accent); }
.recap-table th:nth-child(1) { width: 48%; }
.recap-table th:nth-child(2) { width: 24%; }
.recap-table th:nth-child(3) { width: 28%; }
.pill { display: inline-block; font-size: .72rem; padding: 2px 7px; border-radius: 999px; background: color-mix(in srgb, var(--accent) 12%, var(--panel)); border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line)); }
.check-col { width: 34px; text-align: center; }
.check-col input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.tx-table th:nth-child(1) { width: 30px; }
.tx-table th:nth-child(2) { width: 27%; }
.tx-table th:nth-child(4) { width: 29%; }
.bulk-bar { display: flex; align-items: center; gap: 8px; margin: 0 0 9px; min-height: 34px; }
.bulk-bar[hidden] { display: none; }
.bulk-bar .small { margin-right: auto; }
.bulk-bar form { display: inline; }
.icon-action { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; border-radius: 50%; background: var(--panel); color: var(--ink); border: 1px solid var(--line); }
.icon-action:disabled { opacity: .35; cursor: not-allowed; }
.icon-action.danger { color: var(--danger); }
.search-box { display: flex; align-items: center; gap: 7px; min-width: min(100%, 300px); padding: 0 9px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--muted); }
.search-box .icon { width: 15px; height: 15px; }
.search-box input { flex: 1; min-width: 0; padding: 8px 0; border: 0; outline: 0; background: transparent; }
.search-box:focus-within { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
.empty { padding: 44px 20px; text-align: center; background: var(--panel); border: 1px dashed var(--line); border-radius: 16px; }
.empty.compact { padding: 22px 20px; }
.empty h2 { margin-bottom: 5px; }
.empty p { margin: 0; color: var(--muted); }
.foot { max-width: 1120px; margin: 0 auto; padding: 0 28px 34px; color: var(--muted); font-size: .78rem; }
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 390px); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 30px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 1.8rem; margin: 14px 0 6px; }
.login-card form { display: grid; gap: 8px; margin-top: 20px; }
.login-card label { font-size: .82rem; color: var(--muted); }
.login-card input { width: 100%; }
.login-card button { margin-top: 6px; }
@media (max-width: 760px) {
  .topbar { padding: 12px 16px; }
  .wrap { padding: 20px 16px 48px; }
  .page-head { align-items: flex-start; }
  .month-picker { width: 100%; }
  .month-field { flex: 1; }
  .month-field input { width: 100%; }
  .expense-row { grid-template-columns: 1fr; }
  .remove-row { justify-self: start; }
  .save-button { width: 100%; }
  .form-actions { justify-content: stretch; }
  .section-head { align-items: flex-start; }
  .search-tools { width: 100%; }
  .search-box { flex: 1; width: auto; min-width: 0; }
  .data-table th, .data-table td { padding: 9px 6px; font-size: .78rem; }
  .foot { padding: 0 16px 24px; }
}


@media (orientation: landscape) {
  .transaction-head { flex-wrap: nowrap; align-items: center; }
  .search-tools { width: auto; flex: 1; justify-content: flex-end; flex-wrap: nowrap; }
  .search-box { flex: 1; min-width: 0; }
  .export-button { flex: none; }
}
