/* Each payment row groups the advance, final payment, and contract total. */
dialog[open]:has(.payment-tab-view) {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

dialog:has(.payment-tab-view) > .modal-head,
dialog:has(.payment-tab-view) > .modal-tabs,
dialog:has(.payment-tab-view) > .modal-footer {
  flex: 0 0 auto;
}

dialog:has(.payment-tab-view) > .modal-body {
  display: flex;
  flex: 0 1 auto;
  min-height: 0;
  overflow: hidden;
}

.payment-tab-view {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

.payment-tab-view .payment-register {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--rule, #dce6e2);
  border-radius: 12px;
  background: #fff;
}

.payment-tab-view .payment-register-head {
  flex: 0 0 auto;
  align-items: flex-start;
  gap: 12px;
  margin: 0;
  padding: 16px 18px;
  border-bottom: 1px solid #e1e9e4;
  background: #fbfdfc;
}

.payment-tab-view .payment-register-head h3 {
  font-size: 17px;
  line-height: 1.4;
}

.payment-tab-view .payment-register-head p {
  margin-top: 5px;
  color: #526e5e;
  font-size: 12px;
  line-height: 1.45;
}

.payment-tab-view .payment-table-wrap {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.payment-tab-view .payment-table.payment-table--stages {
  width: 100%;
  min-width: 1000px;
  table-layout: fixed;
  border-collapse: collapse;
  color: #2d4638;
  font-size: 13px;
  line-height: 1.45;
}

.payment-tab-view .payment-table--stages .pay-col-party { width: 22%; }
.payment-tab-view .payment-table--stages .pay-col-advance,
.payment-tab-view .payment-table--stages .pay-col-final,
.payment-tab-view .payment-table--stages .pay-col-total { width: 26%; }

/* Reset legacy per-column widths; separators distinguish the payment stages. */
.payment-tab-view .payment-table.payment-table--stages th,
.payment-tab-view .payment-table.payment-table--stages td {
  width: auto;
  padding: 16px;
  border-right: 1px solid #e8efea;
  border-bottom: 1px solid #dde7e0;
  vertical-align: top;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
}

.payment-tab-view .payment-table.payment-table--stages th:last-child,
.payment-tab-view .payment-table.payment-table--stages td:last-child {
  border-right: 0;
}

.payment-tab-view .payment-table.payment-table--stages thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding-top: 12px;
  padding-bottom: 12px;
  color: #476351;
  background: #f2f7f3;
  font-size: 12px;
  line-height: 1.4;
  font-weight: 650;
  text-transform: none;
  letter-spacing: 0;
  vertical-align: middle;
}

.payment-tab-view .payment-table.payment-table--stages tbody tr:last-child td {
  border-bottom: 0;
}

.payment-tab-view .payment-table--stages .payment-register-row {
  cursor: pointer;
}

.payment-tab-view .payment-table--stages .payment-register-row:hover {
  background: #f5faf7;
  box-shadow: inset 2px 0 #008967;
}

.payment-tab-view .payment-table--stages .payment-register-row:focus-visible {
  outline: 2px solid #008967;
  outline-offset: -2px;
  background: #f0f8f3;
}

.payment-tab-view .payment-table--stages .payment-counterparty {
  display: block;
  max-width: none;
  margin: 0;
  color: #2b4435;
  font-size: 14px;
  line-height: 1.45;
  font-weight: 650;
  white-space: normal;
  overflow-wrap: anywhere;
}

.payment-tab-view .payment-table--stages .payment-direction {
  display: inline-flex;
  align-items: flex-start;
  gap: 5px;
  margin-top: 7px;
  font-size: 11.5px;
  line-height: 1.4;
  font-weight: 500;
}

.payment-tab-view .payment-table--stages .payment-direction svg {
  width: 14px;
  height: 14px;
  margin-top: 1px;
}

.payment-tab-view .payment-table--stages .payment-direction small {
  margin-top: 2px;
  font-size: 11px;
  line-height: 1.4;
}

.payment-tab-view .payment-table--stages .payment-basis-cell {
  display: block;
  max-width: none;
  margin-top: 11px;
  color: #5b7364;
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.payment-tab-view .payment-cell-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 24px;
  margin-bottom: 11px;
}

.payment-tab-view .payment-stage-state {
  display: inline-block;
  max-width: 100%;
  padding: 3px 7px;
  border-radius: 6px;
  color: #526a5a;
  background: #edf2ee;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  white-space: normal;
}

.payment-tab-view .payment-stage-state.is-paid {
  color: #007b59;
  background: #e7f4ec;
}

.payment-tab-view .payment-stage-state.is-unpaid {
  color: #986019;
  background: #fff3df;
}

.payment-tab-view .payment-stage-state.is-partial {
  color: #256781;
  background: #eaf3f8;
}

.payment-tab-view .payment-stage-state.is-overpaid {
  color: #966224;
  background: #fff2dc;
}

.payment-tab-view .payment-stage-state.is-empty {
  color: #647569;
  background: #f0f3f1;
  font-weight: 500;
}

.payment-tab-view .payment-plan-rate {
  color: #516e5d;
  font-size: 12px;
  line-height: 1.4;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.payment-tab-view .payment-cell-values {
  margin: 0;
}

.payment-tab-view .payment-cell-values > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: baseline;
  gap: 8px;
  padding: 4px 0;
}

.payment-tab-view .payment-cell-values dt {
  min-width: 0;
  margin: 0;
  color: #617867;
  font-size: 12px;
  line-height: 1.5;
  font-weight: 400;
  overflow-wrap: normal;
}

.payment-tab-view .payment-cell-values dd {
  margin: 0;
  color: #2b4735;
  font-size: 14px;
  line-height: 1.4;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.payment-tab-view .payment-cell-values .payment-cell-balance {
  margin-top: 5px;
  padding-top: 9px;
  border-top: 1px solid #e3ebe5;
}

.payment-tab-view .payment-cell-balance dt,
.payment-tab-view .payment-cell-balance dd {
  color: #284c36;
  font-weight: 650;
}

.payment-tab-view .payment-cell-balance.is-overpaid dt,
.payment-tab-view .payment-cell-balance.is-overpaid dd {
  color: #976121;
}

.payment-tab-view .payment-cell-empty {
  margin: 0;
  color: #748479;
  font-size: 12px;
  line-height: 1.6;
}

.payment-tab-view .payment-register-note {
  display: block;
  flex: 0 0 auto;
  margin: 0;
  padding: 11px 16px;
  border-top: 1px solid #e1e9e4;
  color: #667b6d;
  font-size: 12px;
  line-height: 1.45;
}

.payment-form-terms {
  min-width: 0;
  margin: 16px 0;
  border: 1px solid #dfe8e2;
  border-radius: 10px;
  background: #f8fbf9;
}

.payment-form-terms > summary {
  padding: 12px 14px;
  color: #365846;
  font-size: 13px;
  line-height: 1.45;
  font-weight: 600;
  cursor: pointer;
}

.payment-form-terms > summary:focus-visible {
  outline: 2px solid #008967;
  outline-offset: -3px;
  border-radius: 9px;
}

.payment-form-terms dl {
  min-width: 0;
  margin: 0;
  padding: 0 14px 8px;
}

.payment-form-terms dl > div {
  display: grid;
  grid-template-columns: minmax(120px, .7fr) minmax(0, 1.6fr);
  align-items: start;
  gap: 12px;
  padding: 11px 0;
  border-top: 1px solid #e5ece7;
}

.payment-form-terms dt {
  margin: 0;
  color: #607566;
  font-size: 12px;
  line-height: 1.5;
}

.payment-form-terms dd {
  min-width: 0;
  margin: 0;
  color: #36513f;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* The calculator shows one VAT-inclusive value for each figure. */
.payment-summary {
  min-width: 0;
  margin: 12px 0 0;
}

.payment-summary .payment-overview {
  min-width: 0;
  padding: 14px 16px 10px;
  border: 1px solid #dce6df;
  border-radius: 11px;
  background: #fff;
}

.payment-summary .payment-section-title {
  padding-bottom: 6px;
  color: #5a7565;
  font-size: 12px;
  line-height: 1.45;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.payment-summary .payment-totals {
  padding: 0 0 9px;
  border: 0;
}

.payment-summary .payment-totals > div,
.payment-summary .payment-fact {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, max-content);
  align-items: baseline;
  gap: 12px;
  padding: 6px 0;
}

.payment-summary .payment-totals > div > span {
  color: #36513f;
  font-size: 14px;
  line-height: 1.45;
}

.payment-summary .payment-totals strong {
  min-width: 0;
  max-width: 100%;
  margin: 0;
  color: #244b34;
  font-size: 17px;
  line-height: 1.4;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: normal;
  overflow-wrap: anywhere;
}

.payment-summary .payment-facts {
  padding: 7px 0 0;
  border: 0;
  border-top: 1px solid #e2eae5;
}

.payment-summary .payment-fact > b {
  min-width: 0;
  color: #5b7363;
  font-size: 13px;
  line-height: 1.5;
  font-weight: 500;
}

.payment-summary .payment-pair {
  display: block;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  color: #2d4c38;
  font-size: 15px;
  line-height: 1.45;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: normal;
  overflow-wrap: anywhere;
}

.payment-summary .payment-pair > span {
  display: block;
  margin: 0;
}

.payment-summary .payment-stage-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 12px;
  margin-top: 12px;
}

.payment-summary .payment-stage {
  min-width: 0;
  padding: 13px 14px 12px;
  border-radius: 10px;
}

.payment-summary .payment-stage-head {
  align-items: flex-start;
  gap: 10px;
  padding-bottom: 9px;
}

.payment-summary .payment-stage-head b {
  min-width: 0;
  font-size: 14px;
  line-height: 1.4;
  font-weight: 650;
}

.payment-summary .payment-stage-head > span {
  flex: 0 1 auto;
  max-width: 48%;
  padding: 3px 7px;
  font-size: 11px;
  line-height: 1.4;
  white-space: normal;
  overflow-wrap: anywhere;
}

.payment-summary .payment-stage p {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, max-content);
  align-items: baseline;
  gap: 12px;
  margin-top: 9px;
}

.payment-summary .payment-stage p > small {
  min-width: 0;
  color: #637969;
  font-size: 12px;
  line-height: 1.45;
}

.payment-summary .payment-stage-muted,
.payment-summary .payment-stage-muted + .payment-stage-final {
  grid-column: 1 / -1;
}

.payment-summary .payment-stage-muted .payment-stage-head {
  align-items: center;
  padding-bottom: 0;
  border-bottom: 0;
}

@media (max-width: 760px) {
  .payment-summary .payment-stage-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  .payment-summary .payment-overview,
  .payment-summary .payment-stage {
    padding: 12px;
  }

  .payment-summary .payment-totals strong {
    font-size: 16px;
  }

  .payment-summary .payment-pair {
    font-size: 14px;
  }
}

@media (max-width: 800px) {
  dialog[open]:has(.payment-tab-view) {
    height: var(--app-height, 100dvh);
    max-height: var(--app-height, 100dvh);
  }

  dialog:has(.payment-tab-view) > .modal-body {
    flex: 1 1 auto;
    padding: 16px 12px;
  }

  .payment-tab-view .payment-register {
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .payment-tab-view .payment-register-head {
    padding: 0 2px 12px;
    border: 0;
    background: transparent;
  }

  .payment-tab-view .payment-register-head h3 {
    font-size: 17px;
  }

  .payment-tab-view .payment-table-wrap {
    padding: 2px;
    border-radius: 10px;
  }

  .payment-tab-view .payment-table.payment-table--stages {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    table-layout: auto;
  }

  .payment-tab-view .payment-table--stages colgroup {
    display: none;
  }

  .payment-tab-view .payment-table.payment-table--stages thead {
    position: absolute;
    display: table-header-group;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .payment-tab-view .payment-table.payment-table--stages tbody {
    display: grid;
    width: 100%;
    gap: 12px;
  }

  .payment-tab-view .payment-table.payment-table--stages tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    min-width: 0;
    border: 1px solid #dfe8e2;
    border-radius: 11px;
    background: #fff;
    overflow: hidden;
  }

  .payment-tab-view .payment-table.payment-table--stages tbody td {
    display: block;
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    padding: 13px 12px;
    border: 0;
    border-top: 1px solid #e5ece7;
  }

  .payment-tab-view .payment-table.payment-table--stages tbody td:first-child {
    border-top: 0;
    padding-top: 15px;
    padding-bottom: 15px;
  }

  .payment-tab-view .payment-table.payment-table--stages tbody td::before {
    display: block;
    content: attr(data-label);
    margin-bottom: 10px;
    color: #36533f;
    font-size: 13px;
    line-height: 1.4;
    font-weight: 650;
    text-align: left;
  }

  .payment-tab-view .payment-table.payment-table--stages tbody td:first-child::before {
    display: none;
  }

  .payment-tab-view .payment-cell-heading {
    margin-bottom: 7px;
  }

  .payment-tab-view .payment-table--stages .payment-basis-cell {
    margin-top: 8px;
  }

  .payment-tab-view .payment-cell-values dd {
    font-size: 14px;
  }

  .payment-tab-view .payment-register-note {
    padding: 11px 2px 0;
    border: 0;
    font-size: 11px;
  }

  .payment-form-terms dl > div {
    grid-template-columns: minmax(0, 1fr);
    gap: 5px;
  }
}
