#receivables {
  --debt-ink: #263f35;
  --debt-fill: #edf1eb;
  --debt-edge: #b5c4b8;
}

#receivables-workspace {
  display: grid;
  gap: 15px;
  overflow-wrap: anywhere;
}

#receivables-workspace [hidden] { display: none !important; }
#receivables-workspace button { min-height: 42px; width: fit-content; font-weight: 620; }
#receivables button.debt-primary { color: #fff; background: var(--debt-ink); border-color: var(--debt-ink); }
#receivables button.debt-primary:hover:not(:disabled) { background: #34564a; }
#receivables-workspace summary { cursor: pointer; scroll-margin-top: 4rem; }
#receivables-workspace summary:hover { color: var(--debt-ink); }

.debt-panel { min-width: 0; padding: 17px 19px; border: 1px solid var(--line); background: var(--panel); }
.debt-control { border-inline-start: 4px solid var(--debt-ink); }
.debt-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px 15px; flex-wrap: wrap; margin-bottom: 11px; }
.debt-kicker { display: block; margin-bottom: 3px; color: var(--muted); font-size: .69rem; font-weight: 700; letter-spacing: .095em; text-transform: uppercase; }
.debt-note { margin: 7px 0; color: var(--muted); font-size: .84rem; }
.debt-empty { margin: 8px 0 0; padding: 10px 0; color: var(--muted); border-block: 1px solid var(--line); }
.debt-message { margin: 7px 0 0; padding: 7px 9px; font-size: .88rem; }
.debt-message:empty { position: absolute; width: 1px; height: 1px; padding: 0; margin: 0; overflow: hidden; clip-path: inset(50%); }
.debt-message[data-tone="error"], .debt-warnings { border-inline-start: 2px solid var(--warning); color: var(--warning); background: #fbede6; }
.debt-message[data-tone="success"] { border-inline-start: 2px solid var(--debt-ink); color: var(--debt-ink); background: var(--debt-fill); }
.debt-warnings { margin: 10px 0 0; padding: 7px 10px 7px 28px; font-size: .86rem; }
.debt-warnings li + li { margin-top: 5px; }

.debt-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
#debt-filter { max-width: 640px; }
.debt-field { display: grid; gap: 4px; align-content: start; min-width: 0; color: var(--muted); font-size: .84rem; }
.debt-field input, .debt-field select, .debt-field textarea { min-height: 39px; text-align: left; }
.debt-field textarea {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: #fffdfa;
  color: var(--text);
  padding: 6px 8px;
  font: inherit;
  resize: vertical;
}
.debt-wide, .debt-fields > .debt-message { grid-column: 1 / -1; }
.debt-check { display: flex; align-items: center; gap: 7px; min-height: 44px; color: var(--muted); font-size: .84rem; cursor: pointer; }
.debt-check input { width: 17px; height: 17px; margin: 0; accent-color: var(--debt-ink); }
.debt-metrics, .debt-aging {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 12px 0 0;
  font-variant-numeric: tabular-nums;
}
.debt-metrics:empty, .debt-aging:empty { display: none; }
.debt-metrics { border-block: 1px solid var(--debt-edge); }
.debt-metrics > div, .debt-aging > div { padding: 7px 9px; min-width: 0; border-inline-end: 1px solid var(--line); }
.debt-metrics > div:first-child { color: var(--debt-ink); background: var(--debt-fill); }
.debt-metrics > div:nth-child(2) { color: var(--warning); }
.debt-metrics > div:last-child, .debt-aging > div:last-child { border-inline-end: 0; }
.debt-metrics dt, .debt-aging dt { color: var(--muted); font-size: .82rem; }
.debt-metrics dd, .debt-aging dd { margin: 2px 0 0; line-height: 1.23; font-weight: 650; }
.debt-metrics dd { font-size: clamp(.97rem, 1.45vw, 1.45rem); }
.debt-aging { margin-top: 5px; border-bottom: 1px solid var(--line); }
.debt-aging dd { font-size: .87rem; }

.debt-record { padding: 8px 0; border-top: 1px solid var(--line); }
.debt-record:last-child { border-bottom: 1px solid var(--line); }
.debt-record > summary {
  display: grid;
  align-items: baseline;
  gap: 7px 10px;
  min-height: 32px;
  font-size: .91rem;
  font-variant-numeric: tabular-nums;
}
.debt-record > summary::before { content: ""; width: 7px; height: 7px; border-right: 1px solid currentColor; border-bottom: 1px solid currentColor; transform: rotate(-45deg); }
.debt-record[open] > summary::before { transform: translateY(-2px) rotate(45deg); }
.debt-obligation { grid-template-columns: 10px minmax(0, 1.5fr) repeat(2, minmax(0, .75fr)) minmax(0, 1fr); }
.debt-contract-row { grid-template-columns: 10px minmax(0, 1.3fr) minmax(0, 1fr); }
.debt-contract-row > span:last-child, .debt-balance { text-align: right; }
.debt-record small { display: block; color: var(--muted); font-size: .78rem; }
.debt-record small.debt-overdue { color: var(--warning); font-weight: 650; }
.debt-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 155px), 1fr));
  gap: 7px 10px;
  margin: 8px 0;
  padding: 8px 10px;
  background: var(--debt-fill);
  font-size: .86rem;
}
.debt-facts dt { color: var(--muted); font-size: .78rem; }
.debt-facts dd { margin: 0; white-space: pre-wrap; }
.debt-version { padding: 7px 0; border-top: 1px solid var(--line); }
.debt-version summary { font-size: .87rem; }
.debt-version-lines { list-style: none; padding: 0; margin: 5px 0 0; font-size: .87rem; }
.debt-version-lines li { display: flex; justify-content: space-between; gap: 7px; padding: 4px 0; }
.debt-version-lines strong { text-align: right; font-variant-numeric: tabular-nums; }
.debt-tail { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.debt-tail[open] > summary { margin-bottom: 8px; }
.debt-bridge-values { margin: 8px 0 0; font-variant-numeric: tabular-nums; }
.debt-bridge-values:empty { display: none; }
.debt-bridge-values > div {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
}
.debt-bridge-values > div:last-child { color: var(--debt-ink); font-weight: 650; }
.debt-bridge-values dd { margin: 0; text-align: right; }
.debt-tail-month { padding: 8px 0; border-bottom: 1px solid var(--line); }
.debt-tail-month h4 { display: flex; justify-content: space-between; gap: 7px; margin: 0; font-size: .89rem; }
.debt-tail-month h4 span { color: var(--debt-ink); text-align: right; font-variant-numeric: tabular-nums; }

.debt-editor { padding: 12px; margin: 10px 0; border: 1px solid var(--debt-edge); background: var(--debt-fill); }
.debt-editor h4, .debt-schedule h5 { margin: 0 0 9px; scroll-margin-top: 4rem; }
.debt-schedule h5 { font-size: .9rem; }
.debt-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.debt-line {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 8px;
  align-items: end;
  min-width: 0;
  margin: 0 0 8px;
  border: 1px solid var(--debt-edge);
  padding: 7px 9px 9px;
}
.debt-line legend { padding: 0 4px; color: var(--muted); font-size: .82rem; }

@media (max-width: 700px) {
  .debt-line { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 500px) {
  #receivables-workspace { gap: 11px; }
  .debt-panel { padding: 12px; }
  .debt-fields { grid-template-columns: minmax(0, 1fr); }
  #debt-filter, .debt-metrics, .debt-aging { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .debt-metrics > div, .debt-aging > div { border-bottom: 1px solid var(--line); }
  .debt-metrics > div:nth-child(even), .debt-aging > div:nth-child(even) { border-inline-end: 0; }
  .debt-metrics > div:nth-last-child(-n+2), .debt-aging > div:nth-last-child(-n+2) { border-bottom: 0; }
  .debt-obligation { grid-template-columns: 10px repeat(2, minmax(0, 1fr)); }
  .debt-obligation > span:first-child { grid-column: 2 / -1; }
  .debt-obligation > span:nth-child(2) { grid-column: 2; }
  .debt-obligation > span:nth-child(3) { grid-column: 3; }
  .debt-balance { grid-column: 2 / -1; text-align: left; }
  .debt-record > summary { gap: 5px 7px; }
}
@media (max-width: 375px) {
  .debt-line { grid-template-columns: minmax(0, 1fr); }
}

.debt-shortcuts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 8px; }
.debt-shortcuts button { min-height: 42px; }
.debt-list-tools { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 14px; }
.debt-list-tools [hidden] { display: none; }
.debt-more-actions { min-width: 0; }
.debt-more-actions[open] { flex: 1 0 100%; }
.debt-more-actions > summary { color: var(--muted); cursor: pointer; font-size: .88rem; padding-block: 6px; }
#debt-list-title { scroll-margin-top: calc(var(--finance-nav-offset, 90px) + 12px); }
.debt-opening { margin-top: 15px; overflow-wrap: anywhere; }
.debt-opening > summary { cursor: pointer; font-weight: 650; }
.debt-opening[open] > summary { margin-bottom: 9px; }
.debt-opening pre { max-width: 100%; overflow: auto; padding: 8px; background: var(--ground); font-size: .85rem; }
.debt-opening form { margin: 12px 0; }
.debt-opening fieldset { min-width: 0; padding: 0; margin: 0; border: 0; }
.debt-opening input[type="file"] { width: 100%; min-width: 0; }
#opening-refund-fields legend { margin-bottom: 9px; font-size: .88rem; font-weight: 650; }
#opening-refund-approve { min-height: 44px; }
#opening-refund-workspace .debt-version-lines li { padding: 9px 0; border-top: 1px solid var(--line); }
#opening-refund-workspace .debt-version-lines li > strong { flex-shrink: 0; white-space: nowrap; }
.debt-fields .debt-field[hidden] { display: none; }
