:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #667069;
  --line: #dfe4df;
  --paper: #ffffff;
  --canvas: #f4f6f2;
  --green: #276749;
  --green-soft: #e1f0e7;
  --red: #a93f3f;
  --red-soft: #f8e6e2;
  --blue: #385d78;
  --blue-soft: #e5eef4;
  --shadow: 0 18px 50px rgb(25 41 31 / 8%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, #e6efe5 0, transparent 28rem),
    var(--canvas);
}

button, input, select { font: inherit; }
button, select { cursor: pointer; }

.site-header {
  height: 74px;
  padding: 0 max(24px, calc((100vw - 1240px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgb(23 33 27 / 8%);
  background: rgb(255 255 255 / 78%);
  backdrop-filter: blur(16px);
}

.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 11px; color: white; background: var(--ink); font-family: Georgia, serif; font-size: 21px;
}
.brand strong, .brand small { display: block; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }

nav { display: flex; align-items: center; gap: 22px; }
nav a { color: var(--ink); font-size: 14px; font-weight: 650; text-decoration: none; }
.health { color: var(--muted); font-size: 13px; }
.health i { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: #47a16c; box-shadow: 0 0 0 4px #dff0e5; }

main { width: min(1240px, calc(100% - 48px)); margin: 0 auto; padding: 58px 0 72px; }
.hero { display: flex; align-items: end; justify-content: space-between; gap: 32px; }
.eyebrow { margin: 0 0 8px; color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1 { max-width: 700px; margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(38px, 5vw, 62px); font-weight: 500; letter-spacing: -.035em; line-height: 1.02; }
.subtitle { margin: 16px 0 0; color: var(--muted); font-size: 17px; }
.month-control, .filters label, .form-grid label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }

input, select {
  height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px;
  outline: none; color: var(--ink); background: var(--paper);
}
input:focus, select:focus { border-color: #79a68b; box-shadow: 0 0 0 3px rgb(70 130 92 / 12%); }

.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 38px 0 24px; }
.summary-card { min-height: 156px; padding: 24px; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); box-shadow: var(--shadow); }
.summary-card span { color: var(--muted); font-size: 13px; font-weight: 700; }
.summary-card strong { display: block; margin: 18px 0 8px; font-family: Georgia, serif; font-size: 32px; font-weight: 500; font-variant-numeric: tabular-nums; }
.summary-card small { color: var(--muted); }
.summary-card.income strong { color: var(--green); }
.summary-card.expense strong { color: var(--red); }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 24px; align-items: start; }
.ledger-panel, .breakdown-panel { border: 1px solid var(--line); border-radius: 16px; background: var(--paper); box-shadow: var(--shadow); }
.ledger-panel { overflow: hidden; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; padding: 24px 26px 18px; }
h2 { margin: 0; font-family: Georgia, serif; font-size: 25px; font-weight: 500; }

.primary-button, .secondary-button, .text-button, .icon-button { border: 0; border-radius: 9px; font-weight: 750; }
.primary-button { min-height: 42px; padding: 0 16px; color: white; background: var(--ink); }
.primary-button:hover { background: #2f3c34; }
.secondary-button { min-height: 42px; padding: 0 18px; color: var(--ink); background: #edf0ec; }
.text-button { align-self: end; height: 42px; padding: 0 12px; color: var(--green); background: transparent; }
.icon-button { width: 36px; height: 36px; color: var(--muted); background: transparent; font-size: 24px; }

.filters { display: grid; grid-template-columns: 1fr 1.3fr 1fr 1fr auto; gap: 12px; padding: 18px 26px; border-top: 1px solid var(--line); background: #fafbf9; }
.table-wrap { min-height: 260px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 13px 20px; color: var(--muted); background: #f5f7f4; font-size: 11px; letter-spacing: .07em; text-align: left; text-transform: uppercase; }
td { padding: 17px 20px; border-top: 1px solid #edf0ec; font-size: 14px; }
tr:hover td { background: #fbfcfa; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.amount-income { color: var(--green); font-weight: 800; }
.amount-expense { color: var(--ink); font-weight: 800; }
.pill { display: inline-block; padding: 5px 9px; border-radius: 999px; color: var(--blue); background: var(--blue-soft); font-size: 11px; font-weight: 750; text-transform: capitalize; }
.source { color: var(--muted); font-size: 12px; text-transform: capitalize; }
.row-actions { display: flex; justify-content: end; gap: 5px; }
.row-actions button { padding: 6px 8px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 700; }
.row-actions button:hover { color: var(--ink); background: #edf0ec; }
.row-actions .delete:hover { color: var(--red); background: var(--red-soft); }

.empty-state { padding: 54px 20px; text-align: center; }
.empty-state span { color: #9aafa0; font-size: 36px; }
.empty-state h3 { margin: 10px 0 5px; font-family: Georgia, serif; font-size: 20px; }
.empty-state p { margin: 0; color: var(--muted); font-size: 13px; }

.breakdown-panel { padding: 24px; }
.breakdown-list { display: grid; gap: 19px; margin-top: 27px; }
.breakdown-item header { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; font-size: 13px; }
.breakdown-item header span { text-transform: capitalize; }
.breakdown-item header strong { font-variant-numeric: tabular-nums; }
.bar { height: 7px; overflow: hidden; border-radius: 999px; background: #edf0ec; }
.bar i { display: block; height: 100%; border-radius: inherit; background: var(--green); }
.breakdown-empty { color: var(--muted); font-size: 13px; line-height: 1.5; }

dialog { width: min(560px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 18px; color: var(--ink); box-shadow: 0 28px 90px rgb(10 20 14 / 30%); }
dialog::backdrop { background: rgb(15 25 19 / 50%); backdrop-filter: blur(3px); }
dialog form { padding: 28px; }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; margin-bottom: 25px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-error { min-height: 20px; margin: 14px 0 0; color: var(--red); font-size: 13px; }
.dialog-actions { display: flex; justify-content: end; gap: 10px; margin-top: 10px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 10; padding: 13px 17px; border-radius: 10px; color: white; background: var(--ink); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(8px); transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .breakdown-panel { order: -1; }
  .breakdown-list { grid-template-columns: repeat(2, 1fr); }
  .filters { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 680px) {
  .site-header { padding: 0 18px; }
  nav a { display: none; }
  main { width: min(100% - 28px, 1240px); padding-top: 38px; }
  .hero { align-items: stretch; flex-direction: column; }
  .month-control { width: 100%; }
  .summary-grid { grid-template-columns: 1fr; }
  .summary-card { min-height: 130px; }
  .panel-heading { align-items: stretch; flex-direction: column; gap: 16px; }
  .filters, .form-grid, .breakdown-list { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  th:nth-child(4), td:nth-child(4) { display: none; }
  td, th { padding-left: 13px; padding-right: 13px; }
}
