#modal-root {
  position: relative;
  z-index: 1000;
}

#modal-stack {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

[hidden] {
  display: none !important;
}

.app-modal {
  --app-modal-edge-gap: 28px;
  --app-modal-vertical-gap: 56px;
  position: absolute;
  z-index: 1;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--app-modal-edge-gap);
  pointer-events: auto;
}

.app-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(14, 20, 28, 0.54);
  opacity: 0;
  transition: opacity 160ms ease;
}

.app-modal__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(var(--app-modal-width, 560px), 100%);
  max-height: min(calc(100dvh - var(--app-modal-vertical-gap)), 880px);
  overflow: hidden;
  background: #fff;
  border: 1px solid #dce1e8;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transition: opacity 160ms ease, transform 160ms ease;
}

.app-modal.has-stable-tab-height .app-modal__panel {
  min-height: min(
    var(--app-modal-session-min-height),
    calc(100dvh - var(--app-modal-vertical-gap)),
    880px
  );
}

.app-modal--sm {
  --app-modal-width: 420px;
}

.app-modal--md {
  --app-modal-width: 560px;
}

.app-modal--lg {
  --app-modal-width: 760px;
}

.app-modal--xl {
  --app-modal-width: 980px;
}

.app-modal.is-open .app-modal__backdrop {
  opacity: 1;
}

.app-modal.is-open .app-modal__panel {
  opacity: 1;
  /* Keep viewport-positioned popovers anchored to their controls after the entrance animation. */
  transform: none;
}

.app-modal.is-closing .app-modal__backdrop {
  opacity: 0;
}

.app-modal.is-closing .app-modal__panel {
  opacity: 0;
  transform: translateY(10px) scale(0.985);
}

.app-modal.is-inactive .app-modal__backdrop {
  pointer-events: none;
}

.app-modal.is-inactive {
  z-index: 0;
}

.app-modal.is-inactive .app-modal__panel {
  transform: translateY(0) scale(0.985);
}

.app-modal__header,
.app-modal__footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
}

.app-modal__header {
  justify-content: space-between;
  border-bottom: 1px solid #e6e9ef;
}

.app-modal__heading {
  min-width: 0;
}

.app-modal__title {
  margin: 0;
  color: #17202c;
  font-size: 1.15rem;
  line-height: 1.25;
}

.app-modal__subtitle {
  margin: 3px 0 0;
  color: #667085;
  font-size: 0.84rem;
  font-weight: 650;
  line-height: 1.3;
}

.app-modal__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #5d6675;
  cursor: pointer;
  font-size: 1.35rem;
  line-height: 1;
}

.app-modal__close:hover {
  background: #f0f3f7;
  color: #1f2937;
}

.app-modal__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
}

.app-modal__body--split-scroll {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.copy-modal {
  gap: 14px;
}

.copy-modal__toolbar {
  flex: 0 0 auto;
  padding-bottom: 14px;
  border-bottom: 1px solid #e6e9ef;
}

.copy-modal__toolbar .month-picker {
  max-width: 300px;
}

.copy-modal__form {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
}

.copy-modal__list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.copy-modal__selection-summary {
  margin-right: auto;
  color: #5f6368;
  font-size: 0.86rem;
  font-weight: 650;
}

.app-modal__panel > form {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.modal-tabs {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.modal-tabs__input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.modal-tabs__list {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 12px 20px 0;
  border-bottom: 1px solid #e6e9ef;
}

.modal-tabs__tab {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  padding: 0 14px;
  border-radius: 8px 8px 0 0;
  color: #5f6368;
  cursor: pointer;
  font-weight: 760;
}

.modal-tabs__tab:hover {
  background: #f8fafd;
  color: #202124;
}

.modal-tabs__input--data:checked ~ .modal-tabs__list .modal-tabs__tab--data,
.modal-tabs__input--representatives:checked ~ .modal-tabs__list .modal-tabs__tab--representatives,
.modal-tabs__input--allocation:checked ~ .modal-tabs__list .modal-tabs__tab--allocation {
  background: #eaf1ff;
  color: #185abc;
}

.modal-tabs__input--main:checked ~ .modal-tabs__list .modal-tabs__tab--main,
.modal-tabs__input--areas:checked ~ .modal-tabs__list .modal-tabs__tab--areas,
.modal-tabs__input--payers:checked ~ .modal-tabs__list .modal-tabs__tab--payers,
.modal-tabs__input--payments:checked ~ .modal-tabs__list .modal-tabs__tab--payments {
  background: #eaf1ff;
  color: #185abc;
}

.modal-tabs__panels {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.modal-tabs__panel {
  display: none;
  flex: 1;
  min-width: 0;
  min-height: 0;
}

.modal-tabs__input--data:checked ~ .modal-tabs__panels .modal-tabs__panel--data,
.modal-tabs__input--representatives:checked ~ .modal-tabs__panels .modal-tabs__panel--representatives,
.modal-tabs__input--allocation:checked ~ .modal-tabs__panels .modal-tabs__panel--allocation {
  display: flex;
}

.modal-tabs__input--main:checked ~ .modal-tabs__panels .modal-tabs__panel--main,
.modal-tabs__input--areas:checked ~ .modal-tabs__panels .modal-tabs__panel--areas,
.modal-tabs__input--payers:checked ~ .modal-tabs__panels .modal-tabs__panel--payers,
.modal-tabs__input--payments:checked ~ .modal-tabs__panels .modal-tabs__panel--payments {
  display: flex;
}

.modal-tabs__panel > form {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.app-modal__footer {
  justify-content: flex-end;
  border-top: 1px solid #e6e9ef;
  background: #fbfcfd;
}

.app-modal--danger .app-modal__header {
  border-bottom-color: #f1c8c3;
}

.app-modal--danger .app-modal__title {
  color: #9f1d14;
}

.app-modal--warning .app-modal__header {
  border-bottom-color: #fde293;
}

.app-modal--warning .app-modal__title {
  color: var(--color-warning, #b06000);
}

.form-grid {
  display: grid;
  align-items: start;
  gap: 16px;
}

.form-grid--two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid--three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid--compact {
  width: 100%;
  max-width: 720px;
}

.form-readonly {
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.app-modal__body--split-scroll > .form-readonly {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  overflow: hidden;
}

.form-readonly:disabled {
  color: inherit;
}

.form-readonly:disabled input,
.form-readonly:disabled select,
.form-readonly:disabled textarea,
.form-readonly:disabled .option-tile,
.form-readonly:disabled .check-tile {
  background: #f8fafd;
  color: #354052;
  cursor: default;
  opacity: 1;
}

.field--wide {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  align-content: start;
  gap: 6px;
  color: #354052;
  font-weight: 650;
}

.field input,
.field select {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid #cbd3df;
  border-radius: 6px;
  background: #fff;
  color: #1f2937;
}

.field input[type="date"].is-empty {
  color: #cccccc;
  font-weight: 500;
}

.field input[type="date"].is-empty:focus {
  color: var(--color-text, #202124);
}

.readonly-field {
  display: flex;
  min-height: 40px;
  align-items: center;
  padding: 0 10px;
  background: #f8fafd;
  border: 1px solid #dfe4eb;
  border-radius: 6px;
  color: #354052;
  font-weight: 700;
}

.option-row,
.check-grid {
  display: grid;
  gap: 8px;
}

.option-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.check-grid {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.option-tile,
.check-tile {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid #dfe4eb;
  border-radius: 6px;
  background: #fff;
  color: #354052;
  font-weight: 700;
}

.option-tile input,
.check-tile input {
  width: auto;
  min-height: auto;
  margin: 0;
}

.field input:focus,
.field select:focus,
.app-modal__panel:focus,
.app-modal__close:focus,
.btn:focus {
  outline: 3px solid rgba(31, 111, 235, 0.24);
  outline-offset: 2px;
}

.field-error,
.form-error {
  color: #b42318;
}

.form-error {
  margin: 0 0 16px;
  font-weight: 650;
}

.field-error {
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.25;
}

.app-modal__eyebrow,
.unit-payment-profile__eyebrow {
  display: block;
  margin-bottom: 2px;
  color: #687385;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.form-section {
  display: grid;
  gap: 16px;
}

.form-section--separated {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #e6e9ef;
}

.form-section__heading {
  display: grid;
  gap: 3px;
  margin-bottom: 16px;
}

.form-section__heading strong {
  color: #1f2937;
  font-size: 1rem;
}

.form-section__heading span {
  color: #687385;
  font-size: 0.88rem;
}

.unit-party-picker {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  align-items: start;
  gap: 8px;
}

.unit-party-picker__select {
  min-width: 0;
}

.unit-party-picker__add {
  margin-top: 26px;
}

.unit-payment-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 20px;
  padding: 4px;
  border: 1px solid #dfe4eb;
  border-radius: 10px;
  background: #f7f9fc;
}

.unit-payment-switch__button {
  display: grid;
  gap: 2px;
  min-height: 48px;
  padding: 7px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #526070;
  cursor: pointer;
  font: inherit;
  font-weight: 760;
  text-align: left;
}

.unit-payment-switch__button span {
  overflow: hidden;
  color: #687385;
  font-size: 0.8rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-payment-switch__button.is-active {
  background: #fff;
  color: #185abc;
  box-shadow: 0 1px 3px rgba(31, 41, 55, 0.12);
}

.unit-payment-switch__button:disabled {
  cursor: default;
  opacity: 0.48;
}

.unit-payment-switch__button:focus-visible {
  outline: 3px solid rgba(31, 111, 235, 0.24);
  outline-offset: 2px;
}

.unit-payment-profile {
  display: grid;
  gap: 20px;
}

.unit-payment-profile__intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}

.unit-payment-profile__intro strong {
  display: block;
  color: #1f2937;
  font-size: 1.05rem;
}

.unit-payment-profile__intro p {
  max-width: 360px;
  margin: 0;
  color: #687385;
  font-size: 0.86rem;
  text-align: right;
}

.unit-payment-options {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-details {
  border-top: 1px solid #e6e9ef;
  padding-top: 14px;
}

.form-details summary {
  color: #526070;
  cursor: pointer;
  font-weight: 760;
}

.form-details[open] summary {
  margin-bottom: 14px;
}

.muted {
  margin-top: 0;
  color: #687385;
}

.select-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.select-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px;
  border: 1px solid #dfe4eb;
  border-radius: 8px;
}

.select-row span {
  display: block;
  margin-top: 3px;
  color: #667085;
  font-size: 0.92rem;
}

.refresh-box {
  margin-top: 16px;
  padding: 12px;
  border: 1px dashed #b8c2d1;
  border-radius: 8px;
  color: #526070;
}

.selected-user {
  display: grid;
  gap: 4px;
}

.selected-user span,
.selected-user small {
  color: #667085;
}

.selected-user strong {
  color: #1f2937;
}

.detail-list {
  display: grid;
  gap: 14px;
  margin: 0;
}

.detail-list div {
  display: grid;
  gap: 4px;
}

.detail-list dt {
  color: #687385;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.detail-list dd {
  margin: 0;
}

.unit-party-merge-selection,
.unit-party-merge-preview {
  display: grid;
  gap: 18px;
}

.unit-party-merge-source {
  display: grid;
  gap: 3px;
  padding: 14px 16px;
  border: 1px solid #dfe4eb;
  border-radius: 8px;
  background: #f8fafd;
}

.unit-party-merge-source > span {
  color: #687385;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.unit-party-merge-source strong {
  color: #1f2937;
  font-size: 1rem;
}

.unit-party-merge-source small {
  color: #687385;
}

.unit-party-merge-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.unit-party-merge-choices legend {
  grid-column: 1 / -1;
  margin-bottom: 2px;
  color: #354052;
  font-weight: 760;
}

.unit-party-merge-card {
  display: grid;
  min-width: 0;
  gap: 14px;
  padding: 16px;
  border: 1px solid #cbd3df;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}

.unit-party-merge-card:has(input:checked) {
  border-color: #1f6feb;
  box-shadow: 0 0 0 2px rgba(31, 111, 235, .14);
}

.unit-party-merge-card:focus-within {
  outline: 3px solid rgba(31, 111, 235, .24);
  outline-offset: 2px;
}

.unit-party-merge-card > strong {
  color: #17202c;
  font-size: 1.03rem;
  overflow-wrap: anywhere;
}

.unit-party-merge-card__choice {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #185abc;
  font-weight: 760;
}

.unit-party-merge-card__choice input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.unit-party-merge-card__details {
  display: grid;
  gap: 9px;
  margin: 0;
}

.unit-party-merge-card__details div {
  display: grid;
  grid-template-columns: 106px minmax(0, 1fr);
  gap: 10px;
}

.unit-party-merge-card__details dt {
  color: #687385;
  font-size: .75rem;
  font-weight: 700;
}

.unit-party-merge-card__details dd {
  min-width: 0;
  margin: 0;
  color: #354052;
  font-size: .85rem;
  overflow-wrap: anywhere;
}

.unit-party-merge-card__usage {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid #e6e9ef;
}

.unit-party-merge-card__usage span {
  padding: 3px 7px;
  border-radius: 999px;
  background: #f0f3f7;
  color: #526070;
  font-size: .72rem;
  font-weight: 700;
}

.unit-party-merge-note {
  margin: 0;
  padding: 12px 14px;
  border-left: 3px solid #f4b400;
  background: #fffaf0;
  color: #654b16;
  font-size: .86rem;
  line-height: 1.45;
}

.htmx-indicator {
  display: none;
  color: #64748b;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline;
}

@media (max-width: 560px) {
  .app-modal {
    --app-modal-edge-gap: 0px;
    --app-modal-vertical-gap: 8dvh;
    align-items: end;
  }

  .app-modal__panel {
    width: 100%;
    border-radius: 8px 8px 0 0;
  }

  .app-modal__footer {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .app-modal__footer .btn {
    width: 100%;
  }

  .form-grid--two {
    grid-template-columns: 1fr;
  }

  .form-grid--three {
    grid-template-columns: 1fr;
  }

  .unit-count-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .unit-party-merge-choices {
    grid-template-columns: 1fr;
  }

  .modal-tabs--unit .modal-tabs__list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    display: grid;
    gap: 4px;
    padding: 10px 12px;
  }

  .modal-tabs--unit .modal-tabs__tab {
    min-height: 36px;
    justify-content: center;
    border-radius: 7px;
  }

  .unit-party-picker {
    grid-template-columns: minmax(0, 1fr) 44px;
  }

  .unit-party-picker__add {
    width: 44px;
    height: 44px;
  }

  .unit-payment-options,
  .unit-payment-switch {
    grid-template-columns: 1fr;
  }

  .unit-payment-profile__intro {
    align-items: start;
    flex-direction: column;
    gap: 6px;
  }

  .unit-payment-profile__intro p {
    text-align: left;
  }
}
.app-confirmation-list {
  display: grid;
  gap: .5rem;
  margin: 1rem 0;
  padding: .85rem 1rem .85rem 2.1rem;
  border: 1px solid var(--border-color, #dfe4ea);
  background: var(--surface-subtle, #f7f8fa);
  border-radius: .75rem;
  color: var(--text-muted, #5f6b7a);
  font-size: .875rem;
}

.app-confirmation-list li::marker {
  color: var(--warning, #b7791f);
}
.portal-access-controls{min-width:0;overflow-wrap:anywhere}.portal-access-controls .form-actions{display:flex;flex-wrap:wrap;gap:8px}.portal-access-controls .btn{white-space:normal;max-width:100%;min-height:44px}.portal-access-controls p{margin-block:8px}
