@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@500;600;700;800&display=swap');

:root {
  color-scheme: light;
  --paper: #f4f5ef;
  --surface: #fffefa;
  --ink: #202b25;
  --muted: #69756e;
  --line: #dce2da;
  --green: #245b43;
  --green-dark: #174530;
  --green-soft: #e8f0e8;
  --red: #ad4c40;
  --red-soft: #f8ece9;
  --gold: #e8d8ab;
  --shadow: 0 14px 36px rgb(33 58 44 / 7%);
  font-family: 'DM Sans', 'Segoe UI', sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--paper); color: var(--ink); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid #b39143; outline-offset: 2px; }
.hidden { display: none !important; }

.auth-layout { min-height: 100vh; display: grid; grid-template-columns: minmax(260px, 1fr) minmax(320px, 460px); gap: clamp(40px, 10vw, 150px); align-items: center; max-width: 1140px; padding: 64px 44px; margin: auto; }
.auth-intro { max-width: 515px; }
.eyebrow { margin: 0 0 14px; color: var(--green); font-size: 11px; font-weight: 700; letter-spacing: .15em; }
.auth-intro h1, .page-heading h1 { font-family: Manrope, 'Segoe UI', sans-serif; font-weight: 700; letter-spacing: -.055em; }
.auth-intro h1 { margin: 0; font-size: clamp(42px, 6vw, 76px); line-height: 1.05; }
.auth-intro h1 span { color: var(--green); }
.intro-copy { max-width: 350px; margin-top: 24px; color: var(--muted); font-size: 16px; line-height: 1.7; }
.auth-card { padding: 36px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.auth-card h2, .panel h2 { margin: 0; font-family: Manrope, 'Segoe UI', sans-serif; font-size: 18px; letter-spacing: -.025em; }
.auth-card form, .form-panel form { display: flex; flex-direction: column; }
.auth-card label, .dialog-form label, .form-panel label, .filter-row label { margin: 18px 0 7px; color: #45524b; font-size: 12px; font-weight: 700; }
.auth-card input, .dialog-form input, .dialog-form select, .form-panel input, .filter-row input, .filter-row select { width: 100%; min-height: 43px; padding: 10px 12px; color: var(--ink); background: #fff; border: 1px solid #ccd5ce; border-radius: 7px; }
.auth-card input::placeholder, .dialog-form input::placeholder, .filter-row input::placeholder { color: #9aa49d; }
.muted { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.text-button { padding: 10px 0; color: var(--green); background: none; border: 0; font-size: 13px; font-weight: 700; text-align: left; }
.notice { min-height: 20px; margin: 12px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.notice.error, .form-error { color: var(--red); }
.notice.success { color: var(--green); }

.topbar { position: sticky; z-index: 5; top: 0; display: flex; min-height: 72px; align-items: center; gap: 34px; padding: 0 max(28px, calc((100vw - 1260px) / 2)); background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; flex-shrink: 0; align-items: center; gap: 10px; color: var(--ink); font-family: Manrope, 'Segoe UI', sans-serif; font-size: 15px; font-weight: 800; text-decoration: none; }
.brand-mark { display: grid; width: 31px; height: 31px; place-items: center; color: white; background: var(--green); border-radius: 8px 8px 8px 3px; font-size: 15px; }
.topbar nav { display: flex; height: 72px; align-items: stretch; gap: 4px; }
.nav-link { position: relative; padding: 0 13px; color: var(--muted); background: none; border: 0; font-size: 13px; font-weight: 600; }
.nav-link.active { color: var(--green-dark); }
.nav-link.active::after { position: absolute; right: 12px; bottom: -1px; left: 12px; height: 2px; background: var(--green); content: ''; }
.account { display: flex; min-width: 0; align-items: center; gap: 14px; margin-left: auto; }
.account span { overflow: hidden; max-width: 210px; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.button { min-height: 39px; padding: 9px 15px; border: 1px solid transparent; border-radius: 7px; font-size: 12px; font-weight: 700; transition: background-color .15s ease, border-color .15s ease; }
.button.primary { color: white; background: var(--green); }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { color: var(--green-dark); background: var(--green-soft); border-color: #d1e0d2; }
.button.quiet { color: #506058; background: transparent; border-color: var(--line); }
.button.quiet:hover { background: #f6f7f2; }
.button.full { width: 100%; margin-top: 22px; }

.page-wrap { max-width: 1260px; margin: auto; padding: 42px 32px 72px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.page-heading .eyebrow { margin-bottom: 8px; }
.page-heading h1 { margin: 0; font-size: 32px; }
.page-heading .muted { margin-top: 6px; }
.notice-banner { margin: 0 0 20px; padding: 12px 15px; color: var(--green-dark); background: var(--green-soft); border: 1px solid #d0e0d1; border-radius: 8px; font-size: 13px; }
.notice-banner.error { color: #8d352b; background: var(--red-soft); border-color: #efd5d0; }
.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; margin-bottom: 18px; }
.summary-card { min-height: 130px; padding: 22px 22px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.summary-card p { margin: 0 0 18px; color: var(--muted); font-size: 12px; font-weight: 600; }
.summary-card strong { color: var(--ink); font-family: Manrope, 'Segoe UI', sans-serif; font-size: clamp(21px, 2.3vw, 30px); letter-spacing: -.04em; }
.balance-card { background: var(--green-dark); border-color: var(--green-dark); }
.balance-card p { color: #c8d8cd; }
.balance-card strong { color: white; }
.content-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(260px, .9fr); gap: 18px; margin-bottom: 18px; }
.panel { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.chart-panel, .category-panel, .table-panel, .report-panel, .form-panel { padding: 21px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.panel-heading .muted { font-size: 12px; }
.chart-wrap { position: relative; height: 220px; margin-top: 16px; }
#cash-chart { display: block; width: 100%; height: 100%; }
.legend { display: flex; justify-content: center; gap: 24px; margin-top: 4px; color: var(--muted); font-size: 11px; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; }
.income-dot { background: var(--green); }
.expense-dot { background: #d5aa62; }
.category-chart { display: flex; flex-direction: column; gap: 17px; margin-top: 23px; }
.category-line { display: grid; grid-template-columns: minmax(80px, 1fr) 2fr auto; align-items: center; gap: 11px; font-size: 11px; }
.category-line .name { overflow: hidden; color: #48554d; text-overflow: ellipsis; white-space: nowrap; }
.category-line .amount { color: var(--ink); font-weight: 700; }
.track { height: 6px; overflow: hidden; background: #edf0e9; border-radius: 6px; }
.track span { display: block; height: 100%; background: #d5aa62; border-radius: inherit; }
.empty-state { padding: 28px 12px; color: var(--muted); font-size: 13px; text-align: center; }
.table-panel { margin-bottom: 18px; }
.table-panel > .panel-heading { margin-bottom: 17px; }
.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; text-align: left; }
th { padding: 10px 12px; color: var(--muted); background: #f7f8f4; font-size: 10px; font-weight: 700; letter-spacing: .035em; text-transform: uppercase; white-space: nowrap; }
td { padding: 13px 12px; border-bottom: 1px solid #edf0ea; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.description-cell { min-width: 160px; font-weight: 700; }
.sub-cell { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; font-weight: 400; }
.type-pill { display: inline-block; padding: 5px 8px; border-radius: 20px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.type-pill.income { color: var(--green-dark); background: var(--green-soft); }
.type-pill.expense { color: #94463b; background: var(--red-soft); }
.row-actions { display: flex; justify-content: flex-end; gap: 7px; }
.row-action { padding: 5px 7px; color: var(--green); background: none; border: 0; font-size: 11px; font-weight: 700; }
.row-action.delete { color: var(--red); }
.filter-row { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 18px; }
.filter-row label { display: flex; min-width: 160px; flex-direction: column; gap: 7px; margin: 0; }
.filter-row input, .filter-row select { min-height: 38px; padding: 8px 10px; font-size: 12px; }
.report-filters { flex-wrap: wrap; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.report-filters label { flex: 0 1 190px; }
.report-totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; padding: 20px 0; }
.report-totals div { display: flex; flex-direction: column; gap: 7px; }
.report-totals span { color: var(--muted); font-size: 11px; }
.report-totals strong { font-family: Manrope, 'Segoe UI', sans-serif; font-size: 18px; }
.category-layout { display: grid; grid-template-columns: minmax(240px, .75fr) minmax(0, 1.6fr); align-items: start; gap: 18px; }
.form-panel h2 { margin-bottom: 6px; }
.form-panel form { margin-top: 14px; }
.form-panel form label { margin-top: 4px; }
.form-panel form .button { align-self: flex-start; margin-top: 15px; }
.optional { color: var(--muted); font-weight: 400; }

#transaction-dialog { width: min(480px, calc(100vw - 28px)); max-height: min(90vh, 820px); padding: 0; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 13px; box-shadow: 0 25px 80px rgb(0 0 0 / 22%); }
#transaction-dialog::backdrop { background: rgb(25 42 32 / 48%); backdrop-filter: blur(2px); }
.dialog-form { display: flex; flex-direction: column; padding: 25px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.dialog-heading .eyebrow { margin-bottom: 6px; font-size: 10px; }
.dialog-heading h2 { margin: 0; font-family: Manrope, 'Segoe UI', sans-serif; font-size: 20px; }
.icon-button { width: 32px; height: 32px; color: var(--muted); background: none; border: 1px solid var(--line); border-radius: 50%; font-size: 20px; line-height: 1; }
.dialog-form label { margin-top: 14px; }
.dialog-form input, .dialog-form select { min-height: 41px; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.two-fields > div { display: flex; flex-direction: column; }
.form-error { min-height: 18px; margin: 9px 0 0; font-size: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 13px; }

@media (max-width: 850px) {
  .auth-layout { grid-template-columns: 1fr; max-width: 570px; gap: 28px; padding: 45px 25px; }
  .auth-intro h1 { font-size: 50px; }
  .intro-copy { margin-top: 14px; }
  .topbar { flex-wrap: wrap; gap: 0 16px; padding: 0 18px; }
  .topbar nav { order: 3; width: 100%; height: 48px; overflow-x: auto; }
  .nav-link { flex: 0 0 auto; padding: 0 12px; }
  .account { margin-left: auto; }
  .page-wrap { padding: 30px 20px 55px; }
  .content-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .auth-layout { gap: 24px; padding: 32px 18px; }
  .auth-intro h1 { font-size: 42px; }
  .auth-card { padding: 24px; }
  .topbar { min-height: 63px; }
  .brand { font-size: 13px; }
  .brand-mark { width: 28px; height: 28px; }
  .account { gap: 7px; }
  .account span { max-width: 105px; font-size: 10px; }
  .account .button { min-height: 33px; padding: 7px 10px; font-size: 10px; }
  .topbar nav { margin: 0 -18px; padding: 0 8px; }
  .nav-link { font-size: 11px; }
  .page-wrap { padding: 24px 14px 42px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .page-heading h1 { font-size: 28px; }
  .page-heading .button { width: 100%; }
  .summary-grid { grid-template-columns: 1fr; gap: 9px; }
  .summary-card { min-height: 95px; padding: 15px; }
  .summary-card p { margin-bottom: 10px; }
  .summary-card strong { font-size: 24px; }
  .chart-panel, .category-panel, .table-panel, .report-panel, .form-panel { padding: 16px; }
  .chart-wrap { height: 190px; }
  .filter-row { align-items: stretch; flex-direction: column; }
  .filter-row label { width: 100%; }
  .report-filters > .button { flex: 1; }
  .report-totals { grid-template-columns: 1fr; gap: 12px; }
  .report-totals div { flex-direction: row; justify-content: space-between; }
  .category-layout { grid-template-columns: 1fr; }
  .category-line { grid-template-columns: 100px 1fr auto; gap: 7px; }
  .category-line .amount { font-size: 10px; }
  .dialog-form { padding: 21px; }
}
@media print {
  body { background: white; }
  .topbar, .page-heading .button, .report-filters, .row-actions, .text-button, .type-pill { display: none !important; }
  .page-wrap { max-width: none; padding: 0; }
  .page-section.hidden { display: none !important; }
  #reports-page.hidden { display: block !important; }
  .panel { border: 0; }
}

.setup-layout { min-height: 100vh; display: grid; place-items: center; padding: 28px 18px; background: var(--paper); }
.setup-card { width: min(100%, 460px); padding: 34px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.setup-card h1 { margin: 0; font-family: Manrope, 'Segoe UI', sans-serif; font-size: 29px; letter-spacing: -.04em; }
.setup-card form { display: flex; flex-direction: column; margin-top: 21px; }
.setup-card label, .profile-panel label { margin: 16px 0 7px; color: #45524b; font-size: 12px; font-weight: 700; }
.setup-card input, .profile-panel input { width: 100%; min-height: 43px; padding: 10px 12px; color: var(--ink); background: #fff; border: 1px solid #ccd5ce; border-radius: 7px; }
.setup-card button { margin-top: 17px; }
.setup-email { padding: 9px 11px; color: var(--muted); background: #f7f8f4; border-radius: 6px; font-size: 12px; }
.profile-panel { max-width: 620px; margin-top: 18px; padding: 21px; }
.profile-panel form { display: grid; grid-template-columns: 1fr; max-width: 430px; }
.profile-panel .button { justify-self: start; margin-top: 16px; }
.activity-panel { margin-top: 0; }
button:disabled { cursor: wait; opacity: .65; }
@media (max-width: 560px) {
  .setup-card { padding: 25px 21px; }
  .profile-panel { padding: 16px; }
}
@media print {
  .page-section:not(#reports-page), .notice-banner { display: none !important; }
  #reports-page { display: block !important; }
  .report-totals { grid-template-columns: repeat(3, 1fr); }
  .report-totals div { flex-direction: column; }
  .report-filters { display: none !important; }
  .page-heading { margin-bottom: 15px; }
  .panel { padding: 0; }
}
