:root {
  color-scheme: light;
  --paper: #f5f4f0;
  --ink: #20282b;
  --muted: #687476;
  --line: #dce2de;
  --line-soft: #e9ede9;
  --card: #fff;
  --green: #235a56;
  --green-dark: #174844;
  --green-pale: #e8f1ee;
  --blue-input: #f4f9fa;
  --warning-bg: #fbf3e8;
  --warning-ink: #69452e;
  --shadow: 0 8px 24px -18px rgb(26 43 41 / 24%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
}

* { box-sizing: border-box; }
body { min-width: 320px; min-height: 100vh; margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.5 Inter, ui-sans-serif, system-ui, sans-serif; }
button, input { font: inherit; }
button { color: inherit; }
.page-shell { width: min(1180px, calc(100% - 48px)); margin: 0 auto; padding: 42px 0 30px; }
.page-header { display: flex; justify-content: space-between; align-items: end; gap: 28px; padding: 0 0 24px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 8px; color: var(--green); font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(30px, 4vw, 43px); line-height: 1.13; letter-spacing: -.04em; }
.intro { max-width: 700px; margin: 12px 0 0; color: var(--muted); font-size: 17px; }
.header-actions { display: flex; flex: 0 0 auto; gap: 9px; }
.button { display: inline-flex; min-height: 44px; justify-content: center; align-items: center; gap: 7px; padding: 9px 15px; border: 1px solid var(--line); border-radius: 11px; cursor: pointer; font-size: 14px; font-weight: 650; transition: background .15s ease, border-color .15s ease, transform .15s ease; }
.button:hover { border-color: #9eb8b0; transform: translateY(-1px); }
.button:focus-visible, .icon-button:focus-visible, .text-button:focus-visible, input:focus-visible { outline: 3px solid #91b9ad; outline-offset: 2px; }
.button-secondary { background: var(--card); }
.button-primary { border-color: var(--green); background: var(--green); color: white; }
.button-primary:hover { border-color: var(--green-dark); background: var(--green-dark); }
.card { margin-top: 20px; padding: 22px; border: 1px solid var(--line); border-radius: 17px; background: var(--card); box-shadow: var(--shadow); }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
h2 { margin: 0; font-size: 20px; line-height: 1.3; letter-spacing: -.02em; }
.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.method-pill { display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; border: 1px solid #cce0d8; border-radius: 100px; background: var(--green-pale); color: var(--green-dark); font-size: 12px; font-weight: 700; white-space: nowrap; }
.method-pill span { display: grid; width: 17px; height: 17px; place-items: center; border-radius: 50%; background: var(--green); color: white; font-size: 11px; }
.settings-grid { display: grid; grid-template-columns: minmax(200px, 1fr) minmax(200px, 1fr) minmax(240px, 1.1fr); gap: 14px; align-items: stretch; }
.contract-fields { display: grid; grid-template-columns: minmax(200px, 1.3fr) minmax(180px, 1fr) minmax(180px, 1fr); gap: 14px; }
.field { display: grid; align-content: start; gap: 7px; color: #445153; font-size: 13px; font-weight: 650; }
.field input, .fixed-value { width: 100%; min-height: 45px; padding: 10px 12px; border: 1px solid #d6dfdc; border-radius: 10px; background: var(--blue-input); color: var(--ink); font-size: 15px; font-weight: 600; }
.field input { accent-color: var(--green); }
.field small { color: var(--muted); font-size: 11px; font-weight: 400; line-height: 1.4; }
.fixed-value { display: flex; align-items: center; gap: 9px; background: #f5f7f5; }
.fixed-value span { color: var(--muted); font-size: 12px; font-weight: 400; }
.source-note { display: flex; align-items: center; gap: 10px; padding: 10px 13px; border: 1px solid var(--line-soft); border-radius: 10px; background: #fbfcfb; }
.source-dot { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; background: #a2b2ad; }
.source-dot.is-loading { background: #dc9a4c; animation: pulse 1s ease-in-out infinite alternate; }
.source-dot.is-ready { background: #3d8b6c; }
.source-dot.is-error { background: #c65751; }
.source-note strong, .source-note small { display: block; }
.source-note strong { font-size: 13px; }
.source-note small { margin-top: 2px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.print-contract-info { display: none; }
.print-contract-info.is-visible { display: block; margin-top: 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: #43504e; font-size: 12px; }
@keyframes pulse { to { opacity: .35; } }
.notice { margin: 17px 0 0; padding: 10px 12px; border-left: 3px solid #d6a15d; border-radius: 5px; background: var(--warning-bg); color: var(--warning-ink); font-size: 12px; }
.payments-heading { align-items: center; }
.payments-heading .button { min-height: 40px; }
.table-scroll { max-width: 100%; overflow-x: auto; }
table { border-collapse: collapse; font-variant-numeric: tabular-nums; }
.payment-table { width: 100%; min-width: 780px; }
th { padding: 10px 12px; background: #f0f4f1; color: #52605e; font-size: 11px; font-weight: 700; text-align: left; white-space: nowrap; }
.payment-table th:first-child { border-radius: 8px 0 0 8px; }
.payment-table th:last-child { border-radius: 0 8px 8px 0; }
td { padding: 8px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.payment-row:last-child td { border-bottom: 0; }
.payment-table input[type="text"], .payment-table input[type="date"], .payment-table input[type="number"] { min-height: 40px; padding: 8px 9px; border: 1px solid #dbe2df; border-radius: 8px; background: #fff; color: var(--ink); font-size: 13px; }
.payment-table .row-amount { width: 130px; text-align: right; font-variant-numeric: tabular-nums; }
.payment-table input:disabled { background: #f1f3f2; color: #76817f; }
.row-label { width: 100%; min-width: 145px; }
.row-due, .row-paid-date { width: 150px; }
.amount-input-wrap { display: flex; align-items: center; gap: 6px; }
.amount-input-wrap span { color: var(--muted); font-size: 13px; }
.status-editor { display: grid; min-width: 142px; gap: 6px; }
.payment-table .row-status { min-height: 38px; padding: 7px 28px 7px 9px; border: 1px solid #dbe2df; border-radius: 8px; background: #fff; color: var(--ink); font-size: 12px; }
.payment-table .row-paid-date[hidden] { display: none; }
.payment-table .row-paid-date:not([hidden]) { width: 100%; }
.icon-button { display: grid; width: 34px; height: 34px; place-items: center; border: 1px solid transparent; border-radius: 8px; background: transparent; color: #83908d; cursor: pointer; font-size: 22px; line-height: 1; }
.icon-button:hover { border-color: #f0d5d2; background: #fff5f4; color: #ac514c; }
.table-help, .formula-note, .data-note { margin: 12px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 18px; }
.summary-card { display: grid; align-content: start; gap: 7px; min-height: 125px; padding: 17px 19px; border: 1px solid var(--line); border-radius: 15px; background: var(--card); box-shadow: var(--shadow); }
.summary-main { border-color: #b9d2c9; background: linear-gradient(145deg, #f5fbf8, #fff 75%); }
.summary-label { color: #596663; font-size: 12px; font-weight: 650; }
.summary-value { color: var(--ink); font-size: clamp(21px, 2.2vw, 29px); line-height: 1.2; letter-spacing: -.035em; overflow-wrap: anywhere; }
.summary-main .summary-value { color: var(--green-dark); }
.summary-foot { color: var(--muted); font-size: 11px; line-height: 1.4; }
.breakdown-card { margin-top: 18px; }
.breakdown-table { width: 100%; min-width: 850px; }
.breakdown-table td, .breakdown-table th { padding: 11px 10px; }
.breakdown-table td { font-size: 12px; }
.breakdown-table td:nth-child(1), .breakdown-table td:nth-child(2), .breakdown-table td:nth-child(5) { white-space: nowrap; }
.breakdown-table td:nth-child(5) { color: #53625f; font-size: 11px; }
.breakdown-table td:last-child, .breakdown-table th:last-child { text-align: right; }
.breakdown-table tfoot td { border-top: 1px solid var(--line); background: #f5f8f6; font-weight: 750; }
.empty-cell { height: 70px; color: #87918f; text-align: center; }
.formula-note { margin-top: 15px; }
.formula-note strong { color: #3c4d49; }
.data-note a { color: var(--green); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.page-footer { display: flex; justify-content: space-between; gap: 14px; margin: 16px 2px 0; color: #798482; font-size: 11px; }
.text-button { padding: 0; border: 0; background: none; color: #667571; cursor: pointer; font: inherit; text-decoration: underline; text-underline-offset: 3px; }
.text-button:hover { color: #a1443e; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; clip-path: inset(50%); }
.is-hidden { display: none !important; }

@media (max-width: 780px) {
  .page-shell { width: min(100% - 30px, 620px); padding-top: 26px; }
  .page-header { align-items: flex-start; flex-direction: column; gap: 16px; }
  .header-actions { width: 100%; }
  .header-actions .button { flex: 1; }
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .contract-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .source-note { grid-column: 1 / -1; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-main { grid-column: 1 / -1; }
}
@media (max-width: 520px) {
  .page-shell { width: calc(100% - 22px); padding-top: 20px; }
  .intro { font-size: 15px; }
  .card { margin-top: 13px; padding: 15px; border-radius: 13px; }
  .section-heading { gap: 10px; margin-bottom: 14px; }
  .settings-card .section-heading { flex-direction: column; }
  .section-heading p { font-size: 12px; }
  .method-pill { align-self: flex-start; padding: 5px 7px; font-size: 10px; }
  .settings-grid { grid-template-columns: 1fr; gap: 12px; }
  .contract-fields { grid-template-columns: 1fr; gap: 12px; }
  .source-note { grid-column: auto; }
  .notice { margin-top: 13px; }
  .payments-heading { align-items: flex-start; flex-direction: column; }
  .payments-heading .button { width: 100%; }
  .table-scroll { overflow-x: visible; }
  .payment-table, .breakdown-table { display: block; width: 100%; min-width: 0; }
  .payment-table thead, .breakdown-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); clip-path: inset(50%); white-space: nowrap; }
  .payment-table tbody { display: grid; gap: 10px; }
  .payment-table tr.payment-row { position: relative; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
  .payment-table td { display: grid; min-width: 0; align-content: start; gap: 4px; padding: 0; border: 0; }
  .payment-table td::before, .breakdown-table tbody td::before { content: attr(data-label); color: #66736f; font-size: 10px; font-weight: 650; line-height: 1.3; }
  .payment-table td:first-child { grid-column: 1 / -1; padding-right: 34px; }
  .payment-table td:nth-child(4) { grid-column: 1 / -1; }
  .payment-table td:last-child { position: absolute; top: 8px; right: 8px; }
  .payment-table td:last-child::before { content: none; }
  .payment-table .row-label, .payment-table .row-amount, .payment-table .row-due, .payment-table .row-paid-date { box-sizing: border-box; width: 100%; min-width: 0; }
  .amount-input-wrap { width: 100%; min-width: 0; }
  .amount-input-wrap input { flex: 1 1 auto; min-width: 0; }
  .status-editor { width: 100%; min-width: 0; }
  .payment-table .row-status { width: 100%; }
  .breakdown-table tbody { display: grid; gap: 9px; }
  .breakdown-table tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px 8px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
  .breakdown-table tbody td { display: grid; min-width: 0; align-content: start; gap: 3px; padding: 3px 2px; border: 0; text-align: left !important; white-space: normal !important; overflow-wrap: anywhere; font-size: 12px; }
  .breakdown-table tbody td:first-child, .breakdown-table tbody td:nth-child(5) { grid-column: 1 / -1; }
  .breakdown-table tbody td:nth-child(5) { color: #53625f; font-size: 11px; }
  .breakdown-table tbody td:last-child { color: var(--green-dark); font-weight: 750; }
  .breakdown-table tbody .empty-cell { display: block; grid-column: 1 / -1; height: auto; min-height: 48px; align-content: center; text-align: center !important; }
  .breakdown-table tfoot { display: block; margin-top: 9px; }
  .breakdown-table tfoot tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px 8px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: #f5f8f6; }
  .breakdown-table tfoot td { min-width: 0; padding: 3px 2px; border: 0 !important; background: transparent !important; text-align: left !important; white-space: normal; overflow-wrap: anywhere; font-size: 10px; }
  .breakdown-table tfoot td:first-child, .breakdown-table tfoot td:nth-child(5) { grid-column: 1 / -1; }
  .breakdown-table tfoot td:last-child { color: var(--green-dark); font-size: 13px; }
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 12px; }
  .summary-card { min-height: 104px; padding: 12px; }
  .summary-label { font-size: 11px; }
  .summary-value { font-size: 20px; }
  .summary-foot { font-size: 10px; }
  .breakdown-card { margin-top: 12px; }
  .page-footer { flex-direction: column; gap: 6px; }
}
@media print {
  :root, body { background: #fff; }
  .page-shell { width: 100%; padding: 0; }
  .header-actions, #add-payment, .remove-row, .page-footer, .notice, .contract-card { display: none !important; }
  .print-contract-info:not(:empty) { display: block; margin: 10px 0 14px; padding: 9px 11px; border: 1px solid #dce2de; border-radius: 8px; color: #263330; font-size: 10px; }
  .card, .summary-card { box-shadow: none; break-inside: avoid; }
  .card { margin-top: 12px; padding: 14px; }
  .table-scroll { overflow: visible; }
  .payment-table, .breakdown-table { min-width: 0; }
  .payment-table th, .payment-table td, .breakdown-table th, .breakdown-table td { padding: 5px; font-size: 9px; }
  .summary-card { min-height: 0; }
  .summary-grid { gap: 8px; }
  a { color: inherit; }
}
