: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; }
.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; }
.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); }

body.drawer-open { overflow: hidden; }
.drawer-overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.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(760px, 100%); max-height: 90vh; overflow-y: auto; padding: 1rem clamp(1.25rem, 5vw, 2.5rem) 2rem;
  border: 1px solid var(--line); border-bottom: 0; border-radius: 22px 22px 0 0; background: var(--card);
  box-shadow: 0 -18px 60px rgba(14, 24, 19, .24); animation: drawer-slide-up .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-up { from { transform: translateY(100%); } to { transform: translateY(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; }
  .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; }
  .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; }
}
