:root {
  --ink: #13231f;
  --muted: #66736e;
  --paper: #f5f4ef;
  --surface: #ffffff;
  --surface-soft: #edf1ed;
  --line: #d9dfda;
  --green: #174f3f;
  --green-2: #2d755f;
  --mint: #dff3e8;
  --gold: #c18b32;
  --gold-soft: #f6ecd8;
  --red: #a33b32;
  --red-soft: #f8e4e1;
  --shadow: 0 18px 55px rgba(23, 48, 40, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 8% 0%, rgba(45, 117, 95, 0.09), transparent 30rem),
    var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

a { color: inherit; }

button, input, select, textarea { font: inherit; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(230px, 1fr) auto minmax(230px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 12px clamp(20px, 4vw, 64px);
  border-bottom: 1px solid rgba(19, 35, 31, 0.08);
  background: rgba(245, 244, 239, 0.92);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  width: fit-content;
  text-decoration: none;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: var(--green);
  color: white;
  font-family: Georgia, serif;
  font-size: 23px;
  box-shadow: 0 7px 16px rgba(23, 79, 63, 0.2);
}

.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: -0.02em; }
.brand small { color: var(--muted); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; }

.primary-nav { display: flex; align-items: center; gap: 6px; }
.primary-nav a, .account-tools a, .link-button {
  padding: 8px 11px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
}
.primary-nav a:hover, .account-tools a:hover, .link-button:hover { background: white; color: var(--ink); }

.account-tools { justify-self: end; display: flex; align-items: center; gap: 3px; }
.account-tools > span { margin-right: 4px; color: var(--ink); font-size: 14px; font-weight: 700; }
.account-tools form { display: inline; }
.link-button { border: 0; background: transparent; cursor: pointer; }

.page-shell { width: min(1440px, 100%); margin: 0 auto; padding: 48px clamp(20px, 4vw, 64px) 80px; }

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 30px;
  margin-bottom: 32px;
}

.dashboard-heading { align-items: center; }
.page-heading h1, .form-intro h1 {
  margin: 0;
  max-width: 780px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(36px, 5vw, 64px);
  font-weight: 500;
  letter-spacing: -0.045em;
  line-height: 1.02;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green-2);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.lede { max-width: 720px; margin: 14px 0 0; color: var(--muted); font-size: 18px; }
.heading-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
}
.btn-primary { background: var(--green); color: white; box-shadow: 0 7px 18px rgba(23, 79, 63, 0.18); }
.btn-primary:hover { background: #103e31; }
.btn-secondary { border-color: var(--line); background: white; color: var(--ink); }
.btn-quiet { color: var(--muted); }
.btn-danger { background: var(--red); color: white; }
.text-link { color: var(--green-2); font-size: 14px; font-weight: 750; text-decoration: none; }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.metric-card {
  min-height: 168px;
  display: flex;
  flex-direction: column;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.74);
  box-shadow: 0 8px 30px rgba(23, 48, 40, 0.04);
}
.metric-card p { margin: 0; color: var(--muted); font-size: 13px; font-weight: 750; text-transform: uppercase; letter-spacing: 0.08em; }
.metric-card strong { margin: auto 0 3px; font-family: Georgia, serif; font-size: clamp(30px, 3vw, 44px); font-weight: 500; letter-spacing: -0.04em; }
.metric-card span { color: var(--muted); font-size: 13px; }
.metric-card-strong { background: var(--green); color: white; border-color: var(--green); }
.metric-card-strong p, .metric-card-strong span { color: rgba(255,255,255,.72); }
.metric-card-alert { background: var(--gold-soft); border-color: #e8d4ad; }
.metric-card-good { background: var(--mint); border-color: #c7e4d5; }

.dashboard-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 18px; }
.span-5 { grid-column: span 5; }
.span-7 { grid-column: span 7; }
.span-12 { grid-column: span 12; }

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px 24px 17px; }
.panel-heading h2 { margin: 0; font-family: Georgia, serif; font-size: 25px; font-weight: 500; letter-spacing: -0.025em; }
.status-chip { padding: 5px 9px; border-radius: 999px; background: var(--surface-soft); color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.status-chip-muted { opacity: .6; }
.status-pending { background: var(--gold-soft); color: #805717; }
.status-posted { background: var(--mint); color: var(--green); }
.status-stale { background: var(--red-soft); color: var(--red); }
.status-active { background: var(--mint); color: var(--green); }
.status-error, .status-needs_attention { background: var(--red-soft); color: var(--red); }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #f8faf8; color: var(--muted); font-size: 11px; letter-spacing: .08em; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { padding: 15px 18px; border-bottom: 1px solid #edf0ed; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td small { display: block; margin-top: 2px; color: var(--muted); }
.table-link { display: block; color: inherit; text-decoration: none; }
.amount-cell { font-variant-numeric: tabular-nums; font-weight: 750; }
.amount-credit { color: var(--green-2); }
.row-actions { text-align: right; }
.row-actions a { margin-left: 12px; color: var(--green-2); font-size: 13px; font-weight: 700; }

.empty-state { padding: 54px 24px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; color: var(--ink); font-family: Georgia, serif; font-size: 24px; font-weight: 500; }
.empty-state p { max-width: 520px; margin: 7px auto 18px; }
.empty-state.compact { padding: 28px 24px; }
.empty-state.compact strong { font-size: 20px; }

.cycle-window { display: flex; align-items: center; gap: 12px; padding: 8px 24px 17px; color: var(--muted); font-size: 13px; font-weight: 750; }
.cycle-window > div { display: grid; grid-template-columns: 1fr 1fr; flex: 1; gap: 3px; }
.cycle-window i { height: 5px; border-radius: 99px; background: var(--green-2); }
.cycle-window i:last-child { background: #9db9af; }
.cycle-totals { display: grid; grid-template-columns: 1fr 1fr; margin: 0 24px; border: 1px solid var(--line); border-radius: 13px; overflow: hidden; }
.cycle-totals > div { padding: 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.cycle-totals > div:nth-child(2n) { border-right: 0; }
.cycle-totals > div:nth-last-child(-n+2) { border-bottom: 0; }
.cycle-totals span, .period-list span { display: block; color: var(--muted); font-size: 11px; font-weight: 750; text-transform: uppercase; letter-spacing: .06em; }
.cycle-totals strong { display: block; margin-top: 3px; font-size: 19px; }
.period-list { padding: 18px 24px 24px; }
.period-list article { display: grid; grid-template-columns: 1.5fr 1fr 1fr; gap: 10px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.period-list article:last-child { border-bottom: 0; }
.period-list article > a { grid-column: 1/-1; color: var(--green-2); font-size: 13px; font-weight: 750; }
.reconciled-note { grid-column: 1/-1; color: var(--green-2); font-size: 12px; font-weight: 750; }

.cash-position-grid { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); }
.cash-position-grid > div { padding: 22px 24px; border-right: 1px solid var(--line); }
.cash-position-grid > div:last-child { border-right: 0; }
.cash-position-grid span, .cash-position-grid small { display: block; color: var(--muted); }
.cash-position-grid span { font-size: 11px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.cash-position-grid strong { display: block; margin: 8px 0 3px; font-family: Georgia, serif; font-size: 28px; font-weight: 500; }
.cash-position-grid small { font-size: 12px; }

.card-exposure-list { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border-top: 1px solid var(--line); }
.card-exposure-list article { padding: 20px 24px; background: white; }
.card-exposure-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-exposure-heading a { text-decoration: none; }
.card-exposure-heading strong, .card-exposure-heading small { display: block; }
.card-exposure-heading small, .exposure-asof { color: var(--muted); font-size: 11px; }
.exposure-line { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 8px 0; border-top: 1px solid #edf0ed; }
.exposure-line > span { color: var(--muted); font-size: 13px; }
.exposure-line > span small { display: block; max-width: 250px; color: var(--muted); font-size: 10px; }
.exposure-line strong { font-variant-numeric: tabular-nums; }
.modifier-line strong { color: var(--gold); }
.exposure-total { margin-top: 3px; padding-top: 11px; border-top-color: var(--ink); }
.exposure-total > span, .exposure-total strong { color: var(--ink); font-weight: 800; }
.exposure-asof { display: block; margin-top: 9px; }
.balance-reconciliation { margin-bottom: 18px; padding: 0 24px 18px; }
.balance-reconciliation .panel-heading { margin: 0 -24px; }

.connection-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; margin: -14px 0 22px; }
.connection-strip > div { position: relative; padding: 16px 18px; border: 1px solid var(--line); border-radius: 13px; background: white; }
.connection-strip strong, .connection-strip small { display: block; }
.connection-strip strong { margin-top: 9px; }
.connection-strip small { color: var(--muted); }
.connection-strip form { position: absolute; top: 10px; right: 10px; }
.form-note { color: var(--muted); }

.account-card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); }
.account-card { min-height: 240px; padding: 24px; background: var(--surface); text-decoration: none; }
.account-card:hover { background: #fafbf9; }
.account-card > div { display: flex; gap: 6px; }
.account-card p { margin: 28px 0 2px; color: var(--muted); font-size: 13px; }
.account-card h2 { margin: 0; font-family: Georgia, serif; font-size: 25px; font-weight: 500; }
.account-card > strong { display: block; margin-top: 32px; font-family: Georgia, serif; font-size: 34px; font-weight: 500; }
.account-card > small { display: block; color: var(--muted); }
.account-metrics { grid-template-columns: repeat(3, 1fr); }

.snapshot-list > div { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 16px; padding: 14px 24px; border-top: 1px solid var(--line); }
.snapshot-list span { color: var(--muted); font-size: 13px; }
.snapshot-list strong { font-size: 17px; }
.snapshot-list small { grid-column: 1/-1; color: var(--muted); font-size: 11px; }

.month-card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; padding: 0 24px 24px; }
.month-card { padding: 18px; border: 1px solid var(--line); border-radius: 13px; text-decoration: none; transition: transform .15s ease, border-color .15s ease; }
.month-card:hover { transform: translateY(-2px); border-color: #aebbb5; }
.month-card span, .month-card strong, .month-card small { display: block; }
.month-card span { color: var(--muted); font-size: 13px; font-weight: 700; }
.month-card strong { margin: 16px 0 2px; font-family: Georgia, serif; font-size: 27px; font-weight: 500; }
.month-card small { color: var(--muted); }

.ledger-list > a { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 24px; border-bottom: 1px solid var(--line); text-decoration: none; }
.ledger-list > a:last-child { border-bottom: 0; }
.ledger-list > a:hover { background: #fafbf9; }
.ledger-list > a > div:first-child { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 10px; }
.ledger-list small { grid-column: 2; color: var(--muted); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gold); }
.status-paid { background: var(--green-2); }
.ledger-amount { text-align: right; }
.ledger-amount strong, .ledger-amount span { display: block; }
.ledger-amount strong { font-size: 21px; }
.ledger-amount span { color: var(--muted); font-size: 12px; }

.detail-total { display: flex; align-items: baseline; gap: 18px; margin-bottom: 18px; padding: 22px 26px; border-radius: var(--radius); background: var(--green); color: white; }
.detail-total span { color: rgba(255,255,255,.72); font-size: 12px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.detail-total strong { font-family: Georgia, serif; font-size: 42px; font-weight: 500; }
.detail-total small { margin-left: auto; color: rgba(255,255,255,.75); }

.form-shell { display: grid; grid-template-columns: minmax(260px, .8fr) minmax(380px, 1.2fr); gap: clamp(30px, 7vw, 100px); align-items: start; max-width: 1100px; margin: 28px auto; }
.form-shell.narrow { max-width: 900px; }
.form-intro { position: sticky; top: 110px; }
.form-intro h1 { font-size: clamp(36px, 4vw, 54px); }
.form-intro > p:last-child { color: var(--muted); }
.form-card { padding: 28px; overflow: visible; }
.field-row, .form-card > div { margin-bottom: 20px; }
.field-row label, .form-card > div > label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 800; }
.field-row input, .field-row select, .field-row textarea, .form-card > div > input, .form-card > div > select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid #bdc8c2;
  border-radius: 10px;
  background: white;
  color: var(--ink);
}
.field-row input:focus, .field-row select:focus, .form-card input:focus { outline: 3px solid rgba(45, 117, 95, .14); border-color: var(--green-2); }
.field-row small { display: block; margin-top: 5px; color: var(--muted); }
.errorlist { margin: 6px 0 0; padding: 0; color: var(--red); font-size: 13px; list-style: none; }
.field-error input, .field-error select { border-color: var(--red); }
.form-actions { display: flex; align-items: center; gap: 8px; margin: 28px 0 0 !important; padding-top: 20px; border-top: 1px solid var(--line); }
.confirm-amount { padding: 24px; border-radius: 12px; background: var(--red-soft); color: var(--red); font-family: Georgia, serif; font-size: 34px; }
.confirm-amount small { display: block; color: var(--muted); font-family: inherit; font-size: 14px; }

.message-stack { position: fixed; top: 84px; right: 24px; z-index: 30; width: min(420px, calc(100vw - 40px)); }
.message { margin-bottom: 8px; padding: 13px 16px; border: 1px solid #bfd8cb; border-radius: 11px; background: #ecf8f1; box-shadow: var(--shadow); }
.message.error { border-color: #ebc0bb; background: var(--red-soft); }

.focus-shell { min-height: calc(100vh - 72px); display: grid; place-items: center; padding: 40px 20px; }
.auth-card { width: min(480px, 100%); padding: 36px; border: 1px solid var(--line); border-radius: var(--radius); background: white; box-shadow: var(--shadow); }
.auth-card h1 { margin: 0 0 8px; font-family: Georgia, serif; font-size: 42px; font-weight: 500; }
.auth-card form p { margin: 18px 0; }
.auth-card label { display: block; margin-bottom: 6px; font-weight: 750; }
.auth-card input, .auth-card select { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid #bdc8c2; border-radius: 10px; }
.auth-card button, .auth-card input[type="submit"] { width: auto; padding: 10px 16px; border: 0; border-radius: 10px; background: var(--green); color: white; font-weight: 750; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1040px) {
  .site-header { grid-template-columns: 1fr auto; }
  .primary-nav { order: 3; grid-column: 1/-1; justify-content: center; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .span-5, .span-7 { grid-column: span 12; }
  .cash-position-grid { grid-template-columns: 1fr 1fr; }
  .cash-position-grid > div:nth-child(2) { border-right: 0; }
  .cash-position-grid > div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .account-card-grid { grid-template-columns: 1fr 1fr; }
  .card-exposure-list { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .site-header { position: static; grid-template-columns: 1fr; gap: 10px; padding: 12px 18px; }
  .account-tools { position: absolute; top: 17px; right: 15px; }
  .account-tools > span, .account-tools > a { display: none; }
  .primary-nav { grid-column: auto; width: 100%; justify-content: flex-start; overflow-x: auto; }
  .page-shell { padding: 32px 16px 60px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .metric-grid { grid-template-columns: 1fr; }
  .account-metrics { grid-template-columns: 1fr; }
  .metric-card { min-height: 145px; }
  .form-shell { grid-template-columns: 1fr; gap: 20px; }
  .form-intro { position: static; }
  .ledger-list > a { align-items: flex-start; }
  .period-list article { grid-template-columns: 1fr 1fr; }
  .period-list article > div:first-child { grid-column: 1/-1; }
  .detail-total { align-items: flex-start; flex-direction: column; gap: 4px; }
  .detail-total small { margin-left: 0; }
  th, td { padding: 12px 14px; }
  .cash-position-grid, .account-card-grid { grid-template-columns: 1fr; }
  .cash-position-grid > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .cash-position-grid > div:last-child { border-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
