:root {
  --ink: #18201d;
  --muted: #68726d;
  --paper: #f5f4ef;
  --card: #fffef9;
  --line: #deddd5;
  --green: #245c46;
  --green-dark: #174432;
  --green-pale: #e5eee8;
  --gold: #d69c36;
  --danger: #a33b32;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--paper); }
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }

.site-header {
  position: sticky; top: 0; z-index: 10; min-height: 68px; display: flex; align-items: center;
  gap: 2rem; padding: 0 4vw; background: rgba(255, 254, 249, .96); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: .65rem; color: var(--ink); font-weight: 750; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: var(--green); color: white; font-size: .75rem; letter-spacing: .04em; }
.brand-mark.large { width: 54px; height: 54px; margin: 0 auto 1rem; font-size: 1rem; }
nav { display: flex; align-self: stretch; gap: .25rem; }
nav a { display: flex; align-items: center; padding: 0 .85rem; color: var(--muted); font-weight: 650; border-bottom: 3px solid transparent; }
nav a.active { color: var(--green); border-color: var(--green); }
.account { margin-left: auto; display: flex; align-items: center; gap: 1rem; color: var(--muted); font-size: .9rem; }
.text-button { padding: 0; border: 0; background: none; color: var(--green); cursor: pointer; font: inherit; }

.page-shell { width: min(1160px, 92vw); margin: 0 auto; padding: 3.5rem 0 5rem; }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 2rem; background: radial-gradient(circle at top, #e7eee8, var(--paper) 55%); }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 2rem; margin-bottom: 2rem; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, serif; font-size: clamp(2rem, 5vw, 3.15rem); font-weight: 500; letter-spacing: -.035em; }
h2 { font-family: Georgia, serif; font-weight: 500; }
.eyebrow { margin-bottom: .45rem; color: var(--green); font-size: .75rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.lede { max-width: 720px; color: var(--muted); font-size: 1.05rem; }
.heading-actions, .form-actions { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; }

.button { display: inline-flex; justify-content: center; align-items: center; min-height: 42px; padding: .65rem 1rem; border: 1px solid transparent; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 700; }
.button:hover { text-decoration: none; }
.button.primary { background: var(--green); color: white; }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { border-color: var(--green); background: var(--green-pale); color: var(--green); }
.button.ghost { border-color: var(--line); background: transparent; color: var(--ink); }
.button.danger { margin-left: auto; border-color: #e4bbb7; background: #fff3f1; color: var(--danger); }
.button.full { width: 100%; }

.balance-card { padding: clamp(1.75rem, 5vw, 3.5rem); border-radius: 18px; color: white; background: linear-gradient(135deg, var(--green-dark), var(--green)); box-shadow: 0 14px 40px rgba(24, 54, 42, .16); }
.balance-card h2 { margin-bottom: .3rem; font-size: clamp(1.6rem, 4vw, 2.5rem); }
.balance-card p { margin-bottom: 0; }
.balance-label { opacity: .75; font-size: .8rem; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.balance-amount { margin-top: .5rem; color: #f4c56f; font-size: clamp(2.3rem, 7vw, 4.5rem); font-weight: 800; letter-spacing: -.04em; }
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin: 1rem 0; }
.summary-card { padding: 1.25rem; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.summary-card span { display: block; margin-bottom: .4rem; color: var(--muted); font-size: .82rem; }
.summary-card strong { font-size: 1.3rem; }
.calculation-note { color: var(--muted); font-size: .88rem; }
.calculation-summary { margin: 1.5rem 0; padding: 1.5rem; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.calculation-summary h2 { margin-bottom: 0; font-size: 1.35rem; }
.calculation-steps { display: grid; gap: .75rem; margin: 1.25rem 0; padding: 0; list-style: none; counter-reset: calculation-step; }
.calculation-steps li { display: grid; grid-template-columns: minmax(220px, 1fr) auto; align-items: center; gap: 1rem; padding-bottom: .75rem; border-bottom: 1px solid var(--line); counter-increment: calculation-step; }
.calculation-steps li::before { content: counter(calculation-step); width: 1.65rem; height: 1.65rem; display: grid; grid-row: 1; grid-column: 1; place-items: center; border-radius: 50%; background: var(--green-pale); color: var(--green); font-size: .75rem; font-weight: 800; }
.calculation-steps li span { grid-row: 1; grid-column: 1; margin-left: 2.2rem; color: var(--muted); }
.calculation-steps li strong { grid-row: 1; grid-column: 2; white-space: nowrap; font-variant-numeric: tabular-nums; }
.calculation-summary-footer { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.calculation-summary-footer p { margin: 0; color: var(--muted); font-size: .88rem; }
.review-banner, .info-note { display: flex; justify-content: space-between; gap: 1rem; margin: 1.5rem 0; padding: 1rem 1.25rem; border: 1px solid #dfca94; border-radius: 10px; background: #fff8e5; color: #69501d; }
.review-banner:hover { text-decoration: none; }

.dashboard-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-top: 2rem; }
.panel { overflow: hidden; margin-bottom: 1.25rem; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--line); }
.panel-heading h2 { margin: 0; font-size: 1.25rem; }
.activity-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .95rem 1.25rem; border-bottom: 1px solid var(--line); color: var(--ink); }
.activity-row:last-child { border-bottom: 0; }
.activity-row:hover { background: #faf9f3; text-decoration: none; }
.activity-row span { min-width: 0; }
.activity-row strong, .activity-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-row small { margin-top: .2rem; color: var(--muted); }
.activity-row b { white-space: nowrap; }

.filters { display: grid; grid-template-columns: 2fr repeat(4, 1fr) auto auto; gap: .6rem; margin-bottom: .75rem; }
input, select { width: 100%; min-height: 42px; padding: .62rem .72rem; border: 1px solid #c9cbc5; border-radius: 8px; background: white; color: var(--ink); font: inherit; }
input:focus, select:focus { outline: 3px solid rgba(36, 92, 70, .16); border-color: var(--green); }
.table-actions { display: flex; justify-content: flex-end; margin: .75rem 0; font-size: .9rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .9rem 1rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); background: #f9f8f3; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
td:nth-last-child(2), th.numeric, td.numeric { text-align: right; }
tr.incomplete { background: #fffaec; }
.status { padding: .2rem .45rem; border-radius: 4px; background: #f7e7bc; color: #735619; font-size: .75rem; font-weight: 700; }
.row-action { text-align: right; }

.form-page { width: min(620px, 100%); margin: 0 auto; }
.record-form { margin-top: 1.75rem; }
.field { flex: 1; margin-bottom: 1rem; }
.field-row { display: flex; gap: 1rem; }
.field label { display: block; margin-bottom: .4rem; font-size: .82rem; font-weight: 750; }
.checkbox-field { display: flex; align-items: center; gap: .55rem; min-height: 42px; color: var(--muted); font-size: .9rem; }
.checkbox-field input { width: auto; min-height: auto; }
.checkbox-field label { margin: 0; font-size: inherit; font-weight: 600; }
.bills-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: .6rem; }
.income-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cash-flow-tabs { display: flex; width: fit-content; margin: -1rem 0 1.5rem; padding: .25rem; gap: .2rem; border: 1px solid var(--line); border-radius: 9px; background: var(--card); }
.cash-flow-tabs a { padding: .5rem .8rem; border-radius: 6px; color: var(--muted); font-size: .9rem; font-weight: 700; }
.cash-flow-tabs a:hover { background: var(--green-pale); text-decoration: none; }
.cash-flow-tabs a.active { background: var(--green); color: white; }
.cash-flow-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cash-flow-card small { display: block; margin-top: .55rem; color: var(--muted); font-size: .8rem; }
.cash-flow-card .positive { color: var(--green); }
.cash-flow-card .negative { color: var(--danger); }
.cash-flow-by-month { margin-top: 1.5rem; }
.cash-flow-by-month tr.current-month { background: var(--green-pale); }
.cash-flow-by-month td.positive { color: var(--green); }
.cash-flow-by-month td.negative { color: var(--danger); }
.cash-flow-month-group.has-projection > tr:first-child { cursor: help; }
.projection-details { display: none; }
.cash-flow-month-group.has-projection:hover .projection-details { display: table-row; }
.projection-details td { padding: 0; white-space: normal; background: #f5faf6; }
.projection-breakdown { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0; }
.projection-breakdown div { display: grid; gap: .25rem; padding: .8rem 1rem; text-align: center; }
.projection-breakdown div + div { border-left: 1px solid rgba(36, 92, 70, .18); }
.projection-breakdown dt { order: 2; color: var(--muted); font-size: .78rem; line-height: 1.25; }
.projection-breakdown dd { order: 1; margin: 0; font-size: 1.1rem; font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }
.projection-breakdown .editable-check-in a { color: inherit; }
.projection-breakdown .editable-check-in a:hover { color: var(--green); }
.projection-breakdown .positive { color: var(--green); }
.projection-breakdown .negative { color: var(--danger); }
.month-selector { display: flex; align-items: center; justify-content: center; gap: 1rem; margin: -1rem 0 1rem; }
.month-selector a { display: grid; width: 36px; height: 36px; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: var(--card); color: var(--ink); font-size: 1.25rem; }
.month-selector a:hover { background: var(--green-pale); text-decoration: none; }
.income-sources, .casual-income-register { margin-top: 1.5rem; }
.income-source-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.income-source-row:last-child { border-bottom: 0; }
.income-source-row strong, .income-source-row small { display: block; }
.income-source-row small { margin-top: .3rem; color: var(--muted); }
.income-source-row small span + span::before { content: " · "; }
.row-link { white-space: nowrap; }
.term-history { margin-top: 2rem; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.bills-summary > turbo-frame { display: contents; }
.due-period-control { display: inline; }
.due-total-card select { display: inline; width: auto; min-height: 0; padding: 0 .1rem; border: 0; border-radius: 0; background: transparent; color: inherit; font: inherit; font-weight: inherit; }
.bills-upcoming { margin-top: 1.5rem; }
.upcoming-bill-week + .upcoming-bill-week { border-top: 1px solid var(--line); }
.upcoming-bill-week h3 { margin: 0; padding: 1rem 1.25rem .55rem; color: var(--muted); font-size: .8rem; }
.bills-register { margin-top: 1.25rem; }
.bill-category-group + .bill-category-group { margin-top: 1.5rem; }
.settings-panel { max-width: 480px; }
.bills-filters { grid-template-columns: 2fr 1fr 1fr auto auto auto; margin-top: 1.5rem; }
.bill-summary-section { margin-top: 2rem; }
.bill-summary-panel { margin-top: 1rem; }
.bill-summary-panel .bills-summary { margin-bottom: 0; }
.tag { display: inline-block; margin: .1rem .2rem .1rem 0; padding: .16rem .42rem; border-radius: 999px; background: var(--green-pale); color: var(--green-dark); font-size: .72rem; font-weight: 700; }
.form-errors { margin: 1rem 0; padding: 1rem; border: 1px solid #e5b5af; border-radius: 8px; background: #fff1ef; color: var(--danger); }
.form-errors ul { margin-bottom: 0; }
.source-note { color: var(--muted); font-size: .85rem; }
.form-actions { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }

.auth-card { width: min(420px, 100%); padding: 2.5rem; border: 1px solid var(--line); border-radius: 18px; background: var(--card); text-align: center; box-shadow: 0 18px 50px rgba(45, 54, 49, .1); }
.auth-card h1 { margin-bottom: .75rem; }
.auth-card > p:not(.eyebrow) { color: var(--muted); }
.auth-card .record-form { text-align: left; }
.subtle-link { display: inline-block; margin-top: 1.25rem; font-size: .88rem; }
.flash { margin-bottom: 1.5rem; padding: .8rem 1rem; border-radius: 8px; background: var(--green-pale); color: var(--green-dark); }
.flash.alert { background: #fff1ef; color: var(--danger); }
.review-list { margin-top: 1.25rem; }
.empty-state { margin: 0; padding: 1.5rem; color: var(--muted); }
.print-heading { display: none; }
.calculation-result { margin-bottom: 1.5rem; }
.worksheet-formula { border-left: 5px solid var(--green); }
.worksheet-groups { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start; }
.calculation-group .panel-heading strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.calculation-group .table-wrap, .excluded-entries .table-wrap { border: 0; border-radius: 0; }
.calculation-group td:nth-last-child(2), .excluded-entries td:nth-last-child(2) { text-align: left; }
.calculation-group tfoot th { color: var(--ink); background: var(--green-pale); font-size: .82rem; }
.excluded-entries { margin-top: 1.25rem; border-color: #dfca94; }
.excluded-entries .panel-heading { background: #fff8e5; }
.excluded-entries .panel-heading h2 { margin: 0; }

body.drawer-open { overflow: hidden; }
.drawer-overlay { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: flex-end; }
.drawer-backdrop { position: absolute; inset: 0; width: 100%; border: 0; background: rgba(14, 24, 19, .54); cursor: default; animation: drawer-fade-in .2s ease-out; }
.drawer-panel {
  position: relative; width: min(560px, 100%); height: 100%; overflow-y: auto; padding: 1.5rem clamp(1.25rem, 4vw, 2.5rem) 2rem;
  border-left: 1px solid var(--line); background: var(--card);
  box-shadow: -18px 0 60px rgba(14, 24, 19, .24); animation: drawer-slide-in .28s cubic-bezier(.2, .75, .25, 1);
}
.drawer-handle { width: 44px; height: 5px; margin: 0 auto 1.25rem; border-radius: 999px; background: #c9cbc5; }
.drawer-header { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.drawer-header h1 { font-size: clamp(1.8rem, 5vw, 2.5rem); }
.drawer-close { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 50%; background: var(--paper); color: var(--ink); cursor: pointer; font-size: 1.6rem; line-height: 1; }
.drawer-panel .record-form { margin-top: 1.4rem; }
@keyframes drawer-slide-in { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes drawer-fade-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .drawer-panel, .drawer-backdrop { animation: none; } }

@media (max-width: 900px) {
  .site-header { flex-wrap: wrap; gap: .6rem; padding-top: .65rem; }
  .site-header nav { order: 3; width: 100%; height: 48px; overflow-x: auto; }
  .site-header nav a { padding: 0 .65rem; }
  .account span { display: none; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-columns { grid-template-columns: 1fr; }
  .worksheet-groups { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .bills-filters { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .page-shell { width: min(94vw, 100%); padding-top: 2rem; }
  .page-heading { align-items: stretch; flex-direction: column; gap: 1rem; }
  .heading-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .summary-grid { grid-template-columns: 1fr; }
  .summary-card { display: flex; justify-content: space-between; align-items: center; }
  .summary-card span { margin: 0; }
  .review-banner, .info-note { flex-direction: column; }
  .calculation-steps li { grid-template-columns: 1fr; }
  .calculation-steps li strong { grid-row: 2; grid-column: 1; margin-left: 2.2rem; white-space: normal; }
  .calculation-summary-footer { align-items: stretch; flex-direction: column; }
  .projection-breakdown { grid-template-columns: 1fr; min-width: 0; padding: .5rem 1rem; }
  .projection-breakdown div + div { border-top: 1px solid rgba(36, 92, 70, .18); border-left: 0; }
  .projection-details { display: table-row; }
  .filters { grid-template-columns: 1fr; }
  .bills-filters { grid-template-columns: 1fr; }
  .field-row { flex-direction: column; gap: 0; }
  .auth-card { padding: 2rem 1.5rem; }
  .activity-row { align-items: flex-start; flex-direction: column; }
  .activity-row b { align-self: flex-end; }
}

@media print {
  :root, body { background: white; }
  .site-header, .print-hidden, .flash, turbo-frame, .calculation-summary-footer { display: none !important; }
  .page-shell { width: 100%; margin: 0; padding: 0; }
  .print-heading { display: block; margin-bottom: 1.5rem; }
  .print-heading h1 { font-size: 2rem; }
  .print-heading p:last-child { color: var(--muted); }
  .balance-card { padding: 1.25rem; color: var(--ink); background: white; border: 2px solid var(--green); box-shadow: none; }
  .balance-amount { color: var(--ink); font-size: 2.2rem; }
  .calculation-summary, .panel, .table-wrap { break-inside: avoid; background: white; }
  .worksheet-groups { display: block; }
  .calculation-group { margin-bottom: 1rem; }
  a { color: var(--ink); }
}
