.terceros-module {
  display: grid;
  gap: var(--space-6);
  min-width: 0;
  color: var(--text-default);
  font-family: var(--font-family-sans);
}

.terceros-module__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.terceros-module__heading {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
}

.terceros-module__title {
  margin: 0;
  color: var(--text-strong);
  font-size: var(--font-size-2xl);
  line-height: var(--line-height-tight);
}

.terceros-module__description {
  max-width: 72ch;
  margin: 0;
  color: var(--text-muted);
  line-height: var(--line-height-relaxed);
}

.terceros-module__actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-3);
}

.terceros-module__summary {
  min-height: 1.5rem;
  margin: 0;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
}

.terceros-module__summary--error {
  color: var(--state-error);
}

.terceros-module .ui-data-grid {
  min-width: 0;
}

.terceros-module .ui-table {
  min-width: 118rem;
}

#terceros-table-body > tr > td:nth-child(9) {
  width: 8rem;
  min-width: 8rem;
  white-space: nowrap;
}

#terceros-table-body > tr > td:nth-child(9) .ui-badge {
  width: max-content;
  max-width: none;
  white-space: nowrap;
}

#terceros-table-body > tr > td:nth-child(9) .ui-badge__text {
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.terceros-table__company,
.terceros-table__identity {
  display: grid;
  gap: var(--space-1);
  min-width: 15rem;
}

.terceros-table__code,
.terceros-table__fiscal-id {
  white-space: nowrap;
}

.terceros-table__legal-name {
  color: var(--text-strong);
  font-weight: var(--font-weight-semibold);
}

.terceros-table__secondary {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

.terceros-table__roles-cell {
  min-width: 18rem;
}

.terceros-table__roles {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.terceros-table__roles .ui-badge {
  white-space: nowrap;
}

.terceros-table__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  min-width: 14rem;
}

.terceros-table__actions .ui-button {
  white-space: nowrap;
}

.terceros-form {
  display: grid;
  gap: var(--space-6);
}

.terceros-form__section {
  display: grid;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  border: 0;
}

.terceros-form__section +
.terceros-form__section {
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
}

.terceros-form__legend {
  width: 100%;
  margin: 0;
  color: var(--text-strong);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
}

.terceros-form__section-description {
  margin: calc(var(--space-2) * -1) 0 0;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-relaxed);
}

.terceros-form__grid {
  display: grid;
  grid-template-columns:
    repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.terceros-form__field--full {
  grid-column: 1 / -1;
}

.terceros-form__required {
  color: var(--state-error);
}

.terceros-form__help {
  margin: var(--space-1) 0 0;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
}

.terceros-form__roles {
  display: grid;
  grid-template-columns:
    repeat(2, minmax(0, 1fr));
  gap: var(--space-3) var(--space-4);
}

.terceros-form__message {
  min-height: 1.5rem;
  margin: 0;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
}

.terceros-form__message--error {
  color: var(--state-error);
}

.terceros-form__message--success {
  color: var(--state-success);
}

.terceros-form__footer-status {
  flex: 1 1 auto;
  min-width: 12rem;
}

#terceros-modal .ui-modal__dialog {
  width: min(72rem, 100%);
}

#terceros-modal .ui-modal__body {
  overscroll-behavior: contain;
}

@media (max-width: 900px) {
  .terceros-module__header {
    align-items: stretch;
    flex-direction: column;
  }

  .terceros-module__actions,
  .terceros-table__actions {
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  .terceros-module {
    gap: var(--space-4);
  }

  .terceros-module__actions,
  .terceros-module__actions .ui-button {
    width: 100%;
  }

  .terceros-form__grid,
  .terceros-form__roles {
    grid-template-columns: 1fr;
  }

  .terceros-form__field--full {
    grid-column: auto;
  }

  #terceros-modal .ui-modal__footer {
    align-items: stretch;
  }

  #terceros-modal .ui-modal__footer .ui-button {
    width: 100%;
  }
}
